Closed tumidi closed 1 year ago
Yep, probably the same bug.
To solve this, I think you could do something like this: https://github.com/micromark/micromark/blob/ce3593ae2f5ff549d9d4445193d950b9a9e95189/packages/micromark-core-commonmark/dev/lib/code-fenced.js#L37-L40.
That is:
a) calculate the indent before the start
b) when encountering a line ending, looking for a minimum of indent
and at most indent + TAB_SIZE - 1
before a “closing”?
Isn't micromark-extension-math
already doing something similar here?
In micromark-extension-gfm-table
I can't find something similar. Also the issue is different for both projects, gfm-table doesn't parse tables properly while here MDX parsing throws an error.
Unfortunately, I am not familiar enough with the internals of micromark to write a PR.
Ah, you are right that they both already do the first step: a). They both don’t do the second step though: b).
Fenced code parses arbitrary whitespace: https://github.com/micromark/micromark/blob/ce3593ae2f5ff549d9d4445193d950b9a9e95189/packages/micromark-core-commonmark/dev/lib/code-fenced.js#L209-L211.
Math (flow) does not: https://github.com/micromark/micromark-extension-math/blob/c44bc3a454774445d82a292f76711e52e52727a7/dev/lib/math-flow.js#L294-L299
Also the issue is different for both projects, gfm-table doesn't parse tables properly while here MDX parsing throws an error.
The results you see are different because tables and math/code are different.
Math runs to the end of the document if it isn’t closed.
So the closing tag for the div
you write is part of the math, it’s not a tag.
Tables work differently.
Initial checklist
Affected packages and versions
micromark-extension-math@2.1.0
Link to runnable example
https://codepen.io/tumidi/pen/rNqxMjm
Steps to reproduce
The CodePen shows that parsing display math fails when nested in two MDX elements and using indent of four spaces.
Might be related or similar to micromark/micromark-extension-gfm-table#10.
Expected behavior
Display math should be parsed correctly.
Actual behavior
Parsing fails with
Expected a closing tag for <div>
.Runtime
Other (please specify in steps to reproduce)
Package manager
Other (please specify in steps to reproduce)
OS
Linux
Build and bundle tools
Other (please specify in steps to reproduce)