Asciidoctor Diagram is a set of Asciidoctor extensions that enable you to add diagrams, which you describe using plain text, to your AsciiDoc document.
The extensions supports the AsciiToSVG, BlockDiag (BlockDiag, SeqDiag, ActDiag, NwDiag), Ditaa, Erd, GraphViz, Mermaid, Msc, Nomnoml, PlantUML, Shaape, State Machine Cat, SvgBob, Syntrax, UMLet, Vega, Vega-Lite and WaveDrom syntax.
Each extension runs the diagram processor to generate an SVG, PNG, or TXT file from the input text. The generated file is then inserted into your converted document.
Asciidoctor Diagram was inspired by the AsciiDoc PlantUML filter.
Translations of the document are available in the following languages:
Asciidoctor Diagram is a RubyGem, which can be installed using the gem
or bundle
commands.
You can install the Asciidoctor Diagram gem by typing gem install
in the CLI.
$ gem install asciidoctor-diagram
by first adding the following entry to your project’s Gemfile.
gem 'asciidoctor-diagram'
Then execute bundle
in the CLI.
$ bundle
A diagram is written inside a literal block, which can accept several attributes.
[diagram-type, generated-file-name, generated-image-format] // (1) (2) (3)
.... // (4)
Diagram in appropriate syntax
....
-
The first positional attribute in the attribute list specifies the diagram that is being used.
-
The second, optional positional attribute assigns a file name (i.e.
target
) to the generated diagram. If a target is not specified an auto-generated name will be used. -
The third, optional positional attribute specifies the image format to create, specified as a three character file extension.
-
Place the attribute list directly on top of the delimited literal block (....). You can also use an open block as an alternative (
--
).
The following diagram types and output formats are available:
Diagram Type | gif | png | svg | txt | |
---|---|---|---|---|---|
☑️ |
|||||
☑️ |
☑️ |
☑️ |
|||
☑️ |
☑️ |
☑️ |
|||
☑️ |
☑️ |
||||
☑️ |
☑️ |
||||
☑️ |
☑️ |
☑️ |
|||
☑️ |
☑️ |
||||
☑️ |
☑️ |
☑️ |
|||
☑️ |
☑️ |
||||
☑️ |
|||||
☑️ |
☑️ |
☑️ |
|||
☑️ |
☑️ |
☑️ |
|||
☑️ |
☑️ |
☑️ |
|||
☑️ |
☑️ |
☑️ |
|||
☑️ |
☑️ |
☑️ |
|||
☑️ |
☑️ |
||||
☑️ |
|||||
☑️ |
|||||
☑️ |
☑️ |
☑️ |
|||
☑️ |
☑️ |
☑️ |
☑️ |
||
☑️ |
☑️ |
||||
☑️ |
☑️ |
||||
☑️ |
☑️ |
The example below illustrates the structure of a basic ditaa block written directly in an AsciiDoc document.
[ditaa]
....
+-------------+
| Asciidoctor |-------+
| diagram | |
+-------------+ | PNG out
^ |
| ditaa in |
| v
+--------+ +--------+----+ /---------------\
| | --+ Asciidoctor +--> | |
| Text | +-------------+ | Beautiful |
|Document| | !magic! | | Output |
| {d}| | | | |
+---+----+ +-------------+ \---------------/
: ^
| Lots of work |
+-----------------------------------+
....
The ditaa block above results in the following generated diagram.
The rendered ditaa diagram above gets the file name 58372f7d2ceffae9e91fd0a7cbb080b6.png
.
That long number is the checksum of the source code calculated by asciidoctor-diagram.
If you want to give your generated files a more meaningful name, fill in the target
attribute.
This can be done by either specifying it as the second positional attribute or as a named attribute.
Both examples below would result in a file called ditaa-diagram.png
.
[ditaa, "ditaa-diagram"] ---- <snip> ---- [ditaa, target="ditaa-diagram"] ---- <snip> ----
The example below illustrates the structure of a basic PlantUML block written directly in an AsciiDoc document.
[plantuml, diagram-classes, png] // (1) (2) (3)
....
class BlockProcessor
class DiagramBlock
class DitaaBlock
class PlantUmlBlock
BlockProcessor <|-- DiagramBlock
DiagramBlock <|-- DitaaBlock
DiagramBlock <|-- PlantUmlBlock
....
-
The diagram is written in PlantUML so the first positional attribute is assigned the
plantuml
diagram type. -
The name of the generated diagram file (target) is written in the second positional attribute.
-
The output format is entered in the third positional attribute.
You can load Asciidoctor diagram in a terminal using the -r
flag.
$ asciidoctor -r asciidoctor-diagram sample.adoc
You can also use Asciidoctor diagram with other converters, such as Asciidoctor EPUB.
Asciidoctor-epub3 is also loaded with the -r
flag.
$ asciidoctor -r asciidoctor-diagram -r asciidoctor-epub3 -b epub3 sample.adoc
Or, you can invoke Asciidoctor and the EPUB converter with the asciidoctor-epub3
command.
The command implicitly sets the -r
and -b
flags for EPUB3 output.
$ asciidoctor-epub3 -r asciidoctor-diagram sample.adoc
In your program, you can either load and register the entire set of diagram extensions
require 'asciidoctor-diagram'
or load and register each extension individually.
require 'asciidoctor-diagram/<extension_name>'
<extension_name>
can be one of a2s
, blockdiag
, ditaa
, erd
, graphviz
, meme
, mermaid
, msc
, plantuml
, shaape
, smcat
, svgbob
, syntrax
, umlet
, vega
or wavedrom
.
Requiring one or more of these files will automatically register the extensions for all processed documents.
If you need more fine grained control over when the extensions are enabled, asciidoctor-diagram/<extension_name>/extension
can be used instead.
This loads the extensions but does not register it in the Asciidoctor extension registry.
You can then manually register the extensions at the appropriate times using the Asciidoctor::Extensions
API.
This document explains the various features of asciidoctor-diagram blocks using ditaa diagrams as an example.
The diagram extensions can also be used in in block macro form.
block-name::source-file-name[generated-file-extension] // (1) (2) (3)
-
The macro name is the same as the block name in the block form.
-
The source file name specifies the external file that contains the diagram source code.
-
The first, optional, positional attribute assigns the file extension (i.e.
format
) to the generated diagram.
When the source file name is a relative path it is resolved with respect to the location of the document being processed.
When Asciidoctor Diagram writes images to disk it will go over the following options in order to determine where to write the files.
-
{imagesoutdir}
if theimagesoutdir
attribute has been specified -
{outdir}/{imagesdir}
if theoutdir
attribute has been specified -
{to_dir}/{imagesdir}
if theto_dir
attribute has been specified -
{base_dir}/{imagesdir}
Asciidoctor Diagram depends on external tools to generates images.
In most cases it will locate these tools automatically for you by looking for specific executables in each directory in the PATH
environment variable.
In case you’ve installed a tool in a way where the executable is not in the PATH
, you can override its location manually using document attributes.
The following table lists the tools that are required for each diagram type, the location where they can be downloaded and the document attribute you can use to override their locations.
Diagram Type | Tool | Attribute |
---|---|---|
a2s |
|
|
actdiag |
|
|
blockdiag |
|
|
ditaa |
|
|
erd |
|
|
graphviz |
|
|
meme |
|
|
mermaid |
|
|
msc |
|
|
nomnoml |
|
|
nwdiag |
|
|
packetdiag |
|
|
plantuml |
|
|
rackdiag |
|
|
seqdiag |
|
|
shaape |
|
|
smcat |
|
|
svgbob |
|
|
syntrax |
|
|
umlet |
|
|
vega |
|
|
vegalite |
|
|
wavedrom |
|
|
WaveDrom CLI (and PhantomJS for WaveDrom CLI v1) |
|
If for instance you installed actdiag
in /home/me/actdiag/bin
and this path is not included in the PATH
you can specify its location on the command line
$ asciidoctor -a actdiag=/home/me/actdiag/bin/actdiag -r asciidoctor-diagram sample.adoc
The meme extension provides a basic ‘Advice Animal’ style image generator. It’s usage is easiest to explain with an example.
meme::yunoguy.jpg[Doc writers,Y U NO // AsciiDoc]
The target of the block macro tells the extension which image to use as background.
The first two positional attributes are top
and bottom
and are used for the top and bottom label.
Occurrences of //
surrounded by whitespace are interpreted as line breaks.
Certain diagram types allow image generation to be customized using attributes.
Each attribute can be specified either at the block level or at the document level.
This is illustrated for the blockdiag fontpath
attribute in the example below.
= Asciidoctor Diagram
:blockdiag-fontpath: /path/to/font.ttf (1)
[blockdiag] (2)
....
....
[blockdiag, fontpath="/path/to/otherfont.ttf"] (3)
....
....
-
Block level attributes can be specified at the document level by prefixing them with
<blocktype>-
-
The first diagram does not specify an explicit value for
fontpath
so the global value will be used -
The second diagram specifies a
fontpath
value which overrrides the global value
Each attribute can either be specified at the block level or at the document level. The attribute name at the block level should be prefixed with the name of the diagram type and a dash.
Name | Default value | Description |
---|---|---|
fontfamily |
unspecified |
The font family to use in the generated SVG image |
noblur |
unspecified |
Disable drop-shadow blurring |
Name | Default value | Description |
---|---|---|
fontpath |
unspecified |
The path to the font that should be used by blockdiag |
Name | Default value | Description |
---|---|---|
scale |
1 |
A scale factor that is applied to the image. |
tabs |
8 |
An integer value that specifies the tab size as a number of spaces. |
background |
FFFFFF |
The background colour of the image. The format should be a six-digit hexadecimal number (as in HTML, FF0000 for red). Pass an eight-digit hex to define transparency. |
antialias |
true |
Enables or disables anti-aliasing. |
separation |
true |
Prevents the separation of common edges of shapes. |
round-corners |
false |
Causes all corners to be rendered as round corners. |
shadows |
true |
Enables or disable drop shadows. |
debug |
false |
Renders the debug grid over the resulting image. |
fixed-slope |
false |
Makes sides of parallelograms and trapezoids fixed slope instead of fixed width. |
transparent |
false |
Makes the background of the image transparent instead of using the background color. |
Name | Default value | Description |
---|---|---|
layout |
unspecified |
The graphviz layout engine to use (dot -K option). |
Name | Default value | Description |
---|---|---|
fillColor |
white |
The fill color for the text. |
strokeColor |
black |
The outline color for the text |
strokeWidth |
2 |
The width of the text outline. |
font |
Impact |
The font face to use for the text. |
options |
unspecified |
a comma separate list of flags that modify the image rendering. Currently only |
Name | Default value | Description |
---|---|---|
background |
FFFFFF |
The background colour of the image. The format should be a six-digit hexadecimal number (as in HTML, FF0000 for red). Pass an eight-digit hex to define transparency. |
css |
unspecified |
Path to a CSS file to pass to mermaid. |
config |
unspecified |
Path to a JSON config file to pass to mermaid. |
ganttconfig |
unspecified |
Path to a gantt config file to pass to mermaid. |
sequenceconfig |
unspecified |
Path to a sequence config file to pass to mermaid. |
theme |
unspecified |
Theme of the chart, could be default, forest, dark or neutral. |
width |
unspecified |
Width of the page. |
height |
unspecified |
Height of the page. |
Name | Default value | Description |
---|---|---|
font |
unspecified |
The name of the font that should be used by mscgen |
Name | Default value | Description |
---|---|---|
config |
unspecified |
Path to a config file to pass to PlantUML. |
Name | Default value | Description |
---|---|---|
direction |
unspecifed |
The direction of the state machine diagram. One of |
engine |
unspecified |
The layout engine to use. One of |