Created
October 16, 2012 15:51
-
-
Save joyrexus/3900110 to your computer and use it in GitHub Desktop.
Convert a markdown file 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 python | |
''' | |
md2html - convert a markdown file to html | |
Dependencies: markdown module (pip install Markdown) | |
Usage: | |
md2html file.md > file.html | |
md2html file.md | browser | |
''' | |
import sys | |
from markdown import Markdown | |
# modify as appropriate | |
css_url = "http://joy.uchicago.edu/~jvoigt/static/css/simple.css" | |
md = Markdown(extensions=['toc'], | |
extension_configs={'title': "Summary", 'anchorlink': True}) | |
prefix = '''<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style>@import url({0});</style> | |
<body>'''.format(css_url) | |
suffix = '''</body></html>''' | |
text = open(sys.argv[1]).read() | |
html = md.convert(text) | |
print '\n'.join([prefix, html, suffix]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment