Skip to content

Commit

Permalink
Merge pull request #3064 from Textualize/fix-markdown-table
Browse files Browse the repository at this point in the history
fix for markdown table
  • Loading branch information
willmcgugan committed Jul 29, 2023
2 parents 01b85ac + 1e1a7b4 commit cbf01a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 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
17 changes: 8 additions & 9 deletions rich/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,14 @@ def __rich_console__(
) -> RenderResult:
table = Table(box=box.SIMPLE_HEAVY)

assert self.header is not None
assert self.header.row is not None
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.header is not None and self.header.row is not None:
for column in self.header.row.cells:
table.add_column(column.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 cbf01a0

Please sign in to comment.