From 01be1fb583bbe1a8df5da3bc646cb59552c81c72 Mon Sep 17 00:00:00 2001 From: _run Date: Tue, 16 Aug 2022 21:39:20 +0500 Subject: [PATCH] Fixes #1650 --- telebot/types.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/telebot/types.py b/telebot/types.py index 27c8ed8..0f7f53f 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -1223,11 +1223,19 @@ class Message(JsonDeserializable): html_text += func(utf16_text[offset * 2 : (offset + entity.length) * 2], entity.type, entity.url, entity.user) offset += entity.length else: - # TODO: process nested entities from Bot API 4.5 - # Now ignoring them - pass + # Here we are processing nested entities. + # We shouldn't update offset, because they are the same as entity before. + # And, here we are replacing previous string with a new html-rendered text(previous string is already html-rendered, + # And we don't change it). + entity_string = utf16_text[entity.offset * 2 : (entity.offset + entity.length) * 2] + formatted_string = func(entity_string, entity.type, entity.url, entity.user) + entity_string_decoded = entity_string.decode("utf-16-le") + last_occurence = html_text.rfind(entity_string_decoded) + string_length = len(entity_string_decoded) + html_text = html_text.replace(html_text[last_occurence:last_occurence+string_length], formatted_string) if offset * 2 < len(utf16_text): html_text += func(utf16_text[offset * 2:]) + return html_text @property