collab/mermaid/docs/intro/getting-started.mdblame
View source
6dd74de1> **Warning**
6dd74de2>
6dd74de3> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
6dd74de4>
6dd74de5> ## Please edit the corresponding file in [/packages/mermaid/src/docs/intro/getting-started.md](../../packages/mermaid/src/docs/intro/getting-started.md).
6dd74de6
6dd74de7# Mermaid User Guide
6dd74de8
6dd74de9## Mermaid is composed of three parts
6dd74de10
6dd74de111. Deployment
6dd74de122. Syntax
6dd74de133. Configuration
6dd74de14
6dd74de15This section talks about the different ways to **deploy** Mermaid.
6dd74de16
6dd74de17If you are a beginner:
6dd74de18
6dd74de19- Check out the [Diagram Syntax](syntax-reference.md) page
6dd74de20- Check out the [Tutorials](../ecosystem/tutorials.md) page
6dd74de21
6dd74de22## Ways to use Mermaid
6dd74de23
6dd74de241. [Using the Mermaid Live Editor](getting-started.md#_1-using-the-mermaid-live-editor)
6dd74de252. [Using the Mermaid Chart Editor](getting-started.md#_2-using-the-mermaid-chart-editor)
6dd74de263. [Using Mermaid Plugins and Integrations](getting-started.md#_3-using-mermaid-plugins)
6dd74de274. [Calling the Mermaid JavaScript API](getting-started.md#_4-calling-the-mermaid-javascript-api)
6dd74de285. [Adding Mermaid as a dependency](getting-started.md#_5-adding-mermaid-as-a-dependency)
6dd74de29
6dd74de30To learn more, visit the [Usage](../config/usage.md) page.
6dd74de31
6dd74de32## 1. Using the Mermaid Live Editor
6dd74de33
6dd74de34Available at the [Mermaid Live Editor](https://mermaid.live) website.
6dd74de35
6dd74de36### Features
6dd74de37
6dd74de38<br />
6dd74de39
6dd74de40#### • Diagram Code
6dd74de41
6dd74de42In the `Code` panel, write or edit Mermaid code, and instantly `Preview` the rendered result in the diagram panel.
6dd74de43
6dd74de44Here is an example of Mermaid code and its rendered result:
6dd74de45
6dd74de46```mermaid-example
6dd74de47graph TD
6dd74de48 A[Enter Chart Definition] --> B(Preview)
6dd74de49 B --> C{decide}
6dd74de50 C --> D[Keep]
6dd74de51 C --> E[Edit Definition]
6dd74de52 E --> B
6dd74de53 D --> F[Save Image and Code]
6dd74de54 F --> B
6dd74de55```
6dd74de56
6dd74de57```mermaid
6dd74de58graph TD
6dd74de59 A[Enter Chart Definition] --> B(Preview)
6dd74de60 B --> C{decide}
6dd74de61 C --> D[Keep]
6dd74de62 C --> E[Edit Definition]
6dd74de63 E --> B
6dd74de64 D --> F[Save Image and Code]
6dd74de65 F --> B
6dd74de66```
6dd74de67
6dd74de68<br />
6dd74de69
6dd74de70#### • Configurations
6dd74de71
6dd74de72Configuration options are available in the `Configuration` panel. The options are applied to the diagram in the `Preview` panel.
6dd74de73
6dd74de74To learn more, visit the [Configuration Reference](../config/setup/README.md) page
6dd74de75
6dd74de76![Code,Config and Preview](./img/Code-Preview-Config.png)
6dd74de77
6dd74de78<br />
6dd74de79
6dd74de80#### • Editing History
6dd74de81
6dd74de82Your code will be autosaved and appear in the `Timeline` tab of the `History` section. Edits are saved every minute and only the last 30 edits are viewable.
6dd74de83
6dd74de84Alternatively, you can manually save code by clicking on the `Save` icon from the `History` section.
6dd74de85
6dd74de86> **Note**
6dd74de87> History is stored in the browser storage only.
6dd74de88
6dd74de89<br />
6dd74de90
6dd74de91#### • Saving a diagram
6dd74de92
6dd74de93There are multiple ways of saving your diagram from the `Actions` section:
6dd74de94
6dd74de95- export PNG
6dd74de96- export SVG
6dd74de97- export as Markdown
6dd74de98
6dd74de99![Flowchart](./img/Live-Editor-Choices.png)
6dd74de100
6dd74de101<br />
6dd74de102
6dd74de103#### • Editing your diagrams
6dd74de104
6dd74de105To edit your diagram, you can copy paste existing Mermaid diagram code into the `Code` section of the `Live Editor`.
6dd74de106
6dd74de107Or:
6dd74de108
6dd74de109- create a new diagram from scratch
6dd74de110- use a Sample Diagram from the `Sample Diagrams` section
6dd74de111
6dd74de112<br />
6dd74de113
6dd74de114#### • Loading from Gists
6dd74de115
6dd74de116The Gist you create should have a `code.mmd` file and optionally a `config.json`, similar to this [example](https://gist.github.com/sidharthv96/6268a23e673a533dcb198f241fd7012a).
6dd74de117
6dd74de118> **Note**
6dd74de119> To learn about Gists, visit the GitHub documentation page on [Creating gists](https://docs.github.com/en/get-started/writing-on-github/editing-and-sharing-content-with-gists/creating-gists).
6dd74de120
6dd74de121Once you have created a Gist, copy paste the Gist URL into the respective field in the `Actions` section and click on the `Load Gist` button.
6dd74de122
6dd74de123Here is an example of a Gist being loaded into the Editor:
6dd74de124
6dd74de125<https://mermaid.live/edit?gist=https://gist.github.com/sidharthv96/6268a23e673a533dcb198f241fd7012a>
6dd74de126
6dd74de127And, here is the diagram view from the above example:
6dd74de128
6dd74de129<https://mermaid.live/view?gist=https://gist.github.com/sidharthv96/6268a23e673a533dcb198f241fd7012a>
6dd74de130
6dd74de131## 2. Using the Mermaid Chart Editor
6dd74de132
6dd74de133Available at the [Mermaid Chart](https://mermaid.ai/) website.
6dd74de134
6dd74de135Mermaid Chart is a web-based diagram editor that allows you to create and edit diagrams in your browser. It is built by the team behind Mermaid.
6dd74de136
6dd74de137Features include:
6dd74de138
6dd74de139- AI diagramming
6dd74de140- Collaboration & multi-user editing
6dd74de141- Storage
6dd74de142- and more
6dd74de143
6dd74de144To learn more, visit the [Mermaid Chart page](/ecosystem/mermaid-chart.html) in the Ecosystem section of the documentation.
6dd74de145
6dd74de146Or go to the [Mermaid Chart website](https://mermaid.ai/app/sign-up) to sign up for a Free account.
6dd74de147
6dd74de148## 3. Using Mermaid Plugins
6dd74de149
6dd74de150### Mermaid Plugins
6dd74de151
6dd74de152You can generate Mermaid diagrams from within popular applications using plug-ins.
6dd74de153
6dd74de154For a list of Mermaid Plugins and Integrations, visit the [Integrations page](../ecosystem/integrations-community.md).
6dd74de155
6dd74de156### Mermaid Chart Plugins
6dd74de157
6dd74de158Mermaid Chart plugins are available for:
6dd74de159
6dd74de160- [ChatGPT](https://mermaid.ai/docs/plugins/mermaid-chart-gpt)
6dd74de161- [JetBrains IDE](https://mermaid.ai/docs/plugins/jetbrains-ide)
6dd74de162- [Microsoft PowerPoint](https://mermaid.ai/docs/plugins/microsoft-powerpoint)
6dd74de163- [Microsoft Word](https://mermaid.ai/docs/plugins/microsoft-word)
6dd74de164- [Visual Studio Code](https://mermaid.ai/docs/plugins/visual-studio-code)
6dd74de165
6dd74de166To learn more, visit the [Mermaid Chart Plugins](https://mermaid.ai/plugins) page.
6dd74de167
6dd74de168### Native Mermaid Support
6dd74de169
6dd74de170For apps that support markdown (e.g. [GitHub](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-diagrams) and [GitLab](https://handbook.gitlab.com/handbook/tools-and-tips/mermaid/)), you can add Mermaid diagrams by making a `mermaid` code block.
6dd74de171
6dd74de172````markdown
6dd74de173The following code-block will be rendered as a Mermaid diagram:
6dd74de174
6dd74de175```mermaid
6dd74de176flowchart LR
6dd74de177 A --> B
6dd74de178```
6dd74de179````
6dd74de180
6dd74de181## 4. Calling the Mermaid JavaScript API
6dd74de182
6dd74de183This method can be used with any common web server like `Apache`, `IIS`, `Nginx`, and `Node Express`.
6dd74de184
6dd74de185You will also need a text editing tool like `Notepad++` to generate an `html` file. It is then deployed by a web browser, i.e. `Firefox`, `Chrome`, `Safari`.
6dd74de186
6dd74de187> **Note**
6dd74de188> Internet Explorer is not supported.
6dd74de189
6dd74de190The API works by pulling rendering instructions from the source `mermaid.js` in order to render diagrams on the page.
6dd74de191
6dd74de192### Requirements for the Mermaid API
6dd74de193
6dd74de194When writing the `html` file, we give two instructions inside the `html code` to the `web browser`:
6dd74de195
6dd74de196a. The Mermaid code for the diagram we want to create.
6dd74de197
6dd74de198b. The importing of the Mermaid library through the `mermaid.esm.mjs` or `mermaid.esm.min.mjs`, and the `mermaid.initialize()` call, which dictates the appearance of diagrams and also starts the rendering process.
6dd74de199
6dd74de200#### Examples
6dd74de201
6dd74de202- This is an example of an embedded Mermaid diagram definition inside a `<pre class="mermaid">`:
6dd74de203
6dd74de204```html
6dd74de205<body>
6dd74de206 Here is a mermaid diagram:
6dd74de207 <pre class="mermaid">
6dd74de208 graph TD
6dd74de209 A[Client] --> B[Load Balancer]
6dd74de210 B --> C[Server01]
6dd74de211 B --> D[Server02]
6dd74de212 </pre>
6dd74de213</body>
6dd74de214```
6dd74de215
6dd74de216> **Note**
6dd74de217> Every Mermaid chart/graph/diagram definition should have separate `<pre>` tags.
6dd74de218
6dd74de219- This is an example of a Mermaid import and the `mermaid.initialize()` call.
6dd74de220
6dd74de221> **Note**
6dd74de222> A `mermaid.initialize()` call takes all the definitions contained within `<pre class="mermaid">` tags and renders them into diagrams.
6dd74de223
6dd74de224```html
6dd74de225<body>
6dd74de226 <script type="module">
6dd74de227 import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
6dd74de228 mermaid.initialize({ startOnLoad: true });
6dd74de229 </script>
6dd74de230</body>
6dd74de231```
6dd74de232
6dd74de233> **Note**
6dd74de234> Rendering in Mermaid is initialized by the `mermaid.initialize()` call. However, doing the opposite lets you control when it starts looking for `<pre>` tags inside the web page with `mermaid.initialize()`. This is useful when you think that not all `<pre>` tags may have loaded on the execution of `mermaid.esm.min.mjs` file.
6dd74de235
6dd74de236`startOnLoad` is one of the parameters that can be defined by `mermaid.initialize()`
6dd74de237
6dd74de238| Parameter | Description | Type | Values |
6dd74de239| ----------- | --------------------------------- | ------- | ----------- |
6dd74de240| startOnLoad | Toggle for Rendering upon loading | Boolean | true, false |
6dd74de241
6dd74de242In this example, the `mermaidAPI` is being called through the `CDN`:
6dd74de243
6dd74de244```html
6dd74de245<html>
6dd74de246 <body>
6dd74de247 Here is one mermaid diagram:
6dd74de248 <pre class="mermaid">
6dd74de249 graph TD
6dd74de250 A[Client] --> B[Load Balancer]
6dd74de251 B --> C[Server1]
6dd74de252 B --> D[Server2]
6dd74de253 </pre>
6dd74de254
6dd74de255 And here is another:
6dd74de256 <pre class="mermaid">
6dd74de257 graph TD
6dd74de258 A[Client] -->|tcp_123| B
6dd74de259 B(Load Balancer)
6dd74de260 B -->|tcp_456| C[Server1]
6dd74de261 B -->|tcp_456| D[Server2]
6dd74de262 </pre>
6dd74de263
6dd74de264 <script type="module">
6dd74de265 import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
6dd74de266 mermaid.initialize({ startOnLoad: true });
6dd74de267 </script>
6dd74de268 </body>
6dd74de269</html>
6dd74de270```
6dd74de271
6dd74de272In this example, `mermaid.js` is referenced in `src` as a separate JavaScript file:
6dd74de273
6dd74de274```html
6dd74de275<html lang="en">
6dd74de276 <head>
6dd74de277 <meta charset="utf-8" />
6dd74de278 </head>
6dd74de279 <body>
6dd74de280 <pre class="mermaid">
6dd74de281 graph LR
6dd74de282 A --- B
6dd74de283 B-->C[fa:fa-ban forbidden]
6dd74de284 B-->D(fa:fa-spinner);
6dd74de285 </pre>
6dd74de286 <pre class="mermaid">
6dd74de287 graph TD
6dd74de288 A[Client] --> B[Load Balancer]
6dd74de289 B --> C[Server1]
6dd74de290 B --> D[Server2]
6dd74de291 </pre>
6dd74de292 <script type="module">
6dd74de293 import mermaid from 'The/Path/In/Your/Package/mermaid.esm.mjs';
6dd74de294 mermaid.initialize({ startOnLoad: true });
6dd74de295 </script>
6dd74de296 </body>
6dd74de297</html>
6dd74de298```
6dd74de299
6dd74de300## 5. Adding Mermaid as a dependency
6dd74de301
6dd74de302Below are the steps for adding Mermaid as a dependency:
6dd74de303
6dd74de3041. Install `node v16`
6dd74de305
6dd74de306> **Note**
6dd74de307> To learn more about downloading and installing `Node.js` and `npm`, visit the [npm Docs website](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).
6dd74de308
6dd74de3091. Install `yarn` using `npm` with this command:
6dd74de310
6dd74de311 `npm install -g yarn`
6dd74de312
6dd74de3132. After yarn installs, enter this command:
6dd74de314
6dd74de315 `yarn add mermaid`
6dd74de316
6dd74de3173. To add Mermaid as a dev dependency, enter this command:
6dd74de318
6dd74de319 `yarn add --dev mermaid`
6dd74de320
6dd74de321## Closing note
6dd74de322
6dd74de323> **Note**
6dd74de324> Comments from Knut Sveidqvist, creator of Mermaid:
6dd74de325>
6dd74de326> - In early versions of Mermaid, the `<script>` tag was invoked in the `<head>` part of the web page. Nowadays, we can place it in the `<body>` as seen above. Older parts of the documentation frequently reflect the previous way, which still works.