astro-mermaid-renderer-cli-smol

An Astro integration that pre-renders Mermaid diagrams to inline SVG at build time. No client-side JavaScript is shipped — diagrams are static SVG in the output HTML.

Current version: 0.1.0 --npm

Installation

$ npm install astro-mermaid-renderer-cli-smol mermaid

Setup

In astro.config.ts:

import mermaidSSR from 'astro-mermaid-renderer-cli-smol';

export default defineConfig({
  integrations: [
    mermaidSSR({
      theme: 'default',
    }),
  ],
});

Options

OptionTypeDefaultDescription
themestring'default'Mermaid theme: default, dark, neutral, forest
titleFixbooleantrueStrip title from rendered SVG (prevents duplicate headings)
injectCSSbooleantrueAuto-inject default styles
securityLevelstring'loose'Mermaid securityLevel setting

Usage in MDX

Write standard Mermaid fences in your MDX files:

```mermaid
graph TD
  A[Start] --> B{Decision}
  B -->|Yes| C[Do thing]
  B -->|No| D[Don't do thing]
  C --> E[End]
  D --> E
```

Live example

nav-bartheme-selectordocs-sidebarsidebar-itemtoc-smolscroll-spycode-blockscopy-buttonshell-session

How it works

The integration registers a remark plugin (remarkMermaidSSR) that transforms ```mermaid fences into inline SVG during the Astro build. It uses svgdom to render Mermaid server-side without a headless browser.

To use the remark plugin directly without the integration:

import { remarkMermaidSSR } from 'astro-mermaid-renderer-cli-smol';

export default defineConfig({
  markdown: {
    remarkPlugins: [[remarkMermaidSSR, { theme: 'neutral' }]],
  },
});