Highlight.js / lowlight grammar for Mermaid diagrams. Enables syntax highlighting in editors like Tiptap with @tiptap/extension-code-block-lowlight.
npm install lowlight-mermaid





!npm bundle size
> TypeScript grammar definitions for Mermaid syntax highlighting
> Compatible with highlight.js and lowlight, designed for editors, markdown renderers, and converters.
---
- 📦 No runtime bloat — ships only grammar definitions
- ⚡ Plug-and-play with highlight.js / lowlight
- 🔧 Full TypeScript types included
- 🛠 Reusable across editors, docs, converters (e.g. @tiptap/extension-code-block-lowlight or mdast2docx)
---
``bash`
pnpm add lowlight-mermaid
_or_
`bash`
npm install lowlight-mermaid
_or_
`bash`
yarn add lowlight-mermaid
---
`ts
import { mermaidGrammar } from "lowlight-mermaid";
import hljs from "highlight.js/lib/core";
hljs.registerLanguage("mermaid", mermaidGrammar);
const code = flowchart TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car];
const result = hljs.highlight(code, { language: "mermaid" });
console.log(result.value);
``
---
- highlight.js — core highlighting engine
- lowlight — AST-friendly wrapper
---
Licensed under MPL-2.0 open-source license.
---
![]()
Support my work via GitHub Sponsors or explore courses.
with 💖 by Mayank Kumar Chaudhari