Class: Markbridge::Parsers::MediaWiki::InlineParser
- Inherits:
-
Object
- Object
- Markbridge::Parsers::MediaWiki::InlineParser
- Defined in:
- lib/markbridge/parsers/media_wiki/inline_parser.rb
Overview
Parses inline MediaWiki markup within a line of text. Handles bold (”‘), italic (”), links ([[…]]), external links ([…]), and HTML inline tags via an InlineTagRegistry.
Constant Summary collapse
- MAX_INLINE_DEPTH =
20
Instance Attribute Summary collapse
-
#unknown_tags ⇒ Hash{String => Integer}
readonly
Tag-name → occurrence count for HTML-like inline tags whose names are not registered.
Instance Method Summary collapse
-
#initialize(handlers: nil, depth: 0, unknown_tags: nil) ⇒ InlineParser
constructor
A new instance of InlineParser.
-
#parse(text, parent:) ⇒ Object
Parse inline markup and append resulting AST nodes to the parent element.
Constructor Details
#initialize(handlers: nil, depth: 0, unknown_tags: nil) ⇒ InlineParser
Returns a new instance of InlineParser.
24 25 26 27 28 |
# File 'lib/markbridge/parsers/media_wiki/inline_parser.rb', line 24 def initialize(handlers: nil, depth: 0, unknown_tags: nil) @registry = handlers || InlineTagRegistry.default @depth = depth @unknown_tags = || Hash.new(0) end |
Instance Attribute Details
#unknown_tags ⇒ Hash{String => Integer} (readonly)
Returns tag-name → occurrence count for HTML-like inline tags whose names are not registered. Shared with nested InlineParser instances so depth-recursive parses contribute to the same tally.
22 23 24 |
# File 'lib/markbridge/parsers/media_wiki/inline_parser.rb', line 22 def @unknown_tags end |
Instance Method Details
#parse(text, parent:) ⇒ Object
Parse inline markup and append resulting AST nodes to the parent element.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/markbridge/parsers/media_wiki/inline_parser.rb', line 34 def parse(text, parent:) @input = text @pos = 0 @length = text.length @parent = parent @text_buffer = +"" while @pos < @length char = @input[@pos] case char when "'" consecutive_apostrophes_at(@pos) >= 2 ? parse_bold_italic : append_literal(char) when "[" flush_text @input[@pos + 1] == "[" ? parse_internal_link : parse_external_link when "<" flush_text parse_html_tag else append_literal(char) end end flush_text end |