From 06a7555c367f10285bb86764ee3cb7e51856a694 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 26 Aug 2024 15:09:07 +0100 Subject: [PATCH] fix superfluous space --- rich/markdown.py | 2 +- tests/test_markdown.py | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/rich/markdown.py b/rich/markdown.py index a58a04fc..26c58d15 100644 --- a/rich/markdown.py +++ b/rich/markdown.py @@ -677,7 +677,7 @@ class Markdown(JupyterMixin): and context.stack.top.on_child_close(context, element) ) if should_render: - if new_line: + if new_line and node_type != "inline": yield _new_line_segment yield from console.render(element, context.options) diff --git a/tests/test_markdown.py b/tests/test_markdown.py index 710436eb..4724deca 100644 --- a/tests/test_markdown.py +++ b/tests/test_markdown.py @@ -18,10 +18,10 @@ Sub-heading Paragraphs are separated by a blank line. -Two spaces at the end of a line +Two spaces at the end of a line produces a line break. -Text attributes _italic_, +Text attributes _italic_, **bold**, `monospace`. Horizontal rule: @@ -174,6 +174,31 @@ def test_partial_table(): assert result == expected +def test_table_with_empty_cells() -> None: + """Test a table with empty cells is rendered without extra newlines above. + Regression test for #3027 https://github.com/Textualize/rich/issues/3027 + """ + complete_table = Markdown( + """\ +| First Header | Second Header | +| ------------- | ------------- | +| Content Cell | Content Cell | +| Content Cell | Content Cell | +""" + ) + table_with_empty_cells = Markdown( + """\ +| First Header | | +| ------------- | ------------- | +| Content Cell | Content Cell | +| | Content Cell | +""" + ) + result = len(render(table_with_empty_cells).splitlines()) + expected = len(render(complete_table).splitlines()) + assert result == expected + + if __name__ == "__main__": markdown = Markdown(MARKDOWN) rendered = render(markdown)