collab/mermaid/docs/config/directives.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/config/directives.md](../../packages/mermaid/src/docs/config/directives.md).
6dd74de6
6dd74de7# Directives
6dd74de8
6dd74de9> **Warning**
6dd74de10> Directives are deprecated from v10.5.0. Please use the `config` key in frontmatter to pass configuration. See [Configuration](./configuration.md) for more details.
6dd74de11
6dd74de12## Directives
6dd74de13
6dd74de14Directives give a diagram author the capability to alter the appearance of a diagram before rendering by changing the applied configuration.
6dd74de15
6dd74de16The significance of having directives is that you have them available while writing the diagram, and can modify the default global and diagram-specific configurations. So, directives are applied on top of the default configuration. The beauty of directives is that you can use them to alter configuration settings for a specific diagram, i.e. at an individual level.
6dd74de17
6dd74de18While directives allow you to change most of the default configuration settings, there are some that are not available, for security reasons. Also, you have the _option to define the set of configurations_ that you wish to allow diagram authors to override with directives.
6dd74de19
6dd74de20## Types of Directives options
6dd74de21
6dd74de22Mermaid basically supports two types of configuration options to be overridden by directives.
6dd74de23
6dd74de241. _General/Top Level configurations_ : These are the configurations that are available and applied to all the diagram. **Some of the most important top-level** configurations are:
6dd74de25 - theme
6dd74de26 - fontFamily
6dd74de27 - logLevel
6dd74de28 - securityLevel
6dd74de29 - startOnLoad
6dd74de30 - secure
6dd74de31
6dd74de322. _Diagram-specific configurations_ : These are the configurations that are available and applied to a specific diagram. For each diagram there are specific configuration that will alter how that particular diagram looks and behaves.
6dd74de33 For example, `mirrorActors` is a configuration that is specific to the `SequenceDiagram` and alters whether the actors are mirrored or not. So this config is available only for the `SequenceDiagram` type.
6dd74de34
6dd74de35**NOTE:** Not all configuration options are listed here. To get hold of all the configuration options, please refer to the [defaultConfig.ts](https://github.com/mermaid-js/mermaid/blob/develop/packages/mermaid/src/defaultConfig.ts) in the source code.
6dd74de36
6dd74de37> **Note**
6dd74de38> We plan to publish a complete list of top-level configurations & diagram-specific configurations with their possible values in the docs soon.
6dd74de39
6dd74de40## Declaring directives
6dd74de41
6dd74de42Now that we have defined the types of configurations that are available, we can learn how to declare directives.
6dd74de43A directive always starts and ends with `%%` signs with directive text in between, like `%% {directive_text} %%`.
6dd74de44
6dd74de45Here the structure of a directive text is like a nested key-value pair map or a JSON object with root being _init_. Where all the general configurations are defined in the top level, and all the diagram specific configurations are defined one level deeper with diagram type as key/root for that section.
6dd74de46
6dd74de47The following code snippet shows the structure of a directive:
6dd74de48
6dd74de49```
6dd74de50%%{
6dd74de51 init: {
6dd74de52 "theme": "dark",
6dd74de53 "fontFamily": "monospace",
6dd74de54 "logLevel": "info",
6dd74de55 "htmlLabels": true,
6dd74de56 "flowchart": {
6dd74de57 "curve": "linear"
6dd74de58 },
6dd74de59 "sequence": {
6dd74de60 "mirrorActors": true
6dd74de61 }
6dd74de62 }
6dd74de63}%%
6dd74de64```
6dd74de65
6dd74de66You can also define the directives in a single line, like this:
6dd74de67
6dd74de68```
6dd74de69%%{init: { **insert configuration options here** } }%%
6dd74de70```
6dd74de71
6dd74de72For example, the following code snippet:
6dd74de73
6dd74de74```
6dd74de75%%{init: { "sequence": { "mirrorActors":false }}}%%
6dd74de76```
6dd74de77
6dd74de78**Notes:**
6dd74de79The JSON object that is passed as {**argument**} must be valid key value pairs and encased in quotation marks or it will be ignored.
6dd74de80Valid Key Value pairs can be found in config.
6dd74de81
6dd74de82Example with a simple graph:
6dd74de83
6dd74de84```mermaid-example
6dd74de85%%{init: { 'logLevel': 'debug', 'theme': 'dark' } }%%
6dd74de86graph LR
6dd74de87A-->B
6dd74de88```
6dd74de89
6dd74de90```mermaid
6dd74de91%%{init: { 'logLevel': 'debug', 'theme': 'dark' } }%%
6dd74de92graph LR
6dd74de93A-->B
6dd74de94```
6dd74de95
6dd74de96Here the directive declaration will set the `logLevel` to `debug` and the `theme` to `dark` for a rendered mermaid diagram, changing the appearance of the diagram itself.
6dd74de97
6dd74de98Note: You can use 'init' or 'initialize' as both are acceptable as init directives. Also note that `%%init%%` and `%%initialize%%` directives will be grouped together after they are parsed.
6dd74de99
6dd74de100```mermaid-example
6dd74de101%%{init: { 'logLevel': 'debug', 'theme': 'forest' } }%%
6dd74de102%%{initialize: { 'logLevel': 'fatal', "theme":'dark', 'startOnLoad': true } }%%
6dd74de103...
6dd74de104```
6dd74de105
6dd74de106```mermaid
6dd74de107%%{init: { 'logLevel': 'debug', 'theme': 'forest' } }%%
6dd74de108%%{initialize: { 'logLevel': 'fatal', "theme":'dark', 'startOnLoad': true } }%%
6dd74de109...
6dd74de110```
6dd74de111
6dd74de112For example, parsing the above generates a single `%%init%%` JSON object below, combining the two directives and carrying over the last value given for `loglevel`:
6dd74de113
6dd74de114```json
6dd74de115{
6dd74de116 "logLevel": "fatal",
6dd74de117 "theme": "dark",
6dd74de118 "startOnLoad": true
6dd74de119}
6dd74de120```
6dd74de121
6dd74de122This will then be sent to `mermaid.initialize(...)` for rendering.
6dd74de123
6dd74de124## Directive Examples
6dd74de125
6dd74de126Now that the concept of directives has been explained, let us see some more examples of directive usage:
6dd74de127
6dd74de128### Changing theme via directive
6dd74de129
6dd74de130The following code snippet changes `theme` to `forest`:
6dd74de131
6dd74de132`%%{init: { "theme": "forest" } }%%`
6dd74de133
6dd74de134Possible theme values are: `default`, `base`, `dark`, `forest` and `neutral`.
6dd74de135Default Value is `default`.
6dd74de136
6dd74de137Example:
6dd74de138
6dd74de139```mermaid-example
6dd74de140%%{init: { "theme": "forest" } }%%
6dd74de141graph TD
6dd74de142A(Forest) --> B[/Another/]
6dd74de143A --> C[End]
6dd74de144 subgraph section
6dd74de145 B
6dd74de146 C
6dd74de147 end
6dd74de148
6dd74de149```
6dd74de150
6dd74de151```mermaid
6dd74de152%%{init: { "theme": "forest" } }%%
6dd74de153graph TD
6dd74de154A(Forest) --> B[/Another/]
6dd74de155A --> C[End]
6dd74de156 subgraph section
6dd74de157 B
6dd74de158 C
6dd74de159 end
6dd74de160
6dd74de161```
6dd74de162
6dd74de163### Changing fontFamily via directive
6dd74de164
6dd74de165The following code snippet changes fontFamily to Trebuchet MS, Verdana, Arial, Sans-Serif:
6dd74de166
6dd74de167`%%{init: { "fontFamily": "Trebuchet MS, Verdana, Arial, Sans-Serif" } }%%`
6dd74de168
6dd74de169Example:
6dd74de170
6dd74de171```mermaid-example
6dd74de172%%{init: { "fontFamily": "Trebuchet MS, Verdana, Arial, Sans-Serif" } }%%
6dd74de173graph TD
6dd74de174A(Forest) --> B[/Another/]
6dd74de175A --> C[End]
6dd74de176 subgraph section
6dd74de177 B
6dd74de178 C
6dd74de179 end
6dd74de180
6dd74de181```
6dd74de182
6dd74de183```mermaid
6dd74de184%%{init: { "fontFamily": "Trebuchet MS, Verdana, Arial, Sans-Serif" } }%%
6dd74de185graph TD
6dd74de186A(Forest) --> B[/Another/]
6dd74de187A --> C[End]
6dd74de188 subgraph section
6dd74de189 B
6dd74de190 C
6dd74de191 end
6dd74de192
6dd74de193```
6dd74de194
6dd74de195### Changing logLevel via directive
6dd74de196
6dd74de197The following code snippet changes `logLevel` to `2`:
6dd74de198
6dd74de199`%%{init: { "logLevel": 2 } }%%`
6dd74de200
6dd74de201Possible `logLevel` values are:
6dd74de202
6dd74de203- `1` for _debug_,
6dd74de204- `2` for _info_
6dd74de205- `3` for _warn_
6dd74de206- `4` for _error_
6dd74de207- `5` for _only fatal errors_
6dd74de208
6dd74de209Default Value is `5`.
6dd74de210
6dd74de211Example:
6dd74de212
6dd74de213```mermaid-example
6dd74de214%%{init: { "logLevel": 2 } }%%
6dd74de215graph TD
6dd74de216A(Forest) --> B[/Another/]
6dd74de217A --> C[End]
6dd74de218 subgraph section
6dd74de219 B
6dd74de220 C
6dd74de221 end
6dd74de222```
6dd74de223
6dd74de224```mermaid
6dd74de225%%{init: { "logLevel": 2 } }%%
6dd74de226graph TD
6dd74de227A(Forest) --> B[/Another/]
6dd74de228A --> C[End]
6dd74de229 subgraph section
6dd74de230 B
6dd74de231 C
6dd74de232 end
6dd74de233```
6dd74de234
6dd74de235### Changing flowchart config via directive
6dd74de236
6dd74de237Some common flowchart configurations are:
6dd74de238
6dd74de239- ~~_htmlLabels_~~: Deprecated, [prefer setting this at the root level](/config/schema-docs/config#htmllabels).
6dd74de240- _curve_: linear/curve
6dd74de241- _diagramPadding_: number
6dd74de242- _useMaxWidth_: number
6dd74de243
6dd74de244For a complete list of flowchart configurations, see [defaultConfig.ts](https://github.com/mermaid-js/mermaid/blob/develop/packages/mermaid/src/defaultConfig.ts) in the source code.
6dd74de245_Soon we plan to publish a complete list of all diagram-specific configurations updated in the docs._
6dd74de246
6dd74de247The following code snippet changes flowchart config:
6dd74de248
6dd74de249```
6dd74de250%%{init: { "htmlLabels": true, "flowchart": { "curve": "linear" } } }%%
6dd74de251```
6dd74de252
6dd74de253Here we are overriding only the flowchart config, and not the general config, setting `htmlLabels` to `true` and `curve` to `linear`.
6dd74de254
6dd74de255> **Warning**
6dd74de256> **Deprecated:** `flowchart.htmlLabels` has been deprecated from (v\<MERMAID_RELEASE_VERSION>+). Use the global `htmlLabels` configuration instead. For example, instead of `"flowchart": { "htmlLabels": true }`, use `"htmlLabels": true` at the top level.
6dd74de257
6dd74de258```mermaid-example
6dd74de259%%{init: { "flowchart": { "htmlLabels": true, "curve": "linear" } } }%%
6dd74de260graph TD
6dd74de261A(Forest) --> B[/Another/]
6dd74de262A --> C[End]
6dd74de263 subgraph section
6dd74de264 B
6dd74de265 C
6dd74de266 end
6dd74de267```
6dd74de268
6dd74de269```mermaid
6dd74de270%%{init: { "flowchart": { "htmlLabels": true, "curve": "linear" } } }%%
6dd74de271graph TD
6dd74de272A(Forest) --> B[/Another/]
6dd74de273A --> C[End]
6dd74de274 subgraph section
6dd74de275 B
6dd74de276 C
6dd74de277 end
6dd74de278```
6dd74de279
6dd74de280### Changing Sequence diagram config via directive
6dd74de281
6dd74de282Some common sequence diagram configurations are:
6dd74de283
6dd74de284- _width_: number
6dd74de285- _height_: number
6dd74de286- _messageAlign_: left, center, right
6dd74de287- _mirrorActors_: boolean
6dd74de288- _useMaxWidth_: boolean
6dd74de289- _rightAngles_: boolean
6dd74de290- _showSequenceNumbers_: boolean
6dd74de291- _wrap_: boolean
6dd74de292
6dd74de293For a complete list of sequence diagram configurations, see [defaultConfig.ts](https://github.com/mermaid-js/mermaid/blob/develop/packages/mermaid/src/defaultConfig.ts) in the source code.
6dd74de294_Soon we plan to publish a complete list of all diagram-specific configurations updated in the docs._
6dd74de295
6dd74de296So, `wrap` by default has a value of `false` for sequence diagrams.
6dd74de297
6dd74de298Let us see an example:
6dd74de299
6dd74de300```mermaid-example
6dd74de301sequenceDiagram
6dd74de302
6dd74de303Alice->Bob: Hello Bob, how are you?
6dd74de304Bob->Alice: Fine, how did your mother like the book I suggested? And did you catch the new book about alien invasion?
6dd74de305Alice->Bob: Good.
6dd74de306Bob->Alice: Cool
6dd74de307```
6dd74de308
6dd74de309```mermaid
6dd74de310sequenceDiagram
6dd74de311
6dd74de312Alice->Bob: Hello Bob, how are you?
6dd74de313Bob->Alice: Fine, how did your mother like the book I suggested? And did you catch the new book about alien invasion?
6dd74de314Alice->Bob: Good.
6dd74de315Bob->Alice: Cool
6dd74de316```
6dd74de317
6dd74de318Now let us enable wrap for sequence diagrams.
6dd74de319
6dd74de320The following code snippet changes sequence diagram config for `wrap` to `true`:
6dd74de321
6dd74de322`%%{init: { "sequence": { "wrap": true} } }%%`
6dd74de323
6dd74de324By applying that snippet to the diagram above, `wrap` will be enabled:
6dd74de325
6dd74de326```mermaid-example
6dd74de327%%{init: { "sequence": { "wrap": true, "width":300 } } }%%
6dd74de328sequenceDiagram
6dd74de329Alice->Bob: Hello Bob, how are you?
6dd74de330Bob->Alice: Fine, how did your mother like the book I suggested? And did you catch the new book about alien invasion?
6dd74de331Alice->Bob: Good.
6dd74de332Bob->Alice: Cool
6dd74de333```
6dd74de334
6dd74de335```mermaid
6dd74de336%%{init: { "sequence": { "wrap": true, "width":300 } } }%%
6dd74de337sequenceDiagram
6dd74de338Alice->Bob: Hello Bob, how are you?
6dd74de339Bob->Alice: Fine, how did your mother like the book I suggested? And did you catch the new book about alien invasion?
6dd74de340Alice->Bob: Good.
6dd74de341Bob->Alice: Cool
6dd74de342```