Behaviour SwRS-MDOKFSTUDIO-DIAG-001
Mermaid fences become inert diagram pictures
When a document contains a mermaid fence or a {mermaid} directive, the extension SHALL render a figure whose diagram element is labelled "Mermaid diagram" and holds the diagram text, with the same text in a collapsed "Diagram source" disclosure, and have the page draw it as one inert picture that fits the content column.
Step 2 of path 1 in StRS-MDOKFSTUDIO-DIAG-001: from “A Mermaid fence is in the document” to “The diagram is drawn as a picture”.
Scenarios 7
The situations the tests check; open one to read it.
nominalFence and directive
Givena document with a mermaid fence and a {mermaid} directive, each holding a flowchart
Whenthe preview is rendered
Thentwo Mermaid figures appear, each with a diagram element labelled "Mermaid diagram" holding the flowchart text and a collapsed details element whose summary reads "Diagram source" and whose code block holds the same text
boundaryEmpty diagram
Givena mermaid fence with no text
Whenthe preview is rendered
Thena figure with an empty diagram element is still produced, the page draws nothing in it and shows no message
nominalValid flowchart is drawn as a picture
Givena valid Mermaid flowchart
Whenthe page draws the diagram
Thenthe diagram element holds one image of class myst-mermaid-image with alt text "Mermaid diagram" and a src starting with data:image/svg+xml;charset=utf-8 (an SVG drawn at the strict security level), the diagram text is replaced, and data-render-state is rendered
nominalLabels fit their boxes in the picture
Givena flowchart with node labels ("Review telemetry", "Hold and inspect") and edge labels ("Yes", "No"), drawn with Mermaid's HTML labels
Whenthe page draws the diagram and shows it as an SVG image
ThenMermaid measures the labels inside an element of class myst-mermaid-measure that the page style sheet gives a pinned system font stack and a 16px size, with no inherited page style, and that is removed once the diagram is drawn
the Mermaid configuration and theme variables carry the same font family and size, so the image draws each label with the metrics it was measured with
in the image, the text of every label fits its label box and, for a node, its shape: no label loses its last characters
the Mermaid configuration and theme variables carry the same font family and size, so the image draws each label with the metrics it was measured with
in the image, the text of every label fits its label box and, for a node, its shape: no label loses its last characters
boundaryLine-break tags in the SVG
GivenMermaid output whose SVG contains HTML line-break tags written without a closing slash
Whenthe page builds the image source
Thenthe data URI holds the self-closing form of each line-break tag so the SVG loads as an image
boundaryPicture width against the content column
| Picture | Outcome |
|---|---|
| Natural width exceeds the content column | Displayed at the column width with its height scaled in proportion (max-width 100 percent, height auto) |
| Narrower than the content column | Keeps its natural size, is not enlarged and is centred |
nominalA diagram under edit is hidden
| Event | Outcome |
|---|---|
| A block editor opens on the diagram block of a Mermaid figure in edit mode | The figure carries data-sphinx-preview-editing true and is not displayed (display none), with the editor placed right after it |
| The editor closes | The attribute is removed and the diagram is displayed again |
Implemented in 7
Tested by 10
- test/build/bundleSplit.test.tsbuild
- test/core/preview/contentPatch.test.tsunit
- test/core/preview/previewStyles.test.tsunit
- test/core/render/mystFeatures.test.tsunit
- test/integration/projectFeatures.test.tsintegration
- test/page/diagReq.diagramEdit.requirements.test.tsunit
- test/page/mermaidLabelFit.test.tsunit
- test/page/modules/mermaidPreviewEntry.test.tsunit
- test/visual/scenarioDefinitions1.tsvisual
- test/visual/scenarioDefinitions2.tsvisual
Known limits (7)
- The page skips a Mermaid diagram whose text is empty and leaves it blank, with no diagnostic (no test covers it).
- No test asserts that the Content Security Policy lets the Mermaid bundle run; only a real VS Code run would show such a regression.
- Scripts and links inside the SVG are inert because the picture is an image with a data URI and Mermaid runs at the strict security level; this is not documented.
- mermaidPreview.ts has no unit test.
- There is no minimum scale and no zoom: a very wide diagram is scaled until its labels become small. The unit test locks the containment, not a minimum label size.
- There is no live preview of the diagram while it is edited (absent from docs/known-limitations.md).
- A theme change still redraws a hidden Mermaid diagram because the theme observer draws every diagram.
Replaces
SwRS-MDOKFSTUDIO-DIAG-002The Mermaid renderer loads only when a Mermaid figure exists superseded superseded by SwRS-MDOKFSTUDIO-DIAG-001 Markdown file
SwRS-MDOKFSTUDIO-DIAG-003Mermaid diagrams are drawn as inert pictures superseded superseded by SwRS-MDOKFSTUDIO-DIAG-001 Markdown file
SwRS-MDOKFSTUDIO-DIAG-004Mermaid pictures keep their natural size within the content width superseded superseded by SwRS-MDOKFSTUDIO-DIAG-001 Markdown file
SwRS-MDOKFSTUDIO-DIAG-022A diagram under edit is hidden superseded superseded by SwRS-MDOKFSTUDIO-DIAG-001 Markdown file