From 73f1432d395e3fb6d34a6a39b442bfb8d179a2d8 Mon Sep 17 00:00:00 2001 From: dobbydobap Date: Sat, 4 Jul 2026 16:52:59 +0530 Subject: [PATCH] Fix links in markdown table rows added via Markdown.append --- CHANGELOG.md | 6 ++++++ src/textual/widgets/_markdown.py | 6 +++--- tests/test_markdown.py | 37 ++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67652d343d..948c5bdc9c 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](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +### Fixed + +- Fixed links in markdown table rows added via `Markdown.append` not being clickable https://github.com/Textualize/textual/issues/6597 + ## [8.2.8] - 2026-06-30 ### Fixed diff --git a/src/textual/widgets/_markdown.py b/src/textual/widgets/_markdown.py index 847f5cfa5a..b027b7f367 100644 --- a/src/textual/widgets/_markdown.py +++ b/src/textual/widgets/_markdown.py @@ -693,14 +693,14 @@ def _update_content(self, headers: list[Content], rows: list[list[Content]]): async def _update_rows(self, updated_rows: list[list[Content]]) -> None: self.styles.grid_size_columns = len(self.headers) await self.query_children(f".cell.row{self.last_row}").remove() - new_cells: list[Static] = [] + new_cells: list[MarkdownTableCellContents] = [] for row_index, row in enumerate(updated_rows, self.last_row): for cell in row: new_cells.append( - Static( + MarkdownTableCellContents( cell, classes=f"row{row_index} cell", - ).with_tooltip(cell) + ).with_tooltip(cell.plain) ) self.last_row = row_index await self.mount_all(new_cells) diff --git a/tests/test_markdown.py b/tests/test_markdown.py index 8493fd0492..1416ee5388 100644 --- a/tests/test_markdown.py +++ b/tests/test_markdown.py @@ -201,6 +201,43 @@ def log_markdown_link_clicked( assert app.messages == ["LinkClicked"] +async def test_link_in_streamed_markdown_table_posts_message_when_clicked(): + """A link inside a table row added via `Markdown.append` should post a + `Markdown.LinkClicked` message when clicked. + + Regression test for https://github.com/Textualize/textual/issues/6597 + """ + + markdown_table = """\ +| Textual Links | +| ------------------------------------------------- | +| [GitHub](https://github.com/textualize/textual/) | +""" + appended_row = "| [Documentation](https://textual.textualize.io/) |" + + class MarkdownTableApp(App): + messages = [] + + def compose(self) -> ComposeResult: + yield Markdown(open_links=False) + + @on(Markdown.LinkClicked) + def log_markdown_link_clicked( + self, + event: Markdown.LinkClicked, + ) -> None: + self.messages.append(event.__class__.__name__) + + app = MarkdownTableApp() + async with app.run_test() as pilot: + markdown = app.query_one(Markdown) + await markdown.append(markdown_table) + await markdown.append(appended_row) + await pilot.pause() + await pilot.click(Markdown, offset=(8, 5)) + assert app.messages == ["LinkClicked"] + + async def test_markdown_quoting(): # https://github.com/Textualize/textual/issues/3350 links = []