In Asciidoctor we can add an anchor with an ID to a section or title and then reference it in a link. The title of the section is used as link text. We can alter that when we define the link, but if we rely on the default behaviour we create a title for our section including the caption label and number. This way the created link points to the correct section and the text contains the caption text and number for that section.
Asciidoctor has some built-in attributes to work with captions for certain content blocks. For example the
table-section attribute defines the caption label (by default Table) that is prefixed to a counter for all tables in the document. When we transform our markup Asciidoctor will insert the text Table followed by the table number. By default the caption for listing blocks is disabled, but we can easily enable it with the
In Asciidoctor we can configure syntax highlighting for our source code listings. We can choose from the built-in support for Coderay, Pygments, highlight.js and prettify. The syntax highlighter libraries Coderay and Pygments support extra highlighting of lines, so we can add extra attention to those lines. In this post we see how to use the line highlighting feature in Asciidoctor.
With Asciidoctor we can use images in our documents with the
image directive. When the document is converted each image gets a caption. By default the caption label is Figure followed a number for the position of the image in the document. So the first image has a caption Figure 1.. If we add a block title (text prefixed with a
.) to the image then that text is used in the caption as well. We can customize the caption label, figure counter, caption text or disable the figure caption using a combination of document and
Asciidoctor has several captions and labels that can be overridden with document attributes. We need to define a document attribute and assign a new value to override a default caption or label. We can use UTF-8 characters as the value. The following list shows captions and labels we can override:
When we use the
include directive to include another document we can must make sure the included document fits the levels of our main document. For example the included document shouldn’t have level 0 headings if the main document already contains a level 0 heading. We can change the level offset in the main document before including another document. This will change the heading levels for the included document so all heading rules are okay.
In Asciidoctor we can create a document attribute as a counter attribute. The attribute is automatically incremented each time we use it in our markup. We can choose to use numbers or characters. Only latin characters from ‘a’ to ‘z’ or ‘A’ to ‘Z’ are allowed. By default the counter will start at 1, but we can define another start value when we use the counter attribute for the first time.
With Asciidoctor we can use text to describe a symbol in our markup. The text is automatically transformed to a Unicode replacement. For example if we use the text
(C) it is converted to
© which is the copyright symbol: ©.
In the following sample we see all the symbol replacements:
Written with Asciidoctor 1.5.2.
GitHub supports Asciidoctor markup. We can add a document to GitHub with the extension
adoc and it is parsed and the resulting HTML is shown when we view the document in our web browser in a GitHub repository. In March 2016 Dan Allen tweeted about enabling admonition icons on GitHub. A follow-up tweet by Ted Bergeron mentioned more examples. In this post we see an example on how to use their suggestions. Normally we wouldn’t see an icon, but we can use document attributes and assign an emoji for each admonition type. For example a note admonition icon is set with the document attribute
note-caption. We can use a condition check to see if the document is rendered on GitHub and only then use the document attributes.