From 1816ab47ea66afe6e6d337bb1436df1609ec991e Mon Sep 17 00:00:00 2001 From: rzzf Date: Fri, 13 Feb 2026 18:14:55 +0800 Subject: [PATCH 1/2] fix: extract label from image-only playground links --- server/utils/readme.ts | 7 ++++++- test/unit/server/utils/readme.spec.ts | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/server/utils/readme.ts b/server/utils/readme.ts index 9920eb2af..919b8285c 100644 --- a/server/utils/readme.ts +++ b/server/utils/readme.ts @@ -415,7 +415,12 @@ ${html} renderer.link = function ({ href, title, tokens }: Tokens.Link) { const text = this.parser.parseInline(tokens) const titleAttr = title ? ` title="${title}"` : '' - const plainText = text.replace(/<[^>]*>/g, '').trim() + let plainText = text.replace(/<[^>]*>/g, '').trim() + + // If plain text is empty, check if we have an image with alt text + if (!plainText && tokens.length === 1 && tokens[0]?.type === 'image') { + plainText = tokens[0].text + } const intermediateTitleAttr = `${` data-title-intermediate="${plainText || title}"`}` diff --git a/test/unit/server/utils/readme.spec.ts b/test/unit/server/utils/readme.spec.ts index 08db45be2..9dc6464c9 100644 --- a/test/unit/server/utils/readme.spec.ts +++ b/test/unit/server/utils/readme.spec.ts @@ -62,6 +62,19 @@ describe('Playground Link Extraction', () => { expect(result.playgroundLinks).toHaveLength(1) expect(result.playgroundLinks[0]!.provider).toBe('codesandbox') }) + + it('extracts label from image link', async () => { + const markdown = `[![Edit CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/example-abc123)` + const result = await renderReadmeHtml(markdown, 'test-pkg') + + expect(result.playgroundLinks).toHaveLength(1) + expect(result.playgroundLinks[0]).toMatchObject({ + provider: 'codesandbox', + providerName: 'CodeSandbox', + label: 'Edit CodeSandbox', + url: 'https://codesandbox.io/s/example-abc123', + }) + }) }) describe('Other Providers', () => { From 98029471840b740d7920d27b5ccc02d437f96432 Mon Sep 17 00:00:00 2001 From: rzzf Date: Fri, 13 Feb 2026 19:28:02 +0800 Subject: [PATCH 2/2] fix: fallback provider name --- server/utils/readme.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/utils/readme.ts b/server/utils/readme.ts index 919b8285c..a76e6442b 100644 --- a/server/utils/readme.ts +++ b/server/utils/readme.ts @@ -422,7 +422,8 @@ ${html} plainText = tokens[0].text } - const intermediateTitleAttr = `${` data-title-intermediate="${plainText || title}"`}` + const intermediateTitleAttr = + plainText || title ? ` data-title-intermediate="${plainText || title}"` : '' return `${text}` }