Class: Markbridge::Parsers::BBCode::Handlers::TableRowHandler

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

Overview

Handler for table row tags (tr)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseHandler

#auto_closeable?

Constructor Details

#initializeTableRowHandler

Returns a new instance of TableRowHandler.



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

def initialize
  @element_class = AST::TableRow
end

Instance Attribute Details

#element_classObject (readonly)

Returns the value of attribute element_class.



30
31
32
# File 'lib/markbridge/parsers/bbcode/handlers/table_row_handler.rb', line 30

def element_class
  @element_class
end

Instance Method Details

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



23
24
25
26
27
28
# File 'lib/markbridge/parsers/bbcode/handlers/table_row_handler.rb', line 23

def on_close(token:, context:, registry:, tokens: nil)
  # Auto-close open cell before closing row
  context.pop if context.current.is_a?(AST::TableCell)

  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/table_row_handler.rb', line 13

def on_open(token:, context:, registry:, tokens: nil)
  # Auto-close open cell before starting new row
  context.pop if context.current.is_a?(AST::TableCell)
  # Auto-close previous row if still open
  context.pop if context.current.is_a?(AST::TableRow)

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