From 91a03428957545c2601340b06de7baf7d6889f62 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Thu, 3 Sep 2026 14:09:04 +0200 Subject: mdedit: add optional mermaid support --- internal/mdedit/res/app.js | 11 ++++++++++- internal/mdedit/res/index.html | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'internal/mdedit/res') diff --git a/internal/mdedit/res/app.js b/internal/mdedit/res/app.js index c934697..f022bae 100644 --- a/internal/mdedit/res/app.js +++ b/internal/mdedit/res/app.js @@ -29,9 +29,13 @@ const receiveHTML = body => { $("div#preview").innerHTML = body; $("span#status").innerText = "Saved"; + + if (window.mermaid) { + mermaid.run({ querySelector: "div#preview code.language-mermaid" }); + } }; - // whenever the changes, wait 3 seconds and then save all changes + // whenever the changes, wait 1 second and then save all changes let timeoutID = null; const onTextChange = event => { if (timeoutID !== null) { @@ -52,6 +56,11 @@ handleResponse(fetch("/data.md", opts), receiveHTML); }; + // initialize Mermaid on startup + if (window.mermaid) { + window.mermaid.initialize({ startOnLoad: false }); + } + // load Markdown and rendered HTML on startup handleResponse(fetch("/data.md"), body => { const editor = $("textarea#editor"); diff --git a/internal/mdedit/res/index.html b/internal/mdedit/res/index.html index 20aea13..601d41d 100644 --- a/internal/mdedit/res/index.html +++ b/internal/mdedit/res/index.html @@ -14,5 +14,6 @@
+ -- cgit v1.3.1