Class: Markbridge::Parsers::BBCode::Handlers::RawHandler
- Inherits:
-
BaseHandler
- Object
- BaseHandler
- Markbridge::Parsers::BBCode::Handlers::RawHandler
- Defined in:
- lib/markbridge/parsers/bbcode/handlers/raw_handler.rb
Overview
Handler for raw/preformatted tags that preserve content as-is Uses RawContentCollector strategy to consume tokens until closing tag without parsing nested BBCode
Direct Known Subclasses
Instance Attribute Summary collapse
-
#element_class ⇒ Object
readonly
Returns the value of attribute element_class.
Instance Method Summary collapse
-
#initialize(element_class, collector: RawContentCollector.new) ⇒ RawHandler
constructor
A new instance of RawHandler.
-
#on_close(token:, context:, registry:, tokens: nil) ⇒ Object
RawHandler doesn’t push to stack, so on_close should do nothing.
- #on_open(token:, context:, registry:, tokens:) ⇒ Object
Methods inherited from BaseHandler
Constructor Details
#initialize(element_class, collector: RawContentCollector.new) ⇒ RawHandler
Returns a new instance of RawHandler.
11 12 13 14 |
# File 'lib/markbridge/parsers/bbcode/handlers/raw_handler.rb', line 11 def initialize(element_class, collector: RawContentCollector.new) @element_class = element_class @collector = collector end |
Instance Attribute Details
#element_class ⇒ Object (readonly)
Returns the value of attribute element_class.
34 35 36 |
# File 'lib/markbridge/parsers/bbcode/handlers/raw_handler.rb', line 34 def element_class @element_class end |
Instance Method Details
#on_close(token:, context:, registry:, tokens: nil) ⇒ Object
RawHandler doesn’t push to stack, so on_close should do nothing
27 28 29 30 31 32 |
# File 'lib/markbridge/parsers/bbcode/handlers/raw_handler.rb', line 27 def on_close(token:, context:, registry:, tokens: nil) # Raw content was already consumed by collector # Closing tag was consumed by collector, so this shouldn't be called # If it is called, treat as text context.add_child(AST::Text.new(token.source)) end |
#on_open(token:, context:, registry:, tokens:) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/markbridge/parsers/bbcode/handlers/raw_handler.rb', line 16 def on_open(token:, context:, registry:, tokens:) result = @collector.collect(token.tag, tokens) # Track unclosed raw tags for diagnostics context.mark_unclosed_raw!(token.tag) if result.unclosed? element = create_element(token:, content: result.content) context.add_child(element) end |