-
-
Save Jakobu5/2a2478935a63442ae7900f72525d3084 to your computer and use it in GitHub Desktop.
Bash script to render github flavoured markdown to HTML
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
#!/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