During the last days I have revived complaints from our editors regarding that to much junk gets pasted into the XHtml text-editors.
I decided to try to clear all the class and styles and other junk during paste (CTRL+ V) in to XHtml editor. Eliminating the old paste to notepad first approach.
It is of great concern to keep the editorial text as clean as possible for SEO and other purposes.
This was not as straight forward as you can imagine….
After spending more then a day looking through all the documentation for Tiny and EPiServer I decided to try making my own plugin override.
We already had one plugin override but this seemed not to work as I wanted.
The problem is the default implementation of the paste.js plugin found here: \modules\_protected\CMS\EPiServer.Cms.Shell.UI.zip\Util\Editor\tinymce\plugins\paste\
I wanted CTRL+ V to completely clear all the style and class data but the default setting shipped with EPiServer is set to:
paste_strip_class_attributes : “mso”
This means clear class defind in MS Word but keep class from web sites.
To accomplish the task I simply created a new class and added the TinyMCEPluginNonVisual attribute.
What this plugin simply does is sticking the “paste as plain text” button in on mode and then some…
Here is how to do this
[TinyMCEPluginNonVisual( PlugInName = "DefaultSettings", AlwaysEnabled = true, EditorInitConfigurationOptions = @"{ paste_text_sticky : true, paste_text_sticky_default: true, paste_auto_cleanup_on_paste : true, paste_strip_class_attributes: 'all', formats: { removeformat : [ {selector : 'b,strong,em,i,font,u,strike,h1,h2,h3,h4,h5,h6', remove : 'all', split : true, expand : false, block_expand : true, deep : true}, {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true}, {selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true} ] }, extended_valid_elements : 'td[style|data-mce-style|class|align|valign|title|hspace|vspace|width|height|scope|name]' }")] public class DefaultSettingsPlugin { }
Thats it!
This will simpley override the original paste.js with the new settings.
This can be applied to all the TinyMCE plugins.