Module: ContentfulRails::MarkdownHelper
- Defined in:
- app/helpers/contentful_rails/markdown_helper.rb
Overview
Custom Redcarpet wrapper with opinionated defaults.
Instance Method Summary collapse
-
#parse_markdown(markdown_string, renderer_options: {}, markdown_options: {}, image_options: {}) ⇒ Object
Return HTML which is passed through the Redcarpet markdown processor, using a custom renderer so that we can manipulate images using contentful’s URL-based API.
Instance Method Details
#parse_markdown(markdown_string, renderer_options: {}, markdown_options: {}, image_options: {}) ⇒ Object
Return HTML which is passed through the Redcarpet markdown processor, using a custom renderer so that we can manipulate images using contentful’s URL-based API. NOTE that this is super-permissive out of the box. Set options to suit when you call the method.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/helpers/contentful_rails/markdown_helper.rb', line 11 def parse_markdown(markdown_string, renderer_options: {}, markdown_options: {}, image_options: {}) markdown_string ||= '' markdown_opts = { no_intr_emphasis: true, tables: true, fenced_code_blocks: true, autolink: true, disable_indented_code_blocks: true, strikethrough: true, lax_spacing: true, space_after_headers: false, superscript: true, underline: true, highlight: true, footnotes: true }.merge() renderer_opts = { filter_html: false, # we want to allow HTML in the markdown blocks no_images: false, no_links: false, no_styles: false, escape_html: false, safe_links_only: false, with_toc_data: true, hard_wrap: true, xhtml: false, prettify: false, link_attributes: {}, image_options: }.merge() renderer = ContentfulRails::MarkdownRenderer.new(renderer_opts) markdown = Redcarpet::Markdown.new(renderer, markdown_opts) markdown.render(markdown_string).html_safe end |