21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/doing/wwid.rb', line 21
def link_urls(opt = {})
opt[:format] ||= :html
if opt[:format] == :html
gsub(%r{(?mi)((http|https)://)?([\w\-_]+(\.[\w\-_]+)+)([\w\-.,@?^=%&:/~+#]*[\w\-@^=%&/~+#])?}) do |_match|
m = Regexp.last_match
proto = m[1].nil? ? 'http://' : ''
%(<a href="#{proto}#{m[0]}" title="Link to #{m[0]}">[#{m[3]}]</a>)
end.gsub(/<(\w+:.*?)>/) do |match|
m = Regexp.last_match
if m[1] =~ /<a href/
match
else
%(<a href="#{m[1]}" title="Link to #{m[1]}">[link]</a>)
end
end
else
self
end
end
|