asciidoctor / asciidoctor-kroki

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

Antora does not support inline + kroki-fetch-diagram option #88

Open ggrossetie opened 4 years ago

ggrossetie commented 4 years ago

I think we should workaround this limitation otherwise an exception is thrown:

SecurityError: Jail is not an absolute path: modules/ROOT/pages/install
    at Opal.send (/nix/store/a3xmzr6d2lbl517gc53hy82jz0xzpjdv-antora-wrapper/libexec/antora-wrapper/node_modules/opal-runtime/src/opal.js:1660:19)
    at Function.$$exception (/nix/store/a3xmzr6d2lbl517gc53hy82jz0xzpjdv-antora-wrapper/libexec/antora-wrapper/node_modules/opal-runtime/src/opal.js:5519:14)
    at $PathResolver.$$raise (/nix/store/a3xmzr6d2lbl517gc53hy82jz0xzpjdv-antora-wrapper/libexec/antora-wrapper/node_modules/opal-runtime/src/opal.js:5204:31)
    at $PathResolver.$$system_path (/nix/store/a3xmzr6d2lbl517gc53hy82jz0xzpjdv-antora-wrapper/libexec/antora-wrapper/node_modules/asciidoctor.js/dist/node/asciidoctor.js:12144:18)
    at $Block.$$normalize_system_path (/nix/store/a3xmzr6d2lbl517gc53hy82jz0xzpjdv-antora-wrapper/libexec/antora-wrapper/node_modules/asciidoctor.js/dist/node/asciidoctor.js:4962:37)
    at $Block.$$read_contents (/nix/store/a3xmzr6d2lbl517gc53hy82jz0xzpjdv-antora-wrapper/libexec/antora-wrapper/node_modules/asciidoctor.js/dist/node/asciidoctor.js:5071:25)
    at Object.$$read_svg_contents (/nix/store/a3xmzr6d2lbl517gc53hy82jz0xzpjdv-antora-wrapper/libexec/antora-wrapper/node_modules/asciidoctor.js/dist/node/asciidoctor.js:17236:33)
    at Object.$$image (/nix/store/a3xmzr6d2lbl517gc53hy82jz0xzpjdv-antora-wrapper/libexec/antora-wrapper/node_modules/asciidoctor.js/dist/node/asciidoctor.js:16058:38)
    at Object.Opal.send (/nix/store/a3xmzr6d2lbl517gc53hy82jz0xzpjdv-antora-wrapper/libexec/antora-wrapper/node_modules/opal-runtime/src/opal.js:1660:19)
    at Object.convertImage (/nix/store/a3xmzr6d2lbl517gc53hy82jz0xzpjdv-antora-wrapper/libexec/antora-wrapper/node_modules/@antora/asciidoc-loader/lib/converter/html5.js:47:17)

The least worst solution is to pass the diagram as data-uri. It's not 100% accurate but it should work. Maybe we should add a warning message to let the user know?

djencks commented 4 years ago

data-uri doesn't work with Antora under any circumstances. The fix for this was in https://gitlab.com/antora/antora/-/issues/536, but I have no idea if that would still apply. If Dan indicates he'll apply it I'd consider checking.

ggrossetie commented 4 years ago

data-uri doesn't work with Antora under any circumstances.

The idea here is to:

  1. fetch the image from the Kroki server (in the extension),
  2. produce a data-uri from the image,
  3. then use this data-uri as the target of the Image node

So basically, it will be equivalent to:

image::data:image/png;base64,...[]

I believe that the above is working, because in this case Asciidoctor won't do any processing on the target, so it will be converted to:

<image src="data:image/png;base64,..."></image>
djencks commented 4 years ago

It would be wonderful if I'm wrong! Perhaps why I couldn't get it to work is because I was asking asciidoctor to encode the data uri, which still seems like the most appropriate option to me, since it can... why duplicate functionality?
I don't think that producing something that isn't inline from inline instructions is a good idea. Dan could take a minute and fix the problem in Antora. There are so many options... is there a specific instruction for a-kroki to produce a data-uri?

ggrossetie commented 4 years ago

It would be wonderful if I'm wrong!

I can confirm that using a data-uri as a target in an image block macro is working:

image::data:image/png;base64,...[]

(you can try using the data-uri returned by: http://www.plantuml.com/plantuml/base64/SoWkIImgAStDuKhCoKnELT2rKqZAJ-82OX0JBCRba9gN0bG10000)

Perhaps why I couldn't get it to work is because I was asking asciidoctor to encode the data uri, which still seems like the most appropriate option to me, since it can... why duplicate functionality?

Yes, Asciidoctor.js 1.5.8 cannot fetch and encode the data-uri properly.

which still seems like the most appropriate option to me, since it can... why duplicate functionality?

I don't mind if Asciidoctor encodes a content to a data-uri but as mentioned previously Asciidoctor should not fetch the content (when the content is already fetched).

I don't think that producing something that isn't inline from inline instructions is a good idea.

Yes that's a workaround so this is not ideal :| The other alternative is to ignore the kroki-fetch-diagram option but it has drawbacks too.

Dan could take a minute and fix the problem in Antora.

I think it should be fixed upstream: https://github.com/asciidoctor/asciidoctor/issues/3698

There are so many options... is there a specific instruction for a-kroki to produce a data-uri?

No we do not provide an option to generate a data-uri but in my opinion this part should be managed by the converter/processor depending on a generic option. In summary, the extension should create an Image node with the contents of the image (bytes) and then Asciidoctor should inline the content according to the format of the image.

xamde commented 1 year ago

Root cause in Antora now discussed in https://gitlab.com/antora/antora/-/issues/1001