Created
August 30, 2012 11:24
-
-
Save jellea/3526641 to your computer and use it in GitHub Desktop.
Markdown2HTML
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
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