Skip to content

fix: support mermaid v9 by falling back to mermaid.init()#40

Open
Colty1999 wants to merge 2 commits intoLeward:masterfrom
Colty1999:patch-1
Open

fix: support mermaid v9 by falling back to mermaid.init()#40
Colty1999 wants to merge 2 commits intoLeward:masterfrom
Colty1999:patch-1

Conversation

@Colty1999
Copy link

Problem

docsify-mermaid@2.0.1 calls mermaid.run() which only exists in
mermaid v10+. However, mermaid v10 requires ESM imports (type="module"),
which load asynchronously — meaning window.mermaid is undefined when the
plugin tries to use it.

Mermaid v9 loads synchronously via a regular <script> tag but only
exposes mermaid.init(), not mermaid.run().

This makes the plugin broken for both versions.

Fix

Fall back to mermaid.init() when mermaid.run() is not available,
supporting both v9 and v10+.

Changes

  • src/plugin.js: check typeof mermaid.run === 'function' before
    calling it; fall back to mermaid.init() for v9
  • 'README.md': updated readme to support both implementations

@Leward
Copy link
Owner

Leward commented Feb 20, 2026

Hi @Colty1999 , thanks for the contribution. I am not watching PRs as often as I should, but I'll try to validate this and get it merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants