-
Notifications
You must be signed in to change notification settings - Fork 842
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
Encoding issue (?) in the message sent by Markdown.LinkClicked #3350
Comments
You likely haven't installed |
Thanks. I have a hard time installing it (not in the AUR, and pip tells me that "error: externally-managed-environment"). If it is possible not to install it that would be easier for me. |
It's fine if you can't, although you should be able to install it the same way you would Textual. But don't worry about it if you can't; it's unlikely the issue you're asking about is down to your operating system and the like. :-) |
This is URL encoding (AKA percent-encoding) which will convert non-ASCII characters to a percent sign followed by two hex digits. For example, |
You might find this video helpful: Arch Linux's Python Protects Me From Myself If you plan on developing Textual apps, I would instead recommend installing |
Thanks for your help with
Actually the Arch User Repository contains python-textual but not python-textual-dev. Back to the original problem, using urllib.parse.unquote allows me to solve my problem (found here): #!/usr/bin/python3
from urllib.parse import unquote
from textual import on
from textual.app import App, ComposeResult
from textual.widgets import Markdown
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):
self.md.update(unquote(message.href))
if __name__ == "__main__":
app = MyApp()
app.run() However, could you explain where this conversion happens and whether this is the expected behavior? |
It looks like this encoding is done by the markdown parser used by Textual. from pprint import pprint
from markdown_it import MarkdownIt
parser = MarkdownIt("gfm-like")
markdown = "[tété](tété)"
for token in parser.parse(markdown):
pprint(token)
It makes sense to me that |
I guess the consensus would be to unquote the href in the message? |
Don't forget to star the repository! Follow @textualizeio for Textual updates. |
I believe this change has the side effect of unquoting already encoded characters that should not be unquoted. See #5426. This breaks signed URLs as the characters don't match the signature. (Ideally, href should be the identical link that is in the markdown.) |
Je suis en vacances (bien méritées), je serai de retour le 6 janvier.
I am on vacation, I will be back on January 6th.
Vincent
--
Vincent Demery ***@***.***>
|
I have what seems to be an encoding issue with the message sent by Markdown.LinkClicked.
Consider the code below, with accented characters. "tété" shows up correctly in the Markdown widget. Clicking on it, and thus sending the message.href "tété" replaces the text by "t%C3%A9t%C3%A9", where it should be "tété". I do not know how the message handles the string, or what is the encoding used.
It will be helpful if you run the following command and paste the results:
I am sorry but this command returns
textual not found
. I use Archlinux withThe text was updated successfully, but these errors were encountered: