Skip to content

Commit c14b8fa

Browse files
authored
👌 IMPROVE: AMSmath defaut HTML tags (#27)
Changed the default rendering to: `<div class="math amsmath">{content}</div>` This will be inline with https://github.com/executablebooks/markdown-it-amsmath Added some tests to cover more realistic AMS math scenarios.
1 parent a0f7ffa commit c14b8fa

File tree

2 files changed

+63
-60
lines changed

2 files changed

+63
-60
lines changed

mdit_py_plugins/amsmath/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,4 @@ def amsmath_block(state: StateBlock, startLine: int, endLine: int, silent: bool)
115115

116116
def render_amsmath_block(self, tokens, idx, options, env):
117117
token = tokens[idx]
118-
return (
119-
'<section class="amsmath">\n<eqn>\n'
120-
f"{escapeHtml(token.content)}\n</eqn>\n</section>\n"
121-
)
118+
return f'<div class="math amsmath">\n{escapeHtml(token.content)}\n</div>\n'

tests/fixtures/amsmath.md

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ equation environment:
44
a = 1
55
\end{equation}
66
.
7-
<section class="amsmath">
8-
<eqn>
7+
<div class="math amsmath">
98
\begin{equation}
109
a = 1
1110
\end{equation}
12-
</eqn>
13-
</section>
11+
</div>
1412
.
1513

1614
equation* environment:
@@ -19,13 +17,11 @@ equation* environment:
1917
a = 1
2018
\end{equation*}
2119
.
22-
<section class="amsmath">
23-
<eqn>
20+
<div class="math amsmath">
2421
\begin{equation*}
2522
a = 1
2623
\end{equation*}
27-
</eqn>
28-
</section>
24+
</div>
2925
.
3026

3127
multline environment:
@@ -34,13 +30,11 @@ multline environment:
3430
a = 1
3531
\end{multline}
3632
.
37-
<section class="amsmath">
38-
<eqn>
33+
<div class="math amsmath">
3934
\begin{multline}
4035
a = 1
4136
\end{multline}
42-
</eqn>
43-
</section>
37+
</div>
4438
.
4539

4640
multline* environment:
@@ -49,13 +43,11 @@ multline* environment:
4943
a = 1
5044
\end{multline*}
5145
.
52-
<section class="amsmath">
53-
<eqn>
46+
<div class="math amsmath">
5447
\begin{multline*}
5548
a = 1
5649
\end{multline*}
57-
</eqn>
58-
</section>
50+
</div>
5951
.
6052

6153
gather environment:
@@ -64,13 +56,11 @@ gather environment:
6456
a = 1
6557
\end{gather}
6658
.
67-
<section class="amsmath">
68-
<eqn>
59+
<div class="math amsmath">
6960
\begin{gather}
7061
a = 1
7162
\end{gather}
72-
</eqn>
73-
</section>
63+
</div>
7464
.
7565

7666
gather* environment:
@@ -79,13 +69,11 @@ gather* environment:
7969
a = 1
8070
\end{gather*}
8171
.
82-
<section class="amsmath">
83-
<eqn>
72+
<div class="math amsmath">
8473
\begin{gather*}
8574
a = 1
8675
\end{gather*}
87-
</eqn>
88-
</section>
76+
</div>
8977
.
9078

9179
align environment:
@@ -94,13 +82,11 @@ align environment:
9482
a = 1
9583
\end{align}
9684
.
97-
<section class="amsmath">
98-
<eqn>
85+
<div class="math amsmath">
9986
\begin{align}
10087
a = 1
10188
\end{align}
102-
</eqn>
103-
</section>
89+
</div>
10490
.
10591

10692
align* environment:
@@ -109,13 +95,11 @@ align* environment:
10995
a = 1
11096
\end{align*}
11197
.
112-
<section class="amsmath">
113-
<eqn>
98+
<div class="math amsmath">
11499
\begin{align*}
115100
a = 1
116101
\end{align*}
117-
</eqn>
118-
</section>
102+
</div>
119103
.
120104

121105
alignat environment:
@@ -124,13 +108,11 @@ alignat environment:
124108
a = 1
125109
\end{alignat}
126110
.
127-
<section class="amsmath">
128-
<eqn>
111+
<div class="math amsmath">
129112
\begin{alignat}
130113
a = 1
131114
\end{alignat}
132-
</eqn>
133-
</section>
115+
</div>
134116
.
135117

136118
alignat* environment:
@@ -139,13 +121,11 @@ alignat* environment:
139121
a = 1
140122
\end{alignat*}
141123
.
142-
<section class="amsmath">
143-
<eqn>
124+
<div class="math amsmath">
144125
\begin{alignat*}
145126
a = 1
146127
\end{alignat*}
147-
</eqn>
148-
</section>
128+
</div>
149129
.
150130

151131
flalign environment:
@@ -154,13 +134,11 @@ flalign environment:
154134
a = 1
155135
\end{flalign}
156136
.
157-
<section class="amsmath">
158-
<eqn>
137+
<div class="math amsmath">
159138
\begin{flalign}
160139
a = 1
161140
\end{flalign}
162-
</eqn>
163-
</section>
141+
</div>
164142
.
165143

166144
flalign* environment:
@@ -169,13 +147,11 @@ flalign* environment:
169147
a = 1
170148
\end{flalign*}
171149
.
172-
<section class="amsmath">
173-
<eqn>
150+
<div class="math amsmath">
174151
\begin{flalign*}
175152
a = 1
176153
\end{flalign*}
177-
</eqn>
178-
</section>
154+
</div>
179155
.
180156

181157
equation environment, with before/after paragraphs:
@@ -187,13 +163,11 @@ a = 1
187163
after
188164
.
189165
<p>before</p>
190-
<section class="amsmath">
191-
<eqn>
166+
<div class="math amsmath">
192167
\begin{equation}
193168
a = 1
194169
\end{equation}
195-
</eqn>
196-
</section>
170+
</div>
197171
<p>after</p>
198172
.
199173

@@ -205,13 +179,45 @@ equation environment, in list:
205179
.
206180
<ul>
207181
<li>
208-
<section class="amsmath">
209-
<eqn>
182+
<div class="math amsmath">
210183
\begin{equation}
211184
a = 1
212185
\end{equation}
213-
</eqn>
214-
</section>
186+
</div>
215187
</li>
216188
</ul>
217189
.
190+
191+
`alignat` environment and HTML escaping
192+
.
193+
\begin{alignat}{3}
194+
& d = \frac{1}{1 + 0.2316419x} \quad && a_1 = 0.31938153 \quad && a_2 = -0.356563782 \\
195+
& a_3 = 1.781477937 \quad && a_4 = -1.821255978 \quad && a_5 = 1.330274429
196+
\end{alignat}
197+
.
198+
<div class="math amsmath">
199+
\begin{alignat}{3}
200+
&amp; d = \frac{1}{1 + 0.2316419x} \quad &amp;&amp; a_1 = 0.31938153 \quad &amp;&amp; a_2 = -0.356563782 \\
201+
&amp; a_3 = 1.781477937 \quad &amp;&amp; a_4 = -1.821255978 \quad &amp;&amp; a_5 = 1.330274429
202+
\end{alignat}
203+
</div>
204+
.
205+
206+
`alignat*` environment and HTML escaping
207+
.
208+
\begin{alignat*}{3}
209+
& m \quad && \text{módulo} \quad && m>0\\
210+
& a \quad && \text{multiplicador} \quad && 0<a<m\\
211+
& c \quad && \text{constante aditiva} \quad && 0\leq c<m\\
212+
& x_0 \quad && \text{valor inicial} \quad && 0\leq x_0 <m
213+
\end{alignat*}
214+
.
215+
<div class="math amsmath">
216+
\begin{alignat*}{3}
217+
&amp; m \quad &amp;&amp; \text{módulo} \quad &amp;&amp; m&gt;0\\
218+
&amp; a \quad &amp;&amp; \text{multiplicador} \quad &amp;&amp; 0&lt;a&lt;m\\
219+
&amp; c \quad &amp;&amp; \text{constante aditiva} \quad &amp;&amp; 0\leq c&lt;m\\
220+
&amp; x_0 \quad &amp;&amp; \text{valor inicial} \quad &amp;&amp; 0\leq x_0 &lt;m
221+
\end{alignat*}
222+
</div>
223+
.

0 commit comments

Comments
 (0)