@wordpress/shortcode 4.12.1-next.082ed6819.0 → 4.13.1-next.cd6172eb0.0
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 +6 -0
- package/README.md +7 -11
- package/build/index.js +30 -41
- package/build/index.js.map +1 -1
- package/build/types.js +6 -0
- package/build/types.js.map +1 -0
- package/build-module/index.js +11 -41
- package/build-module/index.js.map +1 -1
- package/build-module/types.js +2 -0
- package/build-module/types.js.map +1 -0
- package/build-types/index.d.ts +103 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/types.d.ts +182 -0
- package/build-types/types.d.ts.map +1 -0
- package/package.json +3 -2
- package/src/index.js +11 -40
- package/src/types.ts +210 -0
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ _Parameters_
|
|
|
32
32
|
|
|
33
33
|
_Returns_
|
|
34
34
|
|
|
35
|
-
- `
|
|
35
|
+
- `import('./types').ShortcodeAttrs`: Parsed shortcode attributes.
|
|
36
36
|
|
|
37
37
|
### default
|
|
38
38
|
|
|
@@ -40,13 +40,9 @@ Creates a shortcode instance.
|
|
|
40
40
|
|
|
41
41
|
To access a raw representation of a shortcode, pass an `options` object, containing a `tag` string, a string or object of `attrs`, a string indicating the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a `content` string.
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
- _options_ `Object`: Options as described.
|
|
46
|
-
|
|
47
|
-
_Returns_
|
|
43
|
+
_Type_
|
|
48
44
|
|
|
49
|
-
- `
|
|
45
|
+
- `import('./types').shortcode`Shortcode instance.
|
|
50
46
|
|
|
51
47
|
### fromMatch
|
|
52
48
|
|
|
@@ -56,11 +52,11 @@ Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated by
|
|
|
56
52
|
|
|
57
53
|
_Parameters_
|
|
58
54
|
|
|
59
|
-
- _match_ `
|
|
55
|
+
- _match_ `import('./types').Match`: Match array.
|
|
60
56
|
|
|
61
57
|
_Returns_
|
|
62
58
|
|
|
63
|
-
- `
|
|
59
|
+
- `InstanceType<import('./types').shortcode>`: Shortcode instance.
|
|
64
60
|
|
|
65
61
|
### next
|
|
66
62
|
|
|
@@ -74,7 +70,7 @@ _Parameters_
|
|
|
74
70
|
|
|
75
71
|
_Returns_
|
|
76
72
|
|
|
77
|
-
- `
|
|
73
|
+
- `import('./types').ShortcodeMatch | undefined`: Matched information.
|
|
78
74
|
|
|
79
75
|
### regexp
|
|
80
76
|
|
|
@@ -108,7 +104,7 @@ _Parameters_
|
|
|
108
104
|
|
|
109
105
|
- _tag_ `string`: Shortcode tag.
|
|
110
106
|
- _text_ `string`: Text to search.
|
|
111
|
-
- _callback_ `
|
|
107
|
+
- _callback_ `import('./types').ReplaceCallback`: Function to process the match and return replacement string.
|
|
112
108
|
|
|
113
109
|
_Returns_
|
|
114
110
|
|
package/build/index.js
CHANGED
|
@@ -4,6 +4,14 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
+
var _exportNames = {
|
|
8
|
+
next: true,
|
|
9
|
+
replace: true,
|
|
10
|
+
string: true,
|
|
11
|
+
regexp: true,
|
|
12
|
+
attrs: true,
|
|
13
|
+
fromMatch: true
|
|
14
|
+
};
|
|
7
15
|
exports.default = exports.attrs = void 0;
|
|
8
16
|
exports.fromMatch = fromMatch;
|
|
9
17
|
exports.next = next;
|
|
@@ -11,39 +19,22 @@ exports.regexp = regexp;
|
|
|
11
19
|
exports.replace = replace;
|
|
12
20
|
exports.string = string;
|
|
13
21
|
var _memize = _interopRequireDefault(require("memize"));
|
|
22
|
+
var _types = require("./types");
|
|
23
|
+
Object.keys(_types).forEach(function (key) {
|
|
24
|
+
if (key === "default" || key === "__esModule") return;
|
|
25
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
26
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
27
|
+
Object.defineProperty(exports, key, {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () {
|
|
30
|
+
return _types[key];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
14
34
|
/**
|
|
15
35
|
* External dependencies
|
|
16
36
|
*/
|
|
17
37
|
|
|
18
|
-
/**
|
|
19
|
-
* Shortcode attributes object.
|
|
20
|
-
*
|
|
21
|
-
* @typedef {Object} WPShortcodeAttrs
|
|
22
|
-
*
|
|
23
|
-
* @property {Object} named Object with named attributes.
|
|
24
|
-
* @property {Array} numeric Array with numeric attributes.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Shortcode object.
|
|
29
|
-
*
|
|
30
|
-
* @typedef {Object} WPShortcode
|
|
31
|
-
*
|
|
32
|
-
* @property {string} tag Shortcode tag.
|
|
33
|
-
* @property {WPShortcodeAttrs} attrs Shortcode attributes.
|
|
34
|
-
* @property {string} content Shortcode content.
|
|
35
|
-
* @property {string} type Shortcode type: `self-closing`,
|
|
36
|
-
* `closed`, or `single`.
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @typedef {Object} WPShortcodeMatch
|
|
41
|
-
*
|
|
42
|
-
* @property {number} index Index the shortcode is found at.
|
|
43
|
-
* @property {string} content Matched content.
|
|
44
|
-
* @property {WPShortcode} shortcode Shortcode instance of the match.
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
38
|
/**
|
|
48
39
|
* Find the next matching shortcode.
|
|
49
40
|
*
|
|
@@ -51,7 +42,7 @@ var _memize = _interopRequireDefault(require("memize"));
|
|
|
51
42
|
* @param {string} text Text to search.
|
|
52
43
|
* @param {number} index Index to start search from.
|
|
53
44
|
*
|
|
54
|
-
* @return {
|
|
45
|
+
* @return {import('./types').ShortcodeMatch | undefined} Matched information.
|
|
55
46
|
*/
|
|
56
47
|
function next(tag, text, index = 0) {
|
|
57
48
|
const re = regexp(tag);
|
|
@@ -88,10 +79,10 @@ function next(tag, text, index = 0) {
|
|
|
88
79
|
/**
|
|
89
80
|
* Replace matching shortcodes in a block of text.
|
|
90
81
|
*
|
|
91
|
-
* @param {string}
|
|
92
|
-
* @param {string}
|
|
93
|
-
* @param {
|
|
94
|
-
*
|
|
82
|
+
* @param {string} tag Shortcode tag.
|
|
83
|
+
* @param {string} text Text to search.
|
|
84
|
+
* @param {import('./types').ReplaceCallback} callback Function to process the match and return
|
|
85
|
+
* replacement string.
|
|
95
86
|
*
|
|
96
87
|
* @return {string} Text with shortcodes replaced.
|
|
97
88
|
*/
|
|
@@ -168,7 +159,7 @@ function regexp(tag) {
|
|
|
168
159
|
*
|
|
169
160
|
* @param {string} text Serialised shortcode attributes.
|
|
170
161
|
*
|
|
171
|
-
* @return {
|
|
162
|
+
* @return {import('./types').ShortcodeAttrs} Parsed shortcode attributes.
|
|
172
163
|
*/
|
|
173
164
|
const attrs = exports.attrs = (0, _memize.default)(text => {
|
|
174
165
|
const named = {};
|
|
@@ -223,9 +214,9 @@ const attrs = exports.attrs = (0, _memize.default)(text => {
|
|
|
223
214
|
* by `regexp()`. `match` can also be set to the `arguments` from a callback
|
|
224
215
|
* passed to `regexp.replace()`.
|
|
225
216
|
*
|
|
226
|
-
* @param {
|
|
217
|
+
* @param {import('./types').Match} match Match array.
|
|
227
218
|
*
|
|
228
|
-
* @return {
|
|
219
|
+
* @return {InstanceType<import('./types').shortcode>} Shortcode instance.
|
|
229
220
|
*/
|
|
230
221
|
function fromMatch(match) {
|
|
231
222
|
let type;
|
|
@@ -252,9 +243,7 @@ function fromMatch(match) {
|
|
|
252
243
|
* the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a
|
|
253
244
|
* `content` string.
|
|
254
245
|
*
|
|
255
|
-
* @
|
|
256
|
-
*
|
|
257
|
-
* @return {WPShortcode} Shortcode instance.
|
|
246
|
+
* @type {import('./types').shortcode} Shortcode instance.
|
|
258
247
|
*/
|
|
259
248
|
const shortcode = Object.assign(function (options) {
|
|
260
249
|
const {
|
|
@@ -322,7 +311,7 @@ Object.assign(shortcode.prototype, {
|
|
|
322
311
|
* @param {(number|string)} attr Attribute key.
|
|
323
312
|
* @param {string} value Attribute value.
|
|
324
313
|
*
|
|
325
|
-
* @return {
|
|
314
|
+
* @return {InstanceType< import('./types').shortcode >} Shortcode instance.
|
|
326
315
|
*/
|
|
327
316
|
set(attr, value) {
|
|
328
317
|
this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr] = value;
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_memize","_interopRequireDefault","require","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","exports","memize","named","numeric","pattern","toLowerCase","push","type","Object","assign","attributes","attributeTypes","length","every","t","key","entries","forEach","value","set","prototype","get","attr","test","name","_default","default"],"sources":["@wordpress/shortcode/src/index.js"],"sourcesContent":["/**\n * External dependencies\n */\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 | undefined} 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 =\n\t\t/([\\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 = Object.assign(\n\tfunction ( options ) {\n\t\tconst { tag, attrs: attributes, type, content } = options || {};\n\t\tObject.assign( this, { tag, type, content } );\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\tconst attributeTypes = [ 'named', 'numeric' ];\n\n\t\t// Parse a string of attributes.\n\t\tif ( typeof attributes === 'string' ) {\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\tattributes.length === attributeTypes.length &&\n\t\t\tattributeTypes.every( ( t, key ) => t === attributes[ key ] )\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\tObject.entries( attributes ).forEach( ( [ key, value ] ) => {\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\nObject.assign( 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[ typeof attr === 'number' ? 'numeric' : 'named' ][\n\t\t\tattr\n\t\t];\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[ typeof attr === 'number' ? 'numeric' : 'named' ][ attr ] =\n\t\t\tvalue;\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\tthis.attrs.numeric.forEach( ( 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\tObject.entries( this.attrs.named ).forEach( ( [ name, value ] ) => {\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"],"mappings":";;;;;;;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;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,SAASC,IAAIA,CAAEC,G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AAG,GAAGgD,IAAI,GAAG,IAAI,GAAGN,KAAK,GAAG,GAAG;IACxC,CAAE,CAAC;;IAEH;IACA;IACA,IAAK,QAAQ,KAAK,IAAI,CAACX,IAAI,EAAG;MAC7B,OAAO/B,IAAI,GAAG,GAAG;IAClB,CAAC,MAAM,IAAK,cAAc,KAAK,IAAI,CAAC+B,IAAI,EAAG;MAC1C,OAAO/B,IAAI,GAAG,KAAK;IACpB;;IAEA;IACAA,IAAI,IAAI,GAAG;IAEX,IAAK,IAAI,CAACQ,OAAO,EAAG;MACnBR,IAAI,IAAI,IAAI,CAACQ,OAAO;IACrB;;IAEA;IACA,OAAOR,IAAI,GAAG,IAAI,GAAG,IAAI,CAACD,GAAG,GAAG,GAAG;EACpC;AACD,CAAE,CAAC;AAAC,IAAAkD,QAAA,GAAAzB,OAAA,CAAA0B,OAAA,GAEWzC,SAAS","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_memize","_interopRequireDefault","require","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","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","memize","named","numeric","pattern","toLowerCase","push","type","assign","attributes","attributeTypes","length","every","t","entries","value","set","attr","test","name","_default","default"],"sources":["@wordpress/shortcode/src/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport memize from 'memize';\n\nexport * from './types';\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 {import('./types').ShortcodeMatch | undefined} 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 {import('./types').ReplaceCallback} 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 {import('./types').ShortcodeAttrs} 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 =\n\t\t/([\\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 {import('./types').Match} match Match array.\n *\n * @return {InstanceType<import('./types').shortcode>} 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 * @type {import('./types').shortcode} Shortcode instance.\n */\nconst shortcode = Object.assign(\n\tfunction ( options ) {\n\t\tconst { tag, attrs: attributes, type, content } = options || {};\n\t\tObject.assign( this, { tag, type, content } );\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\tconst attributeTypes = [ 'named', 'numeric' ];\n\n\t\t// Parse a string of attributes.\n\t\tif ( typeof attributes === 'string' ) {\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\tattributes.length === attributeTypes.length &&\n\t\t\tattributeTypes.every( ( t, key ) => t === attributes[ key ] )\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\tObject.entries( attributes ).forEach( ( [ key, value ] ) => {\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\nObject.assign( 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[ typeof attr === 'number' ? 'numeric' : 'named' ][\n\t\t\tattr\n\t\t];\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 {InstanceType< import('./types').shortcode >} Shortcode instance.\n\t */\n\tset( attr, value ) {\n\t\tthis.attrs[ typeof attr === 'number' ? 'numeric' : 'named' ][ attr ] =\n\t\t\tvalue;\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\tthis.attrs.numeric.forEach( ( 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\tObject.entries( this.attrs.named ).forEach( ( [ name, value ] ) => {\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAA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AAM,CAACmD,OAAO,CAAE,IAAI,CAACrB,KAAK,CAACS,KAAM,CAAC,CAACrC,OAAO,CAAE,CAAE,CAAEsD,IAAI,EAAEJ,KAAK,CAAE,KAAM;MAClEtC,IAAI,IAAI,GAAG,GAAG0C,IAAI,GAAG,IAAI,GAAGJ,KAAK,GAAG,GAAG;IACxC,CAAE,CAAC;;IAEH;IACA;IACA,IAAK,QAAQ,KAAK,IAAI,CAACR,IAAI,EAAG;MAC7B,OAAO9B,IAAI,GAAG,GAAG;IAClB,CAAC,MAAM,IAAK,cAAc,KAAK,IAAI,CAAC8B,IAAI,EAAG;MAC1C,OAAO9B,IAAI,GAAG,KAAK;IACpB;;IAEA;IACAA,IAAI,IAAI,GAAG;IAEX,IAAK,IAAI,CAACQ,OAAO,EAAG;MACnBR,IAAI,IAAI,IAAI,CAACQ,OAAO;IACrB;;IAEA;IACA,OAAOR,IAAI,GAAG,IAAI,GAAG,IAAI,CAACD,GAAG,GAAG,GAAG;EACpC;AACD,CAAE,CAAC;AAAC,IAAA4C,QAAA,GAAAjD,OAAA,CAAAkD,OAAA,GAEWnC,SAAS","ignoreList":[]}
|
package/build/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/shortcode/src/types.ts"],"sourcesContent":["/**\n * Shortcode attributes object.\n */\nexport type ShortcodeAttrs = {\n\t/**\n\t * Object with named attributes.\n\t */\n\tnamed: Record< string, string | undefined >;\n\n\t/**\n\t * Array with numeric attributes.\n\t */\n\tnumeric: string[];\n};\n\nexport type ShortcodeMatch = {\n\t/**\n\t * Index the shortcode is found at.\n\t */\n\tindex: number;\n\n\t/**\n\t * Matched content.\n\t */\n\tcontent: string;\n\n\t/**\n\t * Shortcode instance of the match.\n\t */\n\tshortcode: Shortcode;\n};\n\n/**\n * Shortcode options.\n */\nexport interface ShortcodeOptions {\n\t/**\n\t * Shortcode tag.\n\t */\n\ttag: string;\n\n\t/**\n\t * Shortcode attributes.\n\t */\n\tattrs?: Partial< ShortcodeAttrs > | string;\n\n\t/**\n\t * Shortcode content.\n\t */\n\tcontent?: string;\n\n\t/**\n\t * Shortcode type: `self-closing`, `closed`, or `single`.\n\t */\n\ttype?: 'self-closing' | 'closed' | 'single';\n}\n\n/**\n * Shortcode object.\n */\nexport interface Shortcode extends ShortcodeOptions {\n\t/**\n\t * Shortcode attributes.\n\t */\n\tattrs: ShortcodeAttrs;\n}\n\nexport type Match =\n\t| NonNullable< ReturnType< RegExp[ 'exec' ] > >\n\t| Array< string >;\n\nexport type ReplaceCallback = ( shortcode: Shortcode ) => string;\n\n/**\n * WordPress Shortcode instance.\n */\nexport interface shortcode {\n\tnew ( options: Partial< ShortcodeOptions > ): Shortcode & {\n\t\t/**\n\t\t * Transform the shortcode into a string.\n\t\t *\n\t\t * @return {string} String representation of the shortcode.\n\t\t */\n\t\tstring: () => string;\n\n\t\t/**\n\t\t * Get a shortcode attribute.\n\t\t *\n\t\t * Automatically detects whether `attr` is named or numeric and routes it\n\t\t * accordingly.\n\t\t *\n\t\t * @param {(number|string)} attr Attribute key.\n\t\t *\n\t\t * @return {string} Attribute value.\n\t\t */\n\t\tget: ( attr: string | number ) => string | undefined;\n\n\t\t/**\n\t\t * Set a shortcode attribute.\n\t\t *\n\t\t * Automatically detects whether `attr` is named or numeric and routes it\n\t\t * accordingly.\n\t\t *\n\t\t * @param {(number|string)} attr Attribute key.\n\t\t * @param {string} value Attribute value.\n\t\t *\n\t\t * @return {InstanceType< shortcode >} Shortcode instance.\n\t\t */\n\t\tset: (\n\t\t\tattr: string | number,\n\t\t\tvalue: string\n\t\t) => InstanceType< shortcode >;\n\t};\n\n\t/**\n\t * Parse shortcode attributes.\n\t *\n\t * Shortcodes accept many types of attributes. These can chiefly be divided into\n\t * named and numeric attributes:\n\t *\n\t * Named attributes are assigned on a key/value basis, while numeric attributes\n\t * are treated as an array.\n\t *\n\t * Named attributes can be formatted as either `name=\"value\"`, `name='value'`,\n\t * or `name=value`. Numeric attributes can be formatted as `\"value\"` or just\n\t * `value`.\n\t *\n\t * @param text Serialised shortcode attributes.\n\t *\n\t * @return Parsed shortcode attributes.\n\t */\n\tattrs: ( text: string ) => ShortcodeAttrs;\n\n\t/**\n\t * Generate a Shortcode Object from a RegExp match.\n\t *\n\t * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated\n\t * by `regexp()`. `match` can also be set to the `arguments` from a callback\n\t * passed to `regexp.replace()`.\n\t *\n\t * @param match Match array.\n\t *\n\t * @return Shortcode instance.\n\t */\n\tfromMatch: ( match: Match ) => InstanceType< shortcode >;\n\n\t/**\n\t * Find the next matching shortcode.\n\t *\n\t * @param tag Shortcode tag.\n\t * @param text Text to search.\n\t * @param index Index to start search from.\n\t *\n\t * @return Matched information.\n\t */\n\tnext: (\n\t\ttag: string,\n\t\ttext: string,\n\t\tindex?: number\n\t) => ShortcodeMatch | undefined;\n\n\t/**\n\t * Generate a RegExp to identify a shortcode.\n\t *\n\t * The base regex is functionally equivalent to the one found in\n\t * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.\n\t *\n\t * Capture groups:\n\t *\n\t * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`\n\t * 2. The shortcode name\n\t * 3. The shortcode argument list\n\t * 4. The self closing `/`\n\t * 5. The content of a shortcode when it wraps some content.\n\t * 6. The closing tag.\n\t * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`\n\t *\n\t * @param tag Shortcode tag.\n\t *\n\t * @return Shortcode RegExp.\n\t */\n\tregexp: ( tag: string ) => RegExp;\n\n\t/**\n\t * Replace matching shortcodes in a block of text.\n\t *\n\t * @param tag Shortcode tag.\n\t * @param text Text to search.\n\t * @param callback Function to process the match and return\n\t * replacement string.\n\t *\n\t * @return Text with shortcodes replaced.\n\t */\n\treplace: ( tag: string, text: string, callback: ReplaceCallback ) => string;\n\n\t/**\n\t * Generate a string from shortcode parameters.\n\t *\n\t * Creates a shortcode instance and returns a string.\n\t *\n\t * Accepts the same `options` as the `shortcode()` constructor, containing a\n\t * `tag` string, a string or object of `attrs`, a boolean indicating whether to\n\t * format the shortcode using a `single` tag, and a `content` string.\n\t *\n\t * @param options\n\t *\n\t * @return String representation of the shortcode.\n\t */\n\tstring: ( options: ShortcodeOptions ) => string;\n}\n"],"mappings":"","ignoreList":[]}
|
package/build-module/index.js
CHANGED
|
@@ -2,35 +2,7 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import memize from 'memize';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Shortcode attributes object.
|
|
8
|
-
*
|
|
9
|
-
* @typedef {Object} WPShortcodeAttrs
|
|
10
|
-
*
|
|
11
|
-
* @property {Object} named Object with named attributes.
|
|
12
|
-
* @property {Array} numeric Array with numeric attributes.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Shortcode object.
|
|
17
|
-
*
|
|
18
|
-
* @typedef {Object} WPShortcode
|
|
19
|
-
*
|
|
20
|
-
* @property {string} tag Shortcode tag.
|
|
21
|
-
* @property {WPShortcodeAttrs} attrs Shortcode attributes.
|
|
22
|
-
* @property {string} content Shortcode content.
|
|
23
|
-
* @property {string} type Shortcode type: `self-closing`,
|
|
24
|
-
* `closed`, or `single`.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @typedef {Object} WPShortcodeMatch
|
|
29
|
-
*
|
|
30
|
-
* @property {number} index Index the shortcode is found at.
|
|
31
|
-
* @property {string} content Matched content.
|
|
32
|
-
* @property {WPShortcode} shortcode Shortcode instance of the match.
|
|
33
|
-
*/
|
|
5
|
+
export * from './types';
|
|
34
6
|
|
|
35
7
|
/**
|
|
36
8
|
* Find the next matching shortcode.
|
|
@@ -39,7 +11,7 @@ import memize from 'memize';
|
|
|
39
11
|
* @param {string} text Text to search.
|
|
40
12
|
* @param {number} index Index to start search from.
|
|
41
13
|
*
|
|
42
|
-
* @return {
|
|
14
|
+
* @return {import('./types').ShortcodeMatch | undefined} Matched information.
|
|
43
15
|
*/
|
|
44
16
|
export function next(tag, text, index = 0) {
|
|
45
17
|
const re = regexp(tag);
|
|
@@ -76,10 +48,10 @@ export function next(tag, text, index = 0) {
|
|
|
76
48
|
/**
|
|
77
49
|
* Replace matching shortcodes in a block of text.
|
|
78
50
|
*
|
|
79
|
-
* @param {string}
|
|
80
|
-
* @param {string}
|
|
81
|
-
* @param {
|
|
82
|
-
*
|
|
51
|
+
* @param {string} tag Shortcode tag.
|
|
52
|
+
* @param {string} text Text to search.
|
|
53
|
+
* @param {import('./types').ReplaceCallback} callback Function to process the match and return
|
|
54
|
+
* replacement string.
|
|
83
55
|
*
|
|
84
56
|
* @return {string} Text with shortcodes replaced.
|
|
85
57
|
*/
|
|
@@ -156,7 +128,7 @@ export function regexp(tag) {
|
|
|
156
128
|
*
|
|
157
129
|
* @param {string} text Serialised shortcode attributes.
|
|
158
130
|
*
|
|
159
|
-
* @return {
|
|
131
|
+
* @return {import('./types').ShortcodeAttrs} Parsed shortcode attributes.
|
|
160
132
|
*/
|
|
161
133
|
export const attrs = memize(text => {
|
|
162
134
|
const named = {};
|
|
@@ -211,9 +183,9 @@ export const attrs = memize(text => {
|
|
|
211
183
|
* by `regexp()`. `match` can also be set to the `arguments` from a callback
|
|
212
184
|
* passed to `regexp.replace()`.
|
|
213
185
|
*
|
|
214
|
-
* @param {
|
|
186
|
+
* @param {import('./types').Match} match Match array.
|
|
215
187
|
*
|
|
216
|
-
* @return {
|
|
188
|
+
* @return {InstanceType<import('./types').shortcode>} Shortcode instance.
|
|
217
189
|
*/
|
|
218
190
|
export function fromMatch(match) {
|
|
219
191
|
let type;
|
|
@@ -240,9 +212,7 @@ export function fromMatch(match) {
|
|
|
240
212
|
* the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a
|
|
241
213
|
* `content` string.
|
|
242
214
|
*
|
|
243
|
-
* @
|
|
244
|
-
*
|
|
245
|
-
* @return {WPShortcode} Shortcode instance.
|
|
215
|
+
* @type {import('./types').shortcode} Shortcode instance.
|
|
246
216
|
*/
|
|
247
217
|
const shortcode = Object.assign(function (options) {
|
|
248
218
|
const {
|
|
@@ -310,7 +280,7 @@ Object.assign(shortcode.prototype, {
|
|
|
310
280
|
* @param {(number|string)} attr Attribute key.
|
|
311
281
|
* @param {string} value Attribute value.
|
|
312
282
|
*
|
|
313
|
-
* @return {
|
|
283
|
+
* @return {InstanceType< import('./types').shortcode >} Shortcode instance.
|
|
314
284
|
*/
|
|
315
285
|
set(attr, value) {
|
|
316
286
|
this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr] = value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["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","Object","assign","attributes","attributeTypes","length","every","t","key","entries","forEach","value","set","prototype","get","attr","test","name"],"sources":["@wordpress/shortcode/src/index.js"],"sourcesContent":["/**\n * External dependencies\n */\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 | undefined} 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 =\n\t\t/([\\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 = Object.assign(\n\tfunction ( options ) {\n\t\tconst { tag, attrs: attributes, type, content } = options || {};\n\t\tObject.assign( this, { tag, type, content } );\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\tconst attributeTypes = [ 'named', 'numeric' ];\n\n\t\t// Parse a string of attributes.\n\t\tif ( typeof attributes === 'string' ) {\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\tattributes.length === attributeTypes.length &&\n\t\t\tattributeTypes.every( ( t, key ) => t === attributes[ key ] )\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\tObject.entries( attributes ).forEach( ( [ key, value ] ) => {\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\nObject.assign( 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[ typeof attr === 'number' ? 'numeric' : 'named' ][\n\t\t\tattr\n\t\t];\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[ typeof attr === 'number' ? 'numeric' : 'named' ][ attr ] =\n\t\t\tvalue;\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\tthis.attrs.numeric.forEach( ( 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\tObject.entries( this.attrs.named ).forEach( ( [ name, value ] ) => {\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"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,MAAM,MAAM,QAAQ;;AAE3B;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,IAAIA,CAAEC,GAAG,EAAEC,IAAI,EAAEC,KAAK,GAAG,CAAC,EAAG;EAC5C,MAAMC,EAAE,GAAGC,MAAM,CAAE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IACA,IAAK,QAAQ,KAAK,IAAI,CAACX,IAAI,EAAG;MAC7B,OAAO7B,IAAI,GAAG,GAAG;IAClB,CAAC,MAAM,IAAK,cAAc,KAAK,IAAI,CAAC6B,IAAI,EAAG;MAC1C,OAAO7B,IAAI,GAAG,KAAK;IACpB;;IAEA;IACAA,IAAI,IAAI,GAAG;IAEX,IAAK,IAAI,CAACQ,OAAO,EAAG;MACnBR,IAAI,IAAI,IAAI,CAACQ,OAAO;IACrB;;IAEA;IACA,OAAOR,IAAI,GAAG,IAAI,GAAG,IAAI,CAACD,GAAG,GAAG,GAAG;EACpC;AACD,CAAE,CAAC;AAEH,eAAeU,SAAS","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["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","Object","assign","attributes","attributeTypes","length","every","t","key","entries","forEach","value","set","prototype","get","attr","test","name"],"sources":["@wordpress/shortcode/src/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport memize from 'memize';\n\nexport * from './types';\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 {import('./types').ShortcodeMatch | undefined} 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 {import('./types').ReplaceCallback} 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 {import('./types').ShortcodeAttrs} 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 =\n\t\t/([\\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 {import('./types').Match} match Match array.\n *\n * @return {InstanceType<import('./types').shortcode>} 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 * @type {import('./types').shortcode} Shortcode instance.\n */\nconst shortcode = Object.assign(\n\tfunction ( options ) {\n\t\tconst { tag, attrs: attributes, type, content } = options || {};\n\t\tObject.assign( this, { tag, type, content } );\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\tconst attributeTypes = [ 'named', 'numeric' ];\n\n\t\t// Parse a string of attributes.\n\t\tif ( typeof attributes === 'string' ) {\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\tattributes.length === attributeTypes.length &&\n\t\t\tattributeTypes.every( ( t, key ) => t === attributes[ key ] )\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\tObject.entries( attributes ).forEach( ( [ key, value ] ) => {\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\nObject.assign( 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[ typeof attr === 'number' ? 'numeric' : 'named' ][\n\t\t\tattr\n\t\t];\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 {InstanceType< import('./types').shortcode >} Shortcode instance.\n\t */\n\tset( attr, value ) {\n\t\tthis.attrs[ typeof attr === 'number' ? 'numeric' : 'named' ][ attr ] =\n\t\t\tvalue;\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\tthis.attrs.numeric.forEach( ( 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\tObject.entries( this.attrs.named ).forEach( ( [ name, value ] ) => {\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"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,MAAM,MAAM,QAAQ;AAE3B,cAAc,SAAS;;AAEvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,IAAIA,CAAEC,GAAG,EAAEC,IAAI,EAAEC,KAAK,GAAG,CAAC,EAAG;EAC5C,MAAMC,EAAE,GAAGC,MAAM,CAAEJ,GAAI,CAAC;EAExBG,EAAE,CAACE,SAAS,GAAGH,KAAK;EAEpB,MAAMI,KAAK,GAAGH,EAAE,CAACI,IAAI,CAAEN,IAAK,CAAC;EAE7B,IAAK,CAAEK,KAAK,EAAG;IACd;EACD;;EAEA;EACA,IAAK,GAAG,KAAKA,KAAK,CAAE,CAAC,CAAE,IAAI,GAAG,KAAKA,KAAK,CAAE,CAAC,CAAE,EAAG;IAC/C,OAAOP,IAAI,CAAEC,GAAG,EAAEC,IAAI,EAAEE,EAAE,CAACE,SAAU,CAAC;EACvC;EAEA,MAAMG,MAAM,GAAG;IACdN,KAAK,EAAEI,KAAK,CAACJ,KAAK;IAClBO,OAAO,EAAEH,KAAK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|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/shortcode/src/types.ts"],"sourcesContent":["/**\n * Shortcode attributes object.\n */\nexport type ShortcodeAttrs = {\n\t/**\n\t * Object with named attributes.\n\t */\n\tnamed: Record< string, string | undefined >;\n\n\t/**\n\t * Array with numeric attributes.\n\t */\n\tnumeric: string[];\n};\n\nexport type ShortcodeMatch = {\n\t/**\n\t * Index the shortcode is found at.\n\t */\n\tindex: number;\n\n\t/**\n\t * Matched content.\n\t */\n\tcontent: string;\n\n\t/**\n\t * Shortcode instance of the match.\n\t */\n\tshortcode: Shortcode;\n};\n\n/**\n * Shortcode options.\n */\nexport interface ShortcodeOptions {\n\t/**\n\t * Shortcode tag.\n\t */\n\ttag: string;\n\n\t/**\n\t * Shortcode attributes.\n\t */\n\tattrs?: Partial< ShortcodeAttrs > | string;\n\n\t/**\n\t * Shortcode content.\n\t */\n\tcontent?: string;\n\n\t/**\n\t * Shortcode type: `self-closing`, `closed`, or `single`.\n\t */\n\ttype?: 'self-closing' | 'closed' | 'single';\n}\n\n/**\n * Shortcode object.\n */\nexport interface Shortcode extends ShortcodeOptions {\n\t/**\n\t * Shortcode attributes.\n\t */\n\tattrs: ShortcodeAttrs;\n}\n\nexport type Match =\n\t| NonNullable< ReturnType< RegExp[ 'exec' ] > >\n\t| Array< string >;\n\nexport type ReplaceCallback = ( shortcode: Shortcode ) => string;\n\n/**\n * WordPress Shortcode instance.\n */\nexport interface shortcode {\n\tnew ( options: Partial< ShortcodeOptions > ): Shortcode & {\n\t\t/**\n\t\t * Transform the shortcode into a string.\n\t\t *\n\t\t * @return {string} String representation of the shortcode.\n\t\t */\n\t\tstring: () => string;\n\n\t\t/**\n\t\t * Get a shortcode attribute.\n\t\t *\n\t\t * Automatically detects whether `attr` is named or numeric and routes it\n\t\t * accordingly.\n\t\t *\n\t\t * @param {(number|string)} attr Attribute key.\n\t\t *\n\t\t * @return {string} Attribute value.\n\t\t */\n\t\tget: ( attr: string | number ) => string | undefined;\n\n\t\t/**\n\t\t * Set a shortcode attribute.\n\t\t *\n\t\t * Automatically detects whether `attr` is named or numeric and routes it\n\t\t * accordingly.\n\t\t *\n\t\t * @param {(number|string)} attr Attribute key.\n\t\t * @param {string} value Attribute value.\n\t\t *\n\t\t * @return {InstanceType< shortcode >} Shortcode instance.\n\t\t */\n\t\tset: (\n\t\t\tattr: string | number,\n\t\t\tvalue: string\n\t\t) => InstanceType< shortcode >;\n\t};\n\n\t/**\n\t * Parse shortcode attributes.\n\t *\n\t * Shortcodes accept many types of attributes. These can chiefly be divided into\n\t * named and numeric attributes:\n\t *\n\t * Named attributes are assigned on a key/value basis, while numeric attributes\n\t * are treated as an array.\n\t *\n\t * Named attributes can be formatted as either `name=\"value\"`, `name='value'`,\n\t * or `name=value`. Numeric attributes can be formatted as `\"value\"` or just\n\t * `value`.\n\t *\n\t * @param text Serialised shortcode attributes.\n\t *\n\t * @return Parsed shortcode attributes.\n\t */\n\tattrs: ( text: string ) => ShortcodeAttrs;\n\n\t/**\n\t * Generate a Shortcode Object from a RegExp match.\n\t *\n\t * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated\n\t * by `regexp()`. `match` can also be set to the `arguments` from a callback\n\t * passed to `regexp.replace()`.\n\t *\n\t * @param match Match array.\n\t *\n\t * @return Shortcode instance.\n\t */\n\tfromMatch: ( match: Match ) => InstanceType< shortcode >;\n\n\t/**\n\t * Find the next matching shortcode.\n\t *\n\t * @param tag Shortcode tag.\n\t * @param text Text to search.\n\t * @param index Index to start search from.\n\t *\n\t * @return Matched information.\n\t */\n\tnext: (\n\t\ttag: string,\n\t\ttext: string,\n\t\tindex?: number\n\t) => ShortcodeMatch | undefined;\n\n\t/**\n\t * Generate a RegExp to identify a shortcode.\n\t *\n\t * The base regex is functionally equivalent to the one found in\n\t * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.\n\t *\n\t * Capture groups:\n\t *\n\t * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`\n\t * 2. The shortcode name\n\t * 3. The shortcode argument list\n\t * 4. The self closing `/`\n\t * 5. The content of a shortcode when it wraps some content.\n\t * 6. The closing tag.\n\t * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`\n\t *\n\t * @param tag Shortcode tag.\n\t *\n\t * @return Shortcode RegExp.\n\t */\n\tregexp: ( tag: string ) => RegExp;\n\n\t/**\n\t * Replace matching shortcodes in a block of text.\n\t *\n\t * @param tag Shortcode tag.\n\t * @param text Text to search.\n\t * @param callback Function to process the match and return\n\t * replacement string.\n\t *\n\t * @return Text with shortcodes replaced.\n\t */\n\treplace: ( tag: string, text: string, callback: ReplaceCallback ) => string;\n\n\t/**\n\t * Generate a string from shortcode parameters.\n\t *\n\t * Creates a shortcode instance and returns a string.\n\t *\n\t * Accepts the same `options` as the `shortcode()` constructor, containing a\n\t * `tag` string, a string or object of `attrs`, a boolean indicating whether to\n\t * format the shortcode using a `single` tag, and a `content` string.\n\t *\n\t * @param options\n\t *\n\t * @return String representation of the shortcode.\n\t */\n\tstring: ( options: ShortcodeOptions ) => string;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find the next matching shortcode.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} tag Shortcode tag.
|
|
5
|
+
* @param {string} text Text to search.
|
|
6
|
+
* @param {number} index Index to start search from.
|
|
7
|
+
*
|
|
8
|
+
* @return {import('./types').ShortcodeMatch | undefined} Matched information.
|
|
9
|
+
*/
|
|
10
|
+
export function next(tag: string, text: string, index?: number): import("./types").ShortcodeMatch | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Replace matching shortcodes in a block of text.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} tag Shortcode tag.
|
|
15
|
+
* @param {string} text Text to search.
|
|
16
|
+
* @param {import('./types').ReplaceCallback} callback Function to process the match and return
|
|
17
|
+
* replacement string.
|
|
18
|
+
*
|
|
19
|
+
* @return {string} Text with shortcodes replaced.
|
|
20
|
+
*/
|
|
21
|
+
export function replace(tag: string, text: string, callback: import("./types").ReplaceCallback): string;
|
|
22
|
+
/**
|
|
23
|
+
* Generate a string from shortcode parameters.
|
|
24
|
+
*
|
|
25
|
+
* Creates a shortcode instance and returns a string.
|
|
26
|
+
*
|
|
27
|
+
* Accepts the same `options` as the `shortcode()` constructor, containing a
|
|
28
|
+
* `tag` string, a string or object of `attrs`, a boolean indicating whether to
|
|
29
|
+
* format the shortcode using a `single` tag, and a `content` string.
|
|
30
|
+
*
|
|
31
|
+
* @param {Object} options
|
|
32
|
+
*
|
|
33
|
+
* @return {string} String representation of the shortcode.
|
|
34
|
+
*/
|
|
35
|
+
export function string(options: Object): string;
|
|
36
|
+
/**
|
|
37
|
+
* Generate a RegExp to identify a shortcode.
|
|
38
|
+
*
|
|
39
|
+
* The base regex is functionally equivalent to the one found in
|
|
40
|
+
* `get_shortcode_regex()` in `wp-includes/shortcodes.php`.
|
|
41
|
+
*
|
|
42
|
+
* Capture groups:
|
|
43
|
+
*
|
|
44
|
+
* 1. An extra `[` to allow for escaping shortcodes with double `[[]]`
|
|
45
|
+
* 2. The shortcode name
|
|
46
|
+
* 3. The shortcode argument list
|
|
47
|
+
* 4. The self closing `/`
|
|
48
|
+
* 5. The content of a shortcode when it wraps some content.
|
|
49
|
+
* 6. The closing tag.
|
|
50
|
+
* 7. An extra `]` to allow for escaping shortcodes with double `[[]]`
|
|
51
|
+
*
|
|
52
|
+
* @param {string} tag Shortcode tag.
|
|
53
|
+
*
|
|
54
|
+
* @return {RegExp} Shortcode RegExp.
|
|
55
|
+
*/
|
|
56
|
+
export function regexp(tag: string): RegExp;
|
|
57
|
+
/**
|
|
58
|
+
* Generate a Shortcode Object from a RegExp match.
|
|
59
|
+
*
|
|
60
|
+
* Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated
|
|
61
|
+
* by `regexp()`. `match` can also be set to the `arguments` from a callback
|
|
62
|
+
* passed to `regexp.replace()`.
|
|
63
|
+
*
|
|
64
|
+
* @param {import('./types').Match} match Match array.
|
|
65
|
+
*
|
|
66
|
+
* @return {InstanceType<import('./types').shortcode>} Shortcode instance.
|
|
67
|
+
*/
|
|
68
|
+
export function fromMatch(match: import("./types").Match): InstanceType<import("./types").shortcode>;
|
|
69
|
+
export * from "./types";
|
|
70
|
+
/**
|
|
71
|
+
* Parse shortcode attributes.
|
|
72
|
+
*
|
|
73
|
+
* Shortcodes accept many types of attributes. These can chiefly be divided into
|
|
74
|
+
* named and numeric attributes:
|
|
75
|
+
*
|
|
76
|
+
* Named attributes are assigned on a key/value basis, while numeric attributes
|
|
77
|
+
* are treated as an array.
|
|
78
|
+
*
|
|
79
|
+
* Named attributes can be formatted as either `name="value"`, `name='value'`,
|
|
80
|
+
* or `name=value`. Numeric attributes can be formatted as `"value"` or just
|
|
81
|
+
* `value`.
|
|
82
|
+
*
|
|
83
|
+
* @param {string} text Serialised shortcode attributes.
|
|
84
|
+
*
|
|
85
|
+
* @return {import('./types').ShortcodeAttrs} Parsed shortcode attributes.
|
|
86
|
+
*/
|
|
87
|
+
export const attrs: ((text?: any) => ReturnType<(text: any) => {
|
|
88
|
+
named: {};
|
|
89
|
+
numeric: string[];
|
|
90
|
+
}>) & import("memize").MemizeMemoizedFunction;
|
|
91
|
+
export default shortcode;
|
|
92
|
+
/**
|
|
93
|
+
* Creates a shortcode instance.
|
|
94
|
+
*
|
|
95
|
+
* To access a raw representation of a shortcode, pass an `options` object,
|
|
96
|
+
* containing a `tag` string, a string or object of `attrs`, a string indicating
|
|
97
|
+
* the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a
|
|
98
|
+
* `content` string.
|
|
99
|
+
*
|
|
100
|
+
* @type {import('./types').shortcode} Shortcode instance.
|
|
101
|
+
*/
|
|
102
|
+
declare const shortcode: import("./types").shortcode;
|
|
103
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;AACH,0BANW,MAAM,QACN,MAAM,UACN,MAAM,GAEL,OAAO,SAAS,EAAE,cAAc,GAAG,SAAS,CAqCvD;AAED;;;;;;;;;GASG;AACH,6BAPW,MAAM,QACN,MAAM,YACN,OAAO,SAAS,EAAE,eAAe,GAGhC,MAAM,CAoBjB;AAED;;;;;;;;;;;;GAYG;AACH,gCAJW,MAAM,GAEL,MAAM,CAIjB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4BAJW,MAAM,GAEL,MAAM,CASjB;AAiED;;;;;;;;;;GAUG;AACH,iCAJW,OAAO,SAAS,EAAE,KAAK,GAEtB,YAAY,CAAC,OAAO,SAAS,EAAE,SAAS,CAAC,CAmBpD;;AA3FD;;;;;;;;;;;;;;;;GAgBG;AACH;;;8CA4CI;;AAgCJ;;;;;;;;;GASG;AACH,yBAFU,OAAO,SAAS,EAAE,SAAS,CA2CnC"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shortcode attributes object.
|
|
3
|
+
*/
|
|
4
|
+
export type ShortcodeAttrs = {
|
|
5
|
+
/**
|
|
6
|
+
* Object with named attributes.
|
|
7
|
+
*/
|
|
8
|
+
named: Record<string, string | undefined>;
|
|
9
|
+
/**
|
|
10
|
+
* Array with numeric attributes.
|
|
11
|
+
*/
|
|
12
|
+
numeric: string[];
|
|
13
|
+
};
|
|
14
|
+
export type ShortcodeMatch = {
|
|
15
|
+
/**
|
|
16
|
+
* Index the shortcode is found at.
|
|
17
|
+
*/
|
|
18
|
+
index: number;
|
|
19
|
+
/**
|
|
20
|
+
* Matched content.
|
|
21
|
+
*/
|
|
22
|
+
content: string;
|
|
23
|
+
/**
|
|
24
|
+
* Shortcode instance of the match.
|
|
25
|
+
*/
|
|
26
|
+
shortcode: Shortcode;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Shortcode options.
|
|
30
|
+
*/
|
|
31
|
+
export interface ShortcodeOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Shortcode tag.
|
|
34
|
+
*/
|
|
35
|
+
tag: string;
|
|
36
|
+
/**
|
|
37
|
+
* Shortcode attributes.
|
|
38
|
+
*/
|
|
39
|
+
attrs?: Partial<ShortcodeAttrs> | string;
|
|
40
|
+
/**
|
|
41
|
+
* Shortcode content.
|
|
42
|
+
*/
|
|
43
|
+
content?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Shortcode type: `self-closing`, `closed`, or `single`.
|
|
46
|
+
*/
|
|
47
|
+
type?: 'self-closing' | 'closed' | 'single';
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Shortcode object.
|
|
51
|
+
*/
|
|
52
|
+
export interface Shortcode extends ShortcodeOptions {
|
|
53
|
+
/**
|
|
54
|
+
* Shortcode attributes.
|
|
55
|
+
*/
|
|
56
|
+
attrs: ShortcodeAttrs;
|
|
57
|
+
}
|
|
58
|
+
export type Match = NonNullable<ReturnType<RegExp['exec']>> | Array<string>;
|
|
59
|
+
export type ReplaceCallback = (shortcode: Shortcode) => string;
|
|
60
|
+
/**
|
|
61
|
+
* WordPress Shortcode instance.
|
|
62
|
+
*/
|
|
63
|
+
export interface shortcode {
|
|
64
|
+
new (options: Partial<ShortcodeOptions>): Shortcode & {
|
|
65
|
+
/**
|
|
66
|
+
* Transform the shortcode into a string.
|
|
67
|
+
*
|
|
68
|
+
* @return {string} String representation of the shortcode.
|
|
69
|
+
*/
|
|
70
|
+
string: () => string;
|
|
71
|
+
/**
|
|
72
|
+
* Get a shortcode attribute.
|
|
73
|
+
*
|
|
74
|
+
* Automatically detects whether `attr` is named or numeric and routes it
|
|
75
|
+
* accordingly.
|
|
76
|
+
*
|
|
77
|
+
* @param {(number|string)} attr Attribute key.
|
|
78
|
+
*
|
|
79
|
+
* @return {string} Attribute value.
|
|
80
|
+
*/
|
|
81
|
+
get: (attr: string | number) => string | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Set a shortcode attribute.
|
|
84
|
+
*
|
|
85
|
+
* Automatically detects whether `attr` is named or numeric and routes it
|
|
86
|
+
* accordingly.
|
|
87
|
+
*
|
|
88
|
+
* @param {(number|string)} attr Attribute key.
|
|
89
|
+
* @param {string} value Attribute value.
|
|
90
|
+
*
|
|
91
|
+
* @return {InstanceType< shortcode >} Shortcode instance.
|
|
92
|
+
*/
|
|
93
|
+
set: (attr: string | number, value: string) => InstanceType<shortcode>;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Parse shortcode attributes.
|
|
97
|
+
*
|
|
98
|
+
* Shortcodes accept many types of attributes. These can chiefly be divided into
|
|
99
|
+
* named and numeric attributes:
|
|
100
|
+
*
|
|
101
|
+
* Named attributes are assigned on a key/value basis, while numeric attributes
|
|
102
|
+
* are treated as an array.
|
|
103
|
+
*
|
|
104
|
+
* Named attributes can be formatted as either `name="value"`, `name='value'`,
|
|
105
|
+
* or `name=value`. Numeric attributes can be formatted as `"value"` or just
|
|
106
|
+
* `value`.
|
|
107
|
+
*
|
|
108
|
+
* @param text Serialised shortcode attributes.
|
|
109
|
+
*
|
|
110
|
+
* @return Parsed shortcode attributes.
|
|
111
|
+
*/
|
|
112
|
+
attrs: (text: string) => ShortcodeAttrs;
|
|
113
|
+
/**
|
|
114
|
+
* Generate a Shortcode Object from a RegExp match.
|
|
115
|
+
*
|
|
116
|
+
* Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated
|
|
117
|
+
* by `regexp()`. `match` can also be set to the `arguments` from a callback
|
|
118
|
+
* passed to `regexp.replace()`.
|
|
119
|
+
*
|
|
120
|
+
* @param match Match array.
|
|
121
|
+
*
|
|
122
|
+
* @return Shortcode instance.
|
|
123
|
+
*/
|
|
124
|
+
fromMatch: (match: Match) => InstanceType<shortcode>;
|
|
125
|
+
/**
|
|
126
|
+
* Find the next matching shortcode.
|
|
127
|
+
*
|
|
128
|
+
* @param tag Shortcode tag.
|
|
129
|
+
* @param text Text to search.
|
|
130
|
+
* @param index Index to start search from.
|
|
131
|
+
*
|
|
132
|
+
* @return Matched information.
|
|
133
|
+
*/
|
|
134
|
+
next: (tag: string, text: string, index?: number) => ShortcodeMatch | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Generate a RegExp to identify a shortcode.
|
|
137
|
+
*
|
|
138
|
+
* The base regex is functionally equivalent to the one found in
|
|
139
|
+
* `get_shortcode_regex()` in `wp-includes/shortcodes.php`.
|
|
140
|
+
*
|
|
141
|
+
* Capture groups:
|
|
142
|
+
*
|
|
143
|
+
* 1. An extra `[` to allow for escaping shortcodes with double `[[]]`
|
|
144
|
+
* 2. The shortcode name
|
|
145
|
+
* 3. The shortcode argument list
|
|
146
|
+
* 4. The self closing `/`
|
|
147
|
+
* 5. The content of a shortcode when it wraps some content.
|
|
148
|
+
* 6. The closing tag.
|
|
149
|
+
* 7. An extra `]` to allow for escaping shortcodes with double `[[]]`
|
|
150
|
+
*
|
|
151
|
+
* @param tag Shortcode tag.
|
|
152
|
+
*
|
|
153
|
+
* @return Shortcode RegExp.
|
|
154
|
+
*/
|
|
155
|
+
regexp: (tag: string) => RegExp;
|
|
156
|
+
/**
|
|
157
|
+
* Replace matching shortcodes in a block of text.
|
|
158
|
+
*
|
|
159
|
+
* @param tag Shortcode tag.
|
|
160
|
+
* @param text Text to search.
|
|
161
|
+
* @param callback Function to process the match and return
|
|
162
|
+
* replacement string.
|
|
163
|
+
*
|
|
164
|
+
* @return Text with shortcodes replaced.
|
|
165
|
+
*/
|
|
166
|
+
replace: (tag: string, text: string, callback: ReplaceCallback) => string;
|
|
167
|
+
/**
|
|
168
|
+
* Generate a string from shortcode parameters.
|
|
169
|
+
*
|
|
170
|
+
* Creates a shortcode instance and returns a string.
|
|
171
|
+
*
|
|
172
|
+
* Accepts the same `options` as the `shortcode()` constructor, containing a
|
|
173
|
+
* `tag` string, a string or object of `attrs`, a boolean indicating whether to
|
|
174
|
+
* format the shortcode using a `single` tag, and a `content` string.
|
|
175
|
+
*
|
|
176
|
+
* @param options
|
|
177
|
+
*
|
|
178
|
+
* @return String representation of the shortcode.
|
|
179
|
+
*/
|
|
180
|
+
string: (options: ShortcodeOptions) => string;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC5B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAAE,CAAC;IAE5C;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC5B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAE,cAAc,CAAE,GAAG,MAAM,CAAC;IAE3C;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,CAAC,EAAE,cAAc,GAAG,QAAQ,GAAG,QAAQ,CAAC;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,SAAU,SAAQ,gBAAgB;IAClD;;OAEG;IACH,KAAK,EAAE,cAAc,CAAC;CACtB;AAED,MAAM,MAAM,KAAK,GACd,WAAW,CAAE,UAAU,CAAE,MAAM,CAAE,MAAM,CAAE,CAAE,CAAE,GAC7C,KAAK,CAAE,MAAM,CAAE,CAAC;AAEnB,MAAM,MAAM,eAAe,GAAG,CAAE,SAAS,EAAE,SAAS,KAAM,MAAM,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,KAAM,OAAO,EAAE,OAAO,CAAE,gBAAgB,CAAE,GAAI,SAAS,GAAG;QACzD;;;;WAIG;QACH,MAAM,EAAE,MAAM,MAAM,CAAC;QAErB;;;;;;;;;WASG;QACH,GAAG,EAAE,CAAE,IAAI,EAAE,MAAM,GAAG,MAAM,KAAM,MAAM,GAAG,SAAS,CAAC;QAErD;;;;;;;;;;WAUG;QACH,GAAG,EAAE,CACJ,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,KAAK,EAAE,MAAM,KACT,YAAY,CAAE,SAAS,CAAE,CAAC;KAC/B,CAAC;IAEF;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,EAAE,CAAE,IAAI,EAAE,MAAM,KAAM,cAAc,CAAC;IAE1C;;;;;;;;;;OAUG;IACH,SAAS,EAAE,CAAE,KAAK,EAAE,KAAK,KAAM,YAAY,CAAE,SAAS,CAAE,CAAC;IAEzD;;;;;;;;OAQG;IACH,IAAI,EAAE,CACL,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,KACV,cAAc,GAAG,SAAS,CAAC;IAEhC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,EAAE,CAAE,GAAG,EAAE,MAAM,KAAM,MAAM,CAAC;IAElC;;;;;;;;;OASG;IACH,OAAO,EAAE,CAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,KAAM,MAAM,CAAC;IAE5E;;;;;;;;;;;;OAYG;IACH,MAAM,EAAE,CAAE,OAAO,EAAE,gBAAgB,KAAM,MAAM,CAAC;CAChD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/shortcode",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.1-next.cd6172eb0.0",
|
|
4
4
|
"description": "Shortcode module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"module": "build-module/index.js",
|
|
27
27
|
"react-native": "src/index",
|
|
28
28
|
"wpScript": true,
|
|
29
|
+
"types": "build-types",
|
|
29
30
|
"dependencies": {
|
|
30
31
|
"@babel/runtime": "7.25.7",
|
|
31
32
|
"memize": "^2.0.1"
|
|
@@ -33,5 +34,5 @@
|
|
|
33
34
|
"publishConfig": {
|
|
34
35
|
"access": "public"
|
|
35
36
|
},
|
|
36
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "4cc93dc1781d8a7bc2bbde265913917920e2bd45"
|
|
37
38
|
}
|
package/src/index.js
CHANGED
|
@@ -3,34 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import memize from 'memize';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
* Shortcode attributes object.
|
|
8
|
-
*
|
|
9
|
-
* @typedef {Object} WPShortcodeAttrs
|
|
10
|
-
*
|
|
11
|
-
* @property {Object} named Object with named attributes.
|
|
12
|
-
* @property {Array} numeric Array with numeric attributes.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Shortcode object.
|
|
17
|
-
*
|
|
18
|
-
* @typedef {Object} WPShortcode
|
|
19
|
-
*
|
|
20
|
-
* @property {string} tag Shortcode tag.
|
|
21
|
-
* @property {WPShortcodeAttrs} attrs Shortcode attributes.
|
|
22
|
-
* @property {string} content Shortcode content.
|
|
23
|
-
* @property {string} type Shortcode type: `self-closing`,
|
|
24
|
-
* `closed`, or `single`.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @typedef {Object} WPShortcodeMatch
|
|
29
|
-
*
|
|
30
|
-
* @property {number} index Index the shortcode is found at.
|
|
31
|
-
* @property {string} content Matched content.
|
|
32
|
-
* @property {WPShortcode} shortcode Shortcode instance of the match.
|
|
33
|
-
*/
|
|
6
|
+
export * from './types';
|
|
34
7
|
|
|
35
8
|
/**
|
|
36
9
|
* Find the next matching shortcode.
|
|
@@ -39,7 +12,7 @@ import memize from 'memize';
|
|
|
39
12
|
* @param {string} text Text to search.
|
|
40
13
|
* @param {number} index Index to start search from.
|
|
41
14
|
*
|
|
42
|
-
* @return {
|
|
15
|
+
* @return {import('./types').ShortcodeMatch | undefined} Matched information.
|
|
43
16
|
*/
|
|
44
17
|
export function next( tag, text, index = 0 ) {
|
|
45
18
|
const re = regexp( tag );
|
|
@@ -81,10 +54,10 @@ export function next( tag, text, index = 0 ) {
|
|
|
81
54
|
/**
|
|
82
55
|
* Replace matching shortcodes in a block of text.
|
|
83
56
|
*
|
|
84
|
-
* @param {string}
|
|
85
|
-
* @param {string}
|
|
86
|
-
* @param {
|
|
87
|
-
*
|
|
57
|
+
* @param {string} tag Shortcode tag.
|
|
58
|
+
* @param {string} text Text to search.
|
|
59
|
+
* @param {import('./types').ReplaceCallback} callback Function to process the match and return
|
|
60
|
+
* replacement string.
|
|
88
61
|
*
|
|
89
62
|
* @return {string} Text with shortcodes replaced.
|
|
90
63
|
*/
|
|
@@ -169,7 +142,7 @@ export function regexp( tag ) {
|
|
|
169
142
|
*
|
|
170
143
|
* @param {string} text Serialised shortcode attributes.
|
|
171
144
|
*
|
|
172
|
-
* @return {
|
|
145
|
+
* @return {import('./types').ShortcodeAttrs} Parsed shortcode attributes.
|
|
173
146
|
*/
|
|
174
147
|
export const attrs = memize( ( text ) => {
|
|
175
148
|
const named = {};
|
|
@@ -224,9 +197,9 @@ export const attrs = memize( ( text ) => {
|
|
|
224
197
|
* by `regexp()`. `match` can also be set to the `arguments` from a callback
|
|
225
198
|
* passed to `regexp.replace()`.
|
|
226
199
|
*
|
|
227
|
-
* @param {
|
|
200
|
+
* @param {import('./types').Match} match Match array.
|
|
228
201
|
*
|
|
229
|
-
* @return {
|
|
202
|
+
* @return {InstanceType<import('./types').shortcode>} Shortcode instance.
|
|
230
203
|
*/
|
|
231
204
|
export function fromMatch( match ) {
|
|
232
205
|
let type;
|
|
@@ -255,9 +228,7 @@ export function fromMatch( match ) {
|
|
|
255
228
|
* the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a
|
|
256
229
|
* `content` string.
|
|
257
230
|
*
|
|
258
|
-
* @
|
|
259
|
-
*
|
|
260
|
-
* @return {WPShortcode} Shortcode instance.
|
|
231
|
+
* @type {import('./types').shortcode} Shortcode instance.
|
|
261
232
|
*/
|
|
262
233
|
const shortcode = Object.assign(
|
|
263
234
|
function ( options ) {
|
|
@@ -328,7 +299,7 @@ Object.assign( shortcode.prototype, {
|
|
|
328
299
|
* @param {(number|string)} attr Attribute key.
|
|
329
300
|
* @param {string} value Attribute value.
|
|
330
301
|
*
|
|
331
|
-
* @return {
|
|
302
|
+
* @return {InstanceType< import('./types').shortcode >} Shortcode instance.
|
|
332
303
|
*/
|
|
333
304
|
set( attr, value ) {
|
|
334
305
|
this.attrs[ typeof attr === 'number' ? 'numeric' : 'named' ][ attr ] =
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shortcode attributes object.
|
|
3
|
+
*/
|
|
4
|
+
export type ShortcodeAttrs = {
|
|
5
|
+
/**
|
|
6
|
+
* Object with named attributes.
|
|
7
|
+
*/
|
|
8
|
+
named: Record< string, string | undefined >;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Array with numeric attributes.
|
|
12
|
+
*/
|
|
13
|
+
numeric: string[];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type ShortcodeMatch = {
|
|
17
|
+
/**
|
|
18
|
+
* Index the shortcode is found at.
|
|
19
|
+
*/
|
|
20
|
+
index: number;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Matched content.
|
|
24
|
+
*/
|
|
25
|
+
content: string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Shortcode instance of the match.
|
|
29
|
+
*/
|
|
30
|
+
shortcode: Shortcode;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Shortcode options.
|
|
35
|
+
*/
|
|
36
|
+
export interface ShortcodeOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Shortcode tag.
|
|
39
|
+
*/
|
|
40
|
+
tag: string;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Shortcode attributes.
|
|
44
|
+
*/
|
|
45
|
+
attrs?: Partial< ShortcodeAttrs > | string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Shortcode content.
|
|
49
|
+
*/
|
|
50
|
+
content?: string;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Shortcode type: `self-closing`, `closed`, or `single`.
|
|
54
|
+
*/
|
|
55
|
+
type?: 'self-closing' | 'closed' | 'single';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Shortcode object.
|
|
60
|
+
*/
|
|
61
|
+
export interface Shortcode extends ShortcodeOptions {
|
|
62
|
+
/**
|
|
63
|
+
* Shortcode attributes.
|
|
64
|
+
*/
|
|
65
|
+
attrs: ShortcodeAttrs;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type Match =
|
|
69
|
+
| NonNullable< ReturnType< RegExp[ 'exec' ] > >
|
|
70
|
+
| Array< string >;
|
|
71
|
+
|
|
72
|
+
export type ReplaceCallback = ( shortcode: Shortcode ) => string;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* WordPress Shortcode instance.
|
|
76
|
+
*/
|
|
77
|
+
export interface shortcode {
|
|
78
|
+
new ( options: Partial< ShortcodeOptions > ): Shortcode & {
|
|
79
|
+
/**
|
|
80
|
+
* Transform the shortcode into a string.
|
|
81
|
+
*
|
|
82
|
+
* @return {string} String representation of the shortcode.
|
|
83
|
+
*/
|
|
84
|
+
string: () => string;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get a shortcode attribute.
|
|
88
|
+
*
|
|
89
|
+
* Automatically detects whether `attr` is named or numeric and routes it
|
|
90
|
+
* accordingly.
|
|
91
|
+
*
|
|
92
|
+
* @param {(number|string)} attr Attribute key.
|
|
93
|
+
*
|
|
94
|
+
* @return {string} Attribute value.
|
|
95
|
+
*/
|
|
96
|
+
get: ( attr: string | number ) => string | undefined;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Set a shortcode attribute.
|
|
100
|
+
*
|
|
101
|
+
* Automatically detects whether `attr` is named or numeric and routes it
|
|
102
|
+
* accordingly.
|
|
103
|
+
*
|
|
104
|
+
* @param {(number|string)} attr Attribute key.
|
|
105
|
+
* @param {string} value Attribute value.
|
|
106
|
+
*
|
|
107
|
+
* @return {InstanceType< shortcode >} Shortcode instance.
|
|
108
|
+
*/
|
|
109
|
+
set: (
|
|
110
|
+
attr: string | number,
|
|
111
|
+
value: string
|
|
112
|
+
) => InstanceType< shortcode >;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Parse shortcode attributes.
|
|
117
|
+
*
|
|
118
|
+
* Shortcodes accept many types of attributes. These can chiefly be divided into
|
|
119
|
+
* named and numeric attributes:
|
|
120
|
+
*
|
|
121
|
+
* Named attributes are assigned on a key/value basis, while numeric attributes
|
|
122
|
+
* are treated as an array.
|
|
123
|
+
*
|
|
124
|
+
* Named attributes can be formatted as either `name="value"`, `name='value'`,
|
|
125
|
+
* or `name=value`. Numeric attributes can be formatted as `"value"` or just
|
|
126
|
+
* `value`.
|
|
127
|
+
*
|
|
128
|
+
* @param text Serialised shortcode attributes.
|
|
129
|
+
*
|
|
130
|
+
* @return Parsed shortcode attributes.
|
|
131
|
+
*/
|
|
132
|
+
attrs: ( text: string ) => ShortcodeAttrs;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Generate a Shortcode Object from a RegExp match.
|
|
136
|
+
*
|
|
137
|
+
* Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated
|
|
138
|
+
* by `regexp()`. `match` can also be set to the `arguments` from a callback
|
|
139
|
+
* passed to `regexp.replace()`.
|
|
140
|
+
*
|
|
141
|
+
* @param match Match array.
|
|
142
|
+
*
|
|
143
|
+
* @return Shortcode instance.
|
|
144
|
+
*/
|
|
145
|
+
fromMatch: ( match: Match ) => InstanceType< shortcode >;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Find the next matching shortcode.
|
|
149
|
+
*
|
|
150
|
+
* @param tag Shortcode tag.
|
|
151
|
+
* @param text Text to search.
|
|
152
|
+
* @param index Index to start search from.
|
|
153
|
+
*
|
|
154
|
+
* @return Matched information.
|
|
155
|
+
*/
|
|
156
|
+
next: (
|
|
157
|
+
tag: string,
|
|
158
|
+
text: string,
|
|
159
|
+
index?: number
|
|
160
|
+
) => ShortcodeMatch | undefined;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Generate a RegExp to identify a shortcode.
|
|
164
|
+
*
|
|
165
|
+
* The base regex is functionally equivalent to the one found in
|
|
166
|
+
* `get_shortcode_regex()` in `wp-includes/shortcodes.php`.
|
|
167
|
+
*
|
|
168
|
+
* Capture groups:
|
|
169
|
+
*
|
|
170
|
+
* 1. An extra `[` to allow for escaping shortcodes with double `[[]]`
|
|
171
|
+
* 2. The shortcode name
|
|
172
|
+
* 3. The shortcode argument list
|
|
173
|
+
* 4. The self closing `/`
|
|
174
|
+
* 5. The content of a shortcode when it wraps some content.
|
|
175
|
+
* 6. The closing tag.
|
|
176
|
+
* 7. An extra `]` to allow for escaping shortcodes with double `[[]]`
|
|
177
|
+
*
|
|
178
|
+
* @param tag Shortcode tag.
|
|
179
|
+
*
|
|
180
|
+
* @return Shortcode RegExp.
|
|
181
|
+
*/
|
|
182
|
+
regexp: ( tag: string ) => RegExp;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Replace matching shortcodes in a block of text.
|
|
186
|
+
*
|
|
187
|
+
* @param tag Shortcode tag.
|
|
188
|
+
* @param text Text to search.
|
|
189
|
+
* @param callback Function to process the match and return
|
|
190
|
+
* replacement string.
|
|
191
|
+
*
|
|
192
|
+
* @return Text with shortcodes replaced.
|
|
193
|
+
*/
|
|
194
|
+
replace: ( tag: string, text: string, callback: ReplaceCallback ) => string;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Generate a string from shortcode parameters.
|
|
198
|
+
*
|
|
199
|
+
* Creates a shortcode instance and returns a string.
|
|
200
|
+
*
|
|
201
|
+
* Accepts the same `options` as the `shortcode()` constructor, containing a
|
|
202
|
+
* `tag` string, a string or object of `attrs`, a boolean indicating whether to
|
|
203
|
+
* format the shortcode using a `single` tag, and a `content` string.
|
|
204
|
+
*
|
|
205
|
+
* @param options
|
|
206
|
+
*
|
|
207
|
+
* @return String representation of the shortcode.
|
|
208
|
+
*/
|
|
209
|
+
string: ( options: ShortcodeOptions ) => string;
|
|
210
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"program":{"fileNames":["../../node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/typescript/lib/lib.es2020.d.ts","../../node_modules/typescript/lib/lib.es2021.d.ts","../../node_modules/typescript/lib/lib.es2022.d.ts","../../node_modules/typescript/lib/lib.es2023.d.ts","../../node_modules/typescript/lib/lib.esnext.d.ts","../../node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/typescript/lib/lib.dom.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/typescript/lib/lib.es2016.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.date.d.ts","../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/typescript/lib/lib.es2019.intl.d.ts","../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../node_modules/typescript/lib/lib.es2020.date.d.ts","../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../node_modules/typescript/lib/lib.es2020.number.d.ts","../../node_modules/typescript/lib/lib.es2021.promise.d.ts","../../node_modules/typescript/lib/lib.es2021.string.d.ts","../../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../node_modules/typescript/lib/lib.es2021.intl.d.ts","../../node_modules/typescript/lib/lib.es2022.array.d.ts","../../node_modules/typescript/lib/lib.es2022.error.d.ts","../../node_modules/typescript/lib/lib.es2022.intl.d.ts","../../node_modules/typescript/lib/lib.es2022.object.d.ts","../../node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2022.string.d.ts","../../node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../node_modules/typescript/lib/lib.es2023.array.d.ts","../../node_modules/typescript/lib/lib.es2023.collection.d.ts","../../node_modules/typescript/lib/lib.es2023.intl.d.ts","../../node_modules/typescript/lib/lib.esnext.array.d.ts","../../node_modules/typescript/lib/lib.esnext.collection.d.ts","../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../node_modules/typescript/lib/lib.esnext.disposable.d.ts","../../node_modules/typescript/lib/lib.esnext.string.d.ts","../../node_modules/typescript/lib/lib.esnext.promise.d.ts","../../node_modules/typescript/lib/lib.esnext.decorators.d.ts","../../node_modules/typescript/lib/lib.esnext.object.d.ts","../../node_modules/typescript/lib/lib.esnext.regexp.d.ts","../../node_modules/typescript/lib/lib.decorators.d.ts","../../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../node_modules/memize/dist/index.d.ts","./src/types.ts","./src/index.js"],"fileInfos":[{"version":"44e584d4f6444f58791784f1d530875970993129442a847597db702a073ca68c","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","9a68c0c07ae2fa71b44384a839b7b8d81662a236d4b9ac30916718f7510b1b2d","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc","27bdc30a0e32783366a5abeda841bc22757c1797de8681bbe81fbc735eeb1c10","17edc026abf73c5c2dd508652d63f68ec4efd9d4856e3469890d27598209feb5",{"version":"4af6b0c727b7a2896463d512fafd23634229adf69ac7c00e2ae15a09cb084fad","affectsGlobalScope":true},{"version":"9c00a480825408b6a24c63c1b71362232927247595d7c97659bc24dc68ae0757","affectsGlobalScope":true},{"version":"6920e1448680767498a0b77c6a00a8e77d14d62c3da8967b171f1ddffa3c18e4","affectsGlobalScope":true},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"bc47685641087c015972a3f072480889f0d6c65515f12bd85222f49a98952ed7","affectsGlobalScope":true},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true},{"version":"93495ff27b8746f55d19fcbcdbaccc99fd95f19d057aed1bd2c0cafe1335fbf0","affectsGlobalScope":true},{"version":"6fc23bb8c3965964be8c597310a2878b53a0306edb71d4b5a4dfe760186bcc01","affectsGlobalScope":true},{"version":"ea011c76963fb15ef1cdd7ce6a6808b46322c527de2077b6cfdf23ae6f5f9ec7","affectsGlobalScope":true},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true},{"version":"bb42a7797d996412ecdc5b2787720de477103a0b2e53058569069a0e2bae6c7e","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"b541a838a13f9234aba650a825393ffc2292dc0fc87681a5d81ef0c96d281e7a","affectsGlobalScope":true},{"version":"9e9fbd7030c440b33d021da145d3232984c8bb7916f277e8ffd3dc2e3eae2bdb","affectsGlobalScope":true},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"74f7fa2d027d5b33eb0471c8e82a6c87216223181ec31247c357a3e8e2fddc5b","affectsGlobalScope":true},{"version":"ae37d6ccd1560b0203ab88d46987393adaaa78c919e51acf32fb82c86502e98c","affectsGlobalScope":true},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"5e07ed3809d48205d5b985642a59f2eba47c402374a7cf8006b686f79efadcbd","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"479553e3779be7d4f68e9f40cdb82d038e5ef7592010100410723ceced22a0f7","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"d3d7b04b45033f57351c8434f60b6be1ea71a2dfec2d0a0c3c83badbb0e3e693","affectsGlobalScope":true},{"version":"956d27abdea9652e8368ce029bb1e0b9174e9678a273529f426df4b3d90abd60","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"e6633e05da3ff36e6da2ec170d0d03ccf33de50ca4dc6f5aeecb572cedd162fb","affectsGlobalScope":true},{"version":"d8670852241d4c6e03f2b89d67497a4bbefe29ecaa5a444e2c11a9b05e6fccc6","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"caccc56c72713969e1cfe5c3d44e5bab151544d9d2b373d7dbe5a1e4166652be","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"b4b67b1a91182421f5df999988c690f14d813b9850b40acd06ed44691f6727ad","affectsGlobalScope":true},{"version":"08a58483392df5fcc1db57d782e87734f77ae9eab42516028acbfe46f29a3ef7","affectsGlobalScope":true},{"version":"436aaf437562f276ec2ddbee2f2cdedac7664c1e4c1d2c36839ddd582eeb3d0a","affectsGlobalScope":true},{"version":"8e3c06ea092138bf9fa5e874a1fdbc9d54805d074bee1de31b99a11e2fec239d","affectsGlobalScope":true},{"version":"0b11f3ca66aa33124202c80b70cd203219c3d4460cfc165e0707aa9ec710fc53","affectsGlobalScope":true},{"version":"6a3f5a0129cc80cf439ab71164334d649b47059a4f5afca90282362407d0c87f","affectsGlobalScope":true},{"version":"811c71eee4aa0ac5f7adf713323a5c41b0cf6c4e17367a34fbce379e12bbf0a4","affectsGlobalScope":true},{"version":"15b98a533864d324e5f57cd3cfc0579b231df58c1c0f6063ea0fcb13c3c74ff9","affectsGlobalScope":true},{"version":"0a6282c8827e4b9a95f4bf4f5c205673ada31b982f50572d27103df8ceb8013c","affectsGlobalScope":true},{"version":"ac77cb3e8c6d3565793eb90a8373ee8033146315a3dbead3bde8db5eaf5e5ec6","affectsGlobalScope":true},{"version":"d4b1d2c51d058fc21ec2629fff7a76249dec2e36e12960ea056e3ef89174080f","affectsGlobalScope":true},{"version":"2fef54945a13095fdb9b84f705f2b5994597640c46afeb2ce78352fab4cb3279","affectsGlobalScope":true},{"version":"56e4ed5aab5f5920980066a9409bfaf53e6d21d3f8d020c17e4de584d29600ad","affectsGlobalScope":true},{"version":"33358442698bb565130f52ba79bfd3d4d484ac85fe33f3cb1759c54d18201393","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},"e824690c25b4d469af83e8fe10d15811d06d588c1b31eae795390b98b888dfc3",{"version":"9fa94085ba2e0695a28fe6c6edadb871bea335374b10a4ff8f708a3de0cffc00","signature":"fd492d31cf68be503e92dd112d6c4fba02ba9c2bb8552c0b103bffd583b89bb8"},{"version":"b1cef1e11d6f0c15395449557fafb63ea0f853f1e168b4605127ad2cb2d503f6","signature":"83bdeccf232fb546d0787a06bd837008a0e72f2a215d7334e2bd1070ee50c11a"}],"root":[75,76],"options":{"allowJs":true,"allowSyntheticDefaultImports":true,"checkJs":false,"composite":true,"declaration":true,"declarationDir":"./build-types","declarationMap":true,"emitDeclarationOnly":true,"esModuleInterop":false,"jsx":1,"module":99,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"rootDir":"./src","skipDefaultLibCheck":true,"strict":true,"target":99},"fileIdsList":[[74,75]],"referencedMap":[[76,1]],"latestChangedDtsFile":"./build-types/index.d.ts"},"version":"5.5.3"}
|