Function Repository Resource:
Mermaid CLIOutput
Returns an image corresponding to a mermaid-js specification via the command line interface of mermaid-js
ResourceFunction["MermaidCLIOutput"][s] invokes Mermaid's Command Line Interface (CLI) with the spec s and imports the result. | |
ResourceFunction["MermaidCLIOutput"][s,t] specifies Mermaid's CLI output to be of type t. | |
ResourceFunction["MermaidCLIOutput"][s,t,copts] invokes Mermaid's CLI with the options copts. |
Details and Options
Examples
Basic Examples (2) 
Here is flowchart generate with a Mermaid specification:
| In[1]:= |
| Out[1]= |
Here is class diagram that is a Graphics expression:
| In[2]:= |
| Out[2]= |
Scope (11) 
Additional options can be passed to mmdc with the third argument of MermaidCLIOutput. For example, if the PNG images are with too low resolution then the mmdc"--scale" option can be used:
| In[3]:= |
| Out[3]= |
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[4]:= |
| Out[5]= |
Here is the corresponding mermaid-js image:
| In[6]:= |
| Out[6]= |
Here is a top-down version:
| In[7]:= |
| Out[7]= |
Mermaid has a different type of diagrams: Flowchart, Sequence Diagram, Class Diagram, State Diagram, Entity Relationship Diagram, User Journey, Gantt, Pie Chart, Requirement Diagram, Gitgraph Diagram, and others.
Sequence Diagram:
| In[8]:= |
| Out[8]= |
Here is Graphics expression of a Class Diagram obtained via a PDF file additionally tweaked to have large image size:
| In[9]:= |
| Out[9]= |
State diagram:
| In[10]:= |
| Out[10]= |
Entity Relationship Diagram:
| In[11]:= |
| Out[11]= |
User Journey -- PNG image is obtained and cropped:
| In[12]:= |
| Out[12]= |
Gantt chart:
| In[13]:= |
| Out[13]= |
Pie chart:
| In[14]:= |
| Out[14]= |
Requirement Diagram:
| In[15]:= |
| Out[15]= |
Options (3) 
Graphics
MermaidCLIOutput takes all options of Graphics. Those options are used when the second, type argument is "PDF".
MermaidDirectives (1) 
The option "MermaidDirectives" is used when the first argument is a Graph object. The value of that option is concatenated to the Mermaid graph specification prefix "graph". Here is an example:
| In[16]:= |
| Out[2]= |
MermaidOptions (2) 
The value of the option "MermaidOptions" is given to the CLI script "mmds". Here are the CLI options:
Here is examples with using different values for the theme option:
| In[17]:= |
| Out[2]= |
ShellSession
This option allows the specification of shell session to be used by MermaidCLIOutput. Its values are external sessions objects (ExternalSessionObject) or "Shell".
Applications (2) 
Markdown-related conversions flowchart:
| In[18]:= |
| Out[18]= |
Sequence Diagram: Blogging app service communication:
| In[19]:= |
| Out[19]= |
Properties and Relations (1) 
There is a fairly straightforward correspondence between the edge specifications for Graph and Mermaid's graph (and flowchart) specifications. Here are illustrating examples:
| In[20]:= |
| Out[20]= |
| In[21]:= |
| Out[21]= |
| In[22]:= |
| Out[22]= |
Possible Issues (1) 
Make sure mermaid-cli is installed and accessible in WL. It mermaid-cli but cannot be found then set up Shell's path variable(s) in a shell session and use the option "ShellSession" to pass that session to MermaidCLIOutput. Consider using SetOptions. For example:
SetOptions[MermaidCLIOutput, "ShellSession" -> ExternalSessions[][[1]]]Neat Examples (2) 
Larger flowchart with some styling:
| In[23]:= |
| Out[23]= |
Some interesting interaction:
| In[24]:= |
| Out[24]= |
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