Mermaid diagram rendering components for Docusaurus websites with theme integration and error handling
npx @tessl/cli install tessl/npm-docusaurus--theme-mermaid@3.8.0@docusaurus/theme-mermaid is a Docusaurus theme plugin that provides Mermaid diagram rendering capabilities for documentation websites. It integrates the popular Mermaid library (>=11.6.0) to enable rendering of diagrams and flowcharts directly in Markdown content with automatic theme switching, error boundaries, and client-side rendering support.
npm install @docusaurus/theme-mermaidimport themeMermaid, { validateThemeConfig } from "@docusaurus/theme-mermaid";For client-side usage:
import {
useMermaidConfig,
useMermaidThemeConfig,
useMermaidRenderResult,
MermaidContainerClassName
} from "@docusaurus/theme-mermaid/client";For React components:
import Mermaid from "@theme/Mermaid";// docusaurus.config.js
import themeMermaid from "@docusaurus/theme-mermaid";
export default {
themes: [themeMermaid()],
themeConfig: {
mermaid: {
theme: {
light: 'default',
dark: 'dark',
},
options: {
// Mermaid config options
},
},
},
};import React from "react";
import Mermaid from "@theme/Mermaid";
export default function MyComponent() {
const mermaidCode = \`
graph TD
A[Start] --> B[Process]
B --> C[End]
\`;
return <Mermaid value={mermaidCode} />;
}@docusaurus/theme-mermaid is built around several key components:
Main plugin factory and theme configuration validation for setting up Mermaid in Docusaurus.
function themeMermaid(): Plugin<void>;
function validateThemeConfig(
context: ThemeConfigValidationContext<ThemeConfig>
): ThemeConfig;Client-side hooks and utilities for rendering Mermaid diagrams with theme integration.
function useMermaidConfig(): MermaidConfig;
function useMermaidThemeConfig(): ThemeConfig['mermaid'];
function useMermaidRenderResult(params: {
text: string;
config?: MermaidConfig;
}): RenderResult | null;
const MermaidContainerClassName: string;Pre-built React components for rendering Mermaid diagrams with error handling.
interface Props {
value: string;
}
function Mermaid(props: Props): ReactNode;interface ThemeConfig {
mermaid: {
theme: {
light: mermaidAPI.Theme;
dark: mermaidAPI.Theme;
};
options: mermaidAPI.Config;
};
}
type UserThemeConfig = DeepPartial<ThemeConfig>;
interface Plugin<T> {
name: string;
getThemePath?(): string;
getTypeScriptThemePath?(): string;
}