LukeCarrier / mkdocs-drawio-exporter

Exports your Draw.io diagrams at build time for easier embedding into your documentation
https://pypi.org/project/mkdocs-drawio-exporter/
MIT License
81 stars 9 forks source link

Compatibility Issue with `mkdocs-glightbox` #72

Closed Thiti517 closed 1 day ago

Thiti517 commented 3 weeks ago

Hello!

First of all, I have to say that your plugin has saved me a lot of time in converting Draw.io files to PNG.

I found an issue when using it alongside the mkdocs-glightbox plugin. This plugin wraps images with an anchor tag, using the image src as the anchor href. This occurs in the on_page_content function, which means the anchor is added before your plugin modifies the image src in on_post_build function (if I understand your code correctly).

As a result, the anchor href remains broken, still pointing to the original .drawio file rather than the generated .png, .svg, or other formats created by your plugin.

LukeCarrier commented 3 weeks ago

Thanks for raising this, it sounds like the ordering of the hooks matters. I'm not sure how MkDocs determines the precedence of plugins, but I wonder if reordering them in the plugins key of mkdocs.yml is enough?

Do you have an example I could clone to test?

Thiti517 commented 2 weeks ago

Unfortunately, changing the plugin order in mkdocs.yml won’t solve the issue. MkDocs processes each event sequentially, and for each event, it checks the plugins (in the order listed in the config) to see if they have a corresponding function like on_event. If a plugin uses an event that occurs after the one used by mkdocs-glightbox, the order of plugins won’t make a difference.

A better solution would be to modify your plugin so that it updates the image link during the on_page_markdown event instead of on_post_build. The on_page_markdown event happens before on_page_content, which is when mkdocs-glightbox wraps the images.

I'll try to create an example project when I find more time in my currently tight schedule. If possible, I'll also work on a pull request with the modifications I believe could solve the issue.

LukeCarrier commented 2 weeks ago

I'm rewriting the images in on_post_page, but copying the images in on_post_build.

Happy to accept a PR or take a look myself, time permitting 👍

LukeCarrier commented 1 week ago

@Thiti517 are you able to give the proposed fix in #75 a go?

I've updated the example configuration in the docs/ subdirectory to include mkdocs-glightbox, and with the default configuration (emitting img tags) it seems to work correctly. Inlining SVGs needs a little more troubleshooting.

Thiti517 commented 1 week ago

Oh! Awesome! I was also considering moving the process to the on_page_markdown event since it seems to be the best solution. I’ll check it out right away!

Thiti517 commented 1 week ago

I tested it out, and it works great!

LukeCarrier commented 3 days ago

This turned out to completely break generation of image source paths, so I've yanked the 0.10.0 release until I have more time to figure it out.

LukeCarrier commented 1 day ago

Should be fixed in 0.10.1 which shipped yesterday.