Skip to content

Commit bf55030

Browse files
authored
Merge pull request #438 from saschabuehrle/fix/issue-370
fix: handle escaped dollar signs in inline math
2 parents 8d0cb75 + 7bd5709 commit bf55030

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/mistune/plugins/math.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
__all__ = ["math", "math_in_quote", "math_in_list"]
1111

1212
BLOCK_MATH_PATTERN = r"^ {0,3}\$\$[ \t]*\n(?P<math_text>[\s\S]+?)\n\$\$[ \t]*$"
13-
INLINE_MATH_PATTERN = r"\$(?!\s)(?P<math_text>.+?)(?!\s)\$"
13+
INLINE_MATH_PATTERN = r"\$(?!\s)(?P<math_text>(?:[^$\\]|\\.)+?)(?!\s)\$"
1414

1515

1616
def parse_block_math(block: "BlockParser", m: Match[str], state: "BlockState") -> int:

tests/fixtures/math.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,9 @@ with $a\neq b$ such that $f(a)=f(b)$.
5555
singleton set <span class="math">\(e_G\)</span>, because otherwise <span class="math">\(\exists a,b\in G\)</span>
5656
with <span class="math">\(a\neq b\)</span> such that <span class="math">\(f(a)=f(b)\)</span>.</p>
5757
````````````````````````````````
58+
59+
```````````````````````````````` example
60+
Escaped dollar sign in math: $x=\$$
61+
.
62+
<p>Escaped dollar sign in math: <span class="math">\(x=\$\)</span></p>
63+
````````````````````````````````

0 commit comments

Comments
 (0)