Skip to content

Added multi-paragraph support inside list items and blockquotes.#1

Open
heshammahamed wants to merge 1 commit into
mainfrom
Added/multi_paragraph_support
Open

Added multi-paragraph support inside list items and blockquotes.#1
heshammahamed wants to merge 1 commit into
mainfrom
Added/multi_paragraph_support

Conversation

@heshammahamed

Copy link
Copy Markdown

Problem

A blank line followed by indented continuation inside a list item
broke out of the list entirely, producing a stray <p> instead of
staying inside the <li>:

Input:
* content

  continuation

outputBeforeChanges:
<ul><li>content</li></ul>
<p>continuation</p>

outputAfterChanges:
<ul><li><p>content</p><p>continuation</p></li></ul>

Summary

  • Added a new rule to handle multi-paragraph continuation inside list items and blockquotes. When a blank line is followed by indented content, the translator now creates a new <p> inside the current <li> or <blockquote> rather than closing the element.

  • Updated ul and ol element tags to wrap <li> content in <p> tag (<ul><li><p> / </p></li></ul>), which is required for multi-paragraph list items to produce valid HTML.

  • Update blockquote element tags to wrap content in <p> tag (<blockquote><p> / </p></blockquote>) which is required for multi-paragraph blockquote to produce valid HTML.

Design Decision: Always Loose Lists

The library now always treats lists as loose (content inside <li> is always wrapped in <p>), rather than implementing the CommonMark loose/tight list distinction.

CommonMark definition:

A list is loose if any of its constituent list items are separated by blank lines, or if any of its constituent list items directly contain two block-level elements with a blank line between them. Otherwise a list is tight. The difference in HTML output is that paragraphs in a loose list are wrapped in <p> tags, while paragraphs in a tight list are not.

Implementing this distinction correctly requires look-ahead — the parser must scan the entire list before deciding whether to wrap content in <p>.

Since this library processes Markdown as a left-to-right stream with no look-ahead, implementing true tight/loose detection is not feasible without a significant architectural change.

Treating all lists as loose is a deliberate simplification. The output is valid HTML and is consistent with how many other lightweight Markdown libraries behave.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant