Created
November 9, 2012 17:14
-
-
Save adamlogic/4046924 to your computer and use it in GitHub Desktop.
Preview a Markdown file using Github's conversion and styling
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
#!/bin/bash | |
md_filename=$1 | |
html_filename=/tmp/ghpreview.html | |
url=https://api.github.com/markdown/raw | |
# Markdown to HTML | |
html=`curl --data-binary @$md_filename -H 'Content-Type:text/plain' $url` | |
# Grab Github's fingerprinted stylesheets | |
stylesheets=`curl https://github.com | grep 'https:.*github.*\.css'` | |
# Wrap it up | |
cat << EOF > $html_filename | |
<html> | |
<head> | |
$stylesheets | |
<style> | |
body { padding: 30px 0; } | |
#readme { width: 914px; margin: 0 auto; } | |
</style> | |
</head> | |
<body> | |
<div id="readme"> | |
<article class="markdown-body"> | |
$html | |
</article> | |
</div> | |
</body> | |
</html> | |
EOF | |
open $html_filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment