Class: Decidim::Comments::MarkdownRender
- Inherits:
-
Redcarpet::Render::Safe
- Object
- Redcarpet::Render::Safe
- Decidim::Comments::MarkdownRender
- Defined in:
- decidim-comments/lib/decidim/comments/markdown.rb
Overview
Custom markdown renderer for Comments
Instance Method Summary collapse
-
#block_quote(quote) ⇒ Object
renders quotes with a custom css class.
-
#emphasis(text) ⇒ Object
Prevents underscores to be replaced with <em> tags in comments, such as github.com/org/module_with_underscores or within words such as “Look for comment_maximum_length in the code”.
-
#header(title, _level) ⇒ Object
removes header tags in comments.
-
#initialize(extensions = {}) ⇒ MarkdownRender
constructor
A new instance of MarkdownRender.
-
#paragraph(text) ⇒ Object
prevents empty <p/> in comments.
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 |
#emphasis(text) ⇒ Object
Prevents underscores to be replaced with <em> tags in comments, such as github.com/org/module_with_underscores or within words such as “Look for comment_maximum_length in the code”. The ‘no_intra_emphasis` option for Redcarpet does not apparently work for this renderer.
Related issues: github.com/vmg/redcarpet/issues/402 github.com/vmg/redcarpet/issues/427
62 63 64 |
# File 'decidim-comments/lib/decidim/comments/markdown.rb', line 62 def emphasis(text) "_#{text}_" 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 |