redcarpet icon indicating copy to clipboard operation
redcarpet copied to clipboard

Redcarpet incorrectly parses nested lists

Open kristoph opened this issue 1 year ago • 4 comments

  1. Lists: You can create a bulleted list by prefacing each line with a dash or an asterisk. For example:

    • Item 1
    • Item 2
    • Item 3

( or equivalent string 5. Lists: You can create a bulleted list by prefacing each line with a dash or an asterisk. For example:\n\n * Item 1\n * Item 2\n * Item 3 )

Generates ...

"<ol>\n<li>Lists: You can create a bulleted list by prefacing each line with a dash or an asterisk. For example:</li>\n</ol>\n\n<ul>\n<li>Item 1</li>\n<li>Item 2</li>\n<li>Item 3</li>\n</ul>\n"

kristoph avatar Jul 05 '24 01:07 kristoph

Any news on this? We are also having this problem with nested lists

jlpereira avatar Jul 10 '24 22:07 jlpereira

The problem seems to be that the <li> tags that should wrap the nested <ul> or <ol> element are missing. Moreover, this problem affects HTML passed in, too, not just markdown. Rendering passed-in HTML gives a hint as to the nature of the problem, since it appears that tags wrapping the nested list are actually stripped. For example, if you pass in something like

<ul>
  <li>Item 1</li>
  <li>
    <ol>
      <li>Subitem 1</li>
      <li>Subitem 2</li>
      <li>Subitem 3</li>
    </ol>
  </li>
</ul>

the rendered HTML will be look more like

<ul>
  <li>Item 1</li>
  <ol>
    <li>Subitem 1</li>
    <li>Subitem 2</li>
    <li>Subitem 3</li>
  </ol>
</ul>

which is invalid HTML.

dhMuse avatar Aug 27 '24 12:08 dhMuse

Nope, sorry, the point in my last post about the surrounding <li> tags being stripped was mistaken! Passing in correctly nested <ul><li><ol></ol></li></ul> will retain the <li> tags.

dhMuse avatar Aug 27 '24 12:08 dhMuse

Potentially related for those poking at code: https://github.com/vmg/redcarpet/blob/master/test/MarkdownTest_1.0.3/Tests/Ordered%20and%20unordered%20lists.html

mjy avatar Sep 11 '24 15:09 mjy