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;
|
||||
el.closest('pre').replaceWith(div);
|
||||
});
|
||||
mermaid.initialize({ startOnLoad: false, theme: 'dark' });
|
||||
await mermaid.run();
|
||||
mermaid.initialize({ startOnLoad: true, theme: 'dark' });
|
||||
</script>"""
|
||||
|
||||
content = open(path).read()
|
||||
open(path, 'w').write(content.replace('</body>', snippet + '\n</body>', 1))
|
||||
with open(path, encoding='utf-8') as f:
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue