summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-12 19:39:32 +0000
committertv <tv@krebsco.de>2026-11-12 19:39:32 +0000
commitcb2199f0b6688ba69ba96f096c460bb167653b9e (patch)
tree4777a4ca3ada54dba285a062ad8590db5bbe9938
parente0deaa4f235619be47d9af35741357aedb0d7d7b (diff)
cgit-about-filter: render mermaid diagrams
-rw-r--r--pkgs/simple/cgit-about-filter/cgit-about-filter.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/pkgs/simple/cgit-about-filter/cgit-about-filter.lua b/pkgs/simple/cgit-about-filter/cgit-about-filter.lua
index cd20d54..f5a092a 100644
--- a/pkgs/simple/cgit-about-filter/cgit-about-filter.lua
+++ b/pkgs/simple/cgit-about-filter/cgit-about-filter.lua
@@ -185,6 +185,38 @@ local function layout_tables(output)
end))
end
+-- Render ```mermaid code blocks in the browser.
+local mermaid_script = [[
+<script type="module">
+ const codeBlocks = document.querySelectorAll("pre code.language-mermaid");
+ try {
+ const { default: mermaid } = await import("https://esm.run/mermaid@12.3.0");
+
+ mermaid.initialize({
+ startOnLoad: false,
+ theme: "default"
+ });
+
+ for (let i = 0; i < codeBlocks.length; i++) {
+ const codeBlock = codeBlocks[i];
+ const preBlock = codeBlock.parentElement;
+ const diagramText = codeBlock.textContent;
+ const id = "mermaid-diagram-" + i;
+
+ try {
+ const { svg } = await mermaid.render(id, diagramText);
+ preBlock.outerHTML = `<div class="mermaid-container">${svg}</div>`;
+ } catch (error) {
+ console.error("Mermaid rendering failed for block " + i, error);
+ codeBlock.textContent += "\n\n[Mermaid Render Error: See console for details]";
+ }
+ }
+ } catch (importError) {
+ console.error("Failed to dynamically load Mermaid module", importError);
+ }
+</script>
+]]
+
local buffer = ""
local should_render = true
local current_dir = "" -- Stores the directory prefix of the file being processed
@@ -261,6 +293,9 @@ function filter_close()
output = layout_tables(output)
end
emit(output)
+ if output:find('<code class="language-mermaid">', 1, true) then
+ emit(mermaid_script)
+ end
else
emit("<p>Error: Could not execute md2html.</p>")
end