Class: Coradoc::Markdown::Document

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/markdown/model/document.rb

Overview

Document model representing a Markdown document.

The Document class is the main container for parsed Markdown content. It holds the document’s blocks (headings, paragraphs, lists, etc.).

Examples:

Create a new document

doc = Coradoc::Markdown::Document.new(
  blocks: [
    Coradoc::Markdown::Heading.new(level: 1, text: "My Document"),
    Coradoc::Markdown::Paragraph.new(text: "Hello World")
  ]
)

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

visit, #visit

Class Method Details

.from_ast(elements) ⇒ Object

Create a document from an array of blocks



43
44
45
# File 'lib/coradoc/markdown/model/document.rb', line 43

def self.from_ast(elements)
  new(blocks: elements)
end

Instance Method Details

#[](index) ⇒ Coradoc::Markdown::Base

Returns The block at the specified index.

Parameters:

  • index (Integer)

    The index of the block to retrieve

Returns:



32
33
34
# File 'lib/coradoc/markdown/model/document.rb', line 32

def [](index)
  blocks[index]
end

#[]=(index, value) ⇒ Object

Parameters:



38
39
40
# File 'lib/coradoc/markdown/model/document.rb', line 38

def []=(index, value)
  blocks[index] = value
end