FIX: Email cooker should support links within blockquotes

This commit is contained in:
Robin Ward 2016-07-18 14:38:40 -04:00
parent 6db50b820d
commit 12cfc8cedd
2 changed files with 13 additions and 4 deletions

View file

@ -17,6 +17,13 @@ class EmailCook
end end
end end
def link_string!(str)
str.scan(EmailCook.url_regexp).each do |m|
url = m[0]
str.gsub!(url, "<a href='#{url}'>#{url}</a>")
end
end
def cook def cook
result = "" result = ""
@ -28,6 +35,7 @@ class EmailCook
if l =~ /^\s*>/ if l =~ /^\s*>/
in_quote = true in_quote = true
link_string!(l)
quote_buffer << l.sub(/^[\s>]*/, '') << "<br>" quote_buffer << l.sub(/^[\s>]*/, '') << "<br>"
elsif in_quote elsif in_quote
add_quote(result, quote_buffer) add_quote(result, quote_buffer)
@ -37,10 +45,7 @@ class EmailCook
sz = l.size sz = l.size
l.scan(EmailCook.url_regexp).each do |m| link_string!(l)
url = m[0]
l.gsub!(url, "<a href='#{url}'>#{url}</a>")
end
result << l result << l

View file

@ -34,4 +34,8 @@ LONG_COOKED
it 'autolinks without the beginning of a line' do it 'autolinks without the beginning of a line' do
expect(EmailCook.new("my site: https://www.eviltrout.com").cook).to eq("my site: <a href='https://www.eviltrout.com'>https://www.eviltrout.com</a><br>") expect(EmailCook.new("my site: https://www.eviltrout.com").cook).to eq("my site: <a href='https://www.eviltrout.com'>https://www.eviltrout.com</a><br>")
end end
it 'links even within a quote' do
expect(EmailCook.new("> https://www.eviltrout.com").cook).to eq("<blockquote><a href='https://www.eviltrout.com'>https://www.eviltrout.com</a><br></blockquote>")
end
end end