mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 15:49:00 +02:00
feat(share): render inline mermaid (closes #5438)
This commit is contained in:
parent
7fdef3418a
commit
b833806ec7
@ -29,6 +29,14 @@ async function formatCodeBlocks() {
|
|||||||
await formatCodeBlocks($("#content"));
|
await formatCodeBlocks($("#content"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function setupTextNote() {
|
||||||
|
formatCodeBlocks();
|
||||||
|
applyMath();
|
||||||
|
|
||||||
|
const setupMermaid = (await import("./share/mermaid.js")).default;
|
||||||
|
setupMermaid();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch note with given ID from backend
|
* Fetch note with given ID from backend
|
||||||
*
|
*
|
||||||
@ -50,8 +58,7 @@ document.addEventListener(
|
|||||||
const noteType = determineNoteType();
|
const noteType = determineNoteType();
|
||||||
|
|
||||||
if (noteType === "text") {
|
if (noteType === "text") {
|
||||||
formatCodeBlocks();
|
setupTextNote();
|
||||||
applyMath();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleMenuButton = document.getElementById("toggleMenuButton");
|
const toggleMenuButton = document.getElementById("toggleMenuButton");
|
||||||
|
17
apps/client/src/share/mermaid.ts
Normal file
17
apps/client/src/share/mermaid.ts
Normal 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();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user