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
This commit is contained in:
Andrew Ozz 2017-01-15 02:05:44 +00:00
parent 2fa90d1077
commit 976976b4a1

View File

@ -129,17 +129,20 @@ 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>([^<>]+)<\/p>/gi, function( tag, text ) {
if ( text === '&nbsp;' || ! /\S/.test( text ) ) {
return '<p><br /></p>';
} }
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 === '&nbsp;' ) {
node.innerHTML = ( tinymce.Env.ie && tinymce.Env.ie < 11 ) ? '' : '<br data-mce-bogus="1">';
} }
}
} );
}); });
editor.on( 'PostProcess', function( event ) { editor.on( 'PostProcess', function( event ) {