Skip to content

Instantly share code, notes, and snippets.

@wfrisch
Created July 15, 2024 07:18
Show Gist options
  • Save wfrisch/40512ad311d2370ddfa5b158970d4636 to your computer and use it in GitHub Desktop.
Save wfrisch/40512ad311d2370ddfa5b158970d4636 to your computer and use it in GitHub Desktop.
md_render: live update for Markdown → HTML using Pandoc
#!/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