Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove other html tags except p tag on Paste?

I am having a little trouble with my inline text editor. it is simple user has permission to copy paste on the textarea div. no problem with that. but i dont want let them paste html with images, and div elements.

I have used

valid_elements: "p,br,b,i,strong,em",

it removes the style of p tags content.

to do this but this is not the solution according to my requirements.

and i also tried with paste_postprocess but it didn't do anything with latest version of tinymce.

and i have also tried many solutions which are already posted in this community. but none of them work for me because i am using the latest version tinymce 4.0.26.

i know i can prevent copy paste by disabling right click. but that will not be a good idea.

Is there any way to filter only p tag with style from html content?

So if anybody has worked on copy paste with the latest versions of tinymce.

Please help.

like image 561
Shail Paras Avatar asked Sep 30 '22 12:09

Shail Paras


1 Answers

You need to explicitly tell TinyMCE what attributes to keep when using the valid_elements option. For example, using your previous valid_elements list, you might do something like this:

valid_elements: "p[style],br,b,i,strong,em"

This tells TinyMCE to only keep the tags listed and to keep any style attributes defined for p tags. Alternatively, you can also include all attributes for a specific element by doing this:

valid_elements: "p[*],br,b,i,strong,em"

Again, this tells TinyMCE to keep all of the tags listed, but for the p tag, keep every attribute defined.

For more information on the syntax of this valid_elements selector, check out this page.

like image 53
Nate Kibler Avatar answered Oct 13 '22 11:10

Nate Kibler