4

PlantUML is a great extension for Asciidoc, but I can't figure out how to use from my groovy code.

As far as I can see, the asciidoctorj-diaram module should be part of the current asciidoctorj-Release, so I guess I need no additional dependency. But my code which renders asciidoc fine, does not render the PlantUML diagrams. It says:

invalid style for open block: plantuml

Any idea what could be wrong? The asciidoctorj-diagram examples I find on the net all use the gradle-plugin :-|

rdmueller
  • 10,742
  • 10
  • 69
  • 126

1 Answers1

2

Even if the library is part of the AsciidoctorJ project, there is a separate java library called: asciidoctorj-diagram (the java version of asciidoctor-diagram)

Are you sure that you have asciidoctorj-diagram on your classpath? Here the maven coordinates:

<dependency>
    <groupId>org.asciidoctor</groupId>
    <artifactId>asciidoctorj-diagram</artifactId>
    <version>1.3.1</version>
</dependency>

You also need to tell Asciidoctor that asciidoctor-diagram is required. See line <1> in the following plain java example:

public static void main(String[] args) {
    org.asciidoctor.Asciidoctor asciidoctor =
             org.asciidoctor.Asciidoctor.Factory.create();

    asciidoctor.requireLibrary("asciidoctor-diagram"); // <1>

    StringBuilder sb = new StringBuilder();
    sb.append("== Diagrams\n");
    sb.append("\n");
    sb.append("[plantuml,auth-protocol]\n");
    sb.append("....\n");
    sb.append("Alice -> Bob: Authentication Request\n");
    sb.append("Bob --> Alice: Authentication Response\n");
    sb.append("\n");
    sb.append("Alice -> Bob: Another authentication Request\n");
    sb.append("Alice <-- Bob: another authentication Response\n");
    sb.append("....\n");

    String html = asciidoctor.convert(sb.toString(), 
             new java.util.HashMap<String, Object>());
    System.out.println(html);
}

By the way, there is also a maven example: asciidoctor-diagram-example. But this example requires the asciidoctor-maven-plugin which is similar to the gradle plugin.

Jmini
  • 9,189
  • 2
  • 55
  • 77
  • thanx for the detailed answer. The dependency and `requireLibrary` where the missing ingredient... now I have to figure out why it doesn't find the GraphViz "dot" tool... – rdmueller Jan 19 '16 at 21:18
  • Btw: yes, graphviz is installed. I wonder why asciidocfx just works and I do have these problems... – rdmueller Jan 19 '16 at 21:31
  • 1
    If you do not want to add `dot` on you path; In the maven plugin, the path to `dot` can be specified with a config: `C:\Program Files (x86)\Graphviz2.38\bin\dot.exe`. You can have a look there to figure out how you can do the same in your java program. – Jmini Jan 20 '16 at 07:02