From 7195db4c910470bd2d17fdb6ecfd08647465865e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Gir=C3=A3o=20Serr=C3=A3o?= <5621605+rodrigogiraoserrao@users.noreply.github.com> Date: Wed, 13 Sep 2023 13:33:32 +0100 Subject: [PATCH] Fix markdown table rendering issue. 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. --- CHANGELOG.md | 6 ++++++ rich/markdown.py | 15 +++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89843c0ae5..8e74f4b2a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/rich/markdown.py b/rich/markdown.py index 704da3010b..729d8fd1d5 100644 --- a/rich/markdown.py +++ b/rich/markdown.py @@ -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: @@ -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):