Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing fails when disabling construct codeIndented (using micromark-extension-mdx-md) #1

Closed
4 tasks done
tumidi opened this issue Apr 13, 2023 · 3 comments
Closed
4 tasks done
Labels
💪 phase/solved Post is done

Comments

@tumidi
Copy link
Contributor

tumidi commented Apr 13, 2023

Initial checklist

Affected packages and versions

[email protected]

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)

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Apr 13, 2023
@wooorm
Copy link
Member

wooorm commented Apr 13, 2023

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”?

@tumidi
Copy link
Contributor Author

tumidi commented Apr 13, 2023

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.

@wooorm
Copy link
Member

wooorm commented Apr 14, 2023

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:

return factorySpace(
effects,
beforeSequenceClose,
types.linePrefix,
constants.tabSize
)

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.

tumidi added a commit to tumidi/micromark-extension-math that referenced this issue May 8, 2023
The problem occurs only when construct codeIndented is disabled, as is
the case with micromark-extension-mdx-md.
tumidi added a commit to tumidi/micromark-extension-math that referenced this issue May 8, 2023
@wooorm wooorm closed this as completed in 65eaae7 May 11, 2023
@wooorm wooorm added the 💪 phase/solved Post is done label May 11, 2023
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done
Development

No branches or pull requests

2 participants