Class: AdminSuite::MarkdownRenderer
- Inherits:
-
Object
- Object
- AdminSuite::MarkdownRenderer
- Defined in:
- lib/admin_suite/markdown_renderer.rb
Overview
MarkdownRenderer converts markdown text into safe HTML with syntax highlighting.
Uses Redcarpet for markdown parsing, Rouge for syntax highlighting, and extracts a table of contents from headings.
Defined Under Namespace
Classes: HtmlRenderer
Instance Attribute Summary collapse
-
#markdown ⇒ Object
readonly
Returns the value of attribute markdown.
Class Method Summary collapse
- .markdown_extensions ⇒ Object
- .render(text) ⇒ ActiveSupport::SafeBuffer
- .render_with_toc(text) ⇒ Hash{Symbol=>Object}
Instance Method Summary collapse
-
#initialize(markdown) ⇒ MarkdownRenderer
constructor
A new instance of MarkdownRenderer.
- #render ⇒ Hash{Symbol=>Object}
Constructor Details
#initialize(markdown) ⇒ MarkdownRenderer
Returns a new instance of MarkdownRenderer.
15 16 17 |
# File 'lib/admin_suite/markdown_renderer.rb', line 15 def initialize(markdown) @markdown = markdown.to_s end |
Instance Attribute Details
#markdown ⇒ Object (readonly)
Returns the value of attribute markdown.
13 14 15 |
# File 'lib/admin_suite/markdown_renderer.rb', line 13 def markdown @markdown end |
Class Method Details
.markdown_extensions ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/admin_suite/markdown_renderer.rb', line 49 def self.markdown_extensions { autolink: true, tables: true, fenced_code_blocks: true, strikethrough: true, highlight: true, superscript: true, underline: true, no_intra_emphasis: true, space_after_headers: true, lax_spacing: true } end |
.render(text) ⇒ ActiveSupport::SafeBuffer
32 33 34 35 36 |
# File 'lib/admin_suite/markdown_renderer.rb', line 32 def self.render(text) renderer = HtmlRenderer.new md = Redcarpet::Markdown.new(renderer, markdown_extensions) md.render(text.to_s).html_safe end |
.render_with_toc(text) ⇒ Hash{Symbol=>Object}
40 41 42 43 44 45 |
# File 'lib/admin_suite/markdown_renderer.rb', line 40 def self.render_with_toc(text) renderer = HtmlRenderer.new md = Redcarpet::Markdown.new(renderer, markdown_extensions) html = md.render(text.to_s).html_safe { html: html, toc: renderer.toc_items } end |
Instance Method Details
#render ⇒ Hash{Symbol=>Object}
20 21 22 23 24 25 26 27 28 |
# File 'lib/admin_suite/markdown_renderer.rb', line 20 def render result = self.class.render_with_toc(markdown) { html: result[:html], toc: result[:toc], reading_time_minutes: reading_time_minutes } end |