Class: LcpRuby::Display::Renderers::Markdown

Inherits:
BaseRenderer show all
Defined in:
lib/lcp_ruby/display/renderers/markdown.rb

Constant Summary collapse

ALLOWED_TAGS =
%w[
  p br strong em del s a ul ol li blockquote pre code h1 h2 h3 h4 h5 h6
  table thead tbody tfoot tr th td hr img input div span
].freeze
ALLOWED_ATTRIBUTES =

Note: ‘input` is kept for tasklist checkbox rendering (generated by Commonmarker tasklist extension). Raw HTML `<input>` from user source is blocked by omitting `unsafe: true` from Commonmarker options.

%w[href src alt title class type checked disabled].freeze

Instance Method Summary collapse

Instance Method Details

Returns:

  • (Boolean)


27
28
29
# File 'lib/lcp_ruby/display/renderers/markdown.rb', line 27

def link_producing?
  true
end

#render(value, options = {}, record: nil, view_context: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/lcp_ruby/display/renderers/markdown.rb', line 16

def render(value, options = {}, record: nil, view_context: nil)
  return nil if value.blank?

  html = Commonmarker.to_html(value.to_s, options: {
    extension: { table: true, tasklist: true, strikethrough: true, autolink: true }
  })
  view_context.(:div,
    view_context.sanitize(html, tags: ALLOWED_TAGS, attributes: ALLOWED_ATTRIBUTES),
    class: "lcp-markdown")
end