[ Index ]

PHP Cross Reference of WordPress

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 = 338);
  86  /******/ })
  87  /************************************************************************/
  88  /******/ ({
  89  
  90  /***/ 2:
  91  /***/ (function(module, exports) {
  92  
  93  (function() { module.exports = this["lodash"]; }());
  94  
  95  /***/ }),
  96  
  97  /***/ 338:
  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__(41);
 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    var _arguments = arguments;
 203    return text.replace(regexp(tag), function (match, left, $3, attrs, slash, content, closing, right) {
 204      // If both extra brackets exist, the shortcode has been properly
 205      // escaped.
 206      if (left === '[' && right === ']') {
 207        return match;
 208      } // Create the match object and pass it through the callback.
 209  
 210  
 211      var result = callback(fromMatch(_arguments)); // Make sure to return any of the extra brackets if they weren't used to
 212      // escape the shortcode.
 213  
 214      return result ? left + result + right : match;
 215    });
 216  }
 217  /**
 218   * Generate a string from shortcode parameters.
 219   *
 220   * Creates a shortcode instance and returns a string.
 221   *
 222   * Accepts the same `options` as the `shortcode()` constructor, containing a
 223   * `tag` string, a string or object of `attrs`, a boolean indicating whether to
 224   * format the shortcode using a `single` tag, and a `content` string.
 225   *
 226   * @param {Object} options
 227   *
 228   * @return {string} String representation of the shortcode.
 229   */
 230  
 231  function string(options) {
 232    return new shortcode(options).string();
 233  }
 234  /**
 235   * Generate a RegExp to identify a shortcode.
 236   *
 237   * The base regex is functionally equivalent to the one found in
 238   * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.
 239   *
 240   * Capture groups:
 241   *
 242   * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`
 243   * 2. The shortcode name
 244   * 3. The shortcode argument list
 245   * 4. The self closing `/`
 246   * 5. The content of a shortcode when it wraps some content.
 247   * 6. The closing tag.
 248   * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`
 249   *
 250   * @param {string} tag Shortcode tag.
 251   *
 252   * @return {RegExp} Shortcode RegExp.
 253   */
 254  
 255  function regexp(tag) {
 256    return new RegExp('\\[(\\[?)(' + tag + ')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)', 'g');
 257  }
 258  /**
 259   * Parse shortcode attributes.
 260   *
 261   * Shortcodes accept many types of attributes. These can chiefly be divided into
 262   * named and numeric attributes:
 263   *
 264   * Named attributes are assigned on a key/value basis, while numeric attributes
 265   * are treated as an array.
 266   *
 267   * Named attributes can be formatted as either `name="value"`, `name='value'`,
 268   * or `name=value`. Numeric attributes can be formatted as `"value"` or just
 269   * `value`.
 270   *
 271   * @param {string} text Serialised shortcode attributes.
 272   *
 273   * @return {WPShortcodeAttrs} Parsed shortcode attributes.
 274   */
 275  
 276  var attrs = memize__WEBPACK_IMPORTED_MODULE_1___default()(function (text) {
 277    var named = {};
 278    var numeric = []; // This regular expression is reused from `shortcode_parse_atts()` in
 279    // `wp-includes/shortcodes.php`.
 280    //
 281    // Capture groups:
 282    //
 283    // 1. An attribute name, that corresponds to...
 284    // 2. a value in double quotes.
 285    // 3. An attribute name, that corresponds to...
 286    // 4. a value in single quotes.
 287    // 5. An attribute name, that corresponds to...
 288    // 6. an unquoted value.
 289    // 7. A numeric attribute in double quotes.
 290    // 8. A numeric attribute in single quotes.
 291    // 9. An unquoted numeric attribute.
 292  
 293    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.
 294  
 295    text = text.replace(/[\u00a0\u200b]/g, ' ');
 296    var match; // Match and normalize attributes.
 297  
 298    while (match = pattern.exec(text)) {
 299      if (match[1]) {
 300        named[match[1].toLowerCase()] = match[2];
 301      } else if (match[3]) {
 302        named[match[3].toLowerCase()] = match[4];
 303      } else if (match[5]) {
 304        named[match[5].toLowerCase()] = match[6];
 305      } else if (match[7]) {
 306        numeric.push(match[7]);
 307      } else if (match[8]) {
 308        numeric.push(match[8]);
 309      } else if (match[9]) {
 310        numeric.push(match[9]);
 311      }
 312    }
 313  
 314    return {
 315      named: named,
 316      numeric: numeric
 317    };
 318  });
 319  /**
 320   * Generate a Shortcode Object from a RegExp match.
 321   *
 322   * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated
 323   * by `regexp()`. `match` can also be set to the `arguments` from a callback
 324   * passed to `regexp.replace()`.
 325   *
 326   * @param {Array} match Match array.
 327   *
 328   * @return {WPShortcode} Shortcode instance.
 329   */
 330  
 331  function fromMatch(match) {
 332    var type;
 333  
 334    if (match[4]) {
 335      type = 'self-closing';
 336    } else if (match[6]) {
 337      type = 'closed';
 338    } else {
 339      type = 'single';
 340    }
 341  
 342    return new shortcode({
 343      tag: match[2],
 344      attrs: match[3],
 345      type: type,
 346      content: match[5]
 347    });
 348  }
 349  /**
 350   * Creates a shortcode instance.
 351   *
 352   * To access a raw representation of a shortcode, pass an `options` object,
 353   * containing a `tag` string, a string or object of `attrs`, a string indicating
 354   * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a
 355   * `content` string.
 356   *
 357   * @param {Object} options Options as described.
 358   *
 359   * @return {WPShortcode} Shortcode instance.
 360   */
 361  
 362  var shortcode = Object(lodash__WEBPACK_IMPORTED_MODULE_0__["extend"])(function (options) {
 363    var _this = this;
 364  
 365    Object(lodash__WEBPACK_IMPORTED_MODULE_0__["extend"])(this, Object(lodash__WEBPACK_IMPORTED_MODULE_0__["pick"])(options || {}, 'tag', 'attrs', 'type', 'content'));
 366    var attributes = this.attrs; // Ensure we have a correctly formatted `attrs` object.
 367  
 368    this.attrs = {
 369      named: {},
 370      numeric: []
 371    };
 372  
 373    if (!attributes) {
 374      return;
 375    } // Parse a string of attributes.
 376  
 377  
 378    if (Object(lodash__WEBPACK_IMPORTED_MODULE_0__["isString"])(attributes)) {
 379      this.attrs = attrs(attributes); // Identify a correctly formatted `attrs` object.
 380    } else if (Object(lodash__WEBPACK_IMPORTED_MODULE_0__["isEqual"])(Object.keys(attributes), ['named', 'numeric'])) {
 381      this.attrs = attributes; // Handle a flat object of attributes.
 382    } else {
 383      Object(lodash__WEBPACK_IMPORTED_MODULE_0__["forEach"])(attributes, function (value, key) {
 384        _this.set(key, value);
 385      });
 386    }
 387  }, {
 388    next: next,
 389    replace: replace,
 390    string: string,
 391    regexp: regexp,
 392    attrs: attrs,
 393    fromMatch: fromMatch
 394  });
 395  Object(lodash__WEBPACK_IMPORTED_MODULE_0__["extend"])(shortcode.prototype, {
 396    /**
 397     * Get a shortcode attribute.
 398     *
 399     * Automatically detects whether `attr` is named or numeric and routes it
 400     * accordingly.
 401     *
 402     * @param {(number|string)} attr Attribute key.
 403     *
 404     * @return {string} Attribute value.
 405     */
 406    get: function get(attr) {
 407      return this.attrs[Object(lodash__WEBPACK_IMPORTED_MODULE_0__["isNumber"])(attr) ? 'numeric' : 'named'][attr];
 408    },
 409  
 410    /**
 411     * Set a shortcode attribute.
 412     *
 413     * Automatically detects whether `attr` is named or numeric and routes it
 414     * accordingly.
 415     *
 416     * @param {(number|string)} attr  Attribute key.
 417     * @param {string}          value Attribute value.
 418     *
 419     * @return {WPShortcode} Shortcode instance.
 420     */
 421    set: function set(attr, value) {
 422      this.attrs[Object(lodash__WEBPACK_IMPORTED_MODULE_0__["isNumber"])(attr) ? 'numeric' : 'named'][attr] = value;
 423      return this;
 424    },
 425  
 426    /**
 427     * Transform the shortcode into a string.
 428     *
 429     * @return {string} String representation of the shortcode.
 430     */
 431    string: function string() {
 432      var text = '[' + this.tag;
 433      Object(lodash__WEBPACK_IMPORTED_MODULE_0__["forEach"])(this.attrs.numeric, function (value) {
 434        if (/\s/.test(value)) {
 435          text += ' "' + value + '"';
 436        } else {
 437          text += ' ' + value;
 438        }
 439      });
 440      Object(lodash__WEBPACK_IMPORTED_MODULE_0__["forEach"])(this.attrs.named, function (value, name) {
 441        text += ' ' + name + '="' + value + '"';
 442      }); // If the tag is marked as `single` or `self-closing`, close the tag and
 443      // ignore any additional content.
 444  
 445      if ('single' === this.type) {
 446        return text + ']';
 447      } else if ('self-closing' === this.type) {
 448        return text + ' /]';
 449      } // Complete the opening tag.
 450  
 451  
 452      text += ']';
 453  
 454      if (this.content) {
 455        text += this.content;
 456      } // Add the closing tag.
 457  
 458  
 459      return text + '[/' + this.tag + ']';
 460    }
 461  });
 462  /* harmony default export */ __webpack_exports__["default"] = (shortcode);
 463  
 464  
 465  /***/ }),
 466  
 467  /***/ 41:
 468  /***/ (function(module, exports, __webpack_require__) {
 469  
 470  module.exports = function memize( fn, options ) {
 471      var size = 0,
 472          maxSize, head, tail;
 473  
 474      if ( options && options.maxSize ) {
 475          maxSize = options.maxSize;
 476      }
 477  
 478  	function memoized( /* ...args */ ) {
 479          var node = head,
 480              len = arguments.length,
 481              args, i;
 482  
 483          searchCache: while ( node ) {
 484              // Perform a shallow equality test to confirm that whether the node
 485              // under test is a candidate for the arguments passed. Two arrays
 486              // are shallowly equal if their length matches and each entry is
 487              // strictly equal between the two sets. Avoid abstracting to a
 488              // function which could incur an arguments leaking deoptimization.
 489  
 490              // Check whether node arguments match arguments length
 491              if ( node.args.length !== arguments.length ) {
 492                  node = node.next;
 493                  continue;
 494              }
 495  
 496              // Check whether node arguments match arguments values
 497              for ( i = 0; i < len; i++ ) {
 498                  if ( node.args[ i ] !== arguments[ i ] ) {
 499                      node = node.next;
 500                      continue searchCache;
 501                  }
 502              }
 503  
 504              // At this point we can assume we've found a match
 505  
 506              // Surface matched node to head if not already
 507              if ( node !== head ) {
 508                  // As tail, shift to previous. Must only shift if not also
 509                  // head, since if both head and tail, there is no previous.
 510                  if ( node === tail ) {
 511                      tail = node.prev;
 512                  }
 513  
 514                  // Adjust siblings to point to each other. If node was tail,
 515                  // this also handles new tail's empty `next` assignment.
 516                  node.prev.next = node.next;
 517                  if ( node.next ) {
 518                      node.next.prev = node.prev;
 519                  }
 520  
 521                  node.next = head;
 522                  node.prev = null;
 523                  head.prev = node;
 524                  head = node;
 525              }
 526  
 527              // Return immediately
 528              return node.val;
 529          }
 530  
 531          // No cached value found. Continue to insertion phase:
 532  
 533          // Create a copy of arguments (avoid leaking deoptimization)
 534          args = new Array( len );
 535          for ( i = 0; i < len; i++ ) {
 536              args[ i ] = arguments[ i ];
 537          }
 538  
 539          node = {
 540              args: args,
 541  
 542              // Generate the result from original function
 543              val: fn.apply( null, args )
 544          };
 545  
 546          // Don't need to check whether node is already head, since it would
 547          // have been returned above already if it was
 548  
 549          // Shift existing head down list
 550          if ( head ) {
 551              head.prev = node;
 552              node.next = head;
 553          } else {
 554              // If no head, follows that there's no tail (at initial or reset)
 555              tail = node;
 556          }
 557  
 558          // Trim tail if we're reached max size and are pending cache insertion
 559          if ( size === maxSize ) {
 560              tail = tail.prev;
 561              tail.next = null;
 562          } else {
 563              size++;
 564          }
 565  
 566          head = node;
 567  
 568          return node.val;
 569      }
 570  
 571      memoized.clear = function() {
 572          head = null;
 573          tail = null;
 574          size = 0;
 575      };
 576  
 577      if ( false ) {}
 578  
 579      return memoized;
 580  };
 581  
 582  
 583  /***/ })
 584  
 585  /******/ })["default"];


Generated: Tue Sep 17 01:00:03 2019 Cross-referenced by PHPXref 0.7.1