Class: Markbridge::Parsers::BBCode::Handlers::ListHandler

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

Overview

Handler for list tags (list, ul, ol, etc.)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseHandler

#auto_closeable?

Constructor Details

#initializeListHandler

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_classObject (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