Class: Middleman::Renderers::CommonmarkerTemplate
- Inherits:
-
Tilt::Template
- Object
- Tilt::Template
- Middleman::Renderers::CommonmarkerTemplate
- Defined in:
- lib/middleman-commonmarker/commonmarker_template.rb
Overview
Tilt template that renders Markdown with commonmarker, walking the AST to transform image and link nodes through Middleman’s helpers.
Constant Summary collapse
- DEFAULT_PARSE_OPTIONS =
{smart: false, default_info_string: nil}.freeze
- DEFAULT_RENDER_OPTIONS =
{hardbreaks: false, github_pre_lang: false, width: 80, unsafe: false, escape: false, sourcepos: false}.freeze
- DEFAULT_EXTENSION_OPTIONS =
{strikethrough: false, tagfilter: false, table: false, autolink: false, tasklist: false, superscript: false, header_ids: nil, footnotes: false, description_lists: false, front_matter_delimiter: nil, shortcodes: false}.freeze
Instance Method Summary collapse
Instance Method Details
#evaluate(scope, _locals, &_block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/middleman-commonmarker/commonmarker_template.rb', line 27 def evaluate(scope, _locals, &_block) self.class.scope = @context || scope doc = ::Commonmarker.parse(data, options: @commonmarker_options) if self.class.scope doc.walk do |node| case node.type when :image then transform_image_node(node) when :link then transform_link_node(node) end end # Force unsafe so the injected raw <img> HTML is emitted. return doc.to_html(options: ) end doc.to_html(options: @commonmarker_options) end |
#prepare ⇒ Object
22 23 24 25 |
# File 'lib/middleman-commonmarker/commonmarker_template.rb', line 22 def prepare @context = .delete(:context) @commonmarker_options = end |