From 976976b4a1c349802125214b39a5491c0c50f34f Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sun, 15 Jan 2017 02:05:44 +0000 Subject: [PATCH] TinyMCE: improve removal of spaces from empty paragraphs when loading HTML in the editor. Fixes #39437. git-svn-id: https://develop.svn.wordpress.org/trunk@39902 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/tinymce/plugins/wordpress/plugin.js | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js b/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js index a38a26d3d4..79d56d2251 100644 --- a/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js @@ -129,19 +129,22 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { '/>'; } ); } - - // Remove spaces from empty paragraphs. - // Try to avoid a lot of backtracking, can freeze the editor. See #35890 and #38294. - event.content = event.content.replace( /

([^<>]+)<\/p>/gi, function( tag, text ) { - if ( text === ' ' || ! /\S/.test( text ) ) { - return '


'; - } - - return tag; - }); } }); + editor.on( 'setcontent', function() { + // Remove spaces from empty paragraphs. + editor.$( 'p' ).each( function( i, node ) { + if ( node.innerHTML && node.innerHTML.length < 10 ) { + var html = tinymce.trim( node.innerHTML ); + + if ( ! html || html === ' ' ) { + node.innerHTML = ( tinymce.Env.ie && tinymce.Env.ie < 11 ) ? '' : '
'; + } + } + } ); + }); + editor.on( 'PostProcess', function( event ) { if ( event.get ) { event.content = event.content.replace(/]+>/g, function( image ) {