Class: Markbridge::Parsers::BBCode::Handlers::TableHandler

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

Overview

Handler for table tags

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseHandler

#auto_closeable?

Constructor Details

#initializeTableHandler

Returns a new instance of TableHandler.



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

def initialize
  @element_class = AST::Table
end

Instance Attribute Details

#element_classObject (readonly)

Returns the value of attribute element_class.



27
28
29
# File 'lib/markbridge/parsers/bbcode/handlers/table_handler.rb', line 27

def element_class
  @element_class
end

Instance Method Details

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



18
19
20
21
22
23
24
25
# File 'lib/markbridge/parsers/bbcode/handlers/table_handler.rb', line 18

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

  super
end

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



13
14
15
16
# File 'lib/markbridge/parsers/bbcode/handlers/table_handler.rb', line 13

def on_open(token:, context:, registry:, tokens: nil)
  element = AST::Table.new
  context.push(element, token:)
end