mermaid.source.statements

mermaid.source

statements(source) -> statements, header_or_err

Cut a diagram's source into statements

Returns the statements after the header, each { text, line } with the source line it came from, and the header in the same shape: the first statement, which names the diagram type. Its text is the header and its line is the header's source line.

Dropped on the way: a leading front-matter block between --- lines, %%{ … }%% directives, lines that open with %%, and blank statements. A directive keeps its newlines, so every line after it keeps its number.

The accessibility statements after the header are no statements. They go on the header: header.title from accTitle: text, header.descr from accDescr: text or accDescr { … }. Their keywords are read in any case. A value runs to the end of its line, semicolons included. A block runs to its first }, and what follows the brace on its line is cut into statements. A block keeps its lines, each trimmed, with the blank ones gone. A value holds no control character, and a run of blanks is one space. A later statement replaces an earlier one, and an empty value is none.

Returns nil and a reason for a source over 64 KB, a line over 2000 bytes, and a source with no statement. Returns nil and line N: reason for an accTitle or an accDescr in neither form, and for an accDescr block left open: accTitle --> B names no node.