In addition to the document title (level 0), AsciiDoc supports four section levels: 1 (top) to 4 (bottom). Section levels are delimited by section titles. Sections are translated using configuration file section markup templates. AsciiDoc generates the following intrinsic attributes specifically for use in section markup templates:
- level
- The
level
attribute is the section level number, it is normally just the title level number (1..4). However, if theleveloffset
attribute is defined it will be added to thelevel
attribute. Theleveloffset
attribute is useful for combining documents. - sectnum
- The
-n
(--section-numbers
) command-line option generates thesectnum
(section number) attribute. Thesectnum
attribute is used for section numbers in HTML outputs (DocBook section numbering are handled automatically by the DocBook toolchain commands).
Section markup templates
Section markup templates specify output markup and are defined in AsciiDoc configuration files. Section markup template names are derived as follows (in order of precedence):
- From the title’s first positional attribute or template attribute. For example, the following three section titles are functionally equivalent:
[[terms]] [glossary] List of Terms ------------- ["glossary",id="terms"] List of Terms ------------- [template="glossary",id="terms"] List of Terms -------------
- When the title text matches a configuration file
[specialsections]
entry. - If neither of the above the default
sect<level>
template is used (where<level>
is a number from 1 to 4).
In addition to the normal section template names (sect1, sect2, sect3, sect4) AsciiDoc has the following templates for frontmatter, backmatter and other special sections: abstract, preface, colophon, dedication, glossary, bibliography, synopsis, appendix, index. These special section templates generate the corresponding Docbook elements; for HTML outputs they default to the sect1 section template.
Section IDs
If no explicit section ID is specified an ID will be synthesised from the section title. The primary purpose of this feature is to ensure persistence of table of contents links (permalinks): the missing section IDs are generated dynamically by the JavaScript TOC generator after the page is loaded. If you link to a dynamically generated TOC address the page will load but the browser will ignore the (as yet ungenerated) section ID.
The IDs are generated by the following algorithm:
- 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 theidprefix
attribute is not defined. - A numbered suffix (
_2
,_3
…) is added if a same named auto-generated section ID exists. - If the
ascii-ids
attribute is defined then non-ASCII characters are replaced with ASCII equivalents. This attribute may be deprecated in future releases and should be avoided, it’s sole purpose is to accommodate deficient downstream applications that cannot process non-ASCII ID attributes.
Example: the title Jim’s House would generate the ID _jim_s_house
.
Section ID synthesis can be disabled by undefining the sectids
attribute.
Special Section Titles
AsciiDoc has a mechanism for mapping predefined section titles auto-magically to specific markup templates. For example a title Appendix A: Code Reference will automatically use the appendix section markup template. The mappings from title to template name are specified in [specialsections]
sections in the Asciidoc language configuration files (lang-*.conf
). Section entries are formatted like:
<title>=<template>
<title>
is a Python regular expression and <template>
is the name of a configuration file markup template section. If the <title>
matches an AsciiDoc document section title then the backend output is marked up using the <template>
markup template (instead of the default sect<level>
section template). The {title}
attribute value is set to the value of the matched regular expression group named title, if there is no title group {title}
defaults to the whole of the AsciiDoc section title. If <template>
is blank then any existing entry with the same <title>
will be deleted.
Special section titles vs. explicit template names AsciiDoc has two mechanisms for specifying non-default section markup templates: you can specify the template name explicitly (using the template attribute) or indirectly (using special section titles). Specifying a section template attribute explicitly is preferred. Auto-magical special section titles have the following drawbacks:
Specifying special section template names explicitly does add more noise to the source document (the template attribute declaration), but the intention is obvious and the syntax is consistent with other AsciiDoc elements c.f. bibliographic, Q&A and glossary lists. Special section titles have been deprecated but are retained for backward compatibility. |