Skip to content

Commit

Permalink
Swap backticks and dollar signs in inline math markup
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Häggström committed Jan 25, 2021
1 parent 97c766d commit e603960
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions m2r2.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,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]+?(?=[\\<!\[:_*`~ ]|https?://| {2,}\n|$)")
# add colon, dollar and space as special text
text = re.compile(r"^[\s\S]+?(?=[\\<!\[:_*`~$ ]|https?://| {2,}\n|$)")
# __word__ or **word**
double_emphasis = re.compile(r"^([_*]){2}(?P<text>[\s\S]+?)\1{2}(?!\1)")
# _word_ or *word*
Expand Down
2 changes: 1 addition & 1 deletion tests/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ __content__

[A link to GitHub](http://github.com/)

This is `$E = mc^2$` inline math.
This is $`E = mc^2`$ inline math.
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
6 changes: 3 additions & 3 deletions tests/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,14 @@ def test_code_with_rest_link(self):
self.assertEqual(out, '\na ``code`` and `RefLink <a>`_ 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 <s>html</s>.'
Expand Down

0 comments on commit e603960

Please sign in to comment.