class Mato::Processor

Attributes

config[R]

@return [Mato::Config]

Public Class Methods

new(config) click to toggle source
# File lib/mato/processor.rb, line 13
def initialize(config)
  @config = config
end

Public Instance Methods

convert(content, flavor:) click to toggle source
# File lib/mato/processor.rb, line 63
def convert(content, flavor:)
  Mato::Converter.new(self, content, flavor).run
end
parse_html(html) click to toggle source

@param [String] html @return [Nokogiri::HTML4::DocumentFragment]

# File lib/mato/processor.rb, line 59
def parse_html(html)
  config.html_parser.parse(html)
end
parse_markdown(text) click to toggle source

@param [String] text @return [CommonMarker::Node]

# File lib/mato/processor.rb, line 47
def parse_markdown(text)
  config.markdown_parser.render_doc(text, config.markdown_parse_options, config.markdown_extensions)
end
process(input) click to toggle source

@param [String] input @return [Mato::Document]

# File lib/mato/processor.rb, line 19
def process(input)
  text = input.dup

  config.text_filters.each do |filter|
    # A text filter returns a mutated text
    text = filter.call(text)
  end

  markdown_node = parse_markdown(text)

  config.markdown_filters.each do |filter|
    # A markdown filter mutates the argument
    filter.call(markdown_node)
  end

  html = render_to_html(markdown_node)
  doc = parse_html(html)

  config.html_filters.each do |filter|
    # An HTML filter mutates the argument
    filter.call(doc)
  end

  config.document_factory.new(doc.freeze)
end
render_to_html(markdown_node) click to toggle source

@param [CommonMarker::Node] markdown_node @return [String]

# File lib/mato/processor.rb, line 53
def render_to_html(markdown_node)
  markdown_node.to_html(config.markdown_render_options)
end