Purpose

Complete API documentation for Ceradoc’s public interface.

Core Module

Ceradoc

The main Ceradoc module provides the primary API for parsing and converting documents.

module Ceradoc
  VERSION: String

  # Parse an AsciiDoc string
  def self.parse(input, **options) -> Ceradoc::Model::Document

  # Parse an AsciiDoc file
  def self.parse_file(filename, **options) -> Ceradoc::Model::Document

  # Convert a document to a format
  def self.convert(document, to:, **options) -> String
end

Core Methods

Ceradoc.parse(input, **options)

Parse an AsciiDoc string into a document model.

signature: parse(input, **options) -> Ceradoc::Model::Document

Parameters:

  • input (String) - AsciiDoc string to parse

  • schema (Symbol) - Schema to use for parsing (:default, :iso, custom)

  • strict (Boolean) - Whether to raise on parse errors (default: false)

  • preserve_whitespace (Boolean) - Preserve whitespace in text (default: false)

  • attributes (Hash) - Default document attributes

Returns: Ceradoc::Model::Document

Raises: Ceradoc::ParseError if parsing fails and strict: true

Examples:

# Basic parsing
doc = Ceradoc.parse("== Title\n\nContent")

# With schema
doc = Ceradoc.parse(input, schema: :iso)

# With attributes
doc = Ceradoc.parse(input, attributes: { "author" => "John Doe" })

# Strict mode
begin
  doc = Ceradoc.parse(input, strict: true)
rescue Ceradoc::ParseError => e
  puts "Parse error: #{e.message}"
end

Ceradoc.parse_file(filename, **options)

Parse an AsciiDoc file into a document model.

signature: parse_file(filename, **options) -> Ceradoc::Model::Document

Parameters:

  • filename (String) - Path to AsciiDoc file

  • schema (Symbol) - Schema to use for parsing

  • strict (Boolean) - Whether to raise on parse errors

  • preserve_whitespace (Boolean) - Preserve whitespace

  • attributes (Hash) - Default document attributes

  • encoding (String) - File encoding (default: "UTF-8")

  • base_dir (String) - Base directory for include resolution

Returns: Ceradoc::Model::Document

Raises: Ceradoc::ParseError, Errno::ENOENT (file not found)

Examples:

# Basic file parsing
doc = Ceradoc.parse_file("document.adoc")

# With encoding
doc = Ceradoc.parse_file("document.adoc", encoding: "ISO-8859-1")

# With base directory for includes
doc = Ceradoc.parse_file("main.adoc", base_dir: "/path/to/docs")

Ceradoc.convert(document, to:, **options)

Convert a document model to a specified format.

signature: convert(document, to:, **options) -> String

Parameters:

  • document (Ceradoc::Model::Base) - Document model to convert

  • to (Symbol) - Target format (:adoc, :html)

  • indent (Integer) - Output indentation (default: 0)

  • line_width (Integer, nil) - Maximum line width (default: nil)

  • sort_attributes (Boolean) - Sort attributes alphabetically

Returns: String output in specified format

Raises: Ceradoc::SerializationError if serialization fails

Examples:

doc = Ceradoc.parse("= Title\n\nContent")

# Convert to AsciiDoc
asciidoc = Ceradoc.convert(doc, to: :adoc)

# Convert with formatting
asciidoc = Ceradoc.convert(doc, to: :adoc, indent: 2, line_width: 80)

# Write to file
File.write("output.adoc", Ceradoc.convert(doc, to: :adoc))

Model Classes

Ceradoc::Model::Base

Base class for all model elements.

class Ceradoc::Model::Base
  # Serialize to AsciiDoc
  def to_adoc(**options) -> String

  # Convert to format
  def convert(to:, **options) -> String
end

Ceradoc::Model::Document

Root document container.

class Ceradoc::Model::Document < Base
  attr_accessor :header        # Ceradoc::Model::Header
  attr_accessor :document_attributes  # Ceradoc::Model::DocumentAttributes
  attr_accessor :sections       # Array<Ceradoc::Model::Section>
end

Ceradoc::Model::Section

Document section with title and content.

class Ceradoc::Model::Section < Base
  attr_accessor :title          # Ceradoc::Model::Title
  attr_accessor :sections       # Array<Ceradoc::Model::Section> (nested)
  attr_accessor :paragraphs     # Array<Ceradoc::Model::Paragraph>
  attr_accessor :blocks         # Array<Ceradoc::Model::Block::Core>
end

Ceradoc::Model::Paragraph

Text paragraph with inline elements.

class Ceradoc::Model::Paragraph < Base
  attr_accessor :content        # Array<TextElement, Inline>
  attr_accessor :attributes     # Ceradoc::Model::AttributeList
end

Ceradoc::Model::Header

Document metadata.

class Ceradoc::Model::Header
  attr_accessor :title          # String
  attr_accessor :author         # Array<Ceradoc::Model::Author>
  attr_accessor :revision       # Ceradoc::Model::Revision
end

Ceradoc::Model::Title

Section or block title.

class Ceradoc::Model::Title
  attr_accessor :level_int      # Integer (1-6)
  attr_accessor :content        # Array<String>
end

Block Classes

Ceradoc::Model::Block::Core

Base class for delimited blocks.

class Ceradoc::Model::Block::Core < Base
  attr_accessor :delimiter_char # String
  attr_accessor :delimiter_len  # Integer
  attr_accessor :lines          # Array<String>
  attr_accessor :attributes     # Ceradoc::Model::AttributeList
end

Block Types

  • Ceradoc::Model::Block::Listing - Code listing block

  • Ceradoc::Model::Block::Literal - Literal text block

  • Ceradoc::Model::Block::Example - Example block

  • Ceradoc::Model::Block::Quote - Quoted text block

  • Ceradoc::Model::Block::Pass - Pass-through content

List Classes

Ceradoc::Model::List::Core

Base list class.

class Ceradoc::Model::List::Core < Base
  attr_accessor :items          # Array<Ceradoc::Model::ListItem>
end

List Types

  • Ceradoc::Model::List::Unordered - Bulleted list

  • Ceradoc::Model::List::Ordered - Numbered list

  • Ceradoc::Model::List::Definition - Definition list

Ceradoc::Model::ListItem

List item.

class Ceradoc::Model::ListItem
  attr_accessor :content        # Array<TextElement, Inline>
  attr_accessor :nested_list    # Ceradoc::Model::List::Core
end

Table Classes

Ceradoc::Model::Table

Table structure.

class Ceradoc::Model::Table < Base
  attr_accessor :rows           # Array<Ceradoc::Model::TableRow>
  attr_accessor :attributes     # Ceradoc::Model::AttributeList
end

Ceradoc::Model::TableRow

Table row.

class Ceradoc::Model::TableRow
  attr_accessor :columns        # Array<Ceradoc::Model::TableCell>
end

Ceradoc::Model::TableCell

Table cell.

class Ceradoc::Model::TableCell
  attr_accessor :content        # Array<TextElement, Inline>
  attr_accessor :attributes     # Ceradoc::Model::AttributeList
end

Inline Classes

Ceradoc::Model::Inline::Base

Base class for inline elements.

class Ceradoc::Model::Inline::Base < Base
  attr_accessor :content        # String or Array
end

Inline Types

  • Ceradoc::Model::Inline::Bold - Bold text (text)

  • Ceradoc::Model::Inline::Italic - Italic text (text)

  • Ceradoc::Model::Inline::Monospace - Monospace text ( text )

  • Ceradoc::Model::Inline::Link - Hyperlink (label)

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

  • Ceradoc::Model::Inline::CrossReference - Cross-reference (text)

Ceradoc::Model::TextElement

Plain text content.

class Ceradoc::Model::TextElement
  attr_accessor :text           # String
end

Helper Classes

Ceradoc::Model::AttributeList

Block or inline attributes.

class Ceradoc::Model::AttributeList
  def add_positional(value) -> void
  def add_named(name, value) -> void
  def get(name) -> String, nil
  def to_h -> Hash
end

Ceradoc::Model::DocumentAttributes

Document-level metadata.

class Ceradoc::Model::DocumentAttributes
  attr_accessor :data           # Hash<String, String>
end

Configuration

Ceradoc.configure

Configure global settings.

Ceradoc.configure do |config|
  config.default_schema = :iso
  config.strict = false
  config.parser.warn_on_undefined = true
end

Ceradoc.debug

Enable/disable debug mode.

Ceradoc.debug = true  # Enable debug output
Ceradoc.debug = false # Disable debug output

Input Conversion

Ceradoc::Input::HTML.convert

Convert HTML to Document Model.

signature: Ceradoc::Input::HTML.convert(html) -> Ceradoc::Model::Document

Parameters:

  • html (String) - HTML string to convert

Returns: Ceradoc::Model::Document

Examples:

html = "<h1>Title</h1><p>Content</p>"
doc = Ceradoc::Input::HTML.convert(html)
asciidoc = doc.to_adoc

Error Classes

Ceradoc::ParseError

Raised when parsing fails.

class Ceradoc::ParseError < StandardError
  attr_reader :line           # Integer
  attr_reader :column         # Integer
end

Ceradoc::SerializationError

Raised when serialization fails.

class Ceradoc::SerializationError < StandardError
  attr_reader :model          # Ceradoc::Model::Base
end

Ceradoc::SchemaError

Raised for schema-related errors.

class Ceradoc::SchemaError < StandardError
end

Version Information

Ceradoc::VERSION  # => "0.x.x"

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