Skip to content

Commit

Permalink
fix for markdown table
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jul 29, 2023
1 parent 01b85ac commit dbf66e8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions rich/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions tests/test_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dbf66e8

Please sign in to comment.