Fixed autolinking to work better in more cases #1013 [Jamis Buck]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1099 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson
2005-04-06 15:22:32 +00:00
parent 6427133584
commit 480150e5fb

View File

@@ -157,7 +157,14 @@ module ActionView
# Turns all urls into clickable links.
def auto_link_urls(text)
text.gsub(/([^=><!:'"\/]|^)((http[s]?:\/\/)|(www\.))(\S+\b\/?)([[:punct:]]*)(\s|$)/, '\1<a href="\3\4\5">\3\4\5</a>\6\7')
text.gsub(/(<\w+.*?>|[^=!:'"\/]|^)((?:http[s]?:\/\/)|(?:www\.))([^\s<]+\/?)([[:punct:]]|\s|<|$)/) do
all, a, b, c, d = $&, $1, $2, $3, $4
if a =~ /<a\s/i # don't replace URL's that are already linked
all
else
%(#{a}<a href="#{b=="www."?"http://www.":b}#{c}">#{b}#{c}</a>#{d})
end
end
end
# Turns all email addresses into clickable links.