Function Repository Resource:
MermaidInk
Get an image corresponding to a Mermaid-js specification via the web Mermaid-ink interface of Mermaid-js
ResourceFunction["MermaidInk"][s] retrieves an image defined by the spec s from Mermaid's Ink Web interface. |
Details and Options
| TB | top to bottom |
| TD | top-down |
| BT | bottom to top |
| RL | right to left |
| LR | left to right |
Examples
Basic Examples (2) 
Generate a flowchart from a Mermaid specification:
| In[1]:= |
| Out[1]= |
Create a Graphics expression from a class diagram:
| In[2]:= |
| Out[2]= |
Scope (9) 
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[3]:= |
| Out[6]= |
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 generate a Mermaid-JS diagram:
| In[9]:= |
| Out[9]= |
Here we generate the corresponding diagram:
| In[10]:= |
| Out[10]= |
Create a Sequence Diagram:
| In[11]:= |
| Out[11]= |
State diagram:
| In[12]:= |
| Out[12]= |
Entity Relationship Diagram:
| In[13]:= |
| Out[13]= |
User Journey -- PNG image is obtained and cropped:
| In[14]:= |
| Out[14]= |
Gantt chart:
| In[15]:= |
| Out[15]= |
Pie chart:
| In[16]:= |
| Out[16]= |
Requirement Diagram:
| In[17]:= |
| Out[17]= |
Options (3) 
DropMarkdownFences (2) 
Very often Large Language Models (LLMs) produce Mermaid-JS code as a Markdown fenced code block. By default the fences are removed:
| In[18]:= |
| Out[18]= |
Without dropping the Markdown code block fences we get an error:
| In[19]:= |
| Out[19]= |
MermaidDirectives (1) 
The option "MermaidDirectives" is used when the first argument is a Graph object:
| In[20]:= |
| Out[21]= |
Applications (2) 
Create a Markdown-related conversions flowchart:
| In[22]:= |
| Out[22]= |
Create a Sequence Diagram for a blogging app service communication:
| In[23]:= |
| Out[23]= |
Properties and Relations (3) 
There is a fairly straightforward correspondence between the edge specifications for Graph and Mermaid graph (or flowchart) specifications:
| In[24]:= |
| Out[24]= |
| In[25]:= |
| Out[25]= |
| In[26]:= |
| Out[26]= |
A diagram that clarifies the execution of MermaidInk:
| In[27]:= |
| Out[27]= |
For some textual content MermaidInk specifications should use quotes. Also, a new line character in text can be included using “
”:
| In[28]:= |
| Out[28]= |
Without the quotes for block "A" the specifications above does not work:
| In[29]:= |
| Out[29]= |
Neat Examples (2) 
Larger flowchart with some styling:
| In[30]:= |
| Out[30]= |
Some interesting interaction:
| In[31]:= |
| Out[31]= |
Related Links
- GitHub - mermaid-js/mermaid: Generation of diagram and flowchart from text in a similar manner as markdown
- mermaid - Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.
- GitHub - mermaid-js/mermaid-cli: Command line tool for the Mermaid library
- Online FlowChart & Diagrams Editor - Mermaid Live Editor