fralau / mkdocs-mermaid2-plugin

A Mermaid graphs plugin for mkdocs
https://mkdocs-mermaid2.readthedocs.io
MIT License
203 stars 25 forks source link

Add support for loading mermaid via esm module #72

Closed maxbrokman closed 1 year ago

maxbrokman commented 1 year ago

Fixes #70

Changes

Context

From mermaid v10 onwards mermaid is only distributed as an ESM module. See Mermaid #3590 for discussion on this change.

Users will probably notice this problem if they are following the readme recommended way of loading the latest version of mermaid through extra_javascript as including https://unpkg.com/mermaid/dist/mermaid.min.js resolves to e.g https://unpkg.com/mermaid@10.0.2/dist/mermaid.min.js which does not exist.

Looking around other projects this seems to be a common issue for libraries including mermaid.

To resolve this mermaid must now be explicitly imported through e.g

<script type="module">
import mermaid from "https://unpkg.com/mermaid@10.0.2/dist/mermaid.esm.min.mjs"
mermaid.initialize()
</script>

To achieve this this PR makes several changes:

fralau commented 1 year ago

Thanks a lot for your contribution.

Could you describe in detail the problem you wanted to solve (what is esm, etc.), and how you solved it?

maxbrokman commented 1 year ago

Ah very sorry @fralau I have sent this to the wrong upstream! Was originally intending to review internally before pushing here but I will update the description shortly

fralau commented 1 year ago

Thanks a lot. I believe the right thing to do would be to open an issue to start the discussion and then, when needed the pull request. Looking forward!

maxbrokman commented 1 year ago

@fralau have now provided a description, sorry about that

fralau commented 1 year ago

I did my own implementation (to guarantee compatibility with earlier versions). Released in 1.0.0.

flowolf commented 1 year ago

this is not yet pushed to pypi - is this planned?