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 ) {