asciidoctor / asciidoctor-kroki

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

Macro form appears not to read files correctly #74

Closed danyill closed 4 years ago

danyill commented 4 years ago

I can't currently get the macro form to function correctly.

For the asciidoc syntax:

plantuml::test.puml[]

I get an error in my rendered HTML:

ENOENT: no such file or directory, open 'test.puml' - plantuml::test.puml[]

I looked at:

https://github.com/Mogztter/asciidoctor-kroki/blob/1daf269b6524a1ad42793ca9f26430db34405b43/src/asciidoctor-kroki.js#L136-L142

When I look in the debugger at vfs.read(target) I see that we have target = test.puml and this doesn't exist where it is being read from (probably the directory the process is being executed from which in this case may not be the same folder the source file is in).

Perhaps all we want is: parent.getDocument().normalizeSystemPath('test.puml') which seems what is done in (random example): https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/b848e53b5a23134348ac40741a3d777fcb22c684/lib/implicit-header-include-processor/extension.rb#L8-L10

ggrossetie commented 4 years ago

Yes you are correct, if we are reading from the file system, we should use normalizeSystemPath.

Here's what Asciidoctor Diagram is doing: https://github.com/asciidoctor/asciidoctor-diagram/blob/66876e9c11c401eec943ff6968cd0c5f6c443906/lib/asciidoctor-diagram/diagram_processor.rb#L317

When reading a file in an Antora environment, I think we should keep the target as-is. In a browser environment, I'm not 100% sure but I think we should also keep the target as-is.

Feel free to submit a pull request, I will gladly merge it 🤗