Skip to content

Instantly share code, notes, and snippets.

@adamlogic
Created November 9, 2012 17:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamlogic/4046924 to your computer and use it in GitHub Desktop.
Save adamlogic/4046924 to your computer and use it in GitHub Desktop.
Preview a Markdown file using Github's conversion and styling
#!/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