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 : '';
|
||||
|
||||
if ( ! preg_match( '/width="([0-9]+)/', $html, $matches ) )
|
||||
if ( ! preg_match( '/width=["\']([0-9]+)/', $html, $matches ) )
|
||||
return $html;
|
||||
|
||||
$width = $matches[1];
|
||||
|
||||
// look only for html tags with attributes
|
||||
$caption = preg_replace_callback( '/<[a-zA-Z0-9]+ [^<>]+>/', '_cleanup_image_add_caption', $caption );
|
||||
$caption = str_replace( '"', '"', $caption );
|
||||
$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( '/\n+/', '<br />', str_replace('"', '"', $caption) );
|
||||
|
||||
$html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
|
||||
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()
|
||||
function _cleanup_image_add_caption($str) {
|
||||
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)
|
||||
$s = preg_replace_callback( '/="[^"]+"/', '_cleanup_image_add_caption2', $str[0] );
|
||||
$s = preg_replace_callback( '/="[^"]+"/', '_cleanup_image_add_caption2', $s );
|
||||
return str_replace( '"', "'", $s );
|
||||
}
|
||||
|
||||
|
@ -1542,14 +1544,15 @@ var addExtImage = {
|
|||
|
||||
<?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
|
||||
if ( f.caption.value ) {
|
||||
caption = f.caption.value.replace(/<[a-zA-Z0-9]+ [^<>]+>/g, function(a){
|
||||
a = a.replace(/="[^"]+"/, function(b){
|
||||
caption = f.caption.value.replace(/\r\n|\r/g, '\n');
|
||||
caption = caption.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(/"/g, '"');
|
||||
caption = caption.replace(/\n+/g, '<br />').replace(/"/g, '"');
|
||||
}
|
||||
<?php } ?>
|
||||
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
|
|
|
@ -186,14 +186,14 @@
|
|||
cls = ( cls && cls[1] ) ? cls[1] : '';
|
||||
cls = cls.match(/align[a-z]+/) || 'alignnone';
|
||||
|
||||
cap = cap.replace(/<[a-zA-Z0-9]+ [^<>]+>/g, function(a){ // look only for html tags with attributes
|
||||
a = a.replace(/="[^"]+"/, function(b){
|
||||
cap = cap.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, "'");
|
||||
});
|
||||
|
||||
cap = cap.replace(/"/g, '"');
|
||||
cap = cap.replace(/\n+/g, '<br />').replace(/"/g, '"');
|
||||
|
||||
return '[caption id="'+id+'" align="'+cls+'" width="'+w+'" caption="'+cap+'"]'+c+'[/caption]';
|
||||
});
|
||||
|
|
|
@ -352,7 +352,7 @@ wpImage = {
|
|||
update : function() {
|
||||
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,
|
||||
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();
|
||||
el = ed.selection.getNode();
|
||||
|
@ -430,6 +430,16 @@ wpImage = {
|
|||
if ( do_caption ) {
|
||||
cap_width = 10 + parseInt(f.width.value);
|
||||
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 ) {
|
||||
ed.dom.setAttribs(DL, {
|
||||
|
@ -441,24 +451,26 @@ wpImage = {
|
|||
ed.dom.setAttrib(DIV, 'class', div_cls);
|
||||
|
||||
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 {
|
||||
if ( (id = f.img_classes.value.match( /wp-image-([0-9]{1,6})/ )) && id[1] )
|
||||
cap_id = 'attachment_'+id[1];
|
||||
|
||||
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);
|
||||
else {
|
||||
} else {
|
||||
html = ed.dom.getOuterHTML(lnk);
|
||||
html = html.match(/<a [^>]+>/i);
|
||||
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+
|
||||
'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);
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue