Add support for line breaks to the caption textareas, see #18311

git-svn-id: https://develop.svn.wordpress.org/trunk@20174 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2012-03-14 21:53:11 +00:00
parent ae895a30c9
commit 995926a5f0
5 changed files with 52 additions and 23 deletions
+18 -4
View File
@@ -62,13 +62,22 @@ var switchEditors = {
},
_wp_Nop : function(content) {
var blocklist1, blocklist2;
var blocklist1, blocklist2, preserve_linebreaks = false, preserve_br = false;
// Protect pre|script tags
if ( content.indexOf('<pre') != -1 || content.indexOf('<script') != -1 ) {
preserve_linebreaks = true;
content = content.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {
a = a.replace(/<br ?\/?>(\r\n|\n)?/g, '<wp_temp>');
return a.replace(/<\/?p( [^>]*)?>(\r\n|\n)?/g, '<wp_temp>');
a = a.replace(/<br ?\/?>(\r\n|\n)?/g, '<wp-temp-lb>');
return a.replace(/<\/?p( [^>]*)?>(\r\n|\n)?/g, '<wp-temp-lb>');
});
}
// keep <br> tags inside captions
if ( content.indexOf('[caption') != -1 ) {
preserve_br = true;
content = content.replace(/\[caption[^\]]+\]/g, function(a) {
return a.replace(/<br([^>]*)>[\r\n]*/g, '<wp-temp-br$1>');
});
}
@@ -119,7 +128,12 @@ var switchEditors = {
content = content.replace(/[\s\u00a0]+$/, '');
// put back the line breaks in pre|script
content = content.replace(/<wp_temp>/g, '\n');
if ( preserve_linebreaks )
content = content.replace(/<wp-temp-lb>/g, '\n');
// and the <br> tags in captions
if ( preserve_br )
content = content.replace(/<wp-temp-br([^>]*)>/g, '<br$1>');
return content;
},