Files
edx-platform/simplewiki/mdx_mathjax.py
Piotr Mitros 646fc0b18f simplewiki
2011-12-30 00:09:16 -05:00

22 lines
665 B
Python

# Source: https://github.com/mayoff/python-markdown-mathjax
import markdown
class MathJaxPattern(markdown.inlinepatterns.Pattern):
def __init__(self):
markdown.inlinepatterns.Pattern.__init__(self, r'(?<!\\)(\$\$?)(.+?)\2')
def handleMatch(self, m):
return markdown.AtomicString(m.group(2) + m.group(3) + m.group(2))
class MathJaxExtension(markdown.Extension):
def extendMarkdown(self, md, md_globals):
# Needs to come before escape matching because \ is pretty important in LaTeX
md.inlinePatterns.add('mathjax', MathJaxPattern(), '<escape')
def makeExtension(configs=None):
return MathJaxExtension(configs)