Remark: Remark mis-parses nested code blocks in list items

Created on 13 Dec 2017  ·  10Comments  ·  Source: remarkjs/remark

When code blocks are nested within list items with CommonMark's 7-space (3+4=7) indentation rule, remark fails to recognize the code blocks and treats them as nested paragraphs in the list item rather than <code>.

Steps to reproduce

This CommonMark playground example shows how CommonMark handles nested code blocks within list items with various indentations.

TL;DR: CommonMark recognizes 7-space indents as code blocks in single-digit ordered list items.

Expected behaviour

The parsed remark AST should be same as the result in the CommonMark playground.

Actual behaviour

The remark parser fails to recognize CommonMark's (3+4=7) indentation for code blocks within list items and treats them as nested paragraphs in the list item rather than <code>.

This Prettier playground example shows how remark stumbles on the 7-space indentation.

_(See https://github.com/prettier/prettier/issues/3459 for the initial discussion and additional examples.)_

remark-parse ⛵️ statureleased 🐛 typbug 🧑 semvemajor

Most helpful comment

Heya, just wanted to give an update about micromark, it’s sort-of a new motor that we’ll soon use in remark to parse markdown. It’s not yet 100% ready but will be relatively soon. The good news is, it fixes this issue! (P.S. see this twitter thread for some more info!)

All 10 comments

Thanks for the issue and sorry for the late reply!

That’s definitely a bug. The code for lists is pretty big and bug prone. It could use a rewrite!

@wooorm @infotexture any fixes for this issue? I believe this is unresolved: This markdown:
## Then numbered lists:

1. First install the dependencies:
\`$ npm install\`
1. Bar **bold**
1. Fruits
   1. Apple
   1. Oranges
   1. Lemons
      1. Roman
      1. Greek  
Muiltiline  
With \`code\`.
      1. Spanish

Gets rendered as:

Then numbered lists:

  1. First install the dependencies:
    $ npm install
  2. Bar bold
  3. Fruits
    1. Apple
    2. Oranges
    3. Lemons 1. Roman 1. Greek
      Muiltiline
      With code. 1. Spanish

This fails to recognize the sublist under the Lemons list item.

This is unresolved but we are working on an alternative: https://github.com/remarkjs/remark/issues/439

Sweet; exciting stuff; I'll keep my eyes peeled! :D

Heya, just wanted to give an update about micromark, it’s sort-of a new motor that we’ll soon use in remark to parse markdown. It’s not yet 100% ready but will be relatively soon. The good news is, it fixes this issue! (P.S. see this twitter thread for some more info!)

Heya, just wanted to give an update about micromark, it’s sort-of a new motor that we’ll soon use in remark to parse markdown. It’s not yet 100% ready but will be relatively soon. The good news is, it fixes this issue! (P.S. see this twitter thread for some more info!)

That's wonderful news! Thanks a ton and we're super excited. :)

Sorry for the wait! I just wanted to share that there’s now a PR that solves this issue: https://github.com/remarkjs/remark/pull/536.

Sorry for the wait! I just wanted to share that there’s now a PR that solves this issue: #536.

Woot Woot Woot Woot! Wow that's really impressive; thanks a ton I'll share the news with the team!!!!

Nice to see a solution for this on the horizon. Thanks to @wooorm for following up. 🙏

This is now released in [email protected]

Was this page helpful?
0 / 5 - 0 ratings