diff --git a/CHANGELOG.md b/CHANGELOG.md index 67652d343d..1a97c413fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ 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 Markdown table links not working when Markdown is appended to https://github.com/Textualize/textual/pull/6638 + ## [8.2.8] - 2026-06-30 ### Fixed diff --git a/src/textual/widgets/_markdown.py b/src/textual/widgets/_markdown.py index 847f5cfa5a..c288093291 100644 --- a/src/textual/widgets/_markdown.py +++ b/src/textual/widgets/_markdown.py @@ -697,7 +697,7 @@ async def _update_rows(self, updated_rows: list[list[Content]]) -> None: 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) diff --git a/tests/test_markdown.py b/tests/test_markdown.py index 8493fd0492..52955b4660 100644 --- a/tests/test_markdown.py +++ b/tests/test_markdown.py @@ -217,3 +217,39 @@ def on_markdown_link_clicked(self, message: Markdown.LinkClicked): async with app.run_test() as pilot: await pilot.click(Markdown, offset=(3, 0)) assert links == ["tété"] + + +async def test_markdown_stream_table_links(): + """Regression test for https://github.com/Textualize/textual/issues/6597 + + Links in tables failed when the markdown was appended to. + """ + + MD_TABLE = """ +| Links | +| --- | +| first row |\n""" + MD_TABLE_ROW = """| [Example](https://www.example.com) |\n\n""" + links: list[str] = [] + + class CollectLinksMarkdown(Markdown): + def on_markdown_link_clicked(self, event: Markdown.LinkClicked): + event.stop() + event.prevent_default() + links.append(event.href) + + class MDApp(App): + def compose(self) -> ComposeResult: + yield CollectLinksMarkdown() + + async def on_mount(self) -> None: + await self.query_one(CollectLinksMarkdown).append(MD_TABLE) + await self.query_one(CollectLinksMarkdown).append(MD_TABLE_ROW) + + app = MDApp() + async with app.run_test() as pilot: + await pilot.click(CollectLinksMarkdown, offset=(5, 5)) + await pilot.pause() + app.save_screenshot(filename="markdowntable.svg") + + assert links == ["https://www.example.com"]