module ActionView::Helpers::TextHelper
def auto_link_urls(text, html_options = {}, options = {})
Turns all urls into clickable links. If a block is given, each url
def auto_link_urls(text, html_options = {}, options = {}) link_attributes = html_options.stringify_keys text.to_str.gsub(AUTO_LINK_RE) do scheme, href = $1, $& punctuation = [] if auto_linked?($`, $') # do not change string; URL is already linked href else # don't include trailing punctuation character as part of the URL while href.sub!(/[^\w\/-]$/, '') punctuation.push $& if opening = BRACKETS[punctuation.last] and href.scan(opening).size > href.scan(punctuation.last).size href << punctuation.pop break end end link_text = block_given? ? yield(href) : href href = 'http://' + href unless scheme sanitize = options[:sanitize] != false content_tag(:a, link_text, link_attributes.merge('href' => href), sanitize) + punctuation.reverse.join('') end end end