feat(share): render inline mermaid (closes #5438)

This commit is contained in:
Elian Doran 2025-07-22 20:05:29 +03:00
parent 7fdef3418a
commit b833806ec7
No known key found for this signature in database
2 changed files with 26 additions and 2 deletions

View File

@ -29,6 +29,14 @@ async function formatCodeBlocks() {
await formatCodeBlocks($("#content"));
}
async function setupTextNote() {
formatCodeBlocks();
applyMath();
const setupMermaid = (await import("./share/mermaid.js")).default;
setupMermaid();
}
/**
* Fetch note with given ID from backend
*
@ -50,8 +58,7 @@ document.addEventListener(
const noteType = determineNoteType();
if (noteType === "text") {
formatCodeBlocks();
applyMath();
setupTextNote();
}
const toggleMenuButton = document.getElementById("toggleMenuButton");

View File

@ -0,0 +1,17 @@
import mermaid from "mermaid";
export default function setupMermaid() {
for (const codeBlock of document.querySelectorAll("#content pre code.language-mermaid")) {
const parentPre = codeBlock.parentElement;
if (!parentPre) {
continue;
}
const mermaidDiv = document.createElement("div");
mermaidDiv.classList.add("mermaid");
mermaidDiv.innerHTML = codeBlock.innerHTML;
parentPre.replaceWith(mermaidDiv);
}
mermaid.init();
}