Class: Markbridge::Parsers::TextFormatter::Handlers::SimpleHandler

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

Overview

Handler for simple XML elements that don’t require attributes

This handler creates an AST node of the specified class and processes all child elements. Use this for simple formatting tags like B, I, U, S.

Examples:

handler = SimpleHandler.new(AST::Bold)
registry.register("B", handler)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element_class) ⇒ SimpleHandler

Returns a new instance of SimpleHandler.

Parameters:

  • element_class (Class)

    the AST node class to instantiate



17
18
19
# File 'lib/markbridge/parsers/text_formatter/handlers/simple_handler.rb', line 17

def initialize(element_class)
  @element_class = element_class
end

Instance Attribute Details

#element_classObject (readonly)

Returns the value of attribute element_class.



32
33
34
# File 'lib/markbridge/parsers/text_formatter/handlers/simple_handler.rb', line 32

def element_class
  @element_class
end

Instance Method Details

#process(element:, parent:) ⇒ Object

Process the element by creating an AST node and processing children

Parameters:



24
25
26
27
28
29
30
# File 'lib/markbridge/parsers/text_formatter/handlers/simple_handler.rb', line 24

def process(element:, parent:)
  node = @element_class.new
  parent << node

  # Return node to signal: process children into this node
  node
end