From e977f42a66bc06e58d1c8606e7262a43c3212b23 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 19 Mar 2015 07:07:48 +0000 Subject: [PATCH] TinyMCE: revert stripping of tags from pasted URLs on `beforeSetContent` [31817] and [31819]. Clean up URLs on `pastePreProcess`. See #31158. git-svn-id: https://develop.svn.wordpress.org/trunk@31832 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/tinymce/plugins/wpview/plugin.js | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js index 95128c7856..d5178d62ac 100644 --- a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js @@ -167,41 +167,38 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { // matching view patterns, and transform the matches into // view wrappers. editor.on( 'BeforeSetContent', function( event ) { - var pastedStr = event.content, - trim = tinymce.trim, - node; + var node; - if ( ! pastedStr ) { + if ( ! event.content ) { return; } - if ( selected ) { - removeView( selected ); - } - node = editor.selection.getNode(); - pastedStr = pastedStr.replace( /<[^>]+>/g, '' ); - pastedStr = trim( pastedStr ); - // When a url is pasted, only try to embed it when pasted in an empty paragrapgh. - if ( /^https?:\/\/\S+$/i.test( pastedStr ) ) { - event.content = pastedStr; + if ( event.content.match( /^\s*(https?:\/\/[^\s"]+)\s*$/i ) && + ( node.nodeName !== 'P' || node.parentNode !== editor.getBody() || ! editor.dom.isEmpty( node ) ) ) { - node = editor.dom.getParent( node, function( node ) { - if ( node.parentNode === editor.getBody() ) { - return node; - } - } ); - - if ( node.nodeName !== 'P' || trim( node.textContent || node.innerText ) ) { - return; - } + return; } event.content = wp.mce.views.setMarkers( event.content ); }); + // When pasting strip all tags and check if the string is an URL. + // Then replace the pasted content with the cleaned URL. + editor.on( 'pastePreProcess', function( event ) { + var pastedStr = event.content; + + if ( pastedStr ) { + pastedStr = tinymce.trim( pastedStr.replace( /<[^>]+>/g, '' ) ); + + if ( /^https?:\/\/\S+$/i.test( pastedStr ) ) { + event.content = pastedStr; + } + } + }); + // When the editor's content has been updated and the DOM has been // processed, render the views in the document. editor.on( 'SetContent', function() {