1. Home
  2. ChevronRight@bdocs/plugin-mermaid

@bdocs/plugin-mermaid

The `@bdocs/plugin-mermaid` plugin integrates Mermaid.js into Boltdocs. It automatically transforms standard `mermaid` code blocks into interactive, responsive diagrams that dynamically sync with your light and dark theme preferences.

Installation & Quick StartLink

Get started by adding the plugin package to your documentation project.

1. Install the packageLink

pnpm add @bdocs/plugin-mermaid

2. Register the pluginLink

Add the plugin to the plugins array in your configuration file:

boltdocs.config.ts
import { defineConfig } from 'boltdocs'
import mermaidPlugin from '@bdocs/plugin-mermaid'

export default defineConfig({
  plugins: [mermaidPlugin()],
})

Concepts & ArchitectureLink

The Mermaid plugin uses a hybrid compilation pipeline to keep your documentation fast:

graph LR
    A[Markdown Source] -->|Remark Transform| B[MDX Component Prep]
    B -->|SSG compilation| C[Light HTML Skeleton]
    C -->|Lazy Client Import| D[Interactive SVG Render]
  1. Build-Time Transformation: When Boltdocs parses your markdown files, the plugin's Remark compiler finds code blocks marked as mermaid. It compiles them into standard <Mermaid /> React components and injects the raw diagram text as a prop.
  2. Dynamic Client-Side Rendering: To prevent huge JavaScript bundle sizes in your static pages, the Mermaid.js engine is dynamically loaded only when a diagram enters the user's viewport. If a page does not contain diagrams, zero Mermaid code is sent to the client.

API ReferenceLink

MermaidPluginOptionsLink

Configuration passed to the mermaidPlugin() initializer.

PropertyTypeDefaultDescription
themesMermaidThemesundefinedCustom theme variables to match your corporate branding.

MermaidThemesLink

Custom configurations for light and dark visualization modes.

PropertyTypeDefaultDescription
lightMermaidThemeVariablesdefaultLightThemeTheme overrides applied when the site's light mode is active.
darkMermaidThemeVariablesdefaultDarkThemeTheme overrides applied when the site's dark mode is active.

MermaidThemeVariablesLink

Complete list of available color variables to customize the diagram node styling.

PropertyTypeDefaultDescription
primaryColorstringLight: '#f8fafc'
Dark: '#1e293b'
Background color for primary nodes.
primaryTextColorstringLight: '#0f172a'
Dark: '#f8fafc'
Text color for primary nodes.
primaryBorderColorstringLight: '#e2e8f0'
Dark: '#334155'
Border color for primary nodes.
lineColorstringLight: '#64748b'
Dark: '#94a3b8'
Color for connecting lines and arrows.
secondaryColorstringLight: '#f1f5f9'
Dark: '#0f172a'
Background color for secondary elements.
tertiaryColorstringLight: '#ffffff'
Dark: '#1e293b'
Background color for tertiary elements.
nodeBorderstringLight: '#e2e8f0'
Dark: '#334155'
Default border color for nodes.
mainBkgstringLight: '#ffffff'
Dark: '#0f172a'
Main canvas background color.
nodeTextColorstringLight: '#0f172a'
Dark: '#f8fafc'
Default text color inside nodes.
edgeLabelBackgroundstringLight: '#f8fafc'
Dark: '#1e293b'
Background color for connector labels.
clusterBkgstringLight: '#f8fafc'
Dark: '#1e293b'
Background color for cluster groups.
clusterBorderstringLight: '#e2e8f0'
Dark: '#334155'
Border color for cluster groups.

Mermaid Component PropsLink

Properties supported when using the <Mermaid /> React component directly in MDX.

PropertyTypeDefaultDescription
chartstring(Required)The Mermaid diagram definition markup.
configMermaidConfigundefinedSpecific inline theme overrides for this single diagram instance.

Detailed ExamplesLink

Custom ThemingLink

You can customize themes by passing variable overrides directly:

boltdocs.config.ts
import { defineConfig } from 'boltdocs'
import mermaidPlugin from '@bdocs/plugin-mermaid'

export default defineConfig({
  plugins: [
    mermaidPlugin({
      themes: {
        light: {
          primaryColor: '#e0f2fe',
          primaryTextColor: '#0369a1',
          primaryBorderColor: '#bae6fd',
          lineColor: '#0284c7',
        },
        dark: {
          primaryColor: '#0c4a6e',
          primaryTextColor: '#e0f2fe',
          primaryBorderColor: '#0284c7',
          lineColor: '#38bdf8',
        },
      },
    }),
  ],
})

Component SyntaxLink

For advanced layouts, you can invoke the JSX component directly:

<Mermaid chart={`
  flowchart LR
    A[Start] --> B[Process]
    B --> C[End]
`} />
Info
Syntax Recommendation

While both markdown blocks and JSX tag variants produce matching outputs, we recommend standard markdown code blocks (```mermaid) for maximum readability in code editors.


TroubleshootingLink

Diagrams fail to renderLink

  • Verify Configuration: Ensure mermaidPlugin() is registered in your boltdocs.config.ts plugins array.
  • Verify Language Identifier: The opening of your markdown code block must be exactly ```mermaid.
  • Check Syntax: Check your web browser console for syntax errors raised by the Mermaid compiler (e.g. unclosed parentheses or typos in node connections).

Themes do not syncLink

The plugin hooks into the site's dark mode provider. If themes are mismatched:

  • Ensure your custom layouts consume the useTheme() hook exported by boltdocs/client to stay in sync with the global app settings.

Large diagrams are cut offLink

By default, Boltdocs surrounds diagrams in a scrollable, responsive container. If you need diagrams to scale to fit the parent container instead, add the following to your custom global CSS stylesheet:

.mermaid-container svg {
  max-width: 100%;
  height: auto;
}
Last updated on July 27, 2026

Was this page helpful?