From: Anderson A. Giacomolli Date: Sat, 7 Nov 2026 19:38:29 +0000 (-0300) Subject: Escape tags in rich replies as HTML entities X-Git-Url: https://git.giacomolli.uk/onechat/commitdiff_plain/5bb22ac2fc501bad7327c119f1d3ac514e3d5398?ds=sidebyside;hp=5bb22ac2fc501bad7327c119f1d3ac514e3d5398 Escape tags in rich replies as HTML entities The bot writes each < of a reply outside inline code and fenced code blocks as < and each & as & before it sends the reply with sendRichMessage. Rich Markdown does not read a backslash before < as an escape: it shows the backslash and still reads the tag as HTML. It reads HTML entities, so < shows as <. The escape of & makes an entity that the model writes in prose, such as <, show as written. The entity fallback reads no HTML, so a rich part that Telegram refuses goes to the fallback with the escape reversed, and the user sees the text as the model wrote it. The reverse is exact, because after the escape each & outside code starts an entity of the escape. The escape and its reverse find the code of a text in the same way, so the reverse also works on each part of the split. The split still counts the escaped text against the rich limit, and the fallback splits the text without the escape at its own limit. When the split cuts a line longer than the limit, it cuts before an & in the last four bytes, so that it does not cut an entity. Issue: d75e312 ---