Plain text is the most universal electronic document format, no matter
what computing environment you use, you can always read and write
plain text documentation. But for many applications plain text is not
a viable presentation format. HTML, PDF and roff (roff is used for
man pages) are the most widely used UNIX presentation formats.
DocBook is a popular UNIX documentation markup format which can be
translated to HTML, PDF and other presentation formats.
AsciiDoc is a plain text human readable/writable document format that
can be translated to DocBook or HTML using the asciidoc(1) command.
You can then either use asciidoc(1) generated HTML directly or run
asciidoc(1) DocBook output through your favorite DocBook toolchain or
use the AsciiDoc a2x(1) toolchain wrapper to produce PDF, DVI, LaTeX,
PostScript, man page, HTML and text formats.
The AsciiDoc format is a useful presentation format in its own right:
AsciiDoc files are unencumbered by markup and are easily viewed,
proofed and edited.
AsciiDoc is light weight: it consists of a single Python script and a
bunch of configuration files. Apart from asciidoc(1) and a Python
interpreter, no other programs are required to convert AsciiDoc text
files to DocBook or HTML. See Example AsciiDoc Documents
below.
You write an AsciiDoc document the same way you would write a normal
text document, there are no markup tags or arcane notations. Built-in
AsciiDoc formatting rules have been kept to a minimum and are
reasonably obvious.
Text markup conventions tend to be a matter of (often strong) personal
preference: if the default syntax is not to your liking you can define
your own by editing the text based asciidoc(1) configuration files.
You can create your own configuration files to translate AsciiDoc
documents to almost any SGML/XML markup.
asciidoc(1) comes with a set of configuration files to translate
AsciiDoc articles, books or man pages to HTML or DocBook backend
formats.
2.1. Installing AsciiDoc
2.2. Example AsciiDoc Documents
The best way to quickly get a feel for AsciiDoc is to view the
AsciiDoc web site and/or distributed examples:
-
Take a look at the linked examples on the AsciiDoc web site home
page http://www.methods.co.nz/asciidoc/. Press the Page Source
sidebar menu item to view corresponding AsciiDoc source.
-
Read the .txt source files in the distribution ./doc directory
in conjunction with the corresponding HTML and DocBook XML files.
There are three types of AsciiDoc documents: article, book and
manpage. All document types share the same AsciiDoc format with some
minor variations.
Use the asciidoc(1) -d (--doctype) option to specify the AsciiDoc
document type — the default document type is article.
By convention the .txt file extension is used for AsciiDoc document
source files.
3.1. article
Used for short documents, articles and general documentation. See the
AsciiDoc distribution ./doc/article.txt example.
3.2. book
Books share the same format as articles; in addition there is the
option to add level 0 book part sections.
Book documents will normally be used to produce DocBook output since
DocBook processors can automatically generate footnotes, table of
contents, list of tables, list of figures, list of examples and
indexes.
AsciiDoc markup supports standard DocBook frontmatter and backmatter
special sections (dedication, preface, bibliography, glossary,
index, colophon) plus footnotes and index entries.
Example book documents
-
Book
-
The ./doc/book.txt file in the AsciiDoc distribution.
-
Multi-part book
-
The ./doc/book-multi.txt file in the AsciiDoc distribution.
3.3. manpage
Used to generate UNIX manual pages. AsciiDoc manpage documents
observe special header title and section naming conventions — see the
Manpage Documents section for details.
See also the asciidoc(1) man page source (./doc/asciidoc.1.txt) from
the AsciiDoc distribution.
The asciidoc(1) command translates an AsciiDoc formatted file to the
backend format specified by the -b (--backend) command-line
option. asciidoc(1) itself has little intrinsic knowledge of backend
formats, all translation rules are contained in customizable cascading
configuration files. Backend specific attributes are listed in
Appendix H.
AsciiDoc ships with the following predefined backend output formats:
4.1. docbook
AsciiDoc generates the following DocBook document types: article, book
and refentry (corresponding to the AsciiDoc article, book and
manpage document types).
DocBook documents are not designed to be viewed directly. Most Linux
distributions come with conversion tools (collectively called a
toolchain) for converting DocBook files to presentation
formats such as Postscript, HTML, PDF, DVI, PostScript, LaTeX, roff
(the native man page format), HTMLHelp, JavaHelp and text.
The AsciiDoc Preamble element generates a DocBook book
preface element although it’s more usual to use an explicit
Preface special section (see the ./doc/book.txt example book).
4.2. xhtml11
The default asciidoc(1) backend is xhtml11 which generates XHTML 1.1
markup styled with CSS2. Default output file have a .html extension.
xhtml11 document generation is influenced by the following
optional attributes (the default behavior is to generate XHTML with no
section numbers, embedded CSS and no linked admonition icon images):
4.2.1. Stylesheets
AsciiDoc XHTML output is styled using CSS2 stylesheets from the
distribution ./stylesheets/ directory.
|
All browsers have CSS quirks, but Microsoft’s IE6 has so many
omissions and errors that the xhtml11-quirks.css stylesheet and
xhtml11-quirks.conf configuration files are included during XHTML
backend processing to to implement workarounds for IE6. If you don’t
use IE6 then the quirks stylesheet and configuration files can be
omitted using the --attribute quirks! command-line option.
|
Default xhtml11 stylesheets:
-
./stylesheets/xhtml11.css
-
The main stylesheet.
-
./stylesheets/xhtml11-manpage.css
-
Tweaks for manpage document type generation.
-
./stylesheets/xhtml11-quirks.css
-
Stylesheet modifications to work around IE6 browser
incompatibilities.
Use the theme attribute to select an alternative set of stylesheets.
For example, the command-line option -a theme=foo will use
stylesheets foo.css, foo-manpage.css and foo-quirks.css instead
of the default stylesheets.
Use the stylesheet attribute to include an additional stylesheet in
XHTML documents. For example, the command-line option -a
stylesheet=newsletter.css will use stylesheets newsletter.css.
4.3. html4
This backend generates plain (unstyled) HTML 4.01 Transitional markup.
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.
5.1. Block Elements
Block elements consist of one or more lines of text and may contain
other block elements.
The AsciiDoc block structure can be informally summarized
[This is a rough structural guide, not a rigorous syntax
definition]
as follows:
Document ::= (Header?,Preamble?,Section*)
Header ::= (Title,(AuthorLine,RevisionLine?)?)
AuthorLine ::= (FirstName,(MiddleName?,LastName)?,EmailAddress?)
RevisionLine ::= (Revision?,Date)
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)*)
-
? implies zero or one occurrence, + implies one or more
occurrences, * implies zero or more occurrences.
-
All block elements are separated by line boundaries.
-
BlockId, AttributeEntry and AttributeList block elements (not
shown) can occur almost anywhere.
-
There are a number of document type and backend specific
restrictions imposed on the block syntax.
-
The following elements cannot contain blank lines: Header, Title,
Paragraph, ItemText.
-
A ListParagraph is a Paragraph with its listelement option set.
-
A ListContinuation is a list continuation element.
The Header contains a document title plus optional authorship and
revision information. The Header is optional but must begin with a
document title. The header can be preceded by comments and
attribute entries. Optional Author and Revision lines
immediately follow the Header title. the header can also include
attribute entry lines. The document heading is separated from the
remainder of the document by one or more blank lines. 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 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 lines:
Joe Bloggs <jbloggs@mymail.com>
Joe Bloggs
Vincent Willem van_Gogh
The optional header revision line follows the author line. The
revision line can be one of two formats:
-
An optional document revision number followed by an optional
revision date followed by an optional revision remark:
-
If the revision number is specified it must be followed by a
comma.
-
The revision number must contain at least one numeric character.
-
Any non-numeric characters preceding the first numeric character
will be dropped.
-
If a revision remark is specified it must be preceded by a colon.
The revision remark extends from the colon up to the next blank
line or attribute entry and is subject to normal text
substitutions.
-
If a revision number or remark has been set but the revision date
has not been set then the revision date is set to the value of the
docdate attribute.
-
An RCS/CSV/SVN $Id$ marker (if an $Id$ revision marker is used the
header author line can be omitted).
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.
5.2.1. Additional document header information
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 and document
history can be optionally included from a separate document
information file containing DocBook elements that are allowed inside
the DocBook articleinfo and bookinfo elements:
-
The document information file must be in the same directory as the
source document and must be named like <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 be included in the DocBook output
if the docinfo attribute is defined, for example:
$ asciidoc -a docinfo -b docbook mydoc.txt
See the ./doc/article-docinfo.xml example that comes with the
AsciiDoc distribution.
5.3. Preamble
The Preamble is an optional untitled section body between the document
Header and the first Section title.
5.4. Sections
AsciiDoc supports five section levels 0 to 4 (although only book
documents are allowed to contain level 0 sections). Section levels are
delineated by the section titles.
Sections are translated using configuration file markup templates.
The names of section templates are specified in the following ways (in
order of precedence):
-
By setting the title’s first positional attribute or template
attribute to the name of a configuration file template. 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
-------------
-
When the title matches a configuration file specialsections
entry.
-
If neither of the above use the default sect<level> template
name.
The -n (--section-numbers) command-line option auto-numbers HTML
outputs (DocBook line numbering is handled automatically by the
DocBook toolchain commands).
Section IDs are auto-generated from section titles if the sectids
attribute is defined (the default behavior). The primary purpose of
this feature is to ensure persistence of table of contents links:
missing section IDs are generated dynamically by the JavaScript TOC
generator after the page is loaded. This means, for example, that if
you go to a bookmarked 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:
-
Replace all non-alphanumeric title characters with underscores.
-
Strip leading or trailing underscores.
-
Convert to lowercase.
-
Prepend the idprefix attribute (so there’s no possibility of name
clashes with existing document IDs). Prepend an underscore if the
idprefix attribute is not defined.
-
A numbered suffix (_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.
5.4.1. Special Sections
In addition to normal sections there are DocBook section elements for
frontmatter and backmatter sections — for example: preface,
bibliography, table of contents, index.
[specialsections] sections are in AsciiDoc language configuration
files; they map specific section titles to markup templates.
Section entries are formatted like:
<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.
AsciiDoc comes preconfigured with the following special section
titles:
Preface (book documents only)
Abstract (article documents only)
Dedication (book documents only)
Glossary
Bibliography|References
Colophon (book documents only)
Index
Appendix [A-Z][:.] <title>
5.5. Inline Elements
Inline document elements are used to markup character
formatting and 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:
-
Special characters
-
These character sequences escape special characters used by
the backend markup (typically "<", ">", and "&"). See
[specialcharacters] configuration file sections.
-
Quotes
-
Characters that markup words and phrases; usually for
character formatting. See [quotes] configuration file
sections.
-
Special Words
-
Word or word phrase patterns singled out for markup without
the need for further annotation. See [specialwords]
configuration file sections.
-
Replacements
-
Each Replacement defines a word or word phrase pattern to
search for along with corresponding replacement text. See
[replacements] configuration file sections.
-
Attributes
-
Document attribute names enclosed in braces (attribute
references) are replaced by the corresponding attribute value.
-
Inline Macros
-
Inline macros are replaced by the contents of parametrized
configuration file sections.
The AsciiDoc source document is read and processed as follows:
-
The document Header is parsed, header parameter values are
substituted into the configuration file [header] template section
which is then written to the output file.
-
Each document Section is processed and its constituent elements
translated to the output file.
-
The configuration file [footer] template section is substituted
and written to the output file.
When a block element is encountered asciidoc(1) determines the type of
block by checking in the following order (first to last): (section)
Titles, BlockMacros, Lists, DelimitedBlocks, Tables, AttributeEntrys,
AttributeLists, BlockTitles, Paragraphs.
The default paragraph definition [paradef-default] is last element
to be checked.
Knowing the parsing order will help you devise unambiguous macro, list
and block syntax rules.
Inline substitutions within block elements are performed in the
following default order:
-
Special characters
-
Quotes
-
Special words
-
Replacements
-
Attributes
-
Inline Macros
-
Replacements2
The substitutions and substitution order performed on
Title, Paragraph and DelimitedBlock elements is determined by
configuration file parameters.
7.1. Quoted Text
Words and phrases can be formatted by enclosing inline text with
quote characters:
-
Emphasized text
-
Word phrases 'enclosed in single quote characters' (acute
accents) or _underline characters_ are emphasized.
-
Strong text
-
Word phrases *enclosed in asterisk characters* are rendered
in a strong font (usually bold).
-
Monospaced text
-
Word phrases +enclosed in plus characters+ are rendered in a
monospaced font. Word phrases `enclosed in backtick
characters` (grave accents) are also rendered in a monospaced
font but in this case the enclosed text is rendered literally
and is not subject to further expansion (see inline literal).
-
‘Single quoted text’
-
Phrases enclosed with a `single grave accent to the left and
a single acute accent to the right' are rendered in single
quotation marks.
-
“Double quoted text”
-
Phrases enclosed with ``two grave accents to the left and
two acute accents to the right'' are rendered in quotation
marks.
-
Unquoted text
-
Placing #hashes around text# does nothing, it is a mechanism
to allow inline attributes to be applied to otherwise
unformatted text (see example below).
Quoted text can be prefixed with an attribute list. Currently
the only use made of this feature is to allow the font color,
background color and size to be specified (XHTML/HTML only, not
DocBook) using the first three positional attribute arguments. The
first argument is the text color; the second the background color; the
third is the font size. Colors are valid CSS colors and the font size
is a number which treated as em units. Here are some examples:
[red]#Red text#.
[,yellow]*bold text on a yellow background*.
[blue,#b0e0e6]+Monospaced blue text on a light blue background+
[,,2]#Double sized text#.
New quotes can be defined by editing asciidoc(1) configuration files.
See the Configuration Files section for details.
Quoted text behavior
-
Quoting cannot be overlapped.
-
Different quoting types can be nested.
-
To suppress quoted text formatting place a backslash character
immediately in front of the leading quote character(s). In the case
of ambiguity between escaped and non-escaped text you will need to
escape both leading and trailing quotes, in the case of
multi-character quotes you may even need to escape individual
characters.
-
A configuration file [quotes] entry can be subsequently undefined
by setting it to a blank value.
7.1.1. Constrained and Unconstrained Quotes
There are actually two types of quotes:
Constrained quotes
Quote text that must be bounded by white space, for example a phrase
or a word. These are the most common type of quote and are the ones
discussed previously.
Unconstrained quotes
Unconstrained quotes have no boundary constraints and can be placed
anywhere within inline text. For consistency and to make them easier
to remember unconstrained quotes are double-ups of the _, *, +
and # constrained quotes:
__unconstrained emphasized text__
**unconstrained strong text**
++unconstrained monospaced text++
##unconstrained unquoted text##
The following example emboldens the letter F:
|
The __, **, ++ and ## unconstrained quotes have to be
double-escaped (because of their similarity to the single character
constrained quotes) — here’s how to escape the previous example:
|
7.2. Superscripts and Subscripts
Put ^carets on either^ side of the text to be superscripted, put
~tildes on either side~ of text to be subscripted. For example, the
following line:
e^πi^+1 = 0. H~2~O and x^10^. Some ^super text^
and ~some sub text~
eπi+1 = 0. H2O and x10. Some super text
and some sub text
Superscripts and subscripts are implemented as unconstrained quotes so they can be escaped with a leading backslash and prefixed
with with an attribute list.
7.3. Line Breaks
A plus character preceded by at least one space character at the end
of a non-blank line forces a line break. It generates a line break
(br) tag for HTML outputs and a custom XML asciidoc-br processing
instruction for DocBook outputs. The asciidoc-br processing
instruction is handled by a2x(1) if you use FOP.
7.4. Page Breaks
A line of three or more less-than (<<<) characters will generate a
hard page break in DocBook and printed HTML outputs. It uses the CSS
page-break-after property for HTML outputs and a custom XML
asciidoc-pagebreak processing instruction for DocBook outputs. The
asciidoc-pagebreak processing instruction is handled by
a2x(1) if you use FOP. Hard page breaks are sometimes handy
but as a general rule you should let your page processor generate page
breaks for you.
7.5. Rulers
A line of three or more apostrophe characters will generate a ruler
line. It generates a ruler (hr) tag for HTML outputs and a custom XML
asciidoc-hr processing instruction for DocBook outputs. The
asciidoc-hr processing instruction is handled by a2x(1) if
you use FOP.
7.6. Tabs
By default tab characters input files will translated to 8 spaces. Tab
expansion is set with the tabsize entry in the configuration file
[miscellaneous] section and can be overridden in included files by
setting a tabsize attribute in the include macro’s attribute list.
For example:
include::addendum.txt[tabsize=2]
The tab size can also be set using the attribute command-line option,
for example --attribute tabsize=4
7.7. Replacements
The following replacements are defined in the default AsciiDoc
configuration:
(C) copyright, (TM) trademark, (R) registered trademark,
-- em dash, ... ellipsis, -> right arrow, <- left arrow, => right
double arrow, <= left double arrow.
© copyright, ™ trademark, ® registered trademark, — em dash, … ellipsis, → right arrow, ← left arrow, ⇒ right
double arrow, ⇐ left double arrow.
You can also include arbitrary entity references in the AsciiDoc
source. Examples:
To render a replacement literally escape it with a leading back-slash.
7.8. Special Words
Words defined in [specialwords] configuration file sections are
automatically marked up without having to be explicitly notated.
Document and section titles can be in either of two formats:
8.1. Two line titles
A two line title consists of a title line, starting hard against the
left margin, and an underline. Section underlines consist a repeated
character pairs spanning the width of the preceding title (give or
take up to three characters):
The default title underlines for each of the document levels are:
Level 0 (top level): ======================
Level 1: ----------------------
Level 2: ~~~~~~~~~~~~~~~~~~~~~~
Level 3: ^^^^^^^^^^^^^^^^^^^^^^
Level 4 (bottom level): ++++++++++++++++++++++
Level One Section Title
-----------------------
Level 2 Subsection Title
~~~~~~~~~~~~~~~~~~~~~~~~
8.2. One line titles
One line titles consist of a single line delimited on either side by
one or more equals characters (the number of equals characters
corresponds to the section level minus one). Here are some examples:
= Document Title (level 0) =
== Section title (level 1) ==
=== Section title (level 2) ===
==== Section title (level 3) ====
===== Section title (level 4) =====
Note
-
One or more spaces must fall between the title and the delimiters.
-
The trailing title delimiter is optional.
-
The one-line title syntax can be changed by editing the
configuration file [titles] section sect0…sect4 entries.
8.3. Floating titles
Setting the title’s first positional attribute or style attribute to
float generates a free-floating title. A free-floating title is
rendered just like a normal section title but is not formally
associated with a text body and is not part of the regular section
hierarchy so the normal ordering rules do not apply. Floating titles
can also be used in contexts where section titles are illegal: for
example sidebar and admonition blocks. Example:
[float]
The second day
~~~~~~~~~~~~~~
A BlockTitle element is a single line beginning with a period
followed by the title text. A BlockTitle is applied to the immediately
following Paragraph, DelimitedBlock, List, Table or BlockMacro. For
example:
.Notes
- Note 1.
- Note 2.
A BlockId is a single line block element containing a unique
identifier enclosed in double square brackets. It is used to assign an
identifier to the ensuing block element for use by referring links.
For example:
[[chapter-titles]]
Chapter titles can be ...
The preceding example identifies the following paragraph so it can be
linked from other location, for example with
<<chapter-titles,chapter titles>>.
BlockId elements can be applied to Title, Paragraph, List,
DelimitedBlock, Table and BlockMacro elements. The BlockId element
sets the {id} attribute for substitution in the subsequent block’s
markup template. If a second argument is supplied it sets the
{reftext} attribute which is used to set the DocBook xreflabel
attribute.
The BlockId element has the same syntax and serves a similar
function to the anchor inline macro.
An AttributeList block element is an attribute list on a
line by itself. AttributeList attributes are only applied to the
following block element — the attributes are available for markup
template substitution. Often the first attribute in the list is used
to specify the following element’s style.
By default only attribute references are substituted within attribute
values, this is because not all attributes are destined to be marked
up and rendered as text (for example the table cols attribute). To
perform normal inline text substitutions (special characters, quotes,
macros, replacements) on an attribute value you need to enclose it in
single quotes. In the following quote block the second attribute value
in the AttributeList is quoted to ensure the http macro is expanded
to a hyperlink.
[quote,'http://en.wikipedia.org/wiki/Samuel_Johnson[Samuel Johnson]']
_____________________________________________________________________
Sir, a woman's preaching is like a dog's walking on his hind legs. It
is not done well; but you are surprised to find it done at all.
_____________________________________________________________________
11.1. Common attributes
Most block elements support the following attributes:
Name |
Backends |
Description |
id |
html4, xhtml11, docbook |
Unique identifier typically serve as link targets.
Can also be set by the BlockId element. |
role |
docbook |
Role contains a string used to classify or subclassify an element.
Used to add the role attribute to DocBook block elements. |
reftext |
docbook |
reftext is used to set the DocBook xreflabel attribute.
Can also be set by the BlockId element. |
Paragraphs are blocks of text terminated by a blank line, the end of
file, or the start of a DelimitedBlock. Paragraph markup is specified
by configuration file [paradef*] sections.
Normal paragraphs consist of one or more non-blank lines of text. The
first line must start hard against the left margin (no intervening
white space). The default processing expectation is that of a normal
paragraph of text. literal and verse paragraph styles are
available (in addition to the default paragraph style).
12.1. literal paragraph style
Literal paragraphs are rendered verbatim in a monospaced font without
any distinguishing background or border. By default there is no text
formatting or substitutions within Literal paragraphs apart from
Special Characters and Callouts. For example:
[literal]
Consul *necessitatibus* per id,
consetetur, eu pro everti postulant
homero verear ea mea, qui.
Consul *necessitatibus* per id,
consetetur, eu pro everti postulant
homero verear ea mea, qui.
12.2. verse paragraph style
The verse paragraph style preserves line boundaries and is
useful for lyrics and poems. For example:
[verse]
Consul *necessitatibus* per id,
consetetur, eu pro everti postulant
homero verear ea mea, qui.
Consul necessitatibus per id,
consetetur, eu pro everti postulant
homero verear ea mea, qui.
12.3. Indented paragraphs
Indented paragraphs (the first line indented by one or more space or
tab characters) are rendered using the literal paragraph style. For example:
Consul *necessitatibus* per id,
consetetur, eu pro everti postulant
homero verear ea mea, qui.
Consul *necessitatibus* per id,
consetetur, eu pro everti postulant
homero verear ea mea, qui.
|
Because lists can be indented it’s possible for your
indented paragraph to be misinterpreted as a list — in situations
like this apply the literal style to a normal paragraph. |
12.4. Admonition Paragraphs
Tip, Note, Important, Warning and Caution paragraph
definitions support the corresponding DocBook admonishment elements — just write a normal paragraph but place NOTE:, TIP:, IMPORTANT:,
WARNING: or CAUTION: as the first word of the paragraph. For
example:
NOTE: This is an example note.
or the alternative syntax:
[NOTE]
This is an example note.
|
This is an example note. |
|
If your admonition is more than a single paragraph use an
admonition block instead. |
12.4.1. Admonition Icons and Captions
|
Admonition customization with icons, iconsdir, icon and
caption attributes does not apply when generating DocBook output. If
you are going the DocBook route then the a2x(1) --no-icons
and --icons-dir options can be used to set the appropriate XSL
Stylesheets parameters. |
By default the asciidoc(1) xhtml11 and html4 backends generate
text captions instead of icon image links. To generate links to icon
images define the icons attribute, for example using the -a
icons command-line option.
The iconsdir attribute sets the location of linked icon
images.
You can override the default icon image using the icon attribute to
specify the path of the linked image. For example:
[icon="./images/icons/wink.png"]
NOTE: What lovely war.
Use the caption attribute to customize the admonition captions (not
applicable to docbook backend). The following example suppresses the
icon image and customizes the caption of a NOTE admonition (undefining
the icons attribute with icons=None is only necessary if
admonition icons have been enabled):
[icons=None, caption="My Special Note"]
NOTE: This is my special note.
Delimited blocks are blocks of text enveloped by leading and trailing
delimiter lines (normally a series of four or more repeated
characters). The behavior of Delimited Blocks is specified by entries
in configuration file [blockdef*] sections.
13.1. Predefined Delimited Blocks
AsciiDoc ships with a number of predefined DelimitedBlocks (see the
asciidoc.conf configuration file in the asciidoc(1) program
directory):
Predefined delimited block underlines:
CommentBlock: //////////////////////////
PassthroughBlock: ++++++++++++++++++++++++++
ListingBlock: --------------------------
LiteralBlock: ..........................
SidebarBlock: **************************
QuoteBlock: __________________________
ExampleBlock: ==========================
OpenBlock: --
Default DelimitedBlock substitutions
|
Attributes |
Callouts |
Macros |
Quotes |
Replacements |
Special chars |
Special words |
PassthroughBlock |
Yes |
No |
Yes |
No |
No |
No |
No |
ListingBlock |
No |
Yes |
No |
No |
No |
Yes |
No |
LiteralBlock |
No |
Yes |
No |
No |
No |
Yes |
No |
SidebarBlock |
Yes |
No |
Yes |
Yes |
Yes |
Yes |
Yes |
QuoteBlock |
Yes |
No |
Yes |
Yes |
Yes |
Yes |
Yes |
ExampleBlock |
Yes |
No |
Yes |
Yes |
Yes |
Yes |
Yes |
OpenBlock |
Yes |
No |
Yes |
Yes |
Yes |
Yes |
Yes |
13.2. Listing Blocks
ListingBlocks are rendered verbatim in a monospaced font, they
retain line and whitespace formatting and are often distinguished by a
background or border. There is no text formatting or substitutions
within Listing blocks apart from Special Characters and Callouts.
Listing blocks are often used for computer output and file listings.
--------------------------------------
#include <stdio.h>
int main() {
printf("Hello World!\n");
exit(0);
}
--------------------------------------
Which will be rendered like:
#include <stdio.h>
int main() {
printf("Hello World!\n");
exit(0);
}
By convention filter blocks use the listing block syntax and
are implemented as listing block styles.
13.3. Literal Blocks
LiteralBlocks behave just like LiteralParagraphs except you don’t
have to indent the contents.
If the listing style is applied to a LiteralBlock it will be
rendered as a ListingBlock (this is handy if you have a listing
containing a ListingBlock).
...................................
Consul *necessitatibus* per id,
consetetur, eu pro everti postulant
homero verear ea mea, qui.
...................................
Consul *necessitatibus* per id,
consetetur, eu pro everti postulant
homero verear ea mea, qui.
A sidebar is a short piece of text presented outside the narrative
flow of the main text. The sidebar is normally presented inside a
bordered box to set it apart from the main text.
The sidebar body is treated like a normal section body.
.An Example Sidebar
************************************************
Any AsciiDoc SectionBody element (apart from
SidebarBlocks) can be placed inside a sidebar.
************************************************
Which will be rendered like:
Apply the abstract style to generate an abstract, for example:
[abstract]
************************************************
In this paper we will attempt to...
************************************************
13.5. Comment Blocks
The contents of CommentBlocks are not processed; they are useful for
annotations and for excluding new or outdated content that you don’t
want displayed. CommentBlocks are never written to output files.
Example:
//////////////////////////////////////////
CommentBlock contents are not processed by
asciidoc(1).
//////////////////////////////////////////
|
System macros are executed inside comment blocks. |
13.6. Passthrough Blocks
By default the block contents is subject to attribute and macro
substitution, no other markup is generated. PassthroughBlock content
will often be backend specific. Here’s an example:
++++++++++++++++++++++++++++++++++++++
<table border="1"><tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr></table>
++++++++++++++++++++++++++++++++++++++
Use and explicit subs attribute to control substitution. The
following styles can be applied to passthrough blocks:
-
pass
-
By default no substitutions are performed.
-
asciimath, latexmath
-
By default no substitutions are performed, the contents are rendered
as mathematical formulas.
13.7. Quote Blocks
QuoteBlocks are used for quoted passages of text. There are two
styles: quote and verse. The style is set by the first positional
attribute, if no style attribute is specified the quote style. The
optional attribution and citetitle attributes (positional
attributes 2 and 3) specify the quote’s author and source.
The quote style treats the content like a SectionBody, for example:
[quote, Bertrand Russell, The World of Mathematics (1956)]
____________________________________________________________________
A good notation has subtlety and suggestiveness which at times makes
it almost seem like a live teacher.
____________________________________________________________________
A good notation has subtlety and suggestiveness which at times makes
it almost seem like a live teacher.
The World of Mathematics (1956)
— Bertrand Russell
The verse style
retains the content’s line breaks, for example:
[verse, William Blake, from Auguries of Innocence]
__________________________________________________
To see a world in a grain of sand,
And a heaven in a wild flower,
Hold infinity in the palm of your hand,
And eternity in an hour.
__________________________________________________
To see a world in a grain of sand,
And a heaven in a wild flower,
Hold infinity in the palm of your hand,
And eternity in an hour.
from Auguries of Innocence
— William Blake
13.8. Example Blocks
ExampleBlocks encapsulate the DocBook Example element and are used
for, well, examples. Example blocks can be titled by preceding them
with a BlockTitle. DocBook toolchains normally number examples and
generate a List of Examples backmatter section.
Example blocks are delimited by lines of equals characters and you can
put any block elements apart from Titles, BlockTitles and Sidebars)
inside an example block. For example:
.An example
=====================================================================
Qui in magna commodo, est labitur dolorum an. Est ne magna primis
adolescens.
=====================================================================
An example
Qui in magna commodo, est labitur dolorum an. Est ne magna primis
adolescens.
A title prefix that can be inserted with the caption attribute
(xhtml11 and html4 backends). For example:
[caption="Example 1: "]
.An example with a custom caption
=====================================================================
Qui in magna commodo, est labitur dolorum an. Est ne magna primis
adolescens.
=====================================================================
13.9. Admonition Blocks
The ExampleBlock definition includes a set of admonition
styles (NOTE, TIP, IMPORTANT, WARNING, CAUTION) for generating
admonition blocks (admonitions containing more than just a
simple paragraph). Just precede the ExampleBlock with an
attribute list containing the admonition style name. For example:
[NOTE]
.A NOTE block
=====================================================================
Qui in magna commodo, est labitur dolorum an. Est ne magna primis
adolescens.
. Fusce euismod commodo velit.
. Vivamus fringilla mi eu lacus.
.. Fusce euismod commodo velit.
.. Vivamus fringilla mi eu lacus.
. Donec eget arcu bibendum
nunc consequat lobortis.
=====================================================================
|
A NOTE block
Qui in magna commodo, est labitur dolorum an. Est ne magna primis
adolescens.
-
Fusce euismod commodo velit.
-
Vivamus fringilla mi eu lacus.
-
Fusce euismod commodo velit.
-
Vivamus fringilla mi eu lacus.
-
Donec eget arcu bibendum
nunc consequat lobortis.
|
13.10. Open Blocks
An OpenBlock renders the block contents without any opening or
closing tags. The open block start and end delimiter is a single line
containing two dashes. Enclosed elements are rendered just as they
would inside a section body. Open blocks are used for list item continuation.
List types
-
Bulleted lists. Also known as itemized or unordered lists.
-
Numbered lists. Also called ordered lists.
-
Labeled lists. Sometimes called variable or definition lists.
-
Callout lists (a list of callout annotations).
List behavior
-
List item indentation is optional and does not determine nesting,
indentation does however make the source more readable.
-
Another list or a literal paragraph immediately following a list
item will be implicitly included in the list item; use list item continuation to explicitly append other block elements to a
list item.
-
A comment block or a comment line block macro element will terminate
a list — use inline comment lines to put comments inside lists.
-
The listindex intrinsic attribute is the current list item
index (1..). If this attribute is not inside a list then it’s value
is the number of items in the most recently closed list. Useful for
displaying the number of items in a list.
14.1. Bulleted Lists
Bulleted list items start with a single dash or one to five asterisks
followed by some white space then some text. Bulleted list syntaxes
are:
- List item.
* List item.
** List item.
*** List item.
**** List item.
***** List item.
14.2. Numbered Lists
List item numbers are explicit or implicit.
Explicit numbering
List items begin with a number followed by some white space then the
item text. The numbers can be decimal (arabic), roman (upper or lower
case) or alpha (upper or lower case). Decimal and alpha numbers are
terminated with a period, roman numbers are terminated with a closing
parenthesis. The different terminators are necessary to ensure i,
v and x roman numbers are are distinguishable from x, v and
x alpha numbers. Examples:
1. Arabic (decimal) numbered list item.
a. Lower case alpha (letter) numbered list item.
F. Upper case alpha (letter) numbered list item.
iii) Lower case roman numbered list item.
IX) Upper case roman numbered list item.
Implicit numbering
List items begin one to five period characters, followed by some white
space then the item text. Examples:
. Arabic (decimal) numbered list item.
.. Lower case alpha (letter) numbered list item.
... Lower case roman numbered list item.
.... Upper case alpha (letter) numbered list item.
..... Upper case roman numbered list item.
You can use the style attribute to specify an alternative numbering
style. The numbered list style can be one of the following values:
arabic, loweralpha, upperalpha, lowerroman, upperroman.
Here are some examples of bulleted and numbered lists:
- Praesent eget purus quis magna eleifend eleifend.
1. Fusce euismod commodo velit.
a. Fusce euismod commodo velit.
b. Vivamus fringilla mi eu lacus.
c. Donec eget arcu bibendum nunc consequat lobortis.
2. Vivamus fringilla mi eu lacus.
i) Fusce euismod commodo velit.
ii) Vivamus fringilla mi eu lacus.
3. Donec eget arcu bibendum nunc consequat lobortis.
4. Nam fermentum mattis ante.
- Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
* Fusce euismod commodo velit.
** Qui in magna commodo, est labitur dolorum an. Est ne magna primis
adolescens. Sit munere ponderum dignissim et. Minim luptatum et
vel.
** Vivamus fringilla mi eu lacus.
* Donec eget arcu bibendum nunc consequat lobortis.
- Nulla porttitor vulputate libero.
. Fusce euismod commodo velit.
. Vivamus fringilla mi eu lacus.
[upperroman]
.. Fusce euismod commodo velit.
.. Vivamus fringilla mi eu lacus.
. Donec eget arcu bibendum nunc consequat lobortis.
-
Praesent eget purus quis magna eleifend eleifend.
-
Fusce euismod commodo velit.
-
Fusce euismod commodo velit.
-
Vivamus fringilla mi eu lacus.
-
Donec eget arcu bibendum nunc consequat lobortis.
-
Vivamus fringilla mi eu lacus.
-
Fusce euismod commodo velit.
-
Vivamus fringilla mi eu lacus.
-
Donec eget arcu bibendum nunc consequat lobortis.
-
Nam fermentum mattis ante.
-
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
-
Nulla porttitor vulputate libero.
-
Fusce euismod commodo velit.
-
Vivamus fringilla mi eu lacus.
-
Fusce euismod commodo velit.
-
Vivamus fringilla mi eu lacus.
-
Donec eget arcu bibendum nunc consequat lobortis.
A predefined compact option is available to bulleted and numbered
lists — this translates to the DocBook spacing="compact" lists
attribute which may or may not be processed by the DocBook toolchain.
Example:
[options="compact"]
- Compact list item.
- Another compact list item.
|
To apply the compact option globally define a document-wide
compact-option attribute, e.g. using the -a compact-option
command-line option. |
14.3. Labeled Lists
Labeled list items consist of one or more text labels followed the
text of the list item.
An item label begins a line with an alphanumeric character hard
against the left margin and ends with one to four colons or two
semi-colons. A list item can have multiple labels, one per line.
The list item text consists of one or more lines of text starting
after the last label (either on the same line or a new line) and can
be followed by nested List or ListParagraph elements. Item text can be
optionally indented.
In::
Lorem::
Fusce euismod commodo velit.
Fusce euismod commodo velit.
Ipsum:: Vivamus fringilla mi eu lacus.
* Vivamus fringilla mi eu lacus.
* Donec eget arcu bibendum nunc consequat lobortis.
Dolor::
Donec eget arcu bibendum nunc consequat lobortis.
Suspendisse;;
A massa id sem aliquam auctor.
Morbi;;
Pretium nulla vel lorem.
In;;
Dictum mauris in urna.
Vivamus::: Fringilla mi eu lacus.
Donec::: Eget arcu bibendum nunc consequat lobortis.
-
In
-
Lorem
-
Fusce euismod commodo velit.
Fusce euismod commodo velit.
-
Ipsum
-
Vivamus fringilla mi eu lacus.
-
Dolor
-
Donec eget arcu bibendum nunc consequat lobortis.
-
Suspendisse
-
A massa id sem aliquam auctor.
-
Morbi
-
Pretium nulla vel lorem.
-
In
-
Dictum mauris in urna.
-
Vivamus
-
Fringilla mi eu lacus.
-
Donec
-
Eget arcu bibendum nunc consequat lobortis.
14.3.1. Horizontal labeled list style
The horizontal labeled list style places the list text side-by-side
with the label instead of under the label. Here is an example:
[horizontal]
*Lorem*:: Fusce euismod commodo velit. Qui in magna commodo, est
labitur dolorum an. Est ne magna primis adolescens.
Fusce euismod commodo velit.
*Ipsum*:: Vivamus fringilla mi eu lacus.
- Vivamus fringilla mi eu lacus.
- Donec eget arcu bibendum nunc consequat lobortis.
*Dolor*::
- Vivamus fringilla mi eu lacus.
- Donec eget arcu bibendum nunc consequat lobortis.
Lorem
|
Fusce euismod commodo velit. Qui in magna commodo, est
labitur dolorum an. Est ne magna primis adolescens.
Fusce euismod commodo velit.
|
Ipsum
|
Vivamus fringilla mi eu lacus.
|
Dolor
|
|
|
-
Current PDF toolchains do not make a good job of determining
the relative column widths for horizontal labeled lists.
-
If you are generating DocBook markup then horizontal labeled lists
should not be nested because the DocBook XML V4.2 DTD does not
permit nested informal tables (although DocBook XSL Stylesheets and dblatex process them correctly).
-
The label width can be set as a percentage of the total width by
setting the width attribute e.g. width="10%"
|
14.4. Question and Answer Lists
AsciiDoc comes pre-configured with a qanda style labeled list for generating
DocBook question and answer (Q&A) lists. Example:
[qanda]
Question one::
Answer one.
Question two::
Answer two.
-
Question one
Answer one.
-
Question two
Answer two.
14.5. Glossary Lists
AsciiDoc comes pre-configured with a glossary style labeled list for
generating DocBook glossary lists. Example:
[glossary]
A glossary term::
The corresponding definition.
A second glossary term::
The corresponding definition.
For working examples see the article.txt and book.txt documents in
the AsciiDoc ./doc distribution directory.
|
To generate valid DocBook output glossary lists must be located
in a glossary section. |
14.6. Bibliography Lists
AsciiDoc comes with a predefined bibliography bulleted list style
generating DocBook bibliography entries. Example:
[bibliography]
- [[[taoup]]] Eric Steven Raymond. 'The Art of UNIX
Programming'. Addison-Wesley. ISBN 0-13-142901-9.
- [[[walsh-muellner]]] Norman Walsh & Leonard Muellner.
'DocBook - The Definitive Guide'. O'Reilly & Associates.
1999. ISBN 1-56592-580-7.
The [[[<reference>]]] syntax is a bibliography entry anchor, it
generates an anchor named <reference> and additionally displays
[<reference>] at the anchor position. For example [\[[taoup]]]
generates an anchor named taoup that displays [taoup] at the
anchor position. Cite the reference from elsewhere your document using
<<taoup>>, this displays a hyperlink ([taoup]) to the
corresponding bibliography entry anchor.
For working examples see the article.txt and book.txt documents in
the AsciiDoc ./doc distribution directory.
|
To generate valid DocBook output bibliography lists must be
located in a bibliography section. |
14.7. List Item Continuation
Another list or a literal paragraph immediately following a list item
is implicitly appended to the list item; to append other block
elements to a list item you need to explicitly join them to the list
item with a list continuation (a separator line containing a single
plus character). Multiple block elements can be appended to a list
item using list continuations (provided they are legal list item
children in the backend markup).
Here are some examples of list item continuations: list item one
contains multiple continuations; list item two is continued with an
OpenBlock containing multiple elements:
1. List item one.
+
List item one continued with a second paragraph followed by an
Indented block.
+
.................
$ ls *.sh
$ mv *.sh ~/tmp
.................
+
List item continued with a third paragraph.
2. List item two continued with an open block.
+
--
This paragraph is part of the preceding list item.
a. This list is nested and does not require explicit item continuation.
+
This paragraph is part of the preceding list item.
b. List item b.
This paragraph belongs to item two of the outer list.
--
-
List item one.
List item one continued with a second paragraph followed by an
Indented block.
$ ls *.sh
$ mv *.sh ~/tmp
List item continued with a third paragraph.
-
List item two continued with an open block.
This paragraph is part of the preceding list item.
-
This list is nested and does not require explicit item continuation.
This paragraph is part of the preceding list item.
-
List item b.
This paragraph belongs to item two of the outer list.
The shipped AsciiDoc configuration includes the footnote:[<text>]
and footnoteref:[<id>,<text>] inline macros for generating
footnotes:
-
The footnote macro generates a footnote.
-
The footnoteref macro has two forms: if the text is supplied a
foot note with an ID is generated; if the text is omitted a
reference to the footnote with the specified ID is generated.
-
The footnote text can span multiple lines.
A footnote footnote:[An example footnote.];
a second footnote with a reference ID footnoteref:[note2,Second footnote.];
finally a reference to the second footnote footnoteref:[note2].
A footnote
[An example footnote.]
;
a second footnote with a reference ID
Footnote note2 [Second footnote]
;
finally a reference to the second footnote
[See footnote note2]
.
Footnotes are primarily useful when generating DocBook output — DocBook conversion programs render footnote outside the primary text
flow.
The shipped AsciiDoc configuration includes the inline macros for
generating document index entries.
-
indexterm:[<primary>,<secondary>,<tertiary>]
-
(((<primary>,<secondary>,<tertiary>)))
-
This inline macro generates an index term (the <secondary> and
<tertiary> attributes are optional). For example
indexterm:[Tigers,Big cats] (or, using the alternative syntax
(((Tigers,Big cats))). Index terms that have secondary and
tertiary entries also generate separate index terms for the
secondary and tertiary entries. The index terms appear in the
index, not the primary text flow.
-
indexterm2:[<primary>]
-
((<primary>))
-
This inline macro generates an index term that appears in both the
index and the primary text flow. The <primary> should not be
padded to the left or right with white space characters.
For working examples see the article.txt and book.txt documents in
the AsciiDoc ./doc distribution directory.
|
Index entries only really make sense if you are generating
DocBook markup — DocBook conversion programs automatically generate
an index at the point an Index section appears in source document. |
Callouts are a mechanism for annotating verbatim text (source code,
computer output and user input for example). Callout markers are
placed inside the annotated text while the actual annotations are
presented in a callout list after the annotated text. Here’s an
example:
.MS-DOS directory listing
-----------------------------------------------------
10/17/97 9:04 <DIR> bin
10/16/97 14:11 <DIR> DOS <1>
10/16/97 14:40 <DIR> Program Files
10/16/97 14:46 <DIR> TEMP
10/17/97 9:04 <DIR> tmp
10/16/97 14:37 <DIR> WINNT
10/16/97 14:25 119 AUTOEXEC.BAT <2>
2/13/94 6:21 54,619 COMMAND.COM <2>
10/16/97 14:25 115 CONFIG.SYS <2>
11/16/97 17:17 61,865,984 pagefile.sys
2/13/94 6:21 9,349 WINA20.386 <3>
-----------------------------------------------------
<1> This directory holds MS-DOS.
<2> System startup code for DOS.
<3> Some sort of Windows 3.1 hack.
MS-DOS directory listing
10/17/97 9:04 <DIR> bin
10/16/97 14:11 <DIR> DOS <1>
10/16/97 14:40 <DIR> Program Files
10/16/97 14:46 <DIR> TEMP
10/17/97 9:04 <DIR> tmp
10/16/97 14:37 <DIR> WINNT
10/16/97 14:25 119 AUTOEXEC.BAT <2>
2/13/94 6:21 54,619 COMMAND.COM <2>
10/16/97 14:25 115 CONFIG.SYS <2>
11/16/97 17:17 61,865,984 pagefile.sys
2/13/94 6:21 9,349 WINA20.386 <3>
-
This directory holds MS-DOS.
-
System startup code for DOS.
-
Some sort of Windows 3.1 hack.
Explanation
-
The callout marks are whole numbers enclosed in angle brackets that
refer to an item index in the following callout list.
-
By default callout marks are confined to LiteralParagraphs,
LiteralBlocks and ListingBlocks (although this is a configuration
file option and can be changed).
-
Callout list item numbering is fairly relaxed — list items can
start with <n>, n> or > where n is the optional list item
number (in the latter case list items starting with a single >
character are implicitly numbered starting at one).
-
Callout lists should not be nested — start list items hard against
the left margin.
-
If you want to present a number inside angle brackets you’ll need to
escape it with a backslash to prevent it being interpreted as a
callout mark.
|
To include callout icons in PDF files generated by
a2x(1) you need to use the --icons command-line option. |
17.1. Implementation Notes
Callout marks are generated by the callout inline macro while
callout lists are generated using the callout list definition. The
callout macro and callout list are special in that they work
together. The callout inline macro is not enabled by the normal
macros substitutions option, instead it has its own callouts
substitution option.
The following attributes are available during inline callout macro
substitution:
-
{index}
-
The callout list item index inside the angle brackets.
-
{coid}
-
An identifier formatted like CO<listnumber>-<index> that
uniquely identifies the callout mark. For example CO2-4
identifies the fourth callout mark in the second set of callout
marks.
The {coids} attribute can be used during callout list item
substitution — it is a space delimited list of callout IDs that refer
to the explanatory list item.
17.2. Including callouts in included code
You can annotate working code examples with callouts — just remember
to put the callouts inside source code comments. This example displays
the test.py source file (containing a single callout) using the
Source Code Highlighter Filter:
AsciiDoc source
[source,python]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include::test.py[]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<1> Print statement.
Included test.py source
print 'Hello World!' # <1>
Macros are a mechanism for substituting parametrized text into output
documents.
Macros have a name, a single target argument and an attribute
list. The usual syntax is <name>:<target>[<attrlist>] (for
inline macros) and <name>::<target>[<attrlist>] (for block
macros). Here are some examples:
http://www.methods.co.nz/asciidoc/index.html[Asciidoc home page]
include::chapt1.txt[tabsize=2]
mailto:srackham@gmail.com[]
Macro behavior
-
<name> is the macro name. It can only contain letters, digits or
dash characters and cannot start with a dash.
-
The optional <target> cannot contain white space characters.
-
<attrlist> is a list of attributes enclosed in square
brackets.
-
] characters in attribute lists that are enclosed in [] brackets
must be escaped with a backslash.
-
Expansion of non-system macro references can normally be escaped by
prefixing a backslash character (see the AsciiDoc FAQ for examples
of exceptions to this rule).
-
System macros cannot be escaped.
-
Attribute references in block macros are expanded.
-
The substitutions performed prior to Inline macro macro expansion
are determined by the inline context.
-
Macros are processed in the order they appear in the configuration
file(s).
-
Calls to inline macros can be nested inside different inline macros
(an inline macro call cannot contain a nested call to itself).
-
In addition to <name>, <target> and <attrlist> the
<passtext> and <subslist> named groups are available to
passthrough macros. A macro is a passthrough macro if the
definition includes a <passtext> named group.
18.1. Inline Macros
Inline Macros occur in an inline element context. Predefined Inline
macros include URLs, image and link macros.
18.1.1. URLs
http, https, ftp, file, mailto and callto URLs are
rendered using predefined inline macros.
-
If you don’t need a customized the link caption you can enter the
http, https, ftp, file URLs and email addresses without any
special macro syntax.
-
If the <attrlist> is empty the URL is displayed.
http://www.methods.co.nz/asciidoc/[The AsciiDoc home page]
http://www.methods.co.nz/asciidoc/
mailto:joe.bloggs@foobar.com[email Joe Bloggs]
joe.bloggs@foobar.com
callto:joe.bloggs[]
-
If the <target> necessitates space characters they should be
replaced by %20. For example large%20image.png.
-
Define an attribute entry if you refer to the same URL more than
once, this will make your document easier to maintain and easier to read.
18.1.2. Internal Cross References
Two AsciiDoc inline macros are provided for creating hypertext links
within an AsciiDoc document. You can use either the standard macro
syntax or the (preferred) alternative.
anchor
Used to specify hypertext link targets:
[[<id>,<xreflabel>]]
anchor:<id>[<xreflabel>]
The <id> is a unique identifier that must begin with a letter. The
optional <xreflabel> is the text to be displayed by captionless
xref macros that refer to this anchor. The optional <xreflabel> is
only really useful when generating DocBook output. Example anchor:
You may have noticed that the syntax of this inline element is the
same as that of the BlockId block element, this is no
coincidence since they are functionally equivalent.
xref
Creates a hypertext link to a document anchor.
<<<id>,<caption>>>
xref:<id>[<caption>]
The <id> refers to an existing anchor <id>. The optional
<caption> is the link’s displayed text. Example:
If <caption> is not specified then the displayed text is
auto-generated:
-
The AsciiDoc xhtml11 backend displays the <id> enclosed in
square brackets.
-
If DocBook is produced the DocBook toolchain is responsible for the
displayed text which will normally be the referenced figure, table
or section title number followed by the element’s title text.
[[tiger_image]]
.Tyger tyger
image::tiger.png[]
This can be seen in <<tiger_image>>.
18.1.3. Linking to Local Documents
Hypertext links to files on the local file system are specified using
the link inline macro.
The link macro generates relative URLs. The link macro <target> is
the target file name (relative to the file system location of the
referring document). The optional <caption> is the link’s displayed
text. If <caption> is not specified then <target> is displayed.
Example:
link:downloads/foo.zip[download foo.zip]
You can use the <filename>#<id> syntax to refer to an anchor within
a target document but this usually only makes sense when targeting
HTML documents.
18.1.4. Images
Inline images are inserted into the output document using the image
macro. The inline syntax is:
image:<target>[<attributes>]
The contents of the image file <target> is displayed. To display the
image its file format must be supported by the target backend
application. HTML and DocBook applications normally support PNG or JPG
files.
<target> file name paths are relative to the location of the
referring document.
Image macro attributes
-
The optional first positional attribute list entry specifies the
alternative text which is displayed if the output application is
unable to process the image file. For example:
image:images/logo.png[Company Logo]
-
The optional width and height attributes scale the image size
and can be used in any combination. The units are pixels. The
following example scales the previous example to a height of 32
pixels:
image:images/logo.png["Company Logo",height=32]
-
The optional link attribute is used to link the image to an
external document. The following example links a screenshot
thumbnail to a full size version:
image:screen-thumbnail.png[height=32,link="screen.png"]
-
The optional scaledwidth attribute is only used in DocBook block
images (specifically for PDF documents). The following example
scales the images to 75% of the available print width:
image::images/logo.png["Company Logo",scaledwidth="75%"]
-
The optional align attribute is used for horizontal image
alignment in DocBook block images (specifically for PDF documents).
Allowed values are center, left and right. For example:
image::images/tiger.png["Tiger image",align="left"]
18.2. Block Macros
A Block macro reference must be contained in a single line separated
either side by a blank line or a block delimiter.
Block macros behave just like Inline macros, with the following
differences:
-
They occur in a block context.
-
The default syntax is <name>::<target>[<attrlist>] (two
colons, not one).
-
Markup template section names end in -blockmacro instead of
-inlinemacro.
18.2.1. Block Identifier
The Block Identifier macro sets the id attribute and has the same
syntax as the anchor inline macro since it performs
essentially the same function — block templates employ the id
attribute as a block link target. For example:
This is equivalent to the [id="X30"] block attribute list.
18.2.2. Images
Formal titled images are inserted into the output document using the
image macro. The syntax is:
image::<target>[<attributes>]
Images can be titled by preceding the image macro with a
BlockTitle. DocBook toolchains normally number examples and
generate a List of Figures backmatter section.
.Main circuit board
image::images/layout.png[J14P main circuit board]
A title prefix that can be inserted with the caption attribute
(xhtml11 and html4 backends). For example:
.Main circuit board
[caption="Figure 2: "]
image::images/layout.png[J14P main circuit board]
18.2.3. Comment Lines
Single lines starting with two forward slashes hard up against the
left margin are treated as comments. Comment lines do not appear in
the output unless the showcomments attribute is defined. Comment
lines have been implemented as both block and inline macros so a
comment line can appear as a standalone block or within block elements
that support inline macro expansion. Example comment line:
If the showcomments attribute is defined comment lines are written
to the output:
-
The normal AsciiDoc inline text formatting is applied to comment
lines.
-
In DocBook the comment lines are enclosed by the remark element
(which may or may not be rendered by your toolchain).
-
The showcomments attribute does not expose Comment Blocks.
Comment Blocks are never passed to the output.
18.3. System Macros
System macros are block macros that perform a predefined task and are
hardwired into the asciidoc(1) program.
-
You can escape system macros with a leading backslash character
(as you can with other macros).
-
The syntax and tasks performed by system macros is built into
asciidoc(1) so they don’t appear in configuration files. You can
however customize the syntax by adding entries to a configuration
file [macros] section.
18.3.1. Include Macros
The include and include1 system macros to include the contents of
a named file into the source document.
The include macro includes a file as if it were part of the parent
document — tabs are expanded and system macros processed. The
contents of include1 files are not subject to tab expansion or
system macro processing nor are attribute or lower priority
substitutions performed. The include1 macro’s intended use is to
include verbatim embedded CSS or scripts into configuration file
headers. Example:
include::chapter1.txt[tabsize=4]
Include macro behavior
-
If the included file name is specified with a relative path then the
path is relative to the location of the referring document.
-
Include macros can appear inside configuration files.
-
Files included from within DelimitedBlocks are read to completion
to avoid false end-of-block underline termination.
-
Attribute references are expanded inside the include target; if an
attribute is undefined then the included file is silently skipped.
-
The tabsize macro attribute sets the number of space characters to
be used for tab expansion in the included file (not applicable to
include1 macro).
-
The depth macro attribute sets the maximum permitted number of
subsequent nested includes (not applicable to include1 macro which
does not process nested includes). Setting depth to one disables
nesting inside the included file. By default, nesting is limited to
a depth of five.
-
Internally the include1 macro is translated to the include1
system attribute which means it must be evaluated in a region where
attribute substitution is enabled. To inhibit nested substitution in
included files it is preferable to use the include macro and set
the attribute depth=1.
18.3.2. Conditional Inclusion Macros
Lines of text in the source document can be selectively included or
excluded from processing based on the existence (or not) of a document
attribute. There are two conditional inclusion macros; the first
includes document text between the ifdef and endif macros if a
document attribute is defined:
ifdef::<attribute>[]
:
endif::<attribute>[]
The second includes document text between the ifndef and endif
macros if the attribute is not defined:
ifndef::<attribute>[]
:
endif::<attribute>[]
<attribute> is an attribute name which is optional in the trailing
endif macro.
If you only want to process a single line of text then the text can be
put inside the square brackets and the endif macro omitted, for
example:
ifdef::revnumber[Version number 42]
ifdef::revnumber[]
Version number 42
endif::revnumber[]
Take a look at the *.conf configuration files in the AsciiDoc
distribution for examples of conditional inclusion macro usage.
18.3.3. eval, sys and sys2 System Macros
These block macros exhibit the same behavior as their same named
system attribute references. The difference is that system
macros occur in a block macro context whereas system attributes are
confined to an inline context where attribute substitution is enabled.
The following example displays a long directory listing inside a
literal block:
------------------
sys::[ls -l *.txt]
------------------
18.3.4. Template System Macro
The template block macro allows the inclusion of one configuration
file template section within another. The following example includes
the [admonitionblock] section in the [admonitionparagraph]
section:
[admonitionparagraph]
template::[admonitionblock]
Template macro behavior
-
The template::[] macro is useful for factoring configuration file
markup.
-
template::[] macros cannot be nested.
-
template::[] macro expansion is applied to all sections
after all configuration files have been read.
18.4. Passthrough macros
Passthrough macros are analogous to passthrough blocks and are
used to pass text directly to the output. The substitution performed
on the text is determined by the macro definition but can be overridden
by the <subslist>. The usual syntax is
<name>:<subslist>[<passtext>] (for inline macros) and
<name>::<subslist>[<passtext>] (for block macros).
-
pass
-
Inline and block. Passes text unmodified apart from explicitly
specified substitutions). Examples:
pass:[<q>To be or not to be</q>]
pass:attributes,quotes[<u>the '{author}'</u>]
-
asciimath, latexmath
-
Inline and block. Passes text unmodified. Used for
mathematical formulas.
-
+++
-
Inline and block. The triple-plus passthrough is functionally
identical to the pass macro but you don’t have to escape ]
characters and you can prefix with quoted attributes in the inline
version. Example:
Red [red]+++`sum_(i=1)\^n i=(n(n+1))/2`$+++ AsciiMathML formula
-
$$
-
Inline and block. The double-dollar passthrough is functionally
identical with one exception: special characters are escaped.
Example:
$$`[[a,b],[c,d]]((n),(k))`$$
-
`
-
Text quoted with single backtick characters constitutes an inline
literal passthrough. The enclosed text is rendered in a monospaced
font and is only subject to special character substitution. This
makes sense since monospace text is usually intended to be rendered
literally and often contains characters that would otherwise have to
be escaped. If you need monospaced text containing inline
substitutions use a plus character instead of a backtick.
18.5. Macro Definitions
Each entry in the configuration [macros] section is a macro
definition which can take one of the following forms:
-
<pattern>=<name>[<subslist]
-
Inline macro definition.
-
<pattern>=#<name>[<subslist]
-
Block macro definition.
-
<pattern>=+<name>[<subslist]
-
System macro definition.
-
<pattern>
-
Delete the existing macro with this <pattern>.
<pattern> is a Python regular expression and <name> is the name of
a markup template. If <name> is omitted then it is the value of the
regular expression match group named name. The optional
[<subslist] is a comma-separated list of substitution names enclosed
in [] brackets, it sets the default substitutions for passthrough
text, if omitted then no passthrough substitutions are performed.
Pattern named groups
The following named groups can be used in macro <pattern> regular
expressions and are available as markup template attributes:
-
name
-
The macro name.
-
target
-
The macro target.
-
attrlist
-
The macro attribute list.
-
passtext
-
Contents of this group are passed unmodified to the output subject
only to subslist substitutions.
-
subslist
-
Processed as a comma-separated list of substitution names for
passtext substitution, overrides the the macro definition
subslist.
Here’s what happens during macro substitution
-
Each contextually relevant macro pattern from the [macros]
section is matched against the input source line.
-
If a match is found the text to be substituted is loaded from a
configuration markup template section named like
<name>-inlinemacro or <name>-blockmacro (depending on the macro
type).
-
Global and macro attribute list attributes are substituted in the
macro’s markup template.
-
The substituted template replaces the macro reference in the output
document.
The AsciiDoc table syntax looks and behaves like other delimited block
types and supports standard block configuration entries.
Formatting is easy to read and, just as importantly, easy to enter.
-
Cells and columns can be formatted using built-in customizable styles.
-
Horizontal and vertical cell alignment can be set on columns and
cell.
-
Horizontal and vertical cell spanning is supported.
19.1. Example tables
Simple table
1 |
2 |
A |
3 |
4 |
B |
5 |
6 |
C |
AsciiDoc source
[width="15%"]
|=======
|1 |2 |A
|3 |4 |B
|5 |6 |C
|=======
Columns formatted with strong, monospaced and emphasis styles
|
Columns 2 and 3 |
footer 1 |
footer 2 |
footer 3 |
1 |
Item 1 |
Item 1 |
2 |
Item 2 |
Item 2 |
3 |
Item 3 |
Item 3 |
4 |
Item 4 |
Item 4 |
AsciiDoc source
.An example table
[width="50%",cols=">s,^m,e",frame="topbot",options="header,footer"]
|==========================
| 2+|Columns 2 and 3
|1 |Item 1 |Item 1
|2 |Item 2 |Item 2
|3 |Item 3 |Item 3
|4 |Item 4 |Item 4
|footer 1|footer 2|footer 3
|==========================
Horizontal and vertical source data
Date |
Duration |
Avg HR |
Notes |
22-Aug-08 |
10:24 |
157 |
Worked out MSHR (max sustainable heart rate) by going hard
for this interval. |
22-Aug-08 |
23:03 |
152 |
Back-to-back with previous interval. |
24-Aug-08 |
40:00 |
145 |
Moderately hard interspersed with 3x 3min intervals (2min
hard + 1min really hard taking the HR up to 160). |
Short cells can be entered horizontally, longer cells vertically. The
default behavior is to strip leading and trailing blank lines within a
cell. These characteristics aid readability and data entry.
AsciiDoc source
.Windtrainer workouts
[width="80%",cols="3,^2,^2,10",options="header"]
|=========================================================
|Date |Duration |Avg HR |Notes
|22-Aug-08 |10:24 | 157 |
Worked out MSHR (max sustainable heart rate) by going hard
for this interval.
|22-Aug-08 |23:03 | 152 |
Back-to-back with previous interval.
|24-Aug-08 |40:00 | 145 |
Moderately hard interspersed with 3x 3min intervals (2min
hard + 1min really hard taking the HR up to 160).
|=========================================================
A table with externally sourced CSV data
ID |
Customer Name |
Contact Name |
Customer Address |
Phone |
AROUT |
Around the Horn |
Thomas Hardy |
120 Hanover Sq.
London |
(171) 555-7788 |
BERGS |
Berglunds snabbkop |
Christina Berglund |
Berguvsvagen 8
Lulea |
0921-12 34 65 |
BLAUS |
Blauer See Delikatessen |
Hanna Moos |
Forsterstr. 57
Mannheim |
0621-08460 |
BLONP |
Blondel pere et fils |
Frederique Citeaux |
24, place Kleber
Strasbourg |
88.60.15.31 |
BOLID |
Bolido Comidas preparadas |
Martin Sommer |
C/ Araquil, 67
Madrid |
(91) 555 22 82 |
BONAP |
Bon app' |
Laurence Lebihan |
12, rue des Bouchers
Marseille |
91.24.45.40 |
BOTTM |
Bottom-Dollar Markets |
Elizabeth Lincoln |
23 Tsawassen Blvd.
Tsawassen |
(604) 555-4729 |
BSBEV |
B’s Beverages |
Victoria Ashworth |
Fauntleroy Circus
London |
(171) 555-1212 |
CACTU |
Cactus Comidas para llevar |
Patricio Simpson |
Cerrito 333
Buenos Aires |
(1) 135-5555 |
AsciiDoc source
[format="csv",cols="^1,4*2",options="header"]
|===================================================
ID,Customer Name,Contact Name,Customer Address,Phone
include::customers.csv[]
|===================================================
Cell spans, alignments and styles
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
AsciiDoc source
[cols="e,m,^,>s",width="25%"]
|============================
|1 >s|2 |3 |4
^|5 2.2+^.^|6 .3+<.>m|7
^|8
|9 2+>|10
|============================
19.2. Table input data formats
AsciiDoc table data can be psv, dsv or csv formatted. The
default table format is psv.
AsciiDoc psv (Prefix Separated Values) and dsv (Delimiter
Separated Values) formats are cell oriented — the table is treated
as a sequence of cells — there are no explicit row separators.
-
psv prefixes each cell with a separator whereas dsv delimits
cells with a separator, that really the only difference (apart from
different default separators).
-
psv and dsv separators are Python regular expressions.
-
The default psv separator contains cell specifier related
named regular expression groups.
-
The default dsv separator is :|\n (a colon or a line break).
-
psv and dsv cell separators can be escaped by preceding them
with a backslash character.
Here are four psv cells (the second item spans two columns; the
last contains an escaped separator):
|One 2+|Two and three |A \| separator character
csv is the quasi-standard row oriented Comma Separated Values
(CSV) format commonly used to import and export spreadsheet and
database data.
19.3. Table attributes
Individual tables are customized by an optional AttributeList
preceding the table. Specify attributes when you want to change the
default table format:
-
format
-
psv (default), dsv or csv (See Table Data Formats).
-
separator
-
The cell separator. A Python regular expression (psv and dsv
formats) or a single character (csv format).
-
frame
-
Defines the table border and can take the following values: topbot
(top and bottom), all (all sides), none and sides (left and
right sides). The default value is all.
-
grid
-
Defines which ruler lines are drawn between table rows and columns.
The grid attribute value can be any of the following values: none,
cols, rows and all. The default value is all.
-
align
-
Use the align attribute to vertically align all cells in a table.
The following values are valid: left, right, and center
(defaults to left). Overridden by Column specifiers and
Cell specifiers.
-
valign
-
Use the valign attribute to vertically align all cells in a table.
The following values are valid: top, bottom, and middle
(defaults to top). Overridden by Column specifiers and
Cell specifiers.
-
options
-
The options attribute can contain the following comma separated
values: header, footer. By default header and footer rows are
omitted.
-
cols
-
The cols attribute is a comma separated list of column specifiers. For example cols="2<p,2*,4p,>".
-
If cols is present it must specify all columns.
-
If the cols attribute is not specified the number of columns is
calculated as the number of data items in the first line of the
table.
-
The degenerate form for the cols attribute is an integer
specifying the number of columns e.g. cols=4.
-
width
-
The width attribute is expressed as a percentage value
("1%"…"99%"). The width specifies the table width relative to
the available width. HTML outputs use this value directly. If width is
specified DocBook uses the absolute widths (see calculated
markup attributes ), if no width is specified all of the
available width is used.
-
filter
-
The filter attribute defines an external shell command that is
invoked for each cell. The built-in asciidoc table style is
implemented using a filter.
19.4. Column Specifiers
Column specifiers define how columns are rendered and appear in the
table cols attribute. A column specifier consists of an
optional column multiplier followed by optional alignment, width and
style values and is formatted like:
[<multiplier>*][<align>][<width>][<style>]
-
All components are optional. The multiplier must be first and the
style last. The order of <align> or <width> is not important.
-
Column <width> can be either an integer proportional value (1…)
or a percentage (1%…100%). The default value is 1. To ensure
portability across different backends, there is no provision for
absolute column widths (not to be confused with output column width
markup attributes which are available in both percentage and
absolute units).
-
The <align> column alignment specifier is formatted like:
[<horizontal>][.<vertical>]
Where <horizontal> and <vertical> are one of the following
characters: <, ^ or > which represent left, center and
right horizontal alignment or top, middle and bottom vertical
alignment respectively.
-
A <multiplier> can be used to specify repeated columns e.g.
cols="4*<" specifies four left-justified columns. Default value 1.
-
The <style> name specifies a table style to used to markup
column cells (you can use the full style names if you wish but the
first letter is normally sufficient).
-
Column specific styles are not applied to header row formatting.
19.5. Cell Specifiers
Cell specifiers allow individual cells in psv formatted tables to be
spanned, multiplied, aligned and styled. Cell specifiers prefix psv
| delimiters and are formatted like:
[<span>*|+][<align>][<style>]
-
<span> specifies horizontal and vertical cell spans (+ operator) or
the number of times the cell is replicated (* operator). <span>
is formatted like:
Where <colspan> and <rowspan> are integers specifying the number of
columns and rows to span.
-
<align> specifies horizontal and vertical cell alignment an is the
same as in column specifiers.
-
A <style> value is the first letter of table style name.
For example, the following psv formatted cell will span two columns
and the text will be centered and emphasized:
19.6. Table styles
Table styles can be applied to the entire table (by setting the
style attribute in the table’s attribute list) or on a per column
basis (by specifying the style in the table’s cols attribute).
Tables come with the following predefined styles:
-
default
-
The default style: AsciiDoc inline text formatting; blank lines are
treated as paragraph breaks.
-
emphasis
-
Like default but all text is emphasised.
-
monospaced
-
Like default but all text is in a monospaced font.
TODO: This doesn’t work in DocBook.
-
strong
-
Like default but all text is bold.
-
asciidoc
-
With this style table cells can contain any of the AsciiDoc elements
that are allowed inside document sections. This style runs asciidoc(1)
as a filter to process cell contents. See also Docbook table limitations.
-
literal
-
No text formatting; monospaced font; all line breaks are retained
(like AsciiDoc LiteralBlock).
-
verse
-
Text formatting; all line breaks are retained (c.f. AsciiDoc delimited
block verse style).
19.7. Markup attributes
AsciiDoc makes a number of attributes available to table markup
templates and tags. Both absolute and percentage width values are
available. Column specific attributes are available when substituting
the colspec cell data tags.
-
pageunits
-
Only used by DocBook, defaults to pt.
-
pagewidth
-
The nominal output page width in pageunit units. Used to calculate
table and column widths. Only used by DocBook, defaults to 425.
-
tableabswidth
-
Integer value calculated from width and pagewidth attributes.
In pageunit units.
-
tablepcwidth
-
Table width expressed as a percentage of the available width. Integer
value (0..100).
-
colabswidth
-
Integer value calculated from cols column width, width and
pagewidth attributes. In pageunit units.
-
colpcwidth
-
Column width expressed as a percentage of the table width. Integer
value (0..100).
-
colcount
-
Total number of table columns.
-
rowcount
-
Total number of table rows.
-
align
-
left, right or center.
-
valign
-
top, bottom or middle.
-
colnumber, colstart
-
The number of the leftmost column occupied by the cell (1…).
-
colend
-
The number of the rightmost column occupied by the cell (1…).
-
colspan
-
Number of columns the cell should span.
-
rowspan
-
Number of rows the cell should span (1…).
-
morerows
-
Number of additional rows the cell should span (0…).
19.8. Nested tables
An alternative table syntax using a ! character instead of a |
character is provided to allow a single level of table nesting.
Columns containing nested tables must use the asciidoc style. An
example can be found in ./examples/website/newtables.txt.
19.9. DocBook table limitations
Fully implementing tables is not trivial, some DocBook toolchains do
better than others. AsciiDoc HTML table outputs are rendered
correctly in all the popular browsers — if your DocBook generated
tables don’t look right compare them with the output generated by the
AsciiDoc xhtml11 backend or try a different DocBook toolchain. Here
is a list of things to be aware of:
-
Although nested tables are not legal in DocBook 4 the FOP and
dblatex toolchains will process them correctly. If you use a2x(1)
you will need to include the --no-xmllint option to suppress
DocBook validation errors.
|
Technically you can nest DocBook 4 tables one level using the
entrytbl element, but not all toolchains process entrytbl. |
-
DocBook only allows a subset of block elements inside table cells so
not all AsciiDoc elements produce valid DocBook inside table cells.
If you get validation errors running a2x(1) try the --no-xmllint
option, toolchains will often process nested block elements such as
sidebar blocks and floating titles correctly.
-
Text formatting in cells using the monospaced table style will
raise validation errors because the DocBook literal element was
not designed to support formatted text (using the literal element
is a kludge on the part of AsciiDoc as there is no easy way to set
the font style in DocBook.
-
Cell alignments are ignored for verse, literal or asciidoc
table styles.
Sooner or later, if you program for a UNIX environment, you’re going
to have to write a man page.
By observing a couple of additional conventions you can compose
AsciiDoc files that will translate to a DocBook refentry (man page)
document. The resulting DocBook file can then be translated to the
native roff man page format (or other formats).
For example, the asciidoc.1.txt file in the AsciiDoc distribution
./doc directory was used to generate both the
asciidoc.1.css-embedded.html HTML file the asciidoc.1 roff
formatted asciidoc(1) man page.
To find out more about man pages view the man(7) manpage
(man 7 man and man man-pages commands).
A document Header is mandatory. The title line contains the man page
name followed immediately by the manual section number in brackets,
for example ASCIIDOC(1). The title name should not contain white
space and the manual section number is a single digit optionally
followed by a single character.
20.2. The NAME Section
The first manpage section is mandatory, must be titled NAME and must
contain a single paragraph (usually a single line) consisting of a
list of one or more comma separated command name(s) separated from the
command purpose by a dash character. The dash must have at least one
white space character on either side. For example:
printf, fprintf, sprintf - print formatted output
20.3. The SYNOPSIS Section
The second manpage section is mandatory and must be titled SYNOPSIS.
20.4. refmiscinfo attributes
In addition to the automatically created man page intrinsic attributes you can assign DocBook
refmiscinfo
element source, version and manual values using AsciiDoc
{mansource}, {manversion} and {manmanual} attributes
respectively. This example is from the AsciiDoc header of a man page
source file:
:man source: AsciiDoc
:man version: {revnumber}
:man manual: AsciiDoc Manual
The asciimath and latexmath passthrough macros along with
asciimath and latexmath passthrough blocks provide a
(backend dependent) mechanism for rendering mathematical formulas. You
can use the following math markups:
|
The latexmath macro used to include LaTeX Math in DocBook
outputs is not the same as the latexmath macro used to include
LaTeX MathML in XHTML outputs. LaTeX Math applies to DocBook
outputs that are processed by dblatex and is normally used to
generate PDF files. LaTeXMathML is very much a subset of LaTeX
Math and applies to XHTML documents. |
21.1. LaTeX Math
latexmath:[$C = \alpha + \beta Y^{\gamma} + \epsilon$]
For more examples see the AsciiDoc
website or the distributed doc/latexmath.txt file.
21.2. ASCIIMathML
ASCIIMathML
formulas can be included in XHTML documents generated using the
xhtml11 backend. To enable ASCIIMathML support you must define the
asciimath attribute, for example using the -a asciimath
command-line option. Example inline formula:
asciimath:[`x/x={(1,if x!=0),(text{undefined},if x=0):}`]
For more examples see the AsciiDoc
website or the distributed doc/asciimathml.txt file.
21.3. LaTeXMathML
LaTeXMathML allows LaTeX Math style formulas to be included in XHTML
documents generated using the AsciiDoc xhtml11 backend. AsciiDoc
uses the
original
LaTeXMathML by Douglas Woodall. LaTeXMathML is derived from
ASCIIMathML and is for users who are more familiar with or prefer
using LaTeX math formulas (it recognizes a subset of LaTeX Math, the
differences are documented on the LaTeXMathML web page). To enable
LaTeXMathML support you must define the latexmath attribute, for
example using the -a latexmath command-line option. Example inline
formula:
latexmath:[$\sum_{n=1}^\infty \frac{1}{2^n}$]
For more examples see the AsciiDoc
website or the distributed doc/latexmathml.txt file.
21.4. MathML
MathML is a low level XML markup for
mathematics. AsciiDoc has no macros for MathML but users familiar with
this markup could use passthrough macros and passthrough blocks to
include MathML in output documents.
AsciiDoc source file syntax and output file markup is largely
controlled by a set of cascading, text based, configuration files. At
runtime The AsciiDoc default configuration files are combined with
optional user and document specific configuration files.
Configuration files contain named sections. Each section begins with a
section name in square brackets []. The section body consists of the
lines of text between adjacent section headings.
-
Section names consist of one or more alphanumeric, underscore or
dash characters and cannot begin or end with a dash.
-
Lines starting with a hash character "#" are treated as comments and
ignored.
-
Same named sections and section entries override previously loaded
sections and section entries (this is sometimes referred to as
cascading). Consequently, downstream configuration files need
only contain those sections and section entries that need to be
overridden.
|
When creating custom configuration files you only need to include
the sections and entries that differ from the default configuration. |
|
The best way to learn about configuration files is to read the
default configuration files in the AsciiDoc distribution in
conjunction with asciidoc(1) output files. You can view configuration
file load sequence by turning on the asciidoc(1) -v (--verbose)
command-line option. |
AsciiDoc reserves the following section names for specific purposes:
-
miscellaneous
-
Configuration options that don’t belong anywhere else.
-
attributes
-
Attribute name/value entries.
-
specialcharacters
-
Special characters reserved by the backend markup.
-
tags
-
Backend markup tags.
-
quotes
-
Definitions for quoted inline character formatting.
-
specialwords
-
Lists of words and phrases singled out for special markup.
-
replacements, replacements2
-
Find and replace substitution definitions.
-
specialsections
-
Used to single out special section names for specific markup.
-
macros
-
Macro syntax definitions.
-
titles
-
Heading, section and block title definitions.
-
paradef-*
-
Paragraph element definitions.
-
blockdef-*
-
DelimitedBlock element definitions.
-
listdef-*
-
List element definitions.
-
listtags-*
-
List element tag definitions.
-
tabledef-*
-
Table element definitions.
-
tabletags-*
-
Table element tag definitions.
Each line of text in these sections is a section entry. Section
entries share the following syntax:
-
name=value
-
The entry value is set to value.
-
name=
-
The entry value is set to a zero length string.
-
name!
-
The entry is undefined (deleted from the configuration). This
syntax only applies to attributes and miscellaneous
sections.
Section entry behavior
-
All equals characters inside the name must be escaped with a
backslash character.
-
name and value are stripped of leading and trailing white space.
-
Attribute names, tag entry names and markup template section names
consist of one or more alphanumeric, underscore or dash characters.
Names should not begin or end with a dash.
-
A blank configuration file section (one without any entries) deletes
any preceding section with the same name (applies to non-markup
template sections).
22.2. Miscellaneous section
The optional [miscellaneous] section specifies the following
name=value options:
-
newline
-
Output file line termination characters. Can include any
valid Python string escape sequences. The default value is
\r\n (carriage return, line feed). Should not be quoted or
contain explicit spaces (use \x20 instead). For example:
$ asciidoc -a 'newline=\n' -b docbook mydoc.txt
-
outfilesuffix
-
The default extension for the output file, for example
outfilesuffix=.html. Defaults to backend name.
-
tabsize
-
The number of spaces to expand tab characters, for example
tabsize=4. Defaults to 8. A tabsize of zero suppresses tab
expansion (useful when piping included files through block
filters). Included files can override this option using the
tabsize attribute.
-
pagewidth, pageunits
-
These global table related options are documented in the
Table Configuration File Definitions sub-section.
|
[miscellaneous] configuration file entries can be set using
the asciidoc(1) -a (--attribute) command-line option. |
22.3. Titles section
-
sectiontitle
-
Two line section title pattern. The entry value is a Python
regular expression containing the named group title.
-
underlines
-
A comma separated list of document and section title underline
character pairs starting with the section level 0 and ending
with section level 4 underline. The default setting is:
underlines="==","--","~~","^^","++"
-
sect0…sect4
-
One line section title patterns. The entry value is a Python
regular expression containing the named group title.
-
blocktitle
-
BlockTitle element pattern. The entry value is a
Python regular expression containing the named group title.
-
subs
-
A comma separated list of substitutions that are performed on
the document header and section titles. Defaults to normal
substitution.
The [tags] section contains backend tag definitions (one per
line). Tags are used to translate AsciiDoc elements to backend
markup.
An AsciiDoc tag definition is formatted like
<tagname>=<starttag>|<endtag>. For example:
In this example asciidoc(1) replaces the | character with the
emphasized text from the AsciiDoc input file and writes the result to
the output file.
Use the {brvbar} attribute reference if you need to include a | pipe
character inside tag text.
22.5. Attributes section
The optional [attributes] section contains predefined attributes.
If the attribute value requires leading or trailing spaces then the
text text should be enclosed in quotation mark (") characters.
To delete a attribute insert a name! entry in a downstream
configuration file or use the asciidoc(1) --attribute name!
command-line option (an attribute name suffixed with a ! character
deletes the attribute)
22.6. Special Characters section
The [specialcharacters] section specifies how to escape characters
reserved by the backend markup. Each translation is specified on a
single line formatted like:
special_character=translated_characters
Special characters are normally confined to those that resolve
markup ambiguity (in the case of SGML/XML markups the ampersand, less
than and greater than characters). The following example causes all
occurrences of the < character to be replaced by <.
22.7. Quoted Text section
Quoting is used primarily for text formatting. The [quotes] section
defines AsciiDoc quoting characters and their corresponding backend
markup tags. Each section entry value is the name of a of a [tags]
section entry. The entry name is the character (or characters) that
quote the text. The following examples are taken from AsciiDoc
configuration files:
[tags]
emphasis=<em>|</em>
You can specify the left and right quote strings separately by
separating them with a | character, for example:
Omitting the tag will disable quoting, for example, if you don’t want
superscripts or subscripts put the following in a custom configuration
file or edit the global asciidoc.conf configuration file:
Unconstrained quotes are differentiated by prefixing the tag
name with a hash character, for example:
22.8. Special Words section
The [specialwords] section is used to single out words and phrases
that you want to consistently format in some way throughout your
document without having to repeatedly specify the markup. The name of
each entry corresponds to a markup template section and the entry
value consists of a list of words and phrases to be marked up. For
example:
[specialwords]
strongwords=NOTE: IMPORTANT:
[strongwords]
<strong>{words}</strong>
The examples specifies that any occurrence of NOTE: or IMPORTANT:
should appear in a bold font.
Words and word phrases are treated as Python regular expressions: for
example, the word ^NOTE: would only match NOTE: if appeared at
the start of a line.
AsciiDoc comes with three built-in Special Word types:
emphasizedwords, monospacedwords and strongwords, each has a
corresponding (backend specific) markup template section. Edit the
configuration files to customize existing Special Words and to add new
ones.
Special word behavior
-
Word list entries must be separated by space characters.
-
Word list entries with embedded spaces should be enclosed in quotation (")
characters.
-
A [specialwords] section entry of the form
name=word1 [word2…] adds words to existing name entries.
-
A [specialwords] section entry of the form name undefines
(deletes) all existing name words.
-
Since word list entries are processed as Python regular expressions
you need to be careful to escape regular expression special
characters.
-
By default Special Words are substituted before Inline Macros, this
may lead to undesirable consequences. For example the special word
foobar would be expanded inside the macro call
http://www.foobar.com[]. A possible solution is to emphasize
whole words only by defining the word using regular expression
characters, for example \bfoobar\b.
-
If the first matched character of a special word is a backslash then
the remaining characters are output without markup i.e. the
backslash can be used to escape special word markup. For example
the special word \\?\b[Tt]en\b will mark up the words Ten and
ten only if they are not preceded by a backslash.
22.9. Replacements section
[replacements] and [replacements2] configuration file entries
specify find and replace text and are formatted like:
find_pattern=replacement_text
The find text can be a Python regular expression; the replace text can
contain Python regular expression group references.
Use Replacement shortcuts for often used macro references, for
example (the second replacement allows us to backslash escape the
macro name):
NEW!=image:./images/smallnew.png[New!]
\\NEW!=NEW!
Replacement behavior
-
The built-in replacements can be escaped with a backslash.
-
If the find or replace text has leading or trailing spaces then the
text should be enclosed in quotation (") characters.
-
Since the find text is processed as a regular expression you need to
be careful to escape regular expression special characters.
-
Replacements are performed in the same order they appear in the
configuration file replacements section.
22.10. Markup Template Sections
Markup template sections supply backend markup for translating
AsciiDoc elements. Since the text is normally backend dependent
you’ll find these sections in the backend specific configuration
files. Template sections differ from other sections in that they
contain a single block of text instead of per line name=value
entries. A markup template section body can contain:
The document content placeholder is a single | character and is
replaced by text from the source element. Use the {brvbar}
attribute reference if you need a literal | character in the template.
22.11. Configuration File Names and Locations
Configuration files have a .conf file name extension; they are
loaded implicitly (using predefined file names and locations) or
explicitly (using the asciidoc(1) -f (--conf-file) command-line
option).
Implicit configuration files are loaded from the following directories
in the following order:
-
The global configuration directory (normally /etc/asciidoc or
/usr/local/etc/asciidoc) if it exists.
-
The directory containing the asciidoc executable.
-
The user’s $HOME/.asciidoc directory (if it exists).
-
The directory containing the AsciiDoc source file.
The following implicit configuration files from each of the above
locations are loaded in the following order:
-
asciidoc.conf
-
<backend>.conf
-
<backend>-<doctype>.conf
Where <backend> and <doctype> are values specified by the
asciidoc(1) -b (--backend) and -d (--doctype) command-line
options.
Next, configuration files named like the source file will be
automatically loaded if they are found in the source file directory.
For example if the source file is mydoc.txt and the
--backend=html4 option is used then asciidoc(1) will look for
mydoc.conf and mydoc-html4.conf in that order.
Implicit configuration files that don’t exist will be silently
skipped.
The user can explicitly specify additional configuration files using
the asciidoc(1) -f (--conf-file) command-line option. The -f
option can be specified multiple times, in which case configuration
files will be processed in the order they appear on the command-line.
For example, when we translate our AsciiDoc document mydoc.txt with:
$ asciidoc -f extra.conf mydoc.txt
The last configuration file to load is the language configuration file
lang-<lang>.conf. <lang> is the value of the AsciiDoc lang
attribute (defaults to en (English)). You can set the lang
attribute inside the AsciiDoc source file using an
AttributeEntry provided it is the first and entry and provided
it precedes the document header, for example:
Configuration files (if they exist) will be processed in the following
order:
-
First default global configuration files from the asciidoc program
directory are loaded:
asciidoc.conf
xhtml11.conf
-
Then, from the users home ~/.asciidoc directory. This is were
you put customization specific to your own asciidoc documents:
asciidoc.conf
xhtml11.conf
xhtml11-article.conf
-
Next from the source document project directory (the first three
apply to all documents in the directory, the last two are specific
to the mydoc.txt document):
asciidoc.conf
xhtml11.conf
xhtml11-article.conf
mydoc.conf
mydoc-xhtml11.conf
-
Finally the file specified by the -f command-line option is
loaded:
|
Use the asciidoc(1) -v (--verbose) command-line option to see
which configuration files are loaded and the order in which they are
loaded. |
A document attribute is comprised of a name and a textual value
and is used for textual substitution in AsciiDoc documents and
configuration files. An attribute reference (an attribute name
enclosed in braces) is replaced by its corresponding attribute
value.
There are four sources of document attributes (from highest to lowest
precedence):
-
Command-line attributes.
-
AttributeEntry, AttributeList, Macro and BlockId elements.
-
Configuration file [attributes] sections.
-
Intrinsic attributes.
Within each of these divisions the last processed entry takes
precedence.
|
If an attribute is not defined then the line containing the
attribute reference is dropped. This property is used extensively in
AsciiDoc configuration files to facilitate conditional markup
generation. |
The AttributeEntry block element allows document attributes to be
assigned within an AsciiDoc document. Attribute entries are added to
the global document attributes dictionary. The attribute name/value
syntax is a single line like:
This will set an attribute reference {authorinitials} to the value
JB in the current document.
To delete (undefine) an attribute use the following syntax:
AttributeEntry behavior
-
The attribute entry line begins with colon — no white space allowed
in left margin.
-
AsciiDoc converts the <name> to a legal attribute name (lower
case, alphanumeric and dash characters only — all other characters
deleted). This allows more reader friendly text to be used.
-
Leading and trailing white space is stripped from the <value>.
-
If the <value> is blank then the corresponding attribute value is
set to an empty string.
-
Special characters in the entry <value> are substituted. You can
enter special characters using character entity values, for example
&.
-
Attribute references contained in the entry <value> will be
expanded.
-
By default AttributeEntry values are substituted for
specialcharacters and attributes (see above), if you want a
different AttributeEntry substitution set the attributeentry-subs
attribute.
-
Attribute entries in the document Header are available for header
markup template substitution.
-
Attribute elements override configuration file and intrinsic
attributes but do not override command-line attributes.
Here are some more attribute entry examples:
AsciiDoc User Manual
====================
:author: Stuart Rackham
:email: srackham@gmail.com
:revdate: April 23, 2004
:revnumber: 5.1.1
:keywords: linux, ralink, debian, wireless
Which creates these attributes:
{author}, {firstname}, {lastname}, {authorinitials}, {email},
{revdate}, {revnumber}, {keywords}
The preceding example is equivalent to the standard AsciiDoc two line
document header (actually it’s a little bit different because of the
addition of the {keywords} attribute).
24.1. Setting configuration entries
A variant of the Attribute Entry syntax allows configuration file
entries to be set from within an AsciiDoc document:
:<section_name>.<entry_name>: <entry_value>
Where <section_name> is the configuration section name,
<entry_name> is the name of the entry and <entry_value> is the
optional entry value. This example sets the default labeled list style
to horizontal:
:listdef-labeled.style: horizontal
It is exactly equivalent to a configuration file containing:
[listdef-labeled]
style=horizontal
An attribute list is a comma separated list of attribute values. The
entire list is enclosed in square brackets. Attribute lists are used
to pass parameters to macros, blocks and inline quotes:
-
The list consists of zero or more positional attribute values
followed by zero or more named attribute values.
-
Attribute values are enclosed in quotation mark (") characters.
-
If the attribute list only contains positional attribute values and
the values contain no commas then quoting is unnecessary.
Here are three examples (a single unquoted positional attribute; three
unquoted attribute values; one positional attribute followed by two
named attributes):
[Hello]
[quote, Bertrand Russell, The World of Mathematics (1956)]
["22 times", backcolor="#0e0e0e", options="noborders,wide"]
Attribute list behavior
-
If one or more attribute values contains a comma the all string
values must be quoted (enclosed in quotation characters).
-
If the list contains any named or quoted attributes then all string
attribute values must be quoted.
-
To include a quotation mark (") character in a quoted attribute
value the the quotation mark must be escaped with a backslash.
-
List attributes take precedence over existing attributes.
-
List attributes can only be referenced in configuration file markup
templates and tags, they are not available inside the document.
-
Attribute references are allowed inside attribute lists — this is
the only substitution performed on attribute lists.
-
Setting a named attribute to None undefines the attribute.
-
Positional attributes are referred to as {1},{2},{3},…
-
Attribute {0} refers to the entire list (excluding the enclosing
square brackets).
-
Attribute lists are evaluated as a list of Python function
arguments. If this fails or any of the items do not evaluate to a
string, a number or None then all list items are treated as string
literals.
25.1. Options attribute
If the attribute list contains an attribute named options it is
processed as a comma separated list of option names:
-
Each name generates an attribute named like <option>-option (where
<option> is the option name) with an empty string value. For
example [options="opt1,opt2,opt3"] is equivalent to setting the
following three attributes
[opt1-option="",opt2-option="",opt2-option=""].
-
If you define a an option attribute globally (for example with an
attribute entry) then it will apply to all elements in the
document.
-
AsciiDoc implements a number of predefined options which are listed
in the Attribute Options appendix.
25.2. Macro Attribute lists
Macros calls are suffixed with an attribute list. The list may be
empty but it cannot be omitted. List entries are used to pass
attribute values to macro markup templates.
An attribute references is an attribute name (possibly followed by an
additional parameters) enclosed in braces. When an attribute
reference is encountered it is evaluated and replaced by its
corresponding text value. If the attribute is undefined the line
containing the attribute is dropped.
There are three types of attribute reference: Simple, Conditional
and System.
Attribute reference behavior
-
You can suppress attribute reference expansion by placing a
backslash character immediately in front of the opening brace
character.
-
By default attribute references are not expanded in
LiteralParagraphs, ListingBlocks or LiteralBlocks.
26.1. Simple Attributes References
Simple attribute references take the form {<name>}. If the
attribute name is defined its text value is substituted otherwise the
line containing the reference is dropped from the output.
26.2. Conditional Attribute References
Additional parameters are used in conjunction with the attribute name
to calculate a substitution value. Conditional attribute references
take the following forms:
-
{<name>=<value>}
-
<value> is substituted if the attribute <name> is
undefined otherwise its value is substituted. <value> can
contain simple attribute references.
-
{<name>?<value>}
-
<value> is substituted if the attribute <name> is defined
otherwise an empty string is substituted. <value> can
contain simple attribute references.
-
{<name>!<value>}
-
<value> is substituted if the attribute <name> is
undefined otherwise an empty string is substituted. <value>
can contain simple attribute references.
-
{<name>#<value>}
-
<value> is substituted if the attribute <name> is defined
otherwise the undefined attribute entry causes the containing
line to be dropped. <value> can contain simple attribute
references.
-
{<name>%<value>}
-
<value> is substituted if the attribute <name> is not
defined otherwise the containing line is dropped. <value>
can contain simple attribute references.
-
{<name>@<regexp>:<value1>[:<value2>]}
-
<value1> is substituted if the value of attribute <name>
matches the regular expression <regexp> otherwise <value2>
is substituted. If attribute <name> is not defined the
containing line is dropped. If <value2> is omitted an empty
string is assumed. The values and the regular expression can
contain simple attribute references. To embed colons in the
values or the regular expression escape them with backslashes.
-
{<name>$<regexp>:<value1>[:<value2>]}
-
Same behavior as the previous ternary attribute except for
the following cases:
-
{<name>$<regexp>:<value>}
-
Substitutes <value> if <name> matches <regexp>
otherwise the result is undefined and the containing
line is dropped.
-
{<name>$<regexp>::<value>}
-
Substitutes <value> if <name> does not match
<regexp> otherwise the result is undefined and the
containing line is dropped.
26.2.1. Conditional attribute examples
Conditional attributes are mainly used in AsciiDoc configuration
files — see the distribution .conf files for examples.
-
Attribute equality test
-
If {backend} is docbook or xhtml11 the example evaluates to
“DocBook or XHTML backend” otherwise it evaluates to “some other
backend”:
{backend@docbook|xhtml11:DocBook or XHTML backend:some other backend}
-
Attribute value map
-
This example maps the frame attribute values [topbot, all,
none, sides] to [hsides, border, void, vsides]:
{frame@topbot:hsides}{frame@all:border}{frame@none:void}{frame@sides:vsides}
26.3. System Attribute References
System attribute references generate the attribute text value by
executing a predefined action that is parametrized by a single
argument. The syntax is {<action>:<argument>}.
-
{eval:<expression>}
-
Substitutes the result of the Python <expression>. If
<expression> evaluates to None or False the reference is
deemed undefined and the line containing the reference is
dropped from the output. If the expression evaluates to
True the attribute evaluates to an empty string. In all
remaining cases the attribute evaluates to a string
representation of the <expression> result.
-
{include:<filename>}
-
Substitutes contents of the file named <filename>.
-
The included file is read at the time of attribute
substitution.
-
If the file does not exist a warning is emitted and the line
containing the reference is dropped from the output file.
-
Tabs are expanded based on the current tabsize attribute
value.
-
{sys:<command>}
-
Substitutes the stdout generated by the execution of the shell
<command>.
-
{sys2:<command>}
-
Substitutes the stdout and stderr generated by the execution
of the shell <command>.
System reference behavior
Intrinsic attributes are simple attributes that are created
automatically from AsciiDoc document header parameters, asciidoc(1)
command-line arguments, execution parameters along with attributes
defined in the default configuration files. Here’s the list of
predefined intrinsic attributes:
{amp} ampersand (&) character
{asciidoc-dir} the asciidoc(1) application directory
{asciidoc-file} the full path name of the asciidoc(1) script
{asciidoc-version} the version of asciidoc(1)
{author} author's full name
{authored} empty string '' if {author} or {email} defined,
{authorinitials} author initials (from document header)
{backend-<backend>} empty string ''
{<backend>-<doctype>} empty string ''
{backend} document backend specified by `-b` option
{backslash} backslash character
{basebackend-<base>} empty string ''
{basebackend} html or docbook
{brvbar} broken vertical bar (|) character
{revdate} document revision date (from document header)
{docdate} document last modified date
{doctime} document last modified time
{docname} document file name without extension
{docfile} document file name (note 5)
{docdir} document input directory name (note 5)
{doctitle} document title (from document header)
{doctype-<doctype>} empty string ''
{doctype} document type specified by `-d` option
{email} author's email address (from document header)
{empty} empty string ''
{encoding} specifies input and output encoding
{filetype-<fileext>} empty string ''
{filetype} output file name file extension
{firstname} author first name (from document header)
{gt} greater than (>) character
{id} running block id generated by BlockId elements
{indir} input file directory name (note 2,5)
{infile} input file name (note 2,5)
{lastname} author last name (from document header)
{level} title level 1..4 (in section titles)
{listindex} the list index (1..) of the most recent list item
{localdate} the current date
{localtime} the current time
{lt} less than (<) character
{manname} manpage name (defined in NAME section)
{manpurpose} manpage (defined in NAME section)
{mantitle} document title minus the manpage volume number
{manvolnum} manpage volume number (1..8) (from document header)
{middlename} author middle name (from document header)
{nbsp} Non-breaking space entity
{outdir} document output directory name (note 2)
{outfile} output file name (note 2)
{reftext} running block xreflabel generated by BlockId elements
{revnumber} document revision number (from document header)
{sectnum} formatted section number (in section titles)
{showcomments} send comment lines to the output
{title} section title (in titled elements)
{two_colons} Two colon characters
{two_semicolons} Two semicolon characters
{user-dir} the ~/.asciidoc directory (if it exists)
{verbose} defined as '' if --verbose command option specified
NOTES
-
Intrinsic attributes are global so avoid defining custom attributes
with the same names.
-
{outfile}, {outdir}, {infile}, {indir} attributes are
effectively read-only (you can set them but it won’t affect the
input or output file paths).
-
See also the xhtml11 subsection for attributes that relate
to AsciiDoc XHTML file generation.
-
The entries that translate to blank strings are designed to be used
for conditional text inclusion. You can also use the ifdef,
ifndef and endif System macros for conditional inclusion.
[Conditional inclusion using ifdef and ifndef macros
differs from attribute conditional inclusion in that the former
occurs when the file is read while the latter occurs when the
contents are written.]
-
{docfile} and {docdir} refer to root document specified on
the asciidoc(1) command-line; {infile} and {indir} refer to
the current input file which may be the root document or an
included file. While the input is being read from the standard
input (stdin) these attributes are undefined.
The syntax and behavior of Paragraph, DelimitedBlock, List and Table
block elements is determined by block definitions contained in
AsciiDoc configuration file sections.
Each definition consists of a section title followed by one or more
section entries. Each entry defines a block parameter controlling some
aspect of the block’s behavior. Here’s an example:
[blockdef-listing]
delimiter=^-{4,}$
template=listingblock
presubs=specialcharacters,callouts
AsciiDoc Paragraph, DelimitedBlock, List and Table block elements
share a common subset of configuration file parameters:
-
delimiter
-
A Python regular expression that matches the first line of a block
element — in the case of DelimitedBlocks it also matches the last
line. Table elements don’t have an explicit delimiter — they
synthesize their delimiters at runtime.
-
template
-
The name of the configuration file markup template section that will
envelope the block contents. The pipe | character is substituted for
the block contents. List elements use a set of (list specific) tag
parameters instead of a single template.
-
options
-
A comma delimited list of element specific option names. In addition
to being used internally, options are available during markup tag
and template substitution as attributes with an empty string value
named like <option>-option (where <option> is the option name).
-
subs, presubs, postsubs
-
-
presubs and postsubs are lists of comma separated substitutions that are
performed on the block contents. presubs is applied first,
postsubs (if specified) second.
-
subs is an alias for presubs.
-
If a filter is allowed (Paragraphs, DelimitedBlocks and Tables)
and has been specified then presubs and postsubs substitutions
are performed before and after the filter is run respectively.
-
Allowed values: specialcharacters, quotes, specialwords,
replacements, macros, attributes, callouts.
-
The following composite values are also allowed:
-
none
-
No substitutions.
-
normal
-
The following substitutions:
specialcharacters,quotes,attributes,specialwords,
replacements,macros.
-
verbatim
-
specialcharacters and callouts substitutions.
-
normal and verbatim substitutions can be redefined by with
subsnormal and subsverbatim entries in a configuration file
[miscellaneous] section.
-
The substitutions are processed in the order in which they are
listed and can appear more than once.
-
filter
-
This optional entry specifies an executable shell command for
processing block content (Paragraphs, DelimitedBlocks and Tables).
The filter command can contain attribute references.
-
posattrs
-
Optional comma separated list of positional attribute names. This
list maps positional attributes (in the block’s attribute list) to named block attributes. The following example, from the
QuoteBlock definition, maps the first and section positional
attributes:
posattrs=attribution,citetitle
-
style
-
This optional parameter specifies the default style name.
-
<stylename>-style
-
Optional style definition (see Styles below).
The following block parameters behave like document attributes and can
be set in block attribute lists and style definitions: template,
options, subs, presubs, postsubs, filter.
28.1. Styles
A style is a set of block attributes bundled as a single named
attribute. The following example defines a style named verbatim:
verbatim-style=template="literalblock",subs="verbatim"
-
All style parameter names must be suffixed with -style and the
style parameter value is in the form of a list of named attributes.
-
Multi-item style attributes (subs,presubs,postsubs,posattrs)
must be specified using Python tuple syntax rather than a simple
list of values as they in separate entries e.g.
postsubs=("callouts",) not postsubs="callouts".
28.2. Paragraphs
Paragraph translation is controlled by [paradef*] configuration file
section entries. Users can define new types of paragraphs and modify
the behavior of existing types by editing AsciiDoc configuration
files.
Here is the shipped Default paragraph definition:
[paradef-default]
delimiter=(?P<text>\S.*)
template=paragraph
The Default paragraph definition has a couple of special properties:
-
It must exist and be defined in a configuration file section named
[paradef-default].
-
Irrespective of its position in the configuration files default
paragraph document matches are attempted only after trying all
other paragraph types.
Paragraph specific block parameter notes:
-
delimiter
-
This regular expression must contain the named group text which
matches the text on the first line. Paragraphs are terminated by a
blank line, the end of file, or the start of a DelimitedBlock.
-
options
-
The listelement option specifies that paragraphs of this type will
automatically be considered part of immediately preceding list
items.
Paragraph processing proceeds as follows:
-
The paragraph text is aligned to the left margin.
-
Optional presubs inline substitutions are performed on the
paragraph text.
-
If a filter command is specified it is executed and the paragraph
text piped to its standard input; the filter output replaces the
paragraph text.
-
Optional postsubs inline substitutions are performed on the
paragraph text.
-
The paragraph text is enveloped by the paragraph’s markup template
and written to the output file.
28.3. Delimited Blocks
DelimitedBlock options values are:
-
sectionbody
-
The block contents are processed as a SectionBody.
-
skip
-
The block is treated as a comment (see CommentBlocks).
presubs, postsubs and filter entries are meaningless when
sectionbody or skip options are set.
DelimitedBlock processing proceeds as follows:
-
Optional presubs substitutions are performed on the block
contents.
-
If a filter is specified it is executed and the block’s contents
piped to its standard input. The filter output replaces the block
contents.
-
Optional postsubs substitutions are performed on the block
contents.
-
The block contents is enveloped by the block’s markup template and
written to the output file.
|
Attribute expansion is performed on the block filter command
before it is executed, this is useful for passing arguments to the
filter. |
28.4. Lists
List behavior and syntax is determined by [listdef*] configuration
file sections. The user can change existing list behavior and add new
list types by editing configuration files.
List specific block definition notes:
-
type
-
This is either bulleted,numbered,labeled or callout.
-
delimiter
-
A Python regular expression that matches the first line of a
list element entry. This expression can contain the named groups
text (bulleted groups), index and text (numbered lists),
label and text (labeled lists).
-
tags
-
The <name> of the [listtags-<name>] configuration file section
containing list markup tag definitions. The tag entries (list,
entry, label, term, text) map the AsciiDoc list structure to
backend markup; see the listtags sections in the AsciiDoc
distributed backend .conf configuration files for examples.
28.5. Tables
Table behavior and syntax is determined by [tabledef*] and
[tabletags*] configuration file sections. The user can change
existing table behavior and add new table types by editing
configuration files. The following [tabledef*] section entries
generate table output markup elements:
-
comspec
-
The table comspec tag definition.
-
headrow, footrow, bodyrow
-
Table header, footer and body row tag definitions. headrow and
footrow table definition entries default to bodyrow if
they are undefined.
-
headdata, footdata, bodydata
-
Table header, footer and body data tag definitions. headdata and
footdata table definition entries default to bodydata if they
are undefined.
-
paragraph
-
If the paragraph tag is specified then blank lines in the cell
data are treated as paragraph delimiters and marked up using this
tag.
Table behavior is also influenced by the following [miscellaneous]
configuration file entries:
-
pagewidth
-
This integer value is the printable width of the output media. See
table attributes.
-
pageunits
-
The units of width in output markup width attribute values.
Table definition behavior
-
The output markup generation is specifically designed to work with
the HTML and CALS (DocBook) table models, but should be adaptable to
most XML table schema.
-
Table definitions can be “mixed in” from multiple cascading
configuration files.
-
New table definitions inherit the default table and table tags
definitions ([tabledef-default] and [tabletags-default]) so you
only need to override those conf file entries that require
modification.
Filters are external shell commands used to process Paragraph and
DelimitedBlock content; they are specified in configuration file
Paragraph and DelimitedBlock definitions.
There’s nothing special about the filters, they’re just standard UNIX
filters: they read text from the standard input, process it, and write
to the standard output.
Attribute substitution is performed on the filter command prior to
execution — attributes can be used to pass parameters from the
AsciiDoc source document to the filter.
|
Filters can potentially generate unsafe output. Before
installing a filter you should verify that it can’t be coerced into
generating malicious output or exposing sensitive information. |
29.1. Filter Search Paths
If the filter command does not specify a directory path then
asciidoc(1) searches for the command:
-
First it looks in the user’s $HOME/.asciidoc/filters directory.
-
Next the /etc/asciidoc/filters directory is searched.
-
Then it looks in the asciidoc(1) ./filters directory.
-
Finally it relies on the executing shell to search the environment
search path ($PATH).
Sub-directories are also included in the searches — standard practice
is to install each filter in it’s own sub-directory with the same name
as the filter’s style definition. For example the music filter’s style
name is music so it’s configuration and filter files are stored in
the filters/music directory.
29.2. Filter Configuration Files
Filters are normally accompanied by a configuration file containing a
Paragraph or DelimitedBlock definition along with corresponding markup
templates.
While it is possible to create new Paragraph or DelimitedBlock
definitions the preferred way to implement a filter is to add a
style to the existing Paragraph and ListingBlock definitions
(all filters shipped with AsciiDoc use this technique). The filter is
applied to the paragraph or delimited block by preceding it with an
attribute list: the first positional attribute is the style name,
remaining attributes are normally filter specific parameters.
asciidoc(1) auto-loads all .conf files found in the filter search
paths (see previous section).
29.3. Code Filter
AsciiDoc comes with a toy filter for highlighting source code keywords
and comments. See also the ./filters/code/code-filter-readme.txt
file.
|
This filter primarily to demonstrate how to write a filter — it’s much to simplistic to be passed off as a code syntax highlighter.
If you want a full featured multi-language highlighter use the
Source Code Highlighter Filter. |
.Code filter example
[code,python]
----------------------------------------------
''' A multi-line
comment.'''
def sub_word(mo):
''' Single line comment.'''
word = mo.group('word') # Inline comment
if word in keywords[language]:
return quote + word + quote
else:
return word
----------------------------------------------
Code filter example
''' A multi-line
comment.'''
def sub_word(mo):
''' Single line comment.'''
word = mo.group('word') # Inline comment
if word in keywords[language]:
return quote + word + quote
else:
return word
29.4. Source Code Highlighter Filter
29.5. Music Filter
A music filter is
included in the distribution ./filters directory. It translates
music in LilyPond or
ABC notation to standard Western classical
notation in the form of a trimmed PNG image which is automatically
inserted into the output document.
DocBook files are validated, parsed and translated by a combination of
applications collectively called a DocBook tool chain. The function
of a tool chain is to read the DocBook markup (produced by AsciiDoc)
and transform it to a presentation format (for example HTML, PDF, HTML
Help, DVI, PostScript, LaTeX).
A wide range of user output format requirements coupled with a choice
of available tools and stylesheets results in many valid tool chain
combinations.
30.1. a2x Toolchain Wrapper
One of the biggest hurdles for new users is installing, configuring
and using a DocBook XML toolchain. a2x(1) can help — it’s a
toolchain wrapper command that will generate XHTML (chunked and
unchunked), PDF, DVI, PS, LaTeX, man page, HTML Help and text file
outputs from an AsciiDoc text file. a2x(1) does all the grunt work
associated with generating and sequencing the toolchain commands and
managing intermediate and output files. a2x(1) also optionally
deploys admonition and navigation icons and a CSS stylesheet. See the
a2x(1) man page for more details. All you need is
xsltproc(1), DocBook XSL Stylesheets and optionally:
dblatex or FOP (if you want PDF); w3m(1) or
lynx(1) (if you want text).
The following examples generate doc/source-highlight-filter.pdf from
the AsciiDoc doc/source-highlight-filter.txt source file. The first
example uses dblatex(1) (the default PDF generator) the second
example forces FOP to be used:
$ a2x -f pdf doc/source-highlight-filter.txt
$ a2x -f pdf --fop doc/source-highlight-filter.txt
See the a2x(1) man page for details.
|
Use the --verbose command-line option to view executed
toolchain commands. |
30.2. HTML generation
AsciiDoc produces nicely styled HTML directly without requiring a
DocBook toolchain but there are also advantages in going the DocBook
route:
-
HTML from DocBook includes automatically generated indexes, tables
of contents, footnotes, lists of figures and tables.
-
DocBook toolchains can also (optionally) generate separate (chunked)
linked HTML pages for each document section.
-
Toolchain processing performs link and document validity checks.
-
If the DocBook lang attribute is set then things like table of
contents, figure and table captions and admonition captions will be
output in the specified language (setting the AsciiDoc lang
attribute sets the DocBook lang attribute).
On the other hand, HTML output directly from AsciiDoc is much faster,
is easily customized and can be used in situations where there is no
suitable DocBook toolchain (see the
AsciiDoc website for example).
30.3. PDF generation
There are two commonly used tools to generate PDFs from DocBook,
dblatex and FOP.
dblatex or FOP?
-
dblatex is easier to install, there’s zero configuration
required and no Java VM to install — it just works out of the box.
-
dblatex source code highlighting and numbering is superb.
-
dblatex is easier to use as it converts DocBook directly to PDF
whereas before using FOP you have to convert DocBook to XML-FO
using DocBook XSL Stylesheets.
-
FOP is more feature complete (for example, callouts are processed
inside literal layouts) and arguably produces nicer looking output.
30.4. HTML Help generation
-
AsciiDoc
-
Converts AsciiDoc (.txt) files to DocBook XML (.xml) files.
-
DocBook XSL Stylesheets
-
These are a set of XSL stylesheets containing rules for converting
DocBook XML documents to HTML, XSL-FO, manpage and HTML Help files.
The stylesheets are used in conjunction with an XML parser such as
xsltproc(1).
-
xsltproc
-
An XML parser for applying XSLT stylesheets (in our case the
DocBook XSL Stylesheets) to XML documents.
-
dblatex
-
Generates PDF, DVI, PostScript and LaTeX formats directly from
DocBook source via the intermediate LaTeX typesetting language — uses DocBook XSL Stylesheets, xsltproc(1) and
latex(1).
-
FOP
-
The Apache Formatting Objects Processor converts XSL-FO (.fo)
files to PDF files. The XSL-FO files are generated from DocBook
source files using DocBook XSL Stylesheets and
xsltproc(1).
-
Microsoft Help Compiler
-
The Microsoft HTML Help Compiler (hhc.exe) is a command-line tool
that converts HTML Help source files to a single HTML Help (.chm)
file. It runs on MS Windows platforms and can be downloaded from
http://www.microsoft.com.
30.6. AsciiDoc dblatex configuration files
The AsciiDoc distribution ./dblatex directory contains
asciidoc-dblatex.xsl (customized XSL parameter settings) and
asciidoc-dblatex.sty (customized LaTeX settings). These are examples
of optional dblatex output customization and are used by
a2x(1).
30.7. AsciiDoc DocBook XSL Stylesheets drivers
You will have noticed that the distributed HTML and HTML Help
documentation files (for example ./doc/asciidoc.html) are not the
plain outputs produced using the default DocBook XSL Stylesheets
configuration. This is because they have been processed using
customized DocBook XSL Stylesheets along with (in the case of HTML
outputs) the custom ./stylesheets/docbook.css CSS stylesheet.
You’ll find the customized DocBook XSL drivers along with additional
documentation in the distribution ./docbook-xsl directory. The
examples that follow are executed from the distribution documentation
(./doc) directory.
-
common.xsl
-
Shared driver parameters. This file is not used directly but is
included in all the following drivers.
-
chunked.xsl
-
Generate chunked XHTML (separate HTML pages for each document
section) in the ./doc/chunked directory. For example:
$ python ../asciidoc.py -b docbook asciidoc.txt
$ xsltproc --nonet ../docbook-xsl/chunked.xsl asciidoc.xml
-
fo.xsl
-
Generate XSL Formatting Object (.fo) files for subsequent PDF
file generation using FOP. For example:
$ python ../asciidoc.py -b docbook article.txt
$ xsltproc --nonet ../docbook-xsl/fo.xsl article.xml > article.fo
$ fop.sh article.fo article.pdf
-
htmlhelp.xsl
-
Generate Microsoft HTML Help source files for the MS HTML Help
Compiler in the ./doc/htmlhelp directory. This example is run on
MS Windows from a Cygwin shell prompt:
$ python ../asciidoc.py -b docbook asciidoc.txt
$ xsltproc --nonet ../docbook-xsl/htmlhelp.xsl asciidoc.xml
$ c:/Program\ Files/HTML\ Help\ Workshop/hhc.exe htmlhelp.hhp
-
manpage.xsl
-
Generate a roff(1) format UNIX man page from a DocBook XML
refentry document. This example generates an asciidoc.1 man
page file:
$ python ../asciidoc.py -d manpage -b docbook asciidoc.1.txt
$ xsltproc --nonet ../docbook-xsl/manpage.xsl asciidoc.1.xml
-
xhtml.xsl
-
Convert a DocBook XML file to a single XHTML file. For example:
$ python ../asciidoc.py -b docbook asciidoc.txt
$ xsltproc --nonet ../docbook-xsl/xhtml.xsl asciidoc.xml > asciidoc.html
If you want to see how the complete documentation set is processed
take a look at the A-A-P script ./doc/main.aap.
AsciiDoc does not have a text backend (for most purposes AsciiDoc
source text is fine), however you can convert AsciiDoc text files to
formatted text using the AsciiDoc a2x(1) toolchain wrapper
utility.
The default XML character set UTF-8 is used when AsciiDoc generates
DocBook files but this can be changed by setting the xmldecl entry
in the [attributes] section of the docbook.conf file or by
composing your own configuration file [header] section).
|
If you get an undefined entity error when processing DocBook
files you’ll may find that you’ve used an undefined HTML character
entity. An easy (although inelegant) fix is to use the character’s
character code instead of its symbolic name (for example use  
instead of ). |
If your system has been configured with an XML catalog you may find a
number of entity sets are already automatically included.
32.1. PDF Fonts
The Adobe PDF Specification states that the following 14 fonts should
be available to every PDF reader: Helvetica (normal, bold, italic,
bold italic), Times (normal, bold, italic, bold italic), Courier
(normal, bold, italic, bold italic), Symbol and ZapfDingbats.
Non-standard fonts should be embedded in the distributed document.
The asciidoc(1) command has a --help option which prints help topics
to stdout. The default topic summarizes asciidoc(1) usage:
To print a list of help topics:
To print a help topic specify the topic name as a command argument.
Help topic names can be shortened so long as they are not ambiguous.
Examples:
$ asciidoc --help=manpage
$ asciidoc -hm # Short version of previous example.
$ asciidoc --help=syntax
$ asciidoc -hs # Short version of previous example.
33.1. Customizing Help
To change, delete or add your own help topics edit a help
configuration file. The help file name help-<lang>.conf is based on
the setting of the lang attribute, it defaults to help.conf
(English). The help file location will depend on whether you
want the topics to apply to all users or just the current user.
The help topic files have the same named section format as other
configuration files. The help.conf files are stored in the
same locations and loaded in the same order as other configuration
files.
When the --help command-line option is specified AsciiDoc loads the
appropriate help files and then prints the contents of the section
whose name matches the help topic name. If a topic name is not
specified default is used. You don’t need to specify the whole help
topic name on the command-line, just enough letters to ensure it’s not
ambiguous. If a matching help file section is not found a list of
available topics is printed.
34.1. Know Your Editor
Writing AsciiDoc documents will be a whole lot more pleasant if you
know your favorite text editor. Learn how to indent and reformat text
blocks, paragraphs, lists and sentences. Tips for vim users
follow.
34.2. Vim Commands for Formatting AsciiDoc
34.2.1. Text Wrap Paragraphs
Use the vim :gq command to reformat paragraphs. Setting the
textwidth sets the right text wrap margin; for example:
-
Position the cursor at the start of the paragraph.
-
Type gq}.
Execute :help gq command to read about the vim gq command.
|
-
Assign the gq} command to the Q key with the nnoremap Q gq}
command or put it in your ~/.vimrc file to so it’s always
available (see the Example ~/.vimrc file).
-
Put set commands in your ~/.vimrc file so you don’t have to
enter them manually.
-
The Vim website (http://www.vim.org) has a wealth of resources,
including scripts for automated spell checking and ASCII Art
drawing.
|
The gq command can also be used to format bulleted, numbered and
callout lists. First you need to set the comments, formatoptions
and formatlistpat (see the Example ~/.vimrc file).
Now you can format simple lists that use dash, asterisk, period and
plus bullets along with numbered ordered lists:
-
Position the cursor at the start of the list.
-
Type gq}.
34.2.3. Indent Paragraphs
Indent whole paragraphs by indenting the fist line with the desired
indent and then executing the gq} command.
34.2.4. Example ~/.vimrc File
" Show tabs and trailing characters.
set listchars=tab:»·,trail:·
set list
" Don't highlight searched text.
highlight clear Search
" Don't move to matched text while search pattern is being entered.
set noincsearch
" Reformat paragraphs and list.
nnoremap R gq}
" Delete trailing white space and Dos-returns and to expand tabs to spaces.
nnoremap S :set et<CR>:retab!<CR>:%s/[\r \t]\+$//<CR>
autocmd BufRead,BufNewFile *.txt,README,TODO,CHANGELOG,NOTES
\ setlocal autoindent expandtab tabstop=8 softtabstop=2 shiftwidth=2 filetype=asciidoc
\ textwidth=70 wrap formatoptions=tcqn
\ formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\\|^\\s*<\\d\\+>\\s\\+\\\\|^\\s*[a-zA-Z.]\\.\\s\\+\\\\|^\\s*[ivxIVX]\\+\\.\\s\\+
\ comments=s1:/*,ex:*/,://,b:#,:%,:XCOMM,fb:-,fb:*,fb:+,fb:.,fb:>
34.3. Troubleshooting
-
The asciidoc(1) -v (--verbose) command-line option displays the
order of configuration file loading and warns of potential
configuration file problems.
-
Not all valid AsciiDoc documents produce valid backend markup. Read
the AsciiDoc Backends section if AsciiDoc output is rejected
as non-conformant by a backend processor.
34.4. Gotchas
-
Incorrect character encoding
-
If you get an error message like 'UTF-8' codec can't decode ...
then you source file contains invalid UTF-8 characters — set the
AsciiDoc encoding attribute for the correct character set
(typically ISO-8859-1 (Latin-1) for European languages).
-
Invalid output
-
AsciiDoc attempts to validate the input AsciiDoc source but makes
no attempt to validate the output markup, it leaves that to
external tools such as xmllint(1) (integrated into a2x(1)).
Backend validation cannot be hardcoded into AsciiDoc because
backends are dynamically configured. The following example
generates valid HTML but invalid DocBook (the DocBook literal
element cannot contain an emphasis element):
+monospaced text with an _emphasized_ word+
-
Misinterpreted text formatting
-
You can suppress markup expansion by placing a backslash character
immediately in front of the element. The following example
suppresses inline monospaced formatting:
-
Overlapping text formatting
-
Overlapping text formatting will generate illegal overlapping
markup tags which will result in downstream XML parsing errors.
Here’s an example:
Some *strong markup _that overlaps* emphasized markup_.
-
Ambiguous underlines
-
A DelimitedBlock can immediately follow paragraph without an
intervening blank line, but be careful, a single line paragraph
underline may be misinterpreted as a section title underline
resulting in a “closing block delimiter expected” error.
-
Ambiguous ordered list items
-
Lines beginning with numbers at the end of sentences will be
interpreted as ordered list items. The following example
(incorrectly) begins a new list with item number 1999:
He was last sighted in
1999. Since then things have moved on.
The list item out of sequence warning makes it unlikely that this
problem will go unnoticed.
-
Special characters in attribute values
-
Special character substitution precedes attribute substitution so
if attribute values contain special characters you may, depending
on the substitution context, need to escape the special characters
yourself. For example:
$ asciidoc -a 'corpname=Bill & Ben Inc.' mydoc.txt
-
Macro attribute lists
-
If named attribute list entries are present then all string
attribute values must be quoted. For example:
["Desktop screenshot",width=32]
34.5. Combining separate documents
You have a number of stand-alone AsciiDoc documents that you want to
process as a single document. Simply processing them with a series of
include macros won’t work because the documents contain (level 0)
document titles. The solution is to create a top level wrapper
document that redefines the document underlines, pushing them down one
level. For example combined.txt:
:titles.underlines: "__","==","--","~~","^^"
Combined Document Title
_______________________
include::document1.txt[]
include::document2.txt[]
include::document3.txt[]
The document titles in the included documents will now be processed as
level 1 section titles.
-
Put a blank line between the include macro lines to ensure the
title of the included document is not seen as part of the last
paragraph of the previous document.
-
You won’t want document Headers (Author and Revision lines) in the
included files — conditionally exclude them if they are necessary
for stand-alone processing.
34.6. Processing document sections separately
You have divided your AsciiDoc document into separate files (one per
top level section) which are combined and processed with the following
top level document:
Combined Document Title
=======================
Joe Bloggs
v1.0, 12-Aug-03
include::section1.txt[]
include::section2.txt[]
include::section3.txt[]
You also want to process the section files as separate documents.
This is easy because asciidoc(1) will quite happily process
section1.txt, section2.txt and section3.txt separately — the
resulting output documents contain the section but have no document
title.
Use the -s (--no-header-footer) command-line option to suppress
header and footer output, this is useful if the processed output is to
be included in another file. For example:
$ asciidoc -s -b docbook section1.txt
34.7. Processing document snippets
asciidoc(1) can be used as a filter, so you can pipe chunks of text
through it. For example:
$ echo 'Hello *World!*' | asciidoc -s -
<div class="paragraph"><p>Hello <strong>World!</strong></p></div>
See the [footer] section in the AsciiDoc distribution xhtml11.conf
configuration file.
34.9. Pretty printing AsciiDoc output
If the indentation and layout of the asciidoc(1) output is not to your
liking you can:
-
Change the indentation and layout of configuration file markup
template sections. The {empty} glossary entry is useful for
outputting trailing blank lines in markup templates.
-
Use Dave Raggett’s HTML Tidy program
to tidy asciidoc(1) output. Example:
$ asciidoc -b docbook -o - mydoc.txt | tidy -indent -xml >mydoc.xml
-
Use the xmllint(1) format option. Example:
$ xmllint --format mydoc.xml
34.10. Supporting minor DocBook DTD variations
The conditional inclusion of DocBook SGML markup at the end of the
distribution docbook.conf file illustrates how to support minor DTD
variations. The included sections override corresponding entries from
preceding sections.
34.11. Shipping stand-alone AsciiDoc source
Reproducing presentation documents from someone else’s source has one
major problem: unless your configuration files are the same as the
creator’s you won’t get the same output.
The solution is to create a single backend specific configuration file
using the asciidoc(1) -c (--dump-conf) command-line option. You
then ship this file along with the AsciiDoc source document plus the
asciidoc.py script. The only end user requirement is that they have
Python installed (and of course that they consider you a trusted
source). This example creates a composite HTML configuration
file for mydoc.txt:
$ asciidoc -cb xhtml11 mydoc.txt > mydoc-xhtml11.conf
Ship mydoc.txt, mydoc-html.conf, and asciidoc.py. With
these three files (and a Python interpreter) the recipient can
regenerate the HMTL output:
$ ./asciidoc.py -eb xhtml11 mydoc.txt
The -e (--no-conf) option excludes the use of implicit
configuration files, ensuring that only entries from the
mydoc-html.conf configuration are used.
34.12. Inserting blank space
Adjust your style sheets to add the correct separation between block
elements. Inserting blank paragraphs containing a single non-breaking
space character {nbsp} works but is an ad hoc solution compared
to using style sheets.
34.13. Closing open sections
You can close off section tags up to level N by calling the
eval::[Section.setlevel(N)] system macro. This is useful if you
want to include a section composed of raw markup. The following
example includes a DocBook glossary division at the top section level
(level 0):
ifdef::backend-docbook[]
eval::[Section.setlevel(0)]
+++++++++++++++++++++++++++++++
<glossary>
<title>Glossary</title>
<glossdiv>
...
</glossdiv>
</glossary>
+++++++++++++++++++++++++++++++
endif::backend-docbook[]
34.14. Validating output files
Use xmllint(1) to check the AsciiDoc generated markup is both well
formed and valid. Here are some examples:
$ xmllint --nonet --noout --valid docbook-file.xml
$ xmllint --nonet --noout --valid xhtml11-file.html
$ xmllint --nonet --noout --valid --html html4-file.html
The --valid option checks the file is valid against the document
type’s DTD, if the DTD is not installed in your system’s catalog then
it will be fetched from its Internet location. If you omit the
--valid option the document will only be checked that it is well
formed.
36.1. Version 7 to version 8
-
A new set of quotes has been introduced which may match inline text
in existing documents — if they do you’ll need to escape the
matched text with backslashes.
-
The index entry inline macro syntax has changed — if your documents
include indexes you may need to edit them.
-
Replaced a2x(1) --no-icons and --no-copy options with their
negated equivalents: --icons and --copy respectively. The
default behavior has also changed — the use of icons and copying of
icon and CSS files must be specified explicitly with the --icons
and --copy options.
The rationale for the changes can be found in the AsciiDoc
CHANGELOG.
|
If you want to disable unconstrained quotes, the new alternative
constrained quotes syntax and the new index entry syntax then you can
define the attribute asciidoc7compatible (for example by using the
-a asciidoc7compatible command-line option). |
Read the README and INSTALL files (in the distribution root
directory) for install prerequisites and procedures. The distribution
Makefile.in (used by configure to generate the Makefile) is the
canonical installation procedure.
AsciiDoc safe mode skips potentially dangerous sections in AsciiDoc
source files by inhibiting the execution of arbitrary code or the
inclusion of arbitrary files.
The safe mode is enabled by default and can only be disabled using the
asciidoc(1) --unsafe command-line option.
Safe mode constraints
-
eval, sys and sys2 executable attributes and block macros are
not executed.
-
include::<filename>[] and include1::<filename>[] block macro
files must reside inside the parent file’s directory.
-
{include:<filename>} executable attribute files must reside
inside the source document directory.
-
Passthrough Blocks are dropped.
|
The safe mode is not designed to protect against unsafe AsciiDoc
configuration files. Be especially careful when:
-
Implementing filters.
-
Implementing elements that don’t escape special characters.
-
Accepting configuration files from untrusted sources.
|
AsciiDoc can process UTF-8 character sets but there are some things
you need to be aware of:
-
If you are generating output documents using a DocBook toolchain
then you should set the AsciiDoc lang attribute to the appropriate
language (it defaults to en (English)). This will ensure things
like table of contents, figure and table captions and admonition
captions are output in the specified language. For example:
$ a2x -a lang=es doc/article.txt
-
If you are outputting HTML directly from asciidoc(1) you’ll
need to set the various *_caption attributes to match your target
language (see the list of captions and titles in the [attributes]
section of the default asciidoc.conf file). The easiest way is to
create a language .conf file (see the AsciiDoc's lang-en.conf
file).
|
You still use the NOTE, CAUTION, TIP, WARNING,
IMPORTANT captions in the AsciiDoc source, they get translated in
the HTML output file. |
-
asciidoc(1) automatically loads configuration files named like
lang-<lang>.conf where <lang> is a two letter language code that
matches the current AsciiDoc lang attribute. See also
Configuration File Names and Locations.
-
Some character sets display double-width characters (for example
Japanese). As far as title underlines are concerned they
should be treated as single character. If you think this looks
untidy so you may prefer to use the single line title
format.
The AsciiDoc ./vim/ distribution directory contains Vim syntax
highlighter and filetype detection scripts for AsciiDoc. Syntax
highlighting makes it much easier to spot AsciiDoc syntax errors.
If Vim is installed on your system the AsciiDoc installer
(install.sh) will automatically install the vim scripts in the Vim
global configuration directory (/etc/vim).
You can also turn on syntax highlighting by adding the following line
to the end of you AsciiDoc source files:
// vim: set syntax=asciidoc:
40.1. Limitations
The current implementation does a reasonable job but on occasions gets
things wrong. This list of limitations also discusses how to work
around the problems:
-
Indented lists with preceding blank lines are sometimes mistaken
for literal (indented) paragraphs. You can work around this by
deleting the preceding blank line, or inserting a space in the
preceding blank lines, or putting a list continuation character
(+) in the preceding blank line.
-
Nested quoted text formatting is highlighted according to the outer
format.
-
If a closing block delimiter is not preceded by a blank line it is
sometimes mistaken for a title underline. A workaround is to insert
a blank line before the closing delimiter.
-
If a list block delimiter is mistaken for a title underline precede
it with a blank line.
-
Lines within a paragraph beginning with a period will be highlighted
as block titles. For example:
To work around this restriction move the last word of the previous
line to the start of the current (although words starting with a
period should probably be quoted monospace which would also get around
the problem).
|
Sometimes incorrect highlighting is caused by preceding lines
that appear blank but contain white space characters — setting your
editor options so that white space characters are visible is a good
idea. |
Option |
Backends |
AsciiDoc Elements |
Description |
compact |
docbook, xhtml11 |
bulleted list, numbered list |
Minimizes vertical space in the list |
strong |
xhtml11,html4 |
labeled lists |
Emboldens label text. |
footer |
docbook, xhtml11, html4 |
table |
The last row of the table is rendered as a footer. |
header |
docbook, xhtml11, html4 |
table |
The first row of the table is rendered as a header. |
autowidth |
xhtml11,html4 |
table |
The column widths are determined by the browser, not the AsciiDoc
cols attribute. If there is no width attribute the table width is
also left up to the browser. |
breakable, unbreakable |
docbook (XSL/FO) |
table |
The breakable options allows the table to break across page
boundaries (the default behavior); unbreakable attempts to keep the
table together on a single page. If neither option is specified the
default XSL stylesheet behavior prevails. |
pgwide |
docbook (XSL/FO) |
table, block image, horizontal labeled list |
Specifies that the element should be rendered across the full text
width of the page irrespective of the current indentation. |
The asciidoc(1) --verbose command-line option prints additional
information to stderr: files processed, filters processed, warnings,
system attribute evaluation.
A special attribute named trace controls the output of diagnostic
information. If the trace attribute is defined then
element-by-element diagnostic messages detailing output markup
generation are printed to stderr. The trace attribute can be set on
the command-line or from within the document using Attribute Entries (the latter allows tracing to be confined to specific
portions of the document).
-
Trace messages consist of a descriptive name followed by the related
markup.
-
The trace message is only printed if the trace attribute value
matches the start of the trace name. The trace attribute value can
be any Python regular expression.
-
A blank trace value matches all trace names and all trace messages
will be printed (this can result in large amounts of output if
applied to the whole document).
-
In the case of inline substitutions:
-
The text before and after the substitution are printed delineated
by <<< and >>> delimiters.
-
The message is only printed if a substitution is made.
-
The subs trace value is an alias for all inline substitutions.
-
Trace the entire document.
$ asciidoc -a trace mydoc.txt
-
Trace messages whose names start with quotes or macros:
$ asciidoc -a 'trace=quotes|macros' mydoc.txt
-
Print the first line of all trace messages:
$ asciidoc -a trace mydoc.txt 2>&1 | grep ^TRACE:
Attribute Entry examples:
-
Begin printing all trace messages:
-
Print only matched trace messages:
-
Turn trace messages off:
This table contains a list of optional attributes that influence the
generated outputs.
Name |
Backends |
Description |
encoding |
html4, xhtml11, docbook |
Set the input and output document character set encoding. For example
the --attribute encoding=ISO-8859-1 command-line option will set the
character set encoding to ISO-8859-1.
-
The default encoding is UTF-8.
-
This attribute specifies the character set in the output document.
-
The encoding name must correspond to a Python codec name or alias.
-
The encoding attribute can be set using an AttributeEntry inside
the document header but it must come at the start of the document
before the document title. For example:
|
imagesdir |
html4, xhtml11, docbook |
If this attribute is defined it is prepended to the target image file
name paths in inline and block image macros. |
iconsdir |
html4, xhtml11, docbook |
The name of the directory containing linked admonition and navigation
icons. Defaults to ./images/icons. |
sgml |
docbook |
The --backend=docbook command-line option produces DocBook XML. You
can produce the older DocBook SGML format using the --attribute sgml
command-line option. |
docinfo |
docbook |
|
revremark |
docbook |
A short summary of changes in this document revision. Must be defined
prior to the first document section. The document also needs to be
dated to output this attribute. |
numbered |
html4, xhtml11 |
Adds section numbers to section titles. |
toc |
xhtml11 |
Adds a table of contents to the start of the document.
-
JavaScript needs to be enabled in your browser for this to work.
-
By default AsciiDoc automatically embeds the required toc.js
JavaScript in the output document — use the linkcss attribute to
link the script.
-
The following example generates a numbered table of contents by
embedding the toc.js script in the mydoc.html output document
(to link the script to the output document use the linkcss and
scriptsdir attributes):
$ asciidoc -a toc -a numbered mydoc.txt
-
The toc attribute must be specified using the --attribute
command-line option. If you define the toc attribute in a custom
configuration file it won’t be recognized because the conditionally
included header code will have already been processed.
|
toclevels |
xhtml11 |
Sets the number of title levels (1..4) reported in the table of
contents (see the toc attribute above). Defaults to 2 and must be
used with the toc attribute. Example usage:
$ asciidoc -a toc -a toclevels=3 doc/asciidoc.txt
|
toc_title |
xhtml11 |
Sets the table of contents title (defaults to Table of Contents). |
linkcss |
xhtml11 |
Link CSS stylesheets and JavaScripts (see the stylesdir and
scriptsdir attributes below). By default linkcss is undefined in
which case stylesheets and scripts are automatically embedded in the
output document. |
scriptsdir |
xhtml11 |
The name of the directory containing linked JavaScripts. Defaults to
. (the same directory as the linking document). |
stylesdir |
xhtml11 |
The name of the directory containing linked stylesheets. Defaults to
. (the same directory as the linking document). |
stylesheet |
xhtml11 |
The file name of an optional additional CSS stylesheet. If you are
embedding the stylesheet specify the actual file name; if you are
linking CSS specify the file name relative to the directory specified
by the stylesdir attribute. |
icons |
xhtml11 |
Link admonition paragraph and admonition block icon images and badge
images. By default icons is undefined and text is used in place of
icon images. |
theme |
xhtml11 |
|
badges |
xhtml11 |
Link badges (XHTML 1.1, CSS and Get Firefox!) in document
footers. By default badges are omitted (badges is undefined).
Note
|
The path names of images, icons and scripts are relative path
names to the output document not the source document. |
|
quirks |
xhtml11 |
Use the xhtml11-quirks.css stylesheet to work around IE6 browser
incompatibilities (this is the default behavior). |
data-uri |
xhtml11 |
|