markedjs / marked

A markdown parser and compiler. Built for speed.
https://marked.js.org
Other
33.23k stars 3.39k forks source link

html comment after list causes all remaining content be commented out #3515

Closed mjbvz closed 2 weeks ago

mjbvz commented 3 weeks ago

Marked version: 14.1.3

Describe the bug When a html comment appears directly after a list, the rest of the content can become incorrectly commented out

To Reproduce

Try rendering the markdown:

- list
<!--
- a
-->

More text

https://marked.js.org/demo/?text=-%20list%0A%3C!--%0A-%20a%0A--%3E%0A%0AMore%20text%0A&options=%7B%0A%20%22async%22%3A%20false%2C%0A%20%22breaks%22%3A%20false%2C%0A%20%22extensions%22%3A%20null%2C%0A%20%22gfm%22%3A%20true%2C%0A%20%22hooks%22%3A%20null%2C%0A%20%22pedantic%22%3A%20false%2C%0A%20%22silent%22%3A%20false%2C%0A%20%22tokenizer%22%3A%20null%2C%0A%20%22walkTokens%22%3A%20null%0A%7D&version=14.1.3

Expected behavior The content after the comment is not shown. Looking at the html source, you can see that an unclosed comment is created which contains the rest of the document:

<ul>
<li>list<!--</li>
<li>a
--&gt;</li>
</ul>
<p>More text</p>

Seems to work on commonmark and for markdown-it

UziTech commented 3 weeks ago

Looks like it is not ending the list at the comment. Well formatted markdown should have a blank line between block elements, which is displayed correctly. (demo)