From be7d1fe851392599d1fad58c7d84229b17d4e5eb Mon Sep 17 00:00:00 2001 From: Artem Tsyrulnikov Date: Wed, 11 Feb 2026 15:55:15 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D1=84=D0=B8=D0=BA=D1=81=20=D0=BA=D1=80?= =?UTF-8?q?=D0=B5=D0=B0=D1=82=D0=B8=D0=B2=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tg_bot/screens/ui/message_format.go | 31 ++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/tg_bot/screens/ui/message_format.go b/tg_bot/screens/ui/message_format.go index 17003f1..a3fbb35 100644 --- a/tg_bot/screens/ui/message_format.go +++ b/tg_bot/screens/ui/message_format.go @@ -252,15 +252,32 @@ func normalizeHTMLTags(input string) string { continue } - if isClosing { - if len(stack) > 0 && stack[len(stack)-1] == tagName { - stack = stack[:len(stack)-1] - out.WriteString(input[i : end+1]) + if isClosing { + // Find the tag in stack + foundIndex := -1 + for j := len(stack) - 1; j >= 0; j-- { + if stack[j] == tagName { + foundIndex = j + break } - } else { - stack = append(stack, tagName) - out.WriteString(input[i : end+1]) } + + if foundIndex >= 0 { + // Close all tags from top of stack down to foundIndex + for j := len(stack) - 1; j > foundIndex; j-- { + out.WriteString("") + } + // Close the found tag + out.WriteString(input[i : end+1]) + // Remove closed tags from stack + stack = stack[:foundIndex] + } + } else { + stack = append(stack, tagName) + out.WriteString(input[i : end+1]) + } i = end + 1 }