File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -415,7 +415,12 @@ ${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
420425 const intermediateTitleAttr = `${ ` data-title-intermediate="${ plainText || title } "` } `
421426
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