Module: ContentfulRails::MarkdownHelper
- Defined in:
- app/helpers/contentful_rails/markdown_helper.rb
Instance Method Summary collapse
-
#parse_markdown(markdown_string, renderer_options: {}, markdown_options: {}, image_options: {}) ⇒ Object
Return HTML which is passed through the Redcloth 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 Redcloth 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.
8 9 10 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 |
# File 'app/helpers/contentful_rails/markdown_helper.rb', line 8 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 |