timvink / mkdocs-print-site-plugin

MkDocs Plugin that adds an additional page that combines all pages, allowing easy exports to PDF and standalone HTML.
https://timvink.github.io/mkdocs-print-site-plugin/
MIT License
145 stars 24 forks source link

Drawio content is missing in printed export #99

Closed hafeja closed 5 months ago

hafeja commented 6 months ago

First of all: Cool plugin @timvink , I like it!

Expected behavior

Drawio diagrams which are part of the mkdocs project are contained in the printed page using /print_page/.

Actual behavior

Drawio diagrams which are part of the mkdocs project are NOT contained in the printed page using /print_page/.

Environment

Ubuntu 22. Following packages are installed using pip in virtual environment.

mkdocs                            1.5.3
mkdocs-drawio-file                1.5.2
mkdocs-glightbox                  0.3.7
mkdocs-material                   9.5.11
mkdocs-material-extensions        1.3.1
mkdocs-print-site-plugin          2.3.6

Remark: Drawio content is added according to the documentation like this: ![](my-diagram.drawio)

Question

What needs to be done in order to see drawio content at /print_page/?

Any feedback is much appreciated!

timvink commented 6 months ago

First of all: Cool plugin @timvink , I like it!

Thanks!

What needs to be done in order to see drawio content at /print_page/?

First of all, I noticed that mkdocs-drawio-file is not maintained anymore, and there is a new version mkdocs-drawio.

I had a quick look at the source code of mkdocs_drawio/ (https://github.com/tuunit/mkdocs-drawio/blob/main/mkdocs_drawio/plugin.py). The main hook is on_post_page().

This plugin saves the HTML before any template is applied, during the on_page_content event. Then on the on_post_build event, we combine the HTMLs of all the page and then apply the templating (template styling basically).

If you look at the mkdocs documentation for plugins, you can see the diagram for the order of plugins events

This should clarify it:

image

So the processing by the mkdocs_drawio is skipped. The solution is to add the post processing to the HTML of the print-site page explicitly, like we do for some other plugins:

https://github.com/timvink/mkdocs-print-site-plugin/blob/a648cff725d39aea6732164470656fef0571f159/mkdocs_print_site_plugin/plugin.py#L353-L358

Would you be willing to look into making a PR?

Perhaps @tuunit can chip in also? Because it would help if the mkdocs-drawio plugin would have a single function that is not dependent on self. Something like replace_drawio(html: str, path: Path, viewer_js_url: str) -> str. Then we can use that in this plugin

hafeja commented 6 months ago

Thanks for the hint that https://pypi.org/project/mkdocs-drawio/ supersedes https://pypi.org/project/mkdocs-drawio-file/!

Would you be willing to look into making a PR?

If I was skilled enough, I would ;-) Therefore, I like your idea to kindly ask @tuunit for professional support.

tuunit commented 6 months ago

Hi together,

sorry for the late reply. Unfortunately all notifications from this thread have been wrongly filtered away by a misconfigured email filter. Thats on me, I'll have a look at the proposed changes and compatibility in the upcoming days.

tuunit commented 6 months ago

@timvink @hafeja I just released a new version 1.6.0 of mkdocs-drawio and opened the PR #100 to introduce the rendering support of the diagrams on the /print_page/ endpoint

timvink commented 5 months ago

Should be fixed with #100

timvink commented 5 months ago

released v2.4.0 to pypi

hafeja commented 5 months ago

Works like expected. Thank you @timvink , @tuunit !! ❤️