diff --git a/src/wp-admin/js/editor.js b/src/wp-admin/js/editor.js index bde22255cc..c42611bb2d 100644 --- a/src/wp-admin/js/editor.js +++ b/src/wp-admin/js/editor.js @@ -122,16 +122,25 @@ blocklist1 = blocklist + '|div|p', blocklist2 = blocklist + '|pre', preserve_linebreaks = false, - preserve_br = false; + preserve_br = false, + preserve = []; if ( ! html ) { return ''; } - // Protect pre|script tags - if ( html.indexOf( ']*>[\s\S]*?<\/\1>/g, function( match ) { + preserve.push( match ); + return ''; + } ); + } + + // Protect pre tags. + if ( html.indexOf( ']*>[\s\S]+?<\/\1>/g, function( a ) { + html = html.replace( /]*>[\s\S]+?<\/pre>/g, function( a ) { a = a.replace( /
(\r\n|\n)?/g, '' ); a = a.replace( /<\/?p( [^>]*)?>(\r\n|\n)?/g, '' ); return a.replace( /\r?\n/g, '' ); @@ -205,6 +214,13 @@ html = html.replace( /]*)>/g, '' ); } + // Put back preserved tags. + if ( preserve.length ) { + html = html.replace( //g, function() { + return preserve.shift(); + } ); + } + return html; } diff --git a/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js b/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js index cc95622e48..46fe40594f 100644 --- a/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js @@ -90,7 +90,6 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { window.wpActiveEditor = editor.id; }); - // Replace Read More/Next Page tags with images editor.on( 'BeforeSetContent', function( event ) { var title; @@ -116,6 +115,21 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { event.content = wp.editor.autop( event.content ); } + if ( event.content.indexOf( ']*>[\s\S]*?<\/\1>/g, function( match, tag ) { + return ''; + } ); + } + // Remove spaces from empty paragraphs. // Avoid backtracking, can freeze the editor. See #35890. // (This is also quite faster than using only one regex.) @@ -129,23 +143,28 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { } }); - // Replace images with tags - editor.on( 'PostProcess', function( e ) { - if ( e.get ) { - e.content = e.content.replace(/]+>/g, function( image ) { - var match, moretext = ''; + editor.on( 'PostProcess', function( event ) { + if ( event.get ) { + event.content = event.content.replace(/]+>/g, function( image ) { + var match, + string, + moretext = ''; if ( image.indexOf( 'data-wp-more="more"' ) !== -1 ) { if ( match = image.match( /data-wp-more-text="([^"]+)"/ ) ) { moretext = match[1]; } - image = ''; + string = ''; } else if ( image.indexOf( 'data-wp-more="nextpage"' ) !== -1 ) { - image = ''; + string = ''; + } else if ( image.indexOf( 'data-wp-preserve' ) !== -1 ) { + if ( match = image.match( / data-wp-preserve="([^"]+)"/ ) ) { + string = decodeURIComponent( match[1] ); + } } - return image; + return string || image; }); } });