@wordpress/shortcode 3.39.0 → 3.40.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 +2 -0
- package/build/index.js +39 -50
- package/build/index.js.map +1 -1
- package/build-module/index.js +40 -42
- package/build-module/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/build/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -11,9 +10,7 @@ exports.next = next;
|
|
|
11
10
|
exports.regexp = regexp;
|
|
12
11
|
exports.replace = replace;
|
|
13
12
|
exports.string = string;
|
|
14
|
-
|
|
15
13
|
var _memize = _interopRequireDefault(require("memize"));
|
|
16
|
-
|
|
17
14
|
/**
|
|
18
15
|
* External dependencies
|
|
19
16
|
*/
|
|
@@ -60,35 +57,34 @@ function next(tag, text, index = 0) {
|
|
|
60
57
|
const re = regexp(tag);
|
|
61
58
|
re.lastIndex = index;
|
|
62
59
|
const match = re.exec(text);
|
|
63
|
-
|
|
64
60
|
if (!match) {
|
|
65
61
|
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
62
|
+
}
|
|
68
63
|
|
|
64
|
+
// If we matched an escaped shortcode, try again.
|
|
69
65
|
if ('[' === match[1] && ']' === match[7]) {
|
|
70
66
|
return next(tag, text, re.lastIndex);
|
|
71
67
|
}
|
|
72
|
-
|
|
73
68
|
const result = {
|
|
74
69
|
index: match.index,
|
|
75
70
|
content: match[0],
|
|
76
71
|
shortcode: fromMatch(match)
|
|
77
|
-
};
|
|
78
|
-
// index accordingly.
|
|
72
|
+
};
|
|
79
73
|
|
|
74
|
+
// If we matched a leading `[`, strip it from the match and increment the
|
|
75
|
+
// index accordingly.
|
|
80
76
|
if (match[1]) {
|
|
81
77
|
result.content = result.content.slice(1);
|
|
82
78
|
result.index++;
|
|
83
|
-
}
|
|
84
|
-
|
|
79
|
+
}
|
|
85
80
|
|
|
81
|
+
// If we matched a trailing `]`, strip it from the match.
|
|
86
82
|
if (match[7]) {
|
|
87
83
|
result.content = result.content.slice(0, -1);
|
|
88
84
|
}
|
|
89
|
-
|
|
90
85
|
return result;
|
|
91
86
|
}
|
|
87
|
+
|
|
92
88
|
/**
|
|
93
89
|
* Replace matching shortcodes in a block of text.
|
|
94
90
|
*
|
|
@@ -99,23 +95,23 @@ function next(tag, text, index = 0) {
|
|
|
99
95
|
*
|
|
100
96
|
* @return {string} Text with shortcodes replaced.
|
|
101
97
|
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
98
|
function replace(tag, text, callback) {
|
|
105
99
|
return text.replace(regexp(tag), function (match, left, $3, attrs, slash, content, closing, right) {
|
|
106
100
|
// If both extra brackets exist, the shortcode has been properly
|
|
107
101
|
// escaped.
|
|
108
102
|
if (left === '[' && right === ']') {
|
|
109
103
|
return match;
|
|
110
|
-
}
|
|
104
|
+
}
|
|
111
105
|
|
|
106
|
+
// Create the match object and pass it through the callback.
|
|
107
|
+
const result = callback(fromMatch(arguments));
|
|
112
108
|
|
|
113
|
-
|
|
109
|
+
// Make sure to return any of the extra brackets if they weren't used to
|
|
114
110
|
// escape the shortcode.
|
|
115
|
-
|
|
116
111
|
return result || result === '' ? left + result + right : match;
|
|
117
112
|
});
|
|
118
113
|
}
|
|
114
|
+
|
|
119
115
|
/**
|
|
120
116
|
* Generate a string from shortcode parameters.
|
|
121
117
|
*
|
|
@@ -129,11 +125,10 @@ function replace(tag, text, callback) {
|
|
|
129
125
|
*
|
|
130
126
|
* @return {string} String representation of the shortcode.
|
|
131
127
|
*/
|
|
132
|
-
|
|
133
|
-
|
|
134
128
|
function string(options) {
|
|
135
129
|
return new shortcode(options).string();
|
|
136
130
|
}
|
|
131
|
+
|
|
137
132
|
/**
|
|
138
133
|
* Generate a RegExp to identify a shortcode.
|
|
139
134
|
*
|
|
@@ -154,11 +149,10 @@ function string(options) {
|
|
|
154
149
|
*
|
|
155
150
|
* @return {RegExp} Shortcode RegExp.
|
|
156
151
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
152
|
function regexp(tag) {
|
|
160
153
|
return new RegExp('\\[(\\[?)(' + tag + ')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)', 'g');
|
|
161
154
|
}
|
|
155
|
+
|
|
162
156
|
/**
|
|
163
157
|
* Parse shortcode attributes.
|
|
164
158
|
*
|
|
@@ -176,11 +170,11 @@ function regexp(tag) {
|
|
|
176
170
|
*
|
|
177
171
|
* @return {WPShortcodeAttrs} Parsed shortcode attributes.
|
|
178
172
|
*/
|
|
179
|
-
|
|
180
|
-
|
|
181
173
|
const attrs = (0, _memize.default)(text => {
|
|
182
174
|
const named = {};
|
|
183
|
-
const numeric = [];
|
|
175
|
+
const numeric = [];
|
|
176
|
+
|
|
177
|
+
// This regular expression is reused from `shortcode_parse_atts()` in
|
|
184
178
|
// `wp-includes/shortcodes.php`.
|
|
185
179
|
//
|
|
186
180
|
// Capture groups:
|
|
@@ -194,12 +188,13 @@ const attrs = (0, _memize.default)(text => {
|
|
|
194
188
|
// 7. A numeric attribute in double quotes.
|
|
195
189
|
// 8. A numeric attribute in single quotes.
|
|
196
190
|
// 9. An unquoted numeric attribute.
|
|
191
|
+
const pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g;
|
|
197
192
|
|
|
198
|
-
|
|
199
|
-
|
|
193
|
+
// Map zero-width spaces to actual spaces.
|
|
200
194
|
text = text.replace(/[\u00a0\u200b]/g, ' ');
|
|
201
|
-
let match;
|
|
195
|
+
let match;
|
|
202
196
|
|
|
197
|
+
// Match and normalize attributes.
|
|
203
198
|
while (match = pattern.exec(text)) {
|
|
204
199
|
if (match[1]) {
|
|
205
200
|
named[match[1].toLowerCase()] = match[2];
|
|
@@ -215,12 +210,12 @@ const attrs = (0, _memize.default)(text => {
|
|
|
215
210
|
numeric.push(match[9]);
|
|
216
211
|
}
|
|
217
212
|
}
|
|
218
|
-
|
|
219
213
|
return {
|
|
220
214
|
named,
|
|
221
215
|
numeric
|
|
222
216
|
};
|
|
223
217
|
});
|
|
218
|
+
|
|
224
219
|
/**
|
|
225
220
|
* Generate a Shortcode Object from a RegExp match.
|
|
226
221
|
*
|
|
@@ -232,12 +227,9 @@ const attrs = (0, _memize.default)(text => {
|
|
|
232
227
|
*
|
|
233
228
|
* @return {WPShortcode} Shortcode instance.
|
|
234
229
|
*/
|
|
235
|
-
|
|
236
230
|
exports.attrs = attrs;
|
|
237
|
-
|
|
238
231
|
function fromMatch(match) {
|
|
239
232
|
let type;
|
|
240
|
-
|
|
241
233
|
if (match[4]) {
|
|
242
234
|
type = 'self-closing';
|
|
243
235
|
} else if (match[6]) {
|
|
@@ -245,7 +237,6 @@ function fromMatch(match) {
|
|
|
245
237
|
} else {
|
|
246
238
|
type = 'single';
|
|
247
239
|
}
|
|
248
|
-
|
|
249
240
|
return new shortcode({
|
|
250
241
|
tag: match[2],
|
|
251
242
|
attrs: match[3],
|
|
@@ -253,6 +244,7 @@ function fromMatch(match) {
|
|
|
253
244
|
content: match[5]
|
|
254
245
|
});
|
|
255
246
|
}
|
|
247
|
+
|
|
256
248
|
/**
|
|
257
249
|
* Creates a shortcode instance.
|
|
258
250
|
*
|
|
@@ -265,8 +257,6 @@ function fromMatch(match) {
|
|
|
265
257
|
*
|
|
266
258
|
* @return {WPShortcode} Shortcode instance.
|
|
267
259
|
*/
|
|
268
|
-
|
|
269
|
-
|
|
270
260
|
const shortcode = Object.assign(function (options) {
|
|
271
261
|
const {
|
|
272
262
|
tag,
|
|
@@ -278,23 +268,25 @@ const shortcode = Object.assign(function (options) {
|
|
|
278
268
|
tag,
|
|
279
269
|
type,
|
|
280
270
|
content
|
|
281
|
-
});
|
|
271
|
+
});
|
|
282
272
|
|
|
273
|
+
// Ensure we have a correctly formatted `attrs` object.
|
|
283
274
|
this.attrs = {
|
|
284
275
|
named: {},
|
|
285
276
|
numeric: []
|
|
286
277
|
};
|
|
287
|
-
|
|
288
278
|
if (!attributes) {
|
|
289
279
|
return;
|
|
290
280
|
}
|
|
281
|
+
const attributeTypes = ['named', 'numeric'];
|
|
291
282
|
|
|
292
|
-
|
|
293
|
-
|
|
283
|
+
// Parse a string of attributes.
|
|
294
284
|
if (typeof attributes === 'string') {
|
|
295
|
-
this.attrs = attrs(attributes);
|
|
285
|
+
this.attrs = attrs(attributes);
|
|
286
|
+
// Identify a correctly formatted `attrs` object.
|
|
296
287
|
} else if (attributes.length === attributeTypes.length && attributeTypes.every((t, key) => t === attributes[key])) {
|
|
297
|
-
this.attrs = attributes;
|
|
288
|
+
this.attrs = attributes;
|
|
289
|
+
// Handle a flat object of attributes.
|
|
298
290
|
} else {
|
|
299
291
|
Object.entries(attributes).forEach(([key, value]) => {
|
|
300
292
|
this.set(key, value);
|
|
@@ -322,7 +314,6 @@ Object.assign(shortcode.prototype, {
|
|
|
322
314
|
get(attr) {
|
|
323
315
|
return this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr];
|
|
324
316
|
},
|
|
325
|
-
|
|
326
317
|
/**
|
|
327
318
|
* Set a shortcode attribute.
|
|
328
319
|
*
|
|
@@ -338,7 +329,6 @@ Object.assign(shortcode.prototype, {
|
|
|
338
329
|
this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr] = value;
|
|
339
330
|
return this;
|
|
340
331
|
},
|
|
341
|
-
|
|
342
332
|
/**
|
|
343
333
|
* Transform the shortcode into a string.
|
|
344
334
|
*
|
|
@@ -355,26 +345,25 @@ Object.assign(shortcode.prototype, {
|
|
|
355
345
|
});
|
|
356
346
|
Object.entries(this.attrs.named).forEach(([name, value]) => {
|
|
357
347
|
text += ' ' + name + '="' + value + '"';
|
|
358
|
-
});
|
|
359
|
-
// ignore any additional content.
|
|
348
|
+
});
|
|
360
349
|
|
|
350
|
+
// If the tag is marked as `single` or `self-closing`, close the tag and
|
|
351
|
+
// ignore any additional content.
|
|
361
352
|
if ('single' === this.type) {
|
|
362
353
|
return text + ']';
|
|
363
354
|
} else if ('self-closing' === this.type) {
|
|
364
355
|
return text + ' /]';
|
|
365
|
-
}
|
|
366
|
-
|
|
356
|
+
}
|
|
367
357
|
|
|
358
|
+
// Complete the opening tag.
|
|
368
359
|
text += ']';
|
|
369
|
-
|
|
370
360
|
if (this.content) {
|
|
371
361
|
text += this.content;
|
|
372
|
-
}
|
|
373
|
-
|
|
362
|
+
}
|
|
374
363
|
|
|
364
|
+
// Add the closing tag.
|
|
375
365
|
return text + '[/' + this.tag + ']';
|
|
376
366
|
}
|
|
377
|
-
|
|
378
367
|
});
|
|
379
368
|
var _default = shortcode;
|
|
380
369
|
exports.default = _default;
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/shortcode/src/index.js"],"names":["next","tag","text","index","re","regexp","lastIndex","match","exec","result","content","shortcode","fromMatch","slice","replace","callback","left","$3","attrs","slash","closing","right","arguments","string","options","RegExp","named","numeric","pattern","toLowerCase","push","type","Object","assign","attributes","attributeTypes","length","every","t","key","entries","forEach","value","set","prototype","get","attr","test","name"],"mappings":";;;;;;;;;;;;;;AAGA;;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;AAC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AAnB,CAA8BC,KAAF,IAAa;AACxC,UAAK,KAAKK,IAAL,CAAWL,KAAX,CAAL,EAA0B;AACzBxC,QAAAA,IAAI,IAAI,OAAOwC,KAAP,GAAe,GAAvB;AACA,OAFD,MAEO;AACNxC,QAAAA,IAAI,IAAI,MAAMwC,KAAd;AACA;AACD,KAND;AAQAV,IAAAA,MAAM,CAACQ,OAAP,CAAgB,KAAKtB,KAAL,CAAWQ,KAA3B,EAAmCe,OAAnC,CAA4C,CAAE,CAAEO,IAAF,EAAQN,KAAR,CAAF,KAAuB;AAClExC,MAAAA,IAAI,IAAI,MAAM8C,IAAN,GAAa,IAAb,GAAoBN,KAApB,GAA4B,GAApC;AACA,KAFD,EAXQ,CAeR;AACA;;AACA,QAAK,aAAa,KAAKX,IAAvB,EAA8B;AAC7B,aAAO7B,IAAI,GAAG,GAAd;AACA,KAFD,MAEO,IAAK,mBAAmB,KAAK6B,IAA7B,EAAoC;AAC1C,aAAO7B,IAAI,GAAG,KAAd;AACA,KArBO,CAuBR;;;AACAA,IAAAA,IAAI,IAAI,GAAR;;AAEA,QAAK,KAAKQ,OAAV,EAAoB;AACnBR,MAAAA,IAAI,IAAI,KAAKQ,OAAb;AACA,KA5BO,CA8BR;;;AACA,WAAOR,IAAI,GAAG,IAAP,GAAc,KAAKD,GAAnB,GAAyB,GAAhC;AACA;;AAvEkC,CAApC;eA0EeU,S","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"]}
|
|
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","memize","named","numeric","pattern","toLowerCase","push","exports","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,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,CAAE,CAAC,CAAE;IACnBI,SAAS,EAAEC,SAAS,CAA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
package/build-module/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import memize from 'memize';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Shortcode attributes object.
|
|
7
8
|
*
|
|
@@ -40,40 +41,38 @@ import memize from 'memize';
|
|
|
40
41
|
*
|
|
41
42
|
* @return {WPShortcodeMatch | undefined} Matched information.
|
|
42
43
|
*/
|
|
43
|
-
|
|
44
44
|
export function next(tag, text, index = 0) {
|
|
45
45
|
const re = regexp(tag);
|
|
46
46
|
re.lastIndex = index;
|
|
47
47
|
const match = re.exec(text);
|
|
48
|
-
|
|
49
48
|
if (!match) {
|
|
50
49
|
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
50
|
+
}
|
|
53
51
|
|
|
52
|
+
// If we matched an escaped shortcode, try again.
|
|
54
53
|
if ('[' === match[1] && ']' === match[7]) {
|
|
55
54
|
return next(tag, text, re.lastIndex);
|
|
56
55
|
}
|
|
57
|
-
|
|
58
56
|
const result = {
|
|
59
57
|
index: match.index,
|
|
60
58
|
content: match[0],
|
|
61
59
|
shortcode: fromMatch(match)
|
|
62
|
-
};
|
|
63
|
-
// index accordingly.
|
|
60
|
+
};
|
|
64
61
|
|
|
62
|
+
// If we matched a leading `[`, strip it from the match and increment the
|
|
63
|
+
// index accordingly.
|
|
65
64
|
if (match[1]) {
|
|
66
65
|
result.content = result.content.slice(1);
|
|
67
66
|
result.index++;
|
|
68
|
-
}
|
|
69
|
-
|
|
67
|
+
}
|
|
70
68
|
|
|
69
|
+
// If we matched a trailing `]`, strip it from the match.
|
|
71
70
|
if (match[7]) {
|
|
72
71
|
result.content = result.content.slice(0, -1);
|
|
73
72
|
}
|
|
74
|
-
|
|
75
73
|
return result;
|
|
76
74
|
}
|
|
75
|
+
|
|
77
76
|
/**
|
|
78
77
|
* Replace matching shortcodes in a block of text.
|
|
79
78
|
*
|
|
@@ -84,22 +83,23 @@ export function next(tag, text, index = 0) {
|
|
|
84
83
|
*
|
|
85
84
|
* @return {string} Text with shortcodes replaced.
|
|
86
85
|
*/
|
|
87
|
-
|
|
88
86
|
export function replace(tag, text, callback) {
|
|
89
87
|
return text.replace(regexp(tag), function (match, left, $3, attrs, slash, content, closing, right) {
|
|
90
88
|
// If both extra brackets exist, the shortcode has been properly
|
|
91
89
|
// escaped.
|
|
92
90
|
if (left === '[' && right === ']') {
|
|
93
91
|
return match;
|
|
94
|
-
}
|
|
92
|
+
}
|
|
95
93
|
|
|
94
|
+
// Create the match object and pass it through the callback.
|
|
95
|
+
const result = callback(fromMatch(arguments));
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
// Make sure to return any of the extra brackets if they weren't used to
|
|
98
98
|
// escape the shortcode.
|
|
99
|
-
|
|
100
99
|
return result || result === '' ? left + result + right : match;
|
|
101
100
|
});
|
|
102
101
|
}
|
|
102
|
+
|
|
103
103
|
/**
|
|
104
104
|
* Generate a string from shortcode parameters.
|
|
105
105
|
*
|
|
@@ -113,10 +113,10 @@ export function replace(tag, text, callback) {
|
|
|
113
113
|
*
|
|
114
114
|
* @return {string} String representation of the shortcode.
|
|
115
115
|
*/
|
|
116
|
-
|
|
117
116
|
export function string(options) {
|
|
118
117
|
return new shortcode(options).string();
|
|
119
118
|
}
|
|
119
|
+
|
|
120
120
|
/**
|
|
121
121
|
* Generate a RegExp to identify a shortcode.
|
|
122
122
|
*
|
|
@@ -137,10 +137,10 @@ export function string(options) {
|
|
|
137
137
|
*
|
|
138
138
|
* @return {RegExp} Shortcode RegExp.
|
|
139
139
|
*/
|
|
140
|
-
|
|
141
140
|
export function regexp(tag) {
|
|
142
141
|
return new RegExp('\\[(\\[?)(' + tag + ')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)', 'g');
|
|
143
142
|
}
|
|
143
|
+
|
|
144
144
|
/**
|
|
145
145
|
* Parse shortcode attributes.
|
|
146
146
|
*
|
|
@@ -158,10 +158,11 @@ export function regexp(tag) {
|
|
|
158
158
|
*
|
|
159
159
|
* @return {WPShortcodeAttrs} Parsed shortcode attributes.
|
|
160
160
|
*/
|
|
161
|
-
|
|
162
161
|
export const attrs = memize(text => {
|
|
163
162
|
const named = {};
|
|
164
|
-
const numeric = [];
|
|
163
|
+
const numeric = [];
|
|
164
|
+
|
|
165
|
+
// This regular expression is reused from `shortcode_parse_atts()` in
|
|
165
166
|
// `wp-includes/shortcodes.php`.
|
|
166
167
|
//
|
|
167
168
|
// Capture groups:
|
|
@@ -175,12 +176,13 @@ export const attrs = memize(text => {
|
|
|
175
176
|
// 7. A numeric attribute in double quotes.
|
|
176
177
|
// 8. A numeric attribute in single quotes.
|
|
177
178
|
// 9. An unquoted numeric attribute.
|
|
179
|
+
const pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g;
|
|
178
180
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
+
// Map zero-width spaces to actual spaces.
|
|
181
182
|
text = text.replace(/[\u00a0\u200b]/g, ' ');
|
|
182
|
-
let match;
|
|
183
|
+
let match;
|
|
183
184
|
|
|
185
|
+
// Match and normalize attributes.
|
|
184
186
|
while (match = pattern.exec(text)) {
|
|
185
187
|
if (match[1]) {
|
|
186
188
|
named[match[1].toLowerCase()] = match[2];
|
|
@@ -196,12 +198,12 @@ export const attrs = memize(text => {
|
|
|
196
198
|
numeric.push(match[9]);
|
|
197
199
|
}
|
|
198
200
|
}
|
|
199
|
-
|
|
200
201
|
return {
|
|
201
202
|
named,
|
|
202
203
|
numeric
|
|
203
204
|
};
|
|
204
205
|
});
|
|
206
|
+
|
|
205
207
|
/**
|
|
206
208
|
* Generate a Shortcode Object from a RegExp match.
|
|
207
209
|
*
|
|
@@ -213,10 +215,8 @@ export const attrs = memize(text => {
|
|
|
213
215
|
*
|
|
214
216
|
* @return {WPShortcode} Shortcode instance.
|
|
215
217
|
*/
|
|
216
|
-
|
|
217
218
|
export function fromMatch(match) {
|
|
218
219
|
let type;
|
|
219
|
-
|
|
220
220
|
if (match[4]) {
|
|
221
221
|
type = 'self-closing';
|
|
222
222
|
} else if (match[6]) {
|
|
@@ -224,7 +224,6 @@ export function fromMatch(match) {
|
|
|
224
224
|
} else {
|
|
225
225
|
type = 'single';
|
|
226
226
|
}
|
|
227
|
-
|
|
228
227
|
return new shortcode({
|
|
229
228
|
tag: match[2],
|
|
230
229
|
attrs: match[3],
|
|
@@ -232,6 +231,7 @@ export function fromMatch(match) {
|
|
|
232
231
|
content: match[5]
|
|
233
232
|
});
|
|
234
233
|
}
|
|
234
|
+
|
|
235
235
|
/**
|
|
236
236
|
* Creates a shortcode instance.
|
|
237
237
|
*
|
|
@@ -244,7 +244,6 @@ export function fromMatch(match) {
|
|
|
244
244
|
*
|
|
245
245
|
* @return {WPShortcode} Shortcode instance.
|
|
246
246
|
*/
|
|
247
|
-
|
|
248
247
|
const shortcode = Object.assign(function (options) {
|
|
249
248
|
const {
|
|
250
249
|
tag,
|
|
@@ -256,23 +255,25 @@ const shortcode = Object.assign(function (options) {
|
|
|
256
255
|
tag,
|
|
257
256
|
type,
|
|
258
257
|
content
|
|
259
|
-
});
|
|
258
|
+
});
|
|
260
259
|
|
|
260
|
+
// Ensure we have a correctly formatted `attrs` object.
|
|
261
261
|
this.attrs = {
|
|
262
262
|
named: {},
|
|
263
263
|
numeric: []
|
|
264
264
|
};
|
|
265
|
-
|
|
266
265
|
if (!attributes) {
|
|
267
266
|
return;
|
|
268
267
|
}
|
|
268
|
+
const attributeTypes = ['named', 'numeric'];
|
|
269
269
|
|
|
270
|
-
|
|
271
|
-
|
|
270
|
+
// Parse a string of attributes.
|
|
272
271
|
if (typeof attributes === 'string') {
|
|
273
|
-
this.attrs = attrs(attributes);
|
|
272
|
+
this.attrs = attrs(attributes);
|
|
273
|
+
// Identify a correctly formatted `attrs` object.
|
|
274
274
|
} else if (attributes.length === attributeTypes.length && attributeTypes.every((t, key) => t === attributes[key])) {
|
|
275
|
-
this.attrs = attributes;
|
|
275
|
+
this.attrs = attributes;
|
|
276
|
+
// Handle a flat object of attributes.
|
|
276
277
|
} else {
|
|
277
278
|
Object.entries(attributes).forEach(([key, value]) => {
|
|
278
279
|
this.set(key, value);
|
|
@@ -300,7 +301,6 @@ Object.assign(shortcode.prototype, {
|
|
|
300
301
|
get(attr) {
|
|
301
302
|
return this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr];
|
|
302
303
|
},
|
|
303
|
-
|
|
304
304
|
/**
|
|
305
305
|
* Set a shortcode attribute.
|
|
306
306
|
*
|
|
@@ -316,7 +316,6 @@ Object.assign(shortcode.prototype, {
|
|
|
316
316
|
this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr] = value;
|
|
317
317
|
return this;
|
|
318
318
|
},
|
|
319
|
-
|
|
320
319
|
/**
|
|
321
320
|
* Transform the shortcode into a string.
|
|
322
321
|
*
|
|
@@ -333,26 +332,25 @@ Object.assign(shortcode.prototype, {
|
|
|
333
332
|
});
|
|
334
333
|
Object.entries(this.attrs.named).forEach(([name, value]) => {
|
|
335
334
|
text += ' ' + name + '="' + value + '"';
|
|
336
|
-
});
|
|
337
|
-
// ignore any additional content.
|
|
335
|
+
});
|
|
338
336
|
|
|
337
|
+
// If the tag is marked as `single` or `self-closing`, close the tag and
|
|
338
|
+
// ignore any additional content.
|
|
339
339
|
if ('single' === this.type) {
|
|
340
340
|
return text + ']';
|
|
341
341
|
} else if ('self-closing' === this.type) {
|
|
342
342
|
return text + ' /]';
|
|
343
|
-
}
|
|
344
|
-
|
|
343
|
+
}
|
|
345
344
|
|
|
345
|
+
// Complete the opening tag.
|
|
346
346
|
text += ']';
|
|
347
|
-
|
|
348
347
|
if (this.content) {
|
|
349
348
|
text += this.content;
|
|
350
|
-
}
|
|
351
|
-
|
|
349
|
+
}
|
|
352
350
|
|
|
351
|
+
// Add the closing tag.
|
|
353
352
|
return text + '[/' + this.tag + ']';
|
|
354
353
|
}
|
|
355
|
-
|
|
356
354
|
});
|
|
357
355
|
export default shortcode;
|
|
358
356
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/shortcode/src/index.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,MAAP,MAAmB,QAAnB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,IAAT,CAAeC,GAAf,EAAoBC,IAApB,EAA0BC,KAAK,GAAG,CAAlC,EAAsC;AAC5C,QAAMC,EAAE,GAAGC,MAAM,CAAEJ,GAAF,CAAjB;AAEAG,EAAAA,EAAE,CAACE,SAAH,GAAeH,KAAf;AAEA,QAAMI,KAAK,GAAGH,EAAE,CAACI,IAAH,CAASN,IAAT,CAAd;;AAEA,MAAK,CAAEK,KAAP,EAAe;AACd;AACA,GAT2C,CAW5C;;;AACA,MAAK,QAAQA,KAAK,CAAE,CAAF,CAAb,IAAsB,QAAQA,KAAK,CAAE,CAAF,CAAxC,EAAgD;AAC/C,WAAOP,IAAI,CAAEC,GAAF,EAAOC,IAAP,EAAaE,EAAE,CAACE,SAAhB,CAAX;AACA;;AAED,QA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KAAKX,IAAvB,EAA8B;AAC7B,aAAO7B,IAAI,GAAG,GAAd;AACA,KAFD,MAEO,IAAK,mBAAmB,KAAK6B,IAA7B,EAAoC;AAC1C,aAAO7B,IAAI,GAAG,KAAd;AACA,KArBO,CAuBR;;;AACAA,IAAAA,IAAI,IAAI,GAAR;;AAEA,QAAK,KAAKQ,OAAV,EAAoB;AACnBR,MAAAA,IAAI,IAAI,KAAKQ,OAAb;AACA,KA5BO,CA8BR;;;AACA,WAAOR,IAAI,GAAG,IAAP,GAAc,KAAKD,GAAnB,GAAyB,GAAhC;AACA;;AAvEkC,CAApC;AA0EA,eAAeU,SAAf","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"]}
|
|
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;A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M,CAACQ,OAAO,CAAE,IAAI,CAACtB,KAAK,CAACQ,KAAM,CAAC,CAACe,OAAO,CAAE,CAAE,CAAEO,IAAI,EAAEN,KAAK,CAAE,KAAM;MAClExC,IAAI,IAAI,GAAG,GAAG8C,IAAI,GAAG,IAAI,GAAGN,KAAK,GAAG,GAAG;IACxC,CAAE,CAAC;;IAEH;IACA;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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/shortcode",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.40.0",
|
|
4
4
|
"description": "Shortcode module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "78a288d55b83a713b2f7d98d5a855c0771a2afc6"
|
|
35
35
|
}
|