Class: Markbridge::Parsers::BBCode::ClosingStrategies::Reordering
- Defined in:
- lib/markbridge/parsers/bbcode/closing_strategies/reordering.rb
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Markbridge::Parsers::BBCode::ClosingStrategies::Base
Instance Method Details
#handle_close(token:, context:, registry:, tokens: nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/markbridge/parsers/bbcode/closing_strategies/reordering.rb', line 7 def handle_close(token:, context:, registry:, tokens: nil) closing_handler = registry[token.tag] # Fast path: when the current element matches the closing tag, # pop and return. try_reorder/try_reopen are reconciliation # strategies that only make sense when the close is mismatched; # running them eagerly here costs a full elements_from_current # walk plus two sort_by/compare passes on every close token, # which dominates runtime for well-formed input. if registry.handler_for_element(context.current) == closing_handler context.pop return end return if tokens && @reconciler.try_reorder(handler: closing_handler, tokens:, context:) return if @reconciler.try_reopen(handler: closing_handler, context:, tokens:) super end |