Ticket #44987: shortcode-package.patch
| File shortcode-package.patch, 31.2 KB (added by , 8 years ago) |
|---|
-
Gruntfile.js
diff --git a/Gruntfile.js b/Gruntfile.js index a77384423c..21af4726c4 100644
a b module.exports = function(grunt) { 276 276 'build/wp-includes/js/mce-view.js': ['./src/js/_enqueues/wp/mce-view.js'], 277 277 'build/wp-includes/js/media-editor.js': ['./src/js/_enqueues/wp/media/editor.js'], 278 278 'build/wp-includes/js/quicktags.js': ['./src/js/_enqueues/lib/quicktags.js'], 279 'build/wp-includes/js/shortcode.js': ['./src/js/_enqueues/wp/shortcode.js'],280 279 'build/wp-includes/js/utils.js': ['./src/js/_enqueues/lib/cookies.js'], 281 280 'build/wp-includes/js/wp-a11y.js': ['./src/js/_enqueues/wp/a11y.js'], 282 281 'build/wp-includes/js/wp-ajax-response.js': ['./src/js/_enqueues/lib/ajax-response.js'], … … module.exports = function(grunt) { 815 814 'src/wp-includes/js/mce-view.js': 'src/js/_enqueues/wp/mce-view.js', 816 815 'src/wp-includes/js/media-editor.js': 'src/js/_enqueues/wp/media/editor.js', 817 816 'src/wp-includes/js/quicktags.js': 'src/js/_enqueues/lib/quicktags.js', 818 'src/wp-includes/js/shortcode.js': 'src/js/_enqueues/wp/shortcode.js',819 817 'src/wp-includes/js/utils.js': 'src/js/_enqueues/lib/cookies.js', 820 818 'src/wp-includes/js/wp-a11y.js': 'src/js/_enqueues/wp/a11y.js', 821 819 'src/wp-includes/js/wp-ajax-response.js': 'src/js/_enqueues/lib/ajax-response.js', -
package-lock.json
diff --git a/package-lock.json b/package-lock.json index 3f81fc78a0..f8bf9667bd 100644
a b 4 4 "lockfileVersion": 1, 5 5 "requires": true, 6 6 "dependencies": { 7 "@babel/polyfill": { 8 "version": "7.0.0", 9 "resolved": "https://registry.npmjs.org/@babel/polyfill/-/polyfill-7.0.0.tgz", 10 "integrity": "sha512-dnrMRkyyr74CRelJwvgnnSUDh2ge2NCTyHVwpOdvRMHtJUyxLtMAfhBN3s64pY41zdw0kgiLPh6S20eb1NcX6Q==", 11 "requires": { 12 "core-js": "^2.5.7", 13 "regenerator-runtime": "^0.11.1" 14 }, 15 "dependencies": { 16 "regenerator-runtime": { 17 "version": "0.11.1", 18 "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", 19 "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" 20 } 21 } 22 }, 23 "@babel/runtime": { 24 "version": "7.0.0", 25 "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.0.0.tgz", 26 "integrity": "sha512-7hGhzlcmg01CvH1EHdSPVXYX1aJ8KCEyz6I9xYIi/asDtzBPMyMhVibhM/K6g/5qnKBwjZtp10bNZIEFTRW1MA==", 27 "requires": { 28 "regenerator-runtime": "^0.12.0" 29 } 30 }, 31 "@wordpress/shortcode": { 32 "version": "2.0.0", 33 "resolved": "https://registry.npmjs.org/@wordpress/shortcode/-/shortcode-2.0.0.tgz", 34 "integrity": "sha512-XfBIkoX+vjZqDtE8lqOz3YKdX+/xppJryxriNoMaipqOpmcsuDfQxqNrrdr6ETL9CvQ/4gMmGC/oZ1BoqghjLQ==", 35 "requires": { 36 "@babel/runtime": "^7.0.0", 37 "lodash": "^4.17.10" 38 } 39 }, 7 40 "abbrev": { 8 41 "version": "1.1.1", 9 42 "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", … … 1801 1834 }, 1802 1835 "compression": { 1803 1836 "version": "1.7.2", 1804 "resolved": "http s://registry.npmjs.org/compression/-/compression-1.7.2.tgz",1837 "resolved": "http://registry.npmjs.org/compression/-/compression-1.7.2.tgz", 1805 1838 "integrity": "sha1-qv+81qr4VLROuygDU9WtFlH1mmk=", 1806 1839 "dev": true, 1807 1840 "requires": { … … 1909 1942 "integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=", 1910 1943 "dev": true 1911 1944 }, 1945 "core-js": { 1946 "version": "2.5.7", 1947 "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.7.tgz", 1948 "integrity": "sha512-RszJCAxg/PP6uzXVXL6BsxSXx/B05oJAQ2vkJRjyjrEcNVycaqOmNb5OTxZPE3xa5gwZduqza6L9JOCenh/Ecw==" 1949 }, 1912 1950 "core-util-is": { 1913 1951 "version": "1.0.2", 1914 1952 "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", … … 6878 6916 } 6879 6917 }, 6880 6918 "lodash": { 6881 "version": "4.17.10", 6882 "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", 6883 "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==", 6884 "dev": true 6919 "version": "4.17.11", 6920 "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", 6921 "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" 6885 6922 }, 6886 6923 "lodash._basecopy": { 6887 6924 "version": "3.0.1", … … 7245 7282 "mimic-fn": "^1.0.0" 7246 7283 } 7247 7284 }, 7285 "memize": { 7286 "version": "1.0.5", 7287 "resolved": "https://registry.npmjs.org/memize/-/memize-1.0.5.tgz", 7288 "integrity": "sha512-Dm8Jhb5kiC4+ynYsVR4QDXKt+o2dfqGuY4hE2x+XlXZkdndlT80bJxfcMv5QGp/FCy6MhG7f5ElpmKPFKOSEpg==" 7289 }, 7248 7290 "memory-fs": { 7249 7291 "version": "0.4.1", 7250 7292 "resolved": "https://registry.npmjs.org/memory-fs/-/memory-fs-0.4.1.tgz", … … 8151 8193 }, 8152 8194 "onetime": { 8153 8195 "version": "1.1.0", 8154 "resolved": "http s://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",8196 "resolved": "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", 8155 8197 "integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=", 8156 8198 "dev": true 8157 8199 }, … … 8882 8924 "strip-indent": "^1.0.1" 8883 8925 } 8884 8926 }, 8927 "regenerator-runtime": { 8928 "version": "0.12.1", 8929 "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz", 8930 "integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==" 8931 }, 8885 8932 "regex-cache": { 8886 8933 "version": "0.4.4", 8887 8934 "resolved": "https://registry.npmjs.org/regex-cache/-/regex-cache-0.4.4.tgz", -
package.json
diff --git a/package.json b/package.json index 06a5a5e343..caa92d21d6 100644
a b 45 45 "webpack-dev-server": "^2.9.1" 46 46 }, 47 47 "dependencies": { 48 "@babel/polyfill": "7.0.0", 49 "@wordpress/shortcode": "2.0.0", 48 50 "backbone": "1.3.3", 49 51 "imagesloaded": "3.2.0", 50 52 "jquery": "1.12.4", … … 52 54 "jquery-form": "4.2.1", 53 55 "jquery-hoverintent": "1.8.3", 54 56 "jquery-ui": "github:jquery/jquery-ui#1.11.4", 57 "lodash": "4.17.11", 55 58 "masonry-layout": "3.3.2", 59 "memize": "1.0.5", 56 60 "twemoji": "11.0.0", 57 61 "underscore": "1.8.3" 58 62 } -
src/js/_enqueues/wp/shortcode.js
diff --git a/src/js/_enqueues/wp/shortcode.js b/src/js/_enqueues/wp/shortcode.js index 8f02273ba7..6bb2aff311 100644
a b 1 /**2 * Utility functions for parsing and handling shortcodes in JavaScript.3 *4 * @output wp-includes/js/shortcode.js5 */6 7 /**8 * Ensure the global `wp` object exists.9 *10 * @namespace wp11 */12 1 window.wp = window.wp || {}; 13 14 (function(){ 15 wp.shortcode = { 16 // ### Find the next matching shortcode 17 // 18 // Given a shortcode `tag`, a block of `text`, and an optional starting 19 // `index`, returns the next matching shortcode or `undefined`. 20 // 21 // Shortcodes are formatted as an object that contains the match 22 // `content`, the matching `index`, and the parsed `shortcode` object. 23 next: function( tag, text, index ) { 24 var re = wp.shortcode.regexp( tag ), 25 match, result; 26 27 re.lastIndex = index || 0; 28 match = re.exec( text ); 29 30 if ( ! match ) { 31 return; 32 } 33 34 // If we matched an escaped shortcode, try again. 35 if ( '[' === match[1] && ']' === match[7] ) { 36 return wp.shortcode.next( tag, text, re.lastIndex ); 37 } 38 39 result = { 40 index: match.index, 41 content: match[0], 42 shortcode: wp.shortcode.fromMatch( match ) 43 }; 44 45 // If we matched a leading `[`, strip it from the match 46 // and increment the index accordingly. 47 if ( match[1] ) { 48 result.content = result.content.slice( 1 ); 49 result.index++; 50 } 51 52 // If we matched a trailing `]`, strip it from the match. 53 if ( match[7] ) { 54 result.content = result.content.slice( 0, -1 ); 55 } 56 57 return result; 58 }, 59 60 // ### Replace matching shortcodes in a block of text 61 // 62 // Accepts a shortcode `tag`, content `text` to scan, and a `callback` 63 // to process the shortcode matches and return a replacement string. 64 // Returns the `text` with all shortcodes replaced. 65 // 66 // Shortcode matches are objects that contain the shortcode `tag`, 67 // a shortcode `attrs` object, the `content` between shortcode tags, 68 // and a boolean flag to indicate if the match was a `single` tag. 69 replace: function( tag, text, callback ) { 70 return text.replace( wp.shortcode.regexp( tag ), function( match, left, tag, attrs, slash, content, closing, right ) { 71 // If both extra brackets exist, the shortcode has been 72 // properly escaped. 73 if ( left === '[' && right === ']' ) { 74 return match; 75 } 76 77 // Create the match object and pass it through the callback. 78 var result = callback( wp.shortcode.fromMatch( arguments ) ); 79 80 // Make sure to return any of the extra brackets if they 81 // weren't used to escape the shortcode. 82 return result ? left + result + right : match; 83 }); 84 }, 85 86 // ### Generate a string from shortcode parameters 87 // 88 // Creates a `wp.shortcode` instance and returns a string. 89 // 90 // Accepts the same `options` as the `wp.shortcode()` constructor, 91 // containing a `tag` string, a string or object of `attrs`, a boolean 92 // indicating whether to format the shortcode using a `single` tag, and a 93 // `content` string. 94 string: function( options ) { 95 return new wp.shortcode( options ).string(); 96 }, 97 98 // ### Generate a RegExp to identify a shortcode 99 // 100 // The base regex is functionally equivalent to the one found in 101 // `get_shortcode_regex()` in `wp-includes/shortcodes.php`. 102 // 103 // Capture groups: 104 // 105 // 1. An extra `[` to allow for escaping shortcodes with double `[[]]` 106 // 2. The shortcode name 107 // 3. The shortcode argument list 108 // 4. The self closing `/` 109 // 5. The content of a shortcode when it wraps some content. 110 // 6. The closing tag. 111 // 7. An extra `]` to allow for escaping shortcodes with double `[[]]` 112 regexp: _.memoize( function( tag ) { 113 return new RegExp( '\\[(\\[?)(' + tag + ')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)', 'g' ); 114 }), 115 116 117 // ### Parse shortcode attributes 118 // 119 // Shortcodes accept many types of attributes. These can chiefly be 120 // divided into named and numeric attributes: 121 // 122 // Named attributes are assigned on a key/value basis, while numeric 123 // attributes are treated as an array. 124 // 125 // Named attributes can be formatted as either `name="value"`, 126 // `name='value'`, or `name=value`. Numeric attributes can be formatted 127 // as `"value"` or just `value`. 128 attrs: _.memoize( function( text ) { 129 var named = {}, 130 numeric = [], 131 pattern, match; 132 133 // This regular expression is reused from `shortcode_parse_atts()` 134 // in `wp-includes/shortcodes.php`. 135 // 136 // Capture groups: 137 // 138 // 1. An attribute name, that corresponds to... 139 // 2. a value in double quotes. 140 // 3. An attribute name, that corresponds to... 141 // 4. a value in single quotes. 142 // 5. An attribute name, that corresponds to... 143 // 6. an unquoted value. 144 // 7. A numeric attribute in double quotes. 145 // 8. A numeric attribute in single quotes. 146 // 9. An unquoted numeric attribute. 147 pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g; 148 149 // Map zero-width spaces to actual spaces. 150 text = text.replace( /[\u00a0\u200b]/g, ' ' ); 151 152 // Match and normalize attributes. 153 while ( (match = pattern.exec( text )) ) { 154 if ( match[1] ) { 155 named[ match[1].toLowerCase() ] = match[2]; 156 } else if ( match[3] ) { 157 named[ match[3].toLowerCase() ] = match[4]; 158 } else if ( match[5] ) { 159 named[ match[5].toLowerCase() ] = match[6]; 160 } else if ( match[7] ) { 161 numeric.push( match[7] ); 162 } else if ( match[8] ) { 163 numeric.push( match[8] ); 164 } else if ( match[9] ) { 165 numeric.push( match[9] ); 166 } 167 } 168 169 return { 170 named: named, 171 numeric: numeric 172 }; 173 }), 174 175 // ### Generate a Shortcode Object from a RegExp match 176 // Accepts a `match` object from calling `regexp.exec()` on a `RegExp` 177 // generated by `wp.shortcode.regexp()`. `match` can also be set to the 178 // `arguments` from a callback passed to `regexp.replace()`. 179 fromMatch: function( match ) { 180 var type; 181 182 if ( match[4] ) { 183 type = 'self-closing'; 184 } else if ( match[6] ) { 185 type = 'closed'; 186 } else { 187 type = 'single'; 188 } 189 190 return new wp.shortcode({ 191 tag: match[2], 192 attrs: match[3], 193 type: type, 194 content: match[5] 195 }); 196 } 197 }; 198 199 200 // Shortcode Objects 201 // ----------------- 202 // 203 // Shortcode objects are generated automatically when using the main 204 // `wp.shortcode` methods: `next()`, `replace()`, and `string()`. 205 // 206 // To access a raw representation of a shortcode, pass an `options` object, 207 // containing a `tag` string, a string or object of `attrs`, a string 208 // indicating the `type` of the shortcode ('single', 'self-closing', or 209 // 'closed'), and a `content` string. 210 wp.shortcode = _.extend( function( options ) { 211 _.extend( this, _.pick( options || {}, 'tag', 'attrs', 'type', 'content' ) ); 212 213 var attrs = this.attrs; 214 215 // Ensure we have a correctly formatted `attrs` object. 216 this.attrs = { 217 named: {}, 218 numeric: [] 219 }; 220 221 if ( ! attrs ) { 222 return; 223 } 224 225 // Parse a string of attributes. 226 if ( _.isString( attrs ) ) { 227 this.attrs = wp.shortcode.attrs( attrs ); 228 229 // Identify a correctly formatted `attrs` object. 230 } else if ( _.isEqual( _.keys( attrs ), [ 'named', 'numeric' ] ) ) { 231 this.attrs = attrs; 232 233 // Handle a flat object of attributes. 234 } else { 235 _.each( options.attrs, function( value, key ) { 236 this.set( key, value ); 237 }, this ); 238 } 239 }, wp.shortcode ); 240 241 _.extend( wp.shortcode.prototype, { 242 // ### Get a shortcode attribute 243 // 244 // Automatically detects whether `attr` is named or numeric and routes 245 // it accordingly. 246 get: function( attr ) { 247 return this.attrs[ _.isNumber( attr ) ? 'numeric' : 'named' ][ attr ]; 248 }, 249 250 // ### Set a shortcode attribute 251 // 252 // Automatically detects whether `attr` is named or numeric and routes 253 // it accordingly. 254 set: function( attr, value ) { 255 this.attrs[ _.isNumber( attr ) ? 'numeric' : 'named' ][ attr ] = value; 256 return this; 257 }, 258 259 // ### Transform the shortcode match into a string 260 string: function() { 261 var text = '[' + this.tag; 262 263 _.each( this.attrs.numeric, function( value ) { 264 if ( /\s/.test( value ) ) { 265 text += ' "' + value + '"'; 266 } else { 267 text += ' ' + value; 268 } 269 }); 270 271 _.each( this.attrs.named, function( value, name ) { 272 text += ' ' + name + '="' + value + '"'; 273 }); 274 275 // If the tag is marked as `single` or `self-closing`, close the 276 // tag and ignore any additional content. 277 if ( 'single' === this.type ) { 278 return text + ']'; 279 } else if ( 'self-closing' === this.type ) { 280 return text + ' /]'; 281 } 282 283 // Complete the opening tag. 284 text += ']'; 285 286 if ( this.content ) { 287 text += this.content; 288 } 289 290 // Add the closing tag. 291 return text + '[/' + this.tag + ']'; 292 } 293 }); 294 }()); 295 296 // HTML utility functions 297 // ---------------------- 298 // 299 // Experimental. These functions may change or be removed in the future. 300 (function(){ 301 wp.html = _.extend( wp.html || {}, { 302 // ### Parse HTML attributes. 303 // 304 // Converts `content` to a set of parsed HTML attributes. 305 // Utilizes `wp.shortcode.attrs( content )`, which is a valid superset of 306 // the HTML attribute specification. Reformats the attributes into an 307 // object that contains the `attrs` with `key:value` mapping, and a record 308 // of the attributes that were entered using `empty` attribute syntax (i.e. 309 // with no value). 310 attrs: function( content ) { 311 var result, attrs; 312 313 // If `content` ends in a slash, strip it. 314 if ( '/' === content[ content.length - 1 ] ) { 315 content = content.slice( 0, -1 ); 316 } 317 318 result = wp.shortcode.attrs( content ); 319 attrs = result.named; 320 321 _.each( result.numeric, function( key ) { 322 if ( /\s/.test( key ) ) { 323 return; 324 } 325 326 attrs[ key ] = ''; 327 }); 328 329 return attrs; 330 }, 331 332 // ### Convert an HTML-representation of an object to a string. 333 string: function( options ) { 334 var text = '<' + options.tag, 335 content = options.content || ''; 336 337 _.each( options.attrs, function( value, attr ) { 338 text += ' ' + attr; 339 340 // Convert boolean values to strings. 341 if ( _.isBoolean( value ) ) { 342 value = value ? 'true' : 'false'; 343 } 344 345 text += '="' + value + '"'; 346 }); 347 348 // Return the result if it is a self-closing tag. 349 if ( options.single ) { 350 return text + ' />'; 351 } 352 353 // Complete the opening tag. 354 text += '>'; 355 356 // If `content` is an object, recursively call this function. 357 text += _.isObject( content ) ? wp.html.string( content ) : content; 358 359 return text + '</' + options.tag + '>'; 360 } 361 }); 362 }()); 2 window.wp.shortcode = require( '@wordpress/shortcode' ); -
src/wp-includes/script-loader.php
diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 226627ecb0..273eafd91d 100644
a b function wp_default_scripts( &$scripts ) { 372 372 $scripts->add( 'json2', "/wp-includes/js/json2$suffix.js", array(), '2015-05-03' ); 373 373 did_action( 'init' ) && $scripts->add_data( 'json2', 'conditional', 'lt IE 8' ); 374 374 375 $scripts->add( 'wp-polyfill', "/wp-includes/js/wp-polyfill$dev_suffix.js", array(), '7.0.0', 1 ); 376 $scripts->add( 'lodash', "/wp-includes/js/lodash$dev_suffix.js", array(), '4.17.11', 1 ); 377 did_action( 'init' ) && $scripts->add_inline_script( 'lodash', 'window.lodash = _.noConflict();' ); 378 375 379 $scripts->add( 'underscore', "/wp-includes/js/underscore$dev_suffix.js", array(), '1.8.3', 1 ); 376 380 $scripts->add( 'backbone', "/wp-includes/js/backbone$dev_suffix.js", array( 'underscore', 'jquery' ), '1.2.3', 1 ); 377 381 … … function wp_default_scripts( &$scripts ) { 696 700 697 701 $scripts->add( 'accordion', "/wp-admin/js/accordion$suffix.js", array( 'jquery' ), false, 1 ); 698 702 699 $scripts->add( 'shortcode', "/wp-includes/js/shortcode$suffix.js", array( ' underscore' ), false, 1 );703 $scripts->add( 'shortcode', "/wp-includes/js/shortcode$suffix.js", array( 'lodash', 'wp-polyfill' ), false, 1 ); 700 704 $scripts->add( 'media-models', "/wp-includes/js/media-models$suffix.js", array( 'wp-backbone' ), false, 1 ); 701 705 did_action( 'init' ) && $scripts->localize( 702 706 'media-models', -
deleted file tests/qunit/wp-includes/js/shortcode.js
diff --git a/tests/qunit/wp-includes/js/shortcode.js b/tests/qunit/wp-includes/js/shortcode.js deleted file mode 100644 index 2fd3c54d4c..0000000000
+ - 1 /* global wp, jQuery */2 jQuery( function() {3 module( 'shortcode' );4 5 test( 'next() should find the shortcode', function() {6 var result;7 8 // Basic9 result = wp.shortcode.next( 'foo', 'this has the [foo] shortcode' );10 equal( result.index, 13, 'foo shortcode found at index 13' );11 12 result = wp.shortcode.next( 'foo', 'this has the [foo param="foo"] shortcode' );13 equal( result.index, 13, 'foo shortcode with params found at index 13' );14 });15 16 test( 'next() should not find shortcodes that are not there', function() {17 var result;18 19 // Not found20 result = wp.shortcode.next( 'bar', 'this has the [foo] shortcode' );21 equal( result, undefined, 'bar shortcode not found' );22 23 result = wp.shortcode.next( 'bar', 'this has the [foo param="bar"] shortcode' );24 equal( result, undefined, 'bar shortcode not found with params' );25 });26 27 test( 'next() should find the shortcode when told to start looking beyond the start of the string', function() {28 var result;29 30 // Starting at indices31 result = wp.shortcode.next( 'foo', 'this has the [foo] shortcode', 12 );32 equal( result.index, 13, 'foo shortcode found before index 13' );33 34 result = wp.shortcode.next( 'foo', 'this has the [foo] shortcode', 13 );35 equal( result.index, 13, 'foo shortcode found at index 13' );36 37 result = wp.shortcode.next( 'foo', 'this has the [foo] shortcode', 14 );38 equal( result, undefined, 'foo shortcode not found after index 13' );39 });40 41 test( 'next() should find the second instances of the shortcode when the starting indice is after the start of the first one', function() {42 var result;43 44 result = wp.shortcode.next( 'foo', 'this has the [foo] shortcode [foo] twice', 14 );45 equal( result.index, 29, 'foo shortcode found the second foo at index 29' );46 });47 48 49 test( 'next() should not find escaped shortcodes', function() {50 var result;51 52 // Escaped53 result = wp.shortcode.next( 'foo', 'this has the [[foo]] shortcode' );54 equal( result, undefined, 'foo shortcode not found when escaped' );55 56 result = wp.shortcode.next( 'foo', 'this has the [[foo param="foo"]] shortcode' );57 equal( result, undefined, 'foo shortcode not found when escaped with params' );58 });59 60 test( 'next() should find shortcodes that are incorrectly escaped by newlines', function() {61 var result;62 63 result = wp.shortcode.next( 'foo', 'this has the [\n[foo]] shortcode' );64 equal( result.index, 15, 'shortcode found when incorrectly escaping the start of it' );65 66 result = wp.shortcode.next( 'foo', 'this has the [[foo]\n] shortcode' );67 equal( result.index, 14, 'shortcode found when incorrectly escaping the end of it' );68 });69 70 test( 'next() should still work when there are not equal ammounts of square brackets', function() {71 var result;72 73 result = wp.shortcode.next( 'foo', 'this has the [[foo] shortcode' );74 equal( result.index, 14, 'shortcode found when there are offset square brackets' );75 76 result = wp.shortcode.next( 'foo', 'this has the [foo]] shortcode' );77 equal( result.index, 13, 'shortcode found when there are offset square brackets' );78 });79 80 test( 'next() should find the second instances of the shortcode when the first one is escaped', function() {81 var result;82 83 84 result = wp.shortcode.next( 'foo', 'this has the [[foo]] shortcode [foo] twice' );85 equal( result.index, 31, 'foo shortcode found the non-escaped foo at index 31' );86 });87 88 test( 'next() should not find shortcodes that are not full matches', function() {89 var result;90 91 // Stubs92 result = wp.shortcode.next( 'foo', 'this has the [foobar] shortcode' );93 equal( result, undefined, 'stub does not trigger match' );94 95 result = wp.shortcode.next( 'foobar', 'this has the [foo] shortcode' );96 equal( result, undefined, 'stub does not trigger match' );97 });98 99 test( 'replace() should replace the shortcode', function() {100 var result;101 102 // Basic103 result = wp.shortcode.replace( 'foo', 'this has the [foo] shortcode', shortcodeReplaceCallback );104 equal( result, 'this has the bar shortcode', 'foo replaced with bar' );105 106 result = wp.shortcode.replace( 'foo', 'this has the [foo param="foo"] shortcode', shortcodeReplaceCallback );107 equal( result, 'this has the bar shortcode', 'foo and params replaced with bar' );108 });109 110 test( 'replace() should not replace the shortcode when it does not match', function() {111 var result;112 113 // Not found114 result = wp.shortcode.replace( 'bar', 'this has the [foo] shortcode', shortcodeReplaceCallback );115 equal( result, 'this has the [foo] shortcode', 'bar not found' );116 117 result = wp.shortcode.replace( 'bar', 'this has the [foo param="bar"] shortcode', shortcodeReplaceCallback );118 equal( result, 'this has the [foo param="bar"] shortcode', 'bar not found with params' );119 });120 121 test( 'replace() should replace the shortcode in all instances of its use', function() {122 var result;123 124 // Multiple instances125 result = wp.shortcode.replace( 'foo', 'this has the [foo] shortcode [foo] twice', shortcodeReplaceCallback );126 equal( result, 'this has the bar shortcode bar twice', 'foo replaced with bar twice' );127 128 result = wp.shortcode.replace( 'foo', 'this has the [foo param="foo"] shortcode [foo] twice', shortcodeReplaceCallback );129 equal( result, 'this has the bar shortcode bar twice', 'foo and params replaced with bar twice' );130 });131 132 test( 'replace() should not replace the escaped shortcodes', function() {133 var result;134 135 // Escaped136 result = wp.shortcode.replace( 'foo', 'this has the [[foo]] shortcode', shortcodeReplaceCallback );137 equal( result, 'this has the [[foo]] shortcode', 'escaped foo not replaced' );138 139 result = wp.shortcode.replace( 'foo', 'this has the [[foo param="bar"]] shortcode', shortcodeReplaceCallback );140 equal( result, 'this has the [[foo param="bar"]] shortcode', 'escaped foo with params not replaced' );141 142 result = wp.shortcode.replace( 'foo', 'this [foo] has the [[foo param="bar"]] shortcode escaped', shortcodeReplaceCallback );143 equal( result, 'this bar has the [[foo param="bar"]] shortcode escaped', 'escaped foo with params not replaced but unescaped foo replaced' );144 });145 146 test( 'replace() should replace improperly escaped shortcodes that include newlines', function() {147 var result;148 149 result = wp.shortcode.replace( 'foo', 'this [foo] has the [[foo param="bar"]\n] shortcode ', shortcodeReplaceCallback );150 equal( result, 'this bar has the [bar\n] shortcode ', 'escaping with newlines should not actually escape the content' );151 152 result = wp.shortcode.replace( 'foo', 'this [foo] has the [\n[foo param="bar"]] shortcode ', shortcodeReplaceCallback );153 equal( result, 'this bar has the [\nbar] shortcode ', 'escaping with newlines should not actually escape the content' );154 });155 156 test( 'replace() should not replace the shortcode when it is an incomplete match', function() {157 var result;158 159 // Stubs160 result = wp.shortcode.replace( 'foo', 'this has the [foobar] shortcode', shortcodeReplaceCallback );161 equal( result, 'this has the [foobar] shortcode', 'stub not replaced' );162 163 result = wp.shortcode.replace( 'foobar', 'this has the [foo] shortcode', shortcodeReplaceCallback );164 equal( result, 'this has the [foo] shortcode', 'stub not replaced' );165 });166 167 // A callback function for the replace tests168 function shortcodeReplaceCallback( ) {169 return 'bar';170 }171 172 test( 'attrs() should return named attributes created with single, double, and no quotes', function() {173 var expected = {174 'named': {175 'param': 'foo',176 'another': 'bar',177 'andagain': 'baz'178 }, 'numeric' : []179 };180 181 deepEqual( wp.shortcode.attrs('param="foo" another=\'bar\' andagain=baz'), expected, 'attr parsed all three named types');182 });183 184 test( 'attrs() should return numeric attributes in the order they are used', function() {185 var expected = {186 'named': {}, 'numeric' : ['foo', 'bar', 'baz']187 };188 189 deepEqual( wp.shortcode.attrs('foo bar baz'), expected, 'attr parsed numeric attributes');190 });191 192 test( 'attrs() should return numeric attributes in the order they are used when they have named attributes in between', function() {193 var expected = {194 'named': { 'not': 'a blocker' }, 'numeric' : ['foo', 'bar', 'baz']195 };196 197 deepEqual( wp.shortcode.attrs('foo not="a blocker" bar baz'), expected, 'attr parsed numeric attributes');198 });199 200 test( 'attrs() should return numeric attributes created with single, double, and no quotes', function() {201 var expected = {202 'named': {}, 'numeric' : ['foo', 'bar', 'baz']203 };204 205 deepEqual( wp.shortcode.attrs('foo "bar" \'baz\''), expected, 'attr parsed numeric attributes');206 });207 208 test( 'attrs() should return mixed attributes created with single, double, and no quotes', function() {209 var expected = {210 'named': { a: 'foo', b: 'bar', c: 'baz' }, 'numeric' : ['foo', 'bar', 'baz']211 };212 213 deepEqual( wp.shortcode.attrs('a="foo" b=\'bar\' c=baz foo "bar" \'baz\''), expected, 'attr parsed numeric attributes');214 });215 }); -
webpack.config.dev.js
diff --git a/webpack.config.dev.js b/webpack.config.dev.js index cf6fa9ea88..e2d16aa134 100644
a b 1 1 var path = require( 'path' ), 2 webpack = require( 'webpack'),2 webpack = require('webpack'), 3 3 admin_files = {}, 4 4 include_files = {}; 5 5 … … include_files = { 12 12 'build/wp-includes/js/media-models.min.js': ['./src/js/_enqueues/wp/media/models.js'], 13 13 'build/wp-includes/js/media-views.js': ['./src/js/_enqueues/wp/media/views.js'], 14 14 'build/wp-includes/js/media-views.min.js': ['./src/js/_enqueues/wp/media/views.js'], 15 'build/wp-includes/js/shortcode.js': ['./src/js/_enqueues/wp/shortcode.js'], 16 'build/wp-includes/js/shortcode.min.js': ['./src/js/_enqueues/wp/shortcode.js'], 15 17 }; 16 18 19 const vendors = { 20 'lodash': 'lodash', 21 'wp-polyfill': '@babel/polyfill' 22 }; 23 24 const externals = { 25 lodash: 'lodash', 26 'lodash-es': 'lodash', 27 }; 28 29 /** 30 * Given a string, returns a new string with dash separators converedd to 31 * camel-case equivalent. This is not as aggressive as `_.camelCase` in 32 * converting to uppercase, where Lodash will convert letters following 33 * numbers. 34 * 35 * @param {string} string Input dash-delimited string. 36 * 37 * @return {string} Camel-cased string. 38 */ 39 function camelCaseDash( string ) { 40 return string.replace( 41 /-([a-z])/g, 42 ( match, letter ) => letter.toUpperCase() 43 ); 44 } 45 17 46 module.exports = [ 18 47 { 19 48 cache: true, 20 49 watch: false, 21 entry: Object.assign( admin_files, include_files ), 50 entry: Object.assign( 51 admin_files, 52 include_files, 53 Object.keys(vendors).reduce( ( memo, fileName ) => { 54 const packageName = vendors[ fileName ]; 55 memo[ `build/wp-includes/js/${ fileName }.js` ] = `./node_modules/${ packageName }`; 56 memo[ `build/wp-includes/js/${ fileName }.min.js` ] = `./node_modules/${ packageName }`; 57 return memo; 58 }, {} ) 59 ), 22 60 output: { 23 61 filename: '[name]', 24 62 }, 63 externals, 25 64 plugins: [ 26 65 new webpack.optimize.UglifyJsPlugin({ 27 66 include: /\.min\.js$/, -
webpack.config.prod.js
diff --git a/webpack.config.prod.js b/webpack.config.prod.js index e6ba61f27e..1e2f71f190 100644
a b 1 var path = require( 'path' ), 2 webpack = require( 'webpack' ), 3 admin_files = {}, 4 include_files = {}; 1 const webpack = require( 'webpack' ) 2 const config = require( './webpack.config.dev' ); 5 3 6 include_files = { 7 'build/wp-includes/js/media-audiovideo.js': ['./src/js/_enqueues/wp/media/audiovideo.js'], 8 'build/wp-includes/js/media-audiovideo.min.js': ['./src/js/_enqueues/wp/media/audiovideo.js'], 9 'build/wp-includes/js/media-grid.js': ['./src/js/_enqueues/wp/media/grid.js'], 10 'build/wp-includes/js/media-grid.min.js': ['./src/js/_enqueues/wp/media/grid.js'], 11 'build/wp-includes/js/media-models.js': ['./src/js/_enqueues/wp/media/models.js'], 12 'build/wp-includes/js/media-models.min.js': ['./src/js/_enqueues/wp/media/models.js'], 13 'build/wp-includes/js/media-views.js': ['./src/js/_enqueues/wp/media/views.js'], 14 'build/wp-includes/js/media-views.min.js': ['./src/js/_enqueues/wp/media/views.js'], 15 }; 16 17 module.exports = [ 18 { 19 cache: true, 20 watch: false, 21 entry: Object.assign( admin_files, include_files ), 22 output: { 23 filename: '[name]', 24 }, 25 plugins: [ 26 new webpack.optimize.ModuleConcatenationPlugin(), 27 new webpack.optimize.UglifyJsPlugin({ 28 include: /\.min\.js$/, 29 minimize: true 30 }) 31 ] 32 } 4 config[0].plugins = [ 5 new webpack.optimize.ModuleConcatenationPlugin(), 6 ...config[0].plugins 33 7 ]; 8 9 module.exports = config; 10 No newline at end of file
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)