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.



9
10
11
# File 'lib/markbridge/parsers/html/handlers/raw_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.



28
29
30
# File 'lib/markbridge/parsers/html/handlers/raw_handler.rb', line 28

def element_class
  @element_class
end

Instance Method Details

#process(element:, parent:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/markbridge/parsers/html/handlers/raw_handler.rb', line 13

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

  # Extract language from class or lang attribute
  language = element["class"] || element["lang"]

  ast_element = @element_class.new(language:)
  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