Skip to content

Conversation

@anish-devgit
Copy link

Problem

Previously, Rich rendered all Markdown lists as "tight" lists, even when items were separated by blank lines (loose lists). This squashed list items together, ignoring the intended vertical spacing defined in the CommonMark spec.

Solution

I updated the ListItem class in rich/markdown.py to respect the hidden attribute provided by the markdown-it-py parser.

  • Logic Update: When ListItem.on_child_close processes a child element, it now checks if that child is explicitly marked as "visible" (not token.hidden).
  • Rendering: If it is visible (indicating a loose list), a single blank line (Text(" ")) is appended to the renderable elements.
  • Regression Tests: I updated tests/test_markdown.py and tests/test_markdown_no_hyperlinks.py to reflect the corrected, spaced-out rendering. This ensures no regressions for standard (tight) lists while fixing the output for loose lists.

Example

Input:

1. Item 1

2. Item 2

Before:
1 Item 1
2 Item 2

After:
1 Item 1

2 Item 2

Linked Issue
Fixes #3907

Updates ListItem to respect the 'hidden' token attribute from markdown-it-py. This ensures that loose lists (items separated by newlines) render with proper spacing, complying with the CommonMark spec, while keeping tight lists compact. Updated regression tests to match the corrected output.
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