Wolfram Language Paclet Repository
Community-contributed installable additions to the Wolfram Language
Graphics and images corresponding to mermaid-js specifications
Contributed by: Anton Antonov
Functions to get graphics and images corresponding to a mermaid-js specifications via mermaid.ink or via mermaid-js' command line interface mermaid-cli.
To install this paclet in your Wolfram Language environment,
evaluate this code:
PacletInstall["AntonAntonov/MermaidJS"]
To load the code after installation, evaluate this code:
Needs["AntonAntonov`MermaidJS`"]
Generate a flowchart from a Mermaid specification:
In[1]:= |
Out[1]= |
Create a Graphics expression from a class diagram:
In[2]:= |
Out[2]= |
Here is class diagram that is a Graphics expression:
In[3]:= |
Out[3]= |
Here is the head of the expression above:
In[4]:= |
Out[4]= |
Additional options can be passed to mmdc with the third argument of MermaidJS. For example, if the PNG images are with too low resolution then the mmdc"--scale" option can be used:
In[5]:= |
Out[5]= |
The first argument can be a Graph object -- the corresponding mermaid-js graph is produced. Here is a random graph that has both directed and undirected edges (some edges have tags):
In[6]:= |
Out[5]= |
Here is the corresponding mermaid-js image:
In[7]:= |
Out[7]= |
Here is a left-to-right version:
In[8]:= |
Out[8]= |
Very often Large Language Models (LLMs) produce Mermaid-JS code as a Markdown fenced code block. By default the fences are removed. Here we synthesize a Mermaid-JS specification:
In[9]:= |
Out[9]= |
Here we generate the corresponding diagram:
In[10]:= |
Out[10]= |