Skip to content

Commit ddc09ed

Browse files
refactor: use css for external readme link
Co-authored-by: Alex Savelyev <91429106+alexdln@users.noreply.github.com>
1 parent e1cc821 commit ddc09ed

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

app/components/Readme.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ function handleClick(event: MouseEvent) {
126126
@apply decoration-accent text-accent;
127127
}
128128
129+
.readme :deep(a[target='_blank']::after) {
130+
content: '';
131+
@apply i-carbon:launch rtl-flip ms-1 size-[1em] opacity-50;
132+
}
133+
129134
.readme :deep(code) {
130135
@apply font-mono;
131136
font-size: 0.875em;

server/utils/readme.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,6 @@ ${html}
399399
const isExternal = resolvedHref.startsWith('http://') || resolvedHref.startsWith('https://')
400400
const relAttr = isExternal ? ' rel="nofollow noreferrer noopener"' : ''
401401
const targetAttr = isExternal ? ' target="_blank"' : ''
402-
const isExternalIcon = isExternal
403-
? `<span
404-
class="i-carbon:launch inline-block rtl-flip ms-1 size-[1em] opacity-50"
405-
aria-hidden="true"
406-
></span>`
407-
: ''
408402

409403
// Check if this is a playground link
410404
const provider = matchPlaygroundProvider(resolvedHref)
@@ -424,7 +418,7 @@ ${html}
424418

425419
const hrefValue = resolvedHref.startsWith('#') ? resolvedHref.toLowerCase() : resolvedHref
426420

427-
return `<a href="${hrefValue}"${titleAttr}${relAttr}${targetAttr}>${text}${isExternalIcon}</a>`
421+
return `<a href="${hrefValue}"${titleAttr}${relAttr}${targetAttr}>${text}</a>`
428422
}
429423

430424
// 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
@@ -346,7 +346,7 @@ describe('Markdown Content Extraction', () => {
346346
const result = await renderReadmeHtml(markdown, 'test-pkg')
347347

348348
expect(result.html).toBe(`<h3 id="user-content-title" data-level="1">Title</h3>
349-
<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>
349+
<p>Some <strong>bold</strong> text and a <a href="https://example.com" rel="nofollow noreferrer noopener" target="_blank">link</a>.</p>
350350
`)
351351
})
352352
})

0 commit comments

Comments
 (0)