Compare commits
No commits in common. "c6052a8a66372a77ac25bb362cef374b1d0841f9" and "7b045979a5921168347f1b534c2964313127c08b" have entirely different histories.
c6052a8a66
...
7b045979a5
1 changed files with 0 additions and 45 deletions
|
|
@ -33,49 +33,4 @@ else
|
||||||
marpteam/marp-cli --html --output /home/marp/output "${REL_SLIDES[@]}"
|
marpteam/marp-cli --html --output /home/marp/output "${REL_SLIDES[@]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Inject mermaid.js into any HTML that contains mermaid code blocks.
|
|
||||||
# Marp emits fenced mermaid blocks as <pre><code class="language-mermaid">.
|
|
||||||
# The script finds those elements, replaces them with <div class="mermaid">,
|
|
||||||
# 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 = """\
|
|
||||||
<script type="module">
|
|
||||||
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
|
|
||||||
document.querySelectorAll('code.language-mermaid').forEach(el => {
|
|
||||||
const div = document.createElement('div');
|
|
||||||
div.className = 'mermaid';
|
|
||||||
div.textContent = el.textContent;
|
|
||||||
el.closest('pre').replaceWith(div);
|
|
||||||
});
|
|
||||||
mermaid.initialize({ startOnLoad: true, theme: 'dark' });
|
|
||||||
</script>"""
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
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/"
|
echo "Done — slides in $OUTPUT_DIR/"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue