Asciidoctor is a Ruby tool, but luckily we can use AsciidoctorJ to use Asciidoctor in Java code. The Asciidoctor Gradle plugin relies on AsciidoctorJ to run. AsciidoctorJ allows us to write custom extensions in Java (or Groovy), but we can still use Asciidoctor extensions written in Ruby with the Gradle plugin.
In the following example we use the emoji-inline-macro from Asciidoctor extensions lab.
This is an extension written in Ruby. We create a new directory for our sample and create a
lib directory we copy the file
emoji-inline-macro.rb and the supporting directory
These files are all in the Asciidoctor extensions lab repository.
After we have copied the files we should have the following structure:
$ tree lib/
│ ├── extension.rb
│ ├── sample.adoc
│ └── twemoji-awesome.css
1 directory, 4 files
In our build file we configure the
asciidoctor task and use the
requires method to define a dependency on the Ruby
// File: build.gradle
id 'org.asciidoctor.convert' version '1.5.3'
// Add requirement on Ruby extension.
We are done. Next we create a sample Asciidoc markup document with the following content:
= Asciidoctor is awesome!
Writing with Asciidoctor makes me feel emoji:sunny[5x]
This sample is written while Devoxx BE is in progress, so
@DevoxxPeople: Enjoy your emoji:beers
We get the following HTML5 output when we run the
Written with Asciidoctor Gradle plugin 1.5.3.