diff options
Diffstat (limited to 'pkgs/simple/cgit-about-filter/cgit-about-filter.lua')
| -rw-r--r-- | pkgs/simple/cgit-about-filter/cgit-about-filter.lua | 35 |
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 |
