fix: robust mermaid injection with utf-8 encoding and error check
This commit is contained in:
parent
b5226fd74c
commit
c6052a8a66
1 changed files with 9 additions and 4 deletions
|
|
@ -52,12 +52,17 @@ document.querySelectorAll('code.language-mermaid').forEach(el => {
|
||||||
div.textContent = el.textContent;
|
div.textContent = el.textContent;
|
||||||
el.closest('pre').replaceWith(div);
|
el.closest('pre').replaceWith(div);
|
||||||
});
|
});
|
||||||
mermaid.initialize({ startOnLoad: false, theme: 'dark' });
|
mermaid.initialize({ startOnLoad: true, theme: 'dark' });
|
||||||
await mermaid.run();
|
|
||||||
</script>"""
|
</script>"""
|
||||||
|
|
||||||
content = open(path).read()
|
with open(path, encoding='utf-8') as f:
|
||||||
open(path, 'w').write(content.replace('</body>', snippet + '\n</body>', 1))
|
content = f.read()
|
||||||
|
new_content = content.replace('</body>', snippet + '\n</body>', 1)
|
||||||
|
if new_content == content:
|
||||||
|
print(f"Warning: </body> not found in {path}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
with open(path, 'w', encoding='utf-8') as f:
|
||||||
|
f.write(new_content)
|
||||||
PYEOF
|
PYEOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue