TinyMCE: improve removal of spaces from empty paragraphs when loading HTML in the editor.

Fixes #39437.
Built from https://develop.svn.wordpress.org/trunk@39902


git-svn-id: http://core.svn.wordpress.org/trunk@39839 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2017-01-15 02:06:41 +00:00
parent 82e17902a9
commit 90f441e1b4
4 changed files with 15 additions and 12 deletions

View File

@ -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>([^<>]+)<\/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 ) {
if ( event.get ) {
event.content = event.content.replace(/<img[^>]+>/g, function( image ) {

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.8-alpha-39901';
$wp_version = '4.8-alpha-39902';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.