File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -415,9 +415,15 @@ ${html}
415415 renderer . link = function ( { href, title, tokens } : Tokens . Link ) {
416416 const text = this . parser . parseInline ( tokens )
417417 const titleAttr = title ? ` title="${ title } "` : ''
418- const plainText = text . replace ( / < [ ^ > ] * > / g, '' ) . trim ( )
418+ let plainText = text . replace ( / < [ ^ > ] * > / g, '' ) . trim ( )
419+
420+ // If plain text is empty, check if we have an image with alt text
421+ if ( ! plainText && tokens . length === 1 && tokens [ 0 ] ?. type === 'image' ) {
422+ plainText = tokens [ 0 ] . text
423+ }
419424
420- const intermediateTitleAttr = `${ ` data-title-intermediate="${ plainText || title } "` } `
425+ const intermediateTitleAttr =
426+ plainText || title ? ` data-title-intermediate="${ plainText || title } "` : ''
421427
422428 return `<a href="${ href } "${ titleAttr } ${ intermediateTitleAttr } >${ text } </a>`
423429 }
Original file line number Diff line number Diff line change @@ -62,6 +62,19 @@ describe('Playground Link Extraction', () => {
6262 expect ( result . playgroundLinks ) . toHaveLength ( 1 )
6363 expect ( result . playgroundLinks [ 0 ] ! . provider ) . toBe ( 'codesandbox' )
6464 } )
65+
66+ it ( 'extracts label from image link' , async ( ) => {
67+ const markdown = `[](https://codesandbox.io/s/example-abc123)`
68+ const result = await renderReadmeHtml ( markdown , 'test-pkg' )
69+
70+ expect ( result . playgroundLinks ) . toHaveLength ( 1 )
71+ expect ( result . playgroundLinks [ 0 ] ) . toMatchObject ( {
72+ provider : 'codesandbox' ,
73+ providerName : 'CodeSandbox' ,
74+ label : 'Edit CodeSandbox' ,
75+ url : 'https://codesandbox.io/s/example-abc123' ,
76+ } )
77+ } )
6578 } )
6679
6780 describe ( 'Other Providers' , ( ) => {
You can’t perform that action at this time.
0 commit comments