Browse Source

make catsoop work with current markdown

resolves issue #21
adam j hartz 2 months ago
parent
commit
9a4876bc0f
2 changed files with 16 additions and 16 deletions
  1. 15
    15
      catsoop/markdown_math.py
  2. 1
    1
      requirements.txt

+ 15
- 15
catsoop/markdown_math.py View File

@@ -16,39 +16,39 @@
16 16
 """CAT-SOOP Math Mode Extension for PyMarkdown"""
17 17
 
18 18
 from markdown.extensions import Extension
19
-from markdown.inlinepatterns import HtmlPattern, SimpleTextPattern
19
+from markdown.inlinepatterns import HtmlInlineProcessor, SimpleTextInlineProcessor
20 20
 
21 21
 _nodoc = {
22 22
     "Extension",
23
-    "HtmlPattern",
24
-    "SimpleTextPattern",
23
+    "HtmlInlineProcessor",
24
+    "SimpleTextInlineProcessor",
25 25
     "absolute_import",
26 26
     "unicode_literals",
27 27
 }
28 28
 
29
-_MATH_RE = r"(^|[^\\])(\$)((?:\\\$|[^$])*)\3"
30
-_DMATH_RE = r"(^|[^\\])(\$\$)(.*?)\3"
29
+_MATH_RE = r"(^|[^\\])(\$)((?:\\\$|[^$])*)\2"
30
+_DMATH_RE = r"(^|[^\\])(\$\$)(.*?)\2"
31 31
 _ESCAPED_DOLLAR_RE = r"\\(\$)"
32 32
 
33 33
 
34
-class RawHtmlPattern(HtmlPattern):
35
-    """A subclass of `catsoop.thirdparty.markdown.inlinepattern.HtmlPattern`
34
+class RawHtmlInlineProcessor(HtmlInlineProcessor):
35
+    """A subclass of `catsoop.thirdparty.markdown.inlinepattern.HtmlInlineProcessor`
36 36
     used to store raw inline html and return a placeholder."""
37 37
 
38 38
     def __init__(self, endtag, *args, **kwargs):
39 39
         self._hz_tag = endtag
40
-        HtmlPattern.__init__(self, *args, **kwargs)
40
+        HtmlInlineProcessor.__init__(self, *args, **kwargs)
41 41
 
42
-    def handleMatch(self, m):
43
-        pre = m.group(2)
44
-        body = self.unescape(m.group(4))
42
+    def handleMatch(self, m, data):
43
+        pre = m.group(1)
44
+        body = self.unescape(m.group(3))
45 45
         rawhtml = "%(pre)s<%(tag)s>%(body)s</%(tag)s>" % {
46 46
             "tag": self._hz_tag,
47 47
             "body": body,
48 48
             "pre": pre,
49 49
         }
50 50
         place_holder = self.markdown.htmlStash.store(rawhtml)
51
-        return place_holder
51
+        return place_holder, m.start(0), m.end(0)
52 52
 
53 53
 
54 54
 class MathExtension(Extension):
@@ -57,7 +57,7 @@ class MathExtension(Extension):
57 57
     def extendMarkdown(self, md, md_globals):
58 58
         """ Modify inline patterns. """
59 59
         md.inlinePatterns.add(
60
-            "dmath", RawHtmlPattern("displaymath", _DMATH_RE, md), "<entity"
60
+            "dmath", RawHtmlInlineProcessor("displaymath", _DMATH_RE, md), "<entity"
61 61
         )
62
-        md.inlinePatterns.add("math", RawHtmlPattern("math", _MATH_RE, md), ">dmath")
63
-        md.inlinePatterns.add("emath", SimpleTextPattern(_ESCAPED_DOLLAR_RE), ">math")
62
+        md.inlinePatterns.add("math", RawHtmlInlineProcessor("math", _MATH_RE, md), ">dmath")
63
+        md.inlinePatterns.add("emath", SimpleTextInlineProcessor(_ESCAPED_DOLLAR_RE), ">math")

+ 1
- 1
requirements.txt View File

@@ -3,7 +3,7 @@ cheroot
3 3
 cryptography
4 4
 filelock
5 5
 python-jose
6
-markdown>2,<3
6
+markdown>=3
7 7
 mpmath
8 8
 ply
9 9
 uwsgi

Loading…
Cancel
Save