Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse mermaid text into json or AST #2523

Open
bschlenk opened this issue Nov 30, 2021 · 8 comments
Open

Parse mermaid text into json or AST #2523

bschlenk opened this issue Nov 30, 2021 · 8 comments
Labels
Status: Triage Needs to be verified, categorized, etc Type: Other Not an enhancement or a bug

Comments

@bschlenk
Copy link

bschlenk commented Nov 30, 2021

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.

@bschlenk bschlenk added the Type: Other Not an enhancement or a bug label Nov 30, 2021
@github-actions github-actions bot added the Status: Triage Needs to be verified, categorized, etc label Nov 30, 2021
@knsv
Copy link
Collaborator

knsv commented Dec 7, 2021

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
Copy link

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

@Yokozuna59
Copy link
Member

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
Copy link

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

It's actually there. Curious no one answers.

@Yokozuna59
Copy link
Member

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
Copy link

Goostavo commented Apr 1, 2024

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
Copy link

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 call await 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.

@serge-salamanka
Copy link

Hi! I want to use JSONNET for generating diargrams of different components that could be interconnected with each other by referencing. Can we make that possible ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage Needs to be verified, categorized, etc Type: Other Not an enhancement or a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants