Browse Source

fixes for math-like things inside of code/pre

master
adam j hartz 2 weeks ago
parent
commit
13c0970f4c
2 changed files with 19 additions and 12 deletions
  1. +3
    -3
      catsoop/markdown_math.py
  2. +16
    -9
      catsoop/test/markdown_tests.py

+ 3
- 3
catsoop/markdown_math.py View File

@@ -64,11 +64,11 @@ class MathExtension(Extension):
203,
)
md.inlinePatterns.register(
RawHtmlInlineProcessor("displaymath", _DMATH_RE, md), "catsoop_dmath", 202
RawHtmlInlineProcessor("displaymath", _DMATH_RE, md), "catsoop_dmath", 183
)
md.inlinePatterns.register(
RawHtmlInlineProcessor("math", _MATH_RE, md), "catsoop_math", 201
RawHtmlInlineProcessor("math", _MATH_RE, md), "catsoop_math", 182
)
md.inlinePatterns.register(
SimpleTextInlineProcessor(_ESCAPED_DOLLAR_RE), "catsoop_emath", 200
SimpleTextInlineProcessor(_ESCAPED_DOLLAR_RE), "catsoop_emath", 181
)

+ 16
- 9
catsoop/test/markdown_tests.py View File

@@ -37,6 +37,13 @@ def dmath(x, env=""):
return "<displaymath%s>%s</displaymath>" % (env, x)


def _md(x):
out = language._md(x)
if out.startswith("<p>") and out.endswith("</p>"):
out = out[3:-4]
return out


class TestMarkdownMath(CATSOOPTest):
def setUp(self):
CATSOOPTest.setUp(self)
@@ -63,7 +70,7 @@ class TestMarkdownMath(CATSOOPTest):
]

for i, o in pairs:
self.assertEqual(language._md_format_string(self.ctx, i, False), o)
self.assertEqual(_md(i), o)

def test_display_math(self):
self.maxDiff = 10000
@@ -90,12 +97,12 @@ class TestMarkdownMath(CATSOOPTest):
]

for i, o in pairs:
self.assertEqual(language._md_format_string(self.ctx, i, False), o)
self.assertEqual(_md(i), o)

def test_dollar_signs(self):
def test_dollar_sign_escapes(self):
self.maxDiff = 10000

allmath = [r"$\$2 + \$3$", r"$x = \$200$"]
allmath = [r"$\$2 + \$3$", r"$x = \$200$", "$math$"]
identities = [
r"$x + $300",
r"some people might type 200$ + 400$ instead.",
@@ -107,16 +114,16 @@ class TestMarkdownMath(CATSOOPTest):
(r"\$x + y$ + $200", "$x + y$ + $200"),
(r"\$x + y\$", "$x + y$"),
(r"\$\$x + y\$\$", "$$x + y$$"),
(r"`$not math$`", r"<code>$not math$</code>"),
(r"```\n$not math$\n```", r"<code>\n$not math$\n</code>"),
]

for i in allmath:
self.assertEqual(
language._md_format_string(self.ctx, i, False), math(i[1:-1])
)
self.assertEqual(_md(i), math(i[1:-1]))
for i in identities:
self.assertEqual(language._md_format_string(self.ctx, i, False), i)
self.assertEqual(_md(i), i)
for i, o in pairs:
self.assertEqual(language._md_format_string(self.ctx, i, False), o)
self.assertEqual(_md(i), o)


if __name__ == "__main__":

Loading…
Cancel
Save