Protect the <pre> and <script> tags when switching editors. Props azaozz. fixes #6610 for trunk
git-svn-id: http://svn.automattic.com/wordpress/trunk@7716 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e399f6ad54
commit
26fd2097a0
|
@ -26,8 +26,14 @@ switchEditors = {
|
||||||
pre_wpautop : function(content) {
|
pre_wpautop : function(content) {
|
||||||
// We have a TON of cleanup to do. Line breaks are already stripped.
|
// 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(/<br ?\/?>[\r\n]*/g, '<wp_temp>');
|
||||||
|
return a.replace(/<\/?p( [^>]*)?>[\r\n]*/g, '<wp_temp>');
|
||||||
|
});
|
||||||
|
|
||||||
// Pretty it up for the source editor
|
// 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*</('+blocklist1+')>\\s*', 'mg'), '</$1>\n');
|
content = content.replace(new RegExp('\\s*</('+blocklist1+')>\\s*', 'mg'), '</$1>\n');
|
||||||
content = content.replace(new RegExp('\\s*<(('+blocklist1+')[^>]*)>', 'mg'), '\n<$1>');
|
content = content.replace(new RegExp('\\s*<(('+blocklist1+')[^>]*)>', 'mg'), '\n<$1>');
|
||||||
|
|
||||||
|
@ -65,6 +71,9 @@ switchEditors = {
|
||||||
content = content.replace(new RegExp('^\\s*', ''), '');
|
content = content.replace(new RegExp('^\\s*', ''), '');
|
||||||
content = content.replace(new RegExp('\\s*$', ''), '');
|
content = content.replace(new RegExp('\\s*$', ''), '');
|
||||||
|
|
||||||
|
// put back the line breaks in pre|script
|
||||||
|
content = content.replace(/<wp_temp>/g, '\n');
|
||||||
|
|
||||||
// Hope.
|
// Hope.
|
||||||
return content;
|
return content;
|
||||||
},
|
},
|
||||||
|
@ -109,7 +118,7 @@ switchEditors = {
|
||||||
ec.style.padding = '6px';
|
ec.style.padding = '6px';
|
||||||
}
|
}
|
||||||
|
|
||||||
ta.style.color = '';
|
ta.style.color = '';
|
||||||
this.wpSetDefaultEditor('html');
|
this.wpSetDefaultEditor('html');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -148,15 +157,21 @@ switchEditors = {
|
||||||
pee = pee.replace(new RegExp('<p>\\s*?</p>', 'gi'), '');
|
pee = pee.replace(new RegExp('<p>\\s*?</p>', 'gi'), '');
|
||||||
pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')[^>]*>)\\s*</p>', 'gi'), "$1");
|
pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')[^>]*>)\\s*</p>', 'gi'), "$1");
|
||||||
pee = pee.replace(new RegExp("<p>(<li.+?)</p>", 'gi'), "$1");
|
pee = pee.replace(new RegExp("<p>(<li.+?)</p>", 'gi'), "$1");
|
||||||
pee = pee.replace(new RegExp('<p><blockquote([^>]*)>', 'gi'), "<blockquote$1><p>");
|
pee = pee.replace(new RegExp('<p>\\s*<blockquote([^>]*)>', 'gi'), "<blockquote$1><p>");
|
||||||
pee = pee.replace(new RegExp('</blockquote></p>', 'gi'), '</p></blockquote>');
|
pee = pee.replace(new RegExp('</blockquote>\\s*</p>', 'gi'), '</p></blockquote>');
|
||||||
pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')[^>]*>)', 'gi'), "$1");
|
pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')[^>]*>)', 'gi'), "$1");
|
||||||
pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*</p>', 'gi'), "$1");
|
pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*</p>', 'gi'), "$1");
|
||||||
pee = pee.replace(new RegExp('\\s*\\n', 'gi'), "<br />\n");
|
pee = pee.replace(new RegExp('\\s*\\n', 'gi'), "<br />\n");
|
||||||
pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br />', 'gi'), "$1");
|
pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br />', 'gi'), "$1");
|
||||||
pee = pee.replace(new RegExp('<br />(\\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)', 'gi'), '$1');
|
pee = pee.replace(new RegExp('<br />(\\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)', 'gi'), '$1');
|
||||||
pee = pee.replace(new RegExp('^((?: )*)\\s', 'mg'), '$1 ');
|
// pee = pee.replace(new RegExp('^((?: )*)\\s', 'mg'), '$1 ');
|
||||||
//pee = pee.replace(new RegExp('(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') . stripslashes(clean_pre('$2')) . '</pre>' "); // Hmm...
|
|
||||||
return pee;
|
// Fix the pre|script tags
|
||||||
|
pee = pee.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {
|
||||||
|
a = a.replace(/<br ?\/?>[\r\n]*/g, '\n');
|
||||||
|
return a.replace(/<\/?p( [^>]*)?>[\r\n]*/g, '\n');
|
||||||
|
});
|
||||||
|
|
||||||
|
return pee;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue