Skip to content

Commit

Permalink
Merge pull request #82 from rupert648/main
Browse files Browse the repository at this point in the history
feat: mermaid support
  • Loading branch information
not-matthias authored Dec 27, 2024
2 parents 875c7ff + e418323 commit c9abd57
Show file tree
Hide file tree
Showing 8 changed files with 1,821 additions and 5 deletions.
21 changes: 21 additions & 0 deletions content/posts/mermaid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
+++
title = "Mermaid Example"
date = "2024-12-26"

[taxonomies]
tags=["example"]

[extra]
comment = true
+++

{% mermaid() %}
graph LR
A[Start] --> B[Initialize]
B --> C[Processing]
C --> D[Complete]
D --> E[Success]

style A fill:#f9f,stroke:#333
style E fill:#9f9,stroke:#333
{% end %}
3 changes: 2 additions & 1 deletion sass/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@import "parts/misc.scss";
@import "parts/table.scss";
@import "parts/tags.scss";
@import "parts/_mermaid";

:root {
/* Used for: block comment, hr, ... */
Expand Down Expand Up @@ -48,4 +49,4 @@ html {
html {
font-size: 18px;
}
}
}
4 changes: 0 additions & 4 deletions sass/parts/_image.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,3 @@ figure h4 {
figure h4::before {
content: "";
}

svg {
max-height: 15px;
}
9 changes: 9 additions & 0 deletions sass/parts/_mermaid.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.mermaid {
text-align: center;
margin-top: 1em;
margin-bottom: 1em;

strong {
font-weight: bold;
}
}
25 changes: 25 additions & 0 deletions static/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
mmdElements = document.getElementsByClassName("mermaid");
const mmdHTML = [];
for (let i = 0; i < mmdElements.length; i++) {
mmdHTML[i] = mmdElements[i].innerHTML;
}

function mermaidRender(theme) {
if (theme == "dark") {
initOptions = {
startOnLoad: false,
theme: "dark",
};
} else {
initOptions = {
startOnLoad: false,
theme: "neutral",
};
}
for (let i = 0; i < mmdElements.length; i++) {
delete mmdElements[i].dataset.processed;
mmdElements[i].innerHTML = mmdHTML[i];
}
mermaid.initialize(initOptions);
mermaid.run();
}
1,760 changes: 1,760 additions & 0 deletions static/js/mermaid.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions templates/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,5 @@
<link rel="stylesheet" href="{{ get_url(path=stylesheet) }}">
{% endfor %}
{% endif %}
<script src="{{config.base_url | safe }}js/mermaid.js"></script>
</head>
3 changes: 3 additions & 0 deletions templates/shortcodes/mermaid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pre class="mermaid">
{{ body | safe }}
</pre>

0 comments on commit c9abd57

Please sign in to comment.