A Brief Introduction to AsciiDoc
The source code for this document is available at github. Unfortunately though, GitHub does NOT support includes so you won’t see this document rendered properly. Instead, I’ve used the Intellij plugin to generate a PDF document which you can see here: ReadMe.pdf.
Introduction
AsciiDoc is a text document format similar to Markdown but with extra features and a more standardized syntax. It can output to different formats like HTML, PDF, docx, epub, etc.
Like Markdown, it’s a plain text format, so it is easy to read and edit.
I find it particularly attractive for documenting code because you can include code snippets and have them automatically formatted - by including tags in your source code, you can reference them in your AsciiDoc file. There are a couple of other ways to do this, but I like tags in the source code since you’ll know when you are editing this that the code is being used in documentation.
My main use-cases
Code Snippets
To include code snippets, you need to tag the code using comments like this:
// tag::tag1[]
awesome code goes here
// end::tag1[]And then you can reference the tag in an include:
include::../../test/kotlin/org/example/LibraryTest.kt[tags=tag1]And you’ll get this in your generated document:
@Test fun someLibraryMethodReturnsTrue() {
val classUnderTest = Library()
assertTrue(classUnderTest.someLibraryMethod(), "someLibraryMethod should return 'true'")
}Variables
Being able to declare variables and reuse them in the document is also nice, as is being able to include other documents and even CSV files (as tables!).
I can define a variable like this:
// define a variable which can be used later :pauls-software-url: https://paulr70.substack.com
And then use it in the document like this:
Visit my newsletter here {pauls-software-url}[Pauls Software Substack].Which will render like this:
Visit my newsletter here Pauls Software Substack.
CSV files
You can also include CSV files as tables:
.Sample CSV [source,csv] ,=== include::./lib/src/docs/data/simple.csv[] ,===
Which will render like this:
id | firstname | desc |
1 | Homer | Dad |
2 | Marge | Mother |
Including other documents
You can also include other asciidoc files using the include directive:
include::lib/src/docs/includes/references.adoc[]
Table of contents
Create an automatic table of contents with the toc attribute:
:toc: :toclevels: 3
Intellij Plugin
Intellij has a plugin for AsciiDoc. It supports previewing the document in a preview pane, and you can click on the tag to jump to it. If the link doesn’t resolve, you’ll see the error highlighted in the editor.

Gradle
Gradle is supported, so with the right plugins configured you can generate HTML, PDF, EPUB from your asciidoc files with some simple gradle configuration like this:
tasks {
val asciidocAttributes = mapOf(
// define a custom attribute to be used in the document eg as {source}
// unfortunately these won't work in the intellij preview, only in the gradle output
// so you would need to separately define these attributes in the intellij settings
"source" to project.sourceSets.test.get().kotlin.srcDirs.first(),
)
"asciidoctor"(AsciidoctorTask::class) {
baseDirFollowsSourceDir()
attributes(asciidocAttributes)
}
"asciidoctorPdf"(AsciidoctorPdfTask::class) {
baseDirFollowsSourceDir()
attributes(asciidocAttributes)
}
}The asciidocAttributes map is used to pass variables to the asciidoc processor so you can use them in your document.
If you want these variables to also work in the Intellij preview pane you’ll need to configure them in the Intellij plugin settings:

In this example I’ve used defaults for everything - so my directory structure for the source looks like this:
└── src
├── docs
│ ├── asciidoc
│ │ ├── example.adoc
│ │ └── images
│ │ └── intellij-asciidoc-settings.png
│ ├── data
│ │ └── simple.csv
│ └── includes
│ └── references.adocHere, example.adoc is the main document, and references.adoc is included in example.adoc.
I can run gradle tasks to produce HTML or PDF like this (note that my documentation is in the lib sub project):
./gradlew lib:asciidoc ./gradlew lib:asciidocPdf
This produces output in the build folder:
├── build │ ├── docs │ │ ├── asciidoc │ │ │ ├── example.html │ │ │ └── images │ │ │ └── intellij-asciidoc-settings.png │ │ └── asciidocPdf │ │ └── example.pdf
Conclusion
Have fun documenting your code! There’s much more to Asciidoc than what I’ve covered here, but this is a good starting point.
GitHub will (somewhat) render asciidoc files, so you can see the output of this file here: https://github.com/prule/asciidoc-example - unfortunately github doesn’t support includes, something which is mentioned here https://github.com/github/markup/issues/1095
There is a copy of the gradle generated output in lib/example-output if you want to see what it looks like.
References
Asciidoctor
Gradle Support
Intellij Support
More