Skip to content

Instantly share code, notes, and snippets.

@Jakobu5
Forked from jaburns/gfm-render.sh
Created April 8, 2019 17:28
Show Gist options
  • Save Jakobu5/2a2478935a63442ae7900f72525d3084 to your computer and use it in GitHub Desktop.
Save Jakobu5/2a2478935a63442ae7900f72525d3084 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