Class: Markbridge::Parsers::BBCode::Handlers::SelfClosingHandler

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

Overview

Handler for self-closing tags (br, hr, etc.)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseHandler

#auto_closeable?

Constructor Details

#initialize(element_class) ⇒ SelfClosingHandler

Returns a new instance of SelfClosingHandler.



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

def initialize(element_class)
  @element_class = element_class
end

Instance Attribute Details

#element_classObject (readonly)

Returns the value of attribute element_class.



23
24
25
# File 'lib/markbridge/parsers/bbcode/handlers/self_closing_handler.rb', line 23

def element_class
  @element_class
end

Instance Method Details

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



18
19
20
21
# File 'lib/markbridge/parsers/bbcode/handlers/self_closing_handler.rb', line 18

def on_close(token:, context:, registry:, tokens: nil)
  # Treat unexpected closing tag as text
  context.add_child(AST::Text.new(token.source))
end

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



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

def on_open(token:, context:, registry:, tokens: nil)
  element = @element_class.new
  context.add_child(element)
end