Created
December 23, 2012 14:22
-
-
Save fracek/4363632 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# Taken from: http://mybyteofcode.blogspot.it/2010/01/use-markdown-and-pygments-with-blogger.html | |
# All credits to the original author | |
# Modified to work with Marked.app | |
import sys | |
import os | |
import markdown | |
# Read the given file, convert it to html then return the html | |
def convert(file): | |
text = file.read() | |
html = markdown.markdown(text, ['codehilite']) | |
return html | |
def main(args=None): | |
# Read from the STDIN and print to STDOUT | |
if (len(args) is 1): | |
print convert(sys.stdin) | |
return | |
# Read from file and write to file | |
if (args is None or len(args) < 2): | |
print "Error, input file missing, usage:" | |
print args[0] + " <markdown formatted file>" | |
return | |
markdownInFile = os.path.abspath(args[1]) | |
(dir, file) = os.path.split(markdownInFile) | |
(file, ext) = os.path.splitext(file) | |
markdownOutFile = os.path.join(dir, ".".join([file,'html'])) | |
print "in: ", markdownInFile | |
with open(markdownInFile, 'r') as f: html = convert(f) | |
with open(markdownOutFile, 'w') as f: f.write(html) | |
print "out: ", markdownOutFile | |
if __name__ == '__main__': | |
main(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment