@@ -55,7 +55,9 @@ function convertToMarkdown(plaintext: string, walker: TreeWalker): string {
55
55
// Walk through the DOM tree
56
56
while ( currentNode && index < NODE_LIMIT ) {
57
57
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 || ''
59
61
60
62
// No need to transform whitespace
61
63
if ( isEmptyString ( text ) ) {
@@ -68,7 +70,7 @@ function convertToMarkdown(plaintext: string, walker: TreeWalker): string {
68
70
69
71
if ( markdownFoundIndex >= 0 ) {
70
72
if ( isLink ( currentNode ) ) {
71
- const markdownLink = linkify ( currentNode )
73
+ const markdownLink = linkify ( currentNode , text )
72
74
// Transform 'example link plus more text' into 'example [link](example link) plus more text'
73
75
// Method: 'example [link](example link) plus more text' = 'example ' + '[link](example link)' + ' plus more text'
74
76
markdown =
@@ -99,8 +101,7 @@ function hasHTML(transfer: DataTransfer): boolean {
99
101
}
100
102
101
103
// 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 {
104
105
const url = element . href || ''
105
106
let markdown = ''
106
107
0 commit comments