Mermaid is a JavaScript library accompanied by couple of CSS files that allows you to add diagrams to your documents using Markdown like syntax. It's really pretty sleek.
With the introduction of Script Assets in LightPaper version 1.2, adding Mermaid documents in your documents is a piece of cake. These are the initial and "one time only" steps required:
- Go to
Preferences...>Script Assets(if it is hidden, click on the>>button) - Click on the
+button and addhttps://cdnjs.cloudflare.com/ajax/libs/mermaid/0.5.8/mermaid.min.jsfor File Source andMermaid JSfor Name and clickAdd. - Click on the
+button again and addhttps://cdnjs.cloudflare.com/ajax/libs/mermaid/0.5.8/mermaid.forest.min.cssfor File Source andMermaid CSSfor Name and clickAdd. - Click on
+ On Update Callback Scriptand addmermaid.init(null, '.mermaid');and clickSave.
That's it! You are all set!!
Now let's add some diagrams using Mermaid syntax:
<div class="mermaid">
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
</div>You should see something like this:
<div class="mermaid">
sequenceDiagram
participant Alice
participant Bob
Alice->John: Hello John, how are you?
loop Healthcheck
John->John: Fight against hypochondria
end
Note right of John: Rational thoughts <br/>prevail...
John-->Alice: Great!
John->Bob: How about you?
Bob-->John: Jolly good!
</div>You should see something like this:
Cool, huh?
These are just couple of simple examples. You can write more advanced and complex diagrams using Mermaid's simple Markdown like syntax. Like adding Font Awesome icons. Visit their website: http://knsv.github.io/mermaid/#mermaid for more information and examples.
Also, you can find other CSS styles and the latest versions of Mermaid here: https://cdnjs.com/libraries/mermaid
If you're one of those who doesn't like adding html elements, like <div class="mermaid"> above, to your Markdown documents then there is a better way. You can "teach" LightPaper to allow you to use familiar GitHub fenced code blocks syntax:
- Go to
Preferences...>Script Assets(if it is hidden, click on the>>button) - Click on
+ On Update Callback Scriptand appendmermaid.init(null, '.language-mermaid');and clickSave.
That's it!
Now let's add a Flowchart using fenced code syntax:
```mermaid
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
```If you see some weird whitespace and ugly background color, you can add following global styles in Preferences...>Custom CSS (thanks @mmatti):
pre.language-mermaid, code.language-mermaid{
color:inherit !important;
background-color:inherit !important;
font-family:inherit !important;
}
pre.language-mermaid > div {
display: none;
}
