Module: AsciidoctorVaped::Parser::Inline
- Defined in:
- lib/asciidoctor_vaped/parser/inline.rb
Constant Summary collapse
- PATTERNS =
[ Inlines::Link, Inlines::Url, Inlines::Strong, Inlines::Emphasis, Inlines::Monospace ].freeze
Class Method Summary collapse
- .container(context, text, attributes = {}) ⇒ Object
- .next_token(text) ⇒ Object
- .parse(text) ⇒ Object
- .parse_until_done(text) ⇒ Object
- .text_node(text) ⇒ Object
Class Method Details
.container(context, text, attributes = {}) ⇒ Object
55 56 57 |
# File 'lib/asciidoctor_vaped/parser/inline.rb', line 55 def container(context, text, attributes = {}) AST::Element.new(context, attributes:, children: parse(text)) end |
.next_token(text) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/asciidoctor_vaped/parser/inline.rb', line 46 def next_token(text) PATTERNS.each_with_index.filter_map do |pattern, priority| match = pattern.match(text) [match.begin(0), priority, match.end(0), pattern] if match end.min_by { |start, priority, _finish, _pattern| [start, priority] }&.then do |start, _priority, finish, pattern| [start, finish, pattern] end end |
.parse(text) ⇒ Object
22 23 24 |
# File 'lib/asciidoctor_vaped/parser/inline.rb', line 22 def parse(text) parse_until_done(text.to_s) end |
.parse_until_done(text) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/asciidoctor_vaped/parser/inline.rb', line 30 def parse_until_done(text) nodes = [] until text.empty? token = next_token(text) return nodes << text_node(text) unless token start, finish, pattern = token nodes << text_node(text[0...start]) if start.positive? nodes << pattern.node(text[start...finish]) text = text[finish..] || "" end nodes end |