diff --git a/app/components/MarkdownText.vue b/app/components/MarkdownText.vue index 492700a3b..e6e2e5ae4 100644 --- a/app/components/MarkdownText.vue +++ b/app/components/MarkdownText.vue @@ -26,6 +26,11 @@ function stripAndEscapeHtml(text: string): string { // First decode any HTML entities in the input let stripped = decodeHtmlEntities(text) + // Check if original text has HTML tags or markdown images BEFORE stripping + // Only strip package name for these "badge-style" descriptions + const hasHtmlTags = /<\/?[a-z][^>]*>/i.test(stripped) + const hasMarkdownImages = /!\[[^\]]*\]\([^)]*\)/.test(stripped) + // Then strip markdown image badges stripped = stripMarkdownImages(stripped) @@ -33,7 +38,9 @@ function stripAndEscapeHtml(text: string): string { // Only match tags that start with a letter or / (to avoid matching things like "a < b > c") stripped = stripped.replace(/<\/?[a-z][^>]*>/gi, '') - if (props.packageName) { + // Only strip package name if original text had HTML tags or markdown images + // Normal descriptions like "Nuxt is a framework..." should keep the package name + if ((hasHtmlTags || hasMarkdownImages) && props.packageName) { // Trim first to handle leading/trailing whitespace from stripped HTML stripped = stripped.trim() // Collapse multiple whitespace into single space diff --git a/test/nuxt/components/MarkdownText.spec.ts b/test/nuxt/components/MarkdownText.spec.ts index 3194fb773..0d4652a48 100644 --- a/test/nuxt/components/MarkdownText.spec.ts +++ b/test/nuxt/components/MarkdownText.spec.ts @@ -259,91 +259,95 @@ describe('MarkdownText', () => { }) describe('packageName prop', () => { - it('strips package name from the beginning of plain text', async () => { + // Package name stripping ONLY happens for descriptions with HTML tags or markdown images + // Normal plain text descriptions should keep the package name (like "Nuxt is a framework...") + + it('does NOT strip package name from plain text descriptions', async () => { + // Plain text descriptions should be kept as-is const component = await mountSuspended(MarkdownText, { props: { text: 'my-package - A great library', packageName: 'my-package', }, }) - expect(component.text()).toBe('A great library') + expect(component.text()).toBe('my-package - A great library') }) - it('strips package name with colon separator', async () => { + it('does NOT strip package name from plain text with colon', async () => { const component = await mountSuspended(MarkdownText, { props: { text: 'my-package: A great library', packageName: 'my-package', }, }) - expect(component.text()).toBe('A great library') + expect(component.text()).toBe('my-package: A great library') }) - it('strips package name with em dash separator', async () => { + it('strips package name from HTML-containing descriptions', async () => { const component = await mountSuspended(MarkdownText, { props: { - text: 'my-package — A great library', + text: 'my-package - A great library', packageName: 'my-package', }, }) expect(component.text()).toBe('A great library') }) - it('strips package name without separator', async () => { + it('strips package name from HTML descriptions with colon separator', async () => { const component = await mountSuspended(MarkdownText, { props: { - text: 'my-package A great library', + text: '