Skip to content

Commit df6ecb0

Browse files
committed
feat: add external link indicator to readme
1 parent c0d51ff commit df6ecb0

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

server/utils/readme.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@ ${html}
368368
const isExternal = resolvedHref.startsWith('http://') || resolvedHref.startsWith('https://')
369369
const relAttr = isExternal ? ' rel="nofollow noreferrer noopener"' : ''
370370
const targetAttr = isExternal ? ' target="_blank"' : ''
371+
const isExternalIcon = isExternal
372+
? `<span
373+
class="i-carbon:launch inline-block rtl-flip ms-1 size-[1em] opacity-50"
374+
aria-hidden="true"
375+
/>`
376+
: ''
371377

372378
// Check if this is a playground link
373379
const provider = matchPlaygroundProvider(resolvedHref)
@@ -387,7 +393,7 @@ ${html}
387393

388394
const hrefValue = resolvedHref.startsWith('#') ? resolvedHref.toLowerCase() : resolvedHref
389395

390-
return `<a href="${hrefValue}"${titleAttr}${relAttr}${targetAttr}>${text}</a>`
396+
return `<a href="${hrefValue}"${titleAttr}${relAttr}${targetAttr}>${text}${isExternalIcon}</a>`
391397
}
392398

393399
// GitHub-style callouts: > [!NOTE], > [!TIP], etc.

test/unit/server/utils/readme.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ describe('Markdown Content Extraction', () => {
323323
const result = await renderReadmeHtml(markdown, 'test-pkg')
324324

325325
expect(result.html).toBe(`<h3 id="user-content-title" data-level="1">Title</h3>
326-
<p>Some <strong>bold</strong> text and a <a href="https://example.com" rel="nofollow noreferrer noopener" target="_blank">link</a>.</p>
326+
<p>Some <strong>bold</strong> text and a <a href="https://example.com" rel="nofollow noreferrer noopener" target="_blank">link<span class="i-carbon:launch inline-block rtl-flip ms-1 size-[1em] opacity-50"></span></a>.</p>
327327
`)
328328
})
329329
})

0 commit comments

Comments
 (0)