From 14f732d8ec42ca7c51a0eef7b2149aae71fd51d7 Mon Sep 17 00:00:00 2001 From: Stefan Krulj Date: Tue, 13 Mar 2012 01:42:29 +0100 Subject: [PATCH] Added a dirty fix for a silly issue --- mdx_math.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 mdx_math.py diff --git a/mdx_math.py b/mdx_math.py new file mode 100644 index 0000000..920b917 --- /dev/null +++ b/mdx_math.py @@ -0,0 +1,23 @@ +def makeExtension(configs=None) : + return MathExtension() + +from markdown.inlinepatterns import Pattern +import markdown, urllib + + +class MathPattern(Pattern): + def __init__(self,md): + Pattern.__init__(self,"!\[math\]\((.*?)\)",md) + def handleMatch(self, m): + texcode=m.group(2).replace("\x02klzzwxh:0000\x03","\\") #silly issue + el = markdown.etree.Element('img') + el.attrib["src"]="mimetex.cgi?"+\ + urllib.urlencode({'':texcode})[1:] + + el.attrib["alt"]=texcode + return el + +class MathExtension(markdown.Extension): + def extendMarkdown(self, md, md_globals): + md.inlinePatterns.add('math', MathPattern(md), '