diff --git a/CHANGELOG.md b/CHANGELOG.md index 31ce39119..2cac5fe54 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 e2cedfaa8..3ab4af0ed 100644 --- a/rich/markdown.py +++ b/rich/markdown.py @@ -259,10 +259,10 @@ def __rich_console__( 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 861665cff..1321dceab 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)