Skip to content

Commit

Permalink
unquote href
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jul 15, 2024
1 parent 9cb9094 commit bee9266
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed

- "Discover" hits in the command palette are no longer sorted alphabetically https://github.com/Textualize/textual/pull/4720
- `Markdown.LinkClicked.href` is now automatically unquoted

## [0.72.0] - 2024-07-09

Expand Down
3 changes: 2 additions & 1 deletion src/textual/widgets/_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from functools import partial
from pathlib import Path, PurePath
from typing import Callable, Iterable, Optional
from urllib.parse import unquote

from markdown_it import MarkdownIt
from markdown_it.token import Token
Expand Down Expand Up @@ -781,7 +782,7 @@ def __init__(self, markdown: Markdown, href: str) -> None:
super().__init__()
self.markdown: Markdown = markdown
"""The `Markdown` widget containing the link clicked."""
self.href: str = href
self.href: str = unquote(href)
"""The link that was selected."""

@property
Expand Down
18 changes: 18 additions & 0 deletions tests/test_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,21 @@ def log_markdown_link_clicked(
async with app.run_test() as pilot:
await pilot.click(Markdown, offset=(3, 3))
assert app.messages == ["LinkClicked"]


async def test_markdown_quoting():
# https://github.com/Textualize/textual/issues/3350
links = []

class MyApp(App):
def compose(self) -> ComposeResult:
self.md = Markdown(markdown="[tété](tété)")
yield self.md

def on_markdown_link_clicked(self, message: Markdown.LinkClicked):
links.append(message.href)

app = MyApp()
async with app.run_test() as pilot:
await pilot.click(Markdown, offset=(0, 0))
assert links == ["tété"]

0 comments on commit bee9266

Please sign in to comment.