Skip to content

Commit

Permalink
Fix markdown table rendering issue.
Browse files Browse the repository at this point in the history
The table data elements were not interacting well with inline styles (in the rich sense) and the table data element would have its content overridden every time we found another excerpt of text with a different style.
  • Loading branch information
rodrigogiraoserrao committed Sep 13, 2023
1 parent 51603be commit e30b822
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Fixed

- Markdown table rendering issue with inline styles and links https://github.com/Textualize/rich/issues/3115

## [13.5.2] - 2023-08-01

### Fixed
Expand Down
12 changes: 5 additions & 7 deletions rich/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class TableDataElement(MarkdownElement):

@classmethod
def create(cls, markdown: "Markdown", token: Token) -> "MarkdownElement":
style = str(token.attrs.get("style" "")) or ""
style = str(token.attrs.get("style")) or ""

justify: JustifyMethod
if "text-align:right" in style:
Expand All @@ -330,15 +330,13 @@ def create(cls, markdown: "Markdown", token: Token) -> "MarkdownElement":
return cls(justify=justify)

def __init__(self, justify: JustifyMethod) -> None:
self.content: TextType = ""
self.content: Text = Text("", justify=justify)
self.justify = justify

def on_text(self, context: "MarkdownContext", text: TextType) -> None:
plain = text.plain if isinstance(text, Text) else text
style = text.style if isinstance(text, Text) else ""
self.content = Text(
plain, justify=self.justify, style=context.style_stack.current
)
text = Text(text) if isinstance(text, str) else text
text.stylize(context.current_style)
self.content.append_text(text)


class ListElement(MarkdownElement):
Expand Down

0 comments on commit e30b822

Please # to comment.