From 5ccc9bb37a5bd82abe7b1548ba420797ff4993e4 Mon Sep 17 00:00:00 2001 From: Cameron Pfiffer Date: Tue, 25 Aug 2026 21:18:50 -0700 Subject: [PATCH] Render formatting inside safe Markdown links. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Link labels now parse their inline tokens so emphasis survives without relaxing URL or raw HTML filtering. 👾 Generated with [Letta Code](https://letta.com) Co-Authored-By: Letta Code --- src/markdown.test.ts | 13 +++++++++++++ src/markdown.ts | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/markdown.test.ts b/src/markdown.test.ts index d7a3742..fc4b513 100644 --- a/src/markdown.test.ts +++ b/src/markdown.test.ts @@ -57,6 +57,19 @@ test("safe Markdown mode keeps HTML examples inert inside code fences", async () assert.match(html, /
 {
+  const html = await renderMarkdown(
+    "[*An Economy of AI Agents*](https://example.com/economy) [**blocked label**](javascript:alert(1))",
+    { allowRawHtml: false },
+  );
+
+  assert.equal(
+    html,
+    '

An Economy of AI Agents blocked label

\n', + ); + assert.doesNotMatch(html, /\*An Economy|javascript:/); +}); + test("safe Markdown mode denies executable link and image protocols", async () => { const html = await renderMarkdown( "[run](javascript:alert(1)) [encoded](javascript:alert(1)) ![payload](data:image/svg+xml,evil) [slash](\\\\evil.example/path) [encoded-slash](\\evil.example/path) ![slash-image](\\\\evil.example/payload.svg) [source](https://example.com/) [local](/knowledge/example)", diff --git a/src/markdown.ts b/src/markdown.ts index 1a271bd..eadf882 100644 --- a/src/markdown.ts +++ b/src/markdown.ts @@ -78,9 +78,9 @@ export async function renderMarkdown( return allowRawHtml ? text : escapeHtml(text); }, ...(!allowRawHtml ? { - link({ href, title, text }) { + link({ href, title, tokens }) { const safeHref = safeMarkdownUrl(href, true); - const label = escapeHtml(text); + const label = this.parser.parseInline(tokens); if (!safeHref) return label; const titleAttribute = title ? ` title="${escapeHtml(title)}"` : ""; return `${label}`; -- 2.51.2