Class: HTMLPipeline::ConvertFilter::MarkdownFilter

Inherits:
HTMLPipeline::ConvertFilter show all
Defined in:
lib/html_pipeline/convert_filter/markdown_filter.rb

Overview

HTML Filter that converts Markdown text into HTML.

Context options:

:markdown[:parse] => Commonmarker parse options
:markdown[:render] => Commonmarker render options
:markdown[:extensions] => Commonmarker extensions options

Instance Attribute Summary

Attributes inherited from HTMLPipeline::ConvertFilter

#html, #text

Attributes inherited from Filter

#context, #result

Instance Method Summary collapse

Methods inherited from HTMLPipeline::ConvertFilter

call

Methods inherited from Filter

#base_url, call, #has_ancestor?, #needs, #validate

Constructor Details

#initialize(context: {}, result: {}) ⇒ MarkdownFilter

Returns a new instance of MarkdownFilter.



14
15
16
# File 'lib/html_pipeline/convert_filter/markdown_filter.rb', line 14

def initialize(context: {}, result: {})
  super
end

Instance Method Details

#call(text, context: @context) ⇒ Object

Convert Commonmark to HTML using the best available implementation.



19
20
21
22
23
# File 'lib/html_pipeline/convert_filter/markdown_filter.rb', line 19

def call(text, context: @context)
  options = context.fetch(:markdown, {})
  plugins = options.fetch(:plugins, {})
  Commonmarker.to_html(text, options: options, plugins: plugins).rstrip!
end