Class: Markbridge::Parsers::HTML::Handlers::RawHandler

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

Overview

Handler for raw/preformatted tags that preserve content as-is

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element_class) ⇒ RawHandler

Returns a new instance of RawHandler.



15
16
17
# File 'lib/markbridge/parsers/html/handlers/raw_handler.rb', line 15

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/html/handlers/raw_handler.rb', line 32

def element_class
  @element_class
end

Instance Method Details

#process(element:, parent:) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/markbridge/parsers/html/handlers/raw_handler.rb', line 19

def process(element:, parent:)
  # Get the inner text content
  content = element.inner_text

  ast_element =
    @element_class.new(language: language_for(element), block: block_for(element))
  ast_element << AST::Text.new(content) unless content.empty?
  parent << ast_element

  # Return nil to signal: don't process children (we handled content directly)
  nil
end