asciidoctor-kroki
asciidoctor-kroki copied to clipboard
PlantUML include resolver is not available in the Ruby extension
Hi,
I am trying to create a set of libraries of files that are included in most of my plantuml diagrams and I'm having a hard time figuring out why kroki-plantuml-include-paths is not working
My setup:
Ubuntu 20.04 on which I have
- a local kroki server started with the follwoing docker compose file:
version: "3"
services:
kroki:
image: yuzutech/kroki
environment:
- KROKI_SAFE_MODE=UNSAFE
- KROKI_PLANTUML_ALLOW_INCLUDE=true
ports:
- "8000:8000"
- the official docker container which I started with
docker run -it --rm -v $(pwd):/documents asciidoctor/docker-asciidoctor
and to which I installed the gem using
gem install asciidoctor-kroki
- and a small project
lib.puml
@startuml lib
skinparam sequence {
ActorBorderColor Black
LifeLineBorderColor black
ParticipantBorderColor black
ArrowColor Black
LifeLineBackgroundColor black
}
@enduml
seq.puml
@startuml
!include ./lib.puml
Actor A
Actor B
A -> B: test
A <-- B: response
@enduml
test.adoc
:doctype: book
:backend-html5:
:doctitle: test
:kroki-server-url: http://172.17.0.1:8000
:kroki-fetch-diagram:
:kroki-plantuml-include-paths: {docdir}
:imagesdir: images
{kroki-plantuml-include-paths}
[[section-adoc]]
= adoc
[plantuml]
....
include::seq.puml[]
....
all the files are in the same directory(mounted to /documents to docker)
bash-5.1# asciidoctor -r asciidoctor-kroki test.adoc
asciidoctor: FAILED: /documents/test.adoc: Failed to load AsciiDoc document - 400 Bad Request
Use --trace for backtrace
Kroki log shows
{"timestamp":"1620972621879","level":"ERROR","thread":"vert.x-eventloop-thread-1","mdc":{"error_message":"cannot include ./lib.puml (line: 2)","path":"/plantuml/svg/eNpzKC5JLCopzc3h4lLMzEvOKU1JVdDTz8lM0isACzoml-QXKThCaSeggIKunYKTlUJJanEJkGOjqwviFaUWF-TnFadyOaTmpQA1AgCk_hqg","method":"GET","action":"error","error_code":"400","failure_class_name":"io.kroki.server.error.BadRequestException","user_agent":"Ruby"},"logger":"io.kroki.server.error.ErrorHandler","message":"An error occurred","context":"default","exception":"io.kroki.server.error.BadRequestException: cannot include ./lib.puml (line: 2)\n\tat io.kroki.server.service.Plantuml.convert(Plantuml.java:269)\n\tat io.kroki.server.service.Plantuml.lambda$convert$5(Plantuml.java:235)\n\tat io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:179)\n\tat io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:96)\n\tat io.vertx.core.impl.ContextImpl.lambda$executeBlocking$1(ContextImpl.java:177)\n\tat io.vertx.core.impl.TaskQueue.run(TaskQueue.java:76)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\n\tat io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)\n\tat java.base/java.lang.Thread.run(Unknown Source)\n"}
- using
:kroki-plantuml-include: {docdir}/lib.pumlworked but this is not enough for me as I have different includes for different files. - removing the include also generates the document successfully
My project is more complicated than this, with a more elaborated folder structure but I strip it down to the simplest form and not even this works.
What am I doing wrong?
kroki-plantuml-include-paths is currently only supported when using the JavaScript extension.
So this feature needs to be implemented in the Ruby extension as well.
@Mogztter I'm interested in working on this issue but I don't know how to start it, for example Asciidoctor::PreprocessorReader#resolve_include_path doesn't seem to support a list of possible directories to look into, could you explain how the case should be handled? Thanks!
I'm interested in working on this issue but I don't know how to start it, for example Asciidoctor::PreprocessorReader#resolve_include_path doesn't seem to support a list of possible directories to look into, could you explain how the case should be handled? Thanks!
We should use our own mechanism. Asciidoctor::PreprocessorReader#resolve_include_path is used to resolve the include:: directive in Asciidoctor. The PlantUML !include directive achieves a similar goal but does not work exactly the same.
The goal here is to implement the following JavaScript function in Ruby:
https://github.com/Mogztter/asciidoctor-kroki/blob/6e6d86c6fca8a8a633eabf742b0fb8aac8b0d206/src/preprocess.js#L90