From 8fe5b9a7790236be60f6fbb86d1e6dfbb444060b Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 12 Nov 2026 20:10:14 +0000 Subject: cgit-about-filter: size mermaid diagrams like the page --- .../simple/cgit-about-filter/cgit-about-filter.lua | 28 ++++++++++++++++++++-- 1 file 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 = `
${svg}
`; + preBlock.outerHTML = `
${svg}
`; + // 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]"; -- cgit v1.3.1