This reference documents all Ruby methods available in Ceradoc’s public API.

Main Module Methods

Ceradoc.parse

Parse a document string into a model.

Syntax
Ceradoc.parse(input, format: :asciidoc, **options) -> CoreModel::Base
Parameters
input

String - Document content

format

Symbol - Input format (:asciidoc, :markdown, :html)

schema

Symbol - Validation schema (:default, :iso)

strict

Boolean - Raise on parse errors (default: false)

attributes

Hash - Document attributes

Returns

Ceradoc::CoreModel::StructuralElement (document)

Examples
# Parse AsciiDoc
doc = Ceradoc.parse("= Title\n\nContent", format: :asciidoc)

# Parse Markdown
doc = Ceradoc.parse("# Title\n\nContent", format: :markdown)

# Parse HTML
doc = Ceradoc.parse("<h1>Title</h1><p>Content</p>", format: :html)

# With strict mode
begin
  doc = Ceradoc.parse(input, format: :asciidoc, strict: true)
rescue Ceradoc::ParseError => e
  puts "Error at line #{e.line}: #{e.message}"
end

Ceradoc.convert

Convert a document between formats.

Syntax
Ceradoc.convert(input, from:, to:, **options) -> String
Parameters
input

String - Document content

from

Symbol - Source format (:asciidoc, :markdown, :html)

to

Symbol - Target format (:asciidoc, :markdown, :html)

theme

Symbol - HTML theme (:classic, :modern, :minimal)

validate

Boolean - Validate before conversion

Returns

String - Converted document

Examples
# Markdown to HTML
html = Ceradoc.convert("# Title", from: :markdown, to: :html)

# AsciiDoc to Markdown
md = Ceradoc.convert("= Title\n\nContent", from: :asciidoc, to: :markdown)

# HTML to AsciiDoc
adoc = Ceradoc.convert("<h1>Title</h1>", from: :html, to: :asciidoc)

# With theme
html = Ceradoc.convert(adoc, from: :asciidoc, to: :html, theme: :modern)

Ceradoc.serialize

Serialize a CoreModel to a format string.

Syntax
Ceradoc.serialize(model, to:, **options) -> String
Parameters
model

CoreModel::Base - Document model

to

Symbol - Target format

indent

Integer - Output indentation

line_width

Integer - Maximum line width

Returns

String - Serialized document

Examples
# Parse then serialize
doc = Ceradoc.parse(input, format: :asciidoc)
html = Ceradoc.serialize(doc, to: :html)

# With formatting options
adoc = Ceradoc.serialize(doc, to: :asciidoc, indent: 2, line_width: 80)

Format Module Methods

Ceradoc::AsciiDoc.parse

Parse AsciiDoc to AsciiDoc model.

Syntax
Ceradoc::AsciiDoc.parse(input, **options) -> AsciiDoc::Model::Document
Examples
require 'ceradoc/asciidoc'

doc = Ceradoc::AsciiDoc.parse("= Title\n\nParagraph")
doc.header.title  # => "Title"

Ceradoc::Markdown.parse

Parse Markdown to Markdown model.

Syntax
Ceradoc::Markdown.parse(input, **options) -> Markdown::Model::Document
Examples
require 'ceradoc/markdown'

doc = Ceradoc::Markdown.parse("# Title\n\nParagraph")
doc.headings.first.content  # => "Title"

Ceradoc::Html.serialize_static

Serialize CoreModel to static HTML.

Syntax
Ceradoc::Html.serialize_static(model, **options) -> String
Examples
require 'ceradoc/html'

html = Ceradoc::Html.serialize_static(core_model, theme: :modern)

Ceradoc::Html.serialize_spa

Serialize CoreModel to SPA-style HTML.

Syntax
Ceradoc::Html.serialize_spa(model, **options) -> String
Examples
require 'ceradoc/html'

html = Ceradoc::Html.serialize_spa(core_model, theme: :modern)

CoreModel Methods

StructuralElement

# Create a document
doc = Ceradoc::CoreModel::StructuralElement.new(
  element_type: "document",
  title: "My Document",
  id: "my-doc",
  children: []
)

