From c6052a8a66372a77ac25bb362cef374b1d0841f9 Mon Sep 17 00:00:00 2001 From: sjat Date: Sun, 10 May 2026 17:43:59 +0200 Subject: [PATCH] fix: robust mermaid injection with utf-8 encoding and error check --- build-slides.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/build-slides.sh b/build-slides.sh index 3bd3b60..47b4a4a 100755 --- a/build-slides.sh +++ b/build-slides.sh @@ -52,12 +52,17 @@ document.querySelectorAll('code.language-mermaid').forEach(el => { div.textContent = el.textContent; el.closest('pre').replaceWith(div); }); -mermaid.initialize({ startOnLoad: false, theme: 'dark' }); -await mermaid.run(); +mermaid.initialize({ startOnLoad: true, theme: 'dark' }); """ -content = open(path).read() -open(path, 'w').write(content.replace('', snippet + '\n', 1)) +with open(path, encoding='utf-8') as f: + content = f.read() +new_content = content.replace('', snippet + '\n', 1) +if new_content == content: + print(f"Warning: not found in {path}", file=sys.stderr) + sys.exit(1) +with open(path, 'w', encoding='utf-8') as f: + f.write(new_content) PYEOF }