Skip to content

Lists with line breaks are not parsed correctly #2779

@d0819

Description

@d0819

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    L2 - annoyingSimilar to L1 - broken but there is a known workaround available for the issuecategory: lists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions