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 7195db4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 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
15 changes: 9 additions & 6 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,18 @@ 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(
text = Text(text) if isinstance(text, str) else text
text.stylize(context.current_style)
self.content.append_text(text)
# plain = text.plain if isinstance(text, Text) else text
# self.content.append(plain, context.style_stack.current)
""" self.content += Text(
plain, justify=self.justify, style=context.style_stack.current
)
) """


class ListElement(MarkdownElement):
Expand Down

0 comments on commit 7195db4

Please sign in to comment.