Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion server/utils/readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`}`

Expand Down
13 changes: 13 additions & 0 deletions test/unit/server/utils/readme.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading