]> git.giacomolli.uk - onechat/commit
Escape tags in the Markdown of rich replies
authorAnderson A. Giacomolli <redacted>
Sat, 7 Nov 2026 17:59:33 +0000 (14:59 -0300)
committerAnderson A. Giacomolli <redacted>
Sat, 7 Nov 2026 17:59:33 +0000 (14:59 -0300)
commitde170709599e849c6b409d247b800dc68b0c7ab7
tree21d3e86a78fd1982a2ff3b3d819fb3f6bfa829df
parent1379d7d0d0173416237ddf8ebe820743d2cecfa6
Escape tags in the Markdown of rich replies

The bot puts a backslash before each < of a reply outside inline code
and fenced code blocks before it sends the reply with sendRichMessage.
Rich Markdown reads a tag in prose, such as <details>, as raw HTML: the
tag name is lost and the rest of the paragraph is in a collapsed
section. With the escape, Telegram shows the tag as written, and a reply
cannot carry raw HTML.

Inline code and code blocks keep their text, also a code block that a
split opens again, because the escape runs before the split. The split
thus counts the escaped text against the length limit. A < that a
backslash already makes plain stays as it is. The pipe, the dollar sign,
and the equals sign are not escaped: the tables use the pipe, and the
live check showed no problem with the dollar sign.

The entity fallback reads the backslash as an escape, so it shows the
same text as before. Other events go as plain text and do not change.

Issue: d75e312
telegram.go
telegram_markdown.go
telegram_markdown_test.go
telegram_test.go