ToHtml incorrectly bunches up separate paragraph in previous <li> #616

Closed
opened 2026-01-29 14:41:13 +00:00 by claunia · 5 comments
Owner

Originally created by @achobanov on GitHub (Aug 16, 2023).

Environment

  • net6.0
  • Markdig v.0.31.0

Code

var html = Markdown.ToHtml(source);

Problem

Using Markdown.ToHtml returns incorrect result - the last list-item element consumes the next paragraph, which obviously results in wrong formatting in output text:

Source:

**Exited Positions:**

+ **McKesson**: -2.3 million shares
+ **Marsh & McLennan**: -404,911 shares

   This item is part of a Wall Street Journal live coverage event. The full stream can be found by searching P/WSJL (WSJ Live Coverage).

Result:

<ul>
  <li><p><strong>McKesson</strong>: -2.3 million shares</p></li>
  <li>
    <p><strong>Marsh &amp; McLennan</strong>: -404,911 shares</p>
    <p>This item is part of a Wall Street Journal live coverage event. The full stream can be found by searching P/WSJL (WSJ Live Coverage).</p>
  </li>
</ul>

Steps to reproduce

  1. Download attached makrdown.txt file
  2. Run the above code
  3. Compare the result with html.txt

html.txt
markdown.txt

Originally created by @achobanov on GitHub (Aug 16, 2023). ## Environment - net6.0 - Markdig v.0.31.0 ## Code ```c# var html = Markdown.ToHtml(source); ``` ## Problem Using `Markdown.ToHtml` returns incorrect result - the last list-item element consumes the next paragraph, which obviously results in wrong formatting in output text: **Source**: ```markdown **Exited Positions:** + **McKesson**: -2.3 million shares + **Marsh & McLennan**: -404,911 shares This item is part of a Wall Street Journal live coverage event. The full stream can be found by searching P/WSJL (WSJ Live Coverage). ``` **Result**: ```html <ul> <li><p><strong>McKesson</strong>: -2.3 million shares</p></li> <li> <p><strong>Marsh &amp; McLennan</strong>: -404,911 shares</p> <p>This item is part of a Wall Street Journal live coverage event. The full stream can be found by searching P/WSJL (WSJ Live Coverage).</p> </li> </ul> ``` ### Steps to reproduce 1. Download attached _makrdown.txt_ file 2. Run the above code 3. Compare the result with _html.txt_ [html.txt](https://github.com/xoofx/markdig/files/12361601/html.txt) [markdown.txt](https://github.com/xoofx/markdig/files/12361602/markdown.txt)
claunia added the invalid label 2026-01-29 14:41:13 +00:00
Author
Owner

@xoofx commented on GitHub (Aug 21, 2023):

This is expected because of this spec line (I believe, It has been 7+ years that I haven't checked the specs in details, but there are also many other rules with blank lines and list)

You can verify also on babelmark here that all other CommonMark implementations are showing the same behavior.

@xoofx commented on GitHub (Aug 21, 2023): This is expected because of this [spec line](https://spec.commonmark.org/0.30/#example-262) (I believe, It has been 7+ years that I haven't checked the specs in details, but there are also many other rules with blank lines and list) You can verify also on babelmark [here](https://babelmark.github.io/?text=**Exited+Positions%3A**%0A%2B+**McKesson**%3A+-2.3+million+shares%0A%2B+**Marsh+%26+McLennan**%3A+-404%2C911+shares%0A%0A+++This+item+is+part+of+a+Wall+Street+Journal+live+coverage+event.+The+full+stream+can+be+found+by+searching+P%2FWSJL+(WSJ+Live+Coverage).) that all other CommonMark implementations are showing the same behavior.
Author
Owner

@achobanov commented on GitHub (Aug 22, 2023):

@xoofx Thanks for the replay. You are probably correct, since I never read the specs. However this does not resolve me problem. How would you suggest I should separate the list from the following paragraph? If the list itself can include anything then there must be something like a closing tag, because it would mean that if there is a list at the start of the text, all other text will be concatenated with the last list item.

@achobanov commented on GitHub (Aug 22, 2023): @xoofx Thanks for the replay. You are probably correct, since I never read the specs. However this does not resolve me problem. How would you suggest I should separate the list from the following paragraph? If the list itself can include **anything** then there must be something like a closing tag, because it would mean that if there is a list at the start of the text, all other text will be concatenated with the last list item.
Author
Owner

@achobanov commented on GitHub (Aug 22, 2023):

TBH I fail to see how this spec makes sense.

@achobanov commented on GitHub (Aug 22, 2023): TBH I fail to see how this spec makes sense.
Author
Owner

@MihaZupan commented on GitHub (Aug 22, 2023):

How would you suggest I should separate the list from the following paragraph?

Avoid the indentation on the following paragraph.

Consider https://babelmark.github.io/?text=%2B+A%0A%2B+B%0A%0AParagraph+1%0A%0A%2B+C%0A%2B+D%0A%0A++++Paragraph+2

@MihaZupan commented on GitHub (Aug 22, 2023): > How would you suggest I should separate the list from the following paragraph? Avoid the indentation on the following paragraph. Consider https://babelmark.github.io/?text=%2B+A%0A%2B+B%0A%0AParagraph+1%0A%0A%2B+C%0A%2B+D%0A%0A++++Paragraph+2
Author
Owner

@achobanov commented on GitHub (Aug 22, 2023):

@MihaZupan oh it's the indentation. I understand now, thanks

@achobanov commented on GitHub (Aug 22, 2023): @MihaZupan oh it's the indentation. I understand now, thanks
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#616