Method deprecated or moved
This method is deprecated or moved on the latest stable version.
The last existing version (v3.0.9) is shown here.
auto_link_urls(text, html_options = {}, options = {})
private
Turns all urls into clickable links. If a block is given, each url is
yielded and the result is used as the link text.
Show source
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?($`, $')
href
else
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