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

fix bug in level - the code increases the level by 1 but doesn't reduce it by 1 #42

Merged
merged 1 commit into from
May 26, 2022

Conversation

williamstein
Copy link
Contributor

@williamstein williamstein commented May 21, 2022

This bug might not be so evident if you're just using the html renderer of markdown-it. However, I use markdown-it to parse markdown and create an AST that is then manipulated using slatejs, and to some subtle use of caching is needed to make this performant. If you look at the similar plugin

https://github.com/iktakahiro/markdown-it-katex/blob/master/index.js

and also

https://github.com/markdown-it/markdown-it-container/blob/master/index.js

you'll see that the third argument that you're pushing onto the state change the level, and the code here doesn't change the level back. This means that the rest of the document gets parsed with the level being at least 1 too large. I think you should instead just pass 0 (as is done for math_inline), since there's only one token that gets emitted, rather than an open/close pair.

Thanks. I hope this is helpful to somobody. I wish github itself used a proper parser like this one for math in Markdown, since what they are currently doing isn't so good: https://news.ycombinator.com/item?id=31450597

…uce it by -1

This bug might not be so evident if you're just using the html renderer of markdown-it. However, I use markdown-it to parse markdown and create an AST that is then manipulated using slatejs, and to some subtle use of caching is needed to make this performant.    If you look at the similar plugin

https://github.com/iktakahiro/markdown-it-katex/blob/master/index.js

and also

https://github.com/markdown-it/markdown-it-container/blob/master/index.js

you'll see that the third argument that you're pushing onto the state change the level, and the code here doesn't change the level back.  This means that the rest of the document gets parsed with the level being at least 1 too large.    I think you should instead just pass 0 (as is done for math_inline), since there's only one token that gets emitted, rather than an open/close pair.


Thanks.  I hope this is helpful to somobody.   I wish github itself used a proper parser like this one for math in Markdown, since what they are currently doing isn't so good:  https://news.ycombinator.com/item?id=31450597
@williamstein williamstein changed the title fix bug in level - the incode incrases the level by 1 but doesn't red… fix bug in level - the code increases the level by 1 but doesn't reduce it by 1 May 21, 2022
@goessner goessner merged commit cdfe8e7 into goessner:master May 26, 2022
@goessner
Copy link
Owner

Thanks for detecting and fixing this bug.

zampino added a commit to nextjournal/markdown that referenced this pull request Nov 28, 2023
zampino added a commit to nextjournal/markdown that referenced this pull request Nov 28, 2023
The formula plugin we're using didn't restore the parser level after pushing their tokens, this messed up our criterium for adding nodes into the table of contents.

The bug was fixed upstream in v1.0.0 with goessner/markdown-it-texmath#42.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants