Skip to content

Instantly share code, notes, and snippets.

@jellea
Created August 30, 2012 11:24
Show Gist options
  • Save jellea/3526641 to your computer and use it in GitHub Desktop.
Save jellea/3526641 to your computer and use it in GitHub Desktop.
Markdown2HTML
import os, markdown2, fnmatch # dependant on python-markdown2
tmp = open("template.html","r").read() # HTML document with {{content}} tag
def locate(pattern, root=os.curdir):
'''Locate all files matching supplied filename pattern in and below
supplied root directory.'''
for path, dirs, files in os.walk(os.path.abspath(root)):
for filename in fnmatch.filter(files, pattern):
yield os.path.join(path, filename)
for files in locate("*.markdown"):
print files
try:
markdownoutput = markdown2.markdown(open(files).read())
output = tmp.replace("{{content}}", markdownoutput.encode('utf-8'))
f = open(files.replace(".markdown",".html"),"w")
f.write(output)
except (SyntaxError):
print files, "\tBADLY FORMED!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment