diff --git a/wp-admin/js/editor.js b/wp-admin/js/editor.js index 757fd3012d..50955c7006 100644 --- a/wp-admin/js/editor.js +++ b/wp-admin/js/editor.js @@ -13,7 +13,7 @@ wpEditorInit = function() { switchEditors = { saveCallback : function(el, content, body) { - + document.getElementById(el).style.color = '#fff'; if ( tinyMCE.activeEditor.isHidden() ) content = document.getElementById(el).value; @@ -26,8 +26,14 @@ switchEditors = { pre_wpautop : function(content) { // We have a TON of cleanup to do. Line breaks are already stripped. + // Protect pre|script tags + content = content.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) { + a = a.replace(/
[\r\n]*/g, ''); + return a.replace(/<\/?p( [^>]*)?>[\r\n]*/g, ''); + }); + // Pretty it up for the source editor - var blocklist1 = 'blockquote|ul|ol|li|table|thead|tbody|tr|th|td|div|h[1-6]|pre|p'; + var blocklist1 = 'blockquote|ul|ol|li|table|thead|tbody|tr|th|td|div|h[1-6]|p'; content = content.replace(new RegExp('\\s*\\s*', 'mg'), '\n'); content = content.replace(new RegExp('\\s*<(('+blocklist1+')[^>]*)>', 'mg'), '\n<$1>'); @@ -46,7 +52,7 @@ switchEditors = { // Fix some block element newline issues content = content.replace(new RegExp('\\s*\\s*', 'mg'), '\n'); - + var blocklist2 = 'blockquote|ul|ol|li|table|thead|tr|th|td|h[1-6]|pre'; content = content.replace(new RegExp('\\s*<(('+blocklist2+') ?[^>]*)\\s*>', 'mg'), '\n<$1>'); content = content.replace(new RegExp('\\s*\\s*', 'mg'), '\n'); @@ -65,6 +71,9 @@ switchEditors = { content = content.replace(new RegExp('^\\s*', ''), ''); content = content.replace(new RegExp('\\s*$', ''), ''); + // put back the line breaks in pre|script + content = content.replace(//g, '\n'); + // Hope. return content; }, @@ -109,7 +118,7 @@ switchEditors = { ec.style.padding = '6px'; } - ta.style.color = ''; + ta.style.color = ''; this.wpSetDefaultEditor('html'); } }, @@ -148,15 +157,21 @@ switchEditors = { pee = pee.replace(new RegExp('

\\s*?

', 'gi'), ''); pee = pee.replace(new RegExp('

\\s*(]*>)\\s*

', 'gi'), "$1"); pee = pee.replace(new RegExp("

(", 'gi'), "$1"); - pee = pee.replace(new RegExp('

]*)>', 'gi'), "

"); - pee = pee.replace(new RegExp('

', 'gi'), '

'); + pee = pee.replace(new RegExp('

\\s*]*)>', 'gi'), "

"); + pee = pee.replace(new RegExp('\\s*

', 'gi'), '

'); pee = pee.replace(new RegExp('

\\s*(]*>)', 'gi'), "$1"); pee = pee.replace(new RegExp('(]*>)\\s*

', 'gi'), "$1"); pee = pee.replace(new RegExp('\\s*\\n', 'gi'), "
\n"); pee = pee.replace(new RegExp('(]*>)\\s*
', 'gi'), "$1"); pee = pee.replace(new RegExp('
(\\s*)', 'gi'), '$1'); - pee = pee.replace(new RegExp('^((?: )*)\\s', 'mg'), '$1 '); - //pee = pee.replace(new RegExp('()(.*?)!ise', " stripslashes('$1') . stripslashes(clean_pre('$2')) . '' "); // Hmm... - return pee; + // pee = pee.replace(new RegExp('^((?: )*)\\s', 'mg'), '$1 '); + + // Fix the pre|script tags + pee = pee.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) { + a = a.replace(/
[\r\n]*/g, '\n'); + return a.replace(/<\/?p( [^>]*)?>[\r\n]*/g, '\n'); + }); + + return pee; } }