kapouer
September 24, 2017, 2:54pm
1
Hi,
i’m trying to handle this scenario:
a user copies an embed code (typically, on youtube)
then pastes it into the editor
However, the pasted snippet is html markup pasted as text/plain.
clipboardTextParser(text) -> slice
would do the job, but it cannot parse the text properly because it’s missing the $context variable.
Would you accept a PR with this change ?
kapouer
September 24, 2017, 3:12pm
2
marijn
September 25, 2017, 7:28am
3
Yes, that makes sense. Merged!
kapouer
September 25, 2017, 5:05pm
4
Cool !
However, having no less than FIVE hooks in parseFromClipboard looks like suspicious design.
Couldn’t it be simplified ?
kapouer
September 25, 2017, 5:10pm
5
Also to make the conversation easier, here’s what i did that motivated the pull request:
clipboardTextParser: function(str, $context) {
if (/^<iframe\s.*>.*<\/iframe>$/igm.test(str) == false) return;
var doc = document.cloneNode(false);
var dom = doc.createElement('div');
dom.innerHTML = str;
var parser = editor.someProp("clipboardParser") || editor.someProp("domParser") || Model.DOMParser.fromSchema(editor.state.schema);
return parser.parseSlice(dom, {preserveWhitespace: true, context: $context});
},
marijn
September 25, 2017, 6:25pm
6
Do you have any specific proposal?
kapouer
September 25, 2017, 7:23pm
7
I don’t know, maybe simply allow overriding the whole parseFromClipboard function ?
marijn
September 26, 2017, 6:27am
8
That would make it impossible to ‘mix in’ transformers from different addons, and would require people overriding it to get all the details, such as pasting into code and creating the proper slice, right in their implementations. If you want to completely redefine paste behavior, you can already do that with handlePaste
.