Class: Markbridge::Parsers::MediaWiki::InlineTagRegistry
- Inherits:
-
Object
- Object
- Markbridge::Parsers::MediaWiki::InlineTagRegistry
- Defined in:
- lib/markbridge/parsers/media_wiki/inline_tag_registry.rb
Overview
Registry of inline HTML-like tag handlers for the MediaWiki parser.
Supports three tag types:
- :raw - content is preserved verbatim (e.g.,
,) - :formatting - content is parsed for inline wiki markup (e.g.,
, ) - :self_closing - no content, produces a leaf AST node (e.g.,
)
Defined Under Namespace
Classes: Entry
Class Method Summary collapse
-
.build_from_default {|InlineTagRegistry| ... } ⇒ InlineTagRegistry
Build a registry from the default with optional customization.
-
.default ⇒ InlineTagRegistry
Create the default registry with standard MediaWiki inline tags.
-
.shared_default ⇒ InlineTagRegistry
Shared, deep-frozen default registry for the no-customization fast path.
Instance Method Summary collapse
-
#[](tag_name) ⇒ Entry?
Look up a tag entry by name.
-
#freeze ⇒ Object
Freeze the registry together with its internal Hash so that registration on a shared instance fails loudly instead of silently mutating state visible to every parser.
-
#initialize ⇒ InlineTagRegistry
constructor
A new instance of InlineTagRegistry.
-
#known?(tag_name) ⇒ Boolean
Check if a tag name is registered.
-
#register(tag_name, type, element_class) ⇒ self
Register a handler for an inline HTML-like tag.
Constructor Details
#initialize ⇒ InlineTagRegistry
Returns a new instance of InlineTagRegistry.
26 27 28 |
# File 'lib/markbridge/parsers/media_wiki/inline_tag_registry.rb', line 26 def initialize @entries = {} end |
Class Method Details
.build_from_default {|InlineTagRegistry| ... } ⇒ InlineTagRegistry
Build a registry from the default with optional customization.
89 90 91 92 93 |
# File 'lib/markbridge/parsers/media_wiki/inline_tag_registry.rb', line 89 def self.build_from_default registry = default yield(registry) if block_given? registry end |
.default ⇒ InlineTagRegistry
Create the default registry with standard MediaWiki inline tags.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/markbridge/parsers/media_wiki/inline_tag_registry.rb', line 65 def self.default registry = new # Raw tags -content preserved verbatim, not parsed for wiki markup registry.register("nowiki", :raw, nil) registry.register("code", :raw, AST::Code) registry.register("pre", :raw, AST::Code) # Formatting tags -content parsed for inline wiki markup registry.register("s", :formatting, AST::Strikethrough) registry.register("del", :formatting, AST::Strikethrough) registry.register("u", :formatting, AST::Underline) registry.register("ins", :formatting, AST::Underline) registry.register("sup", :formatting, AST::Superscript) registry.register("sub", :formatting, AST::Subscript) # Self-closing tags -produce a leaf node, no content registry.register("br", :self_closing, AST::LineBreak) end |
.shared_default ⇒ InlineTagRegistry
Shared, deep-frozen default registry for the no-customization
fast path. Built once per process; Markbridge::Parsers::MediaWiki::InlineParser falls back to
it when no handlers: are given, skipping the full registry
construction on every parse. Entries are immutable Data objects,
so sharing is safe across parsers and threads.
102 103 104 |
# File 'lib/markbridge/parsers/media_wiki/inline_tag_registry.rb', line 102 def self.shared_default @shared_default ||= default.freeze end |
Instance Method Details
#[](tag_name) ⇒ Entry?
Look up a tag entry by name.
46 47 48 49 50 51 52 |
# File 'lib/markbridge/parsers/media_wiki/inline_tag_registry.rb', line 46 def [](tag_name) # Keys are always downcased and the inline parser downcases tag # names before lookup, so the fetch hits directly on the hot # path; the block normalizes only mixed-case lookups instead of # allocating a downcased copy per probe. @entries.fetch(tag_name) { @entries[tag_name.downcase] } end |
#freeze ⇒ Object
Freeze the registry together with its internal Hash so that registration on a shared instance fails loudly instead of silently mutating state visible to every parser.
109 110 111 112 |
# File 'lib/markbridge/parsers/media_wiki/inline_tag_registry.rb', line 109 def freeze @entries.freeze super end |
#known?(tag_name) ⇒ Boolean
Check if a tag name is registered.
58 59 60 |
# File 'lib/markbridge/parsers/media_wiki/inline_tag_registry.rb', line 58 def known?(tag_name) @entries.key?(tag_name.downcase) end |
#register(tag_name, type, element_class) ⇒ self
Register a handler for an inline HTML-like tag.
36 37 38 39 40 |
# File 'lib/markbridge/parsers/media_wiki/inline_tag_registry.rb', line 36 def register(tag_name, type, element_class) validate_type!(type) @entries[tag_name.downcase] = Entry.new(type:, element_class:) self end |