File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,9 @@ function onPaste(event: ClipboardEvent) {
3030 // Generate DOM tree from HTML string
3131 const parser = new DOMParser ( )
3232 const doc = parser . parseFromString ( textHTMLClean , 'text/html' )
33- const walker = doc . createTreeWalker ( doc . body , NodeFilter . SHOW_ELEMENT )
33+ const walker = doc . createTreeWalker ( doc . body , NodeFilter . SHOW_ELEMENT , node =>
34+ node . parentNode && isLink ( node . parentNode ) ? NodeFilter . FILTER_REJECT : NodeFilter . FILTER_ACCEPT
35+ )
3436
3537 const markdown = convertToMarkdown ( plaintext , walker )
3638
Original file line number Diff line number Diff line change @@ -148,6 +148,18 @@ describe('paste-markdown', function () {
148148 assert . equal ( textarea . value , markdownSentence )
149149 } )
150150
151+ it ( 'deals with links with nested html' , function ( ) {
152+ // eslint-disable-next-line github/unescaped-html-literal
153+ const sentence = `<a href="https://example.com/"><span>foo</span></a>
154+ <a href="https://example.com/">bar</a>
155+ foo bar`
156+ const plaintextSentence = 'foo bar foo bar'
157+ const markdownSentence = '[foo](https://example.com/) [bar](https://example.com/) foo bar'
158+
159+ paste ( textarea , { 'text/html' : sentence , 'text/plain' : plaintextSentence } )
160+ assert . equal ( textarea . value , markdownSentence )
161+ } )
162+
151163 it ( "doesn't render any markdown for html link without corresponding plaintext" , function ( ) {
152164 // eslint-disable-next-line github/unescaped-html-literal
153165 const link = `<meta charset='utf-8'><a href="https://github.com/monalisa/playground/issues/1">
You can’t perform that action at this time.
0 commit comments