Instantly share code, notes, and snippets.

Embed
What would you like to do?
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