Search code examples
jquerytinymce

Tinymce paste includes styles


I have a tinymce form and it's working for the most part, but when I copy something from either the internet or a word processor and try and paste it in, the inline styles stay with it.

I have tried to solve this a few ways already, but have had no luck. It seems like this style tag is haunting me!

I would just remove the style tag altogether, and I did try this, but when I do that nullifies the styles you can add in the tinymce, such as text align...and I don't really want to do that.

This is what I have at the moment, you can see I was trying to remove the styles on paste, but it's just not working. Some help would be much appreciated!

tinyMCE.init({
mode : "exact",
elements : "wStory",
plugins : "paste",
theme: "advanced",
width: "80em",
height: "700px",
paste_auto_cleanup_on_paste : true,
paste_remove_styles: true,
paste_remove_styles_if_webkit: true,
paste_strip_class_attributes: true,
theme_advanced_buttons1:"bold,italic,underline,strikethrough,hr,|,justifyleft,justifycenter,justifyright,justifyfull,outdent, indent,|,cleanup,|,forecolor, |,undo,redo,|,link, unlink",
theme_advanced_toolbar_location:"top",
theme_advanced_toolbar_align:"center",
theme_advanced_resizing:false,
width:"100%",height:"700px",
invalid_elements: "span, div",
theme_advanced_path:false,
setup : function(ed) {
    ed.onInit.add(function(ed) {
    ed.pasteAsPlainText = true;
});
},

});


Solution

  • For some odd reason, nothing I did work in the latest tinymce. I hope this helps someone else who runs into this

      cleanup_on_startup : true,
      fix_list_elements : false,
      fix_nesting : false,
      fix_table_elements : false,
      paste_use_dialog : true,
      paste_auto_cleanup_on_paste : true,
    

    I had to paste these in the init function. This allows for it to post plain text and then when the user places styles like centering it adds a paragraph tags around the specified text