Skip to content

Instantly share code, notes, and snippets.

@traverseda
Created January 28, 2015 11:31
Show Gist options
  • Save traverseda/9877cbf32ecc7fac38d7 to your computer and use it in GitHub Desktop.
Save traverseda/9877cbf32ecc7fac38d7 to your computer and use it in GitHub Desktop.
For converting datapacrats weird syntax into common markdown.
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