diff --git a/extensions/telegram/src/format-render.ts b/extensions/telegram/src/format-render.ts index 3530bf595d4..10f8d6f1fec 100644 --- a/extensions/telegram/src/format-render.ts +++ b/extensions/telegram/src/format-render.ts @@ -15,7 +15,11 @@ export function renderTelegramMarkdownIR( ir: MarkdownIR, options: { escapeText: (text: string) => string; - buildLink: (link: MarkdownLinkSpan, text: string) => TelegramRenderLink | null; + buildLink: ( + link: MarkdownLinkSpan, + text: string, + context: { origin: "authored" | "linkify" }, + ) => TelegramRenderLink | null; buildCodeBlockOpen: (span: { language?: string }) => string; }, ): string { diff --git a/extensions/telegram/src/format.ts b/extensions/telegram/src/format.ts index d036d9c6c80..663fa353b09 100644 --- a/extensions/telegram/src/format.ts +++ b/extensions/telegram/src/format.ts @@ -49,7 +49,11 @@ function isTelegramRichLinkHref(href: string): boolean { * * Excluded: .ai, .io, .tv, .fm (popular domain TLDs like x.ai, vercel.io, github.io) */ -function buildTelegramLink(link: MarkdownLinkSpan, text: string) { +function buildTelegramLink( + link: MarkdownLinkSpan, + text: string, + context: { origin: "authored" | "linkify" }, +) { const href = link.href.trim(); if (!href) { return null; @@ -64,7 +68,7 @@ function buildTelegramLink(link: MarkdownLinkSpan, text: string) { } // Suppress auto-linkified file references (e.g. README.md → http://README.md) const label = text.slice(link.start, link.end); - if (isAutoLinkedFileRef(href, label)) { + if (context.origin === "linkify" && isAutoLinkedFileRef(href, label)) { return null; } const safeHref = escapeHtmlAttr(href); @@ -178,7 +182,6 @@ function escapeRegex(str: string): string { return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); } -const AUTO_LINKED_ANCHOR_PATTERN = /]*>\1<\/a>/gi; const HTML_MODE_TAG_PATTERN = /^<(\/?)([a-zA-Z][a-zA-Z0-9-]*)([^<>]*)>$/; const ESCAPED_HTML_TAG_PATTERN = /<(\/?)([a-zA-Z][a-zA-Z0-9-]*)(.*?)>/g; const TELEGRAM_HTML_ANCHOR_PATTERN = @@ -499,15 +502,6 @@ function wrapSegmentFileRefs( } export function wrapFileReferencesInHtml(html: string): string { - // Safety-net: de-linkify auto-generated anchors where href="http://