FIX: Better link extraction than URL.regexp

This commit is contained in:
Robin Ward 2015-10-29 16:01:50 -04:00
parent fe901163cc
commit c68cbe700b

View File

@ -1,9 +1,11 @@
# A very simple formatter for imported emails
require 'uri'
class EmailCook
def self.url_regexp
/[^\>]*((?:https?:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.])(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\([^\s()<>]+\)|[^`!()\[\]{};:'".,<>?«»\s]))/
end
def initialize(raw)
@raw = raw
end
@ -23,6 +25,11 @@ class EmailCook
quote_buffer = ""
in_quote = false
else
l.scan(regexp).each do |m|
url = m[0]
l.gsub!(url, "<a href='#{url}'>#{url}</a>")
end
result << l << "<br>"
end
end
@ -32,11 +39,6 @@ class EmailCook
end
result.gsub!(/(<br>){3,10}/, '<br><br>')
URI.extract(result).each do |m|
result.gsub!(m, "<a href='#{m}'>#{m}</a>")
end
result
end