Class: Marko::Parser::Source
- Inherits:
-
Object
- Object
- Marko::Parser::Source
- Defined in:
- lib/marko/parser/source.rb
Overview
Source parser
Instance Method Summary collapse
-
#initialize ⇒ Source
constructor
A new instance of Source.
- #parse(markups) ⇒ Array<Model::Topic, ParserError>
Constructor Details
Instance Method Details
#parse(markups) ⇒ Array<Model::Topic, ParserError>
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 45 46 47 48 |
# File 'lib/marko/parser/source.rb', line 15 def parse(markups) results = markups.map do |e| begin @topic.parse(e) rescue => ex puts ex. Marko::ParserError.new(ex., e.filename, e.lineno, e.content) end end errors = results.reject{ it.is_a?(Model::Topic) } topics = results.select{ it.is_a?(Model::Topic) } adjusted = [] topics.each do |e| if e.markup_level == 1 adjusted << e next end finder = proc{ it.markup_level == e.markup_level - 1 } parent = adjusted.last&.select(&finder)&.last unless parent errors << Marko::ParserError.new('wrong header level', e.markup_filename, e.markup_lineno, e.markup_content) next end parent.add(e) end adjusted + errors end |