mermaid.flowchart.parser.parse

mermaid.flowchart.parser

parse(statements, header) -> graph, err

Parse a flowchart's statements into a graph

statements and header are what mermaid.source.statements returns.

The graph:

FieldHolds
dir"TD", "BT", "LR" or "RL"; TB reads as TD
nodes{ id, shape, label, parent } in order of first mention
indexthe nodes by id
edges{ from, to, line, head, tail, minlen, label } in order
subgraphs{ id, title, parent } in order of opening
sub_indexthe subgraphs that have an id, by id

A node's label and a subgraph's title are lines; an edge's label is lines or nil. A node's parent is the innermost subgraph of its first mention inside one. minlen is the layers an edge spans at least. An edge's from or to may name a subgraph: such an id is in sub_index and in no node.

Returns nil and line N: reason for a header that names no flowchart or an unknown direction, a statement outside the grammar, an unbalanced bracket or quote, an empty edge text, a styling keyword in a node's place, an end with no subgraph, a subgraph left open, an edge to a subgraph with no node, an edge between a subgraph and a node or subgraph inside it, a graph with no node, and a graph over 200 nodes or 400 edges. N is the source line the statement or the header stands on.