Skip to content

Commit 7ae58e6

Browse files
authored
fix: render markdown in deprecated blocks in package docs (#446)
1 parent 5cab540 commit 7ae58e6

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

app/pages/docs/[...path].vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,16 @@ const showEmptyState = computed(() => docsData.value?.status !== 'ok')
364364
@apply text-badge-orange text-sm;
365365
}
366366
367-
.docs-content .docs-deprecated p {
368-
@apply text-badge-orange text-sm mt-2 mb-0;
367+
.docs-content .docs-deprecated-message {
368+
@apply text-badge-orange text-sm mt-2;
369+
}
370+
371+
.docs-content .docs-deprecated-message code {
372+
@apply bg-badge-orange/20 text-badge-orange;
373+
}
374+
375+
.docs-content .docs-deprecated-message .docs-link {
376+
@apply text-badge-orange;
369377
}
370378
371379
/* Parameters, Returns, Examples, See Also sections */

server/utils/docs/render.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ async function renderJsDocTags(tags: JsDocTag[], symbolLookup: SymbolLookup): Pr
184184
lines.push(`<div class="docs-deprecated">`)
185185
lines.push(`<strong>Deprecated</strong>`)
186186
if (deprecated.doc) {
187-
lines.push(`<p>${parseJsDocLinks(deprecated.doc, symbolLookup)}</p>`)
187+
// We remove new lines because they look weird when rendered into the deprecated block
188+
// I think markdown is actually supposed to collapse single new lines automatically but this function doesn't do that so if that changes remove this
189+
const renderedMessage = await renderMarkdown(deprecated.doc.replace(/\n/g, ' '), symbolLookup)
190+
lines.push(`<div class="docs-deprecated-message">${renderedMessage}</div>`)
188191
}
189192
lines.push(`</div>`)
190193
}

server/utils/docs/text.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function parseJsDocLinks(text: string, symbolLookup: SymbolLookup): strin
7575

7676
// External URL
7777
if (target.startsWith('http://') || target.startsWith('https://')) {
78-
return `<a href="${target}" target="_blank" rel="noopener" class="docs-link">${displayText}</a>`
78+
return `<a href="${target}" target="_blank" rel="noreferrer" class="docs-link">${displayText}</a>`
7979
}
8080

8181
// Internal symbol reference
@@ -116,6 +116,12 @@ export async function renderMarkdown(text: string, symbolLookup: SymbolLookup):
116116
// Now process the rest (JSDoc links, HTML escaping, etc.)
117117
result = parseJsDocLinks(result, symbolLookup)
118118

119+
// Markdown links - i.e. [text](url)
120+
result = result.replace(
121+
/\[([^\]]+)\]\((https?:\/\/[^)]+)\)/g,
122+
'<a href="$2" target="_blank" rel="noreferrer" class="docs-link">$1</a>',
123+
)
124+
119125
// Handle inline code (single backticks) - won't interfere with fenced blocks
120126
result = result
121127
.replace(/`([^`]+)`/g, '<code class="docs-inline-code">$1</code>')

test/unit/docs-text.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('parseJsDocLinks', () => {
7878
const result = parseJsDocLinks('{@link https://example.com}', emptyLookup)
7979
expect(result).toContain('href="https://example.com"')
8080
expect(result).toContain('target="_blank"')
81-
expect(result).toContain('rel="noopener"')
81+
expect(result).toContain('rel="noreferrer"')
8282
})
8383

8484
it('should handle external URLs with labels', () => {
@@ -252,4 +252,14 @@ describe('renderMarkdown', () => {
252252
expect(result).toContain('<code class="docs-inline-code">code</code>')
253253
expect(result).toContain('shiki')
254254
})
255+
256+
it('should handle basic markdown links', async () => {
257+
const result = await renderMarkdown(
258+
'This [thing](https://example.com) is really important',
259+
emptyLookup,
260+
)
261+
expect(result).toContain(
262+
'This <a href="https://example.com" target="_blank" rel="noreferrer" class="docs-link">thing</a> is really important',
263+
)
264+
})
255265
})

0 commit comments

Comments
 (0)