Skip to content

pasteConfig ignores tool's sanitize rules - style attributes stripped before onPaste receives element #2984

@Levan-D

Description

@Levan-D

When pasting HTML content, the sanitizer strips attributes from elements before they reach the tool's onPaste method, even when the tool's static get sanitize() explicitly allows those attributes.

Steps to reproduce:

  1. Create a custom Block Tool with pasteConfig for P tags and sanitize rules to preserve style:
class MyTool {
  static get pasteConfig() {
    return {
      tags: ['P', 'DIV']
    };
  }

  static get sanitize() {
    return {
      p: {
        style: true  
      }
    };
  }

static get pasteConfig() {
  return {
    tags: ['P', 'DIV', 'SPAN', 'PRE', 'CODE', 'BR']
  };
}

  onPaste(event) {
    if (event.type === 'tag') {
      const element = event.detail.data;
      console.log('Received element:', element.outerHTML);
      console.log('Style attribute:', element.getAttribute('style'));
    }
  }
}
  1. Sanitizer rules at Editor config level:
 sanitizer: {
    br: true,
    b: true,
    i: true,
    a: {
      href: true
    }
  }
  1. Copy content from Google Docs that has paragraph indentation (which comes as CSS text-indent: 36pt or margin-left: 36pt in the clipboard HTML)

  2. Paste into Editor.js

Expected behavior:

<p style="text-indent: 36pt;">Lorem ipsum...</p>

Actual behavior

<p><span>Lorem ipsum...</span></p>

Version: "@editorjs/editorjs": "^2.29.0",

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions