Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mermaid - Custom CSS & Scripts in Markdown

tl;dr For a Markdown page on Github, how can I specify a styling sheet and source script for a mermaid diagram?

I'm looking through mermaid's Flowchart documentation and foud a lot of cool features like being able to specify a callback. However, I'm struggling to figure out how one would go about doing this in Markdown.

I've figured out how to change the theme from this question, and am using inline classDef for styling as explained in the docs, but still not sure how I'd go about using a custom styling sheet and defining a callback that's not just a hyperlink.

like image 912
Olshansk Avatar asked Aug 30 '26 18:08

Olshansk


1 Answers

Mermaid's syntax allows you to use inline directives in the Mermaid content, that directs how it should render. You can pass it the same parameters you would pass in init(), such as this example for sequence diagrams.

I did a quick test with the following, and it seems to work:


I am in a Markdown file and I want to show you a diagram:

```mermaid
%%{
  init: {
    "sequence": {
      "actorFontFamily": "monospace",
      "actorFontWeight": "bold",
      "messageFontFamily": "monospace",
      "messageFontWeight": "bold",
      "noteFontWeight": "bolder"
    }
  }
}%%

sequenceDiagram
  autonumber
  participant Browser
  participant AppServer

  rect rgb(255, 255, 255, 0.05)
    note over Browser, AppServer: (Phase 1) Authentication Check

    Browser ->> AppServer: GET /admin { Cookie:  }
    Browser ->> Browser: useSession
  end
```

Changing things like font sizes do not always result in an apparent change (I suppose the SVG must be scaled to the available size in your browser), but you can try changing the "theme" to verify the directive is being processed.

like image 74
Kyle Krull Avatar answered Sep 01 '26 08:09

Kyle Krull



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!