Purpose

This page helps you install Ceradoc and write your first AsciiDoc parsing code. You’ll learn how to parse AsciiDoc documents, access document structure, and serialize back to AsciiDoc.

Prerequisites

  • Ruby 3.1 or higher

  • Basic knowledge of AsciiDoc syntax

Installation

Add Ceradoc to your application’s Gemfile:

gem 'ceradoc'

Then execute:

bundle install

Or install it yourself as a gem:

gem install ceradoc

Basic Parsing

Parse a Simple Document

Parse an AsciiDoc string into a document model:

# Parse AsciiDoc input
doc = Ceradoc.parse("== Hello World\n\nThis is a paragraph.")

# Access document structure
doc.header.title                    # => "Hello World"
doc.sections.first.title.level_int  # => 2
doc.sections.first.paragraphs.first # => First paragraph object

# Serialize back to AsciiDoc
output = doc.to_adoc

Parse from File

Parse an AsciiDoc file:

# Parse from file
doc = Ceradoc.parse_file("document.adoc")

# Work with the model
doc.sections.each do |section|
  puts "Section: #{section.title}"
end

Accessing Document Structure

The document model includes:

  • header - Title, author, revision info

  • document_attributes - Key-value metadata

  • sections - Hierarchical content structure

  • blocks - Paragraphs, lists, code blocks, tables, etc.

  • inline elements - Links, formatting, etc.

# Access document structure
doc.header.title                  # Document title
doc.document_attributes.data     # Metadata attributes
doc.sections                      # Top-level sections
doc.sections.first.sections       # Nested sections
doc.sections.first.paragraphs    # Content blocks

Serialization

Convert document models to AsciiDoc output:

# Any Model object can be serialized to AsciiDoc
paragraph = Ceradoc::Model::Paragraph.new
paragraph.content = [Ceradoc::Model::TextElement.new("Hello")]
paragraph.to_adoc  # => "Hello\n"

Using the Converter

The Ceradoc.convert method provides explicit format conversion:

doc = Ceradoc.parse_file("input.adoc")

# Convert to AsciiDoc (same as to_adoc)
asciidoc_output = Ceradoc.convert(doc, to: :adoc)

DOCX Conversion

Convert Word documents to AsciiDoc or Markdown:

require 'ceradoc/docx'

# Convert DOCX to AsciiDoc
adoc = Ceradoc.convert("input.docx", from: :docx, to: :asciidoc)

# Convert DOCX to Markdown
md = Ceradoc.convert("input.docx", from: :docx, to: :markdown)

# Parse DOCX to CoreModel for inspection
core = Ceradoc.parse("input.docx", format: :docx)
core.title         # => "Document Title"
core.children      # => Array of sections, paragraphs, tables

Install DOCX support:

# Gemfile
gem 'ceradoc-docx'
gem 'uniword'

Next Steps

References


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