Purpose

This page explains the Ceradoc Document Model - the Ruby object representation of AsciiDoc documents. You’ll learn about the model classes, their relationships, and how to work with them programmatically.

Overview

The Document Model represents AsciiDoc structure as Ruby objects. Every element in an AsciiDoc document has a corresponding model class. All model classes inherit from Ceradoc::Model::Base.

Core Model Classes

Document

The root container for all document content.

Ceradoc::Model::Document
  ├── header: Header
  ├── document_attributes: DocumentAttributes
  └── sections: Array<Section>
doc = Ceradoc.parse("= Title\n\nContent")
doc.class  # => Ceradoc::Model::Document

Document metadata including title, author, and revision information.

Ceradoc::Model::Header
  ├── title: String
  ├── author: Array<Author>
  └── revision: Revision
doc.header.title          # Document title
doc.header.author&.first  # First author, if present
doc.header.revision       # Revision information

Section

Hierarchical sections organizing document content.

Ceradoc::Model::Section
  ├── title: Title
  ├── sections: Array<Section>  # Nested sections
  ├── paragraphs: Array<Paragraph>
  └── blocks: Array<Block>
section = Ceradoc::Model::Section.new
section.title = Ceradoc::Model::Title.new
section.title.level_int = 2
section.title.content = ["Chapter 1"]

# Add paragraphs
para = Ceradoc::Model::Paragraph.new
para.content = [Ceradoc::Model::TextElement.new("Content here")]
section.blocks = [para]

Title

Section or block title with level information.

Ceradoc::Model::Title
  ├── level_int: Integer
  └── content: Array<String>

Paragraph

Text paragraph containing inline elements.

Ceradoc::Model::Paragraph
  ├── content: Array<TextElement | Inline>
  └── attributes: AttributeList
para = Ceradoc::Model::Paragraph.new

# Add mixed content
para.content = [
  Ceradoc::Model::TextElement.new("Regular text"),
  Ceradoc::Model::Inline::Bold.new,
  Ceradoc::Model::Inline::Link.new(path: "https://example.com"),
]

# Add attributes
para.attributes = Ceradoc::Model::AttributeList.new
para.attributes.add_named("id", "para1")

Block Classes

Blocks are delimited content sections like code listings and quotes.

Block::Core

Base class for all delimited blocks.

Ceradoc::Model::Block::Core
  ├── delimiter_char: String
  ├── delimiter_len: Integer
  ├── lines: Array<String>
  └── attributes: AttributeList

Block Types

  • Block::Listing - Code listing block

  • Block::Literal - Literal text block

  • Block::Example - Example block

  • Block::Quote - Quoted text block

  • Block::Pass - Pass-through content

# Create a listing block
listing = Ceradoc::Model::Block::Listing.new
listing.lines = ["def hello", "  puts 'world'", "end"]
listing.attributes = Ceradoc::Model::AttributeList.new
listing.attributes.add_positional("ruby")

List Classes

Lists organize items hierarchically.

List::Core

Base class for all list types.

Ceradoc::Model::List::Core
  └── items: Array<ListItem>

List Types

  • List::Unordered - Bulleted list (*)

  • List::Ordered - Numbered list (.)

  • List::Definition - Definition list (::)

# Unordered list
list = Ceradoc::Model::List::Unordered.new
item = Ceradoc::Model::ListItem.new
item.content = [Ceradoc::Model::TextElement.new("First item")]
list.items << item

# Ordered list
ordered = Ceradoc::Model::List::Ordered.new
item = Ceradoc::Model::ListItem.new
item.content = [Ceradoc::Model::TextElement.new("Step one")]
ordered.items << item

# Definition list
definition = Ceradoc::Model::List::Definition.new
def_item = Ceradoc::Model::List::DefinitionItem.new
def_item.terms = [Ceradoc::Model::Term.new(term: "Ruby", type: "language")]
def_item.contents = [Ceradoc::Model::TextElement.new("A programming language")]
definition.items << def_item

Table Classes

Tables represent tabular data.

Ceradoc::Model::Table
  ├── rows: Array<TableRow>
  └── attributes: AttributeList

Ceradoc::Model::TableRow
  └── columns: Array<TableCell>

Ceradoc::Model::TableCell
  └── content: Array<TextElement | Inline>
table = Ceradoc::Model::Table.new

row = Ceradoc::Model::TableRow.new
cell = Ceradoc::Model::TableCell.new
cell.content = [Ceradoc::Model::TextElement.new("Cell content")]
row.columns << cell
table.rows << row

Inline Classes

Inline elements represent text formatting within blocks.

Inline::Base

Base class for all inline elements.

Inline Types

  • Inline::Bold - Bold text (text)

  • Inline::Italic - Italic text (text)

  • Inline::Monospace - Monospace text ( text )

  • Inline::Link - Hyperlink (label)

  • Inline::Anchor - Cross-reference target ()

# Bold text
bold = Ceradoc::Model::Inline::Bold.new
bold.content = "Important text"

# Links
link = Ceradoc::Model::Inline::Link.new
link.path = "https://example.com"
link.name = "Example"

# Anchors (cross-reference targets)
anchor = Ceradoc::Model::Inline::Anchor.new
anchor.id = "section1"

Helper Classes

TextElement

Plain text content.

Ceradoc::Model::TextElement.new("Hello, world!")

AttributeList

Block or inline attributes.

attrs = Ceradoc::Model::AttributeList.new
attrs.add_named("id", "my-id")
attrs.add_positional("ruby")

DocumentAttributes

Document-level metadata attributes.

doc.document_attributes.data.each do |key, value|
  puts "#{key}: #{value}"
end

Working with the Model

doc = Ceradoc.parse("= Main\n\n== Section 1\n\nContent.\n\n=== Subsection\n\nMore.")

# Navigate to sections
doc.sections.each do |section|
  puts section.title.content
  section.sections.each do |subsection|
    puts "  #{subsection.title.content}"
  end
end

Manipulation

doc = Ceradoc.parse("= Title\n\n== Section\n\nOld content.")

# Find section
section = doc.sections.first

# Modify paragraph
section.paragraphs.first.content = [
  Ceradoc::Model::TextElement.new("New content.")
]

# Serialize changes
output = doc.to_adoc

Bibliography


This site uses Just the Docs, a documentation theme for Jekyll.