Skip to content

HTML-tags of newly registered formats disappear when pasting #13292

@websupporter

Description

@websupporter

Describe the bug
I registered a new format type. Lets say: <span class="great-class">. When I copy a text now into the Component, the span.great-class tags get removed:

Received HTML:
df df <span class="great-class">df</span> df df. editor.min.js:55:146144
Received plain text:
df df df df df. editor.min.js:55:146187
Processed inline HTML:
df df df df df. blocks.min.js:2:115611

To Reproduce

const {createElement} = window.wp.element;
const {registerFormatType, toggleFormat} = window.wp.richText;
const {RichTextToolbarButton} = window.wp.editor;

registerFormatType('some/type', {
    title: 'Title',
    tagName: 'span',
    className: 'great-class',
    edit({ isActive, value, onChange}) {
        const onClick = () => {
            onChange(toggleFormat(value, { type: 'some/type' }));
        };

        return (
            createElement(RichTextToolbarButton, {
                icon: 'admin-home',
                title: 'Title',
                onClick,
                isActive,
                shortcutType: 'primary',
                shortcutCharacter: '8',
            })
        )
    }
});
  1. Add this script
  2. Add a text in a RichText component
  3. Select a part of the text and click the new button in the toolbar
  4. Copy all the text in the clipboard
  5. Paste the text in a RichText component
  6. See error

Expected behavior
The new format should survive the copy/pasting

Screenshots
https://www.youtube.com/watch?v=9SiyAROa1Iw

Desktop (please complete the following information):

  • OS: Ubuntu 14.04
  • Browser Firefox

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions