diff --git a/config/initializers/markdown_template_handler.rb b/config/initializers/markdown_template_handler.rb index eb9b3f5..2d2615b 100644 --- a/config/initializers/markdown_template_handler.rb +++ b/config/initializers/markdown_template_handler.rb @@ -3,18 +3,27 @@ def self.erb @erb ||= ActionView::Template.registered_template_handler(:erb) end + def self.redcarpet_options + @options = { + space_after_headers: true, + fenced_code_blocks: true, + smartypants: true, + disable_indented_code_blocks: true, + prettify: true, + tables: true, + with_toc_data: true, + no_intra_emphasis: true, + autolink: true + } + end + + def self.markdown + @markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, redcarpet_options) + end + def self.call(template) compiled_source = erb.call(template) - "Redcarpet::Markdown.new(Redcarpet::Render::HTML, - no_intra_emphasis: true, - fenced_code_blocks: true, - space_after_headers: true, - smartypants: true, - disable_indented_code_blocks: true, - prettify: true, - tables: true, - with_toc_data: true, - autolink: true).render(begin;#{compiled_source};end).html_safe" + "#{markdown.render(compiled_source).inspect}.html_safe" end end