Class: Markbridge::AST::MarkdownText

Inherits:
Node
  • Object
show all
Defined in:
lib/markbridge/ast/markdown_text.rb

Overview

Represents a text node containing pre-formatted Markdown content. Unlike AST::Text, this content will NOT be escaped by the renderer. Use this when you want to pass through Markdown formatting as-is.

Examples:

Creating a markdown text node

text = AST::MarkdownText.new("**bold** and *italic*")

Use case: preserving user-provided Markdown

# When parsing HTML or other formats that allow embedded Markdown
element << AST::MarkdownText.new(markdown_content)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ MarkdownText

Create a new markdown text node with the given content.

Parameters:

  • text (String)

    the markdown text content



22
23
24
# File 'lib/markbridge/ast/markdown_text.rb', line 22

def initialize(text)
  @text = +text
end

Instance Attribute Details

#textString (readonly)

Returns the markdown text content of this node.

Returns:

  • (String)

    the markdown text content of this node



17
18
19
# File 'lib/markbridge/ast/markdown_text.rb', line 17

def text
  @text
end

Instance Method Details

#merge(other) ⇒ MarkdownText

Merge another markdown text node’s content into this one. This mutates the current text node by appending the other’s text.

Parameters:

Returns:



31
32
33
34
# File 'lib/markbridge/ast/markdown_text.rb', line 31

def merge(other)
  @text << other.text
  self
end