Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to filter unwanted HTML tags in RichText component #7591

Open
mirka opened this issue Jun 27, 2018 · 3 comments
Open

Add ability to filter unwanted HTML tags in RichText component #7591

mirka opened this issue Jun 27, 2018 · 3 comments
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Type] Enhancement A suggestion for improvement.
Milestone

Comments

@mirka
Copy link
Member

mirka commented Jun 27, 2018

Is your feature request related to a problem? Please describe.

We don't have much control over what a user pastes into a RichText. The clipboard might contain HTML tags that are inappropriate for the intended use.

For example, I would want to prevent users from pasting a link (e.g. <a href="#">foo</a>) into a RichText intended to be a button.

Describe the solution you'd like

Some possibilities:

  • Allow onPaste handlers on RichText: Then the consumer could strip out unwanted clipboard content onPaste, or even use the plaintext version (event.clipboardData.getData( 'text/plain' )).
  • Add an allowedTags property on RichText: The consumer could pass it an array of acceptable HTML tagNames, and then RichText would handle the onPaste filtering for us.

Describe alternatives you've considered

  • Use onPaste on a wrapper div: While onCopy can be handled this way, it looks like onPaste must be set on the RichText component itself.

  • Try doing it onChange: This poses another set of problems, where any kind of string manipulation in an onChange–setState in React breaks CJK IME input, unless we add a workaround with composition event detection. (Related)

    For example, doing something like this would make CJK input unusable:

    <RichText
      tagName="div"
      value={ this.state.text }
      onChange={ ( value ) => this.setState( { text: value[0].replace( 'foo', 'bar' ) } ) }
    />
    
@mirka mirka mentioned this issue Jun 27, 2018
11 tasks
@danielbachhuber danielbachhuber added [Type] Enhancement A suggestion for improvement. [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Feature] Extensibility The ability to extend blocks or the editing experience labels Jun 28, 2018
@danielbachhuber danielbachhuber added this to the WordPress 5.0 milestone Jun 28, 2018
@rmorse
Copy link
Contributor

rmorse commented Aug 21, 2018

Hey @mirka, I've been digging around a lot of this stuff recently and thought, it might be possible to do what you want already.

Would having access to the TinyMCE editor within RichText help you do the filtering? (I'm thinking it would be possible if you did, I think you can access the paste handlers from the TinyMCE editor)

If so, I can explain further, otherwise I may have jumped the gun ;)

@paaljoachim
Copy link
Contributor

What actionable items can be done here?
Should it be closed?

@paaljoachim
Copy link
Contributor

@tellthemachines I am wondering if you might have something to add to this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

6 participants