pythonpandocmultimarkdown

Replacing double backslash and brackets in Python


I am trying to write a script that could convert things like \\[ or \\] to $$ in order to convert a MultiMarkdown document to Pandoc markdown document that could display equations in HTML. I am using Python to find all instances of these characters using

 matchstring=r'\\['
 re.sub(matchstring,'$$',content)

However I run into the following error:

unexpected end of regular expression:line 15:matchstring=re.compile(r'\\[')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 190:
return _compile(pattern, flags)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 245:
raise error, v # invalid expression

most likely because of the last [ I have in there. Does anyone know a way to get around this?


Solution

  • pandoc -f markdown_mmd -t markdown
    

    will do this for you! (For pandoc >= 1.11)