fix: escape accidental Telegram blockquote markers in MarkdownV2 output (#524)

Co-authored-by: Letta Code <noreply@letta.com>
This commit is contained in:
Cameron
2026-03-09 21:48:11 -07:00
committed by GitHub
parent e8c57ebd9c
commit 1c9489683f
2 changed files with 44 additions and 1 deletions

View File

@@ -40,4 +40,47 @@ describe('markdownToTelegramV2', () => {
const result = await markdownToTelegramV2('Just some plain text');
expect(result).toContain('Just some plain text');
});
it('preserves intentional markdown blockquotes', async () => {
const result = await markdownToTelegramV2('> got annexed by the relationship problem.');
expect(result).toContain('> got annexed by the relationship problem');
});
it('does not alter greater-than signs in the middle of a line', async () => {
const result = await markdownToTelegramV2('2 > 1');
expect(result).toContain('2 \\> 1');
});
it('preserves greater-than signs inside fenced code blocks', async () => {
const result = await markdownToTelegramV2('```\n> code\n```');
expect(result).toContain('```\n> code\n```');
});
it('preserves mixed multiline content with blockquotes and plain text', async () => {
const result = await markdownToTelegramV2('> quote\nnormal line\n2 > 1');
expect(result).toContain('> quote');
expect(result).toContain('normal line');
expect(result).toContain('2 \\> 1');
});
it('preserves indented blockquotes', async () => {
const result = await markdownToTelegramV2(' > indented quote');
expect(result).toContain('> indented quote');
expect(result).not.toContain('\\> indented quote');
});
it('preserves nested blockquotes', async () => {
const result = await markdownToTelegramV2('>> nested');
expect(result).toContain('> > nested');
});
it('preserves greater-than signs in fenced code blocks with language and multiple lines', async () => {
const result = await markdownToTelegramV2('```ts\n> one\n> two\nconst x = 1 > 0\n```');
expect(result).toContain('```\n> one\n> two\nconst x = 1 > 0\n```');
});
it('preserves greater-than signs in inline code spans', async () => {
const result = await markdownToTelegramV2('Use `a > b` inline');
expect(result).toContain('`a > b`');
});
});

View File

@@ -16,7 +16,7 @@ export async function markdownToTelegramV2(markdown: string): Promise<string> {
try {
// Dynamic import to handle ESM module
const telegramifyMarkdown = (await import('telegramify-markdown')).default;
// Use 'keep' strategy to preserve blockquotes (>) and other unsupported elements
// Use 'keep' strategy for broad markdown support, including blockquotes.
return telegramifyMarkdown(markdown, 'keep');
} catch (e) {
log.error('Markdown conversion failed, using escape fallback:', e);