2
votes

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;
});
},

});

1
CKeditor (an alternative to TinyMCE) has a "paste plain" button. I think there may be a similar plugin available for TinyMCE. The easiest short-term solution would be to paste into a plain-text editor like Notepad, then copy from there. - Matt Browne
I know, but I'm building a website for people who won't do that, that's why I'm trying to use tinymce. I'm trying to idiot proof my site. They won't know how to use a paste plain button, and I don't like how these pasted style tags brake my css. - zazvorniki
Re: idiot-proofing your site - The idiots will find a way! :) But this is a noble intention, and certainly pasting without styles by default is a good start. I believe the above link should solve it for you. - Matt Browne
Thank you for the link. Unfortuitly, I already tried every one of those suggestions, and not one of them worked. And yes, the idiots will find a way, but I have to make it harder don't I? :) - zazvorniki

1 Answers

2
votes

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