Dark theme | Light theme

June 13, 2014

Awesome Asciidoctor: Use Link Attributes

To define a link in Asciidoc markup we only have to type the URL followed by an optional text for the link in square brackets ([text link]). With Asciidoctor we can add extra attributes that can be used when the content is generated. We have to set the document attribute :linkattrs: to make sure Asciidoctor will process the attributes.

In the following sample Asciidoc markup we define links with attributes like window and role:

:linkattrs:[Messages from mrhaki, window="_blank"]

// Because window=_blank is used often we can 
// use the shortcut ^.[Messages from mrhaki^, role="ext-link"]

The following HTML is generated when we use Asciidoctor with the HTML backend:

<div class="paragraph">
<p><a href="" target="_blank">Messages from mrhaki</a></p>
<div class="paragraph">
<p><a href="" class="ext-link" target="_blank">Messages from mrhaki</a></p>

Code written with Asciidoctor 0.1.4.