Asciidoctor open links in new window

· by Christoph Stoettner · Read in about 1 min · (131 words)

I write most of my documentation with Asciidoctor, so saving some keystrokes is important.

You can add window=_blank to links in your Asciidoctor source.

For example:
* https://www.duckduckgo.com[window=_blank]
* https://www.duckduckgo.com[DuckDuckGo, window=_blank]
So this creates links with the html source:
<ul>
<li>
<p><a href="https://www.duckduckgo.com" class="bare" target="_blank" rel="noopener">https://www.duckduckgo.com</a></p>
</li>
<li>
<p><a href="https://www.duckduckgo.com" target="_blank" rel="noopener">DuckDuckGo</a></p>
</li>
</ul>

The good thing is, that there is a shortcut for this. You can replace window=_blank with a ^:

* https://www.duckduckgo.com[^]
* https://www.duckduckgo.com[DuckDuckGo^]
Following html source is generated
<ul>
<li>
<p><a href="https://www.duckduckgo.com" class="bare" target="_blank" rel="noopener">https://www.duckduckgo.com</a></p>
</li>
<li>
<p><a href="https://www.duckduckgo.com" target="_blank" rel="noopener">DuckDuckGo</a></p>
</li>
</ul>

You see the result is absolutly the same.

This work also with Antora and was implemented with Asciidoctor 1.5.7.

Thanks to Dan Allen to mention this in the Antora Gitter Chat.