instance method auto_link_urls

Ruby on Rails 2.3.18

Since v2.2.3 Last seen in v3.0.20 Private

Available in: v2.2.3 v2.3.18 v3.0.20

Signature

auto_link_urls(text, html_options = {})

Turns all urls into clickable links. If a block is given, each url is yielded and the result is used as the link text.

Parameters

text req
html_options opt = {}
Source
# File actionpack/lib/action_view/helpers/text_helper.rb, line 548
        def auto_link_urls(text, html_options = {})
          link_attributes = html_options.stringify_keys
          text.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

              content_tag(:a, h(link_text), link_attributes.merge('href' => href)) + punctuation.reverse.join('')
            end
          end
        end

Defined in actionpack/lib/action_view/helpers/text_helper.rb line 548 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionView::Helpers::TextHelper

Type at least 2 characters to search.

↑↓ navigate · open · esc close