When utilizing Telethon to send Telegram messages with monospace or HTML text in Python, the parse_mode option (for example parse_mode='markdown' or parse_mode='html') works well during initial message sending. However, when attempting to edit a previously sent message, the parse_mode option does not appear to be available. How can I effectively edit a message and incorporate monospace or HTML-formatted text?
Example: Sending a message containing monospace string
sent_message = client.send_message(To_id, "the authentication code `8632496`", parse_mode='markdown')
Then editing the message and sending new text containing a monospace string
client(EditMessageRequest(
peer=To_id,
id=sent_message.id,
message="the new authentication code `9832798237`"
))
I am aware that using entities is an option. For instance:
entities = [MessageEntityCode(offset=9, length=18)] # specifying a code block entity
client(EditMessageRequest(
peer=To_id,
id=sent_message.id,
message='This is a monospace string.',
no_webpage=True,
entities=entities
))
However, my text is long and contains multiple monospace strings originating from various sources, for example: text = f"something {variable1}, something {variable2}"
Hence, identifying the starting point and length of each monospace string is challenging.
I'd greatly appreciate any guidance on how to approach this issue, including methods or best practices for effectively managing monospace or HTML text when editing Telegram messages using Telethon.

client(EditMessageRequest(is a old, not preferred way of editing a message.You should use
client.edit_messagemethod, in your example:This way, you don't even need to specify
parse_modeit's the same as the message your editing.Full code to test this:
Result: message changes after 3 seconds: