Telethon icon indicating copy to clipboard operation
Telethon copied to clipboard

Incorrect Markdown Order for Bold Hyperlinks

Open eduardobdamacena opened this issue 8 months ago • 3 comments

Code that causes the issue

message_entity = telegram_client.get_messages('TelethonChat', ids=[661069])
print(message_entity[0].text)

Expected behavior

I'm currently using telethon.extensions.markdown.unparse() to reconstruct messages from text and entities. However, I noticed an issue when dealing with messages that include both bold and hyperlinks.

When the original message contains a bold hyperlink, the unparse() method generates:

[**Bold Link**](https://example.com)

Expected behavior is:

**[Bold Link](https://example.com)**

Telethon version

1.34

Python version

3.12

Operating system (including distribution name and version)

Windows 11

Other details

No response

Checklist

  • [x] The error is in the library's code, and not in my own.
  • [x] I have searched for this issue before posting it and there isn't an open duplicate.
  • [x] I ran pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip and triggered the bug in the latest version.

eduardobdamacena avatar Apr 12 '25 05:04 eduardobdamacena

Does it work if you unparse(*parse('**[Bold Link](https://example.com)**'))?

Lonami avatar Apr 12 '25 06:04 Lonami

When I get a message entity by id, the text property returned from the hyperlink in bold is [**text**](url), but for the sending to work I must follow the pattern **[text](url)**

See the example with message: https://t.me/TelethonChat/661069

eduardobdamacena avatar Apr 12 '25 13:04 eduardobdamacena

If the answer to my question is "yes, it works", then the problem is on Telegram (it puts the link before the bold). If the answer is "no", then it might be an issue in the library.

Lonami avatar Apr 12 '25 16:04 Lonami