Files
KNELPDF/scripts/knelpdf-mermaid
TSYS Group COO d3a4cbe7e9 v2: full document-production pipeline, no Node.js
texlive-full, pandoc, quarto, typst, hugo, mdbook+mermaid,
weasyprint, plantuml, graphviz/gnuplot, chromium+mermaid.js
rendering, eisvogel + reveal.js assets. Layered least-volatile
first for cheap pin bumps.
2026-09-07 16:45:47 -05:00

28 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# knelpdf-mermaid: render a mermaid diagram to PNG without Node.js.
# Uses bundled mermaid.min.js + headless chromium.
# usage: knelpdf-mermaid input.mmd output.png [theme] [width] [height]
set -euo pipefail
IN="${1:?usage: knelpdf-mermaid input.mmd output.png [theme] [width] [height]}"
OUT="${2:?usage: knelpdf-mermaid input.mmd output.png [theme] [width] [height]}"
THEME="${3:-default}"
W="${4:-1600}"; H="${5:-1200}"
case "$IN" in *.svg|*.png) echo "output-only extension in OUT, not IN" >&2; exit 2;; esac
WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
{
echo '<!doctype html><html><head><meta charset="utf-8">'
echo '<style>body{margin:0;background:white;font-family:sans-serif}</style>'
echo '</head><body><div class="mermaid">'
cat "$IN"
echo '</div>'
echo '<script src="file:///opt/mermaid/mermaid.min.js"></script>'
echo "<script>mermaid.initialize({startOnLoad:true,theme:\"${THEME}\"});</script>"
echo '</body></html>'
} > "$WORK/render.html"
chromium --headless=new --no-sandbox --disable-gpu \
--allow-file-access-from-files --hide-scrollbars \
--screenshot="$OUT" --window-size="${W},${H}" \
--virtual-time-budget=10000 "file://$WORK/render.html" 2>/dev/null
test -s "$OUT" && echo "wrote $OUT"