Module: Parliament::Utils::Helpers::MarkdownHelper

Defined in:
lib/parliament/utils/helpers/markdown_helper.rb

Class Method Summary collapse

Class Method Details

.markdown(template) ⇒ Object

Uses redcarpet gem to convert markdown into HTML, with chosen HTML extensions Uses custom Parliament::Utils::Services::ParliamentMarkdownRenderer to override default autolink behaviour of redcarpet gem Uses custom Parliament::Utils::Services::ParliamentMarkdownScrubber to allow additional HTML tags and attributes



14
15
16
17
18
19
20
21
# File 'lib/parliament/utils/helpers/markdown_helper.rb', line 14

def self.markdown(template)
  parliament_renderer = Parliament::Utils::Services::ParliamentMarkdownRenderer
  parliament_scrubber = Parliament::Utils::Services::ParliamentMarkdownScrubber.new

  markdown = Redcarpet::Markdown.new(parliament_renderer, tables: true, autolink: true, lax_spacing: true)
  sanitized_template = ActionController::Base.helpers.sanitize(template, scrubber: parliament_scrubber)
  markdown.render(sanitized_template).html_safe
end