You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
success/packages/excalidraw/mermaid.ts

34 lines
684 B
TypeScript

/** heuristically checks whether the text may be a mermaid diagram definition */
export const isMaybeMermaidDefinition = (text: string) => {
const chartTypes = [
"flowchart",
"graph",
"sequenceDiagram",
"classDiagram",
"stateDiagram",
"stateDiagram-v2",
"erDiagram",
"journey",
"gantt",
"pie",
"quadrantChart",
"requirementDiagram",
"gitGraph",
"C4Context",
"mindmap",
"timeline",
"zenuml",
"sankey",
"xychart",
"block",
];
const re = new RegExp(
`^(?:%%{.*?}%%[\\s\\n]*)?\\b(?:${chartTypes
.map((x) => `\\s*${x}(-beta)?`)
.join("|")})\\b`,
);
return re.test(text.trim());
};