Skip to content

Commit 812ff10

Browse files
committed
add more tests
1 parent 1c90905 commit 812ff10

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

β€Žsrc/paste-markdown-html.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function convertToMarkdown(plaintext: string, walker: TreeWalker): string {
6666
? (currentNode.textContent || '').replace(/[\t\n\r ]+/g, ' ')
6767
: (currentNode.firstChild as Text)?.wholeText || ''
6868

69-
// // update current index without link
69+
// update value of markdownIgnoreBeforeIndex with current index if the current node is not a link
7070
if (!isLink(currentNode)) {
7171
markdownIgnoreBeforeIndex += text.replace(/[\t\n\r ]+/g, ' ').trimStart().length
7272
}

β€Žtest/test.jsβ€Ž

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,41 @@ describe('paste-markdown', function () {
384384
paste(textarea, {'text/html': sentence, 'text/plain': plaintextSentence})
385385
assert.equal(textarea.value, markdownSentence)
386386
})
387+
388+
it('pastes markdown with multiple links and labels correctly', function () {
389+
// eslint-disable-next-line i18n-text/no-en
390+
const commonSentence = 'Great example for example resources for developers'
391+
// eslint-disable-next-line github/unescaped-html-literal
392+
const sentence = `<meta charset='utf-8'><span>
393+
${commonSentence}: <a href="https://www.example.com/">example</a> and <a href="https://www.example.com/">example</a>.</span>`
394+
const plaintextSentence = `${commonSentence}: example and example.`
395+
const markdownSentence = `${commonSentence}: [example](https://www.example.com/) and [example](https://www.example.com/).`
396+
397+
paste(textarea, {'text/html': sentence, 'text/plain': plaintextSentence})
398+
assert.equal(textarea.value, markdownSentence)
399+
})
400+
401+
it('pastes markdown with link labels that contains special characters in html', function () {
402+
// eslint-disable-next-line github/unescaped-html-literal
403+
const sentence = `<meta charset='utf-8'>
404+
<a href="https://www.abcxyz.org/">foo bar</a> <a href="https://example.com/?q=foo&bar=baz">foo&bar</a>`
405+
const plaintextSentence = 'foo bar foo&bar'
406+
const markdownSentence = '[foo bar](https://www.abcxyz.org/) [foo&bar](https://example.com/?q=foo&bar=baz)'
407+
408+
paste(textarea, {'text/html': sentence, 'text/plain': plaintextSentence})
409+
assert.equal(textarea.value, markdownSentence)
410+
})
411+
412+
it('pastes markdown with link labels that contains emojis in html', function () {
413+
// eslint-disable-next-line github/unescaped-html-literal
414+
const sentence = `<meta charset='utf-8'>
415+
<p>foo bar <a href="https://www.abcxyz.org/">foo</a> bar foo <a href="https://example.com/">πŸš€ bar πŸš€</a></p>`
416+
const plaintextSentence = 'foo bar foo bar foo πŸš€ bar πŸš€'
417+
const markdownSentence = 'foo bar [foo](https://www.abcxyz.org/) bar foo [πŸš€ bar πŸš€](https://example.com/)'
418+
419+
paste(textarea, {'text/html': sentence, 'text/plain': plaintextSentence})
420+
assert.equal(textarea.value, markdownSentence)
421+
})
387422
})
388423
})
389424

0 commit comments

Comments
Β (0)