Ticket #25945: shortcode.diff
File shortcode.diff, 4.0 KB (added by , 11 years ago) |
---|
-
src/wp-includes/js/shortcode.js
19 19 re.lastIndex = index || 0; 20 20 match = re.exec( text ); 21 21 22 if ( ! match ) 22 if ( ! match ) { 23 23 return; 24 } 24 25 25 26 // If we matched an escaped shortcode, try again. 26 if ( match[1] === '[' && match[7] === ']' )27 if ( '[' === match[1] && ']' === match[7] ) { 27 28 return wp.shortcode.next( tag, text, re.lastIndex ); 29 } 28 30 29 31 result = { 30 32 index: match.index, … … 40 42 } 41 43 42 44 // If we matched a trailing `]`, strip it from the match. 43 if ( match[7] ) 45 if ( match[7] ) { 44 46 result.match = result.match.slice( 0, -1 ); 47 } 45 48 46 49 return result; 47 50 }, … … 56 59 // a shortcode `attrs` object, the `content` between shortcode tags, 57 60 // and a boolean flag to indicate if the match was a `single` tag. 58 61 replace: function( tag, text, callback ) { 59 return text.replace( wp.shortcode.regexp( tag ), function( match, left, tag, attrs, slash, content, closing, right , offset) {62 return text.replace( wp.shortcode.regexp( tag ), function( match, left, tag, attrs, slash, content, closing, right ) { 60 63 // If both extra brackets exist, the shortcode has been 61 64 // properly escaped. 62 if ( left === '[' && right === ']' ) 65 if ( left === '[' && right === ']' ) { 63 66 return match; 67 } 64 68 65 69 // Create the match object and pass it through the callback. 66 70 var result = callback( wp.shortcode.fromMatch( arguments ) ); … … 164 168 fromMatch: function( match ) { 165 169 var type; 166 170 167 if ( match[4] ) 171 if ( match[4] ) { 168 172 type = 'self-closing'; 169 else if ( match[6] )173 } else if ( match[6] ) { 170 174 type = 'closed'; 171 else175 } else { 172 176 type = 'single'; 177 } 173 178 174 179 return new wp.shortcode({ 175 180 tag: match[2], … … 202 207 numeric: [] 203 208 }; 204 209 205 if ( ! attrs ) 210 if ( ! attrs ) { 206 211 return; 212 } 207 213 208 214 // Parse a string of attributes. 209 215 if ( _.isString( attrs ) ) { … … 244 250 var text = '[' + this.tag; 245 251 246 252 _.each( this.attrs.numeric, function( value ) { 247 if ( /\s/.test( value ) ) 253 if ( /\s/.test( value ) ) { 248 254 text += ' "' + value + '"'; 249 else255 } else { 250 256 text += ' ' + value; 257 } 251 258 }); 252 259 253 260 _.each( this.attrs.named, function( value, name ) { … … 256 263 257 264 // If the tag is marked as `single` or `self-closing`, close the 258 265 // tag and ignore any additional content. 259 if ( 'single' === this.type ) 266 if ( 'single' === this.type ) { 260 267 return text + ']'; 261 else if ( 'self-closing' === this.type )268 } else if ( 'self-closing' === this.type ) { 262 269 return text + ' /]'; 270 } 263 271 264 272 // Complete the opening tag. 265 273 text += ']'; 266 274 267 if ( this.content ) 275 if ( this.content ) { 268 276 text += this.content; 277 } 269 278 270 279 // Add the closing tag. 271 280 return text + '[/' + this.tag + ']'; … … 291 300 var result, attrs; 292 301 293 302 // If `content` ends in a slash, strip it. 294 if ( '/' === content[ content.length - 1 ] ) 303 if ( '/' === content[ content.length - 1 ] ) { 295 304 content = content.slice( 0, -1 ); 305 } 296 306 297 307 result = wp.shortcode.attrs( content ); 298 308 attrs = result.named; 299 309 300 310 _.each( result.numeric, function( key ) { 301 if ( /\s/.test( key ) ) 311 if ( /\s/.test( key ) ) { 302 312 return; 313 } 303 314 304 315 attrs[ key ] = ''; 305 316 }); … … 316 327 text += ' ' + attr; 317 328 318 329 // Use empty attribute notation where possible. 319 if ( '' === value ) 330 if ( '' === value ) { 320 331 return; 332 } 321 333 322 334 // Convert boolean values to strings. 323 if ( _.isBoolean( value ) ) 335 if ( _.isBoolean( value ) ) { 324 336 value = value ? 'true' : 'false'; 337 } 325 338 326 339 text += '="' + value + '"'; 327 340 }); 328 341 329 342 // Return the result if it is a self-closing tag. 330 if ( options.single ) 343 if ( options.single ) { 331 344 return text + ' />'; 345 } 332 346 333 347 // Complete the opening tag. 334 348 text += '>';