Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mermaid CLI - how do you escape characters?

Tags:

I'm using the Mermaid CLI to generate a flowchart (http://knsv.github.io/mermaid/flowchart.html). It works great, but I can't figure out how to get special characters (percent signs, parenthesis, etc) working as text within a node.

For illustration purposes here is a sample flowchart definition for Mermaid (filename is example.mermaid):

graph TD question1{Gas tank less than 1/8?} action1[Fill tank to 100%] question1-- Yes -->action1 

When I run mermaid on that file, I get this error (it blows up on the percent sign):

My-MacBook-Pro:mermaid mark$ mermaid example.mermaid  Error: Parse error on line 3: ...on1[Fill tank to 100%]question1-- Yes - -----------------------^ Expecting 'QUOTE', 'TAG_END', 'TAG_START', 'MULT', 'EQUALS', 'PLUS', 'DOT', 'BRKT', 'COLON', 'ALPHA', 'COMMA', 'NUM', 'CLICK', 'CLASS', 'CLASSDEF', 'LINKSTYLE', 'STYLE', 'PIPE', 'THICK_ARROW_OPEN', 'THICK_ARROW_CROSS', 'THICK_ARROW_CIRCLE', 'THICK_ARROW_POINT', 'DOTTED_ARROW_OPEN', 'DOTTED_ARROW_CROSS', 'DOTTED_ARROW_CIRCLE', 'DOTTED_ARROW_POINT', 'ARROW_OPEN', 'ARROW_CROSS', 'ARROW_CIRCLE', 'ARROW_POINT', '==', '-.', '--', 'MINUS', 'DIAMOND_STOP', 'DIAMOND_START', 'PE', 'PS', 'SQE', 'SQS', 'end', 'subgraph', 'NEWLINE', 'TAGSTART', 'TAGEND', 'DIR', 'SPACE', 'GRAPH', 'EOF', 'SEMI', got 'PCT'    ../dist/mermaid.full.js:14712 in parseError   ../dist/mermaid.full.js:14782 in parse   ../dist/mermaid.full.js:13260   ../dist/mermaid.full.js:16846   ../dist/mermaid.full.js:16889   phantomjs://webpage.evaluate():23 in executeInPage   phantomjs://webpage.evaluate():29   phantomjs://webpage.evaluate():29 PHANTOM ERROR: TypeError: 'null' is not an object (evaluating 'element.setAttribute') TRACE:  -> /usr/local/lib/node_modules/mermaid/lib/phantomscript.js: 149 (in function resolveSVGElement)  -> /usr/local/lib/node_modules/mermaid/lib/phantomscript.js: 69 

I tried escaping the percent sign, like this:

action1[Fill tank to 100&] 

But then I get the same error on the semicolon. Any thoughts on how I can escape those characters to make it work? Thanks!

like image 561
Mark Madej Avatar asked Jan 24 '15 02:01

Mark Madej


People also ask

What is Mermaid syntax?

Mermaid is a syntax similar to Markdown where you can use text to describe and automatically generate diagrams. With Mermaid's Markdown-inspired syntax, you can generate flow charts, UML diagrams, pie charts, Gantt charts, and more.

What are Mermaid diagrams used for?

Mermaid is a tool that lets you create complicated diagrams in Markdown — it works with simple commands and an intuitive syntax. You don't have to draw anything, just write down what you want to see!


1 Answers

Use quotation marks "" to enclose your text and escape special characters, e.g. in your example:

graph TD      question1{"Gas tank less than 1/8?"}     action1["Fill tank to 100%"]      question1-- Yes -->action1 

will produce this diagram:

enter image description here

This is now documented in the official documentation.

like image 54
Aziz Alto Avatar answered Nov 03 '22 01:11

Aziz Alto