Mermaid scope
Zindex reads three kinds of Mermaid: flowchart (or graph), erDiagram and sequenceDiagram. It converts them with the official Mermaid parser, version 12.1.0, and no model, so the same text always gives the same diagram. Every other Mermaid type is refused. Zindex’s eight diagram families cover more than these three types: write a workflow, UI flow, org chart or network diagram as a scene (Diagram families).
Mermaid works wherever a scene does:
- Save, check or preview:
mermaidinstead ofsceneondiagram_create,diagram_validateanddiagram_render, or onPOST /v1/diagrams,/v1/diagrams/validateand/v1/diagrams/preview. Over REST, checking and previewing need no key. - Read:
view: "mermaid"ondiagram_get, or?view=mermaidonGET /v1/diagrams/{id}. - Edit:
mermaidondiagram_editorPOST /v1/diagrams/{id}/revisions(Edits).
The text can be up to 64 KB. If it holds fenced code blocks tagged mermaid, as a chat answer often does, the first one is the diagram. A title in front matter becomes the diagram’s title, and config: can set its theme. Other front matter is ignored, apart from two sequence diagram settings (Sequence diagrams).
What the conversion draws differently or leaves out comes back in warnings, each with a code and one line saying what happened, and doesn’t stop the save. A response lists at most 10 warnings, and the lines Zindex ignores (below) get none. Validation rules: Mermaid notes lists every code. The converted diagram is then checked like any scene: if it breaks a rule, such as more than 1,000 elements (edges included), nothing is saved and the answer is VALIDATION_FAILED. A flowchart with more than 1,000 edges gets the same answer as soon as the parser reaches the 1,001st, and its error says the scene has more than 1,000 elements without counting them.
Themes
The theme in the text’s config, under config: in front matter or in %%{init}%%, becomes the diagram’s theme. Write names in lowercase, as in the table.
| In the config | The diagram’s theme |
|---|---|
| No theme | clean for a new diagram; an edit keeps the diagram’s theme |
theme: clean, blueprint or sketch, Zindex’s own names | That theme |
theme: dark, neo-dark, redux-dark or redux-dark-color, or base with themeVariables.darkMode: true | dark, or sketch with look: handDrawn |
theme: default | clean |
Any other theme, such as neutral or forest | clean, with the note THEME_APPROXIMATED |
Only sketch draws Mermaid’s look: handDrawn. Beside any theme but sketch or a dark one, or with no theme, the look is left out, with the same note.
Mermaid itself has no clean, blueprint or sketch theme, so other Mermaid tools draw text that names them in their default theme. In text meant for both, write theme: dark, with look: handDrawn for sketch.
---
title: Checkout
config:
theme: blueprint
---
flowchart LR
cart --> pay
IDs
A node’s ID is its Mermaid ID. An edge written with an ID, such as a e1@--> b, keeps it; any other edge gets an ID made from its ends, such as a--b. An ID Zindex can’t use as written (anything but letters, digits, ., _, : and -, or longer than 200 characters) becomes a readable slug with a short hash.
In a sequence diagram only participants have Mermaid IDs. Its messages, notes, blocks, boxes, highlights and activations are numbered in order (Sequence diagrams).
Flowcharts
A flowchart becomes a flowchart diagram. It keeps the direction its text gives (TB, TD, BT, LR or RL), and runs top to bottom without one. It’s drawn with the flowchart conventions. To draw a service map as an architecture diagram instead, send an updateScene that sets diagramFamily to architecture after saving.
- Nodes keep their label. A
<br>or<br/>in a label is a line break, and other HTML or Markdown is removed (LABEL_MARKUP_REMOVED). Rectangles, rounded rectangles, stadiums (pill), circles (ellipse), hexagons, right-leaning parallelograms, clouds and subroutines ([[ ]],subroutine,fr-rectorsubproc) draw as written; a cylinder becomes adatabasenode, a diamond adecisionnode and a document (docordocument) adocumentnode with its wavy bottom. Every other shape, such as stacked documents,trapezoid, a double circle or the asymmetric>], is drawn as the nearest shape and reported (SHAPE_APPROXIMATED). - Edges keep their label. Arrowheads, open links (
---), circle ends (--o), cross ends (--x, an X just short of the node), ends at both ends (<-->,o--o,x--x), dotted links (-.->, drawn dashed) and thick links (==>) carry over, and so do circle and cross ends on dotted and thick links (-.-x,==o). Invisible links (~~~) only steer Mermaid’s own layout, so they are left out with a note. linkStyleand accessibility lines are ignored. Aclickline counts as a style (STYLE_DROPPED).
Entity-relationship diagrams
An erDiagram becomes an entityRelationship diagram, laid out left to right whatever direction the text gives.
- Entities become tables with their columns: each column’s type and name,
PK,FKandUK(unique). An entity’s alias becomes its label. Column comments are kept but not drawn (COMMENT_NOT_SHOWN). - Relationships keep their label and the cardinality of each end. An identifying relationship (
--) draws solid and a non-identifying one (..) dashed, as in Mermaid. An end whose cardinality Zindex can’t draw exactly gets no glyph (CARDINALITY_APPROXIMATED). Set it withupdateEdge.
Sequence diagrams
A sequenceDiagram becomes a sequence diagram, drawn with the sequence conventions.
IDs. Participants keep their Mermaid IDs, by the rules under IDs, and a %% zindex-id comment maps an alias back to its participant. Mermaid gives the rest no IDs, so Zindex numbers them in row order, skipping IDs a participant holds:
| Element | IDs |
|---|---|
| Messages | m1, m2, and so on |
| Notes | note1, note2, and so on |
| Fragments (blocks) | by operator: loop1, alt1, opt1, and so on |
| Activation bars | act1, act2, and so on |
| Participant boxes | box1, box2, and so on, in the order written |
Highlights (rect) | rect1, rect2, and so on |
Participants and rows:
| Mermaid | Zindex |
|---|---|
participant, labeled by as, @{ "alias" } or <br/>; a participant used without being declared | sequence.lifeline, in the order they first appear |
actor, @{ "type": "actor" } | sequence.actor |
@{ "type": "database" }, and the same for boundary, control, entity, collections and queue | sequence.database, sequence.boundary, sequence.control, sequence.entity, sequence.collections and sequence.queue |
activate and deactivate, or + and - on a message | sequence.activation, from the message before activate (or the + message) to the message before deactivate (or the - message) |
Note over A, Note over A,B | sequence.note over A, or across A to B |
Note left of A, Note right of A | sequence.note beside A, with extensions.side |
loop, opt, break, alt/else, par/and, critical/option | a fragment frame with that operator, its guard as the title ([guard]), and each else, and or option as an operand |
box round participants, with or without a color and a title | a frame that lists those participants, with the title and the color as its style.fill: a participant box |
rect and a color round rows | a frame that lists those rows, with the color as its style.fill: a highlight band behind them |
create participant B before a message to B | that message as sequence.create, B’s lifeline starting there |
destroy B before a message to B | that message as sequence.destroy, B’s lifeline ending there |
title, or title in front matter | the diagram’s title |
mirrorActors: false, in front matter or %%{init}%% | showLifelineFeet: false: no foot under the lifelines |
A box written transparent, or with no color, has no fill. Rendering: Participant boxes and highlight bands says how both are drawn and where they stop: boxes don’t nest or overlap, and a long message label can cross a box’s border.
Write a fragment’s guard on one line: a fragment draws its title and guards on one row.
Messages. The type says what a message means. Where Mermaid draws its line or arrowheads differently from the type, that difference is written too, so the drawing matches Mermaid’s:
| Mermaid | Line and head | Zindex |
|---|---|---|
->> | solid, filled head | sequence.message |
-> | solid, no head | sequence.message, endArrow: "none" |
-) | solid, open head | sequence.async |
-x | solid, cross | sequence.message, endArrow: "cross" |
<<->> | solid, filled heads at both ends | sequence.message, startArrow: "triangle" |
-->> | dotted, filled head | sequence.reply, endArrow: "triangle" |
--> | dotted, no head | sequence.reply, endArrow: "none" |
--) | dotted, open head | sequence.reply |
--x | dotted, cross | sequence.reply, endArrow: "cross" |
<<-->> | dotted, filled heads at both ends | sequence.reply, startArrow: "triangle", endArrow: "triangle" |
A create or destroy message keeps the line it is written with, such as style.dash: [] for a solid create.
Numbering. Mermaid counts every message, numbered or not, and Zindex keeps the numbers Mermaid draws:
- Every message numbered from one whole number by another (
autonumber,autonumber 10orautonumber 10 5) becomes the settingextensions.autonumber. An edit then renumbers the messages after the one it changes. - An
autonumber Npartway down that keeps the increment also becomes the setting, withstepon the message where the count restarts. - Any other numbering, such as
autonumber offpartway down or a changed increment, becomes each numbered message’sstep, with the noteAUTONUMBER_FIXED. An edit doesn’t renumber those messages. showSequenceNumbers: true, in front matter or%%{init}%%, numbers every message.
Layout engine: Numbered messages has how numbers are drawn.
Drawn differently, with a note:
- A half arrowhead (
-|\,/|-and the rest) is drawn as the nearest whole one, and a central connection’s circle (()) isn’t drawn (ARROW_APPROXIMATED). - A
par_overblock is drawn aspar(CONSTRUCT_APPROXIMATED). - A participant whose
@{ "type": … }isn’t one Mermaid draws is a lifeline (SHAPE_APPROXIMATED). - A participant destroyed as it sends keeps its message, and its lifeline runs on (
CONSTRUCT_APPROXIMATED): Zindex ends a lifeline only where a message arrives at it. - A bar starts at a message that arrives at its lifeline, so an
activateafter a message that leaves the lifeline starts at the next message that arrives (CONSTRUCT_APPROXIMATED).
An imported sequence diagram has no canvas size, so its lifelines spread across the default canvas, 800 px wide, as any sequence diagram’s do. A smaller canvas.width, set with updateScene, draws them closer, as far as their headers and messages allow.
Left out, with a warning
The diagram is saved without these, and each comes back in warnings:
| Mermaid | What happens | Code |
|---|---|---|
A flowchart subgraph | Left out; its nodes are kept | SUBGRAPH_DROPPED |
| An edge to or from a subgraph | Left out; connect it to a node in the subgraph to keep it | CONSTRUCT_DROPPED |
style, classDef, class and click | Left out; set styles on the elements instead | STYLE_DROPPED |
A participant’s link, links, properties and details | Left out | CONSTRUCT_DROPPED |
An empty block, box or rect, or an empty else, and or option section | Left out | CONSTRUCT_DROPPED |
An activate with no deactivate, which Mermaid draws no bar for | Left out | CONSTRUCT_DROPPED |
An activate that no later message arrives at | Left out | CONSTRUCT_DROPPED |
| A message number with a decimal | The message is kept, unnumbered | CONSTRUCT_DROPPED |
A message number above 99, where the numbering doesn’t become autonumber | The message is kept, unnumbered | CONSTRUCT_DROPPED |
Zindex doesn’t draw a flowchart’s subgraphs, so a flowchart that relies on them for grouping loses that grouping. To group a flowchart’s nodes, add frames with operations after saving (Operations: createFrame). Accessibility lines (accTitle, accDescr) and comments are ignored, with no note.
Refused
Nothing is saved, and the answer names the problem:
| Sent | Answer |
|---|---|
Any other Mermaid type, such as classDiagram, stateDiagram or gantt | 422 UNSUPPORTED_DIAGRAM_TYPE; send the diagram as a scene |
| Text Mermaid can’t read, such as a syntax error | 422 PARSE_ERROR; error names the place or the mistake. Zindex never repairs the text |
| Text over 64 KB | 413 INPUT_TOO_LARGE. Over MCP, the tool’s input schema refuses it first |
| Text the parser takes more than 15 seconds on, or stops on | 422 IMPORT_TIMEOUT or IMPORT_FAILED; send shorter text, or a scene |
Empty text; both scene and mermaid, or neither; mermaid with ops or restoreRevision | 400 INVALID_REQUEST |
A PARSE_ERROR carries line when Mermaid names one: the line of the text you sent, counted from 1, where the parser stopped. That can be the line before the mistake. column, counted from 0, comes with it when Mermaid names that too; the sentence in error counts it from 1. A mistake Mermaid describes without a place, such as a participant deactivated twice, has neither.
Reading as Mermaid
A read with view=mermaid writes the diagram as Mermaid you can edit and send back, with its title in front matter. Entity-relationship diagrams come back as an erDiagram, sequence diagrams as a sequenceDiagram, and every other family as a flowchart. The read lists what the text leaves out or writes approximately: in notes over REST, on a note: line over MCP (Notes on a Mermaid view). A flowchart or erDiagram doesn’t write an edge’s step and stepText, and a sequenceDiagram doesn’t write stepText (STEPS_NOT_EXPORTED). No Mermaid type writes emphasis (EMPHASIS_NOT_EXPORTED).
The read writes only theme names Mermaid has: theme: dark for dark, and theme: dark with look: handDrawn for sketch. It writes nothing for clean, Mermaid’s default, or for blueprint, which Mermaid lacks (THEME_NOT_EXPORTED).
Flowchart text doesn’t name the family, so a diagram created from it is a flowchart. A read of any family but flowchart, entity-relationship and sequence says so in FAMILY_NOT_EXPORTED; the saved diagram keeps its family.
In a flowchart:
- The direction is the one the engine draws: top to bottom by default for flowcharts and org charts, left to right for the rest.
- Frames and groups are written as subgraphs, so the text reads like the diagram (
FRAMES_READ_ONLY). Text, image and guide elements, and spanning frames, have no Mermaid form and are left out, with a note. - A
subroutineis written as[[ ]]and adocumentas@{ shape: doc }. Shapes Mermaid has no syntax for, such ascloud,bucket,box3dandiconBox, are written as rectangles (SHAPE_APPROXIMATED). Edge IDs aren’t written. - An ID Mermaid can’t hold, such as
endor one with--in it, is written as an alias likezid1, with a%% zindex-idcomment that maps it back when the text returns. Keep those comments when you edit. - Circle and cross ends are written on plain, dotted and thick links (
--o,-.-x,==x), and ends at both ends on plain links (<-->,o--o,x--x). Abarend is written as an arrow. Where an X suits the diagram, setendArrow: "cross"withupdateEdge, and the text writes--x. - Positions, icons, constraints, other edge ends, and line styles other than dotted and thick aren’t part of the text.
In an erDiagram:
- Each entity is named by its ID; a label that differs isn’t written (
LABEL_NOT_EXPORTED). Frames, groups, text, images and guides are left out. - Each relationship’s cardinality is written as drawn, inferred from the columns where none was set, and as one to zero-or-many where none can be inferred (
CARDINALITY_ASSUMED). Mermaid has no plainmany, somanyis written as zero or many (}ooro{).
In a sequenceDiagram:
- Participants are declared in column order, each a
participantor anactor, withasand the label where it differs from the ID. Any other participant type is aparticipantwith its type:participant db@{ "type": "database" }. - A lifeline whose first row is the
sequence.createmessage arriving at it is declared withcreate participantright before that row, so in the text its column comes where it is created. Mermaid creates a participant only at its first row, so any other create message is written as a plain message (CONSTRUCT_APPROXIMATED).destroycomes before each destroy message. - Rows are written in order, each message’s arrow from its line and arrowheads, as the import’s table maps them. Mermaid has four heads (filled, none, open and cross) and a head at the start only in
<<->>, so another arrowhead is written as the nearest, and a head at the start alone isn’t written. Message styles other than a dash aren’t written. - A bar is written as
activateafter its first message anddeactivateafter its last. Mermaid ends the bar opened last on a participant, so overlapping bars on one lifeline are written nested (CONSTRUCT_APPROXIMATED). - Fragments become blocks, guards written without brackets. A fragment whose operator has no Mermaid block, such as
neg,reforassert, and aloop,optorbreakwith operands, is written as arectblock inrgba(128, 128, 128, 0.1)(FRAMES_READ_ONLY). - A participant box is written as a
boxround its participants’ declarations, with its fill and title, and a highlight band as arectround its rows, with its fill. A hex fill is written asrgb()orrgba(), because#starts a comment in Mermaid. A band in the gray above is writtenrgba(128,128,128,0.1), without spaces. - Mermaid’s
boxholds participants that are side by side, never a created participant or another box, and itsrectholds a color and no title. A frame Mermaid can’t hold is written as near as the text allows, with a note (CONSTRUCT_APPROXIMATED), and a Mermaid edit keeps what the text left out:- A box whose participants aren’t side by side is written round the longest run that is.
- A box inside another is written as a box of its own.
- A band is written without its title, and without a fill that isn’t a color.
autonumberfollowssequenceDiagramwhen the diagram numbers its messages, and a message’s ownstepis written asautonumber Nbefore it. Without the setting,autonumber Nbefore andautonumber offafter each message with a step bring its number back exactly.- A hidden message is written like any other. Mermaid numbers it and Zindex doesn’t, so under
autonumberMermaid’s later numbers run one higher. showLifelineFeet: falseis written asmirrorActors: falsein front matter. In labels and guards,#and;are written as#35;and#59;, and a line break as<br/>.- An ID Mermaid can’t read as a participant name, such as
end,auth-xor one with a space, is written as an alias with a%% zindex-idcomment, as in a flowchart. Keep those comments when you edit. - Edges other than messages, other nodes, a frame that lists both participants and rows or neither, groups, text, images and guides have no form in the text and are left out, with a note (
CONSTRUCT_DROPPED).
Edits
Send the whole diagram as mermaid with baseRevision, usually text you read with view=mermaid and changed. Zindex compares it with the baseRevision version and applies only the differences, as operations, making the next version:
- Nodes are matched by ID, and edges by ID or by their ends, so everything you didn’t change keeps its ID and history. An edge whose ends change becomes a new edge, unless the text gives its ID (
a e1@--> b). Mermaid has no form for an endpoint’sanchor: an edge keeps its anchors while the text keeps it, and a new edge has none. A node keeps its type, such asservice, unless you change its Mermaid shape. - Mermaid has no form for a node’s
textStyle, so a node keeps its own. A diagram saved beforewrap: "auto"existed stores"none"on its nodes, and their long labels stay on one line through Mermaid edits; set"auto"withupdateNodeorsetTextto wrap them. A new node gets the default,"auto". - Mermaid has no form for an edge’s
textStyleeither. An edge keeps its own, and a new edge has none, so its label wraps when it is wider than 200 px (Element types: Label wrapping). - Mermaid has no form for
emphasis. A node or edge keeps its own, and a new one has none: mark it withupdateNodeorupdateEdge(Element types: Emphasis). - Nodes and edges missing from the text are deleted.
- A changed title in the front matter, and a changed flowchart direction, are applied. Text without a title leaves the diagram’s title as it is; to remove a title, send
{ "op": "updateScene", "title": "" }inops. - A theme in the config that differs from the diagram’s is applied, as Themes maps it. Text without one leaves the diagram’s theme as it is.
- Groups, text, images, guides and spanning frames never change through Mermaid, apart from what deleting a node or edge removes with it.
- In flowchart and
erDiagramtext, frames and an edge’sstepandstepTextdon’t change either. A changed subgraph comes back as aFRAMES_NOT_CHANGEDwarning; change frames with operations. - An edge to a subgraph that stands for a frame or group is an edge to that frame or group, changed like any other edge. An edge to any other subgraph is left out, with a
CONSTRUCT_DROPPEDnote. - In an
erDiagram, a changed alias isn’t applied. - In an
erDiagram, a cardinality left as read keeps following the columns; one you change is saved as you wrote it. - A
sequenceDiagramedit has rules of its own (below). - Flowchart or
erDiagramtext sent back as read returnsnoop: truewhen everything in the diagram has a Mermaid form. What the read wrote approximately comes back as written: a shape written as a rectangle becomes a plain rectangle, a bar end becomes an arrow, a dash pattern becomes Mermaid’s dotted line, and a line width becomes normal or thick. The edit’schangedlists those elements. Change such diagrams with operations. - Mermaid edits work on architecture, flowchart, entity-relationship and sequence diagrams, and diagrams without a family. Flowchart text edits an architecture diagram, a flowchart or a diagram without a family, and the diagram keeps its family; an
erDiagramedits an entity-relationship diagram, and asequenceDiagrama sequence diagram. The other pairings, and a Mermaid edit of any other family, are a 422,MERMAID_FAMILY_MISMATCH: change those diagrams with operations. - Retries with
requestIdand conflicts work as for any edit (Concepts: Edits).
Sequence diagram edits
Zindex compares the text with the diagram as its read writes it, so text sent back as read returns noop: true, and what the text doesn’t hold stays as it is.
- Participants are matched by ID. A new one is created, and one you move is placed with
after. A changed label or a changed type (actor, or another in@{ "type": … }) is an update. Renaming a participant’s ID makes a new participant, with new messages: change itsaslabel instead. - Messages and notes have no IDs in the text, so they are compared as lines, as a line diff does. A line you didn’t change keeps its ID, and a line you cut and paste elsewhere is moved. A changed line between unchanged ones keeps its ID as long as its ends stay the same: a new label or arrow is one
updateEdge. New lines take the next freem<n>ornote<n>. - A message whose ends change is removed and added, with a new ID. To keep its ID, change its ends with
updateEdgeinstead. - Numbers. Under
autonumber, a line you add, delete or move renumbers the messages after it and changes no other element. A message’sstepfollows the text’sautonumber Nlines. - Blocks. A fragment whose block you change is created again, and every fragment and highlight in its tree keeps its ID. A line added just outside a block stays outside its fragment.
- Boxes. A changed title or color is one
updateFrame. A box whose participants change is created again under its ID, and keeps any participant the text couldn’t write in it. A newboxmakes a frame, and a removed one deletes the frame and leaves its participants. - Highlights. A
rectwhose color changes is oneupdateFrame, and the same color written another way changes nothing. One whose rows change is created again under its ID, with its title and style. A newrectmakes a band, and a removed one deletes the band and leaves its rows. A newrectin exactlyrgba(128, 128, 128, 0.1)isn’t made (FRAMES_NOT_CHANGED), because that text stands for a fragment Mermaid has no block for. Write the color another way, such asrgba(128,128,128,0.1), or usecreateFrame. rectblocks for fragments. A tree that holds arectblock written for a fragment Mermaid has no block for keeps its fragments’ rows. A line added to or cut from one of those blocks comes back asFRAMES_NOT_CHANGED; change those fragments with operations. Their lines still change.- Bars are matched by lifeline and first message. When you delete a bar’s first message, the bar starts where its
activateline now falls: at the message before it when that one arrives at the lifeline, or else at the next message that does. - Settings. A changed title, theme,
autonumberline ormirrorActorssetting is applied withupdateScene. - Elements the text has no form for, and each message’s
stepText, are kept, apart from what deleting a participant or message removes with it.