@@ -55,7 +55,9 @@ function convertToMarkdown(plaintext: string, walker: TreeWalker): string {
5555 // Walk through the DOM tree
5656 while ( currentNode && index < NODE_LIMIT ) {
5757 index ++
58- const text = isLink ( currentNode ) ? currentNode . textContent || '' : ( currentNode . firstChild as Text ) ?. wholeText || ''
58+ const text = isLink ( currentNode )
59+ ? ( currentNode . textContent || '' ) . replace ( / [ \t \n \r ] + / g, ' ' )
60+ : ( currentNode . firstChild as Text ) ?. wholeText || ''
5961
6062 // No need to transform whitespace
6163 if ( isEmptyString ( text ) ) {
@@ -68,7 +70,7 @@ function convertToMarkdown(plaintext: string, walker: TreeWalker): string {
6870
6971 if ( markdownFoundIndex >= 0 ) {
7072 if ( isLink ( currentNode ) ) {
71- const markdownLink = linkify ( currentNode )
73+ const markdownLink = linkify ( currentNode , text )
7274 // Transform 'example link plus more text' into 'example [link](example link) plus more text'
7375 // Method: 'example [link](example link) plus more text' = 'example ' + '[link](example link)' + ' plus more text'
7476 markdown =
@@ -99,8 +101,7 @@ function hasHTML(transfer: DataTransfer): boolean {
99101}
100102
101103// Makes markdown link from a link element, avoiding special GitHub links
102- function linkify ( element : HTMLAnchorElement ) : string {
103- const label = element . textContent || ''
104+ function linkify ( element : HTMLAnchorElement , label : string ) : string {
104105 const url = element . href || ''
105106 let markdown = ''
106107
0 commit comments