]> git.giacomolli.uk - onechat/commit
Convert reply Markdown to Telegram entities
authorAnderson A. Giacomolli <agiacomolli@gmail.com>
Sat, 7 Nov 2026 14:37:49 +0000 (11:37 -0300)
committerAnderson A. Giacomolli <agiacomolli@gmail.com>
Sat, 7 Nov 2026 14:37:49 +0000 (11:37 -0300)
commitfc51ee2f545233df3cc1fa2fd4f28a4484c6bc00
tree04fb86b97cd1c1df06d2b310bc244d4a993d7cc0
parenta345df4e4bbf9dbaf3da1ce548896eef8f515de3
Convert reply Markdown to Telegram entities

A converter on the standard library turns the Markdown of a model reply
into plain text and Telegram message entities. It knows bold, italic,
strikethrough, inline code, fenced code blocks with an optional
language, links, and ATX headings, which become bold. Lists, quotes and
tables stay as their text. With entities, the text needs no escaping, so
a mark that does not close only stays as text, and it cannot make
Telegram refuse the message.

Inline marks do not cross a line break, so one open mark cannot change
the rest of a reply. Underscores inside a word stay as text, so
snake_case names do not turn italic, and an asterisk that a space
follows, as in a list item, opens nothing. Code holds no entity. The
offsets and lengths count UTF-16 code units, as Telegram does.

Issue: 3309f9b
botapi.go
markdown.go [new file with mode: 0644]
markdown_test.go [new file with mode: 0644]