Created
July 15, 2024 07:18
-
-
Save wfrisch/40512ad311d2370ddfa5b158970d4636 to your computer and use it in GitHub Desktop.
md_render: live update for Markdown → HTML using Pandoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eo pipefail | |
markdown_file=$1 | |
[ -e "$markdown_file" ] || { | |
echo "usage: $0 MARKDOWN_FILE" | |
exit 1 | |
} | |
html_file="$(mktemp)" | |
echo "Output: $html_file" | |
function update() { | |
pandoc "$markdown_file" -f markdown -t html -s -o "$html_file" | |
} | |
function finish() { | |
rm "$html_file" | |
} | |
trap finish EXIT | |
update | |
$BROWSER "$html_file" | |
while ! inotifywait -e modify "$markdown_file"; do | |
update | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment