Skip to content

Commit

Permalink
👌 IMPROVE: AMSmath defaut HTML tags (#27)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rowanc1 committed Sep 9, 2021
1 parent a0f7ffa commit c14b8fa
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 60 deletions.
5 changes: 1 addition & 4 deletions mdit_py_plugins/amsmath/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,4 @@ def amsmath_block(state: StateBlock, startLine: int, endLine: int, silent: bool)

def render_amsmath_block(self, tokens, idx, options, env):
token = tokens[idx]
return (
'<section class="amsmath">\n<eqn>\n'
f"{escapeHtml(token.content)}\n</eqn>\n</section>\n"
)
return f'<div class="math amsmath">\n{escapeHtml(token.content)}\n</div>\n'
118 changes: 62 additions & 56 deletions tests/fixtures/amsmath.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ equation environment:
a = 1
\end{equation}
.
<section class="amsmath">
<eqn>
<div class="math amsmath">
\begin{equation}
a = 1
\end{equation}
</eqn>
</section>
</div>
.

equation* environment:
Expand All @@ -19,13 +17,11 @@ equation* environment:
a = 1
\end{equation*}
.
<section class="amsmath">
<eqn>
<div class="math amsmath">
\begin{equation*}
a = 1
\end{equation*}
</eqn>
</section>
</div>
.

multline environment:
Expand All @@ -34,13 +30,11 @@ multline environment:
a = 1
\end{multline}
.
<section class="amsmath">
<eqn>
<div class="math amsmath">
\begin{multline}
a = 1
\end{multline}
</eqn>
</section>
</div>
.

multline* environment:
Expand All @@ -49,13 +43,11 @@ multline* environment:
a = 1
\end{multline*}
.
<section class="amsmath">
<eqn>
<div class="math amsmath">
\begin{multline*}
a = 1
\end{multline*}
</eqn>
</section>
</div>
.

gather environment:
Expand All @@ -64,13 +56,11 @@ gather environment:
a = 1
\end{gather}
.
<section class="amsmath">
<eqn>
<div class="math amsmath">
\begin{gather}
a = 1
\end{gather}
</eqn>
</section>
</div>
.

gather* environment:
Expand All @@ -79,13 +69,11 @@ gather* environment:
a = 1
\end{gather*}
.
<section class="amsmath">
<eqn>
<div class="math amsmath">
\begin{gather*}
a = 1
\end{gather*}
</eqn>
</section>
</div>
.

align environment:
Expand All @@ -94,13 +82,11 @@ align environment:
a = 1
\end{align}
.
<section class="amsmath">
<eqn>
<div class="math amsmath">
\begin{align}
a = 1
\end{align}
</eqn>
</section>
</div>
.

align* environment:
Expand All @@ -109,13 +95,11 @@ align* environment:
a = 1
\end{align*}
.
<section class="amsmath">
<eqn>
<div class="math amsmath">
\begin{align*}
a = 1
\end{align*}
</eqn>
</section>
</div>
.

alignat environment:
Expand All @@ -124,13 +108,11 @@ alignat environment:
a = 1
\end{alignat}
.
<section class="amsmath">
<eqn>
<div class="math amsmath">
\begin{alignat}
a = 1
\end{alignat}
</eqn>
</section>
</div>
.

alignat* environment:
Expand All @@ -139,13 +121,11 @@ alignat* environment:
a = 1
\end{alignat*}
.
<section class="amsmath">
<eqn>
<div class="math amsmath">
\begin{alignat*}
a = 1
\end{alignat*}
</eqn>
</section>
</div>
.

flalign environment:
Expand All @@ -154,13 +134,11 @@ flalign environment:
a = 1
\end{flalign}
.
<section class="amsmath">
<eqn>
<div class="math amsmath">
\begin{flalign}
a = 1
\end{flalign}
</eqn>
</section>
</div>
.

flalign* environment:
Expand All @@ -169,13 +147,11 @@ flalign* environment:
a = 1
\end{flalign*}
.
<section class="amsmath">
<eqn>
<div class="math amsmath">
\begin{flalign*}
a = 1
\end{flalign*}
</eqn>
</section>
</div>
.

equation environment, with before/after paragraphs:
Expand All @@ -187,13 +163,11 @@ a = 1
after
.
<p>before</p>
<section class="amsmath">
<eqn>
<div class="math amsmath">
\begin{equation}
a = 1
\end{equation}
</eqn>
</section>
</div>
<p>after</p>
.

Expand All @@ -205,13 +179,45 @@ equation environment, in list:
.
<ul>
<li>
<section class="amsmath">
<eqn>
<div class="math amsmath">
\begin{equation}
a = 1
\end{equation}
</eqn>
</section>
</div>
</li>
</ul>
.

`alignat` environment and HTML escaping
.
\begin{alignat}{3}
& d = \frac{1}{1 + 0.2316419x} \quad && a_1 = 0.31938153 \quad && a_2 = -0.356563782 \\
& a_3 = 1.781477937 \quad && a_4 = -1.821255978 \quad && a_5 = 1.330274429
\end{alignat}
.
<div class="math amsmath">
\begin{alignat}{3}
&amp; d = \frac{1}{1 + 0.2316419x} \quad &amp;&amp; a_1 = 0.31938153 \quad &amp;&amp; a_2 = -0.356563782 \\
&amp; a_3 = 1.781477937 \quad &amp;&amp; a_4 = -1.821255978 \quad &amp;&amp; a_5 = 1.330274429
\end{alignat}
</div>
.

`alignat*` environment and HTML escaping
.
\begin{alignat*}{3}
& m \quad && \text{módulo} \quad && m>0\\
& a \quad && \text{multiplicador} \quad && 0<a<m\\
& c \quad && \text{constante aditiva} \quad && 0\leq c<m\\
& x_0 \quad && \text{valor inicial} \quad && 0\leq x_0 <m
\end{alignat*}
.
<div class="math amsmath">
\begin{alignat*}{3}
&amp; m \quad &amp;&amp; \text{módulo} \quad &amp;&amp; m&gt;0\\
&amp; a \quad &amp;&amp; \text{multiplicador} \quad &amp;&amp; 0&lt;a&lt;m\\
&amp; c \quad &amp;&amp; \text{constante aditiva} \quad &amp;&amp; 0\leq c&lt;m\\
&amp; x_0 \quad &amp;&amp; \text{valor inicial} \quad &amp;&amp; 0\leq x_0 &lt;m
\end{alignat*}
</div>
.

0 comments on commit c14b8fa

Please sign in to comment.