👌 Improve parsing of nested amsmath#119
Conversation
the previous logic was problematic for amsmath blocks nested in other blocs (such as blockquotes) the parsing code now principally follows the logic in markdown_it/rules_block/fence.py, except that: (a) it allows for closing tag on same line as opening tag (b) it does not allow for opening tag without closing tag (i.e. no auto-closing)
|
cc @tovrstra |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #119 +/- ##
==========================================
- Coverage 92.80% 92.74% -0.07%
==========================================
Files 31 31
Lines 1835 1833 -2
==========================================
- Hits 1703 1700 -3
- Misses 132 133 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
| > \begin{matrix} | ||
| > -0.707 & 0.408 & 0.577 \\ | ||
| > -0.707 & -0.408 & -0.577 \\ | ||
| > -0. & -0.816 & 0.577 | ||
| > \end{matrix} | ||
| . | ||
| <blockquote> | ||
| <div class="math amsmath"> | ||
| \begin{matrix} | ||
| -0.707 & 0.408 & 0.577 \\ | ||
| -0.707 & -0.408 & -0.577 \\ | ||
| -0. & -0.816 & 0.577 | ||
| \end{matrix} | ||
| </div> | ||
| </blockquote> |
There was a problem hiding this comment.
If compatibility with Jupyter is of importance, then the HTML should be different here:
<blockquote>
<div class="math amsmath">
\begin{matrix}
> -0.707 & 0.408 & 0.577 \\
> -0.707 & -0.408 & -0.577 \\
> -0. & -0.816 & 0.577
> \end{matrix}
</div>
</blockquote>The markdown of this example is rendered in Jupyter Lab as:
Or should this be treated as a Jupyter issue? In Jupyter, one would write the Markdown as:
> \begin{matrix}
-0.707 & 0.408 & 0.577 \\
-0.707 & -0.408 & -0.577 \\
-0. & -0.816 & 0.577
\end{matrix}Given that Jupyter is so widespread, it seems prudent to also include this example in the tests.
There was a problem hiding this comment.
Or should this be treated as a Jupyter issue?
very much so, that is definitely very wrong 😅
I'm interested in "correct parsing", not mimicking bugs of other programs 😬
If compatibility with Jupyter is of importance
As you note, what you are actually talking about here is only the jupyter lab implementation,
which relies on things like markedjs and mathjax,
and is known to have a bunch of issues with math rendering (jupyterlab/jupyterlab#8645, jupyterlab/jupyterlab#14570, etc)
by contrast, try this in https://code.visualstudio.com/docs/datascience/jupyter-notebooks and you will get perfectly correct math 😄
There was a problem hiding this comment.
it seems prudent to also include this example in the tests
I've added it for completeness, but to be clear, this is just a case of block quote lazy continuation: https://spec.commonmark.org/0.30/#example-233
There was a problem hiding this comment.
I've opened a Jupyter issue: jupyterlab/jupyterlab#16755

the previous logic was problematic for amsmath blocks nested in other blocs (such as blockquotes)
the parsing code now principally follows the logic in
markdown_it/rules_block/fence.py(see also https://spec.commonmark.org/0.30/#fenced-code-blocks),
except that:
fixes #117