diff options
| author | tv <tv@krebsco.de> | 2026-11-12 20:10:14 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-12 21:25:42 +0100 |
| commit | 8fe5b9a7790236be60f6fbb86d1e6dfbb444060b (patch) | |
| tree | 4b95aabed65932fc16813435d783d18d4ffdb860 /pkgs/simple/cgit-about-filter | |
| parent | 3e4bbd1d93bd368e0274d7c1d178e3b8d16b3f0d (diff) | |
cgit-about-filter: size mermaid diagrams like the page
Diffstat (limited to 'pkgs/simple/cgit-about-filter')
| -rw-r--r-- | pkgs/simple/cgit-about-filter/cgit-about-filter.lua | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/pkgs/simple/cgit-about-filter/cgit-about-filter.lua b/pkgs/simple/cgit-about-filter/cgit-about-filter.lua index f5a092a..28a493e 100644 --- a/pkgs/simple/cgit-about-filter/cgit-about-filter.lua +++ b/pkgs/simple/cgit-about-filter/cgit-about-filter.lua @@ -192,9 +192,27 @@ local mermaid_script = [[ try { const { default: mermaid } = await import("https://esm.run/mermaid@12.3.0"); + // Text as large as the page's, diagrams at their natural size. + const style = getComputedStyle(document.querySelector("div#summary") || document.body); + const fontSize = parseFloat(style.fontSize); mermaid.initialize({ startOnLoad: false, - theme: "default" + theme: "default", + fontFamily: style.fontFamily, + fontSize, + themeVariables: { + fontFamily: style.fontFamily, + fontSize: style.fontSize, + edgeLabelBackground: "#ffffff" + }, + flowchart: { + wrappingWidth: 300 + }, + sequence: { + actorFontSize: fontSize, + messageFontSize: fontSize, + noteFontSize: fontSize + } }); for (let i = 0; i < codeBlocks.length; i++) { @@ -205,7 +223,13 @@ local mermaid_script = [[ try { const { svg } = await mermaid.render(id, diagramText); - preBlock.outerHTML = `<div class="mermaid-container">${svg}</div>`; + preBlock.outerHTML = `<div class="mermaid-container" style="overflow-x: auto; margin: 1em 0;">${svg}</div>`; + // Mermaid shrinks wide diagrams to fit; scroll them instead. + const rendered = document.getElementById(id); + const box = rendered.viewBox.baseVal; + rendered.style.maxWidth = "none"; + rendered.setAttribute("width", box.width); + rendered.setAttribute("height", box.height); } catch (error) { console.error("Mermaid rendering failed for block " + i, error); codeBlock.textContent += "\n\n[Mermaid Render Error: See console for details]"; |
