# Downloaded from https://github.com/mayoff/python-markdown-mathjax/issues/3 from __future__ import annotations import markdown from markdown.inlinepatterns import Pattern from markdown.postprocessors import Postprocessor class MathJaxPattern(Pattern): def __init__(self): super().__init__(r"(?", "") text = text.replace("", "") return text class MathJaxExtension(markdown.Extension): def extendMarkdown(self, md): # Needs to come before escape matching because \ is pretty important in LaTeX # inlinepatterns in Python-Markdown seem to top out at 200-ish? # https://github.com/Python-Markdown/markdown/blob/0b5e80efbb83f119e0e38801bf5b5b5864c67cd0/markdown/inlinepatterns.py#L53-L95 md.inlinePatterns.register(MathJaxPattern(), "mathjax", 1000) md.postprocessors.register(MathJaxPostprocessor(md), "mathjax", 0) def makeExtension(configs=None): return MathJaxExtension(configs)