@wordpress/shortcode 3.2.2 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.3.0 (2022-01-27)
6
+
5
7
  ## 3.2.0 (2021-07-21)
6
8
 
7
9
  ## 3.1.0 (2021-05-20)
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## Gutenberg
2
2
 
3
- Copyright 2016-2021 by the contributors
3
+ Copyright 2016-2022 by the contributors
4
4
 
5
5
  **License for Contributions (on and after April 15, 2021)**
6
6
 
package/README.md CHANGED
@@ -144,4 +144,10 @@ _Returns_
144
144
 
145
145
  <!-- END TOKEN(Autogenerated API docs) -->
146
146
 
147
- <br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
147
+ ## Contributing to this package
148
+
149
+ This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.
150
+
151
+ To find out more about contributing to this package or Gutenberg as a whole, please read the project's main [contributor guide](https://github.com/WordPress/gutenberg/tree/HEAD/CONTRIBUTING.md).
152
+
153
+ <br /><br /><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
package/build/index.js CHANGED
@@ -5,12 +5,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
+ exports.default = exports.attrs = void 0;
9
+ exports.fromMatch = fromMatch;
8
10
  exports.next = next;
11
+ exports.regexp = regexp;
9
12
  exports.replace = replace;
10
13
  exports.string = string;
11
- exports.regexp = regexp;
12
- exports.fromMatch = fromMatch;
13
- exports.default = exports.attrs = void 0;
14
14
 
15
15
  var _lodash = require("lodash");
16
16
 
@@ -58,7 +58,8 @@ var _memize = _interopRequireDefault(require("memize"));
58
58
  *
59
59
  * @return {?WPShortcodeMatch} Matched information.
60
60
  */
