(text: string)
| 64 | } |
| 65 | |
| 66 | function formatTelegramInline(text: string): string { |
| 67 | let formatted = escapeHtml(text); |
| 68 | |
| 69 | formatted = formatted.replace(LINK_RE, (_, label: string, url: string) => { |
| 70 | return `<a href="${escapeHtmlAttribute(url)}">${escapeHtml(label)}</a>`; |
| 71 | }); |
| 72 | formatted = formatted.replace( |
| 73 | /^(#{1,6})[ \t]+(.+)$/gm, |
| 74 | (_, __: string, content: string) => `<b>${content.trim()}</b>`, |
| 75 | ); |
| 76 | formatted = formatted.replace(/\*\*([^*\n]+)\*\*/g, "<b>$1</b>"); |
| 77 | formatted = formatted.replace(/__([^_\n]+)__/g, "<b>$1</b>"); |
| 78 | formatted = formatted.replace( |
| 79 | /(^|[^\w<])\*([^*\n]+)\*(?=[^\w>]|$)/g, |
| 80 | "$1<i>$2</i>", |
| 81 | ); |
| 82 | formatted = formatted.replace( |
| 83 | /(^|[^\w<])_([^_\n]+)_(?=[^\w>]|$)/g, |
| 84 | "$1<i>$2</i>", |
| 85 | ); |
| 86 | formatted = formatted.replace(/^(?:-|\*) /gm, "• "); |
| 87 | |
| 88 | return formatted; |
| 89 | } |
| 90 | |
| 91 | export function formatSlackMessage(text: string): string { |
| 92 | const unwrapped = unwrapMarkdownSourceBlocks(text); |
no test coverage detected