diff --git a/CHANGELOG.md b/CHANGELOG.md index 31ce3911..2cac5fe5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed Text.expand_tabs not expanding spans. - Fixed TimeElapsedColumn from showing negative. - Fix for escaping strings with a trailing backslash https://github.com/Textualize/rich/issues/2987 +- Fixed exception in Markdown with partial table https://github.com/Textualize/rich/issues/3053 ### Added diff --git a/rich/markdown.py b/rich/markdown.py index e2cedfaa..3ab4af0e 100644 --- a/rich/markdown.py +++ b/rich/markdown.py @@ -259,10 +259,10 @@ class TableElement(MarkdownElement): for column in self.header.row.cells: table.add_column(column.content) - assert self.body is not None - for row in self.body.rows: - row_content = [element.content for element in row.cells] - table.add_row(*row_content) + if self.body is not None: + for row in self.body.rows: + row_content = [element.content for element in row.cells] + table.add_row(*row_content) yield table diff --git a/tests/test_markdown.py b/tests/test_markdown.py index 861665cf..1321dcea 100644 --- a/tests/test_markdown.py +++ b/tests/test_markdown.py @@ -133,6 +133,14 @@ def test_markdown_table(): assert result == expected +def test_partial_table(): + markdown = Markdown("| Simple | Table |\n| ------ | ----- ") + result = render(markdown) + print(repr(result)) + expected = "\n \n \x1b[1m \x1b[0m\x1b[1mSimple\x1b[0m\x1b[1m \x1b[0m \x1b[1m \x1b[0m\x1b[1mTable\x1b[0m\x1b[1m \x1b[0m \n ━━━━━━━━━━━━━━━━ \n \n" + assert result == expected + + if __name__ == "__main__": markdown = Markdown(MARKDOWN) rendered = render(markdown)