From 7ef2d05ca8aa3cb405dab2fdf3282e69cf8089e3 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 12 Apr 2026 14:39:10 +0700 Subject: [PATCH 1/3] fix inline code in table cells --- rich/markdown.py | 10 +++++++--- tests/test_markdown.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/rich/markdown.py b/rich/markdown.py index 1e28343e86..15e16a2151 100644 --- a/rich/markdown.py +++ b/rich/markdown.py @@ -331,9 +331,13 @@ def __init__(self, justify: JustifyMethod) -> None: self.justify = justify def on_text(self, context: MarkdownContext, text: TextType) -> None: - text = Text(text) if isinstance(text, str) else text - text.stylize(context.current_style) - self.content.append_text(text) + if isinstance(text, str): + self.content.append(text, context.current_style) + else: + self.content.append_text(text) + # text = Text(text) if isinstance(text, str) else text + # text.stylize(context.current_style) + # self.content.append_text(text) class ListElement(MarkdownElement): diff --git a/tests/test_markdown.py b/tests/test_markdown.py index a76eac9b18..c461c76966 100644 --- a/tests/test_markdown.py +++ b/tests/test_markdown.py @@ -199,6 +199,22 @@ def test_table_with_empty_cells() -> None: assert result == expected +def test_inline_code_in_table_cells() -> None: + """Test inline code in table cells. + + Regression test for https://github.com/Textualize/rich/issues/4038 + + """ + markdown = Markdown( + "| Col |\n|---|\n| `print('hello');` |\n", + inline_code_theme="monokai", + inline_code_lexer="python", + ) + result = render(markdown) + expected = "\n\x1b[36m \x1b[0m\n\x1b[36m \x1b[0m\x1b[36mCol\x1b[0m\x1b[1m \x1b[0m\x1b[36m \x1b[0m\n\x1b[36m ─────────────── \x1b[0m\n\x1b[36m \x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34mprint\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m(\x1b[0m\x1b[38;2;230;219;116;48;2;39;40;34m'\x1b[0m\x1b[38;2;230;219;116;48;2;39;40;34mhello\x1b[0m\x1b[38;2;230;219;116;48;2;39;40;34m'\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m)\x1b[0m\x1b[38;2;248;248;242;48;2;39;40;34m;\x1b[0m\x1b[36m \x1b[0m\n\x1b[36m \x1b[0m\n" + assert result == expected + + if __name__ == "__main__": markdown = Markdown(MARKDOWN) rendered = render(markdown) From 77f0edbdef71f2a895cd0ab1481e9a1fc79d42e6 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 12 Apr 2026 14:39:42 +0700 Subject: [PATCH 2/3] remove comments --- rich/markdown.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/rich/markdown.py b/rich/markdown.py index 15e16a2151..abbbb07d64 100644 --- a/rich/markdown.py +++ b/rich/markdown.py @@ -335,9 +335,6 @@ def on_text(self, context: MarkdownContext, text: TextType) -> None: self.content.append(text, context.current_style) else: self.content.append_text(text) - # text = Text(text) if isinstance(text, str) else text - # text.stylize(context.current_style) - # self.content.append_text(text) class ListElement(MarkdownElement): From cf3b5a16f7a76b2e8c4921d3314021bb72a6c5c1 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 12 Apr 2026 14:41:17 +0700 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2e7906004..bdcfb49ad2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed empty print ignoring the `end` parameter - Fixed `Text.from_ansi` removing newlines https://github.com/Textualize/rich/pull/4076 - Fixed `FileProxy.isatty` not proxying https://github.com/Textualize/rich/pull/4077 +- Fixed inline code in Markdown tables cells https://github.com/Textualize/rich/pull/4079 ## [14.3.4] - 2026-04-11