Add support for line breaks to the caption textareas, see #18311
git-svn-id: http://svn.automattic.com/wordpress/trunk@20174 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
feb1697b7a
commit
ca3ab6c5c2
|
@ -144,14 +144,14 @@ function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $
|
||||||
|
|
||||||
$id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
|
$id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
|
||||||
|
|
||||||
if ( ! preg_match( '/width="([0-9]+)/', $html, $matches ) )
|
if ( ! preg_match( '/width=["\']([0-9]+)/', $html, $matches ) )
|
||||||
return $html;
|
return $html;
|
||||||
|
|
||||||
$width = $matches[1];
|
$width = $matches[1];
|
||||||
|
|
||||||
// look only for html tags with attributes
|
$caption = str_replace( array("\r\n", "\r"), "\n", $caption);
|
||||||
$caption = preg_replace_callback( '/<[a-zA-Z0-9]+ [^<>]+>/', '_cleanup_image_add_caption', $caption );
|
$caption = preg_replace_callback( '/<[a-zA-Z0-9]+(?: [^<>]+>)*/', '_cleanup_image_add_caption', $caption );
|
||||||
$caption = str_replace( '"', '"', $caption );
|
$caption = preg_replace( '/\n+/', '<br />', str_replace('"', '"', $caption) );
|
||||||
|
|
||||||
$html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
|
$html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
|
||||||
if ( empty($align) )
|
if ( empty($align) )
|
||||||
|
@ -167,8 +167,10 @@ add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 );
|
||||||
// Private, preg_replace callback used in image_add_caption()
|
// Private, preg_replace callback used in image_add_caption()
|
||||||
function _cleanup_image_add_caption($str) {
|
function _cleanup_image_add_caption($str) {
|
||||||
if ( isset($str[0]) ) {
|
if ( isset($str[0]) ) {
|
||||||
|
// remove any line breaks from inside the tags
|
||||||
|
$s = preg_replace( '/[\r\n\t]+/', ' ', $str[0]);
|
||||||
// look for single quotes inside html attributes (for example in title)
|
// look for single quotes inside html attributes (for example in title)
|
||||||
$s = preg_replace_callback( '/="[^"]+"/', '_cleanup_image_add_caption2', $str[0] );
|
$s = preg_replace_callback( '/="[^"]+"/', '_cleanup_image_add_caption2', $s );
|
||||||
return str_replace( '"', "'", $s );
|
return str_replace( '"', "'", $s );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1542,14 +1544,15 @@ var addExtImage = {
|
||||||
|
|
||||||
<?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
|
<?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
|
||||||
if ( f.caption.value ) {
|
if ( f.caption.value ) {
|
||||||
caption = f.caption.value.replace(/<[a-zA-Z0-9]+ [^<>]+>/g, function(a){
|
caption = f.caption.value.replace(/\r\n|\r/g, '\n');
|
||||||
a = a.replace(/="[^"]+"/, function(b){
|
caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){
|
||||||
|
a = a.replace(/[\r\n\t]+/, ' ').replace(/="[^"]+"/, function(b){
|
||||||
return b.replace(/'/g, ''');
|
return b.replace(/'/g, ''');
|
||||||
});
|
});
|
||||||
return a.replace(/"/g, "'");
|
return a.replace(/"/g, "'");
|
||||||
});
|
});
|
||||||
|
|
||||||
caption = caption.replace(/"/g, '"');
|
caption = caption.replace(/\n+/g, '<br />').replace(/"/g, '"');
|
||||||
}
|
}
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
||||||
|
|
|
@ -62,13 +62,22 @@ var switchEditors = {
|
||||||
},
|
},
|
||||||
|
|
||||||
_wp_Nop : function(content) {
|
_wp_Nop : function(content) {
|
||||||
var blocklist1, blocklist2;
|
var blocklist1, blocklist2, preserve_linebreaks = false, preserve_br = false;
|
||||||
|
|
||||||
// Protect pre|script tags
|
// Protect pre|script tags
|
||||||
if ( content.indexOf('<pre') != -1 || content.indexOf('<script') != -1 ) {
|
if ( content.indexOf('<pre') != -1 || content.indexOf('<script') != -1 ) {
|
||||||
|
preserve_linebreaks = true;
|
||||||
content = content.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {
|
content = content.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {
|
||||||
a = a.replace(/<br ?\/?>(\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>');
|
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]+$/, '');
|
content = content.replace(/[\s\u00a0]+$/, '');
|
||||||
|
|
||||||
// put back the line breaks in pre|script
|
// 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;
|
return content;
|
||||||
},
|
},
|
||||||
|
|
|
@ -186,14 +186,14 @@
|
||||||
cls = ( cls && cls[1] ) ? cls[1] : '';
|
cls = ( cls && cls[1] ) ? cls[1] : '';
|
||||||
cls = cls.match(/align[a-z]+/) || 'alignnone';
|
cls = cls.match(/align[a-z]+/) || 'alignnone';
|
||||||
|
|
||||||
cap = cap.replace(/<[a-zA-Z0-9]+ [^<>]+>/g, function(a){ // look only for html tags with attributes
|
cap = cap.replace(/\r\n|\r/g, '\n').replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){
|
||||||
a = a.replace(/="[^"]+"/, function(b){
|
a = a.replace(/[\r\n\t]+/, ' ').replace(/="[^"]+"/, function(b){
|
||||||
return b.replace(/'/g, ''');
|
return b.replace(/'/g, ''');
|
||||||
});
|
});
|
||||||
return a.replace(/"/g, "'");
|
return a.replace(/"/g, "'");
|
||||||
});
|
});
|
||||||
|
|
||||||
cap = cap.replace(/"/g, '"');
|
cap = cap.replace(/\n+/g, '<br />').replace(/"/g, '"');
|
||||||
|
|
||||||
return '[caption id="'+id+'" align="'+cls+'" width="'+w+'" caption="'+cap+'"]'+c+'[/caption]';
|
return '[caption id="'+id+'" align="'+cls+'" width="'+w+'" caption="'+cap+'"]'+c+'[/caption]';
|
||||||
});
|
});
|
||||||
|
|
|
@ -352,7 +352,7 @@ wpImage = {
|
||||||
update : function() {
|
update : function() {
|
||||||
var t = this, f = document.forms[0], ed = tinyMCEPopup.editor, el, b, fixSafari = null,
|
var t = this, f = document.forms[0], ed = tinyMCEPopup.editor, el, b, fixSafari = null,
|
||||||
DL, P, A, DIV, do_caption = null, img_class = f.img_classes.value, html,
|
DL, P, A, DIV, do_caption = null, img_class = f.img_classes.value, html,
|
||||||
id, cap_id = '', cap, DT, DD, cap_width, div_cls, lnk = '', pa, aa;
|
id, cap_id = '', cap, DT, DD, cap_width, div_cls, lnk = '', pa, aa, caption;
|
||||||
|
|
||||||
tinyMCEPopup.restoreSelection();
|
tinyMCEPopup.restoreSelection();
|
||||||
el = ed.selection.getNode();
|
el = ed.selection.getNode();
|
||||||
|
@ -430,6 +430,16 @@ wpImage = {
|
||||||
if ( do_caption ) {
|
if ( do_caption ) {
|
||||||
cap_width = 10 + parseInt(f.width.value);
|
cap_width = 10 + parseInt(f.width.value);
|
||||||
div_cls = (t.align == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp';
|
div_cls = (t.align == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp';
|
||||||
|
caption = f.img_cap_text.value;
|
||||||
|
|
||||||
|
caption = caption.replace(/\r\n|\r/g, '\n').replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){
|
||||||
|
a = a.replace(/[\r\n\t]+/, ' ').replace(/="[^"]+"/, function(b){
|
||||||
|
return b.replace(/'/g, ''');
|
||||||
|
});
|
||||||
|
return a.replace(/"/g, "'");
|
||||||
|
});
|
||||||
|
|
||||||
|
caption = caption.replace(/\n+/g, '<br />').replace(/"/g, '"');
|
||||||
|
|
||||||
if ( DL ) {
|
if ( DL ) {
|
||||||
ed.dom.setAttribs(DL, {
|
ed.dom.setAttribs(DL, {
|
||||||
|
@ -441,24 +451,26 @@ wpImage = {
|
||||||
ed.dom.setAttrib(DIV, 'class', div_cls);
|
ed.dom.setAttrib(DIV, 'class', div_cls);
|
||||||
|
|
||||||
if ( (DT = ed.dom.getParent(el, 'dt')) && (DD = DT.nextSibling) && ed.dom.hasClass(DD, 'wp-caption-dd') )
|
if ( (DT = ed.dom.getParent(el, 'dt')) && (DD = DT.nextSibling) && ed.dom.hasClass(DD, 'wp-caption-dd') )
|
||||||
ed.dom.setHTML(DD, f.img_cap_text.value);
|
ed.dom.setHTML(DD, caption);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if ( (id = f.img_classes.value.match( /wp-image-([0-9]{1,6})/ )) && id[1] )
|
if ( (id = f.img_classes.value.match( /wp-image-([0-9]{1,6})/ )) && id[1] )
|
||||||
cap_id = 'attachment_'+id[1];
|
cap_id = 'attachment_'+id[1];
|
||||||
|
|
||||||
if ( f.link_href.value && (lnk = ed.dom.getParent(el, 'a')) ) {
|
if ( f.link_href.value && (lnk = ed.dom.getParent(el, 'a')) ) {
|
||||||
if ( lnk.childNodes.length == 1 )
|
if ( lnk.childNodes.length == 1 ) {
|
||||||
html = ed.dom.getOuterHTML(lnk);
|
html = ed.dom.getOuterHTML(lnk);
|
||||||
else {
|
} else {
|
||||||
html = ed.dom.getOuterHTML(lnk);
|
html = ed.dom.getOuterHTML(lnk);
|
||||||
html = html.match(/<a[^>]+>/i);
|
html = html.match(/<a [^>]+>/i);
|
||||||
html = html+ed.dom.getOuterHTML(el)+'</a>';
|
html = html+ed.dom.getOuterHTML(el)+'</a>';
|
||||||
}
|
}
|
||||||
} else html = ed.dom.getOuterHTML(el);
|
} else {
|
||||||
|
html = ed.dom.getOuterHTML(el);
|
||||||
|
}
|
||||||
|
|
||||||
html = '<dl id="'+cap_id+'" class="wp-caption '+t.align+'" style="width: '+cap_width+
|
html = '<dl id="'+cap_id+'" class="wp-caption '+t.align+'" style="width: '+cap_width+
|
||||||
'px"><dt class="wp-caption-dt">'+html+'</dt><dd class="wp-caption-dd">'+f.img_cap_text.value+'</dd></dl>';
|
'px"><dt class="wp-caption-dt">'+html+'</dt><dd class="wp-caption-dd">'+caption+'</dd></dl>';
|
||||||
|
|
||||||
cap = ed.dom.create('div', {'class': div_cls}, html);
|
cap = ed.dom.create('div', {'class': div_cls}, html);
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue