X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/53f4633144ed68c8b8fb5861f992b5489894a940..refs/heads/pristine:/wp-admin/js/editor.js diff --git a/wp-admin/js/editor.js b/wp-admin/js/editor.js index d64d3e60..e3fbaab9 100644 --- a/wp-admin/js/editor.js +++ b/wp-admin/js/editor.js @@ -118,20 +118,29 @@ // Replace paragraphs with double line breaks function removep( html ) { - var blocklist = 'blockquote|ul|ol|li|table|thead|tbody|tfoot|tr|th|td|h[1-6]|fieldset', + var blocklist = 'blockquote|ul|ol|li|dl|dt|dd|table|thead|tbody|tfoot|tr|th|td|h[1-6]|fieldset', 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, '' ); @@ -170,7 +179,7 @@ html = html.replace( new RegExp('\\s*<((?:' + blocklist2 + ')(?: [^>]*)?)\\s*>', 'g' ), '\n<$1>' ); html = html.replace( new RegExp('\\s*\\s*', 'g' ), '\n' ); - html = html.replace( /]*)>/g, '\t' ); + html = html.replace( /<((li|dt|dd)[^>]*)>/g, ' \t<$1>' ); if ( html.indexOf( ']*)>/g, '' ); } + // Put back preserved tags. + if ( preserve.length ) { + html = html.replace( //g, function() { + return preserve.shift(); + } ); + } + return html; } @@ -236,7 +252,7 @@ // Protect pre|script tags if ( text.indexOf( ']*>[\s\S]+?<\/\1>/g, function( a ) { + text = text.replace( /<(pre|script)[^>]*>[\s\S]*?<\/\1>/g, function( a ) { return a.replace( /\n/g, '' ); }); } @@ -258,7 +274,7 @@ text = text + '\n\n'; text = text.replace( /
\s*
/gi, '\n\n' ); - text = text.replace( new RegExp( '(<(?:' + blocklist + ')(?: [^>]*)?>)', 'gi' ), '\n$1' ); + text = text.replace( new RegExp( '(<(?:' + blocklist + ')(?: [^>]*)?>)', 'gi' ), '\n\n$1' ); text = text.replace( new RegExp( '()', 'gi' ), '$1\n\n' ); text = text.replace( /]*)?>/gi, '\n\n' ); // hr is self closing block element text = text.replace( /\s*