instance method to_markdown

Ruby on Rails edge

Since edge

Signature

to_markdown(attachment_links: false)

Returns a Markdown version of the markup contained by the content.

content = ActionText::Content.new("<h1>Funny times!</h1>")
content.to_markdown # => "# Funny times!"

content = ActionText::Content.new("<p>Hello <strong>world</strong></p>")
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: that the returned string is not HTML safe and should not be rendered in browsers without additional sanitization.

Parameters

attachment_links key = false
Source
# File actiontext/lib/action_text/content.rb, line 150
    def to_markdown(attachment_links: false)
      render_attachments(with_full_attributes: false) { |attachment|
        ActionText::MarkdownConversion.render_attachment(attachment, attachment_links: attachment_links)
      }.fragment.to_markdown
    end

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

Defined in ActionText::Content

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