Commit 626141a
committed
feat(telegram): rich.py renderer for Bot API 10.1 (chat@4.31 4662309 — TG2/4)
Port packages/adapter-telegram/src/rich.ts character-for-character: the
rich-message -> Markdown / plain-text renderer and media extractor for the
Bot API 10.1 rich-message wire types introduced in TG1.
- TELEGRAM_RICH_MESSAGE_LIMIT = 32768
- truncate_rich_markdown: code-point-aware (list(str) == Array.from), reuses
StreamingMarkdownRenderer.push/finish so the truncated prefix stays valid
markdown; never splits a non-BMP code point.
- escape_text: MARKDOWN_PUNCTUATION /[!-/:-@[-`{-~]/ backslash-escape pass.
- inline/code fence run-sizing: max(1, longest_run+1) / max(3, longest_run+1).
- recursive text()/plain()/block()/plain_block()/media() walkers over every
TelegramRichText / TelegramRichBlock variant, via match statements that
mirror the upstream switch and let pyrefly narrow the recursive union.
Tests port the rich.test.ts it() blocks plus adversarial coverage: a full
punctuation escape sweep (in-class escaped, out-of-class untouched), all-
backtick fence growth, and a surrogate-pair truncation-boundary check. Each
fails on a plausible mutation. Test fixtures annotated to concrete TG1 variant
TypedDicts; pyrefly 0 on src and the test file.1 parent 8939d97 commit 626141a
2 files changed
Lines changed: 767 additions & 0 deletions
0 commit comments