marked icon indicating copy to clipboard operation
marked copied to clipboard

Lists with line breaks are not parsed correctly

Open d0819 opened this issue 1 year ago • 1 comments

Marked version: 4.3.0 4.2.3

Describe the bug

👋Hello. I am using marked and it is a great library, thank you for creating it.

According to this discussion, V4.2.3 is supposed to be 100% compliant with the "Lists" and "List items" of the CommonMark standard. However, it seems to have some issues with parsing lists that contain line breaks, such as the following:

1.
Monday
2.
Tuesday
3.
Wednesday

To Reproduce Steps to reproduce the behavior:

Expected behavior

I believe that parsing it in the following way, like in CommonMark, is correct:

<ol>
<li></li>
</ol>
<p>Monday
2.
Tuesday
3.
Wednesday</p>

Explanation According to CommonMark 5.2 List items:

  1. A list may start or end with an empty list item. So 1. is a list item with empty content.
  2. In this case, the width W of the list marker (1.) is 2, so in order for Monday to become the content of 1., it needs to have 3 (= W + 1) or more spaces of indentation. In the given example, since there are 0 spaces, Monday should become regular text (<p>).

Example1:

1.
Monday

Expected result:

<ol>
<li></li>
</ol>
<p>Monday</p>

Example2:

1.
   Monday

Expected result:

<ol>
<li>Monday</li>
</ol>

d0819 avatar Apr 11 '23 09:04 d0819

It looks like the expected result for Example2 is what happens in marked.

I would say that Example1 is not well formatted markdown and should be considered in the category of garbage in/garbage out.

The are quite a few places in the common mark spec where it describes how common mark works not necessarily how it should work.

UziTech avatar Apr 11 '23 15:04 UziTech