#!/usr/bin/env python
# The world's worst code, ever, all in one place! \o/ \o/ \o/
import markdown2
import sys
import os

if len(sys.argv) > 1:
  file = sys.argv[1]
  md = open(file, 'r').read()
  htmlFile = os.path.splitext(file)[0] + ".html"
  html = open(htmlFile, 'w')
  html.write(markdown2.markdown(md))
  html.close()
  os.system("xhtml2pdf %s" % htmlFile)
  os.remove(htmlFile)

  print("PDF Conversion successful")
else:
  print("Usage: md2pdf markdown_file.md")
