Try AsciiDoc instead of Markdown

Next time you write, use AsciiDoc and Asciidoctor as alternatives to Markdown.
7 readers like this.
Person using a laptop

I'm a happy user of the XML-based Docbook markup language. To me, it's a precise, explicit, and detailed system that allows me to have contextual and domain-specific metadata in what I write. Best of all, though, it can be transformed (that's what XML users call it when XML is converted into another format) into nearly any format, including HTML, EPUB, FO for PDF, plain text, and more. With great power comes a lot of typing, though, and sometimes Docbook feels like it's surplus to requirements. Luckily, there's AsciiDoc, a system of writing plain text with the same markup-less feel of Markdown, but that transforms to Docbook to take advantage of its precision and flexibility.

AsciiDoc rules

Like Markdown, one of the goals of AsciiDoc is that you don't really have to learn it. Instead, it aims to be intuitive and natural. You may well have written snippets of valid AsciiDoc without realizing it if you've ever added a little style to a plain text document for readability. For instance, if you habitually separate paragraphs with a blank line, then you've written the equivalent of the HTML <p> or Docbook <para> tag. It seems obvious, and yet in academia separating paragraphs with blank lines isn't generally done, so even this simple convention is technically markup.

Here's the most common syntax.

Text styles

Text styles include the basics such as bold, italics, and code font. Most of the notation is relatively intuitive, with the possible exception of italics.

*Bold*

_Italics_

*_Bold and italic_*

`Monospace or code`

Code

Code is marked with backticks or by explicit declaration of a code block.

`Monospace or code`

[source,python]
----
print('a whole code block')
----

Headlines

Headings are marked with leading equal signs (=):

= Heading 1 (<h1>)

== Heading 2 (<h2>)

=== Heading 3 (<h3>)

==== Heading 4 (<h4>)

===== Heading 5 (<h5>)

====== Heading 6 (<h6>)

Links

Hyperlinks favor the link first, followed by the word or phrase used to "disguise" the link as text.

This is a http://example.com[hyperlink] that leads to the example.com site.

I don't find this as elegant as Markdown's link notation, but then it's a lot more flexible. For instance, you can add attributes in AsciiDoc links:

This is a https://example.com[link,role=external,window=_blank] with the target="_blank" attribute set.

Lots more

AsciiDoc also features internal links so you can link from one section to another, a standard for document headers, automatic table of content generation, the ability to include other documents within another, and much much more.

But best of all, AsciiDoc is actually standardized. Not everyone knows it, but the term "Markdown" doesn't refer to one markup-light language. Different organizations and groups regularly customize and alter Markdown for their own use, so when you use Markdown you really ought to verify which markdown you're meant to use. Many of the conventions you might have learned from one website using Markdown don't carry over to another site using Markdown. There's essentially no standard for Markdown, and that's resulted in such confusion that the Commonmark.org project has been formed in an attempt to assemble a standardized definition.

AsciiDoc was designed from the start with a standard definition, so the tool or website that claims to parse AsciiDoc actually does parse all valid AsciiDoc, because there's only one valid AsciiDoc.

AsciiDoc to anything

The point of writing in a markup-light language like AsciiDoc is to ensure predictability and consistency when text is parsed. You want a person to write a script, or to run an application someone else has written, to be able to transform your plain text into whatever format works best for them. Sometimes that's HTML (incidentally Markdown's native output format, and fallback language when there's something missing from its own syntax.) Other times it's an EPUB, or a PDF for printing, Docbook, a LibreOffice document, or any number of possible output formats.

There are several tools to help you transform AsciiDoc to another format. A popular command is Asciidoctor, which you can install using your package manager. For instance, on Fedora, CentOS, or RHEL:

$ sudo dnf install asciidoctor

On Debian-based systems:

$ sudo apt install asciidoctor

Alternately, you can install it on any OS with Ruby:

$ gem install asciidoctor

Here's a simple example of an AsciiDoc document, which you can create using any text editor or even a word processor (like LibreOffice) as long as you save the file as plain text. Most applications expect a plain text document to use the extension .txt, and while it's a convention use the extension .adoc for AsciiDoc, it's not necessary. Asciidoctor doesn't require any special extension.

= This is my example document

It's not written in _Markdown_, nor _reStructured Text_.
This is *AsciiDoc*.

It can be transformed into nearly any format using the tool `Asciidoctor` and other similar parsers.
Try it for yourself!

To transform an AsciiDoc document to HTML, run asciidoctor:

$ asciidoctor example.adoc

The file example.adoc is transformed into HTML5 by default, but you can use different backends to gain access to more formats.

From AsciiDoc to XML

My favourite is the Docbook backend, because it transforms my AsciiDoc to Docbook XML, allowing me to use my existing Docbook toolchain (custom Makefiles, Apache FOP, xsltproc, xmlto, and so on) to complete my work:

$ asciidoctor --backend docbook5 example.adoc

This outputs Docbook XML. The final two built-in backends are xhtml5 and manpage.

From AsciiDoc to EPUB

If you want to turn your writing into an ebook, you can install the EPUB3 backend:

$ gem install asciidoctor-epub3

Transform your AsciiDoc into EPUB:

$ asciidoctor-epub3 example.adoc

From AsciiDoc to PDF

You can transform AsciiDoc directly to PDF, too:

$ gem install asciidoctor-pdf
$ asciidoctor-pdf example.adoc
Asciidoctor-pdf output

(Seth Kenlon, CC BY-SA 4.0)

Who should use AsciiDoc

AsciiDoc is excellent for technical writers and writers who have precise requirements for how they want text to be organized and parsed. It's a clear and strictly defined markup format that eliminates the confusion of competing Markdown formats, and it transforms to all the major formats. AsciiDoc is admittedly more verbose and possibly less intuitive than Markdown, but it's still just plain text so you can author on anything, and Asciidoctor makes processing easy. Next time you write a document for any purpose, consider trying AsciiDoc.

What to read next
Seth Kenlon
Seth Kenlon is a UNIX geek, free culture advocate, independent multimedia artist, and D&D nerd. He has worked in the film and computing industry, often at the same time.

7 Comments

An Obsidian-like editor with asciidoc support would be needed for ordinary people. Any suggestions?

Just recently, I used it for the first time to create a PDF, an assignment used for new developers to do for an interview. As I used a CI/CD pipeline with semantic versioning and a few replaceable variables, everyone in the organization uses the same document now. I am happy about it, still have to dive into styling with themes though.

I am very old school, so I appreciate the huge value in LaTex of being able to change a single line at the top of the file and change the document formatting to exactly reproduce the style of different journals, thesis styles and a variety of letter formats. Is this functionality part of AsciiDoc ?

I have been using (and loving) Asciidoc + Asciidoctor for a few years now. One element that I also enjoy is the ability to create and use custom CSS sheets to apply specific styles when the document calls for it (and honestly, the way Asciidoc handles document header information in general).

That might seem like a small thing, but as someone outside the professional Technical Writing/documentation field, it makes my working life easier, and I appreciate that.

Great article and recommendation, Seth!

Is there a simple way convert asciidoc to LibreOffice (odt) format, similar to the other examples above?

Weekly and monthly reports are a necessary evil. In 2012 my assistant and I were spending 14 hours a week preparing reports with starting with six chapters each written by different authors in MS Word, tables produced from Excel workbooks and an SQL database, progress plots, site photographs, and other “standard exhibits”. The main bottleneck was wrangling all the MS Word text into a consistent format and building tables.

The switch to Asciidoc and a bit of Python immediately cut 8 hours from the work flow. After a few months, more python code was written to tweak the workflow cutting an addition three hours.

The reports produced by the new Asciidoc workflow were high quality and directly transformed into PDF and HTML. Moreover, it was possible to prepare two versions of the reports: internal use and client use.

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.