An AsciiDoc document consists of a series of block elements starting with an optional document Header, followed by an optional Preamble, followed by zero or more document Sections.
Almost any combination of zero or more elements constitutes a valid AsciiDoc document: documents can range from a single sentence to a multi-part book.
Block elements consist of one or more lines of text and may contain other block elements.
The AsciiDoc block structure can be informally summarized as follows [1]:
Document ::= (Header?,Preamble?,Section*) Header ::= (Title,(AuthorInfo,RevisionInfo?)?) AuthorInfo ::= (FirstName,(MiddleName?,LastName)?,EmailAddress?) RevisionInfo ::= (RevisionNumber?,RevisionDate,RevisionRemark?) Preamble ::= (SectionBody) Section ::= (Title,SectionBody?,(Section)*) SectionBody ::= ((BlockTitle?,Block)|BlockMacro)+ Block ::= (Paragraph|DelimitedBlock|List|Table) List ::= (BulletedList|NumberedList|LabeledList|CalloutList) BulletedList ::= (ListItem)+ NumberedList ::= (ListItem)+ CalloutList ::= (ListItem)+ LabeledList ::= (ListEntry)+ ListEntry ::= (ListLabel,ListItem) ListLabel ::= (ListTerm+) ListItem ::= (ItemText,(List|ListParagraph|ListContinuation)*)
Where:
BlockId, AttributeEntry and AttributeList block elements (not
shown) can occur almost anywhere.
The Header contains a document title plus optional authorship and revision information:
Here’s an example AsciiDoc document header:
Writing Documentation using AsciiDoc ==================================== Joe Bloggs <jbloggs@mymail.com> v2.0, February 2003: Rewritten for version 2 release.
The author information line contains the author’s name optionally followed by the author’s email address. The author’s name consists of a first name followed by optional middle and last names separated by white space. Multi-word first, middle and last names can be entered in the header author line using the underscore as a word separator. The email address comes last and must be enclosed in angle <> brackets. Author names cannot contain angle <> bracket characters. Here a some examples of author information lines:
Joe Bloggs <jbloggs@mymail.com> Joe Bloggs Vincent Willem van_Gogh
The optional revision information line follows the author information line. The revision information can be one of two formats:
An optional document revision number followed by an optional revision date followed by an optional revision remark:
Here a some examples of header revision lines:
v2.0, February 2003 February 2003 v2.0, v2.0, February 2003: Rewritten for version 2 release. February 2003: Rewritten for version 2 release. v2.0,: Rewritten for version 2 release. :Rewritten for version 2 release.
You can override or set header parameters by passing revnumber,
revremark, revdate, email, author, authorinitials,
firstname and lastname attributes using the asciidoc(1) -a
(--attribute) command-line option. For example:
$ asciidoc -a revdate=2004/07/27 article.txt
The revnumber attribute can be an RCS/CSV/SVN $Id$ marker. Attributes can also be added to the header for substitution in the header template with Attribute Entry elements.
DocBook defines numerous elements for document meta-data, for example: copyrights, document history and authorship information. The AsciiDoc header syntax provides for basic revision and author information — additional information such as copyrights, document history authorship details can be optionally included from a separate document information file. The document information file can contain any DocBook elements that are allowed inside the DocBook articleinfo and bookinfo elements:
<docname>-docinfo.xml. For
example, if the source document is called mydoc.txt then the
document information file would be named mydoc-docinfo.xml.
The document information file will only be included in the DocBook
output if the docinfo attribute is defined, for example:
$ asciidoc -a docinfo -b docbook mydoc.txt
./doc/article-docinfo.xml example that comes with the
AsciiDoc distribution.
<docname>-docinfo.html (if it exists) into HTML backend outputs.
In the case of HTML outputs however it’s usually easier to put
AsciiDoc markup in your source file directly after the header.
| Note | |
|---|---|
DocBook has a rich set of meta data elements, just which of these elements are rendered is DocBook processor dependent. |
The Preamble is an optional untitled section body between the document Header and the first Section title.
In addition to the document title (level 0), AsciiDoc supports four section levels: 1 (top) to 4 (bottom). Section levels are delimited by section titles. Sections are translated using configuration file section markup templates. AsciiDoc generates the following intrinsic attributes specifically for use in section markup templates:
level attribute is the section level number, it is normally just
the title level number (1..4). However, if the leveloffset
attribute is defined it will be added to the level attribute. The
leveloffset attribute is useful for combining documents.
-n (--section-numbers) command-line option generates the
sectnum (section number) attribute. The sectnum attribute is used
for section numbers in HTML outputs (DocBook section numbering are
handled automatically by the DocBook toolchain commands).
Section markup templates specify output markup and are defined in AsciiDoc configuration files. Section markup template names are derived as follows (in order of precedence):
From the title’s first positional attribute or template attribute. For example, the following three section titles are functionally equivalent:
[[terms]] [glossary] List of Terms ------------- ["glossary",id="terms"] List of Terms ------------- [template="glossary",id="terms"] List of Terms -------------
[specialsections] entry.
sect<level> template is used
(where <level> is a number from 1 to 4).
In addition to the normal section template names (sect1, sect2, sect3, sect4) AsciiDoc has the following templates for frontmatter, backmatter and other special sections: abstract, preface, colophon, dedication, glossary, bibliography, synopsis, appendix, index. These special section templates generate the corresponding Docbook elements; for HTML outputs they default to the sect1 section template.
If no explicit section ID is specified an ID will be synthesised from the section title. The primary purpose of this feature is to ensure persistence of table of contents links (permalinks): the missing section IDs are generated dynamically by the JavaScript TOC generator after the page is loaded. If you link to a dynamically generated TOC address the page will load but the browser will ignore the (as yet ungenerated) section ID.
The IDs are generated by the following algorithm:
idprefix attribute (so there’s no possibility of name
clashes with existing document IDs). Prepend an underscore if the
idprefix attribute is not defined.
_2, _3 …) is added if a same named
auto-generated section ID exists.
For example the title Jim’s House would generate the ID
_jim_s_house.
Section ID synthesis can be disabled by undefining the sectids
attribute.
AsciiDoc has a mechanism for mapping predefined section titles
auto-magically to specific markup templates. For example a title
Appendix A: Code Reference will automatically use the appendix
section markup template. The mappings from title to template
name are specified in [specialsections] sections in the Asciidoc
language configuration files (lang-*.conf). Section entries are
formatted like:
<title>=<template>
<title> is a Python regular expression and <template> is the name
of a configuration file markup template section. If the <title>
matches an AsciiDoc document section title then the backend output is
marked up using the <template> markup template (instead of the
default sect<level> section template). The {title} attribute value
is set to the value of the matched regular expression group named
title, if there is no title group {title} defaults to the whole
of the AsciiDoc section title. If <template> is blank then any
existing entry with the same <title> will be deleted.
Inline document elements are used to format text and to
perform various types of text substitution. Inline elements and inline
element syntax is defined in the asciidoc(1) configuration files.
Here is a list of AsciiDoc inline elements in the (default) order in which they are processed:
<, >, and & characters).
See [specialcharacters] configuration file sections.
[quotes] configuration file sections.
[specialwords]
configuration file sections.
[replacements] configuration file sections.