instance method markdown_link

Ruby on Rails edge

Since edge

Signature

markdown_link(title, url, image: false)

Returns a Markdown link: [title](url).

Escapes metacharacters in title, and percent-encodes characters in url that would break the link syntax.

MarkdownConversion.markdown_link("photo", "https://example.com/photo_(large).png")
# => "[photo](https://example.com/photo_%28large%29.png)"

Pass image: true to produce an image link (![title](url)).

MarkdownConversion.markdown_link("photo", "https://example.com/photo.png", image: true)
# => "![photo](https://example.com/photo.png)"

If the URI scheme is not allowed (per Rails::HTML::Sanitizer.allowed_uri?), returns the escaped title wrapped in escaped brackets (\[title\]).

MarkdownConversion.markdown_link("click", "javascript:alert(1)")
# => "\\[click\\]"

Parameters

title req
url req
image key = false
Source
# File actiontext/lib/action_text/markdown_conversion.rb, line 79
    def markdown_link(title, url, image: false)
      if Rails::HTML::Sanitizer.allowed_uri?(url)
        "#{"!" if image}[#{escape_markdown_text(title)}](#{encode_href(url)})"
      else
        "\\[#{escape_markdown_text(title)}\\]"
      end
    end

Defined in actiontext/lib/action_text/markdown_conversion.rb line 79 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionText::MarkdownConversion

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close