Class: Markbridge::Parsers::BBCode::Handlers::ListItemHandler

Inherits:
BaseHandler
  • Object
show all
Defined in:
lib/markbridge/parsers/bbcode/handlers/list_item_handler.rb

Overview

Handler for list item tags (*, li, .)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseHandler

#auto_closeable?, #on_close

Constructor Details

#initializeListItemHandler

Returns a new instance of ListItemHandler.



9
10
11
# File 'lib/markbridge/parsers/bbcode/handlers/list_item_handler.rb', line 9

def initialize
  @element_class = AST::ListItem
end

Instance Attribute Details

#element_classObject (readonly)

Returns the value of attribute element_class.



21
22
23
# File 'lib/markbridge/parsers/bbcode/handlers/list_item_handler.rb', line 21

def element_class
  @element_class
end

Instance Method Details

#on_open(token:, context:, registry:, tokens: nil) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/markbridge/parsers/bbcode/handlers/list_item_handler.rb', line 13

def on_open(token:, context:, registry:, tokens: nil)
  # Auto-close previous list item if opening a new one
  context.pop if context.current.is_a?(AST::ListItem)

  element = AST::ListItem.new
  context.push(element, token:)
end