From b5226fd74c18d09e35440bc6ca3575e51c321c7a Mon Sep 17 00:00:00 2001 From: sjat Date: Sun, 10 May 2026 17:42:35 +0200 Subject: [PATCH] feat: inject mermaid.js into slides that use it --- build-slides.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/build-slides.sh b/build-slides.sh index 41a05ac..3bd3b60 100755 --- a/build-slides.sh +++ b/build-slides.sh @@ -33,4 +33,44 @@ else marpteam/marp-cli --html --output /home/marp/output "${REL_SLIDES[@]}" fi +# Inject mermaid.js into any HTML that contains mermaid code blocks. +# Marp emits fenced mermaid blocks as
.
+# The script finds those elements, replaces them with 
, +# then loads and runs mermaid.js from CDN. +inject_mermaid() { + local html_file="$1" + python3 - "$html_file" << 'PYEOF' +import sys + +path = sys.argv[1] +snippet = """\ +""" + +content = open(path).read() +open(path, 'w').write(content.replace('', snippet + '\n', 1)) +PYEOF +} + +if command -v python3 &>/dev/null; then + for html_file in "$OUTPUT_DIR"/*.html; do + [ -f "$html_file" ] || continue + if grep -q 'class="language-mermaid"' "$html_file"; then + inject_mermaid "$html_file" + echo " Injected mermaid.js into $(basename "$html_file")" + fi + done +else + echo "Warning: python3 not found — skipping mermaid injection" +fi + echo "Done — slides in $OUTPUT_DIR/"