instance method
to_markdown
Ruby on Rails edge
Since edgeSignature
to_markdown(attachment_links: false)
Returns a Markdown version of the markup contained by the body attribute.
message = Message.create!(content: "<h1>Funny times!</h1>")
message.content.to_markdown # => "# Funny times!"
message = Message.create!(content: "<p>Hello <strong>world</strong></p>")
message.content.to_markdown # => "Hello **world**"
When attachment_links is true, ActiveStorage blob attachments generate Markdown links with URLs. This requires a rendering context (e.g., controller or mailer action) and will raise if URL generation fails.
NOTE: The returned string is not HTML safe and should not be rendered in browsers without additional sanitization.
NOTE: Links with unsafe protocols like javascript: are stripped from the returned Markdown on a best-effort basis. Markdown renderers do not all parse Markdown the same way, so HTML rendered from the Markdown should not be displayed in browsers without additional sanitization.
Parameters
-
attachment_linkskey = false
Source
# File actiontext/app/models/action_text/rich_text.rb, line 96
def to_markdown(attachment_links: false)
body&.to_markdown(attachment_links: attachment_links).to_s
end
Defined in actiontext/app/models/action_text/rich_text.rb line 96
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionText::RichText