Skip to content

The agent that grows with you

fix(desktop): an explicit markdown link inside directive-like text stays clickable

Teknium601491feb37d
diff --git a/apps/desktop/src/lib/markdown-preprocess.directives.test.ts b/apps/desktop/src/lib/markdown-preprocess.directives.test.ts
index 5351dad085d..40d681b0b8b 100644
--- a/apps/desktop/src/lib/markdown-preprocess.directives.test.ts
+++ b/apps/desktop/src/lib/markdown-preprocess.directives.test.ts
@@ -103,6 +103,12 @@ describe('preprocessMarkdown / directive attributes holding URLs', () => {
])
expect(directiveAttrs(tree.children[1]?.children?.[0]?.value ?? '')).toEqual({ url })
})
+
+ it('keeps an explicit markdown link inside directive-like text clickable', () => {
+ const children = rendered('::example{\nSee [docs](https://example.com)\n}').children[0]?.children ?? []
+
+ expect(children.filter(child => child.type === 'link').map(child => child.url)).toEqual(['https://example.com'])
+ })
})
function directiveAttrs(text: string) {
diff --git a/apps/desktop/src/lib/transcript-directives.ts b/apps/desktop/src/lib/transcript-directives.ts
index 0ce4d9de236..62b9521d2ce 100644
--- a/apps/desktop/src/lib/transcript-directives.ts
+++ b/apps/desktop/src/lib/transcript-directives.ts
@@ -87,8 +87,18 @@ function inlineText(node: MdNode): string | null {
// A GFM literal autolink keeps its source verbatim, backslash escapes
// included (preprocess escapes `_`/`&`/`~` inside directives); a URL never
// holds a literal `\`, so drop the CommonMark escapes to get it as written.
+ // Only a literal autolink (its text IS its URL) folds: an explicit
+ // `[label](url)` is the author's link and stays clickable.
if (node.type === 'link' && node.children?.every(child => child.type === 'text')) {
- return node.children.map(child => (child.value ?? '').replace(/\\([!-/:-@[-`{-~])/g, '$1')).join('')
+ // GFM keeps the escapes in both the literal's text and its url, so compare them raw.
+ const raw = node.children.map(child => child.value ?? '').join('')
+ const url = (node as MdNode & { url?: string }).url ?? ''
+
+ if (raw !== url && `http://${raw}` !== url && `mailto:${raw}` !== url) {
+ return null
+ }
+
+ return raw.replace(/\\([!-/:-@[-`{-~])/g, '$1')
}
return null