Skip to content

Commit

Permalink
Use configurable mermaid theme (default dark)
Browse files Browse the repository at this point in the history
I’ve added CSS to change edge labels to use a blurred backdrop rather than having a solid fill, as it makes them feel like entities on their own in the diagram with the theme defaults.
  • Loading branch information
mrmanc committed Nov 4, 2022
1 parent f60db09 commit 87d1dd8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ reveal_path: reveal.js/

# mermaid.js diagram integration
mermaid_diagrams: true
mermaid_theme: dark # See https://mermaid-js.github.io/mermaid/#/theming?id=deployable-themes

# Exclude directories and/or files from the conversion
exclude:
Expand Down
6 changes: 5 additions & 1 deletion _layouts/reveal.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
<script type="text/template">
{%
assign lines = post.content | newline_to_br | strip_newlines | split: "<br />"
%}{%
assign mermaid_theme = site.mermaid_theme | default: 'dark'
%}{%
assign mermaid_span = '<!-- .slide: class="diagram-slide" data-transition="none"--><span class="diagram-data" style="display:none;">%%{init: {&#39;theme&#39;:&#39;' | append: mermaid_theme | append: '&#39;}}%%'

This comment has been minimized.

Copy link
@mrmanc

mrmanc Nov 4, 2022

Author Collaborator

I haven’t managed to initialise mermaid with a specific theme as the legacy instructions describe, but I have managed to inject the theme using a directive.

It would be better to try moving from mermaid.init to mermaid.initialize and removing the injected directive if that works better as a way to define the theme.

%}{%
for line in lines
%}{%
Expand All @@ -63,7 +67,7 @@
| replace:'</backgroundimage>','" --> '
| replace:'<backgroundimageopacity>','<!-- .slide: data-background-opacity="'
| replace:'</backgroundimageopacity>','" -->'
| replace:'<mermaid>','<!-- .slide: class="diagram-slide" data-transition="none"--><span class="diagram-data" style="display:none;">'
| replace:'<mermaid>',mermaid_span
| replace:'</mermaid>','</span><div class="diagram-display" style="height: 300px;"></div>'
%}{%
assign first_char = line | strip
Expand Down
6 changes: 2 additions & 4 deletions _posts/0000-01-09-svg-diagrams.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# SVG Diagrams

<background>white</background>

You can use [mermaid-js](https://mermaid-js.github.io/mermaid/) to create SVG diagrams.

(enable the feature by setting `mermaid_diagrams` to `true` in `_config.yml`)
(in `_config.yml` enable the feature by setting `mermaid_diagrams` to `true`, and override the [theme](https://mermaid-js.github.io/mermaid/#/theming?id=deployable-themes) with `mermaid_theme`)

<!-- .element: style="font-size: 50%;" -->

Expand All @@ -14,7 +12,7 @@ graph TD;
A-->C;
B-->D;
C-->D;
D-->E
D-->|an edge label| E
</mermaid>
<!-- .element: style="height: 250px;" -->

Expand Down
5 changes: 5 additions & 0 deletions assets/css/mermaid.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ div.diagram-display svg {
max-width: 100% !important;
width: 100%;
height: 100%;
}
span.edgeLabel, .edgeLabel rect {
background: none !important;
backdrop-filter: blur(10px);
fill: none !important;
}

0 comments on commit 87d1dd8

Please sign in to comment.