$ asciidoc -a toc -a numbered mydoc.txt
»Home
»a2x
»FAQ
|
Table of Contents
AsciiDoc is a text document format for writing short documents, articles, books and UNIX man pages. AsciiDoc files can be translated to HTML and DocBook markups using the asciidoc(1) command. AsciiDoc is highly configurable: both the AsciiDoc source file syntax and the backend output markups (which can be almost any type of SGML/XML markup) can be customized and extended by the user. 1. IntroductionPlain 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. Getting Started2.1. Installing AsciiDocSee the README and INSTALL files for install prerequisites and procedures. Packagers take a look at Appendix B: Packager Notes. 2.2. Example AsciiDoc DocumentsThe best way to quickly get a feel for AsciiDoc is to view the AsciiDoc web site and/or distributed examples:
3. AsciiDoc Document TypesThere 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. articleUsed for short documents, articles and general documentation. See the AsciiDoc distribution ./doc/article.txt example. 3.2. bookBooks 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
3.3. manpageUsed 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. 4. AsciiDoc BackendsThe 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. AsciiDoc ships with the following predefined backend output formats: 4.1. docbookAsciiDoc 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.
4.2. xhtml11The 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. StylesheetsAsciiDoc XHTML output is styled using CSS2 stylesheets from the distribution ./stylesheets/ directory.
Default xhtml11 stylesheets:
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. html4This backend generates plain (unstyled) HTML 4.01 Transitional markup. 5. Document StructureAn 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 ElementsBlock elements consist of one or more lines of text and may contain other block elements. The AsciiDoc block structure can be informally summarized
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)*) Where:
5.2. HeaderThe Header is optional but must start on the first line of the document and must begin with a document title. Optional Author and Revision lines immediately follow the title. The header can be preceded by a CommentBlock or comment lines. 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. The optional document header revision line should immediately follow the author line. The revision line can be one of two formats:
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 ==================================== Stuart Rackham <srackham@gmail.com> v2.0, February 2003 You can override or set header parameters by passing revision, data, email, author, authorinitials, firstname and lastname attributes using the asciidoc(1) -a (--attribute) command-line option. For example: $ asciidoc -a date=2004/07/27 article.txt Attributes can also be added to the header for substitution in the header template with Attribute Entry elements. 5.3. PreambleThe Preamble is an optional untitled section body between the document Header and the first Section title. 5.4. SectionsAsciiDoc 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. To determine which configuration file template to use AsciiDoc first searches for special section titles in the [specialsections] configuration entries, if not found it uses the [sect<level>] template. 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:
For example the title Jim’s House would generate the ID _jim_s_house. 5.4.1. Special SectionsIn addition to normal sections, documents can contain optional frontmatter and backmatter sections — for example: preface, bibliography, table of contents, index. The AsciiDoc configuration file [specialsections] section specifies special section titles and the corresponding backend markup templates. [specialsections] entries are formatted like: <pattern>=<name> <pattern> is a Python regular expression and <name> is the name of a configuration file markup template section. If the <pattern> matches an AsciiDoc document section title then the backend output is marked up using the <name> 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. 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 ElementsInline 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:
6. Document ProcessingThe AsciiDoc source document is read and processed as follows:
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:
The substitutions and substitution order performed on Title, Paragraph and DelimitedBlock elements is determined by configuration file parameters. 7. Text Formatting7.1. Quoted TextWords and phrases can be formatted by enclosing inline text with quote characters:
The alternative underline and plus characters, while marginally less readable, are arguably a better choice than the backtick and apostrophe characters as they are not normally used for, and so not confused with, punctuation. 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
7.1.1. Constrained and Unconstrained QuotesThere are actually two types of quotes: Constrained quotesQuote 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 quotesUnconstrained 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: **F**ile Open...
7.2. Superscripts and SubscriptsPut ^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~ Is rendered like: 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 BreaksA 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 BreaksA 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. RulersA 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. TabsBy 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. ReplacementsThe 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. Which are rendered as: © 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: ➊ ¶ renders: ➊ ¶ To render a replacement literally escape it with a leading back-slash. The Configuration Files section explains how to configure your own replacements. 7.8. Special WordsWords defined in [specialwords] configuration file sections are automatically marked up without having to be explicitly notated. The Configuration Files section explains how to add and replace special words. 8. TitlesDocument and section titles can be in either of two formats: 8.1. Two line titlesA 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): ++++++++++++++++++++++ Examples: Level One Section Title ----------------------- Level 2 Subsection Title ~~~~~~~~~~~~~~~~~~~~~~~~ 8.2. One line titlesOne 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 (levels 2 and 3 illustrate the optional trailing equals characters syntax): = Document Title (level 0) = == Section title (level 1) == === Section title (level 2) === ==== Section title (level 3) ==== ===== Section title (level 4) ===== Note
9. BlockTitlesA BlockTitle element is a single line beginning with a period followed by a title. The title is applied to the next Paragraph, DelimitedBlock, List, Table or BlockMacro. For example: .Notes - Note 1. - Note 2. is rendered as: Notes
10. BlockId ElementA 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 is really just an AttributeList with a special syntax which sets the {id} attribute for substitution in the subsequent block’s markup template. The BlockId element has the same syntax and serves a similar function to the anchor inline macro. 11. ParagraphsParagraphs are terminated by a blank line, the end of file, or the start of a DelimitedBlock. Paragraph markup is specified by configuration file [paradef*] sections. AsciiDoc ships with the following predefined paragraph types: 11.1. Default ParagraphA Default paragraph ([paradef-default]) consists of one or more non-blank lines of text. The first line must start hard against the left margin (no intervening white space). The processing expectation of the default paragraph type is that of a normal paragraph of text. 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. Renders: Consul necessitatibus per id,
consetetur, eu pro everti postulant
homero verear ea mea, qui.
11.2. Literal ParagraphA Literal paragraph ([paradef-literal]) consists of one or more lines of text, where the first line is indented by one or more space or tab characters. Literal paragraphs are rendered verbatim in a monospaced font usually without any distinguishing background or border. There is no text formatting or substitutions within Literal paragraphs apart from Special Characters and Callouts. For example: Consul *necessitatibus* per id, consetetur, eu pro everti postulant homero verear ea mea, qui. Renders: Consul *necessitatibus* per id, consetetur, eu pro everti postulant homero verear ea mea, qui.
11.3. Admonition ParagraphsTip, 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. Renders:
11.3.1. Admonition Icons and Captions
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. This subsection also applies to Admonition Blocks. 12. Delimited BlocksDelimited 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. 12.1. Predefined Delimited BlocksAsciiDoc 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: ========================== Filter blocks: ~~~~~~~~~~~~~~~~~~~~~~~~~~
12.2. Listing BlocksListingBlocks are rendered verbatim in a monospaced font, they retain line and whitespace formatting and 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 code and file listings. Here’s an example: -------------------------------------- #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); } 12.3. Literal BlocksLiteralBlocks behave just like LiteralParagraphs except you don’t have to indent the contents. LiteralBlocks can be used to resolve list ambiguity. If the following list was just indented it would be processed as an ordered list (not an indented paragraph): .................... 1. Item 1 2. Item 2 .................... Renders: 1. Item 1 2. Item 2 12.4. SidebarBlocksA 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. Here’s an example: .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... ************************************************ 12.5. Comment BlocksThe contents of CommentBlocks are not processed; they are useful for annotations and for excluding new or outdated content that you don’t want displayed. Here’s and example: ////////////////////////////////////////// CommentBlock contents are not processed by asciidoc(1). ////////////////////////////////////////// See also Comment Lines.
12.6. Passthrough BlocksBy 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:
12.7. Quote BlocksQuoteBlocks are used for quoted passages of text. There are two styles: quote and verse (the first positional attribute). The attribution and citetitle attributes (positional attributes 2 and 3) specify the content author and source. If no attributes are specified the quote style is used. 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. ____________________________________________________________________ Which is rendered as: 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. __________________________________________________ Which is rendered as: 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 12.8. Example BlocksExampleBlocks 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. ===================================================================== Renders: 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. ===================================================================== 12.9. Admonition BlocksThe 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. ===================================================================== Renders:
See also Admonition Icons and Captions. 13. ListsList types
List behavior
13.1. Bulleted and Numbered ListsBulleted list items start with a dash or an asterisk followed by a space or tab character. Bulleted list syntaxes are: - List item. * List item. There are two numbered list item syntaxes:
You can use the style attribute to specify an alternative numbering style. The numbered list style can be set to one of the following values: arabic, loweralpha, upperalpha, lowerroman, upperroman. Examples of numbered list items: . Arabic (decimal) numbered list item. 1. Arabic (decimal) numbered list item. .. Lower case letter numbered list item. a. Lower case letter numbered list item. A. Upper case letter numbered list item. iii. Lower case roman numbered list item. IX. Upper case roman numbered list item. Here are some examples of bulleted and numbered lists: - 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. 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. .. Fusce euismod commodo velit. .. Vivamus fringilla mi eu lacus. 3. Donec eget arcu bibendum nunc consequat lobortis. 4. Nam fermentum mattis ante. Which render as:
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.
13.2. Labeled ListsLabeled 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 a double colon :: or semi-colon ;;. 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. Here are some examples: 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. Which render as:
13.2.1. Horizontal labeled list styleThe 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. Which render as:
13.3. Question and Answer ListsAsciiDoc 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. Renders:
13.4. Glossary ListsAsciiDoc 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.
13.5. Bibliography ListsAsciiDoc 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.
13.6. List Item ContinuationTo include subsequent block elements in list items (in addition to implicitly included nested lists and Literal paragraphs) place a separator line containing a single plus character between the list item and the ensuing list continuation element. Multiple block elements (excluding section Titles and BlockTitles) may be included in a list item using this technique. Note that the continued items must be indented as they normally would be outside of the list. You also need to use list item continuation if a nested list is accompanied by an attribute list. Here’s an example of list item continuation: 1. List item one. + List item one continued with a second paragraph followed by an Indented block. + ................. $ ls *.sh $ mv *.sh ~/tmp ................. + List item one continued with a third paragraph. 2. List item two. List item two literal paragraph (no continuation required). - Nested list (item one). Nested list literal paragraph (no continuation required). + Nested list appended list item one paragraph - Nested list item two. Renders:
13.7. List BlockA List block is a special delimited block containing a list element.
The List Block is useful for:
Here’s an example of a nested list block: .Nested List Block 1. List item one. + 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 list item b. -- + This paragraph belongs to item 1. 2. Item 2 of the outer list. Renders: Nested List Block
14. FootnotesThe shipped AsciiDoc configuration includes the footnote:[<text>] and footnoteref:[<id>,<text>] inline macros for generating footnotes:
Example footnote: 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]. Which renders: A footnote Footnotes are primarily useful when generating DocBook output — DocBook conversion programs render footnote outside the primary text flow. 15. IndexesThe shipped AsciiDoc configuration includes the inline macros for generating document index entries.
For working examples see the article.txt and book.txt documents in the AsciiDoc ./doc distribution directory.
16. CalloutsCallouts 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. Which renders: 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>
Explanation
16.1. Implementation NotesCallout 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:
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. 16.2. Including callouts in included codeYou 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> 17. MacrosMacros 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
17.1. Inline MacrosInline Macros occur in an inline element context. Predefined Inline macros include URLs, image and link macros. 17.1.1. URLshttp, https, ftp, file, mailto and callto URLs are rendered using predefined inline macros.
Here are some examples: 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[] Which are rendered:
17.1.2. Internal Cross ReferencesTwo 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. anchorUsed 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: [[X1]] 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. xrefCreates 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: <<X21,attribute lists>> If <caption> is not specified then the displayed text is auto-generated:
Here is an example: [[tiger_image]] .Tyger tyger image::tiger.png[] This can be seen in <<tiger_image>>. 17.1.3. Linking to Local DocumentsHypertext links to files on the local file system are specified using the link inline macro. link:<target>[<caption>] 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. Images can serve as hyperlinks using the image macro. 17.1.4. ImagesInline 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
17.2. Block MacrosA 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:
17.2.1. Block IdentifierThe 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: [[X30]] This is equivalent to the [id="X30"] block attribute list. 17.2.2. ImagesFormal titled images are inserted into the output document using the image macro. The syntax is: image::<target>[<attributes>] The block image macro has the same macro attributes as its inline counterpart. 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. For example: .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] 17.2.3. Comment LinesSingle lines starting with two forward slashes hard up against the left margin are treated as comments and are stripped from the output. Comment lines have been implemented as a block macro and are only valid in a block context — they are not treated as comments inside paragraphs or delimited blocks. Example comment line: // This is a comment. See also Comment Blocks. 17.3. System MacrosSystem macros are block macros that perform a predefined task and are hardwired into the asciidoc(1) program.
17.3.1. Include MacrosThe 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 main use is to include verbatim embedded CSS or scripts into configuration file headers. Example: include::chapter1.txt[tabsize=4] Include macro behavior
17.3.2. Conditional Inclusion MacrosLines 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 forms of conditional inclusion macro usage, the first includes document text between the ifdef and endif macros if a document attribute is defined: ifdef::<attribute>[] : endif::<attribute>[] The second for 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. Take a look at the *.conf configuration files in the AsciiDoc distribution for examples of conditional inclusion macro usage. 17.3.3. eval, sys and sys2 System MacrosThese 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] ------------------ 17.3.4. Template System MacroThe 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
17.4. Passthrough macrosPassthrough 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).
17.5. Macro DefinitionsEach entry in the configuration [macros] section is a macro definition which can take one of the following forms:
<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:
Here’s what happens during macro substitution
18. TablesThe 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. There are a wide variety of built-in customizable styles.
18.1. Example tables18.1.1. Simple table
AsciiDoc source: [width="15%"] |======= |1 |2 |A |3 |4 |B |5 |6 |C |======= 18.1.2. Columns formatted with strong, monospaced and emphasis styles
AsciiDoc source: .An example table [width="50%",cols=">s,^m,e",frame="none",options="header,footer"] |========================== | |Column 2|Column 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 |========================== 18.1.3. Horizontal and vertical source dataShort 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). |========================================================= 18.1.4. A table with externally sourced CSV data
AsciiDoc source: [format="csv",cols="^1,4*2",options="header"] |=================================================== ID,Customer Name,Contact Name,Customer Address,Phone include::customers.csv[] |=================================================== 18.2. Table input data formatsAsciiDoc table data can be psv, dsv or csv formatted. The default AsciiDoc table format is psv. csv is the quasi-standard row oriented Comma Separated Values (CSV) format commonly used to import and export spreadsheet and database data. 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 mandatory row separators.
Here are four psv cells (the second item is multiplied by two; the last contains an escaped separator): |One 2*|Two and three |A \| separator character 18.3. Table attributesIndividual tables are customized by an optional AttributeList preceding the table. Specify attributes when you want to change the default table format:
18.4. Column SpecifiersColumn specifiers define how columns are presented and are used 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>]
18.5. Table stylesTable 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:
18.6. Markup attributesAsciiDoc 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.
18.7. Nested tablesAn 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. Manpage DocumentsSooner 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). 19.1. Document HeaderA 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. 19.2. The NAME SectionThe 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 19.3. The SYNOPSIS SectionThe second manpage section is mandatory and must be titled SYNOPSIS. 19.4. refmiscinfo attributesIn 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: {revision} :man manual: AsciiDoc Manual 20. Mathematical FormulasThe 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:
20.1. LaTeX MathLaTeX math can be included in documents that are processed by dblatex(1). Example inline formula: latexmath:[$C = \alpha + \beta Y^{\gamma} + \epsilon$] For more examples see the AsciiDoc website or the distributed doc/latexmath.txt file. 20.2. ASCIIMathMLASCIIMathML 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. 20.3. LaTeXMathMLLaTeXMathML 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. There are more examples on the AsciiDoc website. 20.4. MathMLMathML 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. 21. Configuration FilesAsciiDoc 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. 21.1. Configuration File FormatConfiguration 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.
AsciiDoc reserves the following section names for specific purposes:
Each line of text in these sections is a section entry. Section entries share the following syntax:
Section entry behavior
21.2. Miscellaneous sectionThe optional [miscellaneous] section specifies the following name=value options:
21.3. Titles section
21.4. Tags sectionThe [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: emphasis=<em>|</em> 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. 21.5. Attributes sectionThe 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) 21.6. Special Characters sectionThe [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 <. <=< 21.7. Quoted Text sectionQuoting 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: [quotes] _=emphasis [tags] emphasis=<em>|</em> You can specify the left and right quote strings separately by separating them with a | character, for example: ``|''=quoted 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: [quotes] ^= ~= Unconstrained quotes are differentiated by prefixing the tag name with a hash character, for example: __=#emphasis Quoted text behavior
21.8. Special Words sectionThe [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
21.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
21.10. Markup Template SectionsMarkup 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. 21.11. Configuration File Names and LocationsConfiguration 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 following implicit configuration files from each of the above locations are loaded in the following order:
Where <backend> and <doctype> are values specified by the asciidoc(1) -b (--backend) and -d (--doctype) command-line options. <lang> is the value of the AsciiDoc lang attribute (defaults to en (English)). Finally, 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 Configuration files (if they exist) will be processed in the following order:
22. Document AttributesA 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):
Within each of these divisions the last processed entry takes precedence.
23. Attribute EntriesThe 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: :<name>: <value> For example: :Author Initials: JB This will set an attribute reference {authorinitials} to the value JB in the current document. To delete (undefine) an attribute use the following syntax: :<name>!: AttributeEntry behavior
AsciiDoc User Manual ==================== :Author: Stuart Rackham :Email: srackham@gmail.com :Date: April 23, 2004 :Revision: 5.1.1 :Key words: linux, ralink, debian, wireless :Revision history: Which creates these attributes: {author}, {firstname}, {lastname}, {authorinitials}, {email}, {date}, {revision}, {keywords}, {revisionhistory} The preceding example is equivalent to the standard AsciiDoc two line
document header. Actually it’s a little bit different with the
addition of the {keywords} and {revisionhistory} attributes
23.1. Setting configuration entriesA 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 24. Attribute ListsAn 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:
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
24.1. Options attributeIf the attribute list contains an attribute named options it is processed as a comma separated list of option names:
24.2. Macro Attribute listsMacros 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. 24.3. AttributeList ElementAn attribute list on a line by itself constitutes an AttributeList block element, its attributes apply to the following block element. The list attributes are passed to the next block element for markup template substitution. Often the first list parameter is used to specify the element’s style. 25. Attribute ReferencesAn 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
25.1. Simple Attributes ReferencesSimple 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. 25.2. Conditional Attribute ReferencesAdditional parameters are used in conjunction with the attribute name to calculate a substitution value. Conditional attribute references take the following forms:
25.2.1. Conditional attribute examplesConditional attributes are mainly used in AsciiDoc configuration files — see the distribution .conf files for examples.
25.3. System Attribute ReferencesSystem attribute references generate the attribute text value by executing a predefined action that is parametrized by a single argument. The syntax is {<action>:<argument>}.
System reference behavior
26. Intrinsic AttributesIntrinsic 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 {date} document date (from document header) {docname} document file name without extension {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} document input directory name (note 1) {infile} input file name (note 1) {lastname} author last name (from document header) {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 1) {outfile} output file name (note 1) {revision} document revision number (from document header) {sectnum} section number (in section titles) {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
27. Block Element DefinitionsThe 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:
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. 27.1. StylesA 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"
27.2. ParagraphsParagraph 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:
Paragraph specific block parameter notes:
Paragraph processing proceeds as follows:
27.3. Delimited BlocksDelimitedBlock options values are:
presubs, postsubs and filter entries are meaningless when sectionbody, skip or list options are set. DelimitedBlock processing proceeds as follows:
27.4. ListsList 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:
27.5. TablesTable 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:
Table behavior is also influenced by the following [miscellaneous] configuration file entries:
Table definition behavior
28. FiltersFilters 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.
28.1. Filter Search PathsIf the filter command does not specify a directory path then asciidoc(1) searches for the command:
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. 28.2. Filter Configuration FilesFilters 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 an existing Paragraph or DelimitedBlock definition (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). 28.3. Code FilterAsciiDoc comes with a toy filter for highlighting source code keywords and comments. See also the ./filters/code/code-filter-readme.txt file.
.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 ---------------------------------------------- Outputs: 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 28.4. Source Code Highlighter FilterA source code highlighter filter can be found in the AsciiDoc distribution ./filters directory. 28.5. Music FilterA 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. 29. Converting DocBook to other file formatsDocBook 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. 29.1. a2x Toolchain WrapperOne 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.
29.2. HTML generationAsciiDoc produces nicely styled HTML directly without requiring a DocBook toolchain but there are also advantages in going the DocBook route:
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). 29.3. PDF generationdblatex or FOP?
29.4. HTML Help generation
29.5. Toolchain components summary
29.6. AsciiDoc dblatex configuration filesThe 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). 29.7. AsciiDoc DocBook XSL Stylesheets driversYou 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.
If you want to see how the complete documentation set is processed take a look at the A-A-P script ./doc/main.aap. 30. Generating Plain Text FilesAsciiDoc 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. 31. XML and Character SetsThe 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 your system has been configured with an XML catalog you may find a number of entity sets are already automatically included. 31.1. PDF FontsThe 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. 32. Help CommandsThe asciidoc(1) command has a --help option which prints help topics to stdout. The default topic summarizes asciidoc(1) usage: $ asciidoc --help To print a list of help topics: $ asciidoc --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. 32.1. Customizing HelpTo 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. 33. Tips and Tricks33.1. Know Your EditorWriting 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. 33.2. Vim Commands for Formatting AsciiDoc33.2.1. Text Wrap ParagraphsUse the vim :gq command to reformat paragraphs. Setting the textwidth sets the right text wrap margin; for example: :set textwidth=70 To reformat a paragraph:
Execute :help gq command to read about the vim gq command.
33.2.2. Format ListsThe 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:
33.2.3. Indent ParagraphsIndent whole paragraphs by indenting the fist line with the desired indent and then executing the gq} command. 33.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:> 33.3. Troubleshooting
33.4. Gotchas
33.5. Combining separate documentsYou 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.
33.6. Processing document sections separatelyYou 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 33.7. Processing document snippetsasciidoc(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> 33.8. Badges in HTML page footersSee the [footer] section in the AsciiDoc distribution xhtml11.conf configuration file. 33.9. Pretty printing AsciiDoc outputIf the indentation and layout of the asciidoc(1) output is not to your liking you can:
33.10. Supporting minor DocBook DTD variationsThe 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. 33.11. Shipping stand-alone AsciiDoc sourceReproducing 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. 33.12. Inserting blank spaceAdjust 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. 33.13. Closing open sectionsYou 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[] 33.14. Validating output filesUse 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. 34. Glossary
35. Appendix A: Migration Notes35.1. Version 7 to version 8
The rationale for the changes can be found in the AsciiDoc CHANGELOG.
36. Appendix B: Packager NotesRead 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. 37. Appendix C: AsciiDoc Safe ModeAsciiDoc 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
38. Appendix D: Using AsciiDoc with non-English LanguagesAsciiDoc can process UTF-8 character sets but there are some things you need to be aware of:
39. Appendix E: Vim Syntax HighlighterThe 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:
39.1. LimitationsThe current implementation does a reasonable job but on occasions gets things wrong. This list of limitations also discusses how to work around the problems:
40. Appendix F: Attribute OptionsHere is the list of predefined attribute list options:
|