Skip to content

Commit 2c60b35

Browse files
fix: remove html comments from package description and deprecation notices
1 parent 4db33e9 commit 2c60b35

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

app/composables/useMarkdown.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ function stripAndEscapeHtml(text: string, packageName?: string): string {
3737
// Only match tags that start with a letter or / (to avoid matching things like "a < b > c")
3838
stripped = stripped.replace(/<\/?[a-z][^>]*>/gi, '')
3939

40+
// Strip HTML comments: <!-- ... -->
41+
stripped = stripped.replace(/<!--[\s\S]*?-->/g, '')
42+
4043
if (packageName) {
4144
// Trim first to handle leading/trailing whitespace from stripped HTML
4245
stripped = stripped.trim()

test/nuxt/composables/use-markdown.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,31 @@ describe('useMarkdown', () => {
318318
expect(processed.value).toBe('bold and <strong>also bold</strong>')
319319
})
320320
})
321+
322+
describe('HTML comment stripping', () => {
323+
it('strips HTML comments', () => {
324+
const processed = useMarkdown({ text: '<!-- automd:badges color=yellow -->A library' })
325+
expect(processed.value).toBe('A library')
326+
})
327+
328+
it('strips HTML comments from the middle of text', () => {
329+
const processed = useMarkdown({ text: 'Before <!-- comment --> after' })
330+
expect(processed.value).toBe('Before after')
331+
})
332+
333+
it('strips multiple HTML comments', () => {
334+
const processed = useMarkdown({ text: '<!-- first -->Text <!-- second -->here' })
335+
expect(processed.value).toBe('Text here')
336+
})
337+
338+
it('strips multiline HTML comments', () => {
339+
const processed = useMarkdown({ text: '<!-- multi\nline\ncomment -->Text' })
340+
expect(processed.value).toBe('Text')
341+
})
342+
343+
it('returns empty string when description is only a comment', () => {
344+
const processed = useMarkdown({ text: '<!-- automd:badges color=yellow -->' })
345+
expect(processed.value).toBe('')
346+
})
347+
})
321348
})

0 commit comments

Comments
 (0)