Class: Mato::Processor
- Inherits:
-
Object
- Object
- Mato::Processor
- Defined in:
- lib/mato/processor.rb
Instance Attribute Summary collapse
- #config ⇒ Mato::Config readonly
Instance Method Summary collapse
- #convert(content, flavor:) ⇒ Object
-
#initialize(config) ⇒ Processor
constructor
A new instance of Processor.
- #parse_html(html) ⇒ Nokogiri::HTML4::DocumentFragment
- #parse_markdown(text) ⇒ Commonmarker::Node
- #process(input) ⇒ Mato::Document
- #render_to_html(markdown_node) ⇒ String
Constructor Details
#initialize(config) ⇒ Processor
Returns a new instance of Processor.
13 14 15 |
# File 'lib/mato/processor.rb', line 13 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Mato::Config (readonly)
11 12 13 |
# File 'lib/mato/processor.rb', line 11 def config @config end |
Instance Method Details
#convert(content, flavor:) ⇒ Object
63 64 65 |
# File 'lib/mato/processor.rb', line 63 def convert(content, flavor:) Mato::Converter.new(self, content, flavor).run end |
#parse_html(html) ⇒ Nokogiri::HTML4::DocumentFragment
59 60 61 |
# File 'lib/mato/processor.rb', line 59 def parse_html(html) config.html_parser.parse(html) end |
#parse_markdown(text) ⇒ Commonmarker::Node
47 48 49 |
# File 'lib/mato/processor.rb', line 47 def parse_markdown(text) config.markdown_parser.parse(text, options: config.) end |
#process(input) ⇒ Mato::Document
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 |
# 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) ⇒ String
53 54 55 |
# File 'lib/mato/processor.rb', line 53 def render_to_html(markdown_node) markdown_node.to_html(options: config.) end |