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

Inline SVG embed format #40

Closed herberton closed 6 months ago

herberton commented 2 years ago

Hi @LukeCarrier ,

I work at TOTVS, from Brazil, and we use the mkdocs-drawio-exporter plugin in our mkdocs documentation (thanks a lot). We are putting this documentation to be displayed inside backstage.io and we are faced with the challenge since, for security reasons, the backstage.io techdocs plugin removes the <object/>, <embed/>, <iframe/> and some other HTML tags by default (they are using DOM Purify).

After studying alternatives to solve this problem, we decided to package our mkdocs documentation differently, embedding the SVG content inside the HTML body. So, I forked your project by enabling this new embedding format (which I called html).

Basically, you need to configure mkdocs-drawio-exporter as follows:

plugins:
    - drawio-exporter:
        format: svg
        embed_format: html

To enable this functionality I had to change the order of some things, so the plugin starts generating the SVGs in the on_post_page event and before changing the HTML body. I had to do this to be able to embed the SVG inside the HTML body.

I also reorganized the source code in order to isolate the responsibilities between exporter.py and plugin.py in order to simplify usage, reducing parameter passing and promote better maintainability.

I hope to be able to activate these changes in the next version,

Herberton.

LukeCarrier commented 2 years ago

Hey @herberton,

Thanks for the work on this. Given the size of the diff I really need to review the change properly, but I am snowed under with work right now.

You’re welcome to fork and publish to PyPI yourself if you need this immediately.

herberton commented 1 year ago

Hi @LukeCarrier , I found a little bug but I already fix it!!!

LukeCarrier commented 7 months ago

Fixes #44

LukeCarrier commented 6 months ago

Hey @herberton, hope you're well. Sorry for the delay in getting around to this change!

I didn't want to break the convention we have of letting users specify their own embed_formats using format strings, so in #56 I've introduced a new content value. As the diff for this approach is smaller I'm going to close this PR in favour of the other one.

Many thanks for the idea and implementation, and I hope you're happy with this approach!