Index: src/wp-includes/js/tinymce/plugins/paste/plugin.js
===================================================================
--- src/wp-includes/js/tinymce/plugins/paste/plugin.js (revision 27859)
+++ src/wp-includes/js/tinymce/plugins/paste/plugin.js (working copy)
@@ -579,6 +579,11 @@
removePasteBin();
+ // Always use pastebin HTML if it's available since it contains Word contents
+ if (!plainTextMode && isKeyBoardPaste && html && html != pasteBinDefaultContent) {
+ clipboardContent['text/html'] = html;
+ }
+
if (html == pasteBinDefaultContent || !isKeyBoardPaste) {
html = clipboardContent['text/html'] || clipboardContent['text/plain'] || pasteBinDefaultContent;
@@ -700,7 +705,10 @@
"tinymce/pasteplugin/Utils"
], function(Tools, DomParser, Schema, Serializer, Node, Utils) {
function isWordContent(content) {
- return (/"),t&&/^(PRE|DIV)$/.test(t.nodeName)||!a?e=n.filter(e,[[/\n/g,"
"]]):(e=n.filter(e,[[/\n\n/g,"
)$/,o+"$1"],[/\n/g,"
"]]),-1!=e.indexOf("
")&&(e=o+e)),r(e)}function o(){var t=i.dom,n=i.getBody(),r=i.dom.getViewPort(i.getWin()),a=r.y,o=20,s;if(h=i.selection.getRng(),i.inline&&(s=i.selection.getScrollContainer(),s&&(a=s.scrollTop)),h.getClientRects){var c=h.getClientRects();if(c.length)o=a+(c[0].top-t.getPos(n).y);else{o=a;var l=h.startContainer;l&&(3==l.nodeType&&l.parentNode!=n&&(l=l.parentNode),1==l.nodeType&&(o=t.getPos(l,s||n).y))}}v=t.add(i.getBody(),"div",{id:"mcepastebin",contentEditable:!0,"data-mce-bogus":"1",style:"position: absolute; top: "+o+"px;width: 10px; height: 10px; overflow: hidden; opacity: 0"},b),(e.ie||e.gecko)&&t.setStyle(v,"left","rtl"==t.getStyle(n,"direction",!0)?65535:-65535),t.bind(v,"beforedeactivate focusin focusout",function(e){e.stopPropagation()}),v.focus(),i.selection.select(v,!0)}function s(){if(v){for(var e;e=i.dom.get("mcepastebin");)i.dom.remove(e),i.dom.unbind(e);h&&i.selection.setRng(h)}x=!1,v=h=null}function c(){var e=b,t,n;for(t=i.dom.select("div[id=mcepastebin]"),n=t.length;n--;){var r=t[n].innerHTML;e==b&&(e=""),r.length>e.length&&(e=r)}return e}function l(e){var t={};if(e&&e.types){var n=e.getData("Text");n&&n.length>0&&(t["text/plain"]=n);for(var i=0;i
$/i])}function s(e){if(!n.isWordContent(e))return e;var a=[];t.each(r.schema.getBlockElements(),function(e,t){a.push(t)});var o=new RegExp("(?:
[\\s\\r\\n]+|
)*(<\\/?("+a.join("|")+")[^>]*>)(?:
[\\s\\r\\n]+|
)*","g");return e=i.filter(e,[[o,"$1"]]),e=i.filter(e,[[/
/g,"
"],[/
/g," "],[/
/g,"
"]])}function c(e){return(r.settings.paste_remove_styles||r.settings.paste_remove_styles_if_webkit!==!1)&&(e=e.replace(/ style=\"[^\"]+\"/g,"")),e}e.webkit&&(a(c),a(o)),e.ie&&a(s)}}),i(b,[x,d,g,y],function(e,t,n,i){var r;e.add("paste",function(e){function a(){"text"==s.pasteFormat?(this.active(!1),s.pasteFormat="html"):(s.pasteFormat="text",this.active(!0),r||(e.windowManager.alert("Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off."),r=!0))}var o=this,s,c=e.settings;o.clipboard=s=new t(e),o.quirks=new i(e),o.wordFilter=new n(e),e.settings.paste_as_text&&(o.clipboard.pasteFormat="text"),c.paste_preprocess&&e.on("PastePreProcess",function(e){c.paste_preprocess.call(o,o,e)}),c.paste_postprocess&&e.on("PastePostProcess",function(e){c.paste_postprocess.call(o,o,e)}),e.addCommand("mceInsertClipboardContent",function(e,t){t.content&&o.clipboard.pasteHtml(t.content),t.text&&o.clipboard.pasteText(t.text)}),e.paste_block_drop&&e.on("dragend dragover draggesture dragdrop drop drag",function(e){e.preventDefault(),e.stopPropagation()}),e.settings.paste_data_images||e.on("drop",function(e){var t=e.dataTransfer;t&&t.files&&t.files.length>0&&e.preventDefault()}),e.addButton("pastetext",{icon:"pastetext",tooltip:"Paste as text",onclick:a,active:"text"==o.clipboard.pasteFormat}),e.addMenuItem("pastetext",{text:"Paste as text",selectable:!0,active:s.pasteFormat,onclick:a})})}),o([c,d,g,y,b])}(this);
\ No newline at end of file
+!function(e,t){"use strict";function n(e,t){for(var n,i=[],r=0;r
"]]):(e=n.filter(e,[[/\n\n/g,"
)$/,a+"$1"],[/\n/g,"
"]]),-1!=e.indexOf("
")&&(e=a+e)),r(e)}function a(){var t=i.dom,n=i.getBody(),r=i.dom.getViewPort(i.getWin()),o=r.y,a=20,s;if(v=i.selection.getRng(),i.inline&&(s=i.selection.getScrollContainer(),s&&(o=s.scrollTop)),v.getClientRects){var l=v.getClientRects();if(l.length)a=o+(l[0].top-t.getPos(n).y);else{a=o;var c=v.startContainer;c&&(3==c.nodeType&&c.parentNode!=n&&(c=c.parentNode),1==c.nodeType&&(a=t.getPos(c,s||n).y))}}h=t.add(i.getBody(),"div",{id:"mcepastebin",contentEditable:!0,"data-mce-bogus":"1",style:"position: absolute; top: "+a+"px;width: 10px; height: 10px; overflow: hidden; opacity: 0"},y),(e.ie||e.gecko)&&t.setStyle(h,"left","rtl"==t.getStyle(n,"direction",!0)?65535:-65535),t.bind(h,"beforedeactivate focusin focusout",function(e){e.stopPropagation()}),h.focus(),i.selection.select(h,!0)}function s(){if(h){for(var e;e=i.dom.get("mcepastebin");)i.dom.remove(e),i.dom.unbind(e);v&&i.selection.setRng(v)}x=!1,h=v=null}function l(){var e=y,t,n;for(t=i.dom.select("div[id=mcepastebin]"),n=t.length;n--;){var r=t[n].innerHTML;e==y&&(e=""),r.length>e.length&&(e=r)}return e}function c(e){var t={};if(e&&e.types){var n=e.getData("Text");n&&n.length>0&&(t["text/plain"]=n);for(var i=0;i
$/i])}function s(e){if(!n.isWordContent(e))return e;var o=[];t.each(r.schema.getBlockElements(),function(e,t){o.push(t)});var a=new RegExp("(?:
[\\s\\r\\n]+|
)*(<\\/?("+o.join("|")+")[^>]*>)(?:
[\\s\\r\\n]+|
)*","g");return e=i.filter(e,[[a,"$1"]]),e=i.filter(e,[[/
/g,"
"],[/
/g," "],[/
/g,"
"]])}function l(e){return n.isWordContent(e)?e:((r.settings.paste_remove_styles||r.settings.paste_remove_styles_if_webkit!==!1)&&(e=e.replace(/ style=\"[^\"]+\"/gi,"")),e)}e.webkit&&(o(l),o(a)),e.ie&&o(s)}}),i(y,[x,f,g,b],function(e,t,n,i){var r;e.add("paste",function(e){function o(){"text"==s.pasteFormat?(this.active(!1),s.pasteFormat="html"):(s.pasteFormat="text",this.active(!0),r||(e.windowManager.alert("Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off."),r=!0))}var a=this,s,l=e.settings;a.clipboard=s=new t(e),a.quirks=new i(e),a.wordFilter=new n(e),e.settings.paste_as_text&&(a.clipboard.pasteFormat="text"),l.paste_preprocess&&e.on("PastePreProcess",function(e){l.paste_preprocess.call(a,a,e)}),l.paste_postprocess&&e.on("PastePostProcess",function(e){l.paste_postprocess.call(a,a,e)}),e.addCommand("mceInsertClipboardContent",function(e,t){t.content&&a.clipboard.pasteHtml(t.content),t.text&&a.clipboard.pasteText(t.text)}),e.paste_block_drop&&e.on("dragend dragover draggesture dragdrop drop drag",function(e){e.preventDefault(),e.stopPropagation()}),e.settings.paste_data_images||e.on("drop",function(e){var t=e.dataTransfer;t&&t.files&&t.files.length>0&&e.preventDefault()}),e.addButton("pastetext",{icon:"pastetext",tooltip:"Paste as text",onclick:o,active:"text"==a.clipboard.pasteFormat}),e.addMenuItem("pastetext",{text:"Paste as text",selectable:!0,active:s.pasteFormat,onclick:o})})}),a([l,f,g,b,y])}(this);
\ No newline at end of file
Index: src/wp-includes/js/tinymce/plugins/wordpress/plugin.js
===================================================================
--- src/wp-includes/js/tinymce/plugins/wordpress/plugin.js (revision 27859)
+++ src/wp-includes/js/tinymce/plugins/wordpress/plugin.js (working copy)
@@ -270,6 +270,86 @@
}
});
+ // Additional paste filtering
+ editor.on( 'PastePreProcess', function( event ) {
+ event.content = event.content.replace( /<[a-z1-6]+ [^>]+>/gi, function( match ) {
+ // Remove these by default
+ if ( editor.getParam( 'wp_paste_strip_classes', true ) ) {
+ match = match.replace( / class="[^"]+"/gi, '' ).replace( / class=[\-\w]+/gi, '' );
+ }
+
+ if ( editor.getParam( 'wp_paste_strip_ids', true ) ) {
+ match = match.replace( / id="[^"]+"/gi, '' ).replace( / id=[\-\w]+/gi, '' );
+ }
+
+ if ( editor.getParam( 'wp_paste_strip_tabindex', true ) ) {
+ match = match.replace( / tabindex="[^"]+"/gi, '' ).replace( / tabindex=[\-\d]+/gi, '' );
+ }
+
+ if ( editor.getParam( 'wp_paste_remove_spans' ) ) {
+ match = match.replace( /<\/?span[^>]*>/gi, '' );
+ // is converted to with inline style on cleanup
+ match = match.replace( /<\/?font[^>]*>/gi, '' );
+ }
+
+ return match;
+ });
+ });
+
+ editor.on( 'PastePostProcess', function( event ) {
+ var dom = editor.dom,
+ styleProps = editor.getParam( 'wp_paste_keep_inline_styles', 'font-weight, font-style, color' );
+
+ if ( ! styleProps || typeof styleProps !== 'string' || styleProps === 'none' ) {
+ styleProps = false;
+ } else if ( styleProps === 'all' ) {
+ styleProps = '';
+ } else {
+ styleProps = tinymce.explode( styleProps );
+ }
+
+ tinymce.each( dom.select( '*', event.node ), function( el ) {
+ var styleName, styleValue, i,
+ newStyle = {},
+ npc = 0;
+
+ // Remove empty paragraphs
+ if ( el.nodeName === 'P' && dom.isEmpty( el ) ) {
+ dom.remove( el );
+ return;
+ }
+
+ // Store a subset of the existing styles
+ if ( styleProps ) {
+ for ( i = 0; i < styleProps.length; i++ ) {
+ styleName = styleProps[i];
+ styleValue = dom.getStyle( el, styleName );
+
+ if ( el.nodeName === 'A' && styleName === 'color' ) {
+ continue;
+ }
+
+ if ( styleValue && styleValue !== 'normal' && styleValue !== 'inherit' ) {
+ newStyle[styleName] = styleValue;
+ npc++;
+ }
+ }
+ }
+
+ if ( styleProps !== '' ) {
+ dom.setAttrib( el, 'style', '' );
+ }
+
+ if ( styleProps && npc > 0 ) {
+ dom.setStyles( el, newStyle ); // Add back the stored subset of styles
+ } else { // Remove empty span tags that do not have class attributes
+ if ( el.nodeName == 'SPAN' && ! el.className ) {
+ dom.remove( el, true );
+ }
+ }
+ });
+ });
+
editor.on( 'init', function() {
var env = tinymce.Env,
bodyClass = ['mceContentBody'], // back-compat for themes that use this in editor-style.css...