Purpose
This page explains how Ceradoc parses AsciiDoc documents into a structured document model. You’ll learn about the parser layer, what it produces, and how to work with parsed documents.
Overview
Ceradoc parses AsciiDoc documents into a rich object model using the Parslet parsing expression grammar library. The parser converts text into an Abstract Syntax Tree (AST), which is then transformed into Model objects.
Parsing Methods
The Parsing Process
Stage 1: Lexical Analysis
The AsciiDoc text is tokenized into meaningful elements:
-
Headings (
== Title) -
Delimiters (
----,__) -
List markers (
*,.) -
Inline formatting (
bold,italic) -
Attributes (
:name: value)
Working with Parsed Documents
Accessing the Header
doc = Ceradoc.parse("= Document Title\n\nContent")
doc.header.title # => "Document Title"
doc.header.author # => Array of Author objects
doc.header.revision # => Revision objectAccessing Sections
doc = Ceradoc.parse("== Section 1\n\nContent\n\n== Section 2\n\nContent")
# All top-level sections
doc.sections.each do |section|
puts section.title.content
end
# First section
section = doc.sections.first
puts section.title.level_int # => 2
puts section.paragraphs # => Array of paragraphs
# Nested sections
section.sections.each do |subsection|
puts subsection.title.content
endAccessing Document Attributes
doc = Ceradoc.parse(":author: John Doe\n\n== Title\n\nContent")
# All attributes
doc.document_attributes.data.each do |key, value|
puts "#{key}: #{value}"
end
# Specific attribute
doc.document_attributes.data["author"] # => "John Doe"Accessing Blocks
doc = Ceradoc.parse("== Section\n\nParagraph 1.\n\nParagraph 2.")
section = doc.sections.first
# Paragraphs
section.paragraphs.each do |para|
puts para.content
end
# All blocks (paragraphs, lists, tables, etc.)
section.blocks.each do |block|
puts block.class.name
endAccessing Inline Elements
doc = Ceradoc.parse("= Title\n\nThis has *bold* and _italic_ text.")
paragraph = doc.sections.first.paragraphs.first
paragraph.content.each do |element|
case element
when Ceradoc::Model::TextElement
puts "Text: #{element.text}"
when Ceradoc::Model::Inline::Bold
puts "Bold: #{element.content}"
when Ceradoc::Model::Inline::Italic
puts "Italic: #{element.content}"
end
endWhat Gets Parsed
Ceradoc parses the following AsciiDoc elements:
-
Structure: Document title, sections, headers
-
Blocks: Paragraphs, delimited blocks, lists, tables
-
Inline: Bold, italic, monospace, links, anchors
-
Attributes: Document attributes, block attributes
-
Metadata: Author, revision info
Parser Limitations
The parser focuses on semantic AsciiDoc elements. Some advanced features may not be fully supported:
-
Complex include directives
-
All macro types
-
Conditional processing
See Troubleshooting for known limitations.
Related Documentation
-
Transformation Layer - How AST becomes Model
-
Document Model - Model object details
-
Basic Parsing Tutorial - Hands-on examples