Changeset 26882
- Timestamp:
- 12/31/2013 03:09:34 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js
r26880 r26882 50 50 function getShortcode( content ) { 51 51 return content.replace( /<div (?:id="attachment_|class="mceTemp)[^>]*>([\s\S]+?)<\/div>/g, function( a, b ) { 52 var out = ''; 53 52 54 if ( b.indexOf('<img ') === -1 ) { 53 // Broken caption. The user dragged the image out? 55 // Broken caption. The user managed to drag the image out? 56 // Try to return the caption text as a paragraph. 57 out = b.match( /<dd [^>]+>([\s\S]+?)<\/dd>/i ); 58 59 if ( out && out[1] ) { 60 return '<p>' + out[1] + '</p>' 61 } 62 54 63 return ''; 55 64 } 56 65 57 var ret = b.replace( /<dl ([^>]+)>\s*<dt [^>]+>([\s\S]+?)<\/dt>\s*<dd [^>]+>([\s\S]*?)<\/dd>\s*<\/dl>/gi, function( a, b, c, cap ) {66 out = b.replace( /<dl ([^>]+)>\s*<dt [^>]+>([\s\S]+?)<\/dt>\s*<dd [^>]+>([\s\S]*?)<\/dd>\s*<\/dl>/gi, function( a, b, c, cap ) { 58 67 var id, cls, w; 59 68 … … 83 92 }); 84 93 85 if ( ret.indexOf('[caption') !== 0 ) {94 if ( out.indexOf('[caption') !== 0 ) { 86 95 // the caption html seems brocken, try to find the image that may be wrapped in a link 87 96 // and may be followed by <p> with the caption text. 88 ret = b.replace( /[\s\S]*?((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)(<p>[\s\S]*<\/p>)?[\s\S]*/gi, '<p>$1</p>$2' );89 } 90 91 return ret;97 out = b.replace( /[\s\S]*?((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)(<p>[\s\S]*<\/p>)?[\s\S]*/gi, '<p>$1</p>$2' ); 98 } 99 100 return out; 92 101 }); 93 102 } … … 162 171 } 163 172 173 if ( caption ) { 174 caption = caption.replace( /\r\n|\r/g, '\n' ).replace( /<\/?[a-zA-Z0-9]+( [^<>]+)?>/g, function( a ) { 175 // No line breaks inside HTML tags 176 return a.replace( /[\r\n\t]+/, ' ' ); 177 }); 178 179 // Convert remaining line breaks to <br> 180 caption = caption.replace( /(<br[^>]*>)\s*\n\s*/g, '$1' ).replace( /\s*\n\s*/g, '<br />' ); 181 } 182 164 183 if ( ! imgNode ) { 165 184 // New image inserted … … 295 314 if ( parent = dom.getParent( imgNode, 'dl.wp-caption' ) ) { 296 315 parent = dom.select( 'dd.wp-caption-dd', parent )[0]; 297 data.caption = parent ? parent.innerHTML : ''; 316 317 if ( parent ) { 318 data.caption = editor.serializer.serialize( parent ) 319 .replace( /<br[^>]*>/g, '$&\n' ).replace( /^<p>/, '' ).replace( /<\/p>$/, '' ); 320 } 298 321 } 299 322 });
Note: See TracChangeset
for help on using the changeset viewer.