Skip to content

Instantly share code, notes, and snippets.

@jaburns
Last active August 27, 2023 16:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jaburns/33d88f4aa99bb4ab6ad6 to your computer and use it in GitHub Desktop.
Save jaburns/33d88f4aa99bb4ab6ad6 to your computer and use it in GitHub Desktop.
Bash script to render github flavoured markdown to HTML
#!/usr/bin/env bash
data="$(
cat "$1" \
| sed 's/"/\\"/g' \
| sed ':a;N;$!ba;s/\n/\\n/g' \
)"
if [[ -z "$2" ]]; then
context=''
else
context=",\"context\":\"$2\""
fi
echo '<!DOCTYPE html>'
echo '<html><head><style>'
curl -s 'https://gist.githubusercontent.com/andyferra/2554919/raw/2e66cabdafe1c9a7f354aa2ebf5bc38265e638e5/github.css'
echo '</style></head><body>'
curl -s --data "{\"text\":\"$data\",\"mode\":\"gfm\"$context}" 'https://api.github.com/markdown'
echo '</body></html>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment