Logo

dev-resources.site

for different kinds of informations.

Colouring Your Arrow / Link with `linkStyle` in Mermaid Markdown

Published at
9/10/2023
Categories
productivity
programming
markdown
mermaid
Author
ranggakd
Author
8 person written this
ranggakd
open
Colouring Your Arrow / Link with `linkStyle` in Mermaid Markdown

Welcome back to Technically Speaking, your sanctuary for diving deep into the labyrinthine wonders of technology. Today, we turn the spotlight onto Mermaid, a marvelous tool that's become my go-to for diagramming and documentation. Specifically, we're going to add some splashes of colour to the arrows or links in our Mermaid Markdown flowcharts. Let's get to it!

Setting the Stage

First things first, we need a basic flowchart or graph to work with. Here's a snippet from my upcoming post on steganography, showcasing a flowchart that I built using Mermaid Markdown:



graph TB
    Decode([Decode])
    End([End])
    ULhbCover[/"Unmerged Left-half
    bits Cover Image"/]
    CULhbHidden[/"Cover Image-sized Unmerged Left-half
    bits Hidden Image"/]
    ULhbHidden[/"Unmerged Left-half
    bits Hidden Image"/]
    Merged[/Merged Image/]
    Lhb[LHB Mapping]
    Rhb[RHB Mapping]

    Decode --> Merged
    Merged --> Lhb & Rhb
    Lhb --> ULhbCover
    Rhb --> CULhbHidden
    CULhbHidden --"pass on hidden image
    position in merged image"--> ULhbHidden
    ULhbCover & ULhbHidden --> End


Enter fullscreen mode Exit fullscreen mode

The Art of Styling Links

When I first stumbled upon the Mermaid documentation on styling links, it seemed simple enough. Just use this one-liner:



linkStyle default stroke:green;


Enter fullscreen mode Exit fullscreen mode

The default parameter applies the styling to all links or arrows in your chart. However, there was one hiccup: the documentation didn't specify where to put this mysterious one-liner. Initially, I faced errors that had me scratching my head. Then, eureka! It occurred to me to place the styling directive after all the link syntax, like so:



graph TB
    Decode([Decode])
    End([End])
    ULhbCover[/"Unmerged Left-half
    bits Cover Image"/]
    CULhbHidden[/"Cover Image-sized Unmerged Left-half
    bits Hidden Image"/]
    ULhbHidden[/"Unmerged Left-half
    bits Hidden Image"/]
    Merged[/Merged Image/]
    Lhb[LHB Mapping]
    Rhb[RHB Mapping]

    Decode --> Merged
    Merged --> Lhb & Rhb
    Lhb --> ULhbCover
    Rhb --> CULhbHidden
    CULhbHidden --"pass on hidden image
    position in merged image"--> ULhbHidden
    ULhbCover & ULhbHidden --> End

    linkStyle default stroke:green;


Enter fullscreen mode Exit fullscreen mode

And just like that, it worked! Behold the green strokes in all their glory:

Decode mermaid graph

Uncharted Waters

There are still a couple of nuances that have eluded me. One is colouring the arrowhead itself; I did ask BingChat for a solution, but it involved intricate CSSβ€”a no-go for this Markdown-centric endeavor. Secondly, I'm on a perpetual quest for a contrasting background. Dark mode is my jam, and unfortunately, Mermaid's PNG output doesn't play well with it. I tried to set a solid background colour, but so far, no dice. You could try it live yourself here.

So there we have itβ€”your links now boast eye-catching strokes, although the quest for perfect styling remains ever ongoing. If you've got insights on the elusive arrowhead colouring or background contrast, do share! Until then, keep exploring, keep questioning, and most importantly, keep Technically Speaking.

Happy diagramming! πŸ“Šβœ¨

mermaid Article's
30 articles in total
Favicon
LLM + Mermaid: How Modern Teams Create UML Diagrams Without Lucidchart
Favicon
Draw Diagrams in READMEs using Mermaid
Favicon
Diagram as Code with Mermaid
Favicon
Visualizing Cloud Designations with Mermaid
Favicon
Adding Mermaid diagrams to Astro MDX
Favicon
Mermaid Cheat Sheet for Markdown
Favicon
Mermaid Markdown
Favicon
simple mermaid builder in golang: support ER/sequence diagram, pie chart
Favicon
Why mermaid diagrams will be the next big thing in creating diagrams?
Favicon
HueHive diagram generator -Mermaid diagrams using ChatGPT
Favicon
Automating my Blog
Favicon
Technical presentations with Marp and Mermaid
Favicon
Convert YouTube videos into Mind Maps using ChatGPT
Favicon
Mastering Diagrams: A Professional Approach to Enhancing Visuals with ChatGPT and Mermaid
Favicon
Text to diagram
Favicon
Colouring Your Arrow / Link with `linkStyle` in Mermaid Markdown
Favicon
Creando diagramas con ChatGPT y Mermaid js
Favicon
Scaling Diagram Documentation
Favicon
Diagramming Finite State Machines with Mermaid.js
Favicon
Creating SysML Requirement Diagrams in Mermaid.js
Favicon
Creating Timeline Charts with Mermaid.js
Favicon
How to Make Flowcharts with Mermaid.js
Favicon
Mind Maps in Markdown with Mermaid.js
Favicon
Creating Gantt Charts with Markdown and Mermaid.js
Favicon
Mapping User Journeys with Mermaid.js
Favicon
Making Pie (Charts) out of Mermaid.js
Favicon
Illustrating git Branching with Markdown and Mermaid.js
Favicon
Sequence Diagrams in Markdown with Mermaid.js
Favicon
Text-Based Entity Relationship Diagrams with Mermaid.js
Favicon
Creating Class Diagrams with Mermaid.js

Featured ones: