Skip to content

mermaid

Marcos Caceres edited this page Dec 4, 2026 · 1 revision

<pre class="mermaid">

ReSpec draws Mermaid diagrams from text. Wrap the diagram in a <figure> and ReSpec numbers it, captions it, and lists it in the Table of Figures like any other figure.

Usage

<figure id="release-flow">
  <pre class="mermaid">
    flowchart LR
      A[Draft] --> B[Review] --> C[Publish]
  </pre>
  <figcaption>A change goes from draft to review before it is published</figcaption>
</figure>

<p>As shown in <a href="#release-flow"></a>, every change gets a review.</p>

The empty <a href="#release-flow"> fills in "Figure N", the same as for any other figure.

In a Markdown document, a fenced block tagged mermaid becomes the same <figure>. A title after the tag becomes the <figcaption>:

```mermaid "title": "A change goes from draft to review before it is published"
flowchart LR
  A[Draft] --> B[Review] --> C[Publish]
```

Notes

  • Write the diagram with Mermaid 12.1.0 syntax. ReSpec's tests cover flowcharts, sequence diagrams, class diagrams, state diagrams, and pie charts
  • A <figcaption> is required, as for any other figure. A fence without a "title" has no caption, so ReSpec warns about the missing caption
  • A Markdown fence has no id. To link to the diagram, write the <figure> in HTML and give it an id
  • A <pre class="mermaid"> outside a <figure> still draws, but it gets no number and ReSpec warns: "Diagrams should be inside a <figure>."
  • A fence in a file pulled in with data-include works too, when the include uses data-include-format="markdown"
  • The <figcaption> is the diagram's accessible name for screen readers
  • Readers get a button that flips the diagram to its text and a button that copies the text
  • A wide diagram switches to a narrow layout on a phone
  • In dark mode, the diagram follows the page colors
  • Snapshots saved from the ReSpec menu keep the diagram and both buttons
  • A mistake in the diagram text shows an error card in place of the drawing, with the failing line marked, and adds an error to the ReSpec pill
  • "Could not load the diagram renderer." means the drawing code did not load. The diagrams stay as text. ReSpec runs that code as an inline script from a file named respec-pele.js next to the ReSpec script, so it cannot load from a file:// page, under a Content Security Policy that blocks inline scripts, or when that file is missing. Preview your spec over http:// to see the diagrams
  • "Could not draw the diagrams: the fonts were still loading." means a web font took too long to load. Check the font links in your document and reload
  • "Could not draw a diagram." is a bug in ReSpec, not in your diagram. Please file an issue with the diagram text
  • Set diagrams to false in your respecConfig to leave every <pre class="mermaid"> and mermaid fence alone
  • Other ReSpec profiles do not draw diagrams. In them, a mermaid fence stays a normal code block
  • Also see Figures in the Editor's Guide

Guides

Configuration options

W3C Configuration options

Linting rules

Internal properties

Handled by ReSpec for you.

Special <section> IDs

HTML elements

Custom Elements

HTML attributes

CSS Classes

Special properties

Clone this wiki locally