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