-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(markdown): Correctly render loose lists with blank lines #3916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 @@ def __init__(self) -> None: | |
|
|
||
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FIX would be superfluous once merged... |
||
| if getattr(child, "visible", False): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getattr is often a hack. Why can't we be sure of this attribute? |
||
| # Text(" ") creates exactly one new line of height | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A little redundant perhaps? |
||
| self.elements.append(Text(" ")) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the intent here? I doubt a single space in the output is desirable... |
||
| return False | ||
|
|
||
| def render_bullet(self, console: Console, options: ConsoleOptions) -> RenderResult: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we be sure that the "hidden" attribute exists? Is it not on all Tokens? If not, would an
isinstancecheck allow us to avoid thegetattr.