instance method
markdown_link
Ruby on Rails edge
Since edgeSignature
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 ().
MarkdownConversion.markdown_link("photo", "https://example.com/photo.png", image: true)
# => ""
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
-
titlereq -
urlreq -
imagekey = 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