Markdown OKF-Schema Studio

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
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
PictureOutcome
Natural width exceeds the content columnDisplayed at the column width with its height scaled in proportion (max-width 100 percent, height auto)
Narrower than the content columnKeeps its natural size, is not enlarged and is centred
nominalA diagram under edit is hidden
EventOutcome
A block editor opens on the diagram block of a Mermaid figure in edit modeThe figure carries data-sphinx-preview-editing true and is not displayed (display none), with the editor placed right after it
The editor closesThe attribute is removed and the diagram is displayed again

Implemented in 7

Tested by 10

Known limits (7)

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