Repository navigation
feat(render): send LaTeX formulas as native math blocks - #303
Conversation
Telegram Bot API 10.1 renders formulas in rich messages, but the renderer turned every math fence into a pre block and left $$ ... $$ as plain text. - parse ```math / ```latex / ```tex fences as dedicated math blocks - normalize $$ ... $$ blocks into those fences before parsing - map the math block to Telegram's mathematical_expression - keep a plain-text projection and a MarkdownV2 fallback
|
@Ptah9 thanks for adding native formula rendering. Before merging, please fix these two regressions in markdown-normalizer.ts:
The existing tests, lint, and TypeScript checks pass, but additional checks reproduce both problems. These should be fixed before merging because they change code content and the structure of assistant replies. |
Skip backtick and tilde fences plus indented code when converting \$\$ blocks. Keep the fence indentation so a formula stays inside the list item, and strip that indent from the expression. Regression tests cover tilde fences, four-space indented code and ordered items with a formula.
|
@grinev thanks for the reproductions, fixed both.
Regression tests added: a
|
|
@Ptah9 thanks for addressing the previous feedback. The original examples now work correctly, including formulas inside numbered lists. However, code protection is still incomplete. Please fix these three remaining issues before merging:
Build, lint, typecheck, and all existing tests pass. Additional checks reproduce these issues and confirm that the base commit preserves the original content. |
Description of changes
math /latex / ```tex fences as dedicated math blocks instead of code blocks.$$ ... $$blocks into those fences before parsing, so a model can emit either form.mathematical_expressionrich block, keeping a plain-text projection and a MarkdownV2 fallback that emits the LaTeX source verbatim.$...$is out of scope: only block-level formulas are converted, so ordinary text with a dollar sign is untouched.Closes issue (optional)
How it was tested
$$normalization, and end-to-end pipeline output.npm run lint,npm run build,npm run typecheck— clean.npm test— 228 files, 3552 passed, 7 skipped.v0.28.0: it produces apreblock for ```math and a plain paragraph for$$ ... $$, so no existing behavior is duplicated.User-visible impact
Formulas written as ```math fences or
$$ ... $$blocks now render as native Telegram formulas instead of raw LaTeX text. Other code fences are unchanged.Note on #300 (copyable replies)
Formula rendering relies on rich messages: Telegram has no math markup in
MarkdownV2or entities. If the transport moves to a copyable format, formulas degrade to their LaTeX source (already handled in the MarkdownV2 fallback) rather than break.Checklist
<type>(<scope>)?: <description>mainnpm run lint,npm run build, andnpm test