Skip to content

Commit

Permalink
fix(60): keep pasted links (#62)
Browse files Browse the repository at this point in the history
* fix(60): keep pasted links
* chore: update version
  • Loading branch information
visualjerk authored Sep 3, 2021
1 parent e142e90 commit 9478bb1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quill-magic-url",
"version": "4.1.2",
"version": "4.1.3",
"description": "Checks for URLs during typing and pasting and automatically converts them to links.",
"main": "dist/index.js",
"babel": {
Expand Down
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ export default class MagicUrl {
this.registerBlurListener()
}
registerPasteListener() {
// Preserves existing links
this.quill.clipboard.addMatcher('A', (node, delta) => {
const href = node.getAttribute('href')
const attributes = delta.ops[0].attributes
if (attributes != null && attributes.link != null) {
attributes.link = href
}
return delta
})
this.quill.clipboard.addMatcher(Node.TEXT_NODE, (node, delta) => {
if (typeof node.data !== 'string') {
return
Expand Down
7 changes: 7 additions & 0 deletions tests/e2e/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,12 @@ describe('quill-magic-url', () => {
'i want to be preserved <a href="http://test.de" target="_blank">http://test.de</a> my little pony <a href="http://www.google.com" target="_blank">www.google.com</a> look a mail <a href="mailto:[email protected]" target="_blank">[email protected]</a> bam!'
)
})

it('does not alter existing links', () => {
paste('<a href="http://www.google.com">http://test.de</a>')
shouldContain(
'<p><a href="http://www.google.com" target="_blank">http://test.de</a></p>'
)
})
})
})

0 comments on commit 9478bb1

Please sign in to comment.