-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.js
30 lines (23 loc) · 907 Bytes
/
plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
CKEDITOR.plugins.add('ck-pastepurified', {
init: function (editor) {
// Highest priority
var priority = 1;
editor.on('paste', function (evt) {
if (!(typeof DOMPurify === "object" && typeof DOMPurify.sanitize === "function"))
{
try
{
console.log("Include purify.js from DOMPurify to enable the pastepurified plugin for CKEditor.");
}
// Silently discard error
catch (e) {}
return;
}
var html = evt.data.dataValue;
// DOMPurify.sanitize() will return the input untreated when the browser isn't supported
html = DOMPurify.sanitize(html);
// Update the event to contain the 'purified' HTML
evt.data.dataValue = html;
}, null, null, priority);
}
});