Class: Decidim::Comments::MarkdownRender

Inherits:
Redcarpet::Render::Safe
  • Object
show all
Defined in:
decidim-comments/lib/decidim/comments/markdown.rb

Overview

Custom markdown renderer for Comments

Instance Method Summary collapse

Constructor Details

#initialize(extensions = {}) ⇒ MarkdownRender

Returns a new instance of MarkdownRender.


25
26
27
28
29
30
31
32
33
34
35
# File 'decidim-comments/lib/decidim/comments/markdown.rb', line 25

def initialize(extensions = {})
  super({
    autolink: true,
    escape_html: false,
    filter_html: true,
    hard_wrap: true,
    lax_spacing: false,
    no_images: true,
    no_styles: true
  }.merge(extensions))
end

Instance Method Details

#block_quote(quote) ⇒ Object

renders quotes with a custom css class


38
39
40
# File 'decidim-comments/lib/decidim/comments/markdown.rb', line 38

def block_quote(quote)
  %(<blockquote class="comment__quote">#{quote}</blockquote>)
end

#header(title, _level) ⇒ Object

removes header tags in comments


43
44
45
# File 'decidim-comments/lib/decidim/comments/markdown.rb', line 43

def header(title, _level)
  title
end

#paragraph(text) ⇒ Object

prevents empty <p/> in comments


48
49
50
51
52
# File 'decidim-comments/lib/decidim/comments/markdown.rb', line 48

def paragraph(text)
  return if text.blank?

  "<p>#{text}</p>"
end