13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/doing/wwid.rb', line 13
def link_urls(opt={})
opt[:format] ||= :html
if opt[:format] == :html
self.gsub(/(?mi)((http|https):\/\/)?([\w\-_]+(\.[\w\-_]+)+)([\w\-\.,\@?^=%&:\/~\+#]*[\w\-\@^=%&\/~\+#])?/) {|match|
m = Regexp.last_match
proto = m[1].nil? ? "http://" : ""
%Q{<a href="#{proto}#{m[0]}" title="Link to #{m[0]}">[#{m[3]}]</a>}
}.gsub(/\<(\w+:.*?)\>/) {|match|
m = Regexp.last_match
unless m[1] =~ /<a href/
%Q{<a href="#{m[1]}" title="Link to #{m[1]}">[link]</a>}
else
match
end
}
else
self
end
end
|