Red Gregory

View Original

How To Get Started With Mermaid In Notion

See this content in the original post

Video Guide

Where To Find Mermaid In Notion

Where is mermaid?

  1. Trigger the block menu in the body of any page (“/”)

  2. Find “Code Block”

  3. Change the code language to “Mermaid”

There should be a second dropdown menu next to the language selector with three options:

  1. Code: see just the code

  2. Preview: see just the chart

  3. Split: see the code and the chart

Flowchart Orientation

There are four ways to view a flowchart with Mermaid:

  1. Left to Right: LR

  2. Right to Left : RL

  3. Top to Bottom: TB

  4. Bottom to Top: BT

Step 1: Connect Two Nodes

Each shape in the flowchart is called a node. The lines connecting nodes are called links. Connect the first two nodes, and let’s assume this flowchart is planning a basic project manager in Notion.

Each node has an ID and a Label

G(Goals)

This is a nice syntax to use because it allows you to quickly reference a node without spelling out the entire label further down in your code. You only have to label a node once.

See this content in the original post

Step 2: Adding More Nodes

There are two ways to string nodes together:

See this content in the original post

or

See this content in the original post

Step 3: Link In Multiple Directions

The goals database connects to the projects, of which connects to the tasks. Tasks also has two outcomes — complete or incomplete. This fork is created by connecting tasks to both complete and incomplete nodes like this:

See this content in the original post

or like this:

See this content in the original post
See this content in the original post

Step 4: Adding Comments

Now let’s add some context to the connections between nodes like this:

G(Goals) ---> |Connect To| P(Projects)
See this content in the original post

Step 5: Customizing Node Shapes

There are a handful of different node shapes you can choose from. Take a look at the link to Mermaid’s documentation below to see more. For Notion users, the database shape may be useful. Here are a few:

  • Database

    • G[(Goals)]
  • Pill Shape

    • IC([Incomplete])
  • Subroutine

    • R[[Review]]
See this content in the original post

Step 6: Customizing Link Shapes

You can customize link shapes as well. There are a lot of different options including two-way arrows, plain lines, lines that indicate a stoppage in the flow, and more. Here are a few:

  • Bold arrow

    • G ==> P
  • Two-way arrow

    • G <--> P
  • Line with circle

    • G --o P
  • Line with x

    • G --x P
  • Dotted line

    • G -.-> P
See this content in the original post

Step 7: Code Organization

I recommend organizing your code as the flowchart grows and links begin to multiply. Using %% comments %%, you can create different sections in the flow.

For example, this is how you can separate all connections in the Goals database from the Projects database:

See this content in the original post
See this content in the original post

Step 8: Customize Node Colors

Here is the best way to add colors to your flowchart’s nodes with mermaid. Firstly, create a section for only colors. Next, add all classDef lines inside to define each color you’ll be using in the graph like this:

%% Colors %% classDef blue fill:#2374f7,stroke:#000,stroke-width:2px,color:#fff

Next, add the defined colors above next to the node you want to fill.

G[(Goals)]:::blue <===> |Connect To| P[(Projects)]:::blue
flowchart LR
%% Colors %%
classDef blue fill:#2374f7,stroke:#000,stroke-width:2px,color:#fff
classDef pink fill:#eb3dd6,stroke:#000,stroke-width:2px,color:#fff
classDef orange fill:#fc822b,stroke:#000,stroke-width:2px,color:#fff
classDef red fill:#ed2633,stroke:#000,stroke-width:2px,color:#fff
classDef green fill:#16b522,stroke:#000,stroke-width:2px,color:#fff
%% GOALS DATABASE %%
%% Goals & Projects %%
G[(Goals)]:::blue <===> |Connect To| P[(Projects)]:::blue
%% PROJECTS DATABASE %%
%% Deadline %%
P ---o |Has| PD(Deadline):::orange
PD ---x |Is| MT([Met]):::green
PD ---- |Is| OV([Overdue]):::red
OV ---> |Push| OVF{4 Days}:::pink
%% Tasks %%
P ---o |Has| PT(Tasks):::orange
PT ---x |Is| IC([Incomplete]):::red
PT ---- |Is| C([Complete]):::green
C ---> |Needs| R[[Review]]
%% Review & Goals %%
R -..-> |Creates New| G

Bonus: Add Notion Links TO Nodes

Yes, you can also add links to your nodes. For example, if the Goals node is representing a database called Goals, you can navigate to that page in Notion and copy/paste the page link into this piece of code:

flowchart LR  G[(Goals)] click G "insert link here"

Further Reading

See this gallery in the original post