Skip to content

Commit a81faa9

Browse files
fix: remove html comments from package description and deprecation notices (#1397)
1 parent c37a321 commit a81faa9

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-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: <!-- ... --> (including unclosed comments from truncation)
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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,36 @@ 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+
348+
it('strips unclosed HTML comments (truncated)', () => {
349+
const processed = useMarkdown({ text: 'A library <!-- automd:badges color=yel' })
350+
expect(processed.value).toBe('A library ')
351+
})
352+
})
321353
})

0 commit comments

Comments
 (0)