Skip to content

Commit e30b822

Browse files
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.
1 parent 51603be commit e30b822

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Fixed
11+
12+
- Markdown table rendering issue with inline styles and links https://github.com/Textualize/rich/issues/3115
13+
814
## [13.5.2] - 2023-08-01
915

1016
### Fixed

rich/markdown.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class TableDataElement(MarkdownElement):
314314

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

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

332332
def __init__(self, justify: JustifyMethod) -> None:
333-
self.content: TextType = ""
333+
self.content: Text = Text("", justify=justify)
334334
self.justify = justify
335335

336336
def on_text(self, context: "MarkdownContext", text: TextType) -> None:
337-
plain = text.plain if isinstance(text, Text) else text
338-
style = text.style if isinstance(text, Text) else ""
339-
self.content = Text(
340-
plain, justify=self.justify, style=context.style_stack.current
341-
)
337+
text = Text(text) if isinstance(text, str) else text
338+
text.stylize(context.current_style)
339+
self.content.append_text(text)
342340

343341

344342
class ListElement(MarkdownElement):

0 commit comments

Comments
 (0)