❕ TinaCMS now supports MermaidJS diagrams in version 2.3.0+
Mermaid diagrams use a simple graph description language to create flowcharts, sequence diagrams, Gantt charts, and more. Below is a basic example of Mermaid syntax:
```mermaidgraph TD;A-->B;A-->C;B-->D;C-->D;```
Figure: Mermaid syntax
You can also pass configuration options directly inside your Mermaid code block to control how diagrams are rendered. For example, you can set the theme to light mode as shown below:
```mermaid---config:theme: light---graph TD;A-->B;A-->C;B-->D;C-->D;```
Figure: Adding a mermaid config
This configuration is respected by the TinaCMS renderer.
By default, the Mermaid button is accessible via the rich text toolbar. However, you can choose to hide or show this button using the ToolbarOverride
option.
For more details, see the ToolbarOverride documentation.
Once a Mermaid diagram is inserted, you can switch between Edit Mode (for modifying the Mermaid code) and Preview Mode (to see the rendered diagram).
If there is a syntax error in your Mermaid code, a red error box will appear beneath the diagram. This box displays helpful information and errors reported by the Mermaid parser. Correct the syntax, and the diagram will update.
To delete a Mermaid diagram:
Delete
on your keyboard.Backspace
at the start of the code block.TinaCMS uses the Mermaid NPM package to render and parse the Mermaid syntax. Currently, we have locked the internal version to v9.3.0
to ensure compatibility with CommonJS.
However, when installing Mermaid in your own application, you are free to use any version of Mermaid or other compatible rendering packages.
<TinaMarkdown />
TinaCMS’s <TinaMarkdown />
component includes a mermaid
property, allowing you to render Mermaid diagrams in your project however you'd like.
Here’s an example of how to use it:
<TinaMarkdown content={content} components={{mermaid({ value }) {return <ComponentToRenderMermaid value={value} />;}}} />
To quickly get started with MermaidJS in your React project, follow these steps:
First, install the Mermaid package using your package manager:
pnpm install mermaid
MermaidElement
ComponentThis component will render Mermaid diagrams in your application. Use the following code:
import { useRef, useEffect } from 'react';import mermaid from 'mermaid';export default function MermaidElement({ value }) {const mermaidRef = useRef(null);useEffect(() => {if (mermaidRef.current) {mermaid.initialize({ startOnLoad: true });mermaid.run();}}, []);return (<div contentEditable={false}><div ref={mermaidRef}><pre className="mermaid">{value}</pre></div></div>);}
<TinaMarkdown />
Integrate the MermaidElement
into the <TinaMarkdown />
component to handle Mermaid diagrams:
<TinaMarkdown content={content} components={{mermaid({ value }) {return <MermaidElement value={value} />;}}} />
Your React app will now be able to render Mermaid diagrams created in the TinaCMS editor.
mermaid
property in <TinaMarkdown />
to handle Mermaid diagrams however you need.For more details, check the MermaidJS documentation.
© TinaCMS 2019–2025