@lifeomic/mermaid-simple-flowchart-parser
v1.3.4
Published
Parse mermaid flowchart text to JSON Graph
Downloads
16
Readme
mermaid-simple-flowchart-parser
Parse a subset of mermaid flowchart markdown syntax to JSON Graph.
Install
yarn add @lifeomic/mermaid-simple-flowchart-parser
Usage
Only one function, parseString
is exported. You pass a string containing
mermaid flowchart information. The function will return JSON Graph data or raise
an error.
import { parseString } from '@lifeomic/mermaid-simple-flowchart-parser';
const chart = `
flowchart
start
--> call1("data.debug, arg1: a, arg2: b,c")
`;
const graph = parseString(chart);
/*
graph = {
graph: {
directed: true,
nodes: {
call1: {
label: 'data.debug',
metadata: {
action: 'data.debug',
params: {
arg1: 'a',
arg2: 'b,c'
},
},
},
on_start: {
label: 'start',
},
},
edges: [
{
directed: true,
source: 'on_start',
target: 'call1',
},
],
}
} */
Limitations
This is a subset of mermaid flowchart syntax. It is meant to handle only the following:
%% Comments
- comments in codeflowchart
- start of flowchart (required)id
- bare node definitions (for start and error)id("xxx")
- action nodes with possible parameters-->
- edges between nodes (note this is the only edge supported)-- Comment -->
and-->|comment|
- edge comments are ignored, but will display in mermaid