mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
37 lines
651 B
Ruby
37 lines
651 B
Ruby
|
# A very simple formatter for imported emails
|
||
|
class EmailCook
|
||
|
|
||
|
def initialize(raw)
|
||
|
@raw = raw
|
||
|
end
|
||
|
|
||
|
def cook
|
||
|
result = ""
|
||
|
|
||
|
in_quote = false
|
||
|
quote_buffer = ""
|
||
|
@raw.each_line do |l|
|
||
|
|
||
|
if l =~ /^\s*>/
|
||
|
in_quote = true
|
||
|
quote_buffer << l.sub(/^[\s>]*/, '') << "<br>"
|
||
|
elsif in_quote
|
||
|
result << "<blockquote>#{quote_buffer}</blockquote>"
|
||
|
quote_buffer = ""
|
||
|
in_quote = false
|
||
|
else
|
||
|
result << l << "<br>"
|
||
|
end
|
||
|
end
|
||
|
|
||
|
if in_quote
|
||
|
result << "<blockquote>#{quote_buffer}</blockquote>"
|
||
|
end
|
||
|
|
||
|
result.gsub!(/(<br>){3,10}/, '<br><br>')
|
||
|
|
||
|
result
|
||
|
end
|
||
|
|
||
|
end
|