mermaid-js / mermaid

Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
https://mermaid.js.org
MIT License
70.79k stars 6.35k forks source link

Parse mermaid text into json or AST #2523

Open bschlenk opened 2 years ago

bschlenk commented 2 years ago

Is there a way to parse mermaid text into an AST? I want to render mermaid diagrams in an environment that uses its own elements, not svg. I believe having an AST representation would make this easier as I could walk through it and draw out the diagram myself.

knsv commented 2 years ago

The data is stored in in a diagram specific representation after parsing. I would not that difficlt to dump it to some other format like JSON but there is no built in functionality for that.

dustinlacewell commented 2 years ago

+1 for support for dumping or otherwise exposing access to the AST, in the Mermaid API.

Yokozuna59 commented 1 year ago

Over a year has passed; are there any updates to this issue? 👀

I want to create a tool using the Mermaid API and get the AST, but it looks like it's not currently possible.

victor-develop commented 1 year ago

https://stackblitz.com/edit/node-5crpy6?file=index.mjs&view=editor

It's actually there. Curious no one answers.

Yokozuna59 commented 1 year ago

https://stackblitz.com/edit/node-5crpy6?file=index.mjs&view=editor

It's actually there. Curious no one answers.

Each diagram has its own database, but it doesn't show any internal stuff. For example, in your given code, it doesn't show where each node has been declared, its start and end, or how each node has been declared; much more depends on each diagram.

Goostavo commented 5 months ago

https://stackblitz.com/edit/node-5crpy6?file=index.mjs&view=editor

It's actually there. Curious no one answers.

Thank you. It looks like a real possibility of working with JSON, and making changes easier.

But it's not well documented. The main function used getDiagramFromText has only a mention, but the output time and so on are not clear.

Probably updating docs, can be the solution for this problem.

LTMenezes commented 2 weeks ago

https://stackblitz.com/edit/node-5crpy6?file=index.mjs&view=editor

It's actually there. Curious no one answers.

Quick note for future readers, this solution works but depending on your input it requires you to callawait mermaid.parse(mermaidGraph); before calling getDiagramFromText, the reason for this being that the parse function actually resets the internal configApi and adds the processed config to it's directive.