mirror of
https://github.com/Textualize/rich.git
synced 2025-12-23 07:08:35 +00:00
fix(markdown): render blank lines for loose lists
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.
This commit is contained in:
parent
f82a399d58
commit
3a00a59bc3
3 changed files with 12 additions and 4 deletions
|
|
@ -112,10 +112,14 @@ class Paragraph(TextElement):
|
|||
|
||||
@classmethod
|
||||
def create(cls, markdown: Markdown, token: Token) -> Paragraph:
|
||||
return cls(justify=markdown.justify or "left")
|
||||
return cls(
|
||||
justify=markdown.justify or "left",
|
||||
visible=not getattr(token, "hidden", False),
|
||||
)
|
||||
|
||||
def __init__(self, justify: JustifyMethod) -> None:
|
||||
def __init__(self, justify: JustifyMethod, visible: bool = True) -> None:
|
||||
self.justify = justify
|
||||
self.visible = visible
|
||||
|
||||
def __rich_console__(
|
||||
self, console: Console, options: ConsoleOptions
|
||||
|
|
@ -364,6 +368,10 @@ class ListItem(TextElement):
|
|||
|
||||
def on_child_close(self, context: MarkdownContext, child: MarkdownElement) -> bool:
|
||||
self.elements.append(child)
|
||||
# FIX: If the child is a visible paragraph (loose list), add a blank line
|
||||
if getattr(child, "visible", False):
|
||||
# Text(" ") creates exactly one new line of height
|
||||
self.elements.append(Text(" "))
|
||||
return False
|
||||
|
||||
def render_bullet(self, console: Console, options: ConsoleOptions) -> RenderResult:
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue