Class: Markbridge::Parsers::BBCode::Handlers::TableCellHandler

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

Overview

Handler for table cell tags (td, th)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseHandler

#auto_closeable?, #on_close

Constructor Details

#initializeTableCellHandler

Returns a new instance of TableCellHandler.



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

def initialize
  @element_class = AST::TableCell
end

Instance Attribute Details

#element_classObject (readonly)

Returns the value of attribute element_class.



21
22
23
# File 'lib/markbridge/parsers/bbcode/handlers/table_cell_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/table_cell_handler.rb', line 13

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

  element = AST::TableCell.new(header: token.tag == "th")
  context.push(element, token:)
end