[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-includes/js/dist/ -> shortcode.js (source)

   1  this["wp"] = this["wp"] || {}; this["wp"]["shortcode"] =
   2  /******/ (function(modules) { // webpackBootstrap
   3  /******/     // The module cache
   4  /******/     var installedModules = {};
   5  /******/
   6  /******/     // The require function
   7  /******/ 	function __webpack_require__(moduleId) {
   8  /******/
   9  /******/         // Check if module is in cache
  10  /******/         if(installedModules[moduleId]) {
  11  /******/             return installedModules[moduleId].exports;
  12  /******/         }
  13  /******/         // Create a new module (and put it into the cache)
  14  /******/         var module = installedModules[moduleId] = {
  15  /******/             i: moduleId,
  16  /******/             l: false,
  17  /******/             exports: {}
  18  /******/         };
  19  /******/
  20  /******/         // Execute the module function
  21  /******/         modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22  /******/
  23  /******/         // Flag the module as loaded
  24  /******/         module.l = true;
  25  /******/
  26  /******/         // Return the exports of the module
  27  /******/         return module.exports;
  28  /******/     }
  29  /******/
  30  /******/
  31  /******/     // expose the modules object (__webpack_modules__)
  32  /******/     __webpack_require__.m = modules;
  33  /******/
  34  /******/     // expose the module cache
  35  /******/     __webpack_require__.c = installedModules;
  36  /******/
  37  /******/     // define getter function for harmony exports
  38  /******/     __webpack_require__.d = function(exports, name, getter) {
  39  /******/         if(!__webpack_require__.o(exports, name)) {
  40  /******/             Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41  /******/         }
  42  /******/     };
  43  /******/
  44  /******/     // define __esModule on exports
  45  /******/     __webpack_require__.r = function(exports) {
  46  /******/         if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47  /******/             Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48  /******/         }
  49  /******/         Object.defineProperty(exports, '__esModule', { value: true });
  50  /******/     };
  51  /******/
  52  /******/     // create a fake namespace object
  53  /******/     // mode & 1: value is a module id, require it
  54  /******/     // mode & 2: merge all properties of value into the ns
  55  /******/     // mode & 4: return value when already ns object
  56  /******/     // mode & 8|1: behave like require
  57  /******/     __webpack_require__.t = function(value, mode) {
  58  /******/         if(mode & 1) value = __webpack_require__(value);
  59  /******/         if(mode & 8) return value;
  60  /******/         if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61  /******/         var ns = Object.create(null);
  62  /******/         __webpack_require__.r(ns);
  63  /******/         Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64  /******/         if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65  /******/         return ns;
  66  /******/     };
  67  /******/
  68  /******/     // getDefaultExport function for compatibility with non-harmony modules
  69  /******/     __webpack_require__.n = function(module) {
  70  /******/         var getter = module && module.__esModule ?
  71  /******/ 			function getDefault() { return module['default']; } :
  72  /******/ 			function getModuleExports() { return module; };
  73  /******/         __webpack_require__.d(getter, 'a', getter);
  74  /******/         return getter;
  75  /******/     };
  76  /******/
  77  /******/     // Object.prototype.hasOwnProperty.call
  78  /******/     __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79  /******/
  80  /******/     // __webpack_public_path__
  81  /******/     __webpack_require__.p = "";
  82  /******/
  83  /******/
  84  /******/     // Load entry module and return exports
  85  /******/     return __webpack_require__(__webpack_require__.s = 336);
  86  /******/ })
  87  /************************************************************************/
  88  /******/ ({
  89  
  90  /***/ 2:
  91  /***/ (function(module, exports) {
  92  
  93  (function() { module.exports = this["lodash"]; }());
  94  
  95  /***/ }),
  96  
  97  /***/ 336:
  98  /***/ (function(module, __webpack_exports__, __webpack_require__) {
  99  
 100  "use strict";
 101  __webpack_require__.r(__webpack_exports__);
 102  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "next", function() { return next; });
 103  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "replace", function() { return replace; });
 104  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "string", function() { return string; });
 105  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "regexp", function() { return regexp; });
 106  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "attrs", function() { return attrs; });
 107  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "fromMatch", function() { return fromMatch; });
 108  /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
 109  /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);
 110  /* harmony import */ var memize__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(44);
 111  /* harmony import */ var memize__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(memize__WEBPACK_IMPORTED_MODULE_1__);
 112  /**
 113   * External dependencies
 114   */
 115  
 116  
 117  /**
 118   * Shortcode attributes object.
 119   *
 120   * @typedef {Object} WPShortcodeAttrs
 121   *
 122   * @property {Object} named   Object with named attributes.
 123   * @property {Array}  numeric Array with numeric attributes.
 124   */
 125  
 126  /**
 127   * Shortcode object.
 128   *
 129   * @typedef {Object} WPShortcode
 130   *
 131   * @property {string}           tag     Shortcode tag.
 132   * @property {WPShortcodeAttrs} attrs   Shortcode attributes.
 133   * @property {string}           content Shortcode content.
 134   * @property {string}           type    Shortcode type: `self-closing`,
 135   *                                      `closed`, or `single`.
 136   */
 137  
 138  /**
 139   * @typedef {Object} WPShortcodeMatch
 140   *
 141   * @property {number}      index     Index the shortcode is found at.
 142   * @property {string}      content   Matched content.
 143   * @property {WPShortcode} shortcode Shortcode instance of the match.
 144   */
 145  
 146  /**
 147   * Find the next matching shortcode.
 148   *
 149   * @param {string} tag   Shortcode tag.
 150   * @param {string} text  Text to search.
 151   * @param {number} index Index to start search from.
 152   *
 153   * @return {?WPShortcodeMatch} Matched information.
 154   */
 155  
 156  function next(tag, text) {
 157    var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
 158    var re = regexp(tag);
 159    re.lastIndex = index;
 160    var match = re.exec(text);
 161  
 162    if (!match) {
 163      return;
 164    } // If we matched an escaped shortcode, try again.
 165  
 166  
 167    if ('[' === match[1] && ']' === match[7]) {
 168      return next(tag, text, re.lastIndex);
 169    }
 170  
 171    var result = {
 172      index: match.index,
 173      content: match[0],
 174      shortcode: fromMatch(match)
 175    }; // If we matched a leading `[`, strip it from the match and increment the
 176    // index accordingly.
 177  
 178    if (match[1]) {
 179      result.content = result.content.slice(1);
 180      result.index++;
 181    } // If we matched a trailing `]`, strip it from the match.
 182  
 183  
 184    if (match[7]) {
 185      result.content = result.content.slice(0, -1);
 186    }
 187  
 188    return result;
 189  }
 190  /**
 191   * Replace matching shortcodes in a block of text.
 192   *
 193   * @param {string}   tag      Shortcode tag.
 194   * @param {string}   text     Text to search.
 195   * @param {Function} callback Function to process the match and return
 196   *                            replacement string.
 197   *
 198   * @return {string} Text with shortcodes replaced.
 199   */
 200  
 201  function replace(tag, text, callback) {
 202    return text.replace(regexp(tag), function (match, left, $3, attrs, slash, content, closing, right) {
 203      // If both extra brackets exist, the shortcode has been properly
 204      // escaped.
 205      if (left === '[' && right === ']') {
 206        return match;
 207      } // Create the match object and pass it through the callback.
 208  
 209  
 210      var result = callback(fromMatch(arguments)); // Make sure to return any of the extra brackets if they weren't used to
 211      // escape the shortcode.
 212  
 213      return result ? left + result + right : match;
 214    });
 215  }
 216  /**
 217   * Generate a string from shortcode parameters.
 218   *
 219   * Creates a shortcode instance and returns a string.
 220   *
 221   * Accepts the same `options` as the `shortcode()` constructor, containing a
 222   * `tag` string, a string or object of `attrs`, a boolean indicating whether to
 223   * format the shortcode using a `single` tag, and a `content` string.
 224   *
 225   * @param {Object} options
 226   *
 227   * @return {string} String representation of the shortcode.
 228   */
 229  
 230  function string(options) {
 231    return new shortcode(options).string();
 232  }
 233  /**
 234   * Generate a RegExp to identify a shortcode.
 235   *
 236   * The base regex is functionally equivalent to the one found in
 237   * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.
 238   *
 239   * Capture groups:
 240   *
 241   * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`
 242   * 2. The shortcode name
 243   * 3. The shortcode argument list
 244   * 4. The self closing `/`
 245   * 5. The content of a shortcode when it wraps some content.
 246   * 6. The closing tag.
 247   * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`
 248   *
 249   * @param {string} tag Shortcode tag.
 250   *
 251   * @return {RegExp} Shortcode RegExp.
 252   */
 253  
 254  function regexp(tag) {
 255    return new RegExp('\\[(\\[?)(' + tag + ')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)', 'g');
 256  }
 257  /**
 258   * Parse shortcode attributes.
 259   *
 260   * Shortcodes accept many types of attributes. These can chiefly be divided into
 261   * named and numeric attributes:
 262   *
 263   * Named attributes are assigned on a key/value basis, while numeric attributes
 264   * are treated as an array.
 265   *
 266   * Named attributes can be formatted as either `name="value"`, `name='value'`,
 267   * or `name=value`. Numeric attributes can be formatted as `"value"` or just
 268   * `value`.
 269   *
 270   * @param {string} text Serialised shortcode attributes.
 271   *
 272   * @return {WPShortcodeAttrs} Parsed shortcode attributes.
 273   */
 274  
 275  var attrs = memize__WEBPACK_IMPORTED_MODULE_1___default()(function (text) {
 276    var named = {};
 277    var numeric = []; // This regular expression is reused from `shortcode_parse_atts()` in
 278    // `wp-includes/shortcodes.php`.
 279    //
 280    // Capture groups:
 281    //
 282    // 1. An attribute name, that corresponds to...
 283    // 2. a value in double quotes.
 284    // 3. An attribute name, that corresponds to...
 285    // 4. a value in single quotes.
 286    // 5. An attribute name, that corresponds to...
 287    // 6. an unquoted value.
 288    // 7. A numeric attribute in double quotes.
 289    // 8. A numeric attribute in single quotes.
 290    // 9. An unquoted numeric attribute.
 291  
 292    var pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g; // Map zero-width spaces to actual spaces.
 293  
 294    text = text.replace(/[\u00a0\u200b]/g, ' ');
 295    var match; // Match and normalize attributes.
 296  
 297    while (match = pattern.exec(text)) {
 298      if (match[1]) {
 299        named[match[1].toLowerCase()] = match[2];
 300      } else if (match[3]) {
 301        named[match[3].toLowerCase()] = match[4];
 302      } else if (match[5]) {
 303        named[match[5].toLowerCase()] = match[6];
 304      } else if (match[7]) {
 305        numeric.push(match[7]);
 306      } else if (match[8]) {
 307        numeric.push(match[8]);
 308      } else if (match[9]) {
 309        numeric.push(match[9]);
 310      }
 311    }
 312  
 313    return {
 314      named: named,
 315      numeric: numeric
 316    };
 317  });
 318  /**
 319   * Generate a Shortcode Object from a RegExp match.
 320   *
 321   * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated
 322   * by `regexp()`. `match` can also be set to the `arguments` from a callback
 323   * passed to `regexp.replace()`.
 324   *
 325   * @param {Array} match Match array.
 326   *
 327   * @return {WPShortcode} Shortcode instance.
 328   */
 329  
 330  function fromMatch(match) {
 331    var type;
 332  
 333    if (match[4]) {
 334      type = 'self-closing';
 335    } else if (match[6]) {
 336      type = 'closed';
 337    } else {
 338      type = 'single';
 339    }
 340  
 341    return new shortcode({
 342      tag: match[2],
 343      attrs: match[3],
 344      type: type,
 345      content: match[5]
 346    });
 347  }
 348  /**
 349   * Creates a shortcode instance.
 350   *
 351   * To access a raw representation of a shortcode, pass an `options` object,
 352   * containing a `tag` string, a string or object of `attrs`, a string indicating
 353   * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a
 354   * `content` string.
 355   *
 356   * @param {Object} options Options as described.
 357   *
 358   * @return {WPShortcode} Shortcode instance.
 359   */
 360  
 361  var shortcode = Object(lodash__WEBPACK_IMPORTED_MODULE_0__["extend"])(function (options) {
 362    var _this = this;
 363  
 364    Object(lodash__WEBPACK_IMPORTED_MODULE_0__["extend"])(this, Object(lodash__WEBPACK_IMPORTED_MODULE_0__["pick"])(options || {}, 'tag', 'attrs', 'type', 'content'));
 365    var attributes = this.attrs; // Ensure we have a correctly formatted `attrs` object.
 366  
 367    this.attrs = {
 368      named: {},
 369      numeric: []
 370    };
 371  
 372    if (!attributes) {
 373      return;
 374    } // Parse a string of attributes.
 375  
 376  
 377    if (Object(lodash__WEBPACK_IMPORTED_MODULE_0__["isString"])(attributes)) {
 378      this.attrs = attrs(attributes); // Identify a correctly formatted `attrs` object.
 379    } else if (Object(lodash__WEBPACK_IMPORTED_MODULE_0__["isEqual"])(Object.keys(attributes), ['named', 'numeric'])) {
 380      this.attrs = attributes; // Handle a flat object of attributes.
 381    } else {
 382      Object(lodash__WEBPACK_IMPORTED_MODULE_0__["forEach"])(attributes, function (value, key) {
 383        _this.set(key, value);
 384      });
 385    }
 386  }, {
 387    next: next,
 388    replace: replace,
 389    string: string,
 390    regexp: regexp,
 391    attrs: attrs,
 392    fromMatch: fromMatch
 393  });
 394  Object(lodash__WEBPACK_IMPORTED_MODULE_0__["extend"])(shortcode.prototype, {
 395    /**
 396     * Get a shortcode attribute.
 397     *
 398     * Automatically detects whether `attr` is named or numeric and routes it
 399     * accordingly.
 400     *
 401     * @param {(number|string)} attr Attribute key.
 402     *
 403     * @return {string} Attribute value.
 404     */
 405    get: function get(attr) {
 406      return this.attrs[Object(lodash__WEBPACK_IMPORTED_MODULE_0__["isNumber"])(attr) ? 'numeric' : 'named'][attr];
 407    },
 408  
 409    /**
 410     * Set a shortcode attribute.
 411     *
 412     * Automatically detects whether `attr` is named or numeric and routes it
 413     * accordingly.
 414     *
 415     * @param {(number|string)} attr  Attribute key.
 416     * @param {string}          value Attribute value.
 417     *
 418     * @return {WPShortcode} Shortcode instance.
 419     */
 420    set: function set(attr, value) {
 421      this.attrs[Object(lodash__WEBPACK_IMPORTED_MODULE_0__["isNumber"])(attr) ? 'numeric' : 'named'][attr] = value;
 422      return this;
 423    },
 424  
 425    /**
 426     * Transform the shortcode into a string.
 427     *
 428     * @return {string} String representation of the shortcode.
 429     */
 430    string: function string() {
 431      var text = '[' + this.tag;
 432      Object(lodash__WEBPACK_IMPORTED_MODULE_0__["forEach"])(this.attrs.numeric, function (value) {
 433        if (/\s/.test(value)) {
 434          text += ' "' + value + '"';
 435        } else {
 436          text += ' ' + value;
 437        }
 438      });
 439      Object(lodash__WEBPACK_IMPORTED_MODULE_0__["forEach"])(this.attrs.named, function (value, name) {
 440        text += ' ' + name + '="' + value + '"';
 441      }); // If the tag is marked as `single` or `self-closing`, close the tag and
 442      // ignore any additional content.
 443  
 444      if ('single' === this.type) {
 445        return text + ']';
 446      } else if ('self-closing' === this.type) {
 447        return text + ' /]';
 448      } // Complete the opening tag.
 449  
 450  
 451      text += ']';
 452  
 453      if (this.content) {
 454        text += this.content;
 455      } // Add the closing tag.
 456  
 457  
 458      return text + '[/' + this.tag + ']';
 459    }
 460  });
 461  /* harmony default export */ __webpack_exports__["default"] = (shortcode);
 462  
 463  
 464  /***/ }),
 465  
 466  /***/ 44:
 467  /***/ (function(module, exports, __webpack_require__) {
 468  
 469  module.exports = function memize( fn, options ) {
 470      var size = 0,
 471          maxSize, head, tail;
 472  
 473      if ( options && options.maxSize ) {
 474          maxSize = options.maxSize;
 475      }
 476  
 477  	function memoized( /* ...args */ ) {
 478          var node = head,
 479              len = arguments.length,
 480              args, i;
 481  
 482          searchCache: while ( node ) {
 483              // Perform a shallow equality test to confirm that whether the node
 484              // under test is a candidate for the arguments passed. Two arrays
 485              // are shallowly equal if their length matches and each entry is
 486              // strictly equal between the two sets. Avoid abstracting to a
 487              // function which could incur an arguments leaking deoptimization.
 488  
 489              // Check whether node arguments match arguments length
 490              if ( node.args.length !== arguments.length ) {
 491                  node = node.next;
 492                  continue;
 493              }
 494  
 495              // Check whether node arguments match arguments values
 496              for ( i = 0; i < len; i++ ) {
 497                  if ( node.args[ i ] !== arguments[ i ] ) {
 498                      node = node.next;
 499                      continue searchCache;
 500                  }
 501              }
 502  
 503              // At this point we can assume we've found a match
 504  
 505              // Surface matched node to head if not already
 506              if ( node !== head ) {
 507                  // As tail, shift to previous. Must only shift if not also
 508                  // head, since if both head and tail, there is no previous.
 509                  if ( node === tail ) {
 510                      tail = node.prev;
 511                  }
 512  
 513                  // Adjust siblings to point to each other. If node was tail,
 514                  // this also handles new tail's empty `next` assignment.
 515                  node.prev.next = node.next;
 516                  if ( node.next ) {
 517                      node.next.prev = node.prev;
 518                  }
 519  
 520                  node.next = head;
 521                  node.prev = null;
 522                  head.prev = node;
 523                  head = node;
 524              }
 525  
 526              // Return immediately
 527              return node.val;
 528          }
 529  
 530          // No cached value found. Continue to insertion phase:
 531  
 532          // Create a copy of arguments (avoid leaking deoptimization)
 533          args = new Array( len );
 534          for ( i = 0; i < len; i++ ) {
 535              args[ i ] = arguments[ i ];
 536          }
 537  
 538          node = {
 539              args: args,
 540  
 541              // Generate the result from original function
 542              val: fn.apply( null, args )
 543          };
 544  
 545          // Don't need to check whether node is already head, since it would
 546          // have been returned above already if it was
 547  
 548          // Shift existing head down list
 549          if ( head ) {
 550              head.prev = node;
 551              node.next = head;
 552          } else {
 553              // If no head, follows that there's no tail (at initial or reset)
 554              tail = node;
 555          }
 556  
 557          // Trim tail if we're reached max size and are pending cache insertion
 558          if ( size === maxSize ) {
 559              tail = tail.prev;
 560              tail.next = null;
 561          } else {
 562              size++;
 563          }
 564  
 565          head = node;
 566  
 567          return node.val;
 568      }
 569  
 570      memoized.clear = function() {
 571          head = null;
 572          tail = null;
 573          size = 0;
 574      };
 575  
 576      if ( false ) {}
 577  
 578      return memoized;
 579  };
 580  
 581  
 582  /***/ })
 583  
 584  /******/ })["default"];


Generated: Sat Nov 23 20:47:33 2019 Cross-referenced by PHPXref 0.7