Skip to content

Instantly share code, notes, and snippets.

@menacestudio
Created March 13, 2013 00:42
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 menacestudio/5148452 to your computer and use it in GitHub Desktop.
Save menacestudio/5148452 to your computer and use it in GitHub Desktop.
Converts a Markdown file to HTML.
# Author: Dennis Rongo
# Date: 03.12.2013
# Description: Thie script converts a Markdown (*.md) file to HTML within the same directory.
# This requires Pandoc (http://johnmacfarlane.net/pandoc/) to do the conversion.
import sys
import getopt
import subprocess
def process(arg):
file = arg;
print 'Converting markdown to HTML'
subprocess.call("pandoc -o {file}.html {file}.md".format(file=file))
# The argument takes in the name of the file without the extension.
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
except getopt.error, msg:
print msg
print "for help use --help"
sys.exit(2)
# process options
for o, a in opts:
if o in ("-h", "--help"):
print __doc__
sys.exit(0)
# process arguments
for arg in args:
process(arg)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment