-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: Imtiaz Khan <imtiaz.khan.BDS@gmail.com>
- Loading branch information
1 parent
3e2a67d
commit d3d237d
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs'; | ||
|
||
mermaid.initialize({ | ||
startOnLoad: false, | ||
theme: 'base', | ||
securityLevel: 'loose', | ||
flowchart: { useMaxWidth: false, useMaxHeight: false } | ||
}); | ||
|
||
function renderMermaidDiagrams() { | ||
const diagrams = document.querySelectorAll('.language-mermaid'); | ||
diagrams.forEach((element, index) => { | ||
try { | ||
const graphDefinition = element.textContent; | ||
const graphId = `mermaid-diagram-${index}`; | ||
mermaid.render(graphId, graphDefinition) | ||
.then(({svg, bindFunctions}) => { | ||
element.innerHTML = svg; | ||
bindFunctions?.(element); | ||
}) | ||
.catch(error => { | ||
console.error(`Error rendering Mermaid diagram ${index}:`, error); | ||
element.innerHTML = `<p>Error rendering diagram: ${error.message}</p>`; | ||
}); | ||
} catch (error) { | ||
console.error(`Error processing Mermaid diagram ${index}:`, error); | ||
} | ||
}); | ||
} | ||
|
||
proc_htmx('.language-mermaid', () => { | ||
renderMermaidDiagrams() | ||
// setTimeout(renderMermaidDiagrams, 100); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
date: "2024-10-15" | ||
published: true | ||
slug: mermaid-charts | ||
tags: | ||
- python | ||
- fasthtml | ||
- javascript | ||
- nodejs | ||
time_to_read: 1 | ||
title: Mermaid charts! | ||
description: My site now has mermaid charts! Many thanks to Imtiaz Khan! | ||
--- | ||
|
||
MermaidJS is a JavaScript based diagramming and charting tool that renders Markdown-inspired text definitions to create and modify diagrams dynamically. I've been a fan of tools like it (which includes Graphviz) for years. | ||
|
||
Many thanks to [Imtiaz Khan](https://github.com/ImtiazKhanDS) for sharing with me how to implement it. | ||
|
||
```mermaid | ||
flowchart LR | ||
A[Idea] -->|Code| B(Deploy) | ||
B -->|Share| C[Enjoy] | ||
``` |