diff --git a/CHANGELOG.md b/CHANGELOG.md index 94f03d0271..084829b866 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed grid + keyline when the grid has auto dimensions https://github.com/Textualize/textual/pull/4680 - Fixed mouse code leakage https://github.com/Textualize/textual/pull/4681 +- Fixed link inside markdown table not posting a `Markdown.LinkClicked` message https://github.com/Textualize/textual/issues/4683 ## [0.70.0] - 2024-06-19 diff --git a/src/textual/widgets/_markdown.py b/src/textual/widgets/_markdown.py index b42edfc4ac..5bcc227825 100644 --- a/src/textual/widgets/_markdown.py +++ b/src/textual/widgets/_markdown.py @@ -487,6 +487,11 @@ def render(self) -> Table: table.add_row(*row) return table + async def action_link(self, href: str) -> None: + """Pass a link action on to the MarkdownTable parent.""" + if isinstance(self.parent, MarkdownTable): + await self.parent.action_link(href) + class MarkdownTable(MarkdownBlock): """A Table markdown Block.""" diff --git a/tests/test_markdown.py b/tests/test_markdown.py index 43060c2546..4cedf9b6c0 100644 --- a/tests/test_markdown.py +++ b/tests/test_markdown.py @@ -164,3 +164,36 @@ def log_table_of_content_update( await pilot.app.query_one(Markdown).update("") await pilot.pause() assert messages == ["TableOfContentsUpdated", "TableOfContentsUpdated"] + + +async def test_link_in_markdown_table_posts_message_when_clicked(): + """A link inside a markdown table should post a `Markdown.LinkClicked` + message when clicked. + + Regression test for https://github.com/Textualize/textual/issues/4683 + """ + + markdown_table = """\ +| Textual Links | +| ------------------------------------------------ | +| [GitHub](https://github.com/textualize/textual/) | +| [Documentation](https://textual.textualize.io/) |\ +""" + + class MarkdownTableApp(App): + messages = [] + + def compose(self) -> ComposeResult: + yield Markdown(markdown_table) + + @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: + await pilot.click(Markdown, offset=(3, 3)) + assert app.messages == ["LinkClicked"]