Class: Markbridge::Parsers::MediaWiki::Parser
- Inherits:
-
Object
- Object
- Markbridge::Parsers::MediaWiki::Parser
- Defined in:
- lib/markbridge/parsers/media_wiki/parser.rb
Overview
Parses MediaWiki wikitext into an AST.
Supports:
-
Bold (”‘), italic (”), bold italic (””’)
-
Headings (= through ======)
-
Unordered lists (* / ** / ***)
-
Ordered lists (# / ## / ###)
-
Horizontal rules (—-)
-
Internal links ([[target]] / [[target|display]])
-
External links ([url text])
-
Preformatted text (lines starting with a space)
-
Tables ({| … |})
-
HTML tags: <nowiki>, <code>, <pre>,
, <s>, <del>, <u>, <ins>, <sup>, <sub>
Instance Attribute Summary collapse
-
#unknown_tags ⇒ Hash{String => Integer}
readonly
Tag-name → occurrence count for inline HTML-like tags whose names are not registered.
Instance Method Summary collapse
-
#initialize(handlers: nil) {|InlineTagRegistry| ... } ⇒ Parser
constructor
A new instance of Parser.
-
#parse(input) ⇒ AST::Document
Parse MediaWiki wikitext into an AST Document.
Constructor Details
#initialize(handlers: nil) {|InlineTagRegistry| ... } ⇒ Parser
Returns a new instance of Parser.
33 34 35 36 37 38 |
# File 'lib/markbridge/parsers/media_wiki/parser.rb', line 33 def initialize(handlers: nil, &block) # InlineParser falls back to InlineTagRegistry.default when this is # nil, so we don't need to materialise it here. @handlers = block_given? ? InlineTagRegistry.build_from_default(&block) : handlers @unknown_tags = Hash.new(0) end |
Instance Attribute Details
#unknown_tags ⇒ Hash{String => Integer} (readonly)
Returns tag-name → occurrence count for inline HTML-like tags whose names are not registered. Reset at the start of every #parse call.
27 28 29 |
# File 'lib/markbridge/parsers/media_wiki/parser.rb', line 27 def @unknown_tags end |
Instance Method Details
#parse(input) ⇒ AST::Document
Parse MediaWiki wikitext into an AST Document.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/markbridge/parsers/media_wiki/parser.rb', line 44 def parse(input) normalized = normalize_line_endings(input) lines = normalized.split("\n") @unknown_tags.clear @document = AST::Document.new @inline_parser = InlineParser.new(handlers: @handlers, unknown_tags: @unknown_tags) @list_stack = [] process_lines(lines) @document end |