diff --git a/m2r2.py b/m2r2.py index e78d969..4e6c17b 100644 --- a/m2r2.py +++ b/m2r2.py @@ -119,10 +119,10 @@ class RestInlineGrammar(mistune.InlineGrammar): ) rest_role = re.compile(r":.*?:`.*?`|`[^`]+`:.*?:") rest_link = re.compile(r"`[^`]*?`_") - inline_math = re.compile(r"`\$(.*?)\$`") + inline_math = re.compile(r"\$`(.*?)`\$") eol_literal_marker = re.compile(r"(\s+)?::\s*$") - # add colon and space as special text - text = re.compile(r"^[\s\S]+?(?=[\\[\s\S]+?)\1{2}(?!\1)") # _word_ or *word* diff --git a/tests/test.md b/tests/test.md index 648279d..3b66b50 100644 --- a/tests/test.md +++ b/tests/test.md @@ -8,11 +8,11 @@ __content__ [A link to GitHub](http://github.com/) -This is `$E = mc^2$` inline math. +This is $`E = mc^2`$ inline math. -This first math `$x^2$` in this line will render. This one `$z^3$` should as well. +This first math $`x^2`$ in this line will render. This one $`z^3`$ should as well. -Also within parentheses (`$x^2$`) and (`$z^3$`). +Also within parentheses ($`x^2`$) and ($`z^3`$). ```mermaid graph TD; diff --git a/tests/test_cli.py b/tests/test_cli.py index e55826f..320758d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -136,5 +136,5 @@ def test_disable_inline_math(self): sys.argv = [sys.argv[0], '--disable-inline-math', '--dry-run', test_md] with patch(_builtin + '.print') as m: main() - self.assertIn('``$E = mc^2$``', m.call_args[0][0]) + self.assertIn(r'$\ ``E = mc^2``\ $', m.call_args[0][0]) self.assertNotIn(':math:', m.call_args[0][0]) diff --git a/tests/test_renderer.py b/tests/test_renderer.py index 8e86792..26a952a 100644 --- a/tests/test_renderer.py +++ b/tests/test_renderer.py @@ -264,14 +264,14 @@ def test_code_with_rest_link(self): self.assertEqual(out, '\na ``code`` and `RefLink `_ here.\n') def test_inline_math(self): - src = 'this is `$E = mc^2$` inline math.' + src = 'this is $`E = mc^2`$ inline math.' out = self.conv(src) self.assertEqual(out, '\nthis is :math:`E = mc^2` inline math.\n') def test_disable_inline_math(self): - src = 'this is `$E = mc^2$` inline math.' + src = 'this is $`E = mc^2`$ inline math.' out = self.conv(src, disable_inline_math=True) - self.assertEqual(out, '\nthis is ``$E = mc^2$`` inline math.\n') + self.assertEqual(out, '\nthis is $\\ ``E = mc^2``\\ $ inline math.\n') def test_inline_html(self): src = 'this is html.'