vitepress-plugin-mermaid

Render Mermaid diagrams natively inside VitePress markdown pages.

Library
npm
v2.0.17
179 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
41 /100 Fair
Development Activity 0
Maintenance 20
Community 68
Maturity 56
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
62 /100 Good
Architecture 60
Code Quality 45
Innovation 72
Learning Curve 70

vitepress-plugin-mermaid wraps the mermaid.js diagramming library into a VitePress-native experience: wrap your VitePress config in withMermaid(), drop a fenced ```mermaid code block into any markdown page, and it renders as an interactive SVG diagram at build time via a bundled Vue component and a markdown-it fence override.

The plugin auto-detects VitePress’s dark-mode toggle (any theme class containing “dark”) and re-renders the diagram with mermaid’s dark theme, so flowcharts, sequence diagrams, Gantt charts, and class diagrams stay legible without any theme-switching logic in your own docs code.

What You Get

  • A withMermaid() config wrapper that patches your VitePress markdown-it and Vite config in one call
  • A globally-registered Vue Mermaid.vue component that renders diagrams client-side via mermaid.js
  • Automatic dark-mode detection tied to VitePress’s dark theme class, with no manual theme wiring
  • A pre-configured Vite plugin handling optimizeDeps and aliasing for mermaid’s transitive dependencies (dayjs, cytoscape, etc.)
  • Support for every Mermaid diagram type (flowcharts, sequence, class, state, Gantt, mindmap, C4, ZenUML) through a single fenced code block syntax

Common Use Cases

  • Architecture docs - Engineering teams documenting system architecture in a VitePress knowledge base embed flowcharts and sequence diagrams directly in markdown instead of maintaining separate image exports.
  • API/runbook docs - Platform teams writing operational runbooks use Gantt and state diagrams to describe deployment pipelines and incident-response flows without leaving their docs repo.
  • Open-source project docs - Maintainers of OSS projects that already publish docs via VitePress add mermaid diagrams (e.g. dependency graphs, contribution flow) with a single config wrapper and no extra build step.

Under The Hood

Architecture: The library is a thin integration layer with five source files totaling under 200 lines. withMermaid() (src/index.ts) is the sole public entry point; it mutates a caller-supplied VitePress UserConfig object in place, injecting a markdown-it config hook (MermaidMarkdown, src/mermaid-markdown.ts) that overrides the fence renderer to intercept ```mermaid code blocks and emit a <Suspense>-wrapped <Mermaid> component tag with the diagram source URL-encoded into a graph prop, and pushing a Vite plugin (MermaidPlugin, src/mermaid-plugin.ts) that injects a Mermaid component registration into VitePress’s client bootstrap by string-patching the transformed vitepress/dist/client/app/index.js, and exposes user-supplied MermaidConfig through a virtual module (virtual:mermaid-config). At render time Mermaid.vue calls init()/render() (src/mermaid.ts), thin wrappers around mermaid.js’s registerExternalDiagrams/mermaid.render, and re-renders on any class mutation of document.documentElement via a MutationObserver, which is how it reacts to VitePress’s dark-mode toggle.

Tech Stack: TypeScript (72%) plus a single Vue 3 SFC (28%), built with Vite in library mode (vite.config.ts) producing ES and UMD bundles plus .d.ts typings via vite-plugin-dts, with vite-plugin-static-copy shipping Mermaid.vue/mermaid.ts as raw source alongside the compiled bundle so VitePress’s own toolchain can transform them. mermaid (v10/11) and vitepress (v1.x) are declared as peerDependencies rather than bundled, keeping the plugin thin and letting consumers control both versions independently; @mermaid-js/mermaid-mindmap is an optionalDependency for mindmap support.

Code Quality: There are no automated tests anywhere in the repository — no test runner configured, no *.test.*/*.spec.* files — so correctness relies entirely on manual verification against the docs site. Error handling is minimal: mermaid.ts’s init() catches and silently logs registerExternalDiagrams failures, and mermaid-markdown.ts catches render-time fence errors and falls back to a raw <pre>{err}</pre>. The client-injection strategy in mermaid-plugin.ts — string-splicing a component-registration line into VitePress’s compiled app/index.js by searching for the substring "app.component" — is a real fragility risk tied to VitePress’s internal build output; the repo’s inactive activity status and 0 commits/month reflect this hasn’t been revisited recently. Naming and typing are otherwise consistent, with explicit MermaidPluginConfig/MermaidPluginOptions interfaces.

API Design: The entire integration surface is a single withMermaid(config) wrapper that mutates and returns a standard VitePress UserConfig, so adoption requires one import and one function call around an existing config. Diagram authoring reuses the ```mermaid fence syntax already familiar from GitHub-flavored markdown, plus an mmd alias for syntax-highlighting-only blocks. Configuration splits cleanly into mermaid (passed straight to mermaid.js) and mermaidPlugin (plugin-specific options like a custom CSS class). The main DX rough edge is that dark-theme behavior is implicit and global — any dark-named class flips every diagram to mermaid’s dark theme — with only a single per-page mermaidTheme frontmatter escape hatch, and there’s no dedicated API reference beyond the “Getting Started”/“More examples” guide pages.

Used by 5 apps in this directory

Go
32%
Apache 2.0

CubeSandbox

AI Agents · Developer Tools · Security

12,728

Instant, concurrent, hardware-isolated MicroVM sandboxes for AI agents — E2B-API compatible, sub-60ms cold starts, and a built-in zero-trust egress proxy, all self-hostable at scale.

View details
82
Repo Health
88
Technical
63
Dependency
Built with
Go 32%
Rust 26%
C 22%
Updated 2 weeks ago
TypeScript
96%
MIT

deepseek-harness

AI Agents · AI Development · Developer Tools

237,945

An open-source, plugin-based agent harness from DeepSeek AI that runs coding and automation agents across web, desktop, CLI, and SDK surfaces.

View details
81
Repo Health
89
Technical
74
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
TypeScript
94%
AGPL 3.0

Element Web

Collaboration · Team Chat

13,518

A polished, self-hostable Matrix client for secure, decentralized messaging and collaboration that puts your organization in full control of its data.

View details
96
Repo Health
83
Technical
65
Dependency
Built with
TypeScript 94%
Updated 1 weeks ago
TypeScript
98%
MIT

Kimi Code CLI

AI Agents · AI Code Assistants · Developer Tools

7,705

A single-binary, terminal-native coding agent that reads, edits, and runs code end to end, built by Moonshot AI for Kimi models but pluggable with Anthropic, OpenAI, and Google providers too.

View details
82
Repo Health
87
Technical
67
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
Python
94%
MIT

MemPalace

AI Agents · AI Development · AI Memory

59,323

Local-first AI memory with verbatim storage, pluggable backends, and 96.6% retrieval recall on LongMemEval — no API key required.

View details
84
Repo Health
84
Technical
72
Dependency
Built with
Python 94%
Updated 2 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers