Skip to content

↔️ Asciidoctor diagram extension, with support for PlantUML, Graphviz and ditaa.

License

MIT and 2 other licenses found

Licenses found

MIT
LICENSE.txt
LGPL-3.0
ditaamini-license.txt
Apache-2.0
plantuml-license.txt
Notifications You must be signed in to change notification settings

dkus/asciidoctor-diagram

 
 

Asciidoctor Diagram

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 support BlockDiag (BlockDiag, SeqDiag, ActDiag, NwDiag), Ditaa, GraphViz, Mermaid, PlantUML, Shaape 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:

Status

Linux Build Status Windows Build Status Gem Version

Installation

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.

Gemfile
gem 'asciidoctor-diagram', '~> 1.4.0'

Then execute bundle in the CLI.

$ bundle

Creating a Diagram

A diagram is written inside a literal block, which can accept several attributes.

Anatomy of a diagram
[diagram-type, generated-file-name, generated-image-format] // (1) (2) (3)
.... // (4)
Diagram in appropriate syntax
....
  1. The first positional attribute in the attribute list specifies the diagram that is being used.

  2. 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.

  3. The third, optional positional attribute specifies the image format to create, specified as a three character file extension.

  4. 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 pdf png svg txt

actdiag

☑️

☑️

☑️

blockdiag

☑️

☑️

☑️

ditaa

☑️

erd

☑️

☑️

graphviz

☑️

☑️

☑️

meme

☑️

☑️

mermaid

☑️

☑️

nwdiag

☑️

☑️

☑️

packetdiag

☑️

☑️

☑️

plantuml

☑️

☑️

☑️

rackdiag

☑️

☑️

☑️

seqdiag

☑️

☑️

☑️

shaape

☑️

☑️

umlet

☑️

☑️

☑️

☑️

wavedrom

☑️

☑️

The example below illustrates the structure of a basic ditaa block written directly in an AsciiDoc document.

Basic ditaa block
[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.

Asciidoctor Diagram process diagram
Rendered ditaa 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 Syntax
[plantuml, diagram-classes, png] // (1) (2) (3)
....
class BlockProcessor
class DiagramBlock
class DitaaBlock
class PlantUmlBlock

BlockProcessor <|-- DiagramBlock
DiagramBlock <|-- DitaaBlock
DiagramBlock <|-- PlantUmlBlock
....
  1. The diagram is written in PlantUML so the first positional attribute is assigned the plantuml diagram type.

  2. The name of the generated diagram file (target) is written in the second positional attribute.

  3. The output format is entered in the third positional attribute.

Asciidoctor Diagram classes diagram
Rendered PlantUML diagram

Generating a Diagram from a Terminal

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

Advanced Usage

Enabling Extensions

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 blockdiag, ditaa, erd, graphviz, meme, mermaid, plantuml, shaape, 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.

Diagram Block Macro

The diagram extensions can also be used in in block macro form.

Anatomy of a diagram block macro
block-name::source-file-name[generated-file-extension] // (1) (2) (3)
  1. The macro name is the same as the block name in the block form.

  2. The source file name specifies the external file that contains the diagram source code.

  3. 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.

Image Output Location

When Asciidoctor Diagram writes images to disk it will go over the following options in order to determine where to write the files.

  1. {imagesoutdir} if the imagesoutdir attribute has been specified

  2. {outdir}/{imagesdir} if the outdir attribute has been specified

  3. {to_dir}/{imagesdir} if the to_dir attribute has been specified

  4. {base_dir}/{imagesdir}

Specifying Diagram Generator Paths

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

actdiag

ActDiag

actdiag

blockdiag

BlockDiag

blockdiag

ditaa

Java

java

erd

Erd

erd

graphviz

GraphViz

dot or graphvizdot

meme

ImageMagick

convert and identify

mermaid

Mermaid

mermaid

nwdiag

NwDiag

nwdiag

packetdiag

NwDiag

packetdiag

plantuml

Java

java

rackdiag

NwDiag

rackdiag

seqdiag

SeqDiag

seqdiag

shaape

Shaape

shaape

umlet

Umlet

umlet

wavedrom

WaveDrom Editor

wavedrom

WaveDrom CLI and PhantomJS

wavedrom and phantomjs

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

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.

Diagram Attributes

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)
....
....
  1. Block level attributes can be specified at the document level by prefixing them with <blocktype>-

  2. The first diagram does not specify an explicit value for fontpath so the global value will be used

  3. 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.

Blockdiag

Name Default value Description

fontpath

unspecified

The path to the font that should be used by blockdiag

Ditaa

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.

GraphViz

Name Default value Description

layout

unspecified

The graphviz layout engine to use (dot -K option).

Meme

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 noupcase is supported which disable upper casing the labels.

Mermaid

Name Default value Description

css

unspecified

Path to a CSS 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.

width

unspecified

The width of the generated image.

PlantUML

Name Default value Description

config

unspecified

Path to a config file to pass to PlantUML.

About

↔️ Asciidoctor diagram extension, with support for PlantUML, Graphviz and ditaa.

Resources

License

MIT and 2 other licenses found

Licenses found

MIT
LICENSE.txt
LGPL-3.0
ditaamini-license.txt
Apache-2.0
plantuml-license.txt

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%