# Create a section
section = Ceradoc::CoreModel::StructuralElement.new(
  element_type: "section",
  level: 1,
  title: "Introduction",
  children: []
)

# Access methods
doc.element_type  # => "document"
doc.title         # => "My Document"
doc.id            # => "my-doc"
doc.children      # => []

Block

# Paragraph
para = Ceradoc::CoreModel::Block.new(
  element_type: "paragraph",
  content: "Text content"
)

# Code block
code = Ceradoc::CoreModel::Block.new(
  element_type: "block",
  delimiter_type: "----",
  content: "def hello; end",
  language: "ruby"
)

# Quote block
quote = Ceradoc::CoreModel::Block.new(
  element_type: "block",
  delimiter_type: "____",
  content: "Quote text"
)

ListBlock and ListItem

# Unordered list
list = Ceradoc::CoreModel::ListBlock.new(
  marker_type: "unordered",
  items: [
    Ceradoc::CoreModel::ListItem.new(content: "Item 1", marker: "*"),
    Ceradoc::CoreModel::ListItem.new(content: "Item 2", marker: "*")
  ]
)

# Ordered list
olist = Ceradoc::CoreModel::ListBlock.new(
  marker_type: "ordered",
  items: [
    Ceradoc::CoreModel::ListItem.new(content: "First", marker: "."),
    Ceradoc::CoreModel::ListItem.new(content: "Second", marker: ".")
  ]
)

Table, TableRow, TableCell

# Create a table
table = Ceradoc::CoreModel::Table.new(
  frame: "all",
  grid: "all",
  rows: [
    Ceradoc::CoreModel::TableRow.new(
      header: true,
      cells: [
        Ceradoc::CoreModel::TableCell.new(content: "Name", header: true),
        Ceradoc::CoreModel::TableCell.new(content: "Value", header: true)
      ]
    ),
    Ceradoc::CoreModel::TableRow.new(
      cells: [
        Ceradoc::CoreModel::TableCell.new(content: "Item"),
        Ceradoc::CoreModel::TableCell.new(content: "100")
      ]
    )
  ]
)

# Cell with formatting
cell = Ceradoc::CoreModel::TableCell.new(
  content: "Centered",
  alignment: "center",
  colspan: 2
)

InlineElement

# Bold
bold = Ceradoc::CoreModel::InlineElement.new(
  format_type: "bold",
  content: "Important text"
)

# Link
link = Ceradoc::CoreModel::InlineElement.new(
  format_type: "link",
  content: "Click here",
  target: "https://example.com"
)

# Italic
italic = Ceradoc::CoreModel::InlineElement.new(
  format_type: "italic",
  content: "Emphasized text"
)

Document Manipulator

DocumentManipulator

require 'ceradoc/document_manipulator'

# Create manipulator
manipulator = Ceradoc::DocumentManipulator.new(doc)

# Chain operations
result = manipulator
  .transform_text(&:upcase)
  .transform_headings(&:upcase)
  .add_toc(levels: 3, position: :top)
  .add_metadata("processed_at" => Time.now.iso8601)
  .remove_elements(:comment_line)
  .to_html

# Available methods
manipulator.transform_text(&:method)     # Transform all text
manipulator.transform_headings(&:method) # Transform headings
manipulator.add_toc(options)             # Add table of contents
manipulator.add_metadata(hash)           # Add metadata
manipulator.remove_elements(type)        # Remove element types
manipulator.to_html                      # Output as HTML
manipulator.to_markdown                  # Output as Markdown
manipulator.to_asciidoc                  # Output as AsciiDoc

Query API

Query Methods

# Parse document
doc = Ceradoc.parse(input, format: :asciidoc)

# Find by element type
sections = doc.query('section')
paragraphs = doc.query('paragraph')
tables = doc.query('table')

# Find by ID
intro = doc.query('#intro').first

# Find by class/role
examples = doc.query('.example')

# Complex selectors
results = doc.query('section > paragraph:first-child')

# Query within element
section = sections.first
paras = doc.query_within(section, 'paragraph')

# Chain queries
doc.query('section')
   .filter { |s| s.level == 1 }
   .map { |s| s.title }

Selector Syntax

element

Element type (section, paragraph, table)

#id

ID selector

.class

Class/role selector

[attr=value]

Attribute selector

:first-child

Pseudo-class selectors

>

Child combinator

(space)

Descendant combinator

Streaming API

Streaming Methods

require 'ceradoc/streaming'

# Stream parse large file
Ceradoc::Streaming.parse_large_file("large.adoc", format: :asciidoc,
                                    chunk_size: 100) do |chunk|
  chunk.each { |element| process_element(element) }
end

# Transform in chunks
results = Ceradoc::Streaming.transform_in_chunks(elements, chunk_size: 50) do |chunk|
  chunk.map { |el| transform_element(el) }
end

# Incremental serialization
File.open("output.html", "w") do |file|
  Ceradoc::Streaming.serialize_incremental(document, format: :html) do |chunk|
    file.write(chunk)
  end
end

# Memory-limited processing
progress = Ceradoc::Streaming.process_with_memory_limit(
  "input.adoc", "output.html",
  format: :asciidoc, output_format: :html,
  max_memory: 50 * 1024 * 1024  # 50MB
)
puts progress.to_s  # "100 processed (100.0%) at 10.0/sec"

Validation API

Validation Methods

require 'ceradoc/validation'

# Define a schema
schema = Ceradoc::Validation::Schema.define do
  required :title, type: String, min_length: 1
  required :sections, type: Array, min_count: 1
  optional :author, type: String

  rule :check_references do |doc|
    refs = doc.query('xref')
    missing = refs.reject { |r| doc.resolve_reference(r) }
    missing.map { |r| "Unresolved reference: #{r.target}" }
  end
end

# Validate document
result = schema.validate(document)

if result.valid?
  puts "Document is valid"
else
  result.errors.each { |e| puts "#{e.path}: #{e.message}" }
end

Built-in Validation Rules

required

Field must be present

type

Field must be specific type

min_length/max_length

String/collection length bounds

min_count/max_count

Collection count bounds

format

Match against regex pattern

rule

Custom validation block

Lazy Evaluation API

Lazy Methods

require 'ceradoc/lazy'

# Wrap document for lazy iteration
wrapper = Ceradoc::Lazy.wrap(document)
wrapper.each_section do |section|
  process_section(section)  # Processed on-demand
end

# Lazy transformation pipeline
result = Ceradoc::Lazy.transform(sections) do |p|
  p.map { |s| transform_section(s) }
   .select { |s| s.visible? }
   .take(10)
end.to_a  # Only evaluates when to_a is called

# Process in batches
wrapper.each_batch(10) do |batch|
  batch.each { |section| process(section) }
end

# Lazy reference resolution
resolver = Ceradoc::Lazy.resolver(document, loader: ->(ref, _) {
  load_include_file(ref)
})
content = resolver.resolve("include::chapter1.adoc[]")

Error Handling

Error Classes

# Error hierarchy
Ceradoc::Error                          # Base error class
├── Ceradoc::ParseError                 # Parsing errors
├── Ceradoc::ValidationError            # Validation errors
├── Ceradoc::TransformationError        # Transform errors
├── Ceradoc::UnsupportedFormatError     # Unknown format
└── Ceradoc::ConfigurationError         # Config errors

# Handling errors
begin
  doc = Ceradoc.parse(input, format: :asciidoc, strict: true)
rescue Ceradoc::ParseError => e
  puts "Parse error at line #{e.line}, column #{e.column}"
  puts e.message
rescue Ceradoc::ValidationError => e
  puts "Validation failed: #{e.message}"
rescue Ceradoc::UnsupportedFormatError => e
  puts "Unknown format: #{e.format}"
end

Configuration

Global Configuration

# Configure globally
Ceradoc.configure do |config|
  config.default_format = :asciidoc
  config.strict = false
  config.warn_on_undefined = true
  config.parser_options = { preserve_whitespace: true }
end

# Access configuration
Ceradoc.config.default_format  # => :asciidoc

# Debug mode
Ceradoc.debug = true

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