Class: Markbridge::Parsers::BBCode::Handlers::ListHandler
- Inherits:
-
BaseHandler
- Object
- BaseHandler
- Markbridge::Parsers::BBCode::Handlers::ListHandler
- Defined in:
- lib/markbridge/parsers/bbcode/handlers/list_handler.rb
Overview
Handler for list tags (list, ul, ol, etc.)
Instance Attribute Summary collapse
-
#element_class ⇒ Object
readonly
Returns the value of attribute element_class.
Instance Method Summary collapse
-
#initialize ⇒ ListHandler
constructor
A new instance of ListHandler.
- #on_close(token:, context:, registry:, tokens: nil) ⇒ Object
- #on_open(token:, context:, registry:, tokens: nil) ⇒ Object
Methods inherited from BaseHandler
Constructor Details
#initialize ⇒ ListHandler
Returns a new instance of ListHandler.
9 10 11 |
# File 'lib/markbridge/parsers/bbcode/handlers/list_handler.rb', line 9 def initialize @element_class = AST::List end |
Instance Attribute Details
#element_class ⇒ Object (readonly)
Returns the value of attribute element_class.
31 32 33 |
# File 'lib/markbridge/parsers/bbcode/handlers/list_handler.rb', line 31 def element_class @element_class end |
Instance Method Details
#on_close(token:, context:, registry:, tokens: nil) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/markbridge/parsers/bbcode/handlers/list_handler.rb', line 23 def on_close(token:, context:, registry:, tokens: nil) # Auto-close open list item before closing list context.pop if context.current.is_a?(AST::ListItem) # Then use default closing behavior super end |
#on_open(token:, context:, registry:, tokens: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/markbridge/parsers/bbcode/handlers/list_handler.rb', line 13 def on_open(token:, context:, registry:, tokens: nil) # Check if ordered: explicit ol/olist tag, or type=1, or option=1 ordered = %w[ol olist].include?(token.tag) || token.attrs[:type] == "1" || token.attrs[:option] == "1" element = AST::List.new(ordered:) context.push(element, token:) end |