Skip to content

Commit 6049a73

Browse files
committed
feat: manage link in package description
1 parent 66935c6 commit 6049a73

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

app/components/MarkdownText.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ function parseMarkdown(text: string): string {
3434
// Strikethrough: ~~text~~
3535
html = html.replace(/~~(.+?)~~/g, '<del>$1</del>')
3636
37+
// Links: [text](url) - only allow http, https, mailto
38+
html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, text, url) => {
39+
const decodedUrl = url.replace(/&amp;/g, '&')
40+
if (/^(https?:|mailto:)/i.test(decodedUrl)) {
41+
return `<a href="${decodedUrl}" rel="nofollow noreferrer noopener" target="_blank">${text}</a>`
42+
}
43+
return `${text} (${url})`
44+
})
45+
3746
return html
3847
}
3948

0 commit comments

Comments
 (0)