Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[![npm version](https://badge.fury.io/js/docsify-mermaid.svg)](https://www.npmjs.com/package/docsify-mermaid)

mermaid-docsify is a docsify plugin which allows to render mermaid diagrams in docsify.
mermaid-docsify is a docsify plugin which allows to render mermaid diagrams in docsify. Supports both mermaid v9 and v10+.

## How to use

Add Mermaid and the plugin:
Add Mermaid and the plugin. Choose the option matching your mermaid version:

### Mermaid v10+ (ESM)

```html
<script type="module">
Expand All @@ -15,7 +17,17 @@ Add Mermaid and the plugin:
<script src="//unpkg.com/docsify-mermaid@2.0.1/dist/docsify-mermaid.js"></script>
```

You can optionally customize [mermaid.run](https://mermaid.js.org/config/usage.html#using-mermaid-run) configuration with this props :
### Mermaid v9 (regular script)

```html
<script src="https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.min.js"></script>
<script>
mermaid.initialize({ startOnLoad: false });
</script>
<script src="//unpkg.com/docsify-mermaid@2.0.1/dist/docsify-mermaid.js"></script>
```

You can optionally customize [mermaid.run](https://mermaid.js.org/config/usage.html#using-mermaid-run) (v10+) or [mermaid.init](https://mermaid.js.org/config/usage.html) (v9) configuration with this props:

```html
<script>
Expand Down
12 changes: 10 additions & 2 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ const plugin = (mermaidConf) => (hook) => {
next(htmlElement.innerHTML);
});

hook.doneEach(() => mermaid.run(mermaidConf));
hook.doneEach(() => {
if (typeof mermaid.run === 'function') {
// mermaid.run() is the v10+ API (requires ESM import)
mermaid.run(mermaidConf);
} else {
// mermaid.init() is the v9 API (works with regular <script> tags)
mermaid.init(undefined, mermaidConf.querySelector || '.mermaid');
}
});

};

export default plugin;
export default plugin;