fix(ui): render formatting inside markdown link labels (#54451)

This commit is contained in:
Kit Langton
2026-10-11 02:27:08 -07:00
committed by GitHub
Unverified
parent e31136bdbd
commit d21b0790a6
2 changed files with 14 additions and 6 deletions
+2 -2
View File
@@ -3,10 +3,10 @@ import { Marked } from "marked"
export function createMarkdownBase() {
return new Marked({
renderer: {
link({ href, title, text }) {
link({ href, title, tokens }) {
const titleAttr = title ? ` title="${title}"` : ""
return `<a href="${href}"${titleAttr} class="external-link" target="_blank" rel="noopener noreferrer">${text}</a>`
return `<a href="${href}"${titleAttr} class="external-link" target="_blank" rel="noopener noreferrer">${this.parser.parseInline(tokens)}</a>`
},
},
})
+12 -4
View File
@@ -4,10 +4,18 @@ import { parseSmallMarkdown } from "./marked-base"
const parser = createMarkdownParser((code, language) => `<pre data-language="${language}">${code}</pre>`)
test("renders links with application attributes", async () => {
expect(await parser.parse("[OpenCode](https://opencode.ai)")).toBe(
'<p><a href="https://opencode.ai" class="external-link" target="_blank" rel="noopener noreferrer">OpenCode</a></p>\n',
)
test.each([
["OpenCode", "OpenCode"],
["**`#123`**", "<strong><code>#123</code></strong>"],
["*Review* ~~draft~~", "<em>Review</em> <del>draft</del>"],
["`<example>`", "<code>&lt;example&gt;</code>"],
["\\*literal\\*", "*literal*"],
])("renders link label %s with application attributes", async (label, html) => {
const markdown = `[${label}](https://opencode.ai)`
const expected = `<p><a href="https://opencode.ai" class="external-link" target="_blank" rel="noopener noreferrer">${html}</a></p>\n`
expect(await parser.parse(markdown)).toBe(expected)
expect(parseSmallMarkdown(markdown)).toBe(expected)
})
test("renders inline and block math", async () => {