Class: Marksmith::Renderer
- Inherits:
-
Object
- Object
- Marksmith::Renderer
- Defined in:
- app/models/marksmith/renderer.rb
Instance Method Summary collapse
-
#initialize(body:) ⇒ Renderer
constructor
A new instance of Renderer.
- #render ⇒ Object
- #render_commonmarker ⇒ Object
- #render_kramdown ⇒ Object
- #render_redcarpet ⇒ Object
Constructor Details
#initialize(body:) ⇒ Renderer
Returns a new instance of Renderer.
3 4 5 |
# File 'app/models/marksmith/renderer.rb', line 3 def initialize(body:) @body = body end |
Instance Method Details
#render ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'app/models/marksmith/renderer.rb', line 7 def render if Marksmith.configuration.parser == "commonmarker" render_commonmarker elsif Marksmith.configuration.parser == "kramdown" render_kramdown else render_redcarpet end end |
#render_commonmarker ⇒ Object
17 18 19 20 21 |
# File 'app/models/marksmith/renderer.rb', line 17 def render_commonmarker # commonmarker expects an utf-8 encoded string body = @body.to_s.dup.force_encoding("utf-8") Commonmarker.to_html(body) end |
#render_kramdown ⇒ Object
40 41 42 43 |
# File 'app/models/marksmith/renderer.rb', line 40 def render_kramdown body = @body.to_s.dup.force_encoding("utf-8") Kramdown::Document.new(body).to_html end |
#render_redcarpet ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/marksmith/renderer.rb', line 23 def render_redcarpet ::Redcarpet::Markdown.new( ::Redcarpet::Render::HTML, tables: true, lax_spacing: true, fenced_code_blocks: true, space_after_headers: true, hard_wrap: true, autolink: true, strikethrough: true, underline: true, highlight: true, quote: true, with_toc_data: true ).render(@body) end |