How to remove other html tags except the p tag in Paste?

I have problems with my built-in text editor. a simple user has permission to copy paste on a textarea div. no problem with that. but I don't want them to insert html with images and div elements.

I used

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

Deletes the content style p tags.

for this, but it is not a solution according to my requirements.

and I also tried with paste_postprocess, but did nothing with the latest version of tinymce.

and I also tried many solutions that 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 that I can prevent copying by disabling the right click. but that would not be a good idea.

Is there a way to filter only p tagwith stylefrom html content?

So, if someone worked on copy pastewith the latest versions tinymce.

Please, help.

+4
source share
2 answers

You need to explicitly tell TinyMCE which attributes to keep when using the parameter valid_elements. For example, using the previous list valid_elements, you can do something like this:

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

This tells TinyMCE to only save the listed tags and keep the attributes stylespecific to the tags p. Alternatively, you can also include all the attributes for a specific element by following these steps:

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

, TinyMCE, , p .

valid_elements, .

+3

: img, div, p

( )

paste- > savetext. tinymce , tinymce

tinymce.activeEditor.getContent();

img,div. , on paste

tinymce setup:

setup : function(ed) {
        ed.on('paste',function(e){
           setTimeout(function(){
               var textContent = tinymce.activeEditor.getContent();
                   tinymce.activeEditor.selection.setContent(textContent.trim());
           },200);  
        });
   }

.

@Nate Kibler .

-1

Source: https://habr.com/ru/post/1545324/


All Articles