Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Created October 16, 2012 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joyrexus/3900110 to your computer and use it in GitHub Desktop.
Save joyrexus/3900110 to your computer and use it in GitHub Desktop.
Convert a markdown file to html
#!/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