Class: Markbridge::Parsers::BBCode::ClosingStrategies::Base
- Inherits:
-
Object
- Object
- Markbridge::Parsers::BBCode::ClosingStrategies::Base
- Defined in:
- lib/markbridge/parsers/bbcode/closing_strategies/base.rb
Direct Known Subclasses
Instance Method Summary collapse
- #handle_close(token:, context:, registry:, tokens: nil) ⇒ Object
-
#initialize(reconciler) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(reconciler) ⇒ Base
Returns a new instance of Base.
7 8 9 |
# File 'lib/markbridge/parsers/bbcode/closing_strategies/base.rb', line 7 def initialize(reconciler) @reconciler = reconciler end |
Instance Method Details
#handle_close(token:, context:, registry:, tokens: nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/markbridge/parsers/bbcode/closing_strategies/base.rb', line 11 def handle_close(token:, context:, registry:, tokens: nil) return unless context.current.is_a?(AST::Element) current_handler = registry.handler_for_element(context.current) closing_handler = registry[token.tag] if current_handler == closing_handler context.pop elsif try_reorder(context:, tokens:, closing_handler:) # Reordering handled elsif @reconciler.try_auto_close(handler: closing_handler, context:) # Auto-close succeeded else context.add_child(AST::Text.new(token.source)) end end |