Book Image

The Official Guide to Mermaid.js

By : Knut Sveidqvist, Ashish Jain
Book Image

The Official Guide to Mermaid.js

By: Knut Sveidqvist, Ashish Jain

Overview of this book

Mermaid is a JavaScript-based charting and diagramming tool that lets you represent diagrams using text and code, which simplifies the maintenance of complex diagrams. This is a great option for developers as they’re more familiar with code, rather than using special tools for generating diagrams. Besides, diagrams in code simplify maintenance and ensure that the code is supported by version control systems. In some cases, Mermaid makes refactoring support for name changes possible while also enabling team collaboration for review distribution and updates. Developers working with any system will be able to put their knowledge to work with this practical guide to using Mermaid for documentation. The book is also a great reference for looking up the syntax for specific diagrams when authoring diagrams. You’ll start by learning the importance of accurate and visual documentation. Next, the book introduces Mermaid and establishes how to use it to create effective documentation. By using different tools, editors, or a custom documentation platform, you’ll also understand how to use Mermaid syntax for various diagrams. Later chapters cover advanced configuration settings and theme options to manipulate your diagram as per your needs. By the end of this book, you’ll be well-versed with Mermaid diagrams and how they can be used in your workflows.
Table of Contents (19 chapters)
1
Section 1: Getting Started with Mermaid
7
Section 2: The Most Popular Diagrams
12
Section 3: Powerful Diagrams for the Advanced User

Using different types of Directives

All directives are comments formatted in a special way to allow passing configuration parameters to Mermaid.

The syntax of directives is simple: they start with the line comment format, %%, followed by an opening bracket, {, then the directive, and finally a closing bracket, } (matching the opening one):

%%{directive}

There are several types of directives. We will cover them all, but let's start by looking at the most important and versatile type: the init or initialize directive.

The init directive

This is a directive that you can use to modify the initial configuration of the Mermaid diagram. This directive starts with init or initialize keyword, followed by a colon (:) and a JSON formatted configuration object:

%%{init: configuration-object}

Let's look at an example of using the init directive. There is a configuration option that you can use to turn mirrorActors on or off in sequence diagrams. We used...