marked
marked copied to clipboard
Lists with line breaks are not parsed correctly
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:
- Marked Demo (3 list items)
-
CommonMark Demo
(an empty list item and a
<p>
)
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:
- A list may start or end with an empty list item. So
1.
is a list item with empty content. - In this case, the width
W
of the list marker (1.
) is2
, so in order forMonday
to become the content of1.
, it needs to have3
(=W + 1
) or more spaces of indentation. In the given example, since there are0
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>
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.