ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

How to control the execution order of inputTransformation event listeners?

Open bkosborne opened this issue 1 year ago • 2 comments

I've written a simple plugin that strips all <span> and <div> elements from pasted HTML. I do this because when people paste content from sources like Google Docs or MS Word, lots of empty spans and divs can be created. However, I want to ensure that my plugin's event listener executes after all others. I see that I can set a priority for the subscriber, which defaults to "normal". But, if I change it to "lower" or "lowest", it doesn't execute at all.

Here's the code:

this.editor.plugins
      .get("ClipboardPipeline")
      .on("inputTransformation", (evt, data) => {
        const writer = new UpcastWriter(data.content);

        // Scan all divs and spans and save them for later removal.
        let elementsToUnwrap = [];

        const range = writer.createRangeIn( data.content );
        for (const value of range) {
          if (value.item.is( 'element', 'span') || value.item.is( 'element', 'div')) {
            // We can't just unwrap it here, as it seems to affect the scan
            // for other elements.
            elementsToUnwrap.push(value.item);
          }
        }
        for (const item of elementsToUnwrap) {
          writer.unwrapElement(item);
        }
      });

I believe my event listener is executing before the Paste from Office plugin.

bkosborne avatar Mar 12 '24 13:03 bkosborne

Any updates on this? Even I am facing similar issue

mvprabhu-ma avatar May 30 '24 07:05 mvprabhu-ma

There has been no activity on this issue for the past year. We've marked it as stale and will close it in 30 days. We understand it may still be relevant, so if you're interested in the solution, leave a comment or reaction under this issue.

CKEditorBot avatar Jun 06 '25 23:06 CKEditorBot

We've closed your issue due to inactivity. We understand that the issue may still be relevant. If so, feel free to open a new one (and link this issue to it).

CKEditorBot avatar Jul 07 '25 23:07 CKEditorBot