mermaid

package
v0.4.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package mermaid renders Mermaid diagram text (flowchart, sequence, state, class, er) as Unicode box-drawing art for terminals. It is a faithful port of the npm module grok-mermaid 0.2.2 (Apache-2.0).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Art

type Art struct {
	Plain    []string
	Styled   [][]Span
	Width    int
	Warnings []string
}

Art is a rendered diagram. Plain[i] and Styled[i] describe the same row: Plain is right-trimmed for display width and copy/paste, Styled keeps the run structure needed to colour it.

Width is the display columns the widest row needs — the number to compare against the space you have. It cannot be recovered from Plain, whose rows are strings of code points, not columns.

Warnings lists source the flowchart grammar could not read and dropped. Non-empty means the art is real but incomplete. Only flowcharts warn; the other grammars refuse the whole diagram instead, and Render returns nil. They are advisory: do not gate rendering on them.

func Render

func Render(src string) *Art

Render renders a Mermaid source block as Unicode box-drawing art.

Supported: `graph`/`flowchart` (including `subgraph`), `stateDiagram`, `classDiagram`, `erDiagram` and `sequenceDiagram`.

The diagram is laid out at whatever size it needs; Art.Width reports the columns that turned out to be. Deciding what to do when that exceeds the space at hand is the caller's.

nil means there is no art to show: blank input, a syntax error, a diagram type this renderer does not draw, or one large enough that laying it out is refused.

Rendering is best-effort. A flowchart keeps whatever parsed; the stricter grammars additionally get one retry without their final line, which is what keeps a streaming diagram on screen while its last statement is half-typed. Everything given up on is listed in Art.Warnings — advisory only, never a reason to withhold the art.

type Span

type Span struct {
	Cls  string
	Text string
}

Span is a run of adjacent cells sharing one semantic class.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL