Created
January 28, 2015 11:31
-
-
Save traverseda/9877cbf32ecc7fac38d7 to your computer and use it in GitHub Desktop.
For converting datapacrats weird syntax into common markdown.
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 re,sys,tempfile | |
import markdown2 | |
def emphasis(matchobject): | |
return("*{}*".format(matchobject.group(1))) | |
regexes=[ | |
#Close enough | |
('/(?!/)(?<!//)(.+?)/',emphasis) | |
] | |
doc= open(sys.argv[1], "r") | |
output = tempfile.TemporaryFile(mode="w+") | |
for count,line in enumerate(doc): | |
for regex, replacer in regexes: | |
line = re.sub(regex,replacer,line) | |
output.write(line) | |
output.seek(0) | |
content = markdown2.markdown(output.read()) | |
output = tempfile.TemporaryFile(mode="w+") | |
output.write(content) | |
output.seek(0) | |
print(output.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment