Created
May 9, 2014 03:10
-
-
Save autocorr/a9aade73b73d51739733 to your computer and use it in GitHub Desktop.
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 | |
# encoding: utf-8 | |
from os.path import splitext | |
from argparse import ArgumentParser | |
from markdown import markdown | |
from weasyprint import HTML | |
parser = ArgumentParser(description='Write a markdown file to PDF.') | |
parser.add_argument('filen', metavar='FILE', type=str, | |
help='Markdown filename') | |
args = parser.parse_args() | |
filen = args.filen | |
basen, ext = splitext(filen) | |
with open(filen, 'r') as md, open(basen + '.pdf', 'w') as outf: | |
html = markdown(md.read()) | |
HTML(string=html).write_pdf(basen + '.pdf') | |
print '-- Converting {0} to {1}.pdf'.format(filen, basen) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment