fix: convert markdown bold/italic to HTML in Telegram thinking blocks (#523)
This commit is contained in:
@@ -88,6 +88,14 @@ describe('formatReasoningDisplay', () => {
|
||||
expect(result.text).toBe('<blockquote expandable><b>Thinking</b>\na < b & c > d</blockquote>');
|
||||
});
|
||||
|
||||
it('converts markdown bold and italic to HTML tags in telegram output', () => {
|
||||
const result = formatReasoningDisplay('**Responding with warmth**\nSome text with *emphasis* here', 'telegram');
|
||||
expect(result.parseMode).toBe('HTML');
|
||||
expect(result.text).toBe(
|
||||
'<blockquote expandable><b>Thinking</b>\n<b>Responding with warmth</b>\nSome text with <i>emphasis</i> here</blockquote>',
|
||||
);
|
||||
});
|
||||
|
||||
it('formats non-signal/telegram channels as markdown blockquote', () => {
|
||||
const result = formatReasoningDisplay('line 1\n line 2', 'discord');
|
||||
expect(result).toEqual({ text: '> **Thinking**\n> line 1\n> line 2' });
|
||||
|
||||
@@ -231,13 +231,18 @@ export function formatReasoningDisplay(
|
||||
return { text: `**Thinking**\n_${truncated}_` };
|
||||
}
|
||||
if (channelId === 'telegram' || channelId === 'telegram-mtproto') {
|
||||
// Telegram: use HTML blockquote to bypass telegramify-markdown spacing
|
||||
// Telegram: use HTML blockquote to bypass telegramify-markdown spacing.
|
||||
// Convert basic markdown inline formatting to HTML tags so bold/italic
|
||||
// render correctly instead of showing raw ** and * characters.
|
||||
const escaped = truncated
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>');
|
||||
const html = escaped
|
||||
.replace(/\*\*(.+?)\*\*/g, '<b>$1</b>')
|
||||
.replace(/\*(.+?)\*/g, '<i>$1</i>');
|
||||
return {
|
||||
text: `<blockquote expandable><b>Thinking</b>\n${escaped}</blockquote>`,
|
||||
text: `<blockquote expandable><b>Thinking</b>\n${html}</blockquote>`,
|
||||
parseMode: 'HTML',
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user