@wordpress/shortcode 4.32.0 → 4.32.1-next.b8c8708f3.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/build/index.js +113 -243
- package/build/index.js.map +7 -1
- package/build/types.js +16 -5
- package/build/types.js.map +7 -1
- package/build-module/index.js +80 -220
- package/build-module/index.js.map +7 -1
- package/build-module/types.js +1 -2
- package/build-module/types.js.map +7 -1
- package/package.json +11 -3
package/build/index.js
CHANGED
|
@@ -1,49 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
regexp: true,
|
|
12
|
-
attrs: true,
|
|
13
|
-
fromMatch: true
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
11
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
attrs: () => attrs,
|
|
33
|
+
default: () => index_default,
|
|
34
|
+
fromMatch: () => fromMatch,
|
|
35
|
+
next: () => next,
|
|
36
|
+
regexp: () => regexp,
|
|
37
|
+
replace: () => replace,
|
|
38
|
+
string: () => string
|
|
33
39
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Find the next matching shortcode.
|
|
40
|
-
*
|
|
41
|
-
* @param {string} tag Shortcode tag.
|
|
42
|
-
* @param {string} text Text to search.
|
|
43
|
-
* @param {number} index Index to start search from.
|
|
44
|
-
*
|
|
45
|
-
* @return {import('./types').ShortcodeMatch | undefined} Matched information.
|
|
46
|
-
*/
|
|
40
|
+
module.exports = __toCommonJS(index_exports);
|
|
41
|
+
var import_memize = __toESM(require("memize"));
|
|
42
|
+
__reExport(index_exports, require("./types"), module.exports);
|
|
47
43
|
function next(tag, text, index = 0) {
|
|
48
44
|
const re = regexp(tag);
|
|
49
45
|
re.lastIndex = index;
|
|
@@ -51,9 +47,7 @@ function next(tag, text, index = 0) {
|
|
|
51
47
|
if (!match) {
|
|
52
48
|
return;
|
|
53
49
|
}
|
|
54
|
-
|
|
55
|
-
// If we matched an escaped shortcode, try again.
|
|
56
|
-
if ('[' === match[1] && ']' === match[7]) {
|
|
50
|
+
if ("[" === match[1] && "]" === match[7]) {
|
|
57
51
|
return next(tag, text, re.lastIndex);
|
|
58
52
|
}
|
|
59
53
|
const result = {
|
|
@@ -61,131 +55,42 @@ function next(tag, text, index = 0) {
|
|
|
61
55
|
content: match[0],
|
|
62
56
|
shortcode: fromMatch(match)
|
|
63
57
|
};
|
|
64
|
-
|
|
65
|
-
// If we matched a leading `[`, strip it from the match and increment the
|
|
66
|
-
// index accordingly.
|
|
67
58
|
if (match[1]) {
|
|
68
59
|
result.content = result.content.slice(1);
|
|
69
60
|
result.index++;
|
|
70
61
|
}
|
|
71
|
-
|
|
72
|
-
// If we matched a trailing `]`, strip it from the match.
|
|
73
62
|
if (match[7]) {
|
|
74
63
|
result.content = result.content.slice(0, -1);
|
|
75
64
|
}
|
|
76
65
|
return result;
|
|
77
66
|
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Replace matching shortcodes in a block of text.
|
|
81
|
-
*
|
|
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.
|
|
86
|
-
*
|
|
87
|
-
* @return {string} Text with shortcodes replaced.
|
|
88
|
-
*/
|
|
89
67
|
function replace(tag, text, callback) {
|
|
90
|
-
return text.replace(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
68
|
+
return text.replace(
|
|
69
|
+
regexp(tag),
|
|
70
|
+
function(match, left, $3, attrs2, slash, content, closing, right) {
|
|
71
|
+
if (left === "[" && right === "]") {
|
|
72
|
+
return match;
|
|
73
|
+
}
|
|
74
|
+
const result = callback(fromMatch(arguments));
|
|
75
|
+
return result || result === "" ? left + result + right : match;
|
|
95
76
|
}
|
|
96
|
-
|
|
97
|
-
// Create the match object and pass it through the callback.
|
|
98
|
-
const result = callback(fromMatch(arguments));
|
|
99
|
-
|
|
100
|
-
// Make sure to return any of the extra brackets if they weren't used to
|
|
101
|
-
// escape the shortcode.
|
|
102
|
-
return result || result === '' ? left + result + right : match;
|
|
103
|
-
});
|
|
77
|
+
);
|
|
104
78
|
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Generate a string from shortcode parameters.
|
|
108
|
-
*
|
|
109
|
-
* Creates a shortcode instance and returns a string.
|
|
110
|
-
*
|
|
111
|
-
* Accepts the same `options` as the `shortcode()` constructor, containing a
|
|
112
|
-
* `tag` string, a string or object of `attrs`, a boolean indicating whether to
|
|
113
|
-
* format the shortcode using a `single` tag, and a `content` string.
|
|
114
|
-
*
|
|
115
|
-
* @param {Object} options
|
|
116
|
-
*
|
|
117
|
-
* @return {string} String representation of the shortcode.
|
|
118
|
-
*/
|
|
119
79
|
function string(options) {
|
|
120
80
|
return new shortcode(options).string();
|
|
121
81
|
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Generate a RegExp to identify a shortcode.
|
|
125
|
-
*
|
|
126
|
-
* The base regex is functionally equivalent to the one found in
|
|
127
|
-
* `get_shortcode_regex()` in `wp-includes/shortcodes.php`.
|
|
128
|
-
*
|
|
129
|
-
* Capture groups:
|
|
130
|
-
*
|
|
131
|
-
* 1. An extra `[` to allow for escaping shortcodes with double `[[]]`
|
|
132
|
-
* 2. The shortcode name
|
|
133
|
-
* 3. The shortcode argument list
|
|
134
|
-
* 4. The self closing `/`
|
|
135
|
-
* 5. The content of a shortcode when it wraps some content.
|
|
136
|
-
* 6. The closing tag.
|
|
137
|
-
* 7. An extra `]` to allow for escaping shortcodes with double `[[]]`
|
|
138
|
-
*
|
|
139
|
-
* @param {string} tag Shortcode tag.
|
|
140
|
-
*
|
|
141
|
-
* @return {RegExp} Shortcode RegExp.
|
|
142
|
-
*/
|
|
143
82
|
function regexp(tag) {
|
|
144
|
-
return new RegExp(
|
|
83
|
+
return new RegExp(
|
|
84
|
+
"\\[(\\[?)(" + tag + ")(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)",
|
|
85
|
+
"g"
|
|
86
|
+
);
|
|
145
87
|
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Parse shortcode attributes.
|
|
149
|
-
*
|
|
150
|
-
* Shortcodes accept many types of attributes. These can chiefly be divided into
|
|
151
|
-
* named and numeric attributes:
|
|
152
|
-
*
|
|
153
|
-
* Named attributes are assigned on a key/value basis, while numeric attributes
|
|
154
|
-
* are treated as an array.
|
|
155
|
-
*
|
|
156
|
-
* Named attributes can be formatted as either `name="value"`, `name='value'`,
|
|
157
|
-
* or `name=value`. Numeric attributes can be formatted as `"value"` or just
|
|
158
|
-
* `value`.
|
|
159
|
-
*
|
|
160
|
-
* @param {string} text Serialised shortcode attributes.
|
|
161
|
-
*
|
|
162
|
-
* @return {import('./types').ShortcodeAttrs} Parsed shortcode attributes.
|
|
163
|
-
*/
|
|
164
|
-
const attrs = exports.attrs = (0, _memize.default)(text => {
|
|
88
|
+
const attrs = (0, import_memize.default)((text) => {
|
|
165
89
|
const named = {};
|
|
166
90
|
const numeric = [];
|
|
167
|
-
|
|
168
|
-
// This regular expression is reused from `shortcode_parse_atts()` in
|
|
169
|
-
// `wp-includes/shortcodes.php`.
|
|
170
|
-
//
|
|
171
|
-
// Capture groups:
|
|
172
|
-
//
|
|
173
|
-
// 1. An attribute name, that corresponds to...
|
|
174
|
-
// 2. a value in double quotes.
|
|
175
|
-
// 3. An attribute name, that corresponds to...
|
|
176
|
-
// 4. a value in single quotes.
|
|
177
|
-
// 5. An attribute name, that corresponds to...
|
|
178
|
-
// 6. an unquoted value.
|
|
179
|
-
// 7. A numeric attribute in double quotes.
|
|
180
|
-
// 8. A numeric attribute in single quotes.
|
|
181
|
-
// 9. An unquoted numeric attribute.
|
|
182
91
|
const pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g;
|
|
183
|
-
|
|
184
|
-
// Map zero-width spaces to actual spaces.
|
|
185
|
-
text = text.replace(/[\u00a0\u200b]/g, ' ');
|
|
92
|
+
text = text.replace(/[\u00a0\u200b]/g, " ");
|
|
186
93
|
let match;
|
|
187
|
-
|
|
188
|
-
// Match and normalize attributes.
|
|
189
94
|
while (match = pattern.exec(text)) {
|
|
190
95
|
if (match[1]) {
|
|
191
96
|
named[match[1].toLowerCase()] = match[2];
|
|
@@ -201,31 +106,16 @@ const attrs = exports.attrs = (0, _memize.default)(text => {
|
|
|
201
106
|
numeric.push(match[9]);
|
|
202
107
|
}
|
|
203
108
|
}
|
|
204
|
-
return {
|
|
205
|
-
named,
|
|
206
|
-
numeric
|
|
207
|
-
};
|
|
109
|
+
return { named, numeric };
|
|
208
110
|
});
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Generate a Shortcode Object from a RegExp match.
|
|
212
|
-
*
|
|
213
|
-
* Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated
|
|
214
|
-
* by `regexp()`. `match` can also be set to the `arguments` from a callback
|
|
215
|
-
* passed to `regexp.replace()`.
|
|
216
|
-
*
|
|
217
|
-
* @param {import('./types').Match} match Match array.
|
|
218
|
-
*
|
|
219
|
-
* @return {InstanceType<import('./types').shortcode>} Shortcode instance.
|
|
220
|
-
*/
|
|
221
111
|
function fromMatch(match) {
|
|
222
112
|
let type;
|
|
223
113
|
if (match[4]) {
|
|
224
|
-
type =
|
|
114
|
+
type = "self-closing";
|
|
225
115
|
} else if (match[6]) {
|
|
226
|
-
type =
|
|
116
|
+
type = "closed";
|
|
227
117
|
} else {
|
|
228
|
-
type =
|
|
118
|
+
type = "single";
|
|
229
119
|
}
|
|
230
120
|
return new shortcode({
|
|
231
121
|
tag: match[2],
|
|
@@ -234,60 +124,37 @@ function fromMatch(match) {
|
|
|
234
124
|
content: match[5]
|
|
235
125
|
});
|
|
236
126
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
if (!attributes) {
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
const attributeTypes = ['named', 'numeric'];
|
|
270
|
-
|
|
271
|
-
// Parse a string of attributes.
|
|
272
|
-
if (typeof attributes === 'string') {
|
|
273
|
-
this.attrs = attrs(attributes);
|
|
274
|
-
// Identify a correctly formatted `attrs` object.
|
|
275
|
-
} else if (attributes.length === attributeTypes.length && attributeTypes.every((t, key) => t === attributes[key])) {
|
|
276
|
-
this.attrs = attributes;
|
|
277
|
-
// Handle a flat object of attributes.
|
|
278
|
-
} else {
|
|
279
|
-
Object.entries(attributes).forEach(([key, value]) => {
|
|
280
|
-
this.set(key, value);
|
|
281
|
-
});
|
|
127
|
+
const shortcode = Object.assign(
|
|
128
|
+
function(options) {
|
|
129
|
+
const { tag, attrs: attributes, type, content } = options || {};
|
|
130
|
+
Object.assign(this, { tag, type, content });
|
|
131
|
+
this.attrs = {
|
|
132
|
+
named: {},
|
|
133
|
+
numeric: []
|
|
134
|
+
};
|
|
135
|
+
if (!attributes) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const attributeTypes = ["named", "numeric"];
|
|
139
|
+
if (typeof attributes === "string") {
|
|
140
|
+
this.attrs = attrs(attributes);
|
|
141
|
+
} else if (attributes.length === attributeTypes.length && attributeTypes.every((t, key) => t === attributes[key])) {
|
|
142
|
+
this.attrs = attributes;
|
|
143
|
+
} else {
|
|
144
|
+
Object.entries(attributes).forEach(([key, value]) => {
|
|
145
|
+
this.set(key, value);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
next,
|
|
151
|
+
replace,
|
|
152
|
+
string,
|
|
153
|
+
regexp,
|
|
154
|
+
attrs,
|
|
155
|
+
fromMatch
|
|
282
156
|
}
|
|
283
|
-
|
|
284
|
-
next,
|
|
285
|
-
replace,
|
|
286
|
-
string,
|
|
287
|
-
regexp,
|
|
288
|
-
attrs,
|
|
289
|
-
fromMatch
|
|
290
|
-
});
|
|
157
|
+
);
|
|
291
158
|
Object.assign(shortcode.prototype, {
|
|
292
159
|
/**
|
|
293
160
|
* Get a shortcode attribute.
|
|
@@ -300,7 +167,7 @@ Object.assign(shortcode.prototype, {
|
|
|
300
167
|
* @return {string} Attribute value.
|
|
301
168
|
*/
|
|
302
169
|
get(attr) {
|
|
303
|
-
return this.attrs[typeof attr ===
|
|
170
|
+
return this.attrs[typeof attr === "number" ? "numeric" : "named"][attr];
|
|
304
171
|
},
|
|
305
172
|
/**
|
|
306
173
|
* Set a shortcode attribute.
|
|
@@ -314,7 +181,7 @@ Object.assign(shortcode.prototype, {
|
|
|
314
181
|
* @return {InstanceType< import('./types').shortcode >} Shortcode instance.
|
|
315
182
|
*/
|
|
316
183
|
set(attr, value) {
|
|
317
|
-
this.attrs[typeof attr ===
|
|
184
|
+
this.attrs[typeof attr === "number" ? "numeric" : "named"][attr] = value;
|
|
318
185
|
return this;
|
|
319
186
|
},
|
|
320
187
|
/**
|
|
@@ -323,35 +190,38 @@ Object.assign(shortcode.prototype, {
|
|
|
323
190
|
* @return {string} String representation of the shortcode.
|
|
324
191
|
*/
|
|
325
192
|
string() {
|
|
326
|
-
let text =
|
|
327
|
-
this.attrs.numeric.forEach(value => {
|
|
193
|
+
let text = "[" + this.tag;
|
|
194
|
+
this.attrs.numeric.forEach((value) => {
|
|
328
195
|
if (/\s/.test(value)) {
|
|
329
196
|
text += ' "' + value + '"';
|
|
330
197
|
} else {
|
|
331
|
-
text +=
|
|
198
|
+
text += " " + value;
|
|
332
199
|
}
|
|
333
200
|
});
|
|
334
201
|
Object.entries(this.attrs.named).forEach(([name, value]) => {
|
|
335
|
-
text +=
|
|
202
|
+
text += " " + name + '="' + value + '"';
|
|
336
203
|
});
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
return text + ']';
|
|
342
|
-
} else if ('self-closing' === this.type) {
|
|
343
|
-
return text + ' /]';
|
|
204
|
+
if ("single" === this.type) {
|
|
205
|
+
return text + "]";
|
|
206
|
+
} else if ("self-closing" === this.type) {
|
|
207
|
+
return text + " /]";
|
|
344
208
|
}
|
|
345
|
-
|
|
346
|
-
// Complete the opening tag.
|
|
347
|
-
text += ']';
|
|
209
|
+
text += "]";
|
|
348
210
|
if (this.content) {
|
|
349
211
|
text += this.content;
|
|
350
212
|
}
|
|
351
|
-
|
|
352
|
-
// Add the closing tag.
|
|
353
|
-
return text + '[/' + this.tag + ']';
|
|
213
|
+
return text + "[/" + this.tag + "]";
|
|
354
214
|
}
|
|
355
215
|
});
|
|
356
|
-
var
|
|
357
|
-
|
|
216
|
+
var index_default = shortcode;
|
|
217
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
218
|
+
0 && (module.exports = {
|
|
219
|
+
attrs,
|
|
220
|
+
fromMatch,
|
|
221
|
+
next,
|
|
222
|
+
regexp,
|
|
223
|
+
replace,
|
|
224
|
+
string,
|
|
225
|
+
...require("./types")
|
|
226
|
+
});
|
|
227
|
+
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
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;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AALA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASS,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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I,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":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.js"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAmB;AAEnB,0BAAc,oBALd;AAgBO,SAAS,KAAM,KAAK,MAAM,QAAQ,GAAI;AAC5C,QAAM,KAAK,OAAQ,GAAI;AAEvB,KAAG,YAAY;AAEf,QAAM,QAAQ,GAAG,KAAM,IAAK;AAE5B,MAAK,CAAE,OAAQ;AACd;AAAA,EACD;AAGA,MAAK,QAAQ,MAAO,CAAE,KAAK,QAAQ,MAAO,CAAE,GAAI;AAC/C,WAAO,KAAM,KAAK,MAAM,GAAG,SAAU;AAAA,EACtC;AAEA,QAAM,SAAS;AAAA,IACd,OAAO,MAAM;AAAA,IACb,SAAS,MAAO,CAAE;AAAA,IAClB,WAAW,UAAW,KAAM;AAAA,EAC7B;AAIA,MAAK,MAAO,CAAE,GAAI;AACjB,WAAO,UAAU,OAAO,QAAQ,MAAO,CAAE;AACzC,WAAO;AAAA,EACR;AAGA,MAAK,MAAO,CAAE,GAAI;AACjB,WAAO,UAAU,OAAO,QAAQ,MAAO,GAAG,EAAG;AAAA,EAC9C;AAEA,SAAO;AACR;AAYO,SAAS,QAAS,KAAK,MAAM,UAAW;AAC9C,SAAO,KAAK;AAAA,IACX,OAAQ,GAAI;AAAA,IACZ,SAAW,OAAO,MAAM,IAAIA,QAAO,OAAO,SAAS,SAAS,OAAQ;AAGnE,UAAK,SAAS,OAAO,UAAU,KAAM;AACp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B,SAAK,MAAO,OAAO,SAAS,WAAW,YAAY,OAAQ,EAAG,IAAK,IAClE;AACD,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAS;AACR,QAAI,OAAO,MAAM,KAAK;AAEtB,SAAK,MAAM,QAAQ,QAAS,CAAE,UAAW;AACxC,UAAK,KAAK,KAAM,KAAM,GAAI;AACzB,gBAAQ,OAAO,QAAQ;AAAA,MACxB,OAAO;AACN,gBAAQ,MAAM;AAAA,MACf;AAAA,IACD,CAAE;AAEF,WAAO,QAAS,KAAK,MAAM,KAAM,EAAE,QAAS,CAAE,CAAE,MAAM,KAAM,MAAO;AAClE,cAAQ,MAAM,OAAO,OAAO,QAAQ;AAAA,IACrC,CAAE;AAIF,QAAK,aAAa,KAAK,MAAO;AAC7B,aAAO,OAAO;AAAA,IACf,WAAY,mBAAmB,KAAK,MAAO;AAC1C,aAAO,OAAO;AAAA,IACf;AAGA,YAAQ;AAER,QAAK,KAAK,SAAU;AACnB,cAAQ,KAAK;AAAA,IACd;AAGA,WAAO,OAAO,OAAO,KAAK,MAAM;AAAA,EACjC;AACD,CAAE;AAEF,IAAO,gBAAQ;",
|
|
6
|
+
"names": ["attrs", "memize"]
|
|
7
|
+
}
|
package/build/types.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
package/build/types.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/types.ts"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/index.js
CHANGED
|
@@ -1,28 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
import memize from 'memize';
|
|
5
|
-
export * from './types';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Find the next matching shortcode.
|
|
9
|
-
*
|
|
10
|
-
* @param {string} tag Shortcode tag.
|
|
11
|
-
* @param {string} text Text to search.
|
|
12
|
-
* @param {number} index Index to start search from.
|
|
13
|
-
*
|
|
14
|
-
* @return {import('./types').ShortcodeMatch | undefined} Matched information.
|
|
15
|
-
*/
|
|
16
|
-
export function next(tag, text, index = 0) {
|
|
1
|
+
import memize from "memize";
|
|
2
|
+
export * from "./types";
|
|
3
|
+
function next(tag, text, index = 0) {
|
|
17
4
|
const re = regexp(tag);
|
|
18
5
|
re.lastIndex = index;
|
|
19
6
|
const match = re.exec(text);
|
|
20
7
|
if (!match) {
|
|
21
8
|
return;
|
|
22
9
|
}
|
|
23
|
-
|
|
24
|
-
// If we matched an escaped shortcode, try again.
|
|
25
|
-
if ('[' === match[1] && ']' === match[7]) {
|
|
10
|
+
if ("[" === match[1] && "]" === match[7]) {
|
|
26
11
|
return next(tag, text, re.lastIndex);
|
|
27
12
|
}
|
|
28
13
|
const result = {
|
|
@@ -30,131 +15,42 @@ export function next(tag, text, index = 0) {
|
|
|
30
15
|
content: match[0],
|
|
31
16
|
shortcode: fromMatch(match)
|
|
32
17
|
};
|
|
33
|
-
|
|
34
|
-
// If we matched a leading `[`, strip it from the match and increment the
|
|
35
|
-
// index accordingly.
|
|
36
18
|
if (match[1]) {
|
|
37
19
|
result.content = result.content.slice(1);
|
|
38
20
|
result.index++;
|
|
39
21
|
}
|
|
40
|
-
|
|
41
|
-
// If we matched a trailing `]`, strip it from the match.
|
|
42
22
|
if (match[7]) {
|
|
43
23
|
result.content = result.content.slice(0, -1);
|
|
44
24
|
}
|
|
45
25
|
return result;
|
|
46
26
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* @return {string} Text with shortcodes replaced.
|
|
57
|
-
*/
|
|
58
|
-
export function replace(tag, text, callback) {
|
|
59
|
-
return text.replace(regexp(tag), function (match, left, $3, attrs, slash, content, closing, right) {
|
|
60
|
-
// If both extra brackets exist, the shortcode has been properly
|
|
61
|
-
// escaped.
|
|
62
|
-
if (left === '[' && right === ']') {
|
|
63
|
-
return match;
|
|
27
|
+
function replace(tag, text, callback) {
|
|
28
|
+
return text.replace(
|
|
29
|
+
regexp(tag),
|
|
30
|
+
function(match, left, $3, attrs2, slash, content, closing, right) {
|
|
31
|
+
if (left === "[" && right === "]") {
|
|
32
|
+
return match;
|
|
33
|
+
}
|
|
34
|
+
const result = callback(fromMatch(arguments));
|
|
35
|
+
return result || result === "" ? left + result + right : match;
|
|
64
36
|
}
|
|
65
|
-
|
|
66
|
-
// Create the match object and pass it through the callback.
|
|
67
|
-
const result = callback(fromMatch(arguments));
|
|
68
|
-
|
|
69
|
-
// Make sure to return any of the extra brackets if they weren't used to
|
|
70
|
-
// escape the shortcode.
|
|
71
|
-
return result || result === '' ? left + result + right : match;
|
|
72
|
-
});
|
|
37
|
+
);
|
|
73
38
|
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Generate a string from shortcode parameters.
|
|
77
|
-
*
|
|
78
|
-
* Creates a shortcode instance and returns a string.
|
|
79
|
-
*
|
|
80
|
-
* Accepts the same `options` as the `shortcode()` constructor, containing a
|
|
81
|
-
* `tag` string, a string or object of `attrs`, a boolean indicating whether to
|
|
82
|
-
* format the shortcode using a `single` tag, and a `content` string.
|
|
83
|
-
*
|
|
84
|
-
* @param {Object} options
|
|
85
|
-
*
|
|
86
|
-
* @return {string} String representation of the shortcode.
|
|
87
|
-
*/
|
|
88
|
-
export function string(options) {
|
|
39
|
+
function string(options) {
|
|
89
40
|
return new shortcode(options).string();
|
|
90
41
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
* `get_shortcode_regex()` in `wp-includes/shortcodes.php`.
|
|
97
|
-
*
|
|
98
|
-
* Capture groups:
|
|
99
|
-
*
|
|
100
|
-
* 1. An extra `[` to allow for escaping shortcodes with double `[[]]`
|
|
101
|
-
* 2. The shortcode name
|
|
102
|
-
* 3. The shortcode argument list
|
|
103
|
-
* 4. The self closing `/`
|
|
104
|
-
* 5. The content of a shortcode when it wraps some content.
|
|
105
|
-
* 6. The closing tag.
|
|
106
|
-
* 7. An extra `]` to allow for escaping shortcodes with double `[[]]`
|
|
107
|
-
*
|
|
108
|
-
* @param {string} tag Shortcode tag.
|
|
109
|
-
*
|
|
110
|
-
* @return {RegExp} Shortcode RegExp.
|
|
111
|
-
*/
|
|
112
|
-
export function regexp(tag) {
|
|
113
|
-
return new RegExp('\\[(\\[?)(' + tag + ')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)', 'g');
|
|
42
|
+
function regexp(tag) {
|
|
43
|
+
return new RegExp(
|
|
44
|
+
"\\[(\\[?)(" + tag + ")(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)",
|
|
45
|
+
"g"
|
|
46
|
+
);
|
|
114
47
|
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Parse shortcode attributes.
|
|
118
|
-
*
|
|
119
|
-
* Shortcodes accept many types of attributes. These can chiefly be divided into
|
|
120
|
-
* named and numeric attributes:
|
|
121
|
-
*
|
|
122
|
-
* Named attributes are assigned on a key/value basis, while numeric attributes
|
|
123
|
-
* are treated as an array.
|
|
124
|
-
*
|
|
125
|
-
* Named attributes can be formatted as either `name="value"`, `name='value'`,
|
|
126
|
-
* or `name=value`. Numeric attributes can be formatted as `"value"` or just
|
|
127
|
-
* `value`.
|
|
128
|
-
*
|
|
129
|
-
* @param {string} text Serialised shortcode attributes.
|
|
130
|
-
*
|
|
131
|
-
* @return {import('./types').ShortcodeAttrs} Parsed shortcode attributes.
|
|
132
|
-
*/
|
|
133
|
-
export const attrs = memize(text => {
|
|
48
|
+
const attrs = memize((text) => {
|
|
134
49
|
const named = {};
|
|
135
50
|
const numeric = [];
|
|
136
|
-
|
|
137
|
-
// This regular expression is reused from `shortcode_parse_atts()` in
|
|
138
|
-
// `wp-includes/shortcodes.php`.
|
|
139
|
-
//
|
|
140
|
-
// Capture groups:
|
|
141
|
-
//
|
|
142
|
-
// 1. An attribute name, that corresponds to...
|
|
143
|
-
// 2. a value in double quotes.
|
|
144
|
-
// 3. An attribute name, that corresponds to...
|
|
145
|
-
// 4. a value in single quotes.
|
|
146
|
-
// 5. An attribute name, that corresponds to...
|
|
147
|
-
// 6. an unquoted value.
|
|
148
|
-
// 7. A numeric attribute in double quotes.
|
|
149
|
-
// 8. A numeric attribute in single quotes.
|
|
150
|
-
// 9. An unquoted numeric attribute.
|
|
151
51
|
const pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g;
|
|
152
|
-
|
|
153
|
-
// Map zero-width spaces to actual spaces.
|
|
154
|
-
text = text.replace(/[\u00a0\u200b]/g, ' ');
|
|
52
|
+
text = text.replace(/[\u00a0\u200b]/g, " ");
|
|
155
53
|
let match;
|
|
156
|
-
|
|
157
|
-
// Match and normalize attributes.
|
|
158
54
|
while (match = pattern.exec(text)) {
|
|
159
55
|
if (match[1]) {
|
|
160
56
|
named[match[1].toLowerCase()] = match[2];
|
|
@@ -170,31 +66,16 @@ export const attrs = memize(text => {
|
|
|
170
66
|
numeric.push(match[9]);
|
|
171
67
|
}
|
|
172
68
|
}
|
|
173
|
-
return {
|
|
174
|
-
named,
|
|
175
|
-
numeric
|
|
176
|
-
};
|
|
69
|
+
return { named, numeric };
|
|
177
70
|
});
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Generate a Shortcode Object from a RegExp match.
|
|
181
|
-
*
|
|
182
|
-
* Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated
|
|
183
|
-
* by `regexp()`. `match` can also be set to the `arguments` from a callback
|
|
184
|
-
* passed to `regexp.replace()`.
|
|
185
|
-
*
|
|
186
|
-
* @param {import('./types').Match} match Match array.
|
|
187
|
-
*
|
|
188
|
-
* @return {InstanceType<import('./types').shortcode>} Shortcode instance.
|
|
189
|
-
*/
|
|
190
|
-
export function fromMatch(match) {
|
|
71
|
+
function fromMatch(match) {
|
|
191
72
|
let type;
|
|
192
73
|
if (match[4]) {
|
|
193
|
-
type =
|
|
74
|
+
type = "self-closing";
|
|
194
75
|
} else if (match[6]) {
|
|
195
|
-
type =
|
|
76
|
+
type = "closed";
|
|
196
77
|
} else {
|
|
197
|
-
type =
|
|
78
|
+
type = "single";
|
|
198
79
|
}
|
|
199
80
|
return new shortcode({
|
|
200
81
|
tag: match[2],
|
|
@@ -203,60 +84,37 @@ export function fromMatch(match) {
|
|
|
203
84
|
content: match[5]
|
|
204
85
|
});
|
|
205
86
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (!attributes) {
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
const attributeTypes = ['named', 'numeric'];
|
|
239
|
-
|
|
240
|
-
// Parse a string of attributes.
|
|
241
|
-
if (typeof attributes === 'string') {
|
|
242
|
-
this.attrs = attrs(attributes);
|
|
243
|
-
// Identify a correctly formatted `attrs` object.
|
|
244
|
-
} else if (attributes.length === attributeTypes.length && attributeTypes.every((t, key) => t === attributes[key])) {
|
|
245
|
-
this.attrs = attributes;
|
|
246
|
-
// Handle a flat object of attributes.
|
|
247
|
-
} else {
|
|
248
|
-
Object.entries(attributes).forEach(([key, value]) => {
|
|
249
|
-
this.set(key, value);
|
|
250
|
-
});
|
|
87
|
+
const shortcode = Object.assign(
|
|
88
|
+
function(options) {
|
|
89
|
+
const { tag, attrs: attributes, type, content } = options || {};
|
|
90
|
+
Object.assign(this, { tag, type, content });
|
|
91
|
+
this.attrs = {
|
|
92
|
+
named: {},
|
|
93
|
+
numeric: []
|
|
94
|
+
};
|
|
95
|
+
if (!attributes) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const attributeTypes = ["named", "numeric"];
|
|
99
|
+
if (typeof attributes === "string") {
|
|
100
|
+
this.attrs = attrs(attributes);
|
|
101
|
+
} else if (attributes.length === attributeTypes.length && attributeTypes.every((t, key) => t === attributes[key])) {
|
|
102
|
+
this.attrs = attributes;
|
|
103
|
+
} else {
|
|
104
|
+
Object.entries(attributes).forEach(([key, value]) => {
|
|
105
|
+
this.set(key, value);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
next,
|
|
111
|
+
replace,
|
|
112
|
+
string,
|
|
113
|
+
regexp,
|
|
114
|
+
attrs,
|
|
115
|
+
fromMatch
|
|
251
116
|
}
|
|
252
|
-
|
|
253
|
-
next,
|
|
254
|
-
replace,
|
|
255
|
-
string,
|
|
256
|
-
regexp,
|
|
257
|
-
attrs,
|
|
258
|
-
fromMatch
|
|
259
|
-
});
|
|
117
|
+
);
|
|
260
118
|
Object.assign(shortcode.prototype, {
|
|
261
119
|
/**
|
|
262
120
|
* Get a shortcode attribute.
|
|
@@ -269,7 +127,7 @@ Object.assign(shortcode.prototype, {
|
|
|
269
127
|
* @return {string} Attribute value.
|
|
270
128
|
*/
|
|
271
129
|
get(attr) {
|
|
272
|
-
return this.attrs[typeof attr ===
|
|
130
|
+
return this.attrs[typeof attr === "number" ? "numeric" : "named"][attr];
|
|
273
131
|
},
|
|
274
132
|
/**
|
|
275
133
|
* Set a shortcode attribute.
|
|
@@ -283,7 +141,7 @@ Object.assign(shortcode.prototype, {
|
|
|
283
141
|
* @return {InstanceType< import('./types').shortcode >} Shortcode instance.
|
|
284
142
|
*/
|
|
285
143
|
set(attr, value) {
|
|
286
|
-
this.attrs[typeof attr ===
|
|
144
|
+
this.attrs[typeof attr === "number" ? "numeric" : "named"][attr] = value;
|
|
287
145
|
return this;
|
|
288
146
|
},
|
|
289
147
|
/**
|
|
@@ -292,35 +150,37 @@ Object.assign(shortcode.prototype, {
|
|
|
292
150
|
* @return {string} String representation of the shortcode.
|
|
293
151
|
*/
|
|
294
152
|
string() {
|
|
295
|
-
let text =
|
|
296
|
-
this.attrs.numeric.forEach(value => {
|
|
153
|
+
let text = "[" + this.tag;
|
|
154
|
+
this.attrs.numeric.forEach((value) => {
|
|
297
155
|
if (/\s/.test(value)) {
|
|
298
156
|
text += ' "' + value + '"';
|
|
299
157
|
} else {
|
|
300
|
-
text +=
|
|
158
|
+
text += " " + value;
|
|
301
159
|
}
|
|
302
160
|
});
|
|
303
161
|
Object.entries(this.attrs.named).forEach(([name, value]) => {
|
|
304
|
-
text +=
|
|
162
|
+
text += " " + name + '="' + value + '"';
|
|
305
163
|
});
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
return text + ']';
|
|
311
|
-
} else if ('self-closing' === this.type) {
|
|
312
|
-
return text + ' /]';
|
|
164
|
+
if ("single" === this.type) {
|
|
165
|
+
return text + "]";
|
|
166
|
+
} else if ("self-closing" === this.type) {
|
|
167
|
+
return text + " /]";
|
|
313
168
|
}
|
|
314
|
-
|
|
315
|
-
// Complete the opening tag.
|
|
316
|
-
text += ']';
|
|
169
|
+
text += "]";
|
|
317
170
|
if (this.content) {
|
|
318
171
|
text += this.content;
|
|
319
172
|
}
|
|
320
|
-
|
|
321
|
-
// Add the closing tag.
|
|
322
|
-
return text + '[/' + this.tag + ']';
|
|
173
|
+
return text + "[/" + this.tag + "]";
|
|
323
174
|
}
|
|
324
175
|
});
|
|
325
|
-
|
|
326
|
-
|
|
176
|
+
var index_default = shortcode;
|
|
177
|
+
export {
|
|
178
|
+
attrs,
|
|
179
|
+
index_default as default,
|
|
180
|
+
fromMatch,
|
|
181
|
+
next,
|
|
182
|
+
regexp,
|
|
183
|
+
replace,
|
|
184
|
+
string
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
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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GAAG,IAAI,CAACD,GAAG,GAAG,GAAG;EACpC;AACD,CAAE,CAAC;AAEH,eAAeU,SAAS","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.js"],
|
|
4
|
+
"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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,CAAE;AAEF,WAAO,QAAS,KAAK,MAAM,KAAM,EAAE,QAAS,CAAE,CAAE,MAAM,KAAM,MAAO;AAClE,cAAQ,MAAM,OAAO,OAAO,QAAQ;AAAA,IACrC,CAAE;AAIF,QAAK,aAAa,KAAK,MAAO;AAC7B,aAAO,OAAO;AAAA,IACf,WAAY,mBAAmB,KAAK,MAAO;AAC1C,aAAO,OAAO;AAAA,IACf;AAGA,YAAQ;AAER,QAAK,KAAK,SAAU;AACnB,cAAQ,KAAK;AAAA,IACd;AAGA,WAAO,OAAO,OAAO,KAAK,MAAM;AAAA,EACjC;AACD,CAAE;AAEF,IAAO,gBAAQ;",
|
|
6
|
+
"names": ["attrs"]
|
|
7
|
+
}
|
package/build-module/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=types.js.map
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": [],
|
|
4
|
+
"sourcesContent": [],
|
|
5
|
+
"mappings": "",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/shortcode",
|
|
3
|
-
"version": "4.32.0",
|
|
3
|
+
"version": "4.32.1-next.b8c8708f3.0",
|
|
4
4
|
"description": "Shortcode module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -24,15 +24,23 @@
|
|
|
24
24
|
},
|
|
25
25
|
"main": "build/index.js",
|
|
26
26
|
"module": "build-module/index.js",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./build-types/index.d.ts",
|
|
30
|
+
"import": "./build-module/index.js",
|
|
31
|
+
"require": "./build/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./package.json": "./package.json"
|
|
34
|
+
},
|
|
27
35
|
"react-native": "src/index",
|
|
28
36
|
"wpScript": true,
|
|
37
|
+
"wpScriptDefaultExport": true,
|
|
29
38
|
"types": "build-types",
|
|
30
39
|
"dependencies": {
|
|
31
|
-
"@babel/runtime": "7.25.7",
|
|
32
40
|
"memize": "^2.0.1"
|
|
33
41
|
},
|
|
34
42
|
"publishConfig": {
|
|
35
43
|
"access": "public"
|
|
36
44
|
},
|
|
37
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "67cfd7e661931aeb0d06bec894599d287a4f8d0f"
|
|
38
46
|
}
|