1
votes

I've got 2 CKEditor instances. One editor (A) supporting a number of widgets, another editor B has an Advanced Content Filter with these settings to make sure only <p>, <br>, <em> and <strong> tags are allowed in the second editor:

config.allowedContent = 'p br em strong';

My widget contains an image and some other tags and this filter setting:

config.allowedContent = 'img div figure figcaption';

When text containing this kind of widget from editor A is pasted into editor B, I would like the editor to strip out the widget but it doesn't. This makes sense because the allowedContent setting of the widget makes sure that the image is not removed.

However, my second editor does not know anything about this widget and I would like to configure the filter to strip out all widgets pasted in.

I've tried adding the Disallowed Content setting to editor B:

config.disallowedContent = 'img div span figure figcaption';

But without succes, I keep getting the widget div's in editor B.

Same goes for pasting the widget into editor 4 of the sample editors provided by CKEditor. The widget is inserted even if the ACF does not allow it.

Is there another filter option to prevent widgets from sneaking into the body?

1

1 Answers

2
votes

Unfortunately there's no easy way to filter pasted events with the ACF at the moment - see http://dev.ckeditor.com/ticket/11115. It has the 4.5.0 milestone assigned, but I don't feel that we'll manage to make this change in this version. There are architectural limitations which make this ticket very complex.

What you could try to do is to intercept pasted content on the editor#paste, parse the content and filter pasted widgets manually. The hard thing (the actual #11115 blocker) is that in the pasted content you'll find upcasted versions of widgets, with all wrappers, all internal attributes etc. ACF cannot be applied to this content directly because ACF is supposed to filter downcasted versions of widgets. Therefore you need to filter this more manually or with a special CKEDITOR.filter instance.

You can find this question useful - Apply CKEditor Advanced Content Filter to a string.