That’s the Quill library.
Me neither, really. I just did a bit of searching and that was what came up.
Nonetheless, here’s something of an explanation:
Quill has a concept of modules, which allow Quill’s behavior and functionality to be customized. The Clipboard module is required by Quill and does not need to be included explicitly.
The Clipboard handles copy, cut and paste between Quill and external applications. This has an API which allows us to customize this behaviour. We can do this with matchers and the addMatcher
method.
// Initialize Quill
const quill = new Quill('#editor', {
...
}
// Add a matcher
quill.cliboard.addMatcher(selector, (node, delta) => {
// Code to customize the clipboard behavior here
});
For a description of what matchers, nodes and deltas are, please refer to the Clipboard module’s docs (linked above).
By following the docs and examples I found on Stack Overflow, I was able to get the following matcher to work for me and to strip out any formatting on paste:
quill.clipboard.addMatcher (Node.ELEMENT_NODE, (node, delta) => {
const plaintext = node.innerText;
const Delta = Quill.import('delta');
return new Delta().insert(plaintext);
});
Here is the complete code so that you can run it in context. I took the setup code from Quill’s quick start page.
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="utf-8">
<title>Quill clipboard demo</title>
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
</head>
<body>
<div id="editor">
<p>Hello World!</p>
<p>Some initial <strong>bold</strong> text</p>
<p><br></p>
</div>
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<script>
const quill = new Quill('#editor', {
theme: 'snow',
});
quill.clipboard.addMatcher (Node.ELEMENT_NODE, (node, delta) => {
const plaintext = node.innerText;
const Delta = Quill.import('delta');
return new Delta().insert(plaintext);
});
</script>
</body>
</html>
To see the demo in action try copy/pasting any formatted text (from this thread, for example). With the matcher active, it should be inserted as plain text. If you delete the matcher, it should retain its formatting.