Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(markdown): post message when link clicked in table #4686

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/textual/widgets/_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
33 changes: 33 additions & 0 deletions tests/test_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Loading