61
- function next(tag, text, index = 0) {
61
+ function next(tag, text) {
62
+ let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
62
63
  const re = regexp(tag);
63
64
  re.lastIndex = index;
64
65
  const match = re.exec(text);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/shortcode/src/index.js"],"names":["next","tag","text","index","re","regexp","lastIndex","match","exec","result","content","shortcode","fromMatch","slice","replace","callback","left","$3","attrs","slash","closing","right","arguments","string","options","RegExp","named","numeric","pattern","toLowerCase","push","type","attributes","Object","keys","value","key","set","prototype","get","attr","test","name"],"mappings":";;;;;;;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,IAAT,CAAeC,GAAf,EAAoBC,IAApB,EAA0BC,KAAK,GAAG,CAAlC,EAAsC;AAC5C,QAAMC,EAAE,GAAGC,MAAM,CAAEJ,GAAF,CAAjB;AAEAG,EAAAA,EAAE,CAACE,SAAH,GAAeH,KAAf;AAEA,QAAMI,KAAK,GAAGH,EAAE,CAACI,IAAH,CAASN,IAAT,CAAd;;AAEA,MAAK,CAAEK,KAAP,EAAe;AACd;AACA,GAT2C,CAW5C;;;AACA,MAAK,QAAQA,KAAK,CAAE,CAAF,CAAb,IAAsB,QAAQA,KAAK,CAAE,CAAF,CAAxC,EAAgD;AAC/C,WAAOP,IAAI,CAAEC,GAAF,EAAOC,IAAP,EAAaE,EAAE,CAACE,SAAhB,CAAX;AACA;;AAED,QAAMG,MAAM,GAAG;A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A;AACA;AACA;AACA;AACCH,EAAAA,GAAG,CAAEG,IAAF,EAAQL,KAAR,EAAgB;AAClB,SAAKjB,KAAL,CAAY,sBAAUsB,IAAV,IAAmB,SAAnB,GAA+B,OAA3C,EAAsDA,IAAtD,IAA+DL,KAA/D;AACA,WAAO,IAAP;AACA,GA7B2B;;AA+B5B;AACD;AACA;AACA;AACA;AACCZ,EAAAA,MAAM,GAAG;AACR,QAAIrB,IAAI,GAAG,MAAM,KAAKD,GAAtB;AAEA,yBAAS,KAAKiB,KAAL,CAAWS,OAApB,EAA+BQ,KAAF,IAAa;AACzC,UAAK,KAAKM,IAAL,CAAWN,KAAX,CAAL,EAA0B;AACzBjC,QAAAA,IAAI,IAAI,OAAOiC,KAAP,GAAe,GAAvB;AACA,OAFD,MAEO;AACNjC,QAAAA,IAAI,IAAI,MAAMiC,KAAd;AACA;AACD,KAND;AAQA,yBAAS,KAAKjB,KAAL,CAAWQ,KAApB,EAA2B,CAAES,KAAF,EAASO,IAAT,KAAmB;AAC7CxC,MAAAA,IAAI,IAAI,MAAMwC,IAAN,GAAa,IAAb,GAAoBP,KAApB,GAA4B,GAApC;AACA,KAFD,EAXQ,CAeR;AACA;;AACA,QAAK,aAAa,KAAKJ,IAAvB,EAA8B;AAC7B,aAAO7B,IAAI,GAAG,GAAd;AACA,KAFD,MAEO,IAAK,mBAAmB,KAAK6B,IAA7B,EAAoC;AAC1C,aAAO7B,IAAI,GAAG,KAAd;AACA,KArBO,CAuBR;;;AACAA,IAAAA,IAAI,IAAI,GAAR;;AAEA,QAAK,KAAKQ,OAAV,EAAoB;AACnBR,MAAAA,IAAI,IAAI,KAAKQ,OAAb;AACA,KA5BO,CA8BR;;;AACA,WAAOR,IAAI,GAAG,IAAP,GAAc,KAAKD,GAAnB,GAAyB,GAAhC;AACA;;AApE2B,CAA7B;eAuEeU,S","sourcesContent":["/**\n * External dependencies\n */\nimport { extend, pick, isString, isEqual, forEach, isNumber } from 'lodash';\nimport memize from 'memize';\n\n/**\n * Shortcode attributes object.\n *\n * @typedef {Object} WPShortcodeAttrs\n *\n * @property {Object} named Object with named attributes.\n * @property {Array} numeric Array with numeric attributes.\n */\n\n/**\n * Shortcode object.\n *\n * @typedef {Object} WPShortcode\n *\n * @property {string} tag Shortcode tag.\n * @property {WPShortcodeAttrs} attrs Shortcode attributes.\n * @property {string} content Shortcode content.\n * @property {string} type Shortcode type: `self-closing`,\n * `closed`, or `single`.\n */\n\n/**\n * @typedef {Object} WPShortcodeMatch\n *\n * @property {number} index Index the shortcode is found at.\n * @property {string} content Matched content.\n * @property {WPShortcode} shortcode Shortcode instance of the match.\n */\n\n/**\n * Find the next matching shortcode.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {number} index Index to start search from.\n *\n * @return {?WPShortcodeMatch} Matched information.\n */\nexport function next( tag, text, index = 0 ) {\n\tconst re = regexp( tag );\n\n\tre.lastIndex = index;\n\n\tconst match = re.exec( text );\n\n\tif ( ! match ) {\n\t\treturn;\n\t}\n\n\t// If we matched an escaped shortcode, try again.\n\tif ( '[' === match[ 1 ] && ']' === match[ 7 ] ) {\n\t\treturn next( tag, text, re.lastIndex );\n\t}\n\n\tconst result = {\n\t\tindex: match.index,\n\t\tcontent: match[ 0 ],\n\t\tshortcode: fromMatch( match ),\n\t};\n\n\t// If we matched a leading `[`, strip it from the match and increment the\n\t// index accordingly.\n\tif ( match[ 1 ] ) {\n\t\tresult.content = result.content.slice( 1 );\n\t\tresult.index++;\n\t}\n\n\t// If we matched a trailing `]`, strip it from the match.\n\tif ( match[ 7 ] ) {\n\t\tresult.content = result.content.slice( 0, -1 );\n\t}\n\n\treturn result;\n}\n\n/**\n * Replace matching shortcodes in a block of text.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {Function} callback Function to process the match and return\n * replacement string.\n *\n * @return {string} Text with shortcodes replaced.\n */\nexport function replace( tag, text, callback ) {\n\treturn text.replace(\n\t\tregexp( tag ),\n\t\tfunction ( match, left, $3, attrs, slash, content, closing, right ) {\n\t\t\t// If both extra brackets exist, the shortcode has been properly\n\t\t\t// escaped.\n\t\t\tif ( left === '[' && right === ']' ) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\t// Create the match object and pass it through the callback.\n\t\t\tconst result = callback( fromMatch( arguments ) );\n\n\t\t\t// Make sure to return any of the extra brackets if they weren't used to\n\t\t\t// escape the shortcode.\n\t\t\treturn result || result === '' ? left + result + right : match;\n\t\t}\n\t);\n}\n\n/**\n * Generate a string from shortcode parameters.\n *\n * Creates a shortcode instance and returns a string.\n *\n * Accepts the same `options` as the `shortcode()` constructor, containing a\n * `tag` string, a string or object of `attrs`, a boolean indicating whether to\n * format the shortcode using a `single` tag, and a `content` string.\n *\n * @param {Object} options\n *\n * @return {string} String representation of the shortcode.\n */\nexport function string( options ) {\n\treturn new shortcode( options ).string();\n}\n\n/**\n * Generate a RegExp to identify a shortcode.\n *\n * The base regex is functionally equivalent to the one found in\n * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.\n *\n * Capture groups:\n *\n * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`\n * 2. The shortcode name\n * 3. The shortcode argument list\n * 4. The self closing `/`\n * 5. The content of a shortcode when it wraps some content.\n * 6. The closing tag.\n * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`\n *\n * @param {string} tag Shortcode tag.\n *\n * @return {RegExp} Shortcode RegExp.\n */\nexport function regexp( tag ) {\n\treturn new RegExp(\n\t\t'\\\\[(\\\\[?)(' +\n\t\t\ttag +\n\t\t\t')(?![\\\\w-])([^\\\\]\\\\/]*(?:\\\\/(?!\\\\])[^\\\\]\\\\/]*)*?)(?:(\\\\/)\\\\]|\\\\](?:([^\\\\[]*(?:\\\\[(?!\\\\/\\\\2\\\\])[^\\\\[]*)*)(\\\\[\\\\/\\\\2\\\\]))?)(\\\\]?)',\n\t\t'g'\n\t);\n}\n\n/**\n * Parse shortcode attributes.\n *\n * Shortcodes accept many types of attributes. These can chiefly be divided into\n * named and numeric attributes:\n *\n * Named attributes are assigned on a key/value basis, while numeric attributes\n * are treated as an array.\n *\n * Named attributes can be formatted as either `name=\"value\"`, `name='value'`,\n * or `name=value`. Numeric attributes can be formatted as `\"value\"` or just\n * `value`.\n *\n * @param {string} text Serialised shortcode attributes.\n *\n * @return {WPShortcodeAttrs} Parsed shortcode attributes.\n */\nexport const attrs = memize( ( text ) => {\n\tconst named = {};\n\tconst numeric = [];\n\n\t// This regular expression is reused from `shortcode_parse_atts()` in\n\t// `wp-includes/shortcodes.php`.\n\t//\n\t// Capture groups:\n\t//\n\t// 1. An attribute name, that corresponds to...\n\t// 2. a value in double quotes.\n\t// 3. An attribute name, that corresponds to...\n\t// 4. a value in single quotes.\n\t// 5. An attribute name, that corresponds to...\n\t// 6. an unquoted value.\n\t// 7. A numeric attribute in double quotes.\n\t// 8. A numeric attribute in single quotes.\n\t// 9. An unquoted numeric attribute.\n\tconst pattern = /([\\w-]+)\\s*=\\s*\"([^\"]*)\"(?:\\s|$)|([\\w-]+)\\s*=\\s*'([^']*)'(?:\\s|$)|([\\w-]+)\\s*=\\s*([^\\s'\"]+)(?:\\s|$)|\"([^\"]*)\"(?:\\s|$)|'([^']*)'(?:\\s|$)|(\\S+)(?:\\s|$)/g;\n\n\t// Map zero-width spaces to actual spaces.\n\ttext = text.replace( /[\\u00a0\\u200b]/g, ' ' );\n\n\tlet match;\n\n\t// Match and normalize attributes.\n\twhile ( ( match = pattern.exec( text ) ) ) {\n\t\tif ( match[ 1 ] ) {\n\t\t\tnamed[ match[ 1 ].toLowerCase() ] = match[ 2 ];\n\t\t} else if ( match[ 3 ] ) {\n\t\t\tnamed[ match[ 3 ].toLowerCase() ] = match[ 4 ];\n\t\t} else if ( match[ 5 ] ) {\n\t\t\tnamed[ match[ 5 ].toLowerCase() ] = match[ 6 ];\n\t\t} else if ( match[ 7 ] ) {\n\t\t\tnumeric.push( match[ 7 ] );\n\t\t} else if ( match[ 8 ] ) {\n\t\t\tnumeric.push( match[ 8 ] );\n\t\t} else if ( match[ 9 ] ) {\n\t\t\tnumeric.push( match[ 9 ] );\n\t\t}\n\t}\n\n\treturn { named, numeric };\n} );\n\n/**\n * Generate a Shortcode Object from a RegExp match.\n *\n * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated\n * by `regexp()`. `match` can also be set to the `arguments` from a callback\n * passed to `regexp.replace()`.\n *\n * @param {Array} match Match array.\n *\n * @return {WPShortcode} Shortcode instance.\n */\nexport function fromMatch( match ) {\n\tlet type;\n\n\tif ( match[ 4 ] ) {\n\t\ttype = 'self-closing';\n\t} else if ( match[ 6 ] ) {\n\t\ttype = 'closed';\n\t} else {\n\t\ttype = 'single';\n\t}\n\n\treturn new shortcode( {\n\t\ttag: match[ 2 ],\n\t\tattrs: match[ 3 ],\n\t\ttype,\n\t\tcontent: match[ 5 ],\n\t} );\n}\n\n/**\n * Creates a shortcode instance.\n *\n * To access a raw representation of a shortcode, pass an `options` object,\n * containing a `tag` string, a string or object of `attrs`, a string indicating\n * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a\n * `content` string.\n *\n * @param {Object} options Options as described.\n *\n * @return {WPShortcode} Shortcode instance.\n */\nconst shortcode = extend(\n\tfunction ( options ) {\n\t\textend(\n\t\t\tthis,\n\t\t\tpick( options || {}, 'tag', 'attrs', 'type', 'content' )\n\t\t);\n\n\t\tconst attributes = this.attrs;\n\n\t\t// Ensure we have a correctly formatted `attrs` object.\n\t\tthis.attrs = {\n\t\t\tnamed: {},\n\t\t\tnumeric: [],\n\t\t};\n\n\t\tif ( ! attributes ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Parse a string of attributes.\n\t\tif ( isString( attributes ) ) {\n\t\t\tthis.attrs = attrs( attributes );\n\t\t\t// Identify a correctly formatted `attrs` object.\n\t\t} else if (\n\t\t\tisEqual( Object.keys( attributes ), [ 'named', 'numeric' ] )\n\t\t) {\n\t\t\tthis.attrs = attributes;\n\t\t\t// Handle a flat object of attributes.\n\t\t} else {\n\t\t\tforEach( attributes, ( value, key ) => {\n\t\t\t\tthis.set( key, value );\n\t\t\t} );\n\t\t}\n\t},\n\t{\n\t\tnext,\n\t\treplace,\n\t\tstring,\n\t\tregexp,\n\t\tattrs,\n\t\tfromMatch,\n\t}\n);\n\nextend( shortcode.prototype, {\n\t/**\n\t * Get a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t *\n\t * @return {string} Attribute value.\n\t */\n\tget( attr ) {\n\t\treturn this.attrs[ isNumber( attr ) ? 'numeric' : 'named' ][ attr ];\n\t},\n\n\t/**\n\t * Set a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t * @param {string} value Attribute value.\n\t *\n\t * @return {WPShortcode} Shortcode instance.\n\t */\n\tset( attr, value ) {\n\t\tthis.attrs[ isNumber( attr ) ? 'numeric' : 'named' ][ attr ] = value;\n\t\treturn this;\n\t},\n\n\t/**\n\t * Transform the shortcode into a string.\n\t *\n\t * @return {string} String representation of the shortcode.\n\t */\n\tstring() {\n\t\tlet text = '[' + this.tag;\n\n\t\tforEach( this.attrs.numeric, ( value ) => {\n\t\t\tif ( /\\s/.test( value ) ) {\n\t\t\t\ttext += ' \"' + value + '\"';\n\t\t\t} else {\n\t\t\t\ttext += ' ' + value;\n\t\t\t}\n\t\t} );\n\n\t\tforEach( this.attrs.named, ( value, name ) => {\n\t\t\ttext += ' ' + name + '=\"' + value + '\"';\n\t\t} );\n\n\t\t// If the tag is marked as `single` or `self-closing`, close the tag and\n\t\t// ignore any additional content.\n\t\tif ( 'single' === this.type ) {\n\t\t\treturn text + ']';\n\t\t} else if ( 'self-closing' === this.type ) {\n\t\t\treturn text + ' /]';\n\t\t}\n\n\t\t// Complete the opening tag.\n\t\ttext += ']';\n\n\t\tif ( this.content ) {\n\t\t\ttext += this.content;\n\t\t}\n\n\t\t// Add the closing tag.\n\t\treturn text + '[/' + this.tag + ']';\n\t},\n} );\n\nexport default shortcode;\n"]}
1
+ {"version":3,"sources":["@wordpress/shortcode/src/index.js"],"names":["next","tag","text","index","re","regexp","lastIndex","match","exec","result","content","shortcode","fromMatch","slice","replace","callback","left","$3","attrs","slash","closing","right","arguments","string","options","RegExp","named","numeric","pattern","toLowerCase","push","type","attributes","Object","keys","value","key","set","prototype","get","attr","test","name"],"mappings":";;;;;;;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,IAAT,CAAeC,GAAf,EAAoBC,IAApB,EAAsC;AAAA,MAAZC,KAAY,uEAAJ,CAAI;AAC5C,QAAMC,EAAE,GAAGC,MAAM,CAAEJ,GAAF,CAAjB;AAEAG,EAAAA,EAAE,CAACE,SAAH,GAAeH,KAAf;AAEA,QAAMI,KAAK,GAAGH,EAAE,CAACI,IAAH,CAASN,IAAT,CAAd;;AAEA,MAAK,CAAEK,KAAP,EAAe;AACd;AACA,GAT2C,CAW5C;;;AACA,MAAK,QAAQA,KAAK,CAAE,CAAF,CAAb,IAAsB,QAAQA,KAAK,CAAE,CAAF,CAAxC,EAAgD;AAC/C,WAAOP,IAAI,CAAEC,GAAF,EAAOC,IAAP,EAAaE,EAAE,CAACE,SAAhB,CAAX;AACA;;AAED,QAAMG,MAAM,GAAG;AACdN,IAAAA,KAAK,EAAEI,KAAK,CAACJ,KADC;AAEdO,IAAAA,OAAO,EAAEH,KAAK,CAAE,CAAF,CAFA;AAGdI,IAAAA,SAAS,EAAEC,SAAS,CAAEL,KAAF;AAHN,GAAf,CAhB4C,CAsB5C;AACA;;AACA,MAAKA,KAAK,CAAE,CAA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A+B5B;AACD;AACA;AACA;AACA;AACCZ,EAAAA,MAAM,GAAG;AACR,QAAIrB,IAAI,GAAG,MAAM,KAAKD,GAAtB;AAEA,yBAAS,KAAKiB,KAAL,CAAWS,OAApB,EAA+BQ,KAAF,IAAa;AACzC,UAAK,KAAKM,IAAL,CAAWN,KAAX,CAAL,EAA0B;AACzBjC,QAAAA,IAAI,IAAI,OAAOiC,KAAP,GAAe,GAAvB;AACA,OAFD,MAEO;AACNjC,QAAAA,IAAI,IAAI,MAAMiC,KAAd;AACA;AACD,KAND;AAQA,yBAAS,KAAKjB,KAAL,CAAWQ,KAApB,EAA2B,CAAES,KAAF,EAASO,IAAT,KAAmB;AAC7CxC,MAAAA,IAAI,IAAI,MAAMwC,IAAN,GAAa,IAAb,GAAoBP,KAApB,GAA4B,GAApC;AACA,KAFD,EAXQ,CAeR;AACA;;AACA,QAAK,aAAa,KAAKJ,IAAvB,EAA8B;AAC7B,aAAO7B,IAAI,GAAG,GAAd;AACA,KAFD,MAEO,IAAK,mBAAmB,KAAK6B,IAA7B,EAAoC;AAC1C,aAAO7B,IAAI,GAAG,KAAd;AACA,KArBO,CAuBR;;;AACAA,IAAAA,IAAI,IAAI,GAAR;;AAEA,QAAK,KAAKQ,OAAV,EAAoB;AACnBR,MAAAA,IAAI,IAAI,KAAKQ,OAAb;AACA,KA5BO,CA8BR;;;AACA,WAAOR,IAAI,GAAG,IAAP,GAAc,KAAKD,GAAnB,GAAyB,GAAhC;AACA;;AApE2B,CAA7B;eAuEeU,S","sourcesContent":["/**\n * External dependencies\n */\nimport { extend, pick, isString, isEqual, forEach, isNumber } from 'lodash';\nimport memize from 'memize';\n\n/**\n * Shortcode attributes object.\n *\n * @typedef {Object} WPShortcodeAttrs\n *\n * @property {Object} named Object with named attributes.\n * @property {Array} numeric Array with numeric attributes.\n */\n\n/**\n * Shortcode object.\n *\n * @typedef {Object} WPShortcode\n *\n * @property {string} tag Shortcode tag.\n * @property {WPShortcodeAttrs} attrs Shortcode attributes.\n * @property {string} content Shortcode content.\n * @property {string} type Shortcode type: `self-closing`,\n * `closed`, or `single`.\n */\n\n/**\n * @typedef {Object} WPShortcodeMatch\n *\n * @property {number} index Index the shortcode is found at.\n * @property {string} content Matched content.\n * @property {WPShortcode} shortcode Shortcode instance of the match.\n */\n\n/**\n * Find the next matching shortcode.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {number} index Index to start search from.\n *\n * @return {?WPShortcodeMatch} Matched information.\n */\nexport function next( tag, text, index = 0 ) {\n\tconst re = regexp( tag );\n\n\tre.lastIndex = index;\n\n\tconst match = re.exec( text );\n\n\tif ( ! match ) {\n\t\treturn;\n\t}\n\n\t// If we matched an escaped shortcode, try again.\n\tif ( '[' === match[ 1 ] && ']' === match[ 7 ] ) {\n\t\treturn next( tag, text, re.lastIndex );\n\t}\n\n\tconst result = {\n\t\tindex: match.index,\n\t\tcontent: match[ 0 ],\n\t\tshortcode: fromMatch( match ),\n\t};\n\n\t// If we matched a leading `[`, strip it from the match and increment the\n\t// index accordingly.\n\tif ( match[ 1 ] ) {\n\t\tresult.content = result.content.slice( 1 );\n\t\tresult.index++;\n\t}\n\n\t// If we matched a trailing `]`, strip it from the match.\n\tif ( match[ 7 ] ) {\n\t\tresult.content = result.content.slice( 0, -1 );\n\t}\n\n\treturn result;\n}\n\n/**\n * Replace matching shortcodes in a block of text.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {Function} callback Function to process the match and return\n * replacement string.\n *\n * @return {string} Text with shortcodes replaced.\n */\nexport function replace( tag, text, callback ) {\n\treturn text.replace(\n\t\tregexp( tag ),\n\t\tfunction ( match, left, $3, attrs, slash, content, closing, right ) {\n\t\t\t// If both extra brackets exist, the shortcode has been properly\n\t\t\t// escaped.\n\t\t\tif ( left === '[' && right === ']' ) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\t// Create the match object and pass it through the callback.\n\t\t\tconst result = callback( fromMatch( arguments ) );\n\n\t\t\t// Make sure to return any of the extra brackets if they weren't used to\n\t\t\t// escape the shortcode.\n\t\t\treturn result || result === '' ? left + result + right : match;\n\t\t}\n\t);\n}\n\n/**\n * Generate a string from shortcode parameters.\n *\n * Creates a shortcode instance and returns a string.\n *\n * Accepts the same `options` as the `shortcode()` constructor, containing a\n * `tag` string, a string or object of `attrs`, a boolean indicating whether to\n * format the shortcode using a `single` tag, and a `content` string.\n *\n * @param {Object} options\n *\n * @return {string} String representation of the shortcode.\n */\nexport function string( options ) {\n\treturn new shortcode( options ).string();\n}\n\n/**\n * Generate a RegExp to identify a shortcode.\n *\n * The base regex is functionally equivalent to the one found in\n * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.\n *\n * Capture groups:\n *\n * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`\n * 2. The shortcode name\n * 3. The shortcode argument list\n * 4. The self closing `/`\n * 5. The content of a shortcode when it wraps some content.\n * 6. The closing tag.\n * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`\n *\n * @param {string} tag Shortcode tag.\n *\n * @return {RegExp} Shortcode RegExp.\n */\nexport function regexp( tag ) {\n\treturn new RegExp(\n\t\t'\\\\[(\\\\[?)(' +\n\t\t\ttag +\n\t\t\t')(?![\\\\w-])([^\\\\]\\\\/]*(?:\\\\/(?!\\\\])[^\\\\]\\\\/]*)*?)(?:(\\\\/)\\\\]|\\\\](?:([^\\\\[]*(?:\\\\[(?!\\\\/\\\\2\\\\])[^\\\\[]*)*)(\\\\[\\\\/\\\\2\\\\]))?)(\\\\]?)',\n\t\t'g'\n\t);\n}\n\n/**\n * Parse shortcode attributes.\n *\n * Shortcodes accept many types of attributes. These can chiefly be divided into\n * named and numeric attributes:\n *\n * Named attributes are assigned on a key/value basis, while numeric attributes\n * are treated as an array.\n *\n * Named attributes can be formatted as either `name=\"value\"`, `name='value'`,\n * or `name=value`. Numeric attributes can be formatted as `\"value\"` or just\n * `value`.\n *\n * @param {string} text Serialised shortcode attributes.\n *\n * @return {WPShortcodeAttrs} Parsed shortcode attributes.\n */\nexport const attrs = memize( ( text ) => {\n\tconst named = {};\n\tconst numeric = [];\n\n\t// This regular expression is reused from `shortcode_parse_atts()` in\n\t// `wp-includes/shortcodes.php`.\n\t//\n\t// Capture groups:\n\t//\n\t// 1. An attribute name, that corresponds to...\n\t// 2. a value in double quotes.\n\t// 3. An attribute name, that corresponds to...\n\t// 4. a value in single quotes.\n\t// 5. An attribute name, that corresponds to...\n\t// 6. an unquoted value.\n\t// 7. A numeric attribute in double quotes.\n\t// 8. A numeric attribute in single quotes.\n\t// 9. An unquoted numeric attribute.\n\tconst pattern = /([\\w-]+)\\s*=\\s*\"([^\"]*)\"(?:\\s|$)|([\\w-]+)\\s*=\\s*'([^']*)'(?:\\s|$)|([\\w-]+)\\s*=\\s*([^\\s'\"]+)(?:\\s|$)|\"([^\"]*)\"(?:\\s|$)|'([^']*)'(?:\\s|$)|(\\S+)(?:\\s|$)/g;\n\n\t// Map zero-width spaces to actual spaces.\n\ttext = text.replace( /[\\u00a0\\u200b]/g, ' ' );\n\n\tlet match;\n\n\t// Match and normalize attributes.\n\twhile ( ( match = pattern.exec( text ) ) ) {\n\t\tif ( match[ 1 ] ) {\n\t\t\tnamed[ match[ 1 ].toLowerCase() ] = match[ 2 ];\n\t\t} else if ( match[ 3 ] ) {\n\t\t\tnamed[ match[ 3 ].toLowerCase() ] = match[ 4 ];\n\t\t} else if ( match[ 5 ] ) {\n\t\t\tnamed[ match[ 5 ].toLowerCase() ] = match[ 6 ];\n\t\t} else if ( match[ 7 ] ) {\n\t\t\tnumeric.push( match[ 7 ] );\n\t\t} else if ( match[ 8 ] ) {\n\t\t\tnumeric.push( match[ 8 ] );\n\t\t} else if ( match[ 9 ] ) {\n\t\t\tnumeric.push( match[ 9 ] );\n\t\t}\n\t}\n\n\treturn { named, numeric };\n} );\n\n/**\n * Generate a Shortcode Object from a RegExp match.\n *\n * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated\n * by `regexp()`. `match` can also be set to the `arguments` from a callback\n * passed to `regexp.replace()`.\n *\n * @param {Array} match Match array.\n *\n * @return {WPShortcode} Shortcode instance.\n */\nexport function fromMatch( match ) {\n\tlet type;\n\n\tif ( match[ 4 ] ) {\n\t\ttype = 'self-closing';\n\t} else if ( match[ 6 ] ) {\n\t\ttype = 'closed';\n\t} else {\n\t\ttype = 'single';\n\t}\n\n\treturn new shortcode( {\n\t\ttag: match[ 2 ],\n\t\tattrs: match[ 3 ],\n\t\ttype,\n\t\tcontent: match[ 5 ],\n\t} );\n}\n\n/**\n * Creates a shortcode instance.\n *\n * To access a raw representation of a shortcode, pass an `options` object,\n * containing a `tag` string, a string or object of `attrs`, a string indicating\n * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a\n * `content` string.\n *\n * @param {Object} options Options as described.\n *\n * @return {WPShortcode} Shortcode instance.\n */\nconst shortcode = extend(\n\tfunction ( options ) {\n\t\textend(\n\t\t\tthis,\n\t\t\tpick( options || {}, 'tag', 'attrs', 'type', 'content' )\n\t\t);\n\n\t\tconst attributes = this.attrs;\n\n\t\t// Ensure we have a correctly formatted `attrs` object.\n\t\tthis.attrs = {\n\t\t\tnamed: {},\n\t\t\tnumeric: [],\n\t\t};\n\n\t\tif ( ! attributes ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Parse a string of attributes.\n\t\tif ( isString( attributes ) ) {\n\t\t\tthis.attrs = attrs( attributes );\n\t\t\t// Identify a correctly formatted `attrs` object.\n\t\t} else if (\n\t\t\tisEqual( Object.keys( attributes ), [ 'named', 'numeric' ] )\n\t\t) {\n\t\t\tthis.attrs = attributes;\n\t\t\t// Handle a flat object of attributes.\n\t\t} else {\n\t\t\tforEach( attributes, ( value, key ) => {\n\t\t\t\tthis.set( key, value );\n\t\t\t} );\n\t\t}\n\t},\n\t{\n\t\tnext,\n\t\treplace,\n\t\tstring,\n\t\tregexp,\n\t\tattrs,\n\t\tfromMatch,\n\t}\n);\n\nextend( shortcode.prototype, {\n\t/**\n\t * Get a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t *\n\t * @return {string} Attribute value.\n\t */\n\tget( attr ) {\n\t\treturn this.attrs[ isNumber( attr ) ? 'numeric' : 'named' ][ attr ];\n\t},\n\n\t/**\n\t * Set a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t * @param {string} value Attribute value.\n\t *\n\t * @return {WPShortcode} Shortcode instance.\n\t */\n\tset( attr, value ) {\n\t\tthis.attrs[ isNumber( attr ) ? 'numeric' : 'named' ][ attr ] = value;\n\t\treturn this;\n\t},\n\n\t/**\n\t * Transform the shortcode into a string.\n\t *\n\t * @return {string} String representation of the shortcode.\n\t */\n\tstring() {\n\t\tlet text = '[' + this.tag;\n\n\t\tforEach( this.attrs.numeric, ( value ) => {\n\t\t\tif ( /\\s/.test( value ) ) {\n\t\t\t\ttext += ' \"' + value + '\"';\n\t\t\t} else {\n\t\t\t\ttext += ' ' + value;\n\t\t\t}\n\t\t} );\n\n\t\tforEach( this.attrs.named, ( value, name ) => {\n\t\t\ttext += ' ' + name + '=\"' + value + '\"';\n\t\t} );\n\n\t\t// If the tag is marked as `single` or `self-closing`, close the tag and\n\t\t// ignore any additional content.\n\t\tif ( 'single' === this.type ) {\n\t\t\treturn text + ']';\n\t\t} else if ( 'self-closing' === this.type ) {\n\t\t\treturn text + ' /]';\n\t\t}\n\n\t\t// Complete the opening tag.\n\t\ttext += ']';\n\n\t\tif ( this.content ) {\n\t\t\ttext += this.content;\n\t\t}\n\n\t\t// Add the closing tag.\n\t\treturn text + '[/' + this.tag + ']';\n\t},\n} );\n\nexport default shortcode;\n"]}
@@ -42,7 +42,8 @@ import memize from 'memize';
42
42
  * @return {?WPShortcodeMatch} Matched information.
43
43
  */
44
44
 
45
- export function next(tag, text, index = 0) {
45
+ export function next(tag, text) {
46
+ let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
46
47
  const re = regexp(tag);
47
48
  re.lastIndex = index;
48
49
  const match = re.exec(text);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/shortcode/src/index.js"],"names":["extend","pick","isString","isEqual","forEach","isNumber","memize","next","tag","text","index","re","regexp","lastIndex","match","exec","result","content","shortcode","fromMatch","slice","replace","callback","left","$3","attrs","slash","closing","right","arguments","string","options","RegExp","named","numeric","pattern","toLowerCase","push","type","attributes","Object","keys","value","key","set","prototype","get","attr","test","name"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAT,EAAiBC,IAAjB,EAAuBC,QAAvB,EAAiCC,OAAjC,EAA0CC,OAA1C,EAAmDC,QAAnD,QAAmE,QAAnE;AACA,OAAOC,MAAP,MAAmB,QAAnB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,IAAT,CAAeC,GAAf,EAAoBC,IAApB,EAA0BC,KAAK,GAAG,CAAlC,EAAsC;AAC5C,QAAMC,EAAE,GAAGC,MAAM,CAAEJ,GAAF,CAAjB;AAEAG,EAAAA,EAAE,CAACE,SAAH,GAAeH,KAAf;AAEA,QAAMI,KAAK,GAAGH,EAAE,CAACI,IAAH,CAASN,IAAT,CAAd;;AAEA,MAAK,CAAEK,KAAP,EAAe;AACd;AACA,GAT2C,CAW5C;;;AACA,MAAK,QAAQA,KAAK,CAAE,CAAF,CAAb,IAAsB,QAAQA,KAAK,CAAE,CAAF,CAAxC,EAAgD;AAC/C,WAAOP,IAAI,CAAEC,GAAF,EAAOC,IAAP,EAAaE,EAAE,CAACE,SAAhB,CAAX;AACA;;AAED,QAAMG,MAAM,GAAG;AACdN,IAAAA,KAAK,EAAEI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,IAAP,GAAc,KAAKD,GAAnB,GAAyB,GAAhC;AACA;;AApE2B,CAAvB,CAAN;AAuEA,eAAeU,SAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { extend, pick, isString, isEqual, forEach, isNumber } from 'lodash';\nimport memize from 'memize';\n\n/**\n * Shortcode attributes object.\n *\n * @typedef {Object} WPShortcodeAttrs\n *\n * @property {Object} named Object with named attributes.\n * @property {Array} numeric Array with numeric attributes.\n */\n\n/**\n * Shortcode object.\n *\n * @typedef {Object} WPShortcode\n *\n * @property {string} tag Shortcode tag.\n * @property {WPShortcodeAttrs} attrs Shortcode attributes.\n * @property {string} content Shortcode content.\n * @property {string} type Shortcode type: `self-closing`,\n * `closed`, or `single`.\n */\n\n/**\n * @typedef {Object} WPShortcodeMatch\n *\n * @property {number} index Index the shortcode is found at.\n * @property {string} content Matched content.\n * @property {WPShortcode} shortcode Shortcode instance of the match.\n */\n\n/**\n * Find the next matching shortcode.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {number} index Index to start search from.\n *\n * @return {?WPShortcodeMatch} Matched information.\n */\nexport function next( tag, text, index = 0 ) {\n\tconst re = regexp( tag );\n\n\tre.lastIndex = index;\n\n\tconst match = re.exec( text );\n\n\tif ( ! match ) {\n\t\treturn;\n\t}\n\n\t// If we matched an escaped shortcode, try again.\n\tif ( '[' === match[ 1 ] && ']' === match[ 7 ] ) {\n\t\treturn next( tag, text, re.lastIndex );\n\t}\n\n\tconst result = {\n\t\tindex: match.index,\n\t\tcontent: match[ 0 ],\n\t\tshortcode: fromMatch( match ),\n\t};\n\n\t// If we matched a leading `[`, strip it from the match and increment the\n\t// index accordingly.\n\tif ( match[ 1 ] ) {\n\t\tresult.content = result.content.slice( 1 );\n\t\tresult.index++;\n\t}\n\n\t// If we matched a trailing `]`, strip it from the match.\n\tif ( match[ 7 ] ) {\n\t\tresult.content = result.content.slice( 0, -1 );\n\t}\n\n\treturn result;\n}\n\n/**\n * Replace matching shortcodes in a block of text.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {Function} callback Function to process the match and return\n * replacement string.\n *\n * @return {string} Text with shortcodes replaced.\n */\nexport function replace( tag, text, callback ) {\n\treturn text.replace(\n\t\tregexp( tag ),\n\t\tfunction ( match, left, $3, attrs, slash, content, closing, right ) {\n\t\t\t// If both extra brackets exist, the shortcode has been properly\n\t\t\t// escaped.\n\t\t\tif ( left === '[' && right === ']' ) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\t// Create the match object and pass it through the callback.\n\t\t\tconst result = callback( fromMatch( arguments ) );\n\n\t\t\t// Make sure to return any of the extra brackets if they weren't used to\n\t\t\t// escape the shortcode.\n\t\t\treturn result || result === '' ? left + result + right : match;\n\t\t}\n\t);\n}\n\n/**\n * Generate a string from shortcode parameters.\n *\n * Creates a shortcode instance and returns a string.\n *\n * Accepts the same `options` as the `shortcode()` constructor, containing a\n * `tag` string, a string or object of `attrs`, a boolean indicating whether to\n * format the shortcode using a `single` tag, and a `content` string.\n *\n * @param {Object} options\n *\n * @return {string} String representation of the shortcode.\n */\nexport function string( options ) {\n\treturn new shortcode( options ).string();\n}\n\n/**\n * Generate a RegExp to identify a shortcode.\n *\n * The base regex is functionally equivalent to the one found in\n * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.\n *\n * Capture groups:\n *\n * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`\n * 2. The shortcode name\n * 3. The shortcode argument list\n * 4. The self closing `/`\n * 5. The content of a shortcode when it wraps some content.\n * 6. The closing tag.\n * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`\n *\n * @param {string} tag Shortcode tag.\n *\n * @return {RegExp} Shortcode RegExp.\n */\nexport function regexp( tag ) {\n\treturn new RegExp(\n\t\t'\\\\[(\\\\[?)(' +\n\t\t\ttag +\n\t\t\t')(?![\\\\w-])([^\\\\]\\\\/]*(?:\\\\/(?!\\\\])[^\\\\]\\\\/]*)*?)(?:(\\\\/)\\\\]|\\\\](?:([^\\\\[]*(?:\\\\[(?!\\\\/\\\\2\\\\])[^\\\\[]*)*)(\\\\[\\\\/\\\\2\\\\]))?)(\\\\]?)',\n\t\t'g'\n\t);\n}\n\n/**\n * Parse shortcode attributes.\n *\n * Shortcodes accept many types of attributes. These can chiefly be divided into\n * named and numeric attributes:\n *\n * Named attributes are assigned on a key/value basis, while numeric attributes\n * are treated as an array.\n *\n * Named attributes can be formatted as either `name=\"value\"`, `name='value'`,\n * or `name=value`. Numeric attributes can be formatted as `\"value\"` or just\n * `value`.\n *\n * @param {string} text Serialised shortcode attributes.\n *\n * @return {WPShortcodeAttrs} Parsed shortcode attributes.\n */\nexport const attrs = memize( ( text ) => {\n\tconst named = {};\n\tconst numeric = [];\n\n\t// This regular expression is reused from `shortcode_parse_atts()` in\n\t// `wp-includes/shortcodes.php`.\n\t//\n\t// Capture groups:\n\t//\n\t// 1. An attribute name, that corresponds to...\n\t// 2. a value in double quotes.\n\t// 3. An attribute name, that corresponds to...\n\t// 4. a value in single quotes.\n\t// 5. An attribute name, that corresponds to...\n\t// 6. an unquoted value.\n\t// 7. A numeric attribute in double quotes.\n\t// 8. A numeric attribute in single quotes.\n\t// 9. An unquoted numeric attribute.\n\tconst pattern = /([\\w-]+)\\s*=\\s*\"([^\"]*)\"(?:\\s|$)|([\\w-]+)\\s*=\\s*'([^']*)'(?:\\s|$)|([\\w-]+)\\s*=\\s*([^\\s'\"]+)(?:\\s|$)|\"([^\"]*)\"(?:\\s|$)|'([^']*)'(?:\\s|$)|(\\S+)(?:\\s|$)/g;\n\n\t// Map zero-width spaces to actual spaces.\n\ttext = text.replace( /[\\u00a0\\u200b]/g, ' ' );\n\n\tlet match;\n\n\t// Match and normalize attributes.\n\twhile ( ( match = pattern.exec( text ) ) ) {\n\t\tif ( match[ 1 ] ) {\n\t\t\tnamed[ match[ 1 ].toLowerCase() ] = match[ 2 ];\n\t\t} else if ( match[ 3 ] ) {\n\t\t\tnamed[ match[ 3 ].toLowerCase() ] = match[ 4 ];\n\t\t} else if ( match[ 5 ] ) {\n\t\t\tnamed[ match[ 5 ].toLowerCase() ] = match[ 6 ];\n\t\t} else if ( match[ 7 ] ) {\n\t\t\tnumeric.push( match[ 7 ] );\n\t\t} else if ( match[ 8 ] ) {\n\t\t\tnumeric.push( match[ 8 ] );\n\t\t} else if ( match[ 9 ] ) {\n\t\t\tnumeric.push( match[ 9 ] );\n\t\t}\n\t}\n\n\treturn { named, numeric };\n} );\n\n/**\n * Generate a Shortcode Object from a RegExp match.\n *\n * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated\n * by `regexp()`. `match` can also be set to the `arguments` from a callback\n * passed to `regexp.replace()`.\n *\n * @param {Array} match Match array.\n *\n * @return {WPShortcode} Shortcode instance.\n */\nexport function fromMatch( match ) {\n\tlet type;\n\n\tif ( match[ 4 ] ) {\n\t\ttype = 'self-closing';\n\t} else if ( match[ 6 ] ) {\n\t\ttype = 'closed';\n\t} else {\n\t\ttype = 'single';\n\t}\n\n\treturn new shortcode( {\n\t\ttag: match[ 2 ],\n\t\tattrs: match[ 3 ],\n\t\ttype,\n\t\tcontent: match[ 5 ],\n\t} );\n}\n\n/**\n * Creates a shortcode instance.\n *\n * To access a raw representation of a shortcode, pass an `options` object,\n * containing a `tag` string, a string or object of `attrs`, a string indicating\n * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a\n * `content` string.\n *\n * @param {Object} options Options as described.\n *\n * @return {WPShortcode} Shortcode instance.\n */\nconst shortcode = extend(\n\tfunction ( options ) {\n\t\textend(\n\t\t\tthis,\n\t\t\tpick( options || {}, 'tag', 'attrs', 'type', 'content' )\n\t\t);\n\n\t\tconst attributes = this.attrs;\n\n\t\t// Ensure we have a correctly formatted `attrs` object.\n\t\tthis.attrs = {\n\t\t\tnamed: {},\n\t\t\tnumeric: [],\n\t\t};\n\n\t\tif ( ! attributes ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Parse a string of attributes.\n\t\tif ( isString( attributes ) ) {\n\t\t\tthis.attrs = attrs( attributes );\n\t\t\t// Identify a correctly formatted `attrs` object.\n\t\t} else if (\n\t\t\tisEqual( Object.keys( attributes ), [ 'named', 'numeric' ] )\n\t\t) {\n\t\t\tthis.attrs = attributes;\n\t\t\t// Handle a flat object of attributes.\n\t\t} else {\n\t\t\tforEach( attributes, ( value, key ) => {\n\t\t\t\tthis.set( key, value );\n\t\t\t} );\n\t\t}\n\t},\n\t{\n\t\tnext,\n\t\treplace,\n\t\tstring,\n\t\tregexp,\n\t\tattrs,\n\t\tfromMatch,\n\t}\n);\n\nextend( shortcode.prototype, {\n\t/**\n\t * Get a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t *\n\t * @return {string} Attribute value.\n\t */\n\tget( attr ) {\n\t\treturn this.attrs[ isNumber( attr ) ? 'numeric' : 'named' ][ attr ];\n\t},\n\n\t/**\n\t * Set a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t * @param {string} value Attribute value.\n\t *\n\t * @return {WPShortcode} Shortcode instance.\n\t */\n\tset( attr, value ) {\n\t\tthis.attrs[ isNumber( attr ) ? 'numeric' : 'named' ][ attr ] = value;\n\t\treturn this;\n\t},\n\n\t/**\n\t * Transform the shortcode into a string.\n\t *\n\t * @return {string} String representation of the shortcode.\n\t */\n\tstring() {\n\t\tlet text = '[' + this.tag;\n\n\t\tforEach( this.attrs.numeric, ( value ) => {\n\t\t\tif ( /\\s/.test( value ) ) {\n\t\t\t\ttext += ' \"' + value + '\"';\n\t\t\t} else {\n\t\t\t\ttext += ' ' + value;\n\t\t\t}\n\t\t} );\n\n\t\tforEach( this.attrs.named, ( value, name ) => {\n\t\t\ttext += ' ' + name + '=\"' + value + '\"';\n\t\t} );\n\n\t\t// If the tag is marked as `single` or `self-closing`, close the tag and\n\t\t// ignore any additional content.\n\t\tif ( 'single' === this.type ) {\n\t\t\treturn text + ']';\n\t\t} else if ( 'self-closing' === this.type ) {\n\t\t\treturn text + ' /]';\n\t\t}\n\n\t\t// Complete the opening tag.\n\t\ttext += ']';\n\n\t\tif ( this.content ) {\n\t\t\ttext += this.content;\n\t\t}\n\n\t\t// Add the closing tag.\n\t\treturn text + '[/' + this.tag + ']';\n\t},\n} );\n\nexport default shortcode;\n"]}
1
+ {"version":3,"sources":["@wordpress/shortcode/src/index.js"],"names":["extend","pick","isString","isEqual","forEach","isNumber","memize","next","tag","text","index","re","regexp","lastIndex","match","exec","result","content","shortcode","fromMatch","slice","replace","callback","left","$3","attrs","slash","closing","right","arguments","string","options","RegExp","named","numeric","pattern","toLowerCase","push","type","attributes","Object","keys","value","key","set","prototype","get","attr","test","name"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAT,EAAiBC,IAAjB,EAAuBC,QAAvB,EAAiCC,OAAjC,EAA0CC,OAA1C,EAAmDC,QAAnD,QAAmE,QAAnE;AACA,OAAOC,MAAP,MAAmB,QAAnB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,IAAT,CAAeC,GAAf,EAAoBC,IAApB,EAAsC;AAAA,MAAZC,KAAY,uEAAJ,CAAI;AAC5C,QAAMC,EAAE,GAAGC,MAAM,CAAEJ,GAAF,CAAjB;AAEAG,EAAAA,EAAE,CAACE,SAAH,GAAeH,KAAf;AAEA,QAAMI,KAAK,GAAGH,EAAE,CAACI,IAAH,CAASN,IAAT,CAAd;;AAEA,MAAK,CAAEK,KAAP,EAAe;AACd;AACA,GAT2C,CAW5C;;;AACA,MAAK,QAAQA,KAAK,CAAE,CAAF,CAAb,IAAsB,QAAQA,KAAK,CAAE,CAAF,CAA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IAAAA,IAAI,IAAI,GAAR;;AAEA,QAAK,KAAKQ,OAAV,EAAoB;AACnBR,MAAAA,IAAI,IAAI,KAAKQ,OAAb;AACA,KA5BO,CA8BR;;;AACA,WAAOR,IAAI,GAAG,IAAP,GAAc,KAAKD,GAAnB,GAAyB,GAAhC;AACA;;AApE2B,CAAvB,CAAN;AAuEA,eAAeU,SAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { extend, pick, isString, isEqual, forEach, isNumber } from 'lodash';\nimport memize from 'memize';\n\n/**\n * Shortcode attributes object.\n *\n * @typedef {Object} WPShortcodeAttrs\n *\n * @property {Object} named Object with named attributes.\n * @property {Array} numeric Array with numeric attributes.\n */\n\n/**\n * Shortcode object.\n *\n * @typedef {Object} WPShortcode\n *\n * @property {string} tag Shortcode tag.\n * @property {WPShortcodeAttrs} attrs Shortcode attributes.\n * @property {string} content Shortcode content.\n * @property {string} type Shortcode type: `self-closing`,\n * `closed`, or `single`.\n */\n\n/**\n * @typedef {Object} WPShortcodeMatch\n *\n * @property {number} index Index the shortcode is found at.\n * @property {string} content Matched content.\n * @property {WPShortcode} shortcode Shortcode instance of the match.\n */\n\n/**\n * Find the next matching shortcode.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {number} index Index to start search from.\n *\n * @return {?WPShortcodeMatch} Matched information.\n */\nexport function next( tag, text, index = 0 ) {\n\tconst re = regexp( tag );\n\n\tre.lastIndex = index;\n\n\tconst match = re.exec( text );\n\n\tif ( ! match ) {\n\t\treturn;\n\t}\n\n\t// If we matched an escaped shortcode, try again.\n\tif ( '[' === match[ 1 ] && ']' === match[ 7 ] ) {\n\t\treturn next( tag, text, re.lastIndex );\n\t}\n\n\tconst result = {\n\t\tindex: match.index,\n\t\tcontent: match[ 0 ],\n\t\tshortcode: fromMatch( match ),\n\t};\n\n\t// If we matched a leading `[`, strip it from the match and increment the\n\t// index accordingly.\n\tif ( match[ 1 ] ) {\n\t\tresult.content = result.content.slice( 1 );\n\t\tresult.index++;\n\t}\n\n\t// If we matched a trailing `]`, strip it from the match.\n\tif ( match[ 7 ] ) {\n\t\tresult.content = result.content.slice( 0, -1 );\n\t}\n\n\treturn result;\n}\n\n/**\n * Replace matching shortcodes in a block of text.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {Function} callback Function to process the match and return\n * replacement string.\n *\n * @return {string} Text with shortcodes replaced.\n */\nexport function replace( tag, text, callback ) {\n\treturn text.replace(\n\t\tregexp( tag ),\n\t\tfunction ( match, left, $3, attrs, slash, content, closing, right ) {\n\t\t\t// If both extra brackets exist, the shortcode has been properly\n\t\t\t// escaped.\n\t\t\tif ( left === '[' && right === ']' ) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\t// Create the match object and pass it through the callback.\n\t\t\tconst result = callback( fromMatch( arguments ) );\n\n\t\t\t// Make sure to return any of the extra brackets if they weren't used to\n\t\t\t// escape the shortcode.\n\t\t\treturn result || result === '' ? left + result + right : match;\n\t\t}\n\t);\n}\n\n/**\n * Generate a string from shortcode parameters.\n *\n * Creates a shortcode instance and returns a string.\n *\n * Accepts the same `options` as the `shortcode()` constructor, containing a\n * `tag` string, a string or object of `attrs`, a boolean indicating whether to\n * format the shortcode using a `single` tag, and a `content` string.\n *\n * @param {Object} options\n *\n * @return {string} String representation of the shortcode.\n */\nexport function string( options ) {\n\treturn new shortcode( options ).string();\n}\n\n/**\n * Generate a RegExp to identify a shortcode.\n *\n * The base regex is functionally equivalent to the one found in\n * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.\n *\n * Capture groups:\n *\n * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`\n * 2. The shortcode name\n * 3. The shortcode argument list\n * 4. The self closing `/`\n * 5. The content of a shortcode when it wraps some content.\n * 6. The closing tag.\n * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`\n *\n * @param {string} tag Shortcode tag.\n *\n * @return {RegExp} Shortcode RegExp.\n */\nexport function regexp( tag ) {\n\treturn new RegExp(\n\t\t'\\\\[(\\\\[?)(' +\n\t\t\ttag +\n\t\t\t')(?![\\\\w-])([^\\\\]\\\\/]*(?:\\\\/(?!\\\\])[^\\\\]\\\\/]*)*?)(?:(\\\\/)\\\\]|\\\\](?:([^\\\\[]*(?:\\\\[(?!\\\\/\\\\2\\\\])[^\\\\[]*)*)(\\\\[\\\\/\\\\2\\\\]))?)(\\\\]?)',\n\t\t'g'\n\t);\n}\n\n/**\n * Parse shortcode attributes.\n *\n * Shortcodes accept many types of attributes. These can chiefly be divided into\n * named and numeric attributes:\n *\n * Named attributes are assigned on a key/value basis, while numeric attributes\n * are treated as an array.\n *\n * Named attributes can be formatted as either `name=\"value\"`, `name='value'`,\n * or `name=value`. Numeric attributes can be formatted as `\"value\"` or just\n * `value`.\n *\n * @param {string} text Serialised shortcode attributes.\n *\n * @return {WPShortcodeAttrs} Parsed shortcode attributes.\n */\nexport const attrs = memize( ( text ) => {\n\tconst named = {};\n\tconst numeric = [];\n\n\t// This regular expression is reused from `shortcode_parse_atts()` in\n\t// `wp-includes/shortcodes.php`.\n\t//\n\t// Capture groups:\n\t//\n\t// 1. An attribute name, that corresponds to...\n\t// 2. a value in double quotes.\n\t// 3. An attribute name, that corresponds to...\n\t// 4. a value in single quotes.\n\t// 5. An attribute name, that corresponds to...\n\t// 6. an unquoted value.\n\t// 7. A numeric attribute in double quotes.\n\t// 8. A numeric attribute in single quotes.\n\t// 9. An unquoted numeric attribute.\n\tconst pattern = /([\\w-]+)\\s*=\\s*\"([^\"]*)\"(?:\\s|$)|([\\w-]+)\\s*=\\s*'([^']*)'(?:\\s|$)|([\\w-]+)\\s*=\\s*([^\\s'\"]+)(?:\\s|$)|\"([^\"]*)\"(?:\\s|$)|'([^']*)'(?:\\s|$)|(\\S+)(?:\\s|$)/g;\n\n\t// Map zero-width spaces to actual spaces.\n\ttext = text.replace( /[\\u00a0\\u200b]/g, ' ' );\n\n\tlet match;\n\n\t// Match and normalize attributes.\n\twhile ( ( match = pattern.exec( text ) ) ) {\n\t\tif ( match[ 1 ] ) {\n\t\t\tnamed[ match[ 1 ].toLowerCase() ] = match[ 2 ];\n\t\t} else if ( match[ 3 ] ) {\n\t\t\tnamed[ match[ 3 ].toLowerCase() ] = match[ 4 ];\n\t\t} else if ( match[ 5 ] ) {\n\t\t\tnamed[ match[ 5 ].toLowerCase() ] = match[ 6 ];\n\t\t} else if ( match[ 7 ] ) {\n\t\t\tnumeric.push( match[ 7 ] );\n\t\t} else if ( match[ 8 ] ) {\n\t\t\tnumeric.push( match[ 8 ] );\n\t\t} else if ( match[ 9 ] ) {\n\t\t\tnumeric.push( match[ 9 ] );\n\t\t}\n\t}\n\n\treturn { named, numeric };\n} );\n\n/**\n * Generate a Shortcode Object from a RegExp match.\n *\n * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated\n * by `regexp()`. `match` can also be set to the `arguments` from a callback\n * passed to `regexp.replace()`.\n *\n * @param {Array} match Match array.\n *\n * @return {WPShortcode} Shortcode instance.\n */\nexport function fromMatch( match ) {\n\tlet type;\n\n\tif ( match[ 4 ] ) {\n\t\ttype = 'self-closing';\n\t} else if ( match[ 6 ] ) {\n\t\ttype = 'closed';\n\t} else {\n\t\ttype = 'single';\n\t}\n\n\treturn new shortcode( {\n\t\ttag: match[ 2 ],\n\t\tattrs: match[ 3 ],\n\t\ttype,\n\t\tcontent: match[ 5 ],\n\t} );\n}\n\n/**\n * Creates a shortcode instance.\n *\n * To access a raw representation of a shortcode, pass an `options` object,\n * containing a `tag` string, a string or object of `attrs`, a string indicating\n * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a\n * `content` string.\n *\n * @param {Object} options Options as described.\n *\n * @return {WPShortcode} Shortcode instance.\n */\nconst shortcode = extend(\n\tfunction ( options ) {\n\t\textend(\n\t\t\tthis,\n\t\t\tpick( options || {}, 'tag', 'attrs', 'type', 'content' )\n\t\t);\n\n\t\tconst attributes = this.attrs;\n\n\t\t// Ensure we have a correctly formatted `attrs` object.\n\t\tthis.attrs = {\n\t\t\tnamed: {},\n\t\t\tnumeric: [],\n\t\t};\n\n\t\tif ( ! attributes ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Parse a string of attributes.\n\t\tif ( isString( attributes ) ) {\n\t\t\tthis.attrs = attrs( attributes );\n\t\t\t// Identify a correctly formatted `attrs` object.\n\t\t} else if (\n\t\t\tisEqual( Object.keys( attributes ), [ 'named', 'numeric' ] )\n\t\t) {\n\t\t\tthis.attrs = attributes;\n\t\t\t// Handle a flat object of attributes.\n\t\t} else {\n\t\t\tforEach( attributes, ( value, key ) => {\n\t\t\t\tthis.set( key, value );\n\t\t\t} );\n\t\t}\n\t},\n\t{\n\t\tnext,\n\t\treplace,\n\t\tstring,\n\t\tregexp,\n\t\tattrs,\n\t\tfromMatch,\n\t}\n);\n\nextend( shortcode.prototype, {\n\t/**\n\t * Get a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t *\n\t * @return {string} Attribute value.\n\t */\n\tget( attr ) {\n\t\treturn this.attrs[ isNumber( attr ) ? 'numeric' : 'named' ][ attr ];\n\t},\n\n\t/**\n\t * Set a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t * @param {string} value Attribute value.\n\t *\n\t * @return {WPShortcode} Shortcode instance.\n\t */\n\tset( attr, value ) {\n\t\tthis.attrs[ isNumber( attr ) ? 'numeric' : 'named' ][ attr ] = value;\n\t\treturn this;\n\t},\n\n\t/**\n\t * Transform the shortcode into a string.\n\t *\n\t * @return {string} String representation of the shortcode.\n\t */\n\tstring() {\n\t\tlet text = '[' + this.tag;\n\n\t\tforEach( this.attrs.numeric, ( value ) => {\n\t\t\tif ( /\\s/.test( value ) ) {\n\t\t\t\ttext += ' \"' + value + '\"';\n\t\t\t} else {\n\t\t\t\ttext += ' ' + value;\n\t\t\t}\n\t\t} );\n\n\t\tforEach( this.attrs.named, ( value, name ) => {\n\t\t\ttext += ' ' + name + '=\"' + value + '\"';\n\t\t} );\n\n\t\t// If the tag is marked as `single` or `self-closing`, close the tag and\n\t\t// ignore any additional content.\n\t\tif ( 'single' === this.type ) {\n\t\t\treturn text + ']';\n\t\t} else if ( 'self-closing' === this.type ) {\n\t\t\treturn text + ' /]';\n\t\t}\n\n\t\t// Complete the opening tag.\n\t\ttext += ']';\n\n\t\tif ( this.content ) {\n\t\t\ttext += this.content;\n\t\t}\n\n\t\t// Add the closing tag.\n\t\treturn text + '[/' + this.tag + ']';\n\t},\n} );\n\nexport default shortcode;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/shortcode",
3
- "version": "3.2.2",
3
+ "version": "3.3.1",
4
4
  "description": "Shortcode module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -25,12 +25,12 @@
25
25
  "module": "build-module/index.js",
26
26
  "react-native": "src/index",
27
27
  "dependencies": {
28
- "@babel/runtime": "^7.13.10",
28
+ "@babel/runtime": "^7.16.0",
29
29
  "lodash": "^4.17.21",
30
30
  "memize": "^1.1.0"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
35
- "gitHead": "8f7f052bc04e3f4eb50f479ced14be1489b9fa79"
35
+ "gitHead": "2e4922861e49f5a090f9dc52056165092cfba163"
36
36
  }