asciidoctor / asciidoctor-kroki

Asciidoctor.js extension to convert diagrams to images using Kroki!
https://kroki.io/
MIT License
147 stars 50 forks source link

Resolve relative PlantUML includes from the diagram directory (not from the Asciidoctor base directory) #201

Closed ggrossetie closed 3 years ago

ggrossetie commented 3 years ago

Let's take an example:

docs
├── diagrams
│   ├── hello.puml
│   └── style.puml
└── index.adoc

docs/index.adoc

plantuml::diagrams/hello.puml[]

docs/diagrams/hello.puml

!include ./style.puml

Bob->Alice: Hello

docs/diagrams/style.puml

skinparam monochrome true

Currently, the extension won't resolve style.puml because the path is resolved from the base directory.

Skipping preprocessing of PlantUML include, because reading the referenced local file './style.puml' caused an error:
Error: ENOENT: no such file or directory, open './style.puml'

In the above example the resolved path will be docs/style.puml instead of docs/diagrams/style.puml.

Implementation-wise, the last parameter should be the diagram directory and not the base directory:

https://github.com/Mogztter/asciidoctor-kroki/blob/1372acb3bad3cad143fcbab5a7c8aaa5f802cfb7/src/asciidoctor-kroki.js#L76

This issue is a follow-up of: #191 (where we did this change for Vega diagrams)

romkavt commented 3 years ago

I vote for this issue!

I experiencing difficulties with multi-file & multi-directory documentation project. We are using plantuml include directives with relative paths to parent plantuml document. asciidoctor-kroki preprocessor builds include file paths relative to main asciidoctor documents.

As the consequences we have:

anb0s commented 3 years ago

The plantuml preprocessor here use definition like supported in PlantUML via parameter plantuml.include.path and implicitly set it to doc.getBaseDir(). This behaviour works for us, because we have used property -Dplantuml.include.path=${docBaseDir} for preprocessing and then always use this as base path for all includes, e.g. !include ./diagrams/style.iuml.

I think this can be changed to have the implicit behaviour like -Dplantuml.include.path=${diagramDir} and resolve from the first included diagram. But we need additionally also the support of parameter plantuml.include.path= similiar to PlantUML core for other valid use cases.