From 10b06eda914368d1ac209130302e9ac7ba5a863d Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Sun, 14 Jun 2020 18:41:27 +0200 Subject: [PATCH] #1458 Adding directives section in the docs --- docs/_sidebar.md | 1 + docs/directives.md | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 docs/directives.md diff --git a/docs/_sidebar.md b/docs/_sidebar.md index a6c6a7f71..1b9352d7d 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -16,6 +16,7 @@ - [User Journey](user-journey.md) - [Gantt](gantt.md) - [Pie Chart](pie.md) + - [Directives](directives.md) - Guide diff --git a/docs/directives.md b/docs/directives.md new file mode 100644 index 000000000..18fb04abf --- /dev/null +++ b/docs/directives.md @@ -0,0 +1,57 @@ +### Directives + +#### Init directives + +With this version, directives are supported. Technically there are two flavors of directive: init/initialize and everything else. The init/initialize directive is parsed early in the flow enough to be able to re-initialize mermaid with a new configuration object. Example: + +``` +%%{init: { 'logLevel': 'debug', 'theme': 'dark' } }%% +graph > +A-->B +``` + +will set the `logLevel` to `debug` and the `theme` to `dark` for a flowchart diagram. + +Note: init or initialize are both acceptable as init directives. Also note that init directives are coalesced. This means: + +``` +%%{init: { 'logLevel': 'debug', 'theme': 'forest' } }%% +%%{initialize: { 'logLevel': 'fatal', "theme":'dark', 'startOnLoad': true } }%% +... +``` + +will result an init object looking like this: + +``` +{ + logLevel: 'fatal', + theme: 'dark', + startOnLoad: true +} +``` + +to be sent to `mermaid.initialize(...)` + +#### Other directives + +The other flavor of directive is everything else. In this category are any directives that follow the graph type declaration. Essentially, these directives will not be processed early in the flow like the init directive. Each individual graph type will handle these directives. As an example: + +``` +%%{init: { 'logLevel': 'debug', 'theme': 'dark' } }%% +sequenceDiagram +%%{config: { 'fontFamily': 'Menlo', 'fontSize': 18, 'fontWeight': 400} }%% +Alice->>Bob: Hi Bob +Bob->>Alice: Hi Alice +``` + +This will set the `logLevel` to `debug` and `theme` to `dark` for a sequence diagram. Then, during processing, the config for the sequence diagram is set by the `config` directive. This directive is handled in the `sequenceDb.js`. In this example, the fontFamily, fontSize, and fontWeight are all set for this sequence diagram. + +#### Backwards Compatibility + +Init directives and any other non-multiline directives should be backwards compatible because they will be treated as comments in prior versions of mermaid-js. + +Multiline directives, however, will pose an issue and will render an error. This is unavoidable. + +### Wrapping + +The `%%{wrap}%%` directive and the inline `wrap:` text hint have also been added for sequence diagrams. This has been explained in my previous comments and has not materially changed. \ No newline at end of file