Clipboard Documentation/Examples
Hi guys,
Thank you for this nice editor ;)
I am using quilljs 1.0.0 beta, from what I read the behaviour on paste can be customized thanks to Clipboard.
But I haven't found documentation/examples about that. Could you point me to some of these?
I was happy with quilljs behaviour before, if I am not wrong it allowed to paste only those tags available on the specified formats. It would be nice to reproduce this behaviour with quilljs 1.0.0 again, or at least to copy only the text without format as ctrl + shift + v can do.
Anyone can give me a clue if this can be done and how?
Thanks a lot in advance!
Keep pushing forward! :D
Not sure if this was missed this or if something was unclear there but details on the Clipboard and customizing it can be found on its own documentation. Quill 0.20 allows a whitelist of formats which is still available in 1.0 in its configuration options. If you want to completely remove pasted formatting then it might be best to remove the Clipboard matchers that add formatting.
Thanks @jhchen
I read it that before, but I couldn't guess how to do what I needed with that description. I miss more real examples there. So I thought maybe there was something else. Notice that even I don't know how to do what you suggested "to remove the Clipboard matchers" with that documentation.
Anyway I was playing with the playground on the page, pasting content works I would expect there. So I have spent the full morning trying to guess what was the problem and it seems it was related with having custom.snow.css included... Finally what I did was to upgrade it to the last version beta.9... and redo some work based on this version.
Thanks again!
Thanks for the feedback. I'll work on making the docs more clear.
@jhchen it would really help to do this. I've spent an hour trying to either override or disable the built in clipboard without any luck. It's extremely frustrating.
What specific pages of documentation have you looked at and what have tried?
I too like @adamkdean have trouble understanding how the addMatcher( ) should work... I have been studying the examples here https://quilljs.com/docs/modules/clipboard/ and have been trying to reproduce them but they do not work. Or maybe I might be doing something wrong because I have noticed that when I am pasting simple text or something with a < b > tag (as in the examples) the addMatcher( ) callback function is never called!
Also it would be nice if there was some documentation that lets you know what String formats the addMatcher accepts as its first parameter, for e.g. "B" is for < b > but I have no idea what works for < a >, is it "A" or "a" or none of these? It would be nice if there was a list somewhere listing all the possible options that Quill.js recognizes...
@nitaskenderi As it states in the addMatcher docs it takes a CSS selector. Both "A" and "a" are valid CSS selectors. CSS selectors are too complex to enumerate the possibilities but it's also a common enough technology that I do not see it as Quill's role to explain.
Yes that is how I understood it.. Well then I must be having some trouble using the actual function. Here is how I have been trying to use it:
messageBox = new Quill('#' + containerId, {
placeholder: 'Write a message...',
modules: {
"toolbar": false,
keyboard: {
bindings:
{ enter: {
key: 13,
handler: handleEnter
}
}
}
}
});
messageBox.clipboard.addMatcher('B', function(node, delta) {
//debugger;
return delta.compose(new Delta().retain(delta.length(), { bold: true }));
});
messageBox.clipboard.addMatcher('a', function(node, delta) {
//debugger;
return delta.compose(new Delta().retain(delta.length(), { color: "red"}));
});
So I basically just used the example given in the documentation and then tried to add my own version, but when I paste in html with a < b > tag or a link, it never enters the addMatcher( ) callback function... How do I fix this? I really need to set my own rules for when pasting HTML into the editor because I will only accept two or three HTML elements, everything else has to be pasted as plain text.
Create a minimal complete verifiable example and in another Issue with all fields filled out and someone might be able to help you out. The exercise of making one often reveals the error.
Okay, will do. Thank you!
@jhchen Is it possible to remove one of the default matches? I'm running into a lot of issues with matchSpacing as it adds in extra newlines that screw up email formatting.
Looking through the code it seems like I can only add more, but not specify a set of new matches. I could try to add a matcher with opposite logic that undoes the default one, but doesn't seem like the best solution. It would be hard to know which newlines were automatically added by the matcher and which were intended by the user.
@justinpincar Others have been asking for this as well but Semantic Versioning would dictate that Quill go to 2.0 if it were removed. I could add a config option that would skip this matcher (of course the default of that would have to be false). Would that work?
That would be perfect! Or possibly another config directive along the lines of replaceMatchers that sets new ones instead of appending like the current matchers one does.
Really appreciate the prompt and helpful response! <3
You can now use a new config in 1.3.0 matchVisual to disable Quill's visual paste matching.
Using matchVisual seems to be working great, thank you!
Since I'm using this for composing emails which have no style sheets, I also needed to remove the .ql-editor * { margin: 0; padding: 0;} from quill.snow.scss, otherwise the editor would be really cramped and not match the output.
I can't find matchVisual property in the documentation that you linked. Is there any up to date solution for this problem?
@chillyistkult For some reason, they have removed it from the documentation but the option is still available, you can find the documentation that does include it using WayBackMachine website, link as follows:
https://web.archive.org/web/20170807100811/http://quilljs.com:80/docs/modules/clipboard/
This not in the docs 😱
Is the default behaviour changed in 2.0?
@franciscolourenco No as per my comment above it is not in the docs (although I have provided a link to the archived docs) but it still works in version 1.3.6 which is the version I am using. Sorry, I do not know if it has changed in 2.0 as I am not using that version yet.