@@ -358,6 +358,82 @@ describe('paste-markdown', function () {
358358 assert . equal ( textarea . value , markdownSentence )
359359 } )
360360
361+ it ( 'finds the right link when identical labels are present chrome and edge' , function ( ) {
362+ // eslint-disable-next-line github/unescaped-html-literal
363+ const sentence = `<meta charset='utf-8'>
364+ <p>foo bar<br>bar<span> </span><a href="https://www.abcxyz.org/">bar</a></p><p>bar<span> </span><a href="https://www.abcxyz.com/">bar</a><span> </span>foo</p>`
365+
366+ const markdownSentence = `foo bar
367+ bar [bar](https://www.abcxyz.org/)
368+
369+ bar [bar](https://www.abcxyz.com/) foo`
370+
371+ const plaintextSentence = `foo bar
372+ bar bar
373+
374+ bar bar foo`
375+
376+ paste ( textarea , { 'text/html' : sentence , 'text/plain' : plaintextSentence } )
377+ assert . equal ( textarea . value , markdownSentence )
378+ } )
379+
380+ it ( 'finds the right link when identical labels are present firefox' , function ( ) {
381+ // eslint-disable-next-line github/unescaped-html-literal
382+ const sentence = `<meta charset='utf-8'>
383+ <div><div><p>foo bar<br>
384+ bar <a href="https://www.abcxyz.org/">bar</a></p>
385+ <p>bar <a href="https://www.abcxyz.com/">bar</a> foo</p></div></div>`
386+ const markdownSentence = `foo bar
387+ bar [bar](https://www.abcxyz.org/)
388+
389+ bar [bar](https://www.abcxyz.com/) foo`
390+
391+ const plaintextSentence = `foo bar
392+ bar bar
393+
394+ bar bar foo`
395+
396+ paste ( textarea , { 'text/html' : sentence , 'text/plain' : plaintextSentence } )
397+ assert . equal ( textarea . value , markdownSentence )
398+ } )
399+
400+ it ( 'pastes markdown with links correctly when identical labels are present' , function ( ) {
401+ // eslint-disable-next-line github/unescaped-html-literal
402+ const sentence = `<meta charset='utf-8'><span>
403+ foo bar baz <a href="https://www.abcxyz.com/">bar</a></span>`
404+ const plaintextSentence = 'foo bar baz bar'
405+ const markdownSentence = 'foo bar baz [bar](https://www.abcxyz.com/)'
406+
407+ paste ( textarea , { 'text/html' : sentence , 'text/plain' : plaintextSentence } )
408+ assert . equal ( textarea . value , markdownSentence )
409+ } )
410+
411+ it ( 'pastes markdown with line breaks and links correctly when identical labels are present' , function ( ) {
412+ // eslint-disable-next-line github/unescaped-html-literal
413+ const sentence = `<meta charset='utf-8'>
414+ <p>foo bar
415+ bar baz <a href="https://www.abcxyz.org/">bar</a> </p>
416+ <p>baz <a href="https://www.abcxyz.com/">baz</a> foo</p>`
417+ const plaintextSentence = 'foo bar bar baz bar baz baz foo'
418+ const markdownSentence = 'foo bar bar baz [bar](https://www.abcxyz.org/) baz [baz](https://www.abcxyz.com/) foo'
419+
420+ paste ( textarea , { 'text/html' : sentence , 'text/plain' : plaintextSentence } )
421+ assert . equal ( textarea . value , markdownSentence )
422+ } )
423+
424+ it ( 'pastes markdown with multiple links and labels correctly' , function ( ) {
425+ // eslint-disable-next-line i18n-text/no-en
426+ const commonSentence = 'Great example for example resources for developers'
427+ // eslint-disable-next-line github/unescaped-html-literal
428+ const sentence = `<meta charset='utf-8'><span>
429+ ${ commonSentence } : <a href="https://www.example.com/">example</a> and <a href="https://www.example.com/">example</a>.</span>`
430+ const plaintextSentence = `${ commonSentence } : example and example.`
431+ const markdownSentence = `${ commonSentence } : [example](https://www.example.com/) and [example](https://www.example.com/).`
432+
433+ paste ( textarea , { 'text/html' : sentence , 'text/plain' : plaintextSentence } )
434+ assert . equal ( textarea . value , markdownSentence )
435+ } )
436+
361437 it ( 'finds the right link when identical labels are present' , function ( ) {
362438 // eslint-disable-next-line github/unescaped-html-literal
363439 const sentence = `<meta charset='utf-8'><span>example<span> </span>
0 commit comments