| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 (function() { 2 "use strict"; 3 var wp; 4 (wp ||= {}).shortcode = (() => { 5 var __defProp = Object.defineProperty; 6 var __getOwnPropDesc = Object.getOwnPropertyDescriptor; 7 var __getOwnPropNames = Object.getOwnPropertyNames; 8 var __hasOwnProp = Object.prototype.hasOwnProperty; 9 var __export = (target, all) => { 10 for (var name in all) 11 __defProp(target, name, { get: all[name], enumerable: true }); 12 }; 13 var __copyProps = (to, from, except, desc) => { 14 if (from && typeof from === "object" || typeof from === "function") { 15 for (let key of __getOwnPropNames(from)) 16 if (!__hasOwnProp.call(to, key) && key !== except) 17 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); 18 } 19 return to; 20 }; 21 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); 22 23 // packages/shortcode/build-module/index.mjs 24 var index_exports = {}; 25 __export(index_exports, { 26 attrs: () => attrs, 27 default: () => index_default, 28 fromMatch: () => fromMatch, 29 next: () => next, 30 regexp: () => regexp, 31 replace: () => replace, 32 string: () => string 33 }); 34 35 // node_modules/memize/dist/index.js 36 function memize(fn, options) { 37 var size = 0; 38 var head; 39 var tail; 40 options = options || {}; 41 function memoized() { 42 var node = head, len = arguments.length, args, i; 43 searchCache: while (node) { 44 if (node.args.length !== arguments.length) { 45 node = node.next; 46 continue; 47 } 48 for (i = 0; i < len; i++) { 49 if (node.args[i] !== arguments[i]) { 50 node = node.next; 51 continue searchCache; 52 } 53 } 54 if (node !== head) { 55 if (node === tail) { 56 tail = node.prev; 57 } 58 node.prev.next = node.next; 59 if (node.next) { 60 node.next.prev = node.prev; 61 } 62 node.next = head; 63 node.prev = null; 64 head.prev = node; 65 head = node; 66 } 67 return node.val; 68 } 69 args = new Array(len); 70 for (i = 0; i < len; i++) { 71 args[i] = arguments[i]; 72 } 73 node = { 74 args, 75 // Generate the result from original function 76 val: fn.apply(null, args) 77 }; 78 if (head) { 79 head.prev = node; 80 node.next = head; 81 } else { 82 tail = node; 83 } 84 if (size === /** @type {MemizeOptions} */ 85 options.maxSize) { 86 tail = /** @type {MemizeCacheNode} */ 87 tail.prev; 88 tail.next = null; 89 } else { 90 size++; 91 } 92 head = node; 93 return node.val; 94 } 95 memoized.clear = function() { 96 head = null; 97 tail = null; 98 size = 0; 99 }; 100 return memoized; 101 } 102 103 // packages/shortcode/build-module/index.mjs 104 function next(tag, text, index = 0) { 105 const re = regexp(tag); 106 re.lastIndex = index; 107 const match = re.exec(text); 108 if (!match) { 109 return; 110 } 111 if ("[" === match[1] && "]" === match[7]) { 112 return next(tag, text, re.lastIndex); 113 } 114 const result = { 115 index: match.index, 116 content: match[0], 117 shortcode: fromMatch(match) 118 }; 119 if (match[1]) { 120 result.content = result.content.slice(1); 121 result.index++; 122 } 123 if (match[7]) { 124 result.content = result.content.slice(0, -1); 125 } 126 return result; 127 } 128 function replace(tag, text, callback) { 129 return text.replace( 130 regexp(tag), 131 // Let us use spread syntax to capture the arguments object. 132 (...args) => { 133 const match = args[0]; 134 const left = args[1]; 135 const right = args[7]; 136 if (left === "[" && right === "]") { 137 return match; 138 } 139 const result = callback(fromMatch(args)); 140 return result || result === "" ? left + result + right : match; 141 } 142 ); 143 } 144 function string(options) { 145 return new Shortcode(options).string(); 146 } 147 function regexp(tag) { 148 return new RegExp( 149 "\\[(\\[?)(" + tag + ")(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)", 150 "g" 151 ); 152 } 153 var attrs = memize((text) => { 154 const named = {}; 155 const numeric = []; 156 const pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g; 157 text = text.replace(/[\u00a0\u200b]/g, " "); 158 let match; 159 while (match = pattern.exec(text)) { 160 if (match[1]) { 161 named[match[1].toLowerCase()] = match[2]; 162 } else if (match[3]) { 163 named[match[3].toLowerCase()] = match[4]; 164 } else if (match[5]) { 165 named[match[5].toLowerCase()] = match[6]; 166 } else if (match[7]) { 167 numeric.push(match[7]); 168 } else if (match[8]) { 169 numeric.push(match[8]); 170 } else if (match[9]) { 171 numeric.push(match[9]); 172 } 173 } 174 return { named, numeric }; 175 }); 176 function fromMatch(match) { 177 let type; 178 if (match[4]) { 179 type = "self-closing"; 180 } else if (match[6]) { 181 type = "closed"; 182 } else { 183 type = "single"; 184 } 185 return new Shortcode({ 186 tag: match[2], 187 attrs: match[3], 188 type, 189 content: match[5] 190 }); 191 } 192 var Shortcode = class { 193 // Instance properties 194 tag; 195 type; 196 content; 197 attrs; 198 // Static methods 199 static next = next; 200 static replace = replace; 201 static string = string; 202 static regexp = regexp; 203 static attrs = attrs; 204 static fromMatch = fromMatch; 205 constructor(options) { 206 const { tag, attrs: attributes, type, content } = options; 207 this.tag = tag; 208 this.type = type; 209 this.content = content; 210 this.attrs = { 211 named: {}, 212 numeric: [] 213 }; 214 if (!attributes) { 215 return; 216 } 217 if (typeof attributes === "string") { 218 this.attrs = attrs(attributes); 219 } else if ("named" in attributes && "numeric" in attributes && attributes.named !== void 0 && attributes.numeric !== void 0) { 220 this.attrs = attributes; 221 } else { 222 Object.entries(attributes).forEach(([key, value]) => { 223 if (value !== void 0) { 224 this.set(key, String(value)); 225 } 226 }); 227 } 228 } 229 /** 230 * Get a shortcode attribute. 231 * 232 * Automatically detects whether `attr` is named or numeric and routes it 233 * accordingly. 234 * 235 * @param attr Attribute key. 236 * 237 * @return Attribute value. 238 */ 239 get(attr) { 240 if (typeof attr === "number") { 241 return this.attrs.numeric[attr]; 242 } 243 return this.attrs.named[attr]; 244 } 245 /** 246 * Set a shortcode attribute. 247 * 248 * Automatically detects whether `attr` is named or numeric and routes it 249 * accordingly. 250 * 251 * @param attr Attribute key. 252 * @param value Attribute value. 253 * 254 * @return Shortcode instance. 255 */ 256 set(attr, value) { 257 if (typeof attr === "number") { 258 this.attrs.numeric[attr] = value; 259 } else { 260 this.attrs.named[attr] = value; 261 } 262 return this; 263 } 264 /** 265 * Transform the shortcode into a string. 266 * 267 * @return String representation of the shortcode. 268 */ 269 string() { 270 let text = "[" + this.tag; 271 this.attrs.numeric.forEach((value) => { 272 if (/\s/.test(value)) { 273 text += ' "' + value + '"'; 274 } else { 275 text += " " + value; 276 } 277 }); 278 Object.entries(this.attrs.named).forEach(([name, value]) => { 279 text += " " + name + '="' + value + '"'; 280 }); 281 if ("single" === this.type) { 282 return text + "]"; 283 } else if ("self-closing" === this.type) { 284 return text + " /]"; 285 } 286 text += "]"; 287 if (this.content) { 288 text += this.content; 289 } 290 return text + "[/" + this.tag + "]"; 291 } 292 }; 293 var index_default = Shortcode; 294 return __toCommonJS(index_exports); 295 })(); 296 if (typeof wp.shortcode === 'object' && wp.shortcode.default) { wp.shortcode = wp.shortcode.default; } 297 (window.wp ||= {}).shortcode = wp.shortcode; 298 })();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sat Aug 8 08:20:21 2026 | Cross-referenced by PHPXref |