Skip to content

Commit ce6cef7

Browse files
committed
Fix handling of begin/end inside inline math
Fixes #30.
1 parent 49ea0ac commit ce6cef7

File tree

6 files changed

+25
-1
lines changed

6 files changed

+25
-1
lines changed

mdx_math.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ def extendMarkdown(self, md):
129129
pattern._add_preview = add_preview
130130
pattern._content_type = content_type
131131
# we should have higher priority than 'escape' which has 180
132-
md.inlinePatterns.register(pattern, 'math-%d' % i, 185)
132+
# also begin/end pattern should have lower priority than all others
133+
priority = 184 if i == 2 else 185
134+
md.inlinePatterns.register(pattern, 'math-%d' % i, priority)
133135
for i, pattern in enumerate(inlinemathpatterns):
134136
pattern._add_preview = add_preview
135137
pattern._content_type = content_type

test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def r(mkd_name, html_name, **config):
3333
test_standalone_gitlab_nested = r('standalone_gitlab_nested', 'standalone_gitlab_nested', use_gitlab_delimiters=True)
3434
test_begin_end = r('beginend', 'beginend')
3535
test_begin_end_preview = r('beginend', 'beginend_preview', add_preview=True)
36+
test_begin_end_inside_inline = r('beginend_inside_inline', 'beginend_inside_inline')
37+
test_begin_end_inside_standalone = r('beginend_inside_standalone', 'beginend_inside_standalone')
3638
test_inline_asciimath = r('inline_asciimath', 'inline_asciimath', use_asciimath=True)
3739

3840

test_data/beginend_inside_inline.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<p>
2+
<script type="math/tex"> T(v) = \begin{bmatrix}\alpha & \beta \\ \gamma & \delta \end{bmatrix} </script>
3+
</p>

test_data/beginend_inside_inline.mkd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
\( T(v) = \begin{bmatrix}\alpha & \beta \\ \gamma & \delta \end{bmatrix} \)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<p>
2+
<script type="math/tex; mode=display">
3+
s(x) = \begin{cases}
4+
1 & \text{if } x > 0\\
5+
0 & \text{if } x = 0\\
6+
-1 & \text{if } x < 0
7+
\end{cases}
8+
</script>
9+
</p>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
$$
2+
s(x) = \begin{cases}
3+
1 & \text{if } x > 0\\
4+
0 & \text{if } x = 0\\
5+
-1 & \text{if } x < 0
6+
\end{cases}
7+
$$

0 commit comments

Comments
 (0)