Skip to content

Commit 4d82af1

Browse files
authored
fix bug in level - the incode incrases the level by 1 but doesn't reduce 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
1 parent b08ddd3 commit 4d82af1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

texmath.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ texmath.block = (rule) =>
9494
if (parentType === 'blockquote') // remove all leading '>' inside multiline formula
9595
match[1] = match[1].replace(/(\n*?^(?:\s*>)+)/gm,'');
9696
// begin token
97-
let token = state.push(rule.name, 'math', 1); // 'math_block'
97+
let token = state.push(rule.name, 'math', 0); // 'math_block'
9898
token.block = true;
9999
token.tag = rule.tag;
100100
token.markup = '';

0 commit comments

Comments
 (0)