Closed cloud-on-prem closed 3 months ago
I'm also running into this limitation. D2, in particular, has a pretty strong import system and doesn't currently allow for absolute imports, so I'd expect folks to be trying to leverage relative imports.
It looks like we might just need to pass the target file's cwd to the d2 invocation here: https://github.com/landmaj/mkdocs-d2-plugin/blob/master/d2/plugin.py#L103
If I get some time I will try and submit a PR.
I released version 1.4.0 which supports imports in image tags. There is a caveat though, documented here.
BTW it don't think there is a way to make it work for fenced code blocks since such diagrams are passed using stdin. Setting CWD for subprocess does not appear to work, imports may just not work in d2 when using stdin.
Thank you @landmaj! I actually think it's likely a pretty reasonable trade-off not to have imports in fences, as I am far more likely to be building complex diagrams as standalone files and, hence, require imports.
For example, given this structure:
./src/_styles.d2
./src/test.d2
When rendering the test.d2 file using:
![Diagram](./src/test.d2)
I see this error in the logs (and obviously no image is generated as a result)
I am able to generate the image correctly using the command line (both svg and png)