Mermaid diagrams on the cell grid. layout lays a diagram out into a
frame (mermaid.frame), and a painter reads the frame. render runs
both and gives rows for a terminal.
The group knows no terminal and no theme. A row's runs name their styles, and the caller supplies what a style looks like.
| Module | Description |
|---|---|
| mermaid.flowchart | A flowchart, from its statements to a frame: the parser, then the four steps of the layout in order. |
| mermaid.frame | The frame: a laid out diagram on the terminal's cell grid. |
| mermaid.glyph | The glyph painter: a frame drawn in box characters, for a terminal that shows no image. |
| mermaid.label | A diagram's label, from its source text to lines of cells. |
| mermaid.outline | The shape table: each box shape's outline, for the painters that draw strokes as geometry. |
| mermaid.pixel | The pixel painter: a frame's strokes as strips of pixels, one strip a text row. |
| mermaid.raster | A small surface for a diagram's strokes: one band of pixels, as tall as a text row and as wide as the diagram, drawn and written out, then reused for the next row. |
| mermaid.sequence | A sequence diagram, from its statements to a frame: the parser, then the layout. |
| mermaid.source | A diagram's source text, cut into statements. |
| mermaid.svg | The SVG painter: a frame as one inline <svg>, for a web page. |
| Name | Signature |
|---|---|
| layout | layout(source, opts) -> frame, err |
| render | render(source, opts) -> rows, err |
| is_fence | is_fence(info) -> yes |
| text | text(row, style_fn) -> line |
layout(
source,opts) ->frame,err
Lay a diagram's source out into a frame
Parses the source by its diagram type and lays it out on the cell grid.
Returns a frame that passes mermaid.frame.check, with frame.kind set
to "flowchart" or "sequence". Any painter can read it. The source's
accTitle and accDescr go on the frame as frame.title and
frame.descr, when it has them.
opts:
| Field | Holds |
|---|---|
max_cols | past this width the diagram is laid out once more, compact |
compact | lay the diagram out compact from the start |
turned | lay a flowchart out in its other flow: TD as LR, BT as RL, and back |
A frame still wider than max_cols after the compact layout is returned
all the same. The caller decides what a too wide frame costs.
The retry for max_cols never changes the direction. A chart is turned
only when the caller asks for it, and both its tries are then turned.
Returns nil and a reason for a diagram type other than a flowchart and a
sequence diagram, a source its parser refuses, a diagram the layout does
not draw, and a frame that fails the check. turned on a sequence
diagram, which has one direction, returns nil and
"a diagram with one direction".
render(
source,opts) ->rows,err
Draw a diagram's source as rows
Lays the diagram out with layout and paints it. Returns one entry per
row, each { runs = { ... } }; mermaid.text turns one into a line.
rows.cols is the diagram's width in columns.
opts:
| Field | Holds |
|---|---|
max_cols | the widest diagram the caller can show |
compact | lay the diagram out compact from the start, whatever the room |
turned | lay a flowchart out in its other flow, as layout does |
painter | "glyph", the default, or "pixel" |
cell_w, cell_h, inks, stroke | what mermaid.pixel.paint reads |
The glyph painter draws every stroke in box characters. Under the pixel
painter a row's runs are its labels alone, and its strokes are a strip of
pixels in row.strip, { w, h, cols, rgba }, to be shown under the
row's text. A row with no stroke has false for its strip. Both painters
give the same rows and columns, and the same labels at the same cells.
Returns nil and a reason when there is no picture to show: each refusal
of layout, and "too wide" for a diagram wider than opts.max_cols
even when laid out compact. The caller then shows the source.
is_fence(
info) ->yes
Report whether a fence's info string names a diagram
True when the first word of the info string is mermaid. The rest of the
string is ignored: mermaid {.wide} is a diagram. The word is matched as
written: Mermaid is not one.
text(
row,style_fn) ->line
Join a painted row's runs into one line of text
Writes each run at its column, with spaces across the blank cells before
it. style_fn(style, text) returns a run's text as the terminal should
get it; with no function a run goes out plain. Nothing follows the last
run, so a line is as wide as its last run's end.