@@ -382,6 +382,66 @@ describe('paste-markdown', function () {
382382 paste ( textarea , data )
383383 assert . include ( textarea . value , tableMarkdown )
384384 } )
385+
386+ it ( 'pastes markdown with links correctly when identical labels are present' , function ( ) {
387+ // eslint-disable-next-line github/unescaped-html-literal
388+ const sentence = `<meta charset='utf-8'><span>
389+ foo bar baz <a href="https://www.abcxyz.com/">bar</a></span>`
390+ const plaintextSentence = 'foo bar baz bar'
391+ const markdownSentence = 'foo bar baz [bar](https://www.abcxyz.com/)'
392+
393+ paste ( textarea , { 'text/html' : sentence , 'text/plain' : plaintextSentence } )
394+ assert . equal ( textarea . value , markdownSentence )
395+ } )
396+
397+ it ( 'pastes markdown with line breaks and links correctly when identical labels are present' , function ( ) {
398+ // eslint-disable-next-line github/unescaped-html-literal
399+ const sentence = `<meta charset='utf-8'>
400+ <p>foo bar
401+ bar baz <a href="https://www.abcxyz.org/">bar</a> </p>
402+ <p>baz <a href="https://www.abcxyz.com/">baz</a> foo</p>`
403+ const plaintextSentence = 'foo bar bar baz bar baz baz foo'
404+ const markdownSentence = 'foo bar bar baz [bar](https://www.abcxyz.org/) baz [baz](https://www.abcxyz.com/) foo'
405+
406+ paste ( textarea , { 'text/html' : sentence , 'text/plain' : plaintextSentence } )
407+ assert . equal ( textarea . value , markdownSentence )
408+ } )
409+
410+ it ( 'pastes markdown with multiple links and labels correctly' , function ( ) {
411+ // eslint-disable-next-line i18n-text/no-en
412+ const commonSentence = 'Great example for example resources for developers'
413+ // eslint-disable-next-line github/unescaped-html-literal
414+ const sentence = `<meta charset='utf-8'><span>
415+ ${ commonSentence } : <a href="https://www.example.com/">example</a> and <a href="https://www.example.com/">example</a>.</span>`
416+ const plaintextSentence = `${ commonSentence } : example and example.`
417+ const markdownSentence = `${ commonSentence } : [example](https://www.example.com/) and [example](https://www.example.com/).`
418+
419+ paste ( textarea , { 'text/html' : sentence , 'text/plain' : plaintextSentence } )
420+ assert . equal ( textarea . value , markdownSentence )
421+ } )
422+
423+ it ( 'pastes markdown with link labels that contains special characters in html' , function ( ) {
424+ // eslint-disable-next-line github/unescaped-html-literal
425+ const sentence = `<meta charset='utf-8'>
426+ <p>foo&bar <a href="https://www.abcxyz.org/">foo bar</a> <a href="https://example.com/?q=foo&bar=baz">foo&bar</a></p>`
427+ const plaintextSentence = 'foo&bar foo bar foo&bar'
428+ const markdownSentence =
429+ 'foo&bar [foo bar](https://www.abcxyz.org/) [foo&bar](https://example.com/?q=foo&bar=baz)'
430+
431+ paste ( textarea , { 'text/html' : sentence , 'text/plain' : plaintextSentence } )
432+ assert . equal ( textarea . value , markdownSentence )
433+ } )
434+
435+ it ( 'pastes markdown with link labels that contains emojis in html' , function ( ) {
436+ // eslint-disable-next-line github/unescaped-html-literal
437+ const sentence = `<meta charset='utf-8'>
438+ <p>foo bar <a href="https://www.abcxyz.org/">foo</a> bar foo <a href="https://example.com/">π bar π</a></p>`
439+ const plaintextSentence = 'foo bar foo bar foo π bar π'
440+ const markdownSentence = 'foo bar [foo](https://www.abcxyz.org/) bar foo [π bar π](https://example.com/)'
441+
442+ paste ( textarea , { 'text/html' : sentence , 'text/plain' : plaintextSentence } )
443+ assert . equal ( textarea . value , markdownSentence )
444+ } )
385445 } )
386446} )
387447
0 commit comments