@vectojs/markdown 0.3.0 → 0.5.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/README.md +35 -2
- package/dist/Markdown.d.ts +66 -15
- package/dist/MarkdownWorkerSource.d.ts +1 -1
- package/dist/StreamController.d.ts +40 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +642 -76
- package/dist/index.mjs +646 -77
- package/package.json +5 -3
package/dist/index.js
CHANGED
|
@@ -30,6 +30,391 @@ module.exports = __toCommonJS(index_exports);
|
|
|
30
30
|
// src/Markdown.ts
|
|
31
31
|
var import_core = require("@vectojs/core");
|
|
32
32
|
var import_marked = require("marked");
|
|
33
|
+
|
|
34
|
+
// src/StreamController.ts
|
|
35
|
+
var DEFAULT_MAX_BUFFERED_CHARS = 64 * 1024;
|
|
36
|
+
var MAX_FRAME_DELTA_MS = 100;
|
|
37
|
+
var MIN_SCAN_CODE_UNITS = 64;
|
|
38
|
+
function positiveFinite(value, label) {
|
|
39
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
40
|
+
throw new RangeError(`${label} must be a positive finite number`);
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
function abortError() {
|
|
45
|
+
const error = new Error("Stream aborted");
|
|
46
|
+
error.name = "AbortError";
|
|
47
|
+
return error;
|
|
48
|
+
}
|
|
49
|
+
var StreamControllerImpl = class {
|
|
50
|
+
constructor(host, options) {
|
|
51
|
+
this.host = host;
|
|
52
|
+
this.maxBufferedChars = positiveFinite(
|
|
53
|
+
options.maxBufferedChars ?? DEFAULT_MAX_BUFFERED_CHARS,
|
|
54
|
+
"maxBufferedChars"
|
|
55
|
+
);
|
|
56
|
+
this.graphemesPerSecond = options.pacing ? positiveFinite(options.pacing.graphemesPerSecond, "pacing.graphemesPerSecond") : null;
|
|
57
|
+
this.segmenter = this.graphemesPerSecond === null ? null : new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
58
|
+
this.signal = options.signal;
|
|
59
|
+
this.onSignalAbort = () => this.abort(this.signal?.reason);
|
|
60
|
+
if (this.signal?.aborted) this.abort(this.signal.reason);
|
|
61
|
+
else this.signal?.addEventListener("abort", this.onSignalAbort, { once: true });
|
|
62
|
+
}
|
|
63
|
+
host;
|
|
64
|
+
maxBufferedChars;
|
|
65
|
+
graphemesPerSecond;
|
|
66
|
+
segmenter;
|
|
67
|
+
signal;
|
|
68
|
+
onSignalAbort;
|
|
69
|
+
chunks = [];
|
|
70
|
+
headIndex = 0;
|
|
71
|
+
headOffset = 0;
|
|
72
|
+
acceptedChars = 0;
|
|
73
|
+
blocked = null;
|
|
74
|
+
currentState = "open";
|
|
75
|
+
terminalReason = null;
|
|
76
|
+
rafId = null;
|
|
77
|
+
lastFrameAt = null;
|
|
78
|
+
graphemeCredit = 0;
|
|
79
|
+
released = false;
|
|
80
|
+
closePromise = null;
|
|
81
|
+
resolveClose = null;
|
|
82
|
+
rejectClose = null;
|
|
83
|
+
get state() {
|
|
84
|
+
return this.currentState;
|
|
85
|
+
}
|
|
86
|
+
get bufferedChars() {
|
|
87
|
+
return this.acceptedChars + (this.blocked?.chunk.length ?? 0);
|
|
88
|
+
}
|
|
89
|
+
write(chunk) {
|
|
90
|
+
if (this.currentState !== "open" || this.closePromise) {
|
|
91
|
+
return Promise.reject(this.reasonForWrite());
|
|
92
|
+
}
|
|
93
|
+
if (chunk.length === 0) return Promise.resolve();
|
|
94
|
+
if (this.blocked) {
|
|
95
|
+
return Promise.reject(new Error("StreamController already has a blocked write"));
|
|
96
|
+
}
|
|
97
|
+
if (this.canAdmit(chunk)) {
|
|
98
|
+
this.admit(chunk);
|
|
99
|
+
try {
|
|
100
|
+
this.schedule();
|
|
101
|
+
return Promise.resolve();
|
|
102
|
+
} catch (error) {
|
|
103
|
+
return Promise.reject(error);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
const blocked = { chunk, resolve, reject };
|
|
108
|
+
this.blocked = blocked;
|
|
109
|
+
try {
|
|
110
|
+
this.schedule();
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (this.blocked === blocked) this.blocked = null;
|
|
113
|
+
reject(error);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
flush() {
|
|
118
|
+
if (this.currentState === "closed") return;
|
|
119
|
+
if (this.currentState === "aborted") throw this.terminalReason;
|
|
120
|
+
this.cancelFrame();
|
|
121
|
+
this.commitAllSubmitted();
|
|
122
|
+
this.resetPacingIfIdle();
|
|
123
|
+
}
|
|
124
|
+
close() {
|
|
125
|
+
if (this.currentState === "closed") return Promise.resolve();
|
|
126
|
+
if (this.currentState === "aborted") return Promise.reject(this.terminalReason);
|
|
127
|
+
if (this.closePromise) return this.closePromise;
|
|
128
|
+
let resolveClose;
|
|
129
|
+
let rejectClose;
|
|
130
|
+
const closePromise = new Promise((resolve, reject) => {
|
|
131
|
+
resolveClose = resolve;
|
|
132
|
+
rejectClose = reject;
|
|
133
|
+
});
|
|
134
|
+
this.closePromise = closePromise;
|
|
135
|
+
this.resolveClose = resolveClose;
|
|
136
|
+
this.rejectClose = rejectClose;
|
|
137
|
+
this.cancelFrame();
|
|
138
|
+
try {
|
|
139
|
+
this.commitAllSubmitted();
|
|
140
|
+
} catch (error) {
|
|
141
|
+
this.rejectPendingClose(error);
|
|
142
|
+
return closePromise;
|
|
143
|
+
}
|
|
144
|
+
if (this.currentState !== "open") {
|
|
145
|
+
this.rejectPendingClose(this.terminalReason);
|
|
146
|
+
return closePromise;
|
|
147
|
+
}
|
|
148
|
+
this.currentState = "closed";
|
|
149
|
+
this.cleanup();
|
|
150
|
+
this.resolveClose?.();
|
|
151
|
+
this.resolveClose = null;
|
|
152
|
+
this.rejectClose = null;
|
|
153
|
+
return closePromise;
|
|
154
|
+
}
|
|
155
|
+
abort(reason) {
|
|
156
|
+
if (this.currentState !== "open") return;
|
|
157
|
+
this.fail(reason === void 0 ? abortError() : reason);
|
|
158
|
+
}
|
|
159
|
+
destroy() {
|
|
160
|
+
this.abort();
|
|
161
|
+
}
|
|
162
|
+
onFrame = (timestamp) => {
|
|
163
|
+
this.rafId = null;
|
|
164
|
+
if (this.currentState !== "open") return;
|
|
165
|
+
let keepScheduling = true;
|
|
166
|
+
try {
|
|
167
|
+
if (this.graphemesPerSecond === null) this.commitAccepted();
|
|
168
|
+
else keepScheduling = this.commitPaced(timestamp);
|
|
169
|
+
} catch {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (this.currentState !== "open") return;
|
|
173
|
+
this.admitBlockedIfPossible();
|
|
174
|
+
this.resetPacingIfIdle();
|
|
175
|
+
if (!keepScheduling) return;
|
|
176
|
+
try {
|
|
177
|
+
this.schedule();
|
|
178
|
+
} catch {
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
reasonForWrite() {
|
|
182
|
+
if (this.currentState === "aborted") return this.terminalReason;
|
|
183
|
+
if (this.currentState === "closed") return new Error("StreamController is closed");
|
|
184
|
+
return new Error("StreamController is closing");
|
|
185
|
+
}
|
|
186
|
+
canAdmit(chunk) {
|
|
187
|
+
return this.acceptedChars + chunk.length <= this.maxBufferedChars || this.acceptedChars === 0 && chunk.length > this.maxBufferedChars;
|
|
188
|
+
}
|
|
189
|
+
admit(chunk) {
|
|
190
|
+
this.chunks.push(chunk);
|
|
191
|
+
this.acceptedChars += chunk.length;
|
|
192
|
+
}
|
|
193
|
+
admitBlockedIfPossible() {
|
|
194
|
+
const blocked = this.blocked;
|
|
195
|
+
if (!blocked || !this.canAdmit(blocked.chunk)) return;
|
|
196
|
+
this.blocked = null;
|
|
197
|
+
this.admit(blocked.chunk);
|
|
198
|
+
blocked.resolve();
|
|
199
|
+
}
|
|
200
|
+
schedule() {
|
|
201
|
+
if (this.currentState !== "open" || this.acceptedChars === 0 || this.rafId !== null) return;
|
|
202
|
+
if (typeof requestAnimationFrame !== "function") {
|
|
203
|
+
this.flush();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
this.rafId = requestAnimationFrame(this.onFrame);
|
|
207
|
+
}
|
|
208
|
+
cancelFrame() {
|
|
209
|
+
if (this.rafId === null) return;
|
|
210
|
+
if (typeof cancelAnimationFrame === "function") cancelAnimationFrame(this.rafId);
|
|
211
|
+
this.rafId = null;
|
|
212
|
+
}
|
|
213
|
+
commitAccepted() {
|
|
214
|
+
if (this.acceptedChars === 0) return;
|
|
215
|
+
const text = this.takeAcceptedText();
|
|
216
|
+
try {
|
|
217
|
+
this.host.append(text);
|
|
218
|
+
} catch (error) {
|
|
219
|
+
this.fail(error);
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/** Return true while another frame can make progress without more producer input. */
|
|
224
|
+
commitPaced(timestamp) {
|
|
225
|
+
if (this.lastFrameAt === null) {
|
|
226
|
+
this.lastFrameAt = timestamp;
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
const delta = Math.min(MAX_FRAME_DELTA_MS, Math.max(0, timestamp - this.lastFrameAt));
|
|
230
|
+
this.lastFrameAt = timestamp;
|
|
231
|
+
this.graphemeCredit += delta * this.graphemesPerSecond / 1e3;
|
|
232
|
+
const available = Math.floor(this.graphemeCredit);
|
|
233
|
+
if (available < 1) return true;
|
|
234
|
+
const selected = this.selectGraphemePrefix(available);
|
|
235
|
+
if (selected.count === 0) {
|
|
236
|
+
this.lastFrameAt = null;
|
|
237
|
+
this.graphemeCredit = 0;
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
const completedBlocked = this.consumeSubmittedChars(selected.codeUnits);
|
|
241
|
+
try {
|
|
242
|
+
this.host.append(selected.text);
|
|
243
|
+
completedBlocked?.resolve();
|
|
244
|
+
} catch (error) {
|
|
245
|
+
completedBlocked?.reject(error);
|
|
246
|
+
this.fail(error);
|
|
247
|
+
throw error;
|
|
248
|
+
}
|
|
249
|
+
this.graphemeCredit -= selected.count;
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
selectGraphemePrefix(maxCount) {
|
|
253
|
+
const submittedChars = this.acceptedChars + (this.blocked?.chunk.length ?? 0);
|
|
254
|
+
let scanLength = Math.min(submittedChars, Math.max(MIN_SCAN_CODE_UNITS, maxCount * 2));
|
|
255
|
+
while (scanLength > 0) {
|
|
256
|
+
let sample = this.peekSubmittedChars(scanLength);
|
|
257
|
+
if (scanLength < submittedChars && /[\uD800-\uDBFF]$/.test(sample)) {
|
|
258
|
+
scanLength++;
|
|
259
|
+
sample = this.peekSubmittedChars(scanLength);
|
|
260
|
+
}
|
|
261
|
+
const segments = [...this.segmenter.segment(sample)];
|
|
262
|
+
const hasUnscannedText = scanLength < submittedChars;
|
|
263
|
+
if (hasUnscannedText && segments.length <= maxCount) {
|
|
264
|
+
scanLength = Math.min(submittedChars, scanLength * 2);
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
const count = hasUnscannedText ? maxCount : Math.min(maxCount, Math.max(0, segments.length - 1));
|
|
268
|
+
if (count > 0) {
|
|
269
|
+
const last = segments[count - 1];
|
|
270
|
+
const codeUnits = last.index + last.segment.length;
|
|
271
|
+
return { text: sample.slice(0, codeUnits), count, codeUnits };
|
|
272
|
+
}
|
|
273
|
+
if (this.blocked || this.acceptedChars > this.maxBufferedChars) {
|
|
274
|
+
return this.forceCodePointPrefix(sample);
|
|
275
|
+
}
|
|
276
|
+
return { text: "", count: 0, codeUnits: 0 };
|
|
277
|
+
}
|
|
278
|
+
return { text: "", count: 0, codeUnits: 0 };
|
|
279
|
+
}
|
|
280
|
+
forceCodePointPrefix(sample) {
|
|
281
|
+
const first = sample.charCodeAt(0);
|
|
282
|
+
const second = sample.charCodeAt(1);
|
|
283
|
+
const codeUnits = first >= 55296 && first <= 56319 && second >= 56320 && second <= 57343 ? 2 : 1;
|
|
284
|
+
return { text: sample.slice(0, codeUnits), count: 1, codeUnits };
|
|
285
|
+
}
|
|
286
|
+
peekSubmittedChars(limit) {
|
|
287
|
+
const parts = this.peekAcceptedParts(Math.min(limit, this.acceptedChars));
|
|
288
|
+
const acceptedLength = Math.min(limit, this.acceptedChars);
|
|
289
|
+
const blockedLength = limit - acceptedLength;
|
|
290
|
+
if (blockedLength > 0 && this.blocked) {
|
|
291
|
+
parts.push(this.blocked.chunk.slice(0, blockedLength));
|
|
292
|
+
}
|
|
293
|
+
return parts.length === 1 ? parts[0] : parts.join("");
|
|
294
|
+
}
|
|
295
|
+
peekAcceptedParts(limit) {
|
|
296
|
+
if (limit <= 0) return [];
|
|
297
|
+
const parts = [];
|
|
298
|
+
let remaining = limit;
|
|
299
|
+
for (let index = this.headIndex; index < this.chunks.length && remaining > 0; index++) {
|
|
300
|
+
const chunk = this.chunks[index];
|
|
301
|
+
const start = index === this.headIndex ? this.headOffset : 0;
|
|
302
|
+
const available = chunk.length - start;
|
|
303
|
+
if (available <= remaining) {
|
|
304
|
+
parts.push(start === 0 ? chunk : chunk.slice(start));
|
|
305
|
+
remaining -= available;
|
|
306
|
+
} else {
|
|
307
|
+
parts.push(chunk.slice(start, start + remaining));
|
|
308
|
+
remaining = 0;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return parts;
|
|
312
|
+
}
|
|
313
|
+
consumeSubmittedChars(count) {
|
|
314
|
+
const acceptedCount = Math.min(count, this.acceptedChars);
|
|
315
|
+
this.consumeAcceptedChars(acceptedCount);
|
|
316
|
+
const blockedCount = count - acceptedCount;
|
|
317
|
+
if (blockedCount === 0) return null;
|
|
318
|
+
const blocked = this.blocked;
|
|
319
|
+
if (!blocked) throw new Error("StreamController queue accounting diverged");
|
|
320
|
+
if (blockedCount >= blocked.chunk.length) {
|
|
321
|
+
this.blocked = null;
|
|
322
|
+
return blocked;
|
|
323
|
+
}
|
|
324
|
+
blocked.chunk = blocked.chunk.slice(blockedCount);
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
consumeAcceptedChars(count) {
|
|
328
|
+
if (count < 0 || count > this.acceptedChars) {
|
|
329
|
+
throw new Error("StreamController queue accounting diverged");
|
|
330
|
+
}
|
|
331
|
+
this.acceptedChars -= count;
|
|
332
|
+
let remaining = count;
|
|
333
|
+
while (remaining > 0) {
|
|
334
|
+
const chunk = this.chunks[this.headIndex];
|
|
335
|
+
const available = chunk.length - this.headOffset;
|
|
336
|
+
if (remaining < available) {
|
|
337
|
+
this.headOffset += remaining;
|
|
338
|
+
remaining = 0;
|
|
339
|
+
} else {
|
|
340
|
+
remaining -= available;
|
|
341
|
+
this.headIndex++;
|
|
342
|
+
this.headOffset = 0;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (this.acceptedChars === 0) {
|
|
346
|
+
this.chunks = [];
|
|
347
|
+
this.headIndex = 0;
|
|
348
|
+
this.headOffset = 0;
|
|
349
|
+
} else if (this.headIndex >= 64 && this.headIndex * 2 >= this.chunks.length) {
|
|
350
|
+
this.chunks.splice(0, this.headIndex);
|
|
351
|
+
this.headIndex = 0;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
takeAcceptedText() {
|
|
355
|
+
const parts = this.takeAcceptedParts();
|
|
356
|
+
return parts.length === 1 ? parts[0] : parts.join("");
|
|
357
|
+
}
|
|
358
|
+
takeAcceptedParts() {
|
|
359
|
+
const parts = this.peekAcceptedParts(this.acceptedChars);
|
|
360
|
+
this.chunks = [];
|
|
361
|
+
this.headIndex = 0;
|
|
362
|
+
this.headOffset = 0;
|
|
363
|
+
this.acceptedChars = 0;
|
|
364
|
+
return parts;
|
|
365
|
+
}
|
|
366
|
+
commitAllSubmitted() {
|
|
367
|
+
const blocked = this.blocked;
|
|
368
|
+
this.blocked = null;
|
|
369
|
+
const parts = this.takeAcceptedParts();
|
|
370
|
+
if (blocked) parts.push(blocked.chunk);
|
|
371
|
+
if (parts.length === 0) return;
|
|
372
|
+
try {
|
|
373
|
+
this.host.append(parts.length === 1 ? parts[0] : parts.join(""));
|
|
374
|
+
blocked?.resolve();
|
|
375
|
+
} catch (error) {
|
|
376
|
+
blocked?.reject(error);
|
|
377
|
+
this.fail(error);
|
|
378
|
+
throw error;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
rejectPendingClose(reason) {
|
|
382
|
+
this.rejectClose?.(reason);
|
|
383
|
+
this.resolveClose = null;
|
|
384
|
+
this.rejectClose = null;
|
|
385
|
+
}
|
|
386
|
+
fail(reason) {
|
|
387
|
+
if (this.currentState !== "open") return;
|
|
388
|
+
this.currentState = "aborted";
|
|
389
|
+
this.terminalReason = reason;
|
|
390
|
+
this.cancelFrame();
|
|
391
|
+
this.chunks = [];
|
|
392
|
+
this.headIndex = 0;
|
|
393
|
+
this.headOffset = 0;
|
|
394
|
+
this.acceptedChars = 0;
|
|
395
|
+
const blocked = this.blocked;
|
|
396
|
+
this.blocked = null;
|
|
397
|
+
blocked?.reject(reason);
|
|
398
|
+
this.rejectPendingClose(reason);
|
|
399
|
+
this.cleanup();
|
|
400
|
+
}
|
|
401
|
+
cleanup() {
|
|
402
|
+
this.signal?.removeEventListener("abort", this.onSignalAbort);
|
|
403
|
+
if (this.released) return;
|
|
404
|
+
this.released = true;
|
|
405
|
+
this.host.release(this);
|
|
406
|
+
}
|
|
407
|
+
resetPacingIfIdle() {
|
|
408
|
+
if (this.acceptedChars !== 0 || this.blocked) return;
|
|
409
|
+
this.lastFrameAt = null;
|
|
410
|
+
this.graphemeCredit = 0;
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
function createStreamController(host, options = {}) {
|
|
414
|
+
return new StreamControllerImpl(host, options);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// src/Markdown.ts
|
|
33
418
|
var import_mathjax = require("mathjax-full/js/mathjax.js");
|
|
34
419
|
var import_tex = require("mathjax-full/js/input/tex.js");
|
|
35
420
|
var import_svg = require("mathjax-full/js/output/svg.js");
|
|
@@ -39,10 +424,19 @@ var import_AllPackages = require("mathjax-full/js/input/tex/AllPackages.js");
|
|
|
39
424
|
var import_ui = require("@vectojs/ui");
|
|
40
425
|
|
|
41
426
|
// src/MarkdownWorkerSource.ts
|
|
42
|
-
var WORKER_SOURCE_STRING = '"use strict";(()=>{function O(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var T=O();function oe(r){T=r}var R={exec:()=>null};function z(r){let e=[];return t=>{let s=Math.max(0,Math.min(3,t-1)),n=e[s];return n||(n=r(s),e[s]=n),n}}function g(r,e=""){let t=typeof r=="string"?r:r.source,s={replace:(n,i)=>{let a=typeof i=="string"?i:i.source;return a=a.replace(x.caret,"$1"),t=t.replace(n,a),s},getRegex:()=>new RegExp(t,e)};return s}var me=((r="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+r)}catch{return!1}})(),x={codeRemoveIndent:/^(?: {1,4}| {0,3}\\t)/gm,outputLinkReplace:/\\\\([\\[\\]])/g,indentCodeCompensation:/^(\\s+)(?:```)/,beginningSpace:/^\\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\\n/g,tabCharGlobal:/\\t/g,multipleSpaceGlobal:/\\s+/g,blankLine:/^[ \\t]*$/,doubleBlankLine:/\\n[ \\t]*\\n[ \\t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\\n {0,3}((?:=+|-+) *)(?=\\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \\t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\\[[ xX]\\] +\\S/,listReplaceTask:/^\\[[ xX]\\] +/,listTaskCheckbox:/\\[[ xX]\\]/,anyLine:/\\n.*\\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\\||\\| *$/g,tableRowBlankLine:/\\n[ \\t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\\s|>)/i,endPreScriptTag:/^<\\/(pre|code|kbd|script)(\\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^\'"]*[^\\s])\\s+([\'"])(.*)\\2/,unicodeAlphaNumeric:/[\\p{L}\\p{N}]/u,escapeTest:/[&<>"\']/,escapeReplace:/[&<>"\']/g,escapeTestNoEncode:/[<>"\']|&(?!(#\\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\\w+);)/,escapeReplaceNoEncode:/[<>"\']|&(?!(#\\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\\w+);)/g,caret:/(^|[^\\[])\\^/g,percentDecode:/%25/g,findPipe:/\\|/g,splitPipe:/ \\|/,slashPipe:/\\\\\\|/g,carriageReturn:/\\r\\n|\\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\\S*/,endingNewline:/\\n$/,listItemRegex:r=>new RegExp(`^( {0,3}${r})((?:[ ][^\\\\n]*)?(?:\\\\n|$))`),nextBulletRegex:z(r=>new RegExp(`^ {0,${r}}(?:[*+-]|\\\\d{1,9}[.)])((?:[ ][^\\\\n]*)?(?:\\\\n|$))`)),hrRegex:z(r=>new RegExp(`^ {0,${r}}((?:- *){3,}|(?:_ *){3,}|(?:\\\\* *){3,})(?:\\\\n+|$)`)),fencesBeginRegex:z(r=>new RegExp(`^ {0,${r}}(?:\\`\\`\\`|~~~)`)),headingBeginRegex:z(r=>new RegExp(`^ {0,${r}}#`)),htmlBeginRegex:z(r=>new RegExp(`^ {0,${r}}<(?:[a-z].*>|!--)`,"i")),blockquoteBeginRegex:z(r=>new RegExp(`^ {0,${r}}>`))},ye=/^(?:[ \\t]*(?:\\n|$))+/,$e=/^((?: {4}| {0,3}\\t)[^\\n]+(?:\\n(?:[ \\t]*(?:\\n|$))*)?)+/,Re=/^ {0,3}(`{3,}(?=[^`\\n]*(?:\\n|$))|~{3,})([^\\n]*)(?:\\n|$)(?:|([\\s\\S]*?)(?:\\n|$))(?: {0,3}\\1[~`]* *(?=\\n|$)|$)/,v=/^ {0,3}((?:-[\\t ]*){3,}|(?:_[ \\t]*){3,}|(?:\\*[ \\t]*){3,})(?:\\n+|$)/,Se=/^ {0,3}(#{1,6})(?=\\s|$)(.*)(?:\\n+|$)/,N=/ {0,3}(?:[*+-]|\\d{1,9}[.)])/,ce=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\\n(?!\\s*?\\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\\n {0,3}(=+|-+) *(?:\\n+|$)/,he=g(ce).replace(/bull/g,N).replace(/blockCode/g,/(?: {4}| {0,3}\\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\\s|$)/).replace(/html/g,/ {0,3}<[^\\n>]+>\\n/).replace(/\\|table/g,"").getRegex(),Te=g(ce).replace(/bull/g,N).replace(/blockCode/g,/(?: {4}| {0,3}\\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\\s|$)/).replace(/html/g,/ {0,3}<[^\\n>]+>\\n/).replace(/table/g,/ {0,3}\\|?(?:[:\\- ]*\\|)+[\\:\\- ]*\\n/).getRegex(),G=/^([^\\n]+(?:\\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \\t]+\\n)[^\\n]+)*)/,ze=/^[^\\n]+/,X=/(?!\\s*\\])(?:\\\\[\\s\\S]|[^\\[\\]\\\\])+/,Ae=g(/^ {0,3}\\[(label)\\]: *(?:\\n[ \\t]*)?([^<\\s][^\\s]*|<.*?>)(?:(?: +(?:\\n[ \\t]*)?| *\\n[ \\t]*)(title))? *(?:\\n+|$)/).replace("label",X).replace("title",/(?:"(?:\\\\"?|[^"\\\\])*"|\'[^\'\\n]*(?:\\n[^\'\\n]+)*\\n?\'|\\([^()]*\\))/).getRegex(),_e=g(/^(bull)([ \\t][^\\n]*?)?(?:\\n|$)/).replace(/bull/g,N).getRegex(),q="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",W=/<!--(?:-?>|[\\s\\S]*?(?:-->|$))/,Pe=g("^ {0,3}(?:<(script|pre|style|textarea)[\\\\s>][\\\\s\\\\S]*?(?:</\\\\1>[^\\\\n]*\\\\n*|$)|comment[^\\\\n]*(\\\\n+|$)|<\\\\?[\\\\s\\\\S]*?(?:\\\\?>[^\\\\n]*\\\\n*|$)|<![A-Z][\\\\s\\\\S]*?(?:>[^\\\\n]*\\\\n*|$)|<!\\\\[CDATA\\\\[[\\\\s\\\\S]*?(?:\\\\]\\\\]>[^\\\\n]*\\\\n*|$)|</?(tag)(?: +|\\\\n|/?>)[\\\\s\\\\S]*?(?:(?:\\\\n[ ]*)+\\\\n|$)|<(?!script|pre|style|textarea)([a-z][\\\\w-]*)(?:attribute)*? */?>(?=[ \\\\t]*(?:\\\\n|$))[\\\\s\\\\S]*?(?:(?:\\\\n[ ]*)+\\\\n|$)|</(?!script|pre|style|textarea)[a-z][\\\\w-]*\\\\s*>(?=[ \\\\t]*(?:\\\\n|$))[\\\\s\\\\S]*?(?:(?:\\\\n[ ]*)+\\\\n|$))","i").replace("comment",W).replace("tag",q).replace("attribute",/ +[a-zA-Z:_][\\w.:-]*(?: *= *"[^"\\n]*"| *= *\'[^\'\\n]*\'| *= *[^\\s"\'=<>`]+)?/).getRegex(),pe=r=>g(G).replace("hr",v).replace("heading"," {0,3}#{1,6}(?:\\\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\\\n]*\\\\n)|~~~)[^\\\\n]*\\\\n").replace("list",r).replace("html","</?(?:tag)(?: +|\\\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",q).getRegex(),Le=pe(/ {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]/),ve=pe(/ {0,3}(?:[*+-]|\\d{1,9}[.)])(?:[ \\t]|\\n|$)/),Ie=g(/^( {0,3}> ?(paragraph|[^\\n]*)(?:\\n|$))+/).replace("paragraph",ve).getRegex(),F={blockquote:Ie,code:$e,def:Ae,fences:Re,heading:Se,hr:v,html:Pe,lheading:he,list:_e,newline:ye,paragraph:Le,table:R,text:ze},te=g("^ *([^\\\\n ].*)\\\\n {0,3}((?:\\\\| *)?:?-+:? *(?:\\\\| *:?-+:? *)*(?:\\\\| *)?)(?:\\\\n((?:(?! *\\\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\\\n|$))*)\\\\n*|$)").replace("hr",v).replace("heading"," {0,3}#{1,6}(?:\\\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\\\n]*\\\\n)|~~~)[^\\\\n]*\\\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\\\t]").replace("html","</?(?:tag)(?: +|\\\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",q).getRegex(),Ee={...F,lheading:Te,table:te,paragraph:g(G).replace("hr",v).replace("heading"," {0,3}#{1,6}(?:\\\\s|$)").replace("|lheading","").replace("table",te).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\\\n]*\\\\n)|~~~)[^\\\\n]*\\\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\\\t]+[^ \\\\t\\\\n]").replace("html","</?(?:tag)(?: +|\\\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",q).getRegex()},Ce={...F,html:g(`^ *(?:comment *(?:\\\\n|\\\\s*$)|<(tag)[\\\\s\\\\S]+?</\\\\1> *(?:\\\\n{2,}|\\\\s*$)|<tag(?:"[^"]*"|\'[^\']*\'|\\\\s[^\'"/>\\\\s]*)*?/?> *(?:\\\\n{2,}|\\\\s*$))`).replace("comment",W).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\\\b)\\\\w+(?!:|[^\\\\w\\\\s@]*@)\\\\b").getRegex(),def:/^ *\\[([^\\]]+)\\]: *<?([^\\s>]+)>?(?: +(["(][^\\n]+[")]))? *(?:\\n+|$)/,heading:/^(#{1,6})(.*)(?:\\n+|$)/,fences:R,lheading:/^(.+?)\\n {0,3}(=+|-+) *(?:\\n+|$)/,paragraph:g(G).replace("hr",v).replace("heading",` *#{1,6} *[^\n]`).replace("lheading",he).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Be=/^\\\\([!"#$%&\'()*+,\\-./:;<=>?@\\[\\]\\\\^_`{|}~])/,qe=/^(`+)([^`]|[^`][\\s\\S]*?[^`])\\1(?!`)/,ue=/^( {2,}|\\\\)\\n(?!\\s*$)/,Ze=/^(`+|[^`])(?:(?= {2,}\\n)|[\\s\\S]*?(?:(?=[\\\\<!\\[`*_]|\\b_|$)|[^ ](?= {2,}\\n)))/,A=/[\\p{P}\\p{S}]/u,Z=/[\\s\\p{P}\\p{S}]/u,U=/[^\\s\\p{P}\\p{S}]/u,De=g(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Z).getRegex(),ge=/(?!~)[\\p{P}\\p{S}]/u,Me=/(?!~)[\\s\\p{P}\\p{S}]/u,Qe=/(?:[^\\s\\p{P}\\p{S}]|~)/u,je=g(/link|precode-code|html/,"g").replace("link",/\\[(?:[^\\[\\]`]|(?<a>`+)[^`]+\\k<a>(?!`))*?\\]\\((?:\\\\[\\s\\S]|[^\\\\\\(\\)]|\\((?:\\\\[\\s\\S]|[^\\\\\\(\\)])*\\))*\\)/).replace("precode-",me?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),ke=/^(?:\\*+(?:((?!\\*)punct)|([^\\s*]))?)|^_+(?:((?!_)punct)|([^\\s_]))?/,He=g(ke,"u").replace(/punct/g,A).getRegex(),Oe=g(ke,"u").replace(/punct/g,ge).getRegex(),de="^[^_*]*?__[^_*]*?\\\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\\\*)punct(\\\\*+)(?=[\\\\s]|$)|notPunctSpace(\\\\*+)(?!\\\\*)(?=punctSpace|$)|(?!\\\\*)punctSpace(\\\\*+)(?=notPunctSpace)|[\\\\s](\\\\*+)(?!\\\\*)(?=punct)|(?!\\\\*)punct(\\\\*+)(?!\\\\*)(?=punct)|notPunctSpace(\\\\*+)(?=notPunctSpace)",Ne=g(de,"gu").replace(/notPunctSpace/g,U).replace(/punctSpace/g,Z).replace(/punct/g,A).getRegex(),Ge=g(de,"gu").replace(/notPunctSpace/g,Qe).replace(/punctSpace/g,Me).replace(/punct/g,ge).getRegex(),Xe=g("^[^_*]*?\\\\*\\\\*[^_*]*?_[^_*]*?(?=\\\\*\\\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,U).replace(/punctSpace/g,Z).replace(/punct/g,A).getRegex(),We=g(/^~~?(?:((?!~)punct)|[^\\s~])/,"u").replace(/punct/g,A).getRegex(),Fe="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",Ue=g(Fe,"gu").replace(/notPunctSpace/g,U).replace(/punctSpace/g,Z).replace(/punct/g,A).getRegex(),Ve=g(/\\\\(punct)/,"gu").replace(/punct/g,A).getRegex(),Je=g(/^<(scheme:[^\\s\\x00-\\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&\'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Ke=g(W).replace("(?:-->|$)","-->").getRegex(),Ye=g("^comment|^</[a-zA-Z][\\\\w:-]*\\\\s*>|^<[a-zA-Z][\\\\w-]*(?:attribute)*?\\\\s*/?>|^<\\\\?[\\\\s\\\\S]*?\\\\?>|^<![a-zA-Z]+\\\\s[\\\\s\\\\S]*?>|^<!\\\\[CDATA\\\\[[\\\\s\\\\S]*?\\\\]\\\\]>").replace("comment",Ke).replace("attribute",/\\s+[a-zA-Z:_][\\w.:-]*(?:\\s*=\\s*"[^"]*"|\\s*=\\s*\'[^\']*\'|\\s*=\\s*[^\\s"\'=<>`]+)?/).getRegex(),E=/(?:\\[(?:\\\\[\\s\\S]|[^\\[\\]\\\\])*\\]|\\\\[\\s\\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\\])|[^\\[\\]\\\\`])*?/,et=g(/^!?\\[(label)\\]\\(\\s*(href)(?:(?:[ \\t]+(?:\\n[ \\t]*)?|\\n[ \\t]*)(title))?\\s*\\)/).replace("label",E).replace("href",/<(?:\\\\.|[^\\n<>\\\\])+>|[^ \\t\\n\\x00-\\x1f]+|(?=\\))/).replace("title",/"(?:\\\\"?|[^"\\\\])*"|\'(?:\\\\\'?|[^\'\\\\])*\'|\\((?:\\\\\\)?|[^)\\\\])*\\)/).getRegex(),fe=g(/^!?\\[(label)\\]\\[(ref)\\]/).replace("label",E).replace("ref",X).getRegex(),xe=g(/^!?\\[(ref)\\](?:\\[\\])?/).replace("ref",X).getRegex(),tt=g("reflink|nolink(?!\\\\()","g").replace("reflink",fe).replace("nolink",xe).getRegex(),re=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,V={_backpedal:R,anyPunctuation:Ve,autolink:Je,blockSkip:je,br:ue,code:qe,del:R,delLDelim:R,delRDelim:R,emStrongLDelim:He,emStrongRDelimAst:Ne,emStrongRDelimUnd:Xe,escape:Be,link:et,nolink:xe,punctuation:De,reflink:fe,reflinkSearch:tt,tag:Ye,text:Ze,url:R},rt={...V,link:g(/^!?\\[(label)\\]\\((.*?)\\)/).replace("label",E).getRegex(),reflink:g(/^!?\\[(label)\\]\\s*\\[([^\\]]*)\\]/).replace("label",E).getRegex()},Q={...V,emStrongRDelimAst:Ge,emStrongLDelim:Oe,delLDelim:We,delRDelim:Ue,url:g(/^((?:protocol):\\/\\/|www\\.)(?:[a-zA-Z0-9\\-]+\\.?)+[^\\s<]*|^email/).replace("protocol",re).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_\'"~()&]+|\\([^)]*\\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_\'"~)]+(?!$))+/,del:/^(~~?)(?=[^\\s~])((?:\\\\[\\s\\S]|[^\\\\])*?(?:\\\\[\\s\\S]|[^\\s~\\\\]))\\1(?=[^~]|$)/,text:g(/^(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\\n)|(?=[a-zA-Z0-9.!#$%&\'*+\\/=?_`{\\|}~-]+@)|[\\s\\S]*?(?:(?=[\\\\<!\\[`*~_]|\\b_|protocol:\\/\\/|www\\.|$)|[^ ](?= {2,}\\n)|[^a-zA-Z0-9.!#$%&\'*+\\/=?_`{\\|}~-](?=[a-zA-Z0-9.!#$%&\'*+\\/=?_`{\\|}~-]+@)))/).replace("protocol",re).getRegex()},nt={...Q,br:g(ue).replace("{2,}","*").getRegex(),text:g(Q.text).replace("\\\\b_","\\\\b_| {2,}\\\\n").replace(/\\{2,\\}/g,"*").getRegex()},I={normal:F,gfm:Ee,pedantic:Ce},P={normal:V,gfm:Q,breaks:nt,pedantic:rt},st={"&":"&","<":"<",">":">",\'"\':""","\'":"'"},ne=r=>st[r];function m(r,e){if(e){if(x.escapeTest.test(r))return r.replace(x.escapeReplace,ne)}else if(x.escapeTestNoEncode.test(r))return r.replace(x.escapeReplaceNoEncode,ne);return r}function se(r){try{r=encodeURI(r).replace(x.percentDecode,"%")}catch{return null}return r}function ie(r,e){let t=r.replace(x.findPipe,(i,a,l)=>{let o=!1,c=a;for(;--c>=0&&l[c]==="\\\\";)o=!o;return o?"|":" |"}),s=t.split(x.splitPipe),n=0;if(s[0].trim()||s.shift(),s.length>0&&!s.at(-1)?.trim()&&s.pop(),e)if(s.length>e)s.splice(e);else for(;s.length<e;)s.push("");for(;n<s.length;n++)s[n]=s[n].trim().replace(x.slashPipe,"|");return s}function $(r,e,t){let s=r.length;if(s===0)return"";let n=0;for(;n<s;){let i=r.charAt(s-n-1);if(i===e&&!t)n++;else if(i!==e&&t)n++;else break}return r.slice(0,s-n)}function le(r){let e=r.split(`\n`),t=e.length-1;for(;t>=0&&x.blankLine.test(e[t]);)t--;return e.length-t<=2?r:e.slice(0,t+1).join(`\n`)}function it(r,e){if(r.indexOf(e[1])===-1)return-1;let t=0;for(let s=0;s<r.length;s++)if(r[s]==="\\\\")s++;else if(r[s]===e[0])t++;else if(r[s]===e[1]&&(t--,t<0))return s;return t>0?-2:-1}function lt(r,e=0){let t=e,s="";for(let n of r)if(n===" "){let i=4-t%4;s+=" ".repeat(i),t+=i}else s+=n,t++;return s}function ae(r,e,t,s,n){let i=e.href,a=e.title||null,l=r[1].replace(n.other.outputLinkReplace,"$1");s.state.inLink=!0;let o={type:r[0].charAt(0)==="!"?"image":"link",raw:t,href:i,title:a,text:l,tokens:s.inlineTokens(l)};return s.state.inLink=!1,o}function at(r,e,t){let s=r.match(t.other.indentCodeCompensation);if(s===null)return e;let n=s[1];return e.split(`\n`).map(i=>{let a=i.match(t.other.beginningSpace);if(a===null)return i;let[l]=a;return l.length>=n.length?i.slice(n.length):i}).join(`\n`)}var C=class{options;rules;lexer;constructor(r){this.options=r||T}space(r){let e=this.rules.block.newline.exec(r);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(r){let e=this.rules.block.code.exec(r);if(e){let t=this.options.pedantic?e[0]:le(e[0]),s=t.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t,codeBlockStyle:"indented",text:s}}}fences(r){let e=this.rules.block.fences.exec(r);if(e){let t=e[0],s=at(t,e[3]||"",this.rules);return{type:"code",raw:t,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:s}}}heading(r){let e=this.rules.block.heading.exec(r);if(e){let t=e[2].trim();if(this.rules.other.endingHash.test(t)){let s=$(t,"#");(this.options.pedantic||!s||this.rules.other.endingSpaceChar.test(s))&&(t=s.trim())}return{type:"heading",raw:$(e[0],`\n`),depth:e[1].length,text:t,tokens:this.lexer.inline(t)}}}hr(r){let e=this.rules.block.hr.exec(r);if(e)return{type:"hr",raw:$(e[0],`\n`)}}blockquote(r){let e=this.rules.block.blockquote.exec(r);if(e){let t=$(e[0],`\n`).split(`\n`),s="",n="",i=[];for(;t.length>0;){let a=!1,l=[],o;for(o=0;o<t.length;o++)if(this.rules.other.blockquoteStart.test(t[o]))l.push(t[o]),a=!0;else if(!a)l.push(t[o]);else break;t=t.slice(o);let c=l.join(`\n`),p=c.replace(this.rules.other.blockquoteSetextReplace,`\n $1`).replace(this.rules.other.blockquoteSetextReplace2,"");s=s?`${s}\n${c}`:c,n=n?`${n}\n${p}`:p;let h=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(p,i,!0),this.lexer.state.top=h,t.length===0)break;let u=i.at(-1);if(u?.type==="code")break;if(u?.type==="blockquote"){let f=u,d=f.raw+`\n`+t.join(`\n`),y=this.blockquote(d);i[i.length-1]=y,s=s.substring(0,s.length-f.raw.length)+y.raw,n=n.substring(0,n.length-f.text.length)+y.text;break}else if(u?.type==="list"){let f=u,d=f.raw+`\n`+t.join(`\n`),y=this.list(d);i[i.length-1]=y,s=s.substring(0,s.length-u.raw.length)+y.raw,n=n.substring(0,n.length-f.raw.length)+y.raw,t=d.substring(i.at(-1).raw.length).split(`\n`);continue}}return{type:"blockquote",raw:s,tokens:i,text:n}}}list(r){let e=this.rules.block.list.exec(r);if(e){let t=e[1].trim(),s=t.length>1,n={type:"list",raw:"",ordered:s,start:s?+t.slice(0,-1):"",loose:!1,items:[]};t=s?`\\\\d{1,9}\\\\${t.slice(-1)}`:`\\\\${t}`,this.options.pedantic&&(t=s?t:"[*+-]");let i=this.rules.other.listItemRegex(t),a=!1;for(;r;){let o=!1,c="",p="";if(!(e=i.exec(r))||this.rules.block.hr.test(r))break;c=e[0],r=r.substring(c.length);let h=lt(e[2].split(`\n`,1)[0],e[1].length),u=r.split(`\n`,1)[0],f=!h.trim(),d=0;if(this.options.pedantic?(d=2,p=h.trimStart()):f?d=e[1].length+1:(d=h.search(this.rules.other.nonSpaceChar),d=d>4?1:d,p=h.slice(d),d+=e[1].length),f&&this.rules.other.blankLine.test(u)&&(c+=u+`\n`,r=r.substring(u.length+1),o=!0),!o){let y=this.rules.other.nextBulletRegex(d),K=this.rules.other.hrRegex(d),Y=this.rules.other.fencesBeginRegex(d),ee=this.rules.other.headingBeginRegex(d),be=this.rules.other.htmlBeginRegex(d),we=this.rules.other.blockquoteBeginRegex(d);for(;r;){let M=r.split(`\n`,1)[0],_;if(u=M,this.options.pedantic?(u=u.replace(this.rules.other.listReplaceNesting," "),_=u):_=u.replace(this.rules.other.tabCharGlobal," "),Y.test(u)||ee.test(u)||be.test(u)||we.test(u)||y.test(u)||K.test(u))break;if(_.search(this.rules.other.nonSpaceChar)>=d||!u.trim())p+=`\n`+_.slice(d);else{if(f||h.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||Y.test(h)||ee.test(h)||K.test(h))break;p+=`\n`+u}f=!u.trim(),c+=M+`\n`,r=r.substring(M.length+1),h=_.slice(d)}}n.loose||(a?n.loose=!0:this.rules.other.doubleBlankLine.test(c)&&(a=!0)),n.items.push({type:"list_item",raw:c,task:!!this.options.gfm&&this.rules.other.listIsTask.test(p),loose:!1,text:p,tokens:[]}),n.raw+=c}let l=n.items.at(-1);if(l)l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd();else return;n.raw=n.raw.trimEnd();for(let o of n.items){this.lexer.state.top=!1,o.tokens=this.lexer.blockTokens(o.text,[]);let c=o.tokens[0];if(o.task&&(c?.type==="text"||c?.type==="paragraph")){o.text=o.text.replace(this.rules.other.listReplaceTask,""),c.raw=c.raw.replace(this.rules.other.listReplaceTask,""),c.text=c.text.replace(this.rules.other.listReplaceTask,"");for(let h=this.lexer.inlineQueue.length-1;h>=0;h--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[h].src)){this.lexer.inlineQueue[h].src=this.lexer.inlineQueue[h].src.replace(this.rules.other.listReplaceTask,"");break}let p=this.rules.other.listTaskCheckbox.exec(o.raw);if(p){let h={type:"checkbox",raw:p[0]+" ",checked:p[0]!=="[ ]"};o.checked=h.checked,n.loose?o.tokens[0]&&["paragraph","text"].includes(o.tokens[0].type)&&"tokens"in o.tokens[0]&&o.tokens[0].tokens?(o.tokens[0].raw=h.raw+o.tokens[0].raw,o.tokens[0].text=h.raw+o.tokens[0].text,o.tokens[0].tokens.unshift(h)):o.tokens.unshift({type:"paragraph",raw:h.raw,text:h.raw,tokens:[h]}):o.tokens.unshift(h)}}else o.task&&(o.task=!1);if(!n.loose){let p=o.tokens.filter(u=>u.type==="space"),h=p.length>0&&p.some(u=>this.rules.other.anyLine.test(u.raw));n.loose=h}}if(n.loose)for(let o of n.items){o.loose=!0;for(let c of o.tokens)c.type==="text"&&(c.type="paragraph")}return n}}html(r){let e=this.rules.block.html.exec(r);if(e){let t=le(e[0]);return{type:"html",block:!0,raw:t,pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:t}}}def(r){let e=this.rules.block.def.exec(r);if(e){let t=e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),s=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",n=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:t,raw:$(e[0],`\n`),href:s,title:n}}}table(r){let e=this.rules.block.table.exec(r);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let t=ie(e[1]),s=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),n=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`\n`):[],i={type:"table",raw:$(e[0],`\n`),header:[],align:[],rows:[]};if(t.length===s.length){for(let a of s)this.rules.other.tableAlignRight.test(a)?i.align.push("right"):this.rules.other.tableAlignCenter.test(a)?i.align.push("center"):this.rules.other.tableAlignLeft.test(a)?i.align.push("left"):i.align.push(null);for(let a=0;a<t.length;a++)i.header.push({text:t[a],tokens:this.lexer.inline(t[a]),header:!0,align:i.align[a]});for(let a of n)i.rows.push(ie(a,i.header.length).map((l,o)=>({text:l,tokens:this.lexer.inline(l),header:!1,align:i.align[o]})));return i}}lheading(r){let e=this.rules.block.lheading.exec(r);if(e){let t=e[1].trim();return{type:"heading",raw:$(e[0],`\n`),depth:e[2].charAt(0)==="="?1:2,text:t,tokens:this.lexer.inline(t)}}}paragraph(r){let e=this.rules.block.paragraph.exec(r);if(e){let t=e[1].charAt(e[1].length-1)===`\n`?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:t,tokens:this.lexer.inline(t)}}}text(r){let e=this.rules.block.text.exec(r);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(r){let e=this.rules.inline.escape.exec(r);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(r){let e=this.rules.inline.tag.exec(r);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(r){let e=this.rules.inline.link.exec(r);if(e){let t=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(t)){if(!this.rules.other.endAngleBracket.test(t))return;let i=$(t.slice(0,-1),"\\\\");if((t.length-i.length)%2===0)return}else{let i=it(e[2],"()");if(i===-2)return;if(i>-1){let a=(e[0].indexOf("!")===0?5:4)+e[1].length+i;e[2]=e[2].substring(0,i),e[0]=e[0].substring(0,a).trim(),e[3]=""}}let s=e[2],n="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(s);i&&(s=i[1],n=i[3])}else n=e[3]?e[3].slice(1,-1):"";return s=s.trim(),this.rules.other.startAngleBracket.test(s)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(t)?s=s.slice(1):s=s.slice(1,-1)),ae(e,{href:s&&s.replace(this.rules.inline.anyPunctuation,"$1"),title:n&&n.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(r,e){let t;if((t=this.rules.inline.reflink.exec(r))||(t=this.rules.inline.nolink.exec(r))){let s=(t[2]||t[1]).replace(this.rules.other.multipleSpaceGlobal," "),n=e[s.toLowerCase()];if(!n){let i=t[0].charAt(0);return{type:"text",raw:i,text:i}}return ae(t,n,t[0],this.lexer,this.rules)}}emStrong(r,e,t=""){let s=this.rules.inline.emStrongLDelim.exec(r);if(!(!s||!s[1]&&!s[2]&&!s[3]&&!s[4]||s[4]&&t.match(this.rules.other.unicodeAlphaNumeric))&&(!(s[1]||s[3])||!t||this.rules.inline.punctuation.exec(t))){let n=[...s[0]].length-1,i,a,l=n,o=0,c=s[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(c.lastIndex=0,e=e.slice(-1*r.length+n);(s=c.exec(e))!==null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i)continue;if(a=[...i].length,s[3]||s[4]){l+=a;continue}else if((s[5]||s[6])&&n%3&&!((n+a)%3)){o+=a;continue}if(l-=a,l>0)continue;a=Math.min(a,a+l+o);let p=[...s[0]][0].length,h=r.slice(0,n+s.index+p+a);if(Math.min(n,a)%2){let f=h.slice(1,-1);return{type:"em",raw:h,text:f,tokens:this.lexer.inlineTokens(f)}}let u=h.slice(2,-2);return{type:"strong",raw:h,text:u,tokens:this.lexer.inlineTokens(u)}}}}codespan(r){let e=this.rules.inline.code.exec(r);if(e){let t=e[2].replace(this.rules.other.newLineCharGlobal," "),s=this.rules.other.nonSpaceChar.test(t),n=this.rules.other.startingSpaceChar.test(t)&&this.rules.other.endingSpaceChar.test(t);return s&&n&&(t=t.substring(1,t.length-1)),{type:"codespan",raw:e[0],text:t}}}br(r){let e=this.rules.inline.br.exec(r);if(e)return{type:"br",raw:e[0]}}del(r,e,t=""){let s=this.rules.inline.delLDelim.exec(r);if(s&&(!s[1]||!t||this.rules.inline.punctuation.exec(t))){let n=[...s[0]].length-1,i,a,l=n,o=this.rules.inline.delRDelim;for(o.lastIndex=0,e=e.slice(-1*r.length+n);(s=o.exec(e))!==null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i||(a=[...i].length,a!==n))continue;if(s[3]||s[4]){l+=a;continue}if(l-=a,l>0)continue;a=Math.min(a,a+l);let c=[...s[0]][0].length,p=r.slice(0,n+s.index+c+a),h=p.slice(n,-n);return{type:"del",raw:p,text:h,tokens:this.lexer.inlineTokens(h)}}}}autolink(r){let e=this.rules.inline.autolink.exec(r);if(e){let t,s;return e[2]==="@"?(t=e[1],s="mailto:"+t):(t=e[1],s=t),{type:"link",raw:e[0],text:t,href:s,tokens:[{type:"text",raw:t,text:t}]}}}url(r){let e;if(e=this.rules.inline.url.exec(r)){let t,s;if(e[2]==="@")t=e[0],s="mailto:"+t;else{let n;do n=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(n!==e[0]);t=e[0],e[1]==="www."?s="http://"+e[0]:s=e[0]}return{type:"link",raw:e[0],text:t,href:s,tokens:[{type:"text",raw:t,text:t}]}}}inlineText(r){let e=this.rules.inline.text.exec(r);if(e){let t=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:t}}}},b=class j{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||T,this.options.tokenizer=this.options.tokenizer||new C,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:x,block:I.normal,inline:P.normal};this.options.pedantic?(t.block=I.pedantic,t.inline=P.pedantic):this.options.gfm&&(t.block=I.gfm,this.options.breaks?t.inline=P.breaks:t.inline=P.gfm),this.tokenizer.rules=t}static get rules(){return{block:I,inline:P}}static lex(e,t){return new j(t).lex(e)}static lexInline(e,t){return new j(t).inlineTokens(e)}lex(e){e=e.replace(x.carriageReturn,`\n`),this.blockTokens(e,this.tokens);for(let t=0;t<this.inlineQueue.length;t++){let s=this.inlineQueue[t];this.inlineTokens(s.src,s.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],s=!1){this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(x.tabCharGlobal," ").replace(x.spaceLine,""));let n=1/0;for(;e;){if(e.length<n)n=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}let i;if(this.options.extensions?.block?.some(l=>(i=l.call({lexer:this},e,t))?(e=e.substring(i.raw.length),t.push(i),!0):!1))continue;if(i=this.tokenizer.space(e)){e=e.substring(i.raw.length);let l=t.at(-1);i.raw.length===1&&l!==void 0?l.raw+=`\n`:t.push(i);continue}if(i=this.tokenizer.code(e)){e=e.substring(i.raw.length);let l=t.at(-1);l?.type==="paragraph"||l?.type==="text"?(l.raw+=(l.raw.endsWith(`\n`)?"":`\n`)+i.raw,l.text+=`\n`+i.text,this.inlineQueue.at(-1).src=l.text):t.push(i);continue}if(i=this.tokenizer.fences(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.heading(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.hr(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.blockquote(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.list(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.html(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.def(e)){e=e.substring(i.raw.length);let l=t.at(-1);l?.type==="paragraph"||l?.type==="text"?(l.raw+=(l.raw.endsWith(`\n`)?"":`\n`)+i.raw,l.text+=`\n`+i.raw,this.inlineQueue.at(-1).src=l.text):this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title},t.push(i));continue}if(i=this.tokenizer.table(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.lheading(e)){e=e.substring(i.raw.length),t.push(i);continue}let a=e;if(this.options.extensions?.startBlock){let l=1/0,o=e.slice(1),c;this.options.extensions.startBlock.forEach(p=>{c=p.call({lexer:this},o),typeof c=="number"&&c>=0&&(l=Math.min(l,c))}),l<1/0&&l>=0&&(a=e.substring(0,l+1))}if(this.state.top&&(i=this.tokenizer.paragraph(a))){let l=t.at(-1);s&&l?.type==="paragraph"?(l.raw+=(l.raw.endsWith(`\n`)?"":`\n`)+i.raw,l.text+=`\n`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=l.text):t.push(i),s=a.length!==e.length,e=e.substring(i.raw.length);continue}if(i=this.tokenizer.text(e)){e=e.substring(i.raw.length);let l=t.at(-1);l?.type==="text"?(l.raw+=(l.raw.endsWith(`\n`)?"":`\n`)+i.raw,l.text+=`\n`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=l.text):t.push(i);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){this.tokenizer.lexer=this;let s=e;if(this.tokens.links){let l=Object.keys(this.tokens.links);l.length>0&&(s=s.replace(this.tokenizer.rules.inline.reflinkSearch,o=>l.includes(o.slice(o.lastIndexOf("[")+1,-1))?"["+"a".repeat(o.length-2)+"]":o))}s=s.replace(this.tokenizer.rules.inline.anyPunctuation,"++"),s=s.replace(this.tokenizer.rules.inline.blockSkip,(l,o,c)=>{let p=c?c.length:0;return l.slice(0,p)+"["+"a".repeat(l.length-p-2)+"]"}),s=this.options.hooks?.emStrongMask?.call({lexer:this},s)??s;let n=!1,i="",a=1/0;for(;e;){if(e.length<a)a=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}n||(i=""),n=!1;let l;if(this.options.extensions?.inline?.some(c=>(l=c.call({lexer:this},e,t))?(e=e.substring(l.raw.length),t.push(l),!0):!1))continue;if(l=this.tokenizer.escape(e)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.tag(e)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.link(e)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(l.raw.length);let c=t.at(-1);l.type==="text"&&c?.type==="text"?(c.raw+=l.raw,c.text+=l.text):t.push(l);continue}if(l=this.tokenizer.emStrong(e,s,i)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.codespan(e)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.br(e)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.del(e,s,i)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.autolink(e)){e=e.substring(l.raw.length),t.push(l);continue}if(!this.state.inLink&&(l=this.tokenizer.url(e))){e=e.substring(l.raw.length),t.push(l);continue}let o=e;if(this.options.extensions?.startInline){let c=1/0,p=e.slice(1),h;this.options.extensions.startInline.forEach(u=>{h=u.call({lexer:this},p),typeof h=="number"&&h>=0&&(c=Math.min(c,h))}),c<1/0&&c>=0&&(o=e.substring(0,c+1))}if(l=this.tokenizer.inlineText(o)){e=e.substring(l.raw.length),l.raw.slice(-1)!=="_"&&(i=l.raw.slice(-1)),n=!0;let c=t.at(-1);c?.type==="text"?(c.raw+=l.raw,c.text+=l.text):t.push(l);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return t}infiniteLoopError(e){let t="Infinite loop on byte: "+e;if(this.options.silent)console.error(t);else throw new Error(t)}},B=class{options;parser;constructor(r){this.options=r||T}space(r){return""}code({text:r,lang:e,escaped:t}){let s=(e||"").match(x.notSpaceStart)?.[0],n=r.replace(x.endingNewline,"")+`\n`;return s?\'<pre><code class="language-\'+m(s)+\'">\'+(t?n:m(n,!0))+`</code></pre>\n`:"<pre><code>"+(t?n:m(n,!0))+`</code></pre>\n`}blockquote({tokens:r}){return`<blockquote>\n${this.parser.parse(r)}</blockquote>\n`}html({text:r}){return r}def(r){return""}heading({tokens:r,depth:e}){return`<h${e}>${this.parser.parseInline(r)}</h${e}>\n`}hr(r){return`<hr>\n`}list(r){let e=r.ordered,t=r.start,s="";for(let a=0;a<r.items.length;a++){let l=r.items[a];s+=this.listitem(l)}let n=e?"ol":"ul",i=e&&t!==1?\' start="\'+t+\'"\':"";return"<"+n+i+`>\n`+s+"</"+n+`>\n`}listitem(r){return`<li>${this.parser.parse(r.tokens)}</li>\n`}checkbox({checked:r}){return"<input "+(r?\'checked="" \':"")+\'disabled="" type="checkbox"> \'}paragraph({tokens:r}){return`<p>${this.parser.parseInline(r)}</p>\n`}table(r){let e="",t="";for(let n=0;n<r.header.length;n++)t+=this.tablecell(r.header[n]);e+=this.tablerow({text:t});let s="";for(let n=0;n<r.rows.length;n++){let i=r.rows[n];t="";for(let a=0;a<i.length;a++)t+=this.tablecell(i[a]);s+=this.tablerow({text:t})}return s&&(s=`<tbody>${s}</tbody>`),`<table>\n<thead>\n`+e+`</thead>\n`+s+`</table>\n`}tablerow({text:r}){return`<tr>\n${r}</tr>\n`}tablecell(r){let e=this.parser.parseInline(r.tokens),t=r.header?"th":"td";return(r.align?`<${t} align="${r.align}">`:`<${t}>`)+e+`</${t}>\n`}strong({tokens:r}){return`<strong>${this.parser.parseInline(r)}</strong>`}em({tokens:r}){return`<em>${this.parser.parseInline(r)}</em>`}codespan({text:r}){return`<code>${m(r,!0)}</code>`}br(r){return"<br>"}del({tokens:r}){return`<del>${this.parser.parseInline(r)}</del>`}link({href:r,title:e,tokens:t}){let s=this.parser.parseInline(t),n=se(r);if(n===null)return s;r=n;let i=\'<a href="\'+r+\'"\';return e&&(i+=\' title="\'+m(e)+\'"\'),i+=">"+s+"</a>",i}image({href:r,title:e,text:t,tokens:s}){s&&(t=this.parser.parseInline(s,this.parser.textRenderer));let n=se(r);if(n===null)return m(t);r=n;let i=`<img src="${r}" alt="${m(t)}"`;return e&&(i+=` title="${m(e)}"`),i+=">",i}text(r){return"tokens"in r&&r.tokens?this.parser.parseInline(r.tokens):"escaped"in r&&r.escaped?r.text:m(r.text)}},J=class{strong({text:r}){return r}em({text:r}){return r}codespan({text:r}){return r}del({text:r}){return r}html({text:r}){return r}text({text:r}){return r}link({text:r}){return""+r}image({text:r}){return""+r}br(){return""}checkbox({raw:r}){return r}},w=class H{options;renderer;textRenderer;constructor(e){this.options=e||T,this.options.renderer=this.options.renderer||new B,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new J}static parse(e,t){return new H(t).parse(e)}static parseInline(e,t){return new H(t).parseInline(e)}parse(e){this.renderer.parser=this;let t="";for(let s=0;s<e.length;s++){let n=e[s];if(this.options.extensions?.renderers?.[n.type]){let a=n,l=this.options.extensions.renderers[a.type].call({parser:this},a);if(l!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(a.type)){t+=l||"";continue}}let i=n;switch(i.type){case"space":{t+=this.renderer.space(i);break}case"hr":{t+=this.renderer.hr(i);break}case"heading":{t+=this.renderer.heading(i);break}case"code":{t+=this.renderer.code(i);break}case"table":{t+=this.renderer.table(i);break}case"blockquote":{t+=this.renderer.blockquote(i);break}case"list":{t+=this.renderer.list(i);break}case"checkbox":{t+=this.renderer.checkbox(i);break}case"html":{t+=this.renderer.html(i);break}case"def":{t+=this.renderer.def(i);break}case"paragraph":{t+=this.renderer.paragraph(i);break}case"text":{t+=this.renderer.text(i);break}default:{let a=\'Token with "\'+i.type+\'" type was not found.\';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return t}parseInline(e,t=this.renderer){this.renderer.parser=this;let s="";for(let n=0;n<e.length;n++){let i=e[n];if(this.options.extensions?.renderers?.[i.type]){let l=this.options.extensions.renderers[i.type].call({parser:this},i);if(l!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){s+=l||"";continue}}let a=i;switch(a.type){case"escape":{s+=t.text(a);break}case"html":{s+=t.html(a);break}case"link":{s+=t.link(a);break}case"image":{s+=t.image(a);break}case"checkbox":{s+=t.checkbox(a);break}case"strong":{s+=t.strong(a);break}case"em":{s+=t.em(a);break}case"codespan":{s+=t.codespan(a);break}case"br":{s+=t.br(a);break}case"del":{s+=t.del(a);break}case"text":{s+=t.text(a);break}default:{let l=\'Token with "\'+a.type+\'" type was not found.\';if(this.options.silent)return console.error(l),"";throw new Error(l)}}}return s}},L=class{options;block;constructor(r){this.options=r||T}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(r){return r}postprocess(r){return r}processAllTokens(r){return r}emStrongMask(r){return r}provideLexer(r=this.block){return r?b.lex:b.lexInline}provideParser(r=this.block){return r?w.parse:w.parseInline}},ot=class{defaults=O();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=w;Renderer=B;TextRenderer=J;Lexer=b;Tokenizer=C;Hooks=L;constructor(...r){this.use(...r)}walkTokens(r,e){let t=[];for(let s of r)switch(t=t.concat(e.call(this,s)),s.type){case"table":{let n=s;for(let i of n.header)t=t.concat(this.walkTokens(i.tokens,e));for(let i of n.rows)for(let a of i)t=t.concat(this.walkTokens(a.tokens,e));break}case"list":{let n=s;t=t.concat(this.walkTokens(n.items,e));break}default:{let n=s;this.defaults.extensions?.childTokens?.[n.type]?this.defaults.extensions.childTokens[n.type].forEach(i=>{let a=n[i].flat(1/0);t=t.concat(this.walkTokens(a,e))}):n.tokens&&(t=t.concat(this.walkTokens(n.tokens,e)))}}return t}use(...r){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return r.forEach(t=>{let s={...t};if(s.async=this.defaults.async||s.async||!1,t.extensions&&(t.extensions.forEach(n=>{if(!n.name)throw new Error("extension name required");if("renderer"in n){let i=e.renderers[n.name];i?e.renderers[n.name]=function(...a){let l=n.renderer.apply(this,a);return l===!1&&(l=i.apply(this,a)),l}:e.renderers[n.name]=n.renderer}if("tokenizer"in n){if(!n.level||n.level!=="block"&&n.level!=="inline")throw new Error("extension level must be \'block\' or \'inline\'");let i=e[n.level];i?i.unshift(n.tokenizer):e[n.level]=[n.tokenizer],n.start&&(n.level==="block"?e.startBlock?e.startBlock.push(n.start):e.startBlock=[n.start]:n.level==="inline"&&(e.startInline?e.startInline.push(n.start):e.startInline=[n.start]))}"childTokens"in n&&n.childTokens&&(e.childTokens[n.name]=n.childTokens)}),s.extensions=e),t.renderer){let n=this.defaults.renderer||new B(this.defaults);for(let i in t.renderer){if(!(i in n))throw new Error(`renderer \'${i}\' does not exist`);if(["options","parser"].includes(i))continue;let a=i,l=t.renderer[a],o=n[a];n[a]=(...c)=>{let p=l.apply(n,c);return p===!1&&(p=o.apply(n,c)),p||""}}s.renderer=n}if(t.tokenizer){let n=this.defaults.tokenizer||new C(this.defaults);for(let i in t.tokenizer){if(!(i in n))throw new Error(`tokenizer \'${i}\' does not exist`);if(["options","rules","lexer"].includes(i))continue;let a=i,l=t.tokenizer[a],o=n[a];n[a]=(...c)=>{let p=l.apply(n,c);return p===!1&&(p=o.apply(n,c)),p}}s.tokenizer=n}if(t.hooks){let n=this.defaults.hooks||new L;for(let i in t.hooks){if(!(i in n))throw new Error(`hook \'${i}\' does not exist`);if(["options","block"].includes(i))continue;let a=i,l=t.hooks[a],o=n[a];L.passThroughHooks.has(i)?n[a]=c=>{if(this.defaults.async&&L.passThroughHooksRespectAsync.has(i))return(async()=>{let h=await l.call(n,c);return o.call(n,h)})();let p=l.call(n,c);return o.call(n,p)}:n[a]=(...c)=>{if(this.defaults.async)return(async()=>{let h=await l.apply(n,c);return h===!1&&(h=await o.apply(n,c)),h})();let p=l.apply(n,c);return p===!1&&(p=o.apply(n,c)),p}}s.hooks=n}if(t.walkTokens){let n=this.defaults.walkTokens,i=t.walkTokens;s.walkTokens=function(a){let l=[];return l.push(i.call(this,a)),n&&(l=l.concat(n.call(this,a))),l}}this.defaults={...this.defaults,...s}}),this}setOptions(r){return this.defaults={...this.defaults,...r},this}lexer(r,e){return b.lex(r,e??this.defaults)}parser(r,e){return w.parse(r,e??this.defaults)}parseMarkdown(r){return(e,t)=>{let s={...t},n={...this.defaults,...s},i=this.onError(!!n.silent,!!n.async);if(this.defaults.async===!0&&s.async===!1)return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof e>"u"||e===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));if(n.hooks&&(n.hooks.options=n,n.hooks.block=r),n.async)return(async()=>{let a=n.hooks?await n.hooks.preprocess(e):e,l=await(n.hooks?await n.hooks.provideLexer(r):r?b.lex:b.lexInline)(a,n),o=n.hooks?await n.hooks.processAllTokens(l):l;n.walkTokens&&await Promise.all(this.walkTokens(o,n.walkTokens));let c=await(n.hooks?await n.hooks.provideParser(r):r?w.parse:w.parseInline)(o,n);return n.hooks?await n.hooks.postprocess(c):c})().catch(i);try{n.hooks&&(e=n.hooks.preprocess(e));let a=(n.hooks?n.hooks.provideLexer(r):r?b.lex:b.lexInline)(e,n);n.hooks&&(a=n.hooks.processAllTokens(a)),n.walkTokens&&this.walkTokens(a,n.walkTokens);let l=(n.hooks?n.hooks.provideParser(r):r?w.parse:w.parseInline)(a,n);return n.hooks&&(l=n.hooks.postprocess(l)),l}catch(a){return i(a)}}}onError(r,e){return t=>{if(t.message+=`\nPlease report this to https://github.com/markedjs/marked.`,r){let s="<p>An error occurred:</p><pre>"+m(t.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(t);throw t}}},S=new ot;function k(r,e){return S.parse(r,e)}k.options=k.setOptions=function(r){return S.setOptions(r),k.defaults=S.defaults,oe(k.defaults),k};k.getDefaults=O;k.defaults=T;k.use=function(...r){return S.use(...r),k.defaults=S.defaults,oe(k.defaults),k};k.walkTokens=function(r,e){return S.walkTokens(r,e)};k.parseInline=S.parseInline;k.Parser=w;k.parser=w.parse;k.Renderer=B;k.TextRenderer=J;k.Lexer=b;k.lexer=b.lex;k.Tokenizer=C;k.Hooks=L;k.parse=k;var ct=k.options,ht=k.setOptions,pt=k.use,ut=k.walkTokens,gt=k.parseInline;var kt=w.parse,dt=b.lex;k.use({extensions:[{name:"inlineMath",level:"inline",start(r){return r.match(/(?<![\\\\$])\\$(?![$\\s])/)?.index},tokenizer(r){let e=/^\\$(?![$\\s\\d])((?:\\\\\\$|[^$\\n])*?)(?<!\\s)\\$(?!\\d)/.exec(r);if(e)return{type:"inlineMath",raw:e[0],text:e[1].trim()}},renderer(r){return r.raw}}]});var D=new Map;self.onmessage=r=>{let e=r.data;if(typeof e!="object"||e===null)return;let{id:t,text:s,oldRaws:n,instance:i,baseVersion:a,dispose:l}=e;if(l===!0){typeof i=="string"&&D.delete(i);return}if(typeof s!="string")return;let o=typeof i=="string"?i:null,c=typeof a=="number"?a:null,p=null;if(Array.isArray(n))p=n;else if(o!==null&&c!==null){let h=D.get(o);if(h&&h.version===c)p=h.raws;else{self.postMessage({id:t,needRaws:!0});return}}try{let h=k.lexer(s),u=0;if(p){let f=Math.min(p.length,h.length);for(;u<f&&p[u]===h[u].raw;u++);}o!==null&&c!==null&&D.set(o,{version:c+1,raws:h.map(f=>f.raw)}),self.postMessage({id:t,matchLen:u,tail:h.slice(u)})}catch(h){o!==null&&D.delete(o),self.postMessage({id:t,error:String(h)})}};})();\n';
|
|
427
|
+
var WORKER_SOURCE_STRING = '"use strict";(()=>{function U(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var A=U();function he(r){A=r}var T={exec:()=>null};function L(r){let e=[];return t=>{let s=Math.max(0,Math.min(3,t-1)),n=e[s];return n||(n=r(s),e[s]=n),n}}function g(r,e=""){let t=typeof r=="string"?r:r.source,s={replace:(n,i)=>{let a=typeof i=="string"?i:i.source;return a=a.replace(b.caret,"$1"),t=t.replace(n,a),s},getRegex:()=>new RegExp(t,e)};return s}var me=((r="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+r)}catch{return!1}})(),b={codeRemoveIndent:/^(?: {1,4}| {0,3}\\t)/gm,outputLinkReplace:/\\\\([\\[\\]])/g,indentCodeCompensation:/^(\\s+)(?:```)/,beginningSpace:/^\\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\\n/g,tabCharGlobal:/\\t/g,multipleSpaceGlobal:/\\s+/g,blankLine:/^[ \\t]*$/,doubleBlankLine:/\\n[ \\t]*\\n[ \\t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\\n {0,3}((?:=+|-+) *)(?=\\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \\t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\\[[ xX]\\] +\\S/,listReplaceTask:/^\\[[ xX]\\] +/,listTaskCheckbox:/\\[[ xX]\\]/,anyLine:/\\n.*\\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\\||\\| *$/g,tableRowBlankLine:/\\n[ \\t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\\s|>)/i,endPreScriptTag:/^<\\/(pre|code|kbd|script)(\\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^\'"]*[^\\s])\\s+([\'"])(.*)\\2/,unicodeAlphaNumeric:/[\\p{L}\\p{N}]/u,escapeTest:/[&<>"\']/,escapeReplace:/[&<>"\']/g,escapeTestNoEncode:/[<>"\']|&(?!(#\\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\\w+);)/,escapeReplaceNoEncode:/[<>"\']|&(?!(#\\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\\w+);)/g,caret:/(^|[^\\[])\\^/g,percentDecode:/%25/g,findPipe:/\\|/g,splitPipe:/ \\|/,slashPipe:/\\\\\\|/g,carriageReturn:/\\r\\n|\\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\\S*/,endingNewline:/\\n$/,listItemRegex:r=>new RegExp(`^( {0,3}${r})((?:[ ][^\\\\n]*)?(?:\\\\n|$))`),nextBulletRegex:L(r=>new RegExp(`^ {0,${r}}(?:[*+-]|\\\\d{1,9}[.)])((?:[ ][^\\\\n]*)?(?:\\\\n|$))`)),hrRegex:L(r=>new RegExp(`^ {0,${r}}((?:- *){3,}|(?:_ *){3,}|(?:\\\\* *){3,})(?:\\\\n+|$)`)),fencesBeginRegex:L(r=>new RegExp(`^ {0,${r}}(?:\\`\\`\\`|~~~)`)),headingBeginRegex:L(r=>new RegExp(`^ {0,${r}}#`)),htmlBeginRegex:L(r=>new RegExp(`^ {0,${r}}<(?:[a-z].*>|!--)`,"i")),blockquoteBeginRegex:L(r=>new RegExp(`^ {0,${r}}>`))},ye=/^(?:[ \\t]*(?:\\n|$))+/,$e=/^((?: {4}| {0,3}\\t)[^\\n]+(?:\\n(?:[ \\t]*(?:\\n|$))*)?)+/,Re=/^ {0,3}(`{3,}(?=[^`\\n]*(?:\\n|$))|~{3,})([^\\n]*)(?:\\n|$)(?:|([\\s\\S]*?)(?:\\n|$))(?: {0,3}\\1[~`]* *(?=\\n|$)|$)/,M=/^ {0,3}((?:-[\\t ]*){3,}|(?:_[ \\t]*){3,}|(?:\\*[ \\t]*){3,})(?:\\n+|$)/,Se=/^ {0,3}(#{1,6})(?=\\s|$)(.*)(?:\\n+|$)/,F=/ {0,3}(?:[*+-]|\\d{1,9}[.)])/,pe=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\\n(?!\\s*?\\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\\n {0,3}(=+|-+) *(?:\\n+|$)/,ue=g(pe).replace(/bull/g,F).replace(/blockCode/g,/(?: {4}| {0,3}\\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\\s|$)/).replace(/html/g,/ {0,3}<[^\\n>]+>\\n/).replace(/\\|table/g,"").getRegex(),Te=g(pe).replace(/bull/g,F).replace(/blockCode/g,/(?: {4}| {0,3}\\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\\s|$)/).replace(/html/g,/ {0,3}<[^\\n>]+>\\n/).replace(/table/g,/ {0,3}\\|?(?:[:\\- ]*\\|)+[\\:\\- ]*\\n/).getRegex(),V=/^([^\\n]+(?:\\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \\t]+\\n)[^\\n]+)*)/,ze=/^[^\\n]+/,J=/(?!\\s*\\])(?:\\\\[\\s\\S]|[^\\[\\]\\\\])+/,Ae=g(/^ {0,3}\\[(label)\\]: *(?:\\n[ \\t]*)?([^<\\s][^\\s]*|<.*?>)(?:(?: +(?:\\n[ \\t]*)?| *\\n[ \\t]*)(title))? *(?:\\n+|$)/).replace("label",J).replace("title",/(?:"(?:\\\\"?|[^"\\\\])*"|\'[^\'\\n]*(?:\\n[^\'\\n]+)*\\n?\'|\\([^()]*\\))/).getRegex(),Le=g(/^(bull)([ \\t][^\\n]*?)?(?:\\n|$)/).replace(/bull/g,F).getRegex(),j="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",K=/<!--(?:-?>|[\\s\\S]*?(?:-->|$))/,_e=g("^ {0,3}(?:<(script|pre|style|textarea)[\\\\s>][\\\\s\\\\S]*?(?:</\\\\1>[^\\\\n]*\\\\n*|$)|comment[^\\\\n]*(\\\\n+|$)|<\\\\?[\\\\s\\\\S]*?(?:\\\\?>[^\\\\n]*\\\\n*|$)|<![A-Z][\\\\s\\\\S]*?(?:>[^\\\\n]*\\\\n*|$)|<!\\\\[CDATA\\\\[[\\\\s\\\\S]*?(?:\\\\]\\\\]>[^\\\\n]*\\\\n*|$)|</?(tag)(?: +|\\\\n|/?>)[\\\\s\\\\S]*?(?:(?:\\\\n[ ]*)+\\\\n|$)|<(?!script|pre|style|textarea)([a-z][\\\\w-]*)(?:attribute)*? */?>(?=[ \\\\t]*(?:\\\\n|$))[\\\\s\\\\S]*?(?:(?:\\\\n[ ]*)+\\\\n|$)|</(?!script|pre|style|textarea)[a-z][\\\\w-]*\\\\s*>(?=[ \\\\t]*(?:\\\\n|$))[\\\\s\\\\S]*?(?:(?:\\\\n[ ]*)+\\\\n|$))","i").replace("comment",K).replace("tag",j).replace("attribute",/ +[a-zA-Z:_][\\w.:-]*(?: *= *"[^"\\n]*"| *= *\'[^\'\\n]*\'| *= *[^\\s"\'=<>`]+)?/).getRegex(),ge=r=>g(V).replace("hr",M).replace("heading"," {0,3}#{1,6}(?:\\\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\\\n]*\\\\n)|~~~)[^\\\\n]*\\\\n").replace("list",r).replace("html","</?(?:tag)(?: +|\\\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",j).getRegex(),Pe=ge(/ {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]/),ve=ge(/ {0,3}(?:[*+-]|\\d{1,9}[.)])(?:[ \\t]|\\n|$)/),Ie=g(/^( {0,3}> ?(paragraph|[^\\n]*)(?:\\n|$))+/).replace("paragraph",ve).getRegex(),Y={blockquote:Ie,code:$e,def:Ae,fences:Re,heading:Se,hr:M,html:_e,lheading:ue,list:Le,newline:ye,paragraph:Pe,table:T,text:ze},ne=g("^ *([^\\\\n ].*)\\\\n {0,3}((?:\\\\| *)?:?-+:? *(?:\\\\| *:?-+:? *)*(?:\\\\| *)?)(?:\\\\n((?:(?! *\\\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\\\n|$))*)\\\\n*|$)").replace("hr",M).replace("heading"," {0,3}#{1,6}(?:\\\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\\\n]*\\\\n)|~~~)[^\\\\n]*\\\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\\\t]").replace("html","</?(?:tag)(?: +|\\\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",j).getRegex(),Ce={...Y,lheading:Te,table:ne,paragraph:g(V).replace("hr",M).replace("heading"," {0,3}#{1,6}(?:\\\\s|$)").replace("|lheading","").replace("table",ne).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\\\n]*\\\\n)|~~~)[^\\\\n]*\\\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\\\t]+[^ \\\\t\\\\n]").replace("html","</?(?:tag)(?: +|\\\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",j).getRegex()},Ee={...Y,html:g(`^ *(?:comment *(?:\\\\n|\\\\s*$)|<(tag)[\\\\s\\\\S]+?</\\\\1> *(?:\\\\n{2,}|\\\\s*$)|<tag(?:"[^"]*"|\'[^\']*\'|\\\\s[^\'"/>\\\\s]*)*?/?> *(?:\\\\n{2,}|\\\\s*$))`).replace("comment",K).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\\\b)\\\\w+(?!:|[^\\\\w\\\\s@]*@)\\\\b").getRegex(),def:/^ *\\[([^\\]]+)\\]: *<?([^\\s>]+)>?(?: +(["(][^\\n]+[")]))? *(?:\\n+|$)/,heading:/^(#{1,6})(.*)(?:\\n+|$)/,fences:T,lheading:/^(.+?)\\n {0,3}(=+|-+) *(?:\\n+|$)/,paragraph:g(V).replace("hr",M).replace("heading",` *#{1,6} *[^\n]`).replace("lheading",ue).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Me=/^\\\\([!"#$%&\'()*+,\\-./:;<=>?@\\[\\]\\\\^_`{|}~])/,Be=/^(`+)([^`]|[^`][\\s\\S]*?[^`])\\1(?!`)/,ke=/^( {2,}|\\\\)\\n(?!\\s*$)/,qe=/^(`+|[^`])(?:(?= {2,}\\n)|[\\s\\S]*?(?:(?=[\\\\<!\\[`*_]|\\b_|$)|[^ ](?= {2,}\\n)))/,_=/[\\p{P}\\p{S}]/u,H=/[\\s\\p{P}\\p{S}]/u,ee=/[^\\s\\p{P}\\p{S}]/u,Ze=g(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,H).getRegex(),fe=/(?!~)[\\p{P}\\p{S}]/u,De=/(?!~)[\\s\\p{P}\\p{S}]/u,Qe=/(?:[^\\s\\p{P}\\p{S}]|~)/u,Ne=g(/link|precode-code|html/,"g").replace("link",/\\[(?:[^\\[\\]`]|(?<a>`+)[^`]+\\k<a>(?!`))*?\\]\\((?:\\\\[\\s\\S]|[^\\\\\\(\\)]|\\((?:\\\\[\\s\\S]|[^\\\\\\(\\)])*\\))*\\)/).replace("precode-",me?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),de=/^(?:\\*+(?:((?!\\*)punct)|([^\\s*]))?)|^_+(?:((?!_)punct)|([^\\s_]))?/,je=g(de,"u").replace(/punct/g,_).getRegex(),He=g(de,"u").replace(/punct/g,fe).getRegex(),xe="^[^_*]*?__[^_*]*?\\\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\\\*)punct(\\\\*+)(?=[\\\\s]|$)|notPunctSpace(\\\\*+)(?!\\\\*)(?=punctSpace|$)|(?!\\\\*)punctSpace(\\\\*+)(?=notPunctSpace)|[\\\\s](\\\\*+)(?!\\\\*)(?=punct)|(?!\\\\*)punct(\\\\*+)(?!\\\\*)(?=punct)|notPunctSpace(\\\\*+)(?=notPunctSpace)",Oe=g(xe,"gu").replace(/notPunctSpace/g,ee).replace(/punctSpace/g,H).replace(/punct/g,_).getRegex(),Ge=g(xe,"gu").replace(/notPunctSpace/g,Qe).replace(/punctSpace/g,De).replace(/punct/g,fe).getRegex(),We=g("^[^_*]*?\\\\*\\\\*[^_*]*?_[^_*]*?(?=\\\\*\\\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,ee).replace(/punctSpace/g,H).replace(/punct/g,_).getRegex(),Xe=g(/^~~?(?:((?!~)punct)|[^\\s~])/,"u").replace(/punct/g,_).getRegex(),Ue="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",Fe=g(Ue,"gu").replace(/notPunctSpace/g,ee).replace(/punctSpace/g,H).replace(/punct/g,_).getRegex(),Ve=g(/\\\\(punct)/,"gu").replace(/punct/g,_).getRegex(),Je=g(/^<(scheme:[^\\s\\x00-\\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&\'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Ke=g(K).replace("(?:-->|$)","-->").getRegex(),Ye=g("^comment|^</[a-zA-Z][\\\\w:-]*\\\\s*>|^<[a-zA-Z][\\\\w-]*(?:attribute)*?\\\\s*/?>|^<\\\\?[\\\\s\\\\S]*?\\\\?>|^<![a-zA-Z]+\\\\s[\\\\s\\\\S]*?>|^<!\\\\[CDATA\\\\[[\\\\s\\\\S]*?\\\\]\\\\]>").replace("comment",Ke).replace("attribute",/\\s+[a-zA-Z:_][\\w.:-]*(?:\\s*=\\s*"[^"]*"|\\s*=\\s*\'[^\']*\'|\\s*=\\s*[^\\s"\'=<>`]+)?/).getRegex(),D=/(?:\\[(?:\\\\[\\s\\S]|[^\\[\\]\\\\])*\\]|\\\\[\\s\\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\\])|[^\\[\\]\\\\`])*?/,et=g(/^!?\\[(label)\\]\\(\\s*(href)(?:(?:[ \\t]+(?:\\n[ \\t]*)?|\\n[ \\t]*)(title))?\\s*\\)/).replace("label",D).replace("href",/<(?:\\\\.|[^\\n<>\\\\])+>|[^ \\t\\n\\x00-\\x1f]+|(?=\\))/).replace("title",/"(?:\\\\"?|[^"\\\\])*"|\'(?:\\\\\'?|[^\'\\\\])*\'|\\((?:\\\\\\)?|[^)\\\\])*\\)/).getRegex(),be=g(/^!?\\[(label)\\]\\[(ref)\\]/).replace("label",D).replace("ref",J).getRegex(),we=g(/^!?\\[(ref)\\](?:\\[\\])?/).replace("ref",J).getRegex(),tt=g("reflink|nolink(?!\\\\()","g").replace("reflink",be).replace("nolink",we).getRegex(),se=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,te={_backpedal:T,anyPunctuation:Ve,autolink:Je,blockSkip:Ne,br:ke,code:Be,del:T,delLDelim:T,delRDelim:T,emStrongLDelim:je,emStrongRDelimAst:Oe,emStrongRDelimUnd:We,escape:Me,link:et,nolink:we,punctuation:Ze,reflink:be,reflinkSearch:tt,tag:Ye,text:qe,url:T},rt={...te,link:g(/^!?\\[(label)\\]\\((.*?)\\)/).replace("label",D).getRegex(),reflink:g(/^!?\\[(label)\\]\\s*\\[([^\\]]*)\\]/).replace("label",D).getRegex()},G={...te,emStrongRDelimAst:Ge,emStrongLDelim:He,delLDelim:Xe,delRDelim:Fe,url:g(/^((?:protocol):\\/\\/|www\\.)(?:[a-zA-Z0-9\\-]+\\.?)+[^\\s<]*|^email/).replace("protocol",se).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_\'"~()&]+|\\([^)]*\\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_\'"~)]+(?!$))+/,del:/^(~~?)(?=[^\\s~])((?:\\\\[\\s\\S]|[^\\\\])*?(?:\\\\[\\s\\S]|[^\\s~\\\\]))\\1(?=[^~]|$)/,text:g(/^(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\\n)|(?=[a-zA-Z0-9.!#$%&\'*+\\/=?_`{\\|}~-]+@)|[\\s\\S]*?(?:(?=[\\\\<!\\[`*~_]|\\b_|protocol:\\/\\/|www\\.|$)|[^ ](?= {2,}\\n)|[^a-zA-Z0-9.!#$%&\'*+\\/=?_`{\\|}~-](?=[a-zA-Z0-9.!#$%&\'*+\\/=?_`{\\|}~-]+@)))/).replace("protocol",se).getRegex()},nt={...G,br:g(ke).replace("{2,}","*").getRegex(),text:g(G.text).replace("\\\\b_","\\\\b_| {2,}\\\\n").replace(/\\{2,\\}/g,"*").getRegex()},Z={normal:Y,gfm:Ce,pedantic:Ee},C={normal:te,gfm:G,breaks:nt,pedantic:rt},st={"&":"&","<":"<",">":">",\'"\':""","\'":"'"},ie=r=>st[r];function y(r,e){if(e){if(b.escapeTest.test(r))return r.replace(b.escapeReplace,ie)}else if(b.escapeTestNoEncode.test(r))return r.replace(b.escapeReplaceNoEncode,ie);return r}function le(r){try{r=encodeURI(r).replace(b.percentDecode,"%")}catch{return null}return r}function ae(r,e){let t=r.replace(b.findPipe,(i,a,l)=>{let o=!1,c=a;for(;--c>=0&&l[c]==="\\\\";)o=!o;return o?"|":" |"}),s=t.split(b.splitPipe),n=0;if(s[0].trim()||s.shift(),s.length>0&&!s.at(-1)?.trim()&&s.pop(),e)if(s.length>e)s.splice(e);else for(;s.length<e;)s.push("");for(;n<s.length;n++)s[n]=s[n].trim().replace(b.slashPipe,"|");return s}function S(r,e,t){let s=r.length;if(s===0)return"";let n=0;for(;n<s;){let i=r.charAt(s-n-1);if(i===e&&!t)n++;else if(i!==e&&t)n++;else break}return r.slice(0,s-n)}function oe(r){let e=r.split(`\n`),t=e.length-1;for(;t>=0&&b.blankLine.test(e[t]);)t--;return e.length-t<=2?r:e.slice(0,t+1).join(`\n`)}function it(r,e){if(r.indexOf(e[1])===-1)return-1;let t=0;for(let s=0;s<r.length;s++)if(r[s]==="\\\\")s++;else if(r[s]===e[0])t++;else if(r[s]===e[1]&&(t--,t<0))return s;return t>0?-2:-1}function lt(r,e=0){let t=e,s="";for(let n of r)if(n===" "){let i=4-t%4;s+=" ".repeat(i),t+=i}else s+=n,t++;return s}function ce(r,e,t,s,n){let i=e.href,a=e.title||null,l=r[1].replace(n.other.outputLinkReplace,"$1");s.state.inLink=!0;let o={type:r[0].charAt(0)==="!"?"image":"link",raw:t,href:i,title:a,text:l,tokens:s.inlineTokens(l)};return s.state.inLink=!1,o}function at(r,e,t){let s=r.match(t.other.indentCodeCompensation);if(s===null)return e;let n=s[1];return e.split(`\n`).map(i=>{let a=i.match(t.other.beginningSpace);if(a===null)return i;let[l]=a;return l.length>=n.length?i.slice(n.length):i}).join(`\n`)}var Q=class{options;rules;lexer;constructor(r){this.options=r||A}space(r){let e=this.rules.block.newline.exec(r);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(r){let e=this.rules.block.code.exec(r);if(e){let t=this.options.pedantic?e[0]:oe(e[0]),s=t.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t,codeBlockStyle:"indented",text:s}}}fences(r){let e=this.rules.block.fences.exec(r);if(e){let t=e[0],s=at(t,e[3]||"",this.rules);return{type:"code",raw:t,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:s}}}heading(r){let e=this.rules.block.heading.exec(r);if(e){let t=e[2].trim();if(this.rules.other.endingHash.test(t)){let s=S(t,"#");(this.options.pedantic||!s||this.rules.other.endingSpaceChar.test(s))&&(t=s.trim())}return{type:"heading",raw:S(e[0],`\n`),depth:e[1].length,text:t,tokens:this.lexer.inline(t)}}}hr(r){let e=this.rules.block.hr.exec(r);if(e)return{type:"hr",raw:S(e[0],`\n`)}}blockquote(r){let e=this.rules.block.blockquote.exec(r);if(e){let t=S(e[0],`\n`).split(`\n`),s="",n="",i=[];for(;t.length>0;){let a=!1,l=[],o;for(o=0;o<t.length;o++)if(this.rules.other.blockquoteStart.test(t[o]))l.push(t[o]),a=!0;else if(!a)l.push(t[o]);else break;t=t.slice(o);let c=l.join(`\n`),p=c.replace(this.rules.other.blockquoteSetextReplace,`\n $1`).replace(this.rules.other.blockquoteSetextReplace2,"");s=s?`${s}\n${c}`:c,n=n?`${n}\n${p}`:p;let h=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(p,i,!0),this.lexer.state.top=h,t.length===0)break;let u=i.at(-1);if(u?.type==="code")break;if(u?.type==="blockquote"){let x=u,f=x.raw+`\n`+t.join(`\n`),d=this.blockquote(f);i[i.length-1]=d,s=s.substring(0,s.length-x.raw.length)+d.raw,n=n.substring(0,n.length-x.text.length)+d.text;break}else if(u?.type==="list"){let x=u,f=x.raw+`\n`+t.join(`\n`),d=this.list(f);i[i.length-1]=d,s=s.substring(0,s.length-u.raw.length)+d.raw,n=n.substring(0,n.length-x.raw.length)+d.raw,t=f.substring(i.at(-1).raw.length).split(`\n`);continue}}return{type:"blockquote",raw:s,tokens:i,text:n}}}list(r){let e=this.rules.block.list.exec(r);if(e){let t=e[1].trim(),s=t.length>1,n={type:"list",raw:"",ordered:s,start:s?+t.slice(0,-1):"",loose:!1,items:[]};t=s?`\\\\d{1,9}\\\\${t.slice(-1)}`:`\\\\${t}`,this.options.pedantic&&(t=s?t:"[*+-]");let i=this.rules.other.listItemRegex(t),a=!1;for(;r;){let o=!1,c="",p="";if(!(e=i.exec(r))||this.rules.block.hr.test(r))break;c=e[0],r=r.substring(c.length);let h=lt(e[2].split(`\n`,1)[0],e[1].length),u=r.split(`\n`,1)[0],x=!h.trim(),f=0;if(this.options.pedantic?(f=2,p=h.trimStart()):x?f=e[1].length+1:(f=h.search(this.rules.other.nonSpaceChar),f=f>4?1:f,p=h.slice(f),f+=e[1].length),x&&this.rules.other.blankLine.test(u)&&(c+=u+`\n`,r=r.substring(u.length+1),o=!0),!o){let d=this.rules.other.nextBulletRegex(f),B=this.rules.other.hrRegex(f),$=this.rules.other.fencesBeginRegex(f),q=this.rules.other.headingBeginRegex(f),R=this.rules.other.htmlBeginRegex(f),v=this.rules.other.blockquoteBeginRegex(f);for(;r;){let O=r.split(`\n`,1)[0],I;if(u=O,this.options.pedantic?(u=u.replace(this.rules.other.listReplaceNesting," "),I=u):I=u.replace(this.rules.other.tabCharGlobal," "),$.test(u)||q.test(u)||R.test(u)||v.test(u)||d.test(u)||B.test(u))break;if(I.search(this.rules.other.nonSpaceChar)>=f||!u.trim())p+=`\n`+I.slice(f);else{if(x||h.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||$.test(h)||q.test(h)||B.test(h))break;p+=`\n`+u}x=!u.trim(),c+=O+`\n`,r=r.substring(O.length+1),h=I.slice(f)}}n.loose||(a?n.loose=!0:this.rules.other.doubleBlankLine.test(c)&&(a=!0)),n.items.push({type:"list_item",raw:c,task:!!this.options.gfm&&this.rules.other.listIsTask.test(p),loose:!1,text:p,tokens:[]}),n.raw+=c}let l=n.items.at(-1);if(l)l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd();else return;n.raw=n.raw.trimEnd();for(let o of n.items){this.lexer.state.top=!1,o.tokens=this.lexer.blockTokens(o.text,[]);let c=o.tokens[0];if(o.task&&(c?.type==="text"||c?.type==="paragraph")){o.text=o.text.replace(this.rules.other.listReplaceTask,""),c.raw=c.raw.replace(this.rules.other.listReplaceTask,""),c.text=c.text.replace(this.rules.other.listReplaceTask,"");for(let h=this.lexer.inlineQueue.length-1;h>=0;h--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[h].src)){this.lexer.inlineQueue[h].src=this.lexer.inlineQueue[h].src.replace(this.rules.other.listReplaceTask,"");break}let p=this.rules.other.listTaskCheckbox.exec(o.raw);if(p){let h={type:"checkbox",raw:p[0]+" ",checked:p[0]!=="[ ]"};o.checked=h.checked,n.loose?o.tokens[0]&&["paragraph","text"].includes(o.tokens[0].type)&&"tokens"in o.tokens[0]&&o.tokens[0].tokens?(o.tokens[0].raw=h.raw+o.tokens[0].raw,o.tokens[0].text=h.raw+o.tokens[0].text,o.tokens[0].tokens.unshift(h)):o.tokens.unshift({type:"paragraph",raw:h.raw,text:h.raw,tokens:[h]}):o.tokens.unshift(h)}}else o.task&&(o.task=!1);if(!n.loose){let p=o.tokens.filter(u=>u.type==="space"),h=p.length>0&&p.some(u=>this.rules.other.anyLine.test(u.raw));n.loose=h}}if(n.loose)for(let o of n.items){o.loose=!0;for(let c of o.tokens)c.type==="text"&&(c.type="paragraph")}return n}}html(r){let e=this.rules.block.html.exec(r);if(e){let t=oe(e[0]);return{type:"html",block:!0,raw:t,pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:t}}}def(r){let e=this.rules.block.def.exec(r);if(e){let t=e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),s=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",n=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:t,raw:S(e[0],`\n`),href:s,title:n}}}table(r){let e=this.rules.block.table.exec(r);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let t=ae(e[1]),s=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),n=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`\n`):[],i={type:"table",raw:S(e[0],`\n`),header:[],align:[],rows:[]};if(t.length===s.length){for(let a of s)this.rules.other.tableAlignRight.test(a)?i.align.push("right"):this.rules.other.tableAlignCenter.test(a)?i.align.push("center"):this.rules.other.tableAlignLeft.test(a)?i.align.push("left"):i.align.push(null);for(let a=0;a<t.length;a++)i.header.push({text:t[a],tokens:this.lexer.inline(t[a]),header:!0,align:i.align[a]});for(let a of n)i.rows.push(ae(a,i.header.length).map((l,o)=>({text:l,tokens:this.lexer.inline(l),header:!1,align:i.align[o]})));return i}}lheading(r){let e=this.rules.block.lheading.exec(r);if(e){let t=e[1].trim();return{type:"heading",raw:S(e[0],`\n`),depth:e[2].charAt(0)==="="?1:2,text:t,tokens:this.lexer.inline(t)}}}paragraph(r){let e=this.rules.block.paragraph.exec(r);if(e){let t=e[1].charAt(e[1].length-1)===`\n`?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:t,tokens:this.lexer.inline(t)}}}text(r){let e=this.rules.block.text.exec(r);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(r){let e=this.rules.inline.escape.exec(r);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(r){let e=this.rules.inline.tag.exec(r);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(r){let e=this.rules.inline.link.exec(r);if(e){let t=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(t)){if(!this.rules.other.endAngleBracket.test(t))return;let i=S(t.slice(0,-1),"\\\\");if((t.length-i.length)%2===0)return}else{let i=it(e[2],"()");if(i===-2)return;if(i>-1){let a=(e[0].indexOf("!")===0?5:4)+e[1].length+i;e[2]=e[2].substring(0,i),e[0]=e[0].substring(0,a).trim(),e[3]=""}}let s=e[2],n="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(s);i&&(s=i[1],n=i[3])}else n=e[3]?e[3].slice(1,-1):"";return s=s.trim(),this.rules.other.startAngleBracket.test(s)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(t)?s=s.slice(1):s=s.slice(1,-1)),ce(e,{href:s&&s.replace(this.rules.inline.anyPunctuation,"$1"),title:n&&n.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(r,e){let t;if((t=this.rules.inline.reflink.exec(r))||(t=this.rules.inline.nolink.exec(r))){let s=(t[2]||t[1]).replace(this.rules.other.multipleSpaceGlobal," "),n=e[s.toLowerCase()];if(!n){let i=t[0].charAt(0);return{type:"text",raw:i,text:i}}return ce(t,n,t[0],this.lexer,this.rules)}}emStrong(r,e,t=""){let s=this.rules.inline.emStrongLDelim.exec(r);if(!(!s||!s[1]&&!s[2]&&!s[3]&&!s[4]||s[4]&&t.match(this.rules.other.unicodeAlphaNumeric))&&(!(s[1]||s[3])||!t||this.rules.inline.punctuation.exec(t))){let n=[...s[0]].length-1,i,a,l=n,o=0,c=s[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(c.lastIndex=0,e=e.slice(-1*r.length+n);(s=c.exec(e))!==null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i)continue;if(a=[...i].length,s[3]||s[4]){l+=a;continue}else if((s[5]||s[6])&&n%3&&!((n+a)%3)){o+=a;continue}if(l-=a,l>0)continue;a=Math.min(a,a+l+o);let p=[...s[0]][0].length,h=r.slice(0,n+s.index+p+a);if(Math.min(n,a)%2){let x=h.slice(1,-1);return{type:"em",raw:h,text:x,tokens:this.lexer.inlineTokens(x)}}let u=h.slice(2,-2);return{type:"strong",raw:h,text:u,tokens:this.lexer.inlineTokens(u)}}}}codespan(r){let e=this.rules.inline.code.exec(r);if(e){let t=e[2].replace(this.rules.other.newLineCharGlobal," "),s=this.rules.other.nonSpaceChar.test(t),n=this.rules.other.startingSpaceChar.test(t)&&this.rules.other.endingSpaceChar.test(t);return s&&n&&(t=t.substring(1,t.length-1)),{type:"codespan",raw:e[0],text:t}}}br(r){let e=this.rules.inline.br.exec(r);if(e)return{type:"br",raw:e[0]}}del(r,e,t=""){let s=this.rules.inline.delLDelim.exec(r);if(s&&(!s[1]||!t||this.rules.inline.punctuation.exec(t))){let n=[...s[0]].length-1,i,a,l=n,o=this.rules.inline.delRDelim;for(o.lastIndex=0,e=e.slice(-1*r.length+n);(s=o.exec(e))!==null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i||(a=[...i].length,a!==n))continue;if(s[3]||s[4]){l+=a;continue}if(l-=a,l>0)continue;a=Math.min(a,a+l);let c=[...s[0]][0].length,p=r.slice(0,n+s.index+c+a),h=p.slice(n,-n);return{type:"del",raw:p,text:h,tokens:this.lexer.inlineTokens(h)}}}}autolink(r){let e=this.rules.inline.autolink.exec(r);if(e){let t,s;return e[2]==="@"?(t=e[1],s="mailto:"+t):(t=e[1],s=t),{type:"link",raw:e[0],text:t,href:s,tokens:[{type:"text",raw:t,text:t}]}}}url(r){let e;if(e=this.rules.inline.url.exec(r)){let t,s;if(e[2]==="@")t=e[0],s="mailto:"+t;else{let n;do n=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(n!==e[0]);t=e[0],e[1]==="www."?s="http://"+e[0]:s=e[0]}return{type:"link",raw:e[0],text:t,href:s,tokens:[{type:"text",raw:t,text:t}]}}}inlineText(r){let e=this.rules.inline.text.exec(r);if(e){let t=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:t}}}},w=class W{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||A,this.options.tokenizer=this.options.tokenizer||new Q,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:b,block:Z.normal,inline:C.normal};this.options.pedantic?(t.block=Z.pedantic,t.inline=C.pedantic):this.options.gfm&&(t.block=Z.gfm,this.options.breaks?t.inline=C.breaks:t.inline=C.gfm),this.tokenizer.rules=t}static get rules(){return{block:Z,inline:C}}static lex(e,t){return new W(t).lex(e)}static lexInline(e,t){return new W(t).inlineTokens(e)}lex(e){e=e.replace(b.carriageReturn,`\n`),this.blockTokens(e,this.tokens);for(let t=0;t<this.inlineQueue.length;t++){let s=this.inlineQueue[t];this.inlineTokens(s.src,s.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],s=!1){this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(b.tabCharGlobal," ").replace(b.spaceLine,""));let n=1/0;for(;e;){if(e.length<n)n=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}let i;if(this.options.extensions?.block?.some(l=>(i=l.call({lexer:this},e,t))?(e=e.substring(i.raw.length),t.push(i),!0):!1))continue;if(i=this.tokenizer.space(e)){e=e.substring(i.raw.length);let l=t.at(-1);i.raw.length===1&&l!==void 0?l.raw+=`\n`:t.push(i);continue}if(i=this.tokenizer.code(e)){e=e.substring(i.raw.length);let l=t.at(-1);l?.type==="paragraph"||l?.type==="text"?(l.raw+=(l.raw.endsWith(`\n`)?"":`\n`)+i.raw,l.text+=`\n`+i.text,this.inlineQueue.at(-1).src=l.text):t.push(i);continue}if(i=this.tokenizer.fences(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.heading(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.hr(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.blockquote(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.list(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.html(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.def(e)){e=e.substring(i.raw.length);let l=t.at(-1);l?.type==="paragraph"||l?.type==="text"?(l.raw+=(l.raw.endsWith(`\n`)?"":`\n`)+i.raw,l.text+=`\n`+i.raw,this.inlineQueue.at(-1).src=l.text):this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title},t.push(i));continue}if(i=this.tokenizer.table(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.lheading(e)){e=e.substring(i.raw.length),t.push(i);continue}let a=e;if(this.options.extensions?.startBlock){let l=1/0,o=e.slice(1),c;this.options.extensions.startBlock.forEach(p=>{c=p.call({lexer:this},o),typeof c=="number"&&c>=0&&(l=Math.min(l,c))}),l<1/0&&l>=0&&(a=e.substring(0,l+1))}if(this.state.top&&(i=this.tokenizer.paragraph(a))){let l=t.at(-1);s&&l?.type==="paragraph"?(l.raw+=(l.raw.endsWith(`\n`)?"":`\n`)+i.raw,l.text+=`\n`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=l.text):t.push(i),s=a.length!==e.length,e=e.substring(i.raw.length);continue}if(i=this.tokenizer.text(e)){e=e.substring(i.raw.length);let l=t.at(-1);l?.type==="text"?(l.raw+=(l.raw.endsWith(`\n`)?"":`\n`)+i.raw,l.text+=`\n`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=l.text):t.push(i);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){this.tokenizer.lexer=this;let s=e;if(this.tokens.links){let l=Object.keys(this.tokens.links);l.length>0&&(s=s.replace(this.tokenizer.rules.inline.reflinkSearch,o=>l.includes(o.slice(o.lastIndexOf("[")+1,-1))?"["+"a".repeat(o.length-2)+"]":o))}s=s.replace(this.tokenizer.rules.inline.anyPunctuation,"++"),s=s.replace(this.tokenizer.rules.inline.blockSkip,(l,o,c)=>{let p=c?c.length:0;return l.slice(0,p)+"["+"a".repeat(l.length-p-2)+"]"}),s=this.options.hooks?.emStrongMask?.call({lexer:this},s)??s;let n=!1,i="",a=1/0;for(;e;){if(e.length<a)a=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}n||(i=""),n=!1;let l;if(this.options.extensions?.inline?.some(c=>(l=c.call({lexer:this},e,t))?(e=e.substring(l.raw.length),t.push(l),!0):!1))continue;if(l=this.tokenizer.escape(e)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.tag(e)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.link(e)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(l.raw.length);let c=t.at(-1);l.type==="text"&&c?.type==="text"?(c.raw+=l.raw,c.text+=l.text):t.push(l);continue}if(l=this.tokenizer.emStrong(e,s,i)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.codespan(e)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.br(e)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.del(e,s,i)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.autolink(e)){e=e.substring(l.raw.length),t.push(l);continue}if(!this.state.inLink&&(l=this.tokenizer.url(e))){e=e.substring(l.raw.length),t.push(l);continue}let o=e;if(this.options.extensions?.startInline){let c=1/0,p=e.slice(1),h;this.options.extensions.startInline.forEach(u=>{h=u.call({lexer:this},p),typeof h=="number"&&h>=0&&(c=Math.min(c,h))}),c<1/0&&c>=0&&(o=e.substring(0,c+1))}if(l=this.tokenizer.inlineText(o)){e=e.substring(l.raw.length),l.raw.slice(-1)!=="_"&&(i=l.raw.slice(-1)),n=!0;let c=t.at(-1);c?.type==="text"?(c.raw+=l.raw,c.text+=l.text):t.push(l);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return t}infiniteLoopError(e){let t="Infinite loop on byte: "+e;if(this.options.silent)console.error(t);else throw new Error(t)}},N=class{options;parser;constructor(r){this.options=r||A}space(r){return""}code({text:r,lang:e,escaped:t}){let s=(e||"").match(b.notSpaceStart)?.[0],n=r.replace(b.endingNewline,"")+`\n`;return s?\'<pre><code class="language-\'+y(s)+\'">\'+(t?n:y(n,!0))+`</code></pre>\n`:"<pre><code>"+(t?n:y(n,!0))+`</code></pre>\n`}blockquote({tokens:r}){return`<blockquote>\n${this.parser.parse(r)}</blockquote>\n`}html({text:r}){return r}def(r){return""}heading({tokens:r,depth:e}){return`<h${e}>${this.parser.parseInline(r)}</h${e}>\n`}hr(r){return`<hr>\n`}list(r){let e=r.ordered,t=r.start,s="";for(let a=0;a<r.items.length;a++){let l=r.items[a];s+=this.listitem(l)}let n=e?"ol":"ul",i=e&&t!==1?\' start="\'+t+\'"\':"";return"<"+n+i+`>\n`+s+"</"+n+`>\n`}listitem(r){return`<li>${this.parser.parse(r.tokens)}</li>\n`}checkbox({checked:r}){return"<input "+(r?\'checked="" \':"")+\'disabled="" type="checkbox"> \'}paragraph({tokens:r}){return`<p>${this.parser.parseInline(r)}</p>\n`}table(r){let e="",t="";for(let n=0;n<r.header.length;n++)t+=this.tablecell(r.header[n]);e+=this.tablerow({text:t});let s="";for(let n=0;n<r.rows.length;n++){let i=r.rows[n];t="";for(let a=0;a<i.length;a++)t+=this.tablecell(i[a]);s+=this.tablerow({text:t})}return s&&(s=`<tbody>${s}</tbody>`),`<table>\n<thead>\n`+e+`</thead>\n`+s+`</table>\n`}tablerow({text:r}){return`<tr>\n${r}</tr>\n`}tablecell(r){let e=this.parser.parseInline(r.tokens),t=r.header?"th":"td";return(r.align?`<${t} align="${r.align}">`:`<${t}>`)+e+`</${t}>\n`}strong({tokens:r}){return`<strong>${this.parser.parseInline(r)}</strong>`}em({tokens:r}){return`<em>${this.parser.parseInline(r)}</em>`}codespan({text:r}){return`<code>${y(r,!0)}</code>`}br(r){return"<br>"}del({tokens:r}){return`<del>${this.parser.parseInline(r)}</del>`}link({href:r,title:e,tokens:t}){let s=this.parser.parseInline(t),n=le(r);if(n===null)return s;r=n;let i=\'<a href="\'+r+\'"\';return e&&(i+=\' title="\'+y(e)+\'"\'),i+=">"+s+"</a>",i}image({href:r,title:e,text:t,tokens:s}){s&&(t=this.parser.parseInline(s,this.parser.textRenderer));let n=le(r);if(n===null)return y(t);r=n;let i=`<img src="${r}" alt="${y(t)}"`;return e&&(i+=` title="${y(e)}"`),i+=">",i}text(r){return"tokens"in r&&r.tokens?this.parser.parseInline(r.tokens):"escaped"in r&&r.escaped?r.text:y(r.text)}},re=class{strong({text:r}){return r}em({text:r}){return r}codespan({text:r}){return r}del({text:r}){return r}html({text:r}){return r}text({text:r}){return r}link({text:r}){return""+r}image({text:r}){return""+r}br(){return""}checkbox({raw:r}){return r}},m=class X{options;renderer;textRenderer;constructor(e){this.options=e||A,this.options.renderer=this.options.renderer||new N,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new re}static parse(e,t){return new X(t).parse(e)}static parseInline(e,t){return new X(t).parseInline(e)}parse(e){this.renderer.parser=this;let t="";for(let s=0;s<e.length;s++){let n=e[s];if(this.options.extensions?.renderers?.[n.type]){let a=n,l=this.options.extensions.renderers[a.type].call({parser:this},a);if(l!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(a.type)){t+=l||"";continue}}let i=n;switch(i.type){case"space":{t+=this.renderer.space(i);break}case"hr":{t+=this.renderer.hr(i);break}case"heading":{t+=this.renderer.heading(i);break}case"code":{t+=this.renderer.code(i);break}case"table":{t+=this.renderer.table(i);break}case"blockquote":{t+=this.renderer.blockquote(i);break}case"list":{t+=this.renderer.list(i);break}case"checkbox":{t+=this.renderer.checkbox(i);break}case"html":{t+=this.renderer.html(i);break}case"def":{t+=this.renderer.def(i);break}case"paragraph":{t+=this.renderer.paragraph(i);break}case"text":{t+=this.renderer.text(i);break}default:{let a=\'Token with "\'+i.type+\'" type was not found.\';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return t}parseInline(e,t=this.renderer){this.renderer.parser=this;let s="";for(let n=0;n<e.length;n++){let i=e[n];if(this.options.extensions?.renderers?.[i.type]){let l=this.options.extensions.renderers[i.type].call({parser:this},i);if(l!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){s+=l||"";continue}}let a=i;switch(a.type){case"escape":{s+=t.text(a);break}case"html":{s+=t.html(a);break}case"link":{s+=t.link(a);break}case"image":{s+=t.image(a);break}case"checkbox":{s+=t.checkbox(a);break}case"strong":{s+=t.strong(a);break}case"em":{s+=t.em(a);break}case"codespan":{s+=t.codespan(a);break}case"br":{s+=t.br(a);break}case"del":{s+=t.del(a);break}case"text":{s+=t.text(a);break}default:{let l=\'Token with "\'+a.type+\'" type was not found.\';if(this.options.silent)return console.error(l),"";throw new Error(l)}}}return s}},E=class{options;block;constructor(r){this.options=r||A}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(r){return r}postprocess(r){return r}processAllTokens(r){return r}emStrongMask(r){return r}provideLexer(r=this.block){return r?w.lex:w.lexInline}provideParser(r=this.block){return r?m.parse:m.parseInline}},ot=class{defaults=U();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=m;Renderer=N;TextRenderer=re;Lexer=w;Tokenizer=Q;Hooks=E;constructor(...r){this.use(...r)}walkTokens(r,e){let t=[];for(let s of r)switch(t=t.concat(e.call(this,s)),s.type){case"table":{let n=s;for(let i of n.header)t=t.concat(this.walkTokens(i.tokens,e));for(let i of n.rows)for(let a of i)t=t.concat(this.walkTokens(a.tokens,e));break}case"list":{let n=s;t=t.concat(this.walkTokens(n.items,e));break}default:{let n=s;this.defaults.extensions?.childTokens?.[n.type]?this.defaults.extensions.childTokens[n.type].forEach(i=>{let a=n[i].flat(1/0);t=t.concat(this.walkTokens(a,e))}):n.tokens&&(t=t.concat(this.walkTokens(n.tokens,e)))}}return t}use(...r){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return r.forEach(t=>{let s={...t};if(s.async=this.defaults.async||s.async||!1,t.extensions&&(t.extensions.forEach(n=>{if(!n.name)throw new Error("extension name required");if("renderer"in n){let i=e.renderers[n.name];i?e.renderers[n.name]=function(...a){let l=n.renderer.apply(this,a);return l===!1&&(l=i.apply(this,a)),l}:e.renderers[n.name]=n.renderer}if("tokenizer"in n){if(!n.level||n.level!=="block"&&n.level!=="inline")throw new Error("extension level must be \'block\' or \'inline\'");let i=e[n.level];i?i.unshift(n.tokenizer):e[n.level]=[n.tokenizer],n.start&&(n.level==="block"?e.startBlock?e.startBlock.push(n.start):e.startBlock=[n.start]:n.level==="inline"&&(e.startInline?e.startInline.push(n.start):e.startInline=[n.start]))}"childTokens"in n&&n.childTokens&&(e.childTokens[n.name]=n.childTokens)}),s.extensions=e),t.renderer){let n=this.defaults.renderer||new N(this.defaults);for(let i in t.renderer){if(!(i in n))throw new Error(`renderer \'${i}\' does not exist`);if(["options","parser"].includes(i))continue;let a=i,l=t.renderer[a],o=n[a];n[a]=(...c)=>{let p=l.apply(n,c);return p===!1&&(p=o.apply(n,c)),p||""}}s.renderer=n}if(t.tokenizer){let n=this.defaults.tokenizer||new Q(this.defaults);for(let i in t.tokenizer){if(!(i in n))throw new Error(`tokenizer \'${i}\' does not exist`);if(["options","rules","lexer"].includes(i))continue;let a=i,l=t.tokenizer[a],o=n[a];n[a]=(...c)=>{let p=l.apply(n,c);return p===!1&&(p=o.apply(n,c)),p}}s.tokenizer=n}if(t.hooks){let n=this.defaults.hooks||new E;for(let i in t.hooks){if(!(i in n))throw new Error(`hook \'${i}\' does not exist`);if(["options","block"].includes(i))continue;let a=i,l=t.hooks[a],o=n[a];E.passThroughHooks.has(i)?n[a]=c=>{if(this.defaults.async&&E.passThroughHooksRespectAsync.has(i))return(async()=>{let h=await l.call(n,c);return o.call(n,h)})();let p=l.call(n,c);return o.call(n,p)}:n[a]=(...c)=>{if(this.defaults.async)return(async()=>{let h=await l.apply(n,c);return h===!1&&(h=await o.apply(n,c)),h})();let p=l.apply(n,c);return p===!1&&(p=o.apply(n,c)),p}}s.hooks=n}if(t.walkTokens){let n=this.defaults.walkTokens,i=t.walkTokens;s.walkTokens=function(a){let l=[];return l.push(i.call(this,a)),n&&(l=l.concat(n.call(this,a))),l}}this.defaults={...this.defaults,...s}}),this}setOptions(r){return this.defaults={...this.defaults,...r},this}lexer(r,e){return w.lex(r,e??this.defaults)}parser(r,e){return m.parse(r,e??this.defaults)}parseMarkdown(r){return(e,t)=>{let s={...t},n={...this.defaults,...s},i=this.onError(!!n.silent,!!n.async);if(this.defaults.async===!0&&s.async===!1)return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof e>"u"||e===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));if(n.hooks&&(n.hooks.options=n,n.hooks.block=r),n.async)return(async()=>{let a=n.hooks?await n.hooks.preprocess(e):e,l=await(n.hooks?await n.hooks.provideLexer(r):r?w.lex:w.lexInline)(a,n),o=n.hooks?await n.hooks.processAllTokens(l):l;n.walkTokens&&await Promise.all(this.walkTokens(o,n.walkTokens));let c=await(n.hooks?await n.hooks.provideParser(r):r?m.parse:m.parseInline)(o,n);return n.hooks?await n.hooks.postprocess(c):c})().catch(i);try{n.hooks&&(e=n.hooks.preprocess(e));let a=(n.hooks?n.hooks.provideLexer(r):r?w.lex:w.lexInline)(e,n);n.hooks&&(a=n.hooks.processAllTokens(a)),n.walkTokens&&this.walkTokens(a,n.walkTokens);let l=(n.hooks?n.hooks.provideParser(r):r?m.parse:m.parseInline)(a,n);return n.hooks&&(l=n.hooks.postprocess(l)),l}catch(a){return i(a)}}}onError(r,e){return t=>{if(t.message+=`\nPlease report this to https://github.com/markedjs/marked.`,r){let s="<p>An error occurred:</p><pre>"+y(t.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(t);throw t}}},z=new ot;function k(r,e){return z.parse(r,e)}k.options=k.setOptions=function(r){return z.setOptions(r),k.defaults=z.defaults,he(k.defaults),k};k.getDefaults=U;k.defaults=A;k.use=function(...r){return z.use(...r),k.defaults=z.defaults,he(k.defaults),k};k.walkTokens=function(r,e){return z.walkTokens(r,e)};k.parseInline=z.parseInline;k.Parser=m;k.parser=m.parse;k.Renderer=N;k.TextRenderer=re;k.Lexer=w;k.lexer=w.lex;k.Tokenizer=Q;k.Hooks=E;k.parse=k;var ut=k.options,gt=k.setOptions,kt=k.use,ft=k.walkTokens,dt=k.parseInline;var xt=m.parse,bt=w.lex;var ct=0;function ht(r){if(typeof r!="string"||typeof performance.mark!="function"||typeof performance.measure!="function")return null;let e=ct++,t={name:r,startMark:`${r}:start:${e}`,endMark:`${r}:end:${e}`};try{return performance.mark(t.startMark),t}catch{return null}}function pt(r){if(r)try{performance.mark(r.endMark),performance.measure(r.name,r.startMark,r.endMark)}catch{}finally{try{performance.clearMarks?.(r.startMark),performance.clearMarks?.(r.endMark)}catch{}}}k.use({extensions:[{name:"inlineMath",level:"inline",start(r){return r.match(/(?<![\\\\$])\\$(?![$\\s])/)?.index},tokenizer(r){let e=/^\\$(?![$\\s\\d])((?:\\\\\\$|[^$\\n])*?)(?<!\\s)\\$(?!\\d)/.exec(r);if(e)return{type:"inlineMath",raw:e[0],text:e[1].trim()}},renderer(r){return r.raw}}]});var P=new Map;self.onmessage=r=>{let e=r.data;if(typeof e!="object"||e===null)return;let{id:t,text:s,append:n,expectedLength:i,oldRaws:a,instance:l,baseVersion:o,dispose:c,userTimingName:p}=e;if(c===!0){typeof l=="string"&&P.delete(l);return}let h=typeof l=="string"?l:null,u=typeof o=="number"?o:null,x,f=null;if(typeof n=="string"){if(h===null||u===null){self.postMessage({id:t,needResync:!0});return}let d=P.get(h);if(!d||d.version!==u){self.postMessage({id:t,needResync:!0});return}if(x=d.source+n,typeof i=="number"&&x.length!==i){P.delete(h),self.postMessage({id:t,needResync:!0});return}f=d.raws}else if(typeof s=="string"){if(x=s,Array.isArray(a))f=a;else if(h!==null&&u!==null){let d=P.get(h);if(d&&d.version===u)f=d.raws;else{self.postMessage({id:t,needResync:!0});return}}}else return;try{let d=typeof p=="string"?ht(p):null,B=performance.now(),$;try{$=k.lexer(x)}finally{d&&pt(d)}let q=performance.now()-B,R=0;if(f){let v=Math.min(f.length,$.length);for(;R<v&&f[R]===$[R].raw;R++);}h!==null&&u!==null&&P.set(h,{version:u+1,raws:$.map(v=>v.raw),source:x}),self.postMessage({id:t,matchLen:R,tail:$.slice(R),lexerMs:q,sourceCharsLexed:x.length})}catch(d){h!==null&&P.delete(h),self.postMessage({id:t,error:String(d)})}};})();\n';
|
|
43
428
|
|
|
44
429
|
// src/Markdown.ts
|
|
45
430
|
var now = () => typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
|
|
431
|
+
function lexMarkdown(text, userTiming) {
|
|
432
|
+
if (!userTiming) return import_marked.marked.lexer(text);
|
|
433
|
+
const timing = (0, import_core.beginVectoUserTiming)(import_core.VECTO_USER_TIMING.markdown.parse);
|
|
434
|
+
try {
|
|
435
|
+
return import_marked.marked.lexer(text);
|
|
436
|
+
} finally {
|
|
437
|
+
if (timing) (0, import_core.endVectoUserTiming)(timing);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
46
440
|
import_marked.marked.use({
|
|
47
441
|
extensions: [
|
|
48
442
|
{
|
|
@@ -96,7 +490,7 @@ var workerInstanceCounter = 0;
|
|
|
96
490
|
var workerCallbacks = /* @__PURE__ */ new Map();
|
|
97
491
|
function runSyncFallback(entry) {
|
|
98
492
|
try {
|
|
99
|
-
entry.cb(0,
|
|
493
|
+
entry.cb(0, lexMarkdown(entry.text, entry.userTiming), true);
|
|
100
494
|
} catch (err) {
|
|
101
495
|
console.warn("Markdown sync fallback parse failed", err);
|
|
102
496
|
}
|
|
@@ -108,16 +502,19 @@ if (typeof Worker !== "undefined") {
|
|
|
108
502
|
});
|
|
109
503
|
markdownWorker = new Worker(URL.createObjectURL(blob));
|
|
110
504
|
markdownWorker.onmessage = (e) => {
|
|
111
|
-
const { id, matchLen, tail, error,
|
|
505
|
+
const { id, matchLen, tail, error, needResync, lexerMs, sourceCharsLexed } = e.data;
|
|
112
506
|
const entry = workerCallbacks.get(id);
|
|
113
507
|
if (entry) {
|
|
114
508
|
workerCallbacks.delete(id);
|
|
115
|
-
if (
|
|
116
|
-
entry.
|
|
117
|
-
} else if (
|
|
509
|
+
if (needResync && entry.onNeedResync) {
|
|
510
|
+
entry.onNeedResync();
|
|
511
|
+
} else if (needResync) {
|
|
118
512
|
runSyncFallback(entry);
|
|
119
513
|
} else if (!error) {
|
|
120
|
-
entry.cb(matchLen, tail
|
|
514
|
+
entry.cb(matchLen, tail, false, {
|
|
515
|
+
lexerMs: typeof lexerMs === "number" ? lexerMs : 0,
|
|
516
|
+
sourceCharsLexed: typeof sourceCharsLexed === "number" ? sourceCharsLexed : 0
|
|
517
|
+
});
|
|
121
518
|
} else {
|
|
122
519
|
runSyncFallback(entry);
|
|
123
520
|
}
|
|
@@ -744,8 +1141,19 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
744
1141
|
theme;
|
|
745
1142
|
onLinkClick;
|
|
746
1143
|
selectable;
|
|
1144
|
+
activeBlockMetrics = null;
|
|
1145
|
+
/**
|
|
1146
|
+
* Called after a streamed append has re-laid-out the document.
|
|
1147
|
+
*
|
|
1148
|
+
* Not required for a `VirtualList` to track a streaming row's height: the list
|
|
1149
|
+
* re-reads `height` on every mounted row each frame, so it sees this entity grow
|
|
1150
|
+
* without being told. Prefer that over wiring this up — it fires from the append
|
|
1151
|
+
* path only, **not** from `setContent()`, so it is not a complete size signal.
|
|
1152
|
+
*/
|
|
747
1153
|
onLayoutUpdated;
|
|
748
1154
|
rawMarkdown;
|
|
1155
|
+
streamController = null;
|
|
1156
|
+
_userTiming;
|
|
749
1157
|
tokens = [];
|
|
750
1158
|
// At most one worker lex request in flight at a time. Required for the
|
|
751
1159
|
// delta-transfer protocol below to be safe: the request captures a
|
|
@@ -760,19 +1168,38 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
760
1168
|
/**
|
|
761
1169
|
* Streaming counters for the DevTools inspector.
|
|
762
1170
|
*
|
|
763
|
-
* Cheap enough to keep always-on (
|
|
764
|
-
*
|
|
765
|
-
*
|
|
766
|
-
*
|
|
767
|
-
*
|
|
1171
|
+
* Cheap enough to keep always-on (a handful of integer increments per append).
|
|
1172
|
+
*
|
|
1173
|
+
* These describe the **token diff and the transfer**, not the parser. `marked`
|
|
1174
|
+
* has no incremental lexing API, so the worker calls `marked.lexer()` on the
|
|
1175
|
+
* whole accumulated source for every chunk and the lexer's cost is O(document)
|
|
1176
|
+
* per append no matter how well the diff goes. That is what `lexerMs` and
|
|
1177
|
+
* `sourceCharsLexed` are for; an earlier version of these counters was named as
|
|
1178
|
+
* though a high prefix match meant less lexing, which sent readers to optimise
|
|
1179
|
+
* the already-solved transfer path.
|
|
768
1180
|
*/
|
|
769
1181
|
streamStats = {
|
|
770
1182
|
appends: 0,
|
|
771
1183
|
workerResponses: 0,
|
|
772
|
-
/**
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
1184
|
+
/**
|
|
1185
|
+
* Sum of `matchLen`: leading tokens whose `raw` was unchanged, so the main
|
|
1186
|
+
* thread kept its existing token objects and child entities. A prefix match,
|
|
1187
|
+
* not a lexer saving — the worker still lexed them.
|
|
1188
|
+
*/
|
|
1189
|
+
tokensPrefixMatched: 0,
|
|
1190
|
+
/**
|
|
1191
|
+
* Sum of returned tail lengths: tokens the worker sent back because their
|
|
1192
|
+
* `raw` differed. This is the structured-clone payload size in tokens, which
|
|
1193
|
+
* is what the delta protocol exists to keep small.
|
|
1194
|
+
*/
|
|
1195
|
+
tokensReturned: 0,
|
|
1196
|
+
/** Total ms spent inside `marked.lexer()` across worker responses. */
|
|
1197
|
+
lexerMs: 0,
|
|
1198
|
+
/**
|
|
1199
|
+
* Characters handed to the lexer, summed across responses. Grows ~O(n^2) over
|
|
1200
|
+
* a stream of n chunks, because every chunk re-lexes the whole document.
|
|
1201
|
+
*/
|
|
1202
|
+
sourceCharsLexed: 0,
|
|
776
1203
|
/** Total round-trip ms across worker lex requests, dispatch to callback. */
|
|
777
1204
|
workerMs: 0,
|
|
778
1205
|
/** Longest single worker round trip, which is what a dropped frame feels. */
|
|
@@ -782,7 +1209,7 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
782
1209
|
* worker matched and did not re-read.
|
|
783
1210
|
*/
|
|
784
1211
|
stablePrefixChars: 0,
|
|
785
|
-
/** Source length of the tail
|
|
1212
|
+
/** Source length of the tail whose tokens changed on the most recent append. */
|
|
786
1213
|
changedTailChars: 0,
|
|
787
1214
|
/** Child entities kept across reconciles, either untouched or updated in place. */
|
|
788
1215
|
entitiesReused: 0,
|
|
@@ -803,6 +1230,23 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
803
1230
|
// that cache instead of silently diffing against stale raws.
|
|
804
1231
|
workerInstanceId = `md-${workerInstanceCounter++}`;
|
|
805
1232
|
tokenVersion = 0;
|
|
1233
|
+
/**
|
|
1234
|
+
* How many characters of {@link rawMarkdown} the worker is known to hold.
|
|
1235
|
+
*
|
|
1236
|
+
* The worker keeps the document source too, not just the prior token raws, so a
|
|
1237
|
+
* steady-state append posts only the new chunk instead of the whole document —
|
|
1238
|
+
* that term was O(document) per chunk, i.e. O(N²) over a stream, and unlike the
|
|
1239
|
+
* re-lex it accompanies it is paid on the MAIN thread (structured-cloning the
|
|
1240
|
+
* string happens in `postMessage`, not in the worker). Measured on a 240Hz
|
|
1241
|
+
* panel: 4µs per append at 8KB rising to 220µs at 512KB on Chrome, against a
|
|
1242
|
+
* flat ~2µs for a chunk-sized post.
|
|
1243
|
+
*
|
|
1244
|
+
* 0 means the worker holds nothing for this instance, so the next request must
|
|
1245
|
+
* carry the full text. It is only advanced when a response proves the worker
|
|
1246
|
+
* accepted that source, and reset to 0 by anything the worker did not produce
|
|
1247
|
+
* ({@link setContent}, a sync-fallback parse, a worker error or crash).
|
|
1248
|
+
*/
|
|
1249
|
+
workerSourceLen = 0;
|
|
806
1250
|
// `tokenChildPrefix[i]` = how many of `tokens[0..i)` render a child entity, so
|
|
807
1251
|
// `updateTokens` can map a token index to its child slot in O(1). Maintained
|
|
808
1252
|
// incrementally by setTokens() (only the changed suffix is recomputed).
|
|
@@ -838,6 +1282,7 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
838
1282
|
this.theme = { ...DEFAULT_THEME, ...opts.theme };
|
|
839
1283
|
this.onLinkClick = opts.onLinkClick;
|
|
840
1284
|
this.selectable = opts.selectable ?? true;
|
|
1285
|
+
this._userTiming = opts.userTiming ?? false;
|
|
841
1286
|
this.content = new import_ui.Stack({ direction: "vertical", gap: 16 });
|
|
842
1287
|
this.add(this.content);
|
|
843
1288
|
this.rawMarkdown = markdownText;
|
|
@@ -845,7 +1290,7 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
845
1290
|
this.renderMarkdown(markdownText);
|
|
846
1291
|
}
|
|
847
1292
|
renderMarkdown(text) {
|
|
848
|
-
const tokens =
|
|
1293
|
+
const tokens = lexMarkdown(text, this._userTiming);
|
|
849
1294
|
this.setTokens(tokens);
|
|
850
1295
|
for (const token of tokens) {
|
|
851
1296
|
const el = this.renderToken(token);
|
|
@@ -856,9 +1301,32 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
856
1301
|
this.width = this.content.width;
|
|
857
1302
|
this.height = this.content.height;
|
|
858
1303
|
}
|
|
1304
|
+
/** Create a frame-coalesced stream bound to this Markdown instance. */
|
|
1305
|
+
createStream(options = {}) {
|
|
1306
|
+
if (this.streamController) {
|
|
1307
|
+
throw new Error("Markdown already has an active StreamController");
|
|
1308
|
+
}
|
|
1309
|
+
const controller = createStreamController(
|
|
1310
|
+
{
|
|
1311
|
+
append: (chunk) => this.appendMarkdownCore(chunk),
|
|
1312
|
+
release: (released) => {
|
|
1313
|
+
if (this.streamController === released) this.streamController = null;
|
|
1314
|
+
}
|
|
1315
|
+
},
|
|
1316
|
+
options
|
|
1317
|
+
);
|
|
1318
|
+
if (controller.state === "open") this.streamController = controller;
|
|
1319
|
+
return controller;
|
|
1320
|
+
}
|
|
859
1321
|
/** Replace all markdown content (full rebuild). */
|
|
860
1322
|
setContent(markdown) {
|
|
1323
|
+
this.streamController?.abort(new Error("Markdown content was replaced"));
|
|
1324
|
+
for (const id of this.pendingWorkerIds) workerCallbacks.delete(id);
|
|
1325
|
+
this.pendingWorkerIds.clear();
|
|
1326
|
+
this.appendInFlight = false;
|
|
1327
|
+
this.appendPending = false;
|
|
861
1328
|
this.rawMarkdown = markdown;
|
|
1329
|
+
this.workerSourceLen = 0;
|
|
862
1330
|
while (this.content.children.length > 0) {
|
|
863
1331
|
this.content.children[this.content.children.length - 1].destroy();
|
|
864
1332
|
}
|
|
@@ -873,6 +1341,7 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
873
1341
|
* content subtree via `super.destroy()` so every block's resources are freed.
|
|
874
1342
|
*/
|
|
875
1343
|
destroy() {
|
|
1344
|
+
this.streamController?.destroy();
|
|
876
1345
|
for (const id of this.pendingWorkerIds) workerCallbacks.delete(id);
|
|
877
1346
|
this.pendingWorkerIds.clear();
|
|
878
1347
|
this.appendInFlight = false;
|
|
@@ -887,24 +1356,38 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
887
1356
|
* Streaming and parse state — the markdown streaming inspector.
|
|
888
1357
|
*
|
|
889
1358
|
* Source length, chunk count, worker in-flight state, and the stable-prefix
|
|
890
|
-
* versus
|
|
1359
|
+
* versus changed-tail split. That last ratio is the one worth watching: it is
|
|
891
1360
|
* how you tell incremental reuse is working from outside, and nothing else
|
|
892
1361
|
* surfaces it. A ratio near 1 means the worker matched almost the whole prefix
|
|
893
|
-
* and only
|
|
1362
|
+
* and rebuilt only the tail's entities; near 0 means almost nothing was reused.
|
|
1363
|
+
* Neither says anything about lexer CPU, which is O(document) per append — that
|
|
1364
|
+
* is what the Parser cost group reports.
|
|
894
1365
|
*/
|
|
895
1366
|
getDevtoolsDescriptor() {
|
|
896
1367
|
const s = this.streamStats;
|
|
897
|
-
const
|
|
898
|
-
const
|
|
1368
|
+
const diffedTokens = s.tokensPrefixMatched + s.tokensReturned;
|
|
1369
|
+
const tokenPrefixReuseRatio = diffedTokens > 0 ? s.tokensPrefixMatched / diffedTokens : 0;
|
|
899
1370
|
return {
|
|
900
1371
|
kind: "Markdown",
|
|
901
1372
|
groups: [
|
|
902
1373
|
{
|
|
903
1374
|
label: "Source",
|
|
904
1375
|
fields: [
|
|
905
|
-
{
|
|
906
|
-
|
|
907
|
-
|
|
1376
|
+
{
|
|
1377
|
+
label: "sourceLength",
|
|
1378
|
+
value: this.rawMarkdown.length,
|
|
1379
|
+
readOnly: true
|
|
1380
|
+
},
|
|
1381
|
+
{
|
|
1382
|
+
label: "topLevelTokens",
|
|
1383
|
+
value: this.tokens.length,
|
|
1384
|
+
readOnly: true
|
|
1385
|
+
},
|
|
1386
|
+
{
|
|
1387
|
+
label: "childEntities",
|
|
1388
|
+
value: this.content.children.length,
|
|
1389
|
+
readOnly: true
|
|
1390
|
+
},
|
|
908
1391
|
{ label: "selectable", value: this.selectable }
|
|
909
1392
|
]
|
|
910
1393
|
},
|
|
@@ -924,7 +1407,11 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
924
1407
|
hint: "One lex request at a time; the delta protocol requires it",
|
|
925
1408
|
readOnly: true
|
|
926
1409
|
},
|
|
927
|
-
{
|
|
1410
|
+
{
|
|
1411
|
+
label: "appendPending",
|
|
1412
|
+
value: this.appendPending,
|
|
1413
|
+
readOnly: true
|
|
1414
|
+
},
|
|
928
1415
|
{
|
|
929
1416
|
label: "workerMsAvg",
|
|
930
1417
|
value: s.workerResponses > 0 ? Math.round(s.workerMs / s.workerResponses * 100) / 100 : 0,
|
|
@@ -951,7 +1438,7 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
951
1438
|
{
|
|
952
1439
|
label: "changedTailChars",
|
|
953
1440
|
value: s.changedTailChars,
|
|
954
|
-
hint: "Source characters
|
|
1441
|
+
hint: "Source characters whose tokens changed on the last append. Growing with the document means the delta is not a delta",
|
|
955
1442
|
readOnly: true
|
|
956
1443
|
},
|
|
957
1444
|
{
|
|
@@ -978,21 +1465,38 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
978
1465
|
label: "Incremental reuse",
|
|
979
1466
|
fields: [
|
|
980
1467
|
{
|
|
981
|
-
label: "
|
|
982
|
-
value: s.
|
|
983
|
-
hint: "Sum of matchLen:
|
|
1468
|
+
label: "tokensPrefixMatched",
|
|
1469
|
+
value: s.tokensPrefixMatched,
|
|
1470
|
+
hint: "Sum of matchLen: leading tokens whose raw was unchanged, so their entities were kept",
|
|
984
1471
|
readOnly: true
|
|
985
1472
|
},
|
|
986
1473
|
{
|
|
987
|
-
label: "
|
|
988
|
-
value: s.
|
|
989
|
-
hint: "Sum of returned tail lengths:
|
|
1474
|
+
label: "tokensReturned",
|
|
1475
|
+
value: s.tokensReturned,
|
|
1476
|
+
hint: "Sum of returned tail lengths: the changed suffix the worker cloned back",
|
|
990
1477
|
readOnly: true
|
|
991
1478
|
},
|
|
992
1479
|
{
|
|
993
|
-
label: "
|
|
994
|
-
value: Math.round(
|
|
995
|
-
hint: "
|
|
1480
|
+
label: "tokenPrefixReuseRatio",
|
|
1481
|
+
value: Math.round(tokenPrefixReuseRatio * 1e3) / 1e3,
|
|
1482
|
+
hint: "matched / (matched + returned). Near 1 means small transfers and high entity reuse \u2014 NOT less lexing",
|
|
1483
|
+
readOnly: true
|
|
1484
|
+
}
|
|
1485
|
+
]
|
|
1486
|
+
},
|
|
1487
|
+
{
|
|
1488
|
+
label: "Parser cost",
|
|
1489
|
+
fields: [
|
|
1490
|
+
{
|
|
1491
|
+
label: "lexerMs",
|
|
1492
|
+
value: Math.round(s.lexerMs * 10) / 10,
|
|
1493
|
+
hint: "Total ms inside marked.lexer() \u2014 the whole source, every append",
|
|
1494
|
+
readOnly: true
|
|
1495
|
+
},
|
|
1496
|
+
{
|
|
1497
|
+
label: "sourceCharsLexed",
|
|
1498
|
+
value: s.sourceCharsLexed,
|
|
1499
|
+
hint: "Characters lexed, summed over appends. Grows ~O(n^2) across a stream",
|
|
996
1500
|
readOnly: true
|
|
997
1501
|
}
|
|
998
1502
|
]
|
|
@@ -1000,13 +1504,22 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1000
1504
|
],
|
|
1001
1505
|
notes: s.workerResponses === 0 && s.appends > 0 ? [
|
|
1002
1506
|
"No worker responses yet: either the worker is unavailable and parsing ran synchronously on the main thread, or the first request is still in flight."
|
|
1003
|
-
] :
|
|
1004
|
-
`Only ${Math.round(
|
|
1507
|
+
] : tokenPrefixReuseRatio > 0 && tokenPrefixReuseRatio < 0.5 ? [
|
|
1508
|
+
`Only ${Math.round(tokenPrefixReuseRatio * 100)}% of tokens matched the prior prefix, so most of the token array is being returned and its entities rebuilt every chunk. Note the LEXER is O(document) per append regardless \u2014 see lexerMs.`
|
|
1005
1509
|
] : s.changedTailChars > 0 && this.rawMarkdown.length > 0 && s.changedTailChars / this.rawMarkdown.length > 0.5 ? [
|
|
1006
|
-
`The last append
|
|
1510
|
+
`The last append changed ${s.changedTailChars} of ${this.rawMarkdown.length} characters. A changed tail that grows with the document means the delta is not a delta, so almost every entity is rebuilt per chunk.`
|
|
1007
1511
|
] : void 0
|
|
1008
1512
|
};
|
|
1009
1513
|
}
|
|
1514
|
+
/** Enable or disable User Timing for subsequent parses. */
|
|
1515
|
+
setUserTiming(enabled) {
|
|
1516
|
+
this._userTiming = enabled;
|
|
1517
|
+
return this;
|
|
1518
|
+
}
|
|
1519
|
+
/** Whether Markdown parse User Timing is enabled. */
|
|
1520
|
+
get userTiming() {
|
|
1521
|
+
return this._userTiming;
|
|
1522
|
+
}
|
|
1010
1523
|
/** Enable or disable native selection for existing and future Markdown text. */
|
|
1011
1524
|
setSelectable(selectable) {
|
|
1012
1525
|
this.selectable = selectable;
|
|
@@ -1021,10 +1534,15 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1021
1534
|
}
|
|
1022
1535
|
/** Append a markdown chunk incrementally. Reuses unchanged prefix entities. */
|
|
1023
1536
|
appendMarkdown(chunk) {
|
|
1537
|
+
this.streamController?.flush();
|
|
1538
|
+
return this.appendMarkdownCore(chunk);
|
|
1539
|
+
}
|
|
1540
|
+
appendMarkdownCore(chunk) {
|
|
1024
1541
|
this.rawMarkdown += chunk;
|
|
1025
1542
|
this.streamStats.appends++;
|
|
1026
1543
|
if (!markdownWorker) {
|
|
1027
|
-
|
|
1544
|
+
this.workerSourceLen = 0;
|
|
1545
|
+
const newTokens = lexMarkdown(this.rawMarkdown, this._userTiming);
|
|
1028
1546
|
this.updateTokens(newTokens);
|
|
1029
1547
|
return this;
|
|
1030
1548
|
}
|
|
@@ -1038,32 +1556,41 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1038
1556
|
/**
|
|
1039
1557
|
* Post one lex request for the accumulated text.
|
|
1040
1558
|
*
|
|
1041
|
-
*
|
|
1042
|
-
* worker
|
|
1043
|
-
*
|
|
1044
|
-
*
|
|
1045
|
-
* O(N²) over a stream
|
|
1046
|
-
*
|
|
1047
|
-
*
|
|
1048
|
-
*
|
|
1559
|
+
* Two shapes. Steady state sends a DELTA — `{ append }` plus the expected total
|
|
1560
|
+
* length — because the worker keeps both this instance's prior token raws and
|
|
1561
|
+
* the document source itself (keyed by `workerInstanceId` + `tokenVersion`).
|
|
1562
|
+
* Re-sending the document each chunk made main->worker transfer O(document) per
|
|
1563
|
+
* chunk, i.e. O(N²) over a stream, and that cost is paid on the main thread:
|
|
1564
|
+
* `postMessage` structured-clones the string synchronously before the worker
|
|
1565
|
+
* ever wakes. `resync` forces the FULL shape instead — the whole text plus the
|
|
1566
|
+
* prior raw list — and is used for the first request for this instance, after
|
|
1567
|
+
* anything the worker did not produce (`setContent`, a sync-fallback parse), and
|
|
1568
|
+
* whenever the worker reports it cannot trust what it holds (`needResync`).
|
|
1049
1569
|
*/
|
|
1050
|
-
dispatchAppend(
|
|
1570
|
+
dispatchAppend(resync = false) {
|
|
1051
1571
|
if (!markdownWorker) return;
|
|
1052
1572
|
this.appendInFlight = true;
|
|
1053
1573
|
const id = workerIdCounter++;
|
|
1054
1574
|
const oldTokensSnapshot = this.tokens;
|
|
1055
1575
|
const baseVersion = this.tokenVersion;
|
|
1056
1576
|
const dispatchedAt = now();
|
|
1577
|
+
const sentLength = this.rawMarkdown.length;
|
|
1578
|
+
const canSendDelta = !resync && this.workerSourceLen > 0 && this.workerSourceLen <= sentLength;
|
|
1057
1579
|
this.pendingWorkerIds.add(id);
|
|
1058
1580
|
workerCallbacks.set(id, {
|
|
1059
|
-
cb: (matchLen, tail) => {
|
|
1581
|
+
cb: (matchLen, tail, local = false, lex) => {
|
|
1060
1582
|
this.pendingWorkerIds.delete(id);
|
|
1061
1583
|
this.streamStats.workerResponses++;
|
|
1062
|
-
this.streamStats.
|
|
1063
|
-
this.streamStats.
|
|
1584
|
+
this.streamStats.tokensPrefixMatched += matchLen;
|
|
1585
|
+
this.streamStats.tokensReturned += tail.length;
|
|
1586
|
+
if (lex) {
|
|
1587
|
+
this.streamStats.lexerMs += lex.lexerMs;
|
|
1588
|
+
this.streamStats.sourceCharsLexed += lex.sourceCharsLexed;
|
|
1589
|
+
}
|
|
1064
1590
|
const elapsed = now() - dispatchedAt;
|
|
1065
1591
|
this.streamStats.workerMs += elapsed;
|
|
1066
1592
|
if (elapsed > this.streamStats.workerMsMax) this.streamStats.workerMsMax = elapsed;
|
|
1593
|
+
this.workerSourceLen = local ? 0 : sentLength;
|
|
1067
1594
|
let prefixChars = 0;
|
|
1068
1595
|
for (let i = 0; i < matchLen; i++) prefixChars += oldTokensSnapshot[i]?.raw.length ?? 0;
|
|
1069
1596
|
this.streamStats.stablePrefixChars = prefixChars;
|
|
@@ -1076,22 +1603,34 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1076
1603
|
this.dispatchAppend();
|
|
1077
1604
|
}
|
|
1078
1605
|
},
|
|
1079
|
-
// The worker can't trust
|
|
1080
|
-
//
|
|
1081
|
-
// the retry's snapshot and version still line up.
|
|
1082
|
-
|
|
1606
|
+
// The worker can't trust what it holds for this request; retry it once with
|
|
1607
|
+
// the full text and raws attached. `this.tokens` is untouched (no
|
|
1608
|
+
// updateTokens ran), so the retry's snapshot and version still line up.
|
|
1609
|
+
onNeedResync: () => {
|
|
1083
1610
|
this.pendingWorkerIds.delete(id);
|
|
1084
1611
|
this.appendInFlight = false;
|
|
1612
|
+
this.workerSourceLen = 0;
|
|
1085
1613
|
this.dispatchAppend(true);
|
|
1086
1614
|
},
|
|
1087
|
-
text: this.rawMarkdown
|
|
1615
|
+
text: this.rawMarkdown,
|
|
1616
|
+
userTiming: this._userTiming
|
|
1088
1617
|
});
|
|
1089
1618
|
markdownWorker.postMessage({
|
|
1090
1619
|
id,
|
|
1091
|
-
text: this.rawMarkdown,
|
|
1092
1620
|
instance: this.workerInstanceId,
|
|
1093
1621
|
baseVersion,
|
|
1094
|
-
|
|
1622
|
+
userTimingName: this._userTiming ? import_core.VECTO_USER_TIMING.markdown.parse : void 0,
|
|
1623
|
+
...canSendDelta ? {
|
|
1624
|
+
append: this.rawMarkdown.slice(this.workerSourceLen),
|
|
1625
|
+
// What the worker's source must total once it applies this append. It
|
|
1626
|
+
// rejects a mismatch with one resync rather than lexing a source that
|
|
1627
|
+
// has diverged from this one — a dropped or duplicated chunk would
|
|
1628
|
+
// otherwise return a matchLen against tokens this instance never had.
|
|
1629
|
+
expectedLength: sentLength
|
|
1630
|
+
} : {
|
|
1631
|
+
text: this.rawMarkdown,
|
|
1632
|
+
oldRaws: oldTokensSnapshot.map((t) => t.raw)
|
|
1633
|
+
}
|
|
1095
1634
|
});
|
|
1096
1635
|
}
|
|
1097
1636
|
updateTokens(newTokens, knownMatchLen) {
|
|
@@ -1166,6 +1705,19 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1166
1705
|
this.onLayoutUpdated();
|
|
1167
1706
|
}
|
|
1168
1707
|
}
|
|
1708
|
+
/**
|
|
1709
|
+
* Render one nested block with a temporary width/margin context while
|
|
1710
|
+
* preserving `renderToken` as the subclass override seam.
|
|
1711
|
+
*/
|
|
1712
|
+
renderTokenWithMetrics(token, metrics) {
|
|
1713
|
+
const previous = this.activeBlockMetrics;
|
|
1714
|
+
this.activeBlockMetrics = metrics;
|
|
1715
|
+
try {
|
|
1716
|
+
return this.renderToken(token);
|
|
1717
|
+
} finally {
|
|
1718
|
+
this.activeBlockMetrics = previous;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1169
1721
|
/**
|
|
1170
1722
|
* Whether {@link renderToken} produces a child entity for this token (vs
|
|
1171
1723
|
* `null`). `updateTokens` maps token indices to child-entity indices, and the
|
|
@@ -1200,6 +1752,13 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1200
1752
|
renderToken(token) {
|
|
1201
1753
|
const t = this.theme;
|
|
1202
1754
|
const bodyFont = `${t.fontSize}px ${t.bodyFont}`;
|
|
1755
|
+
const metrics = this.activeBlockMetrics ?? {
|
|
1756
|
+
marginBefore: 0,
|
|
1757
|
+
marginAfter: 0,
|
|
1758
|
+
indentStart: 0,
|
|
1759
|
+
availableWidth: this.maxWidth
|
|
1760
|
+
};
|
|
1761
|
+
const availableWidth = metrics.availableWidth;
|
|
1203
1762
|
switch (token.type) {
|
|
1204
1763
|
// ── Headings ─────────────────────────────────────────────────────
|
|
1205
1764
|
case "heading": {
|
|
@@ -1212,7 +1771,7 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1212
1771
|
hToken.text,
|
|
1213
1772
|
headingFont,
|
|
1214
1773
|
t.headingColor,
|
|
1215
|
-
|
|
1774
|
+
availableWidth,
|
|
1216
1775
|
t,
|
|
1217
1776
|
this.selectable,
|
|
1218
1777
|
this.onLinkClick
|
|
@@ -1227,7 +1786,7 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1227
1786
|
pToken.text,
|
|
1228
1787
|
bodyFont,
|
|
1229
1788
|
t.textColor,
|
|
1230
|
-
|
|
1789
|
+
availableWidth,
|
|
1231
1790
|
t,
|
|
1232
1791
|
this.selectable,
|
|
1233
1792
|
this.onLinkClick
|
|
@@ -1236,7 +1795,7 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1236
1795
|
const stack = new import_ui.Stack({
|
|
1237
1796
|
direction: "vertical",
|
|
1238
1797
|
gap: 16,
|
|
1239
|
-
maxWidth:
|
|
1798
|
+
maxWidth: availableWidth
|
|
1240
1799
|
});
|
|
1241
1800
|
let currentTokens = [];
|
|
1242
1801
|
const flushText = () => {
|
|
@@ -1247,7 +1806,7 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1247
1806
|
"",
|
|
1248
1807
|
bodyFont,
|
|
1249
1808
|
t.textColor,
|
|
1250
|
-
|
|
1809
|
+
availableWidth,
|
|
1251
1810
|
t,
|
|
1252
1811
|
this.selectable,
|
|
1253
1812
|
this.onLinkClick
|
|
@@ -1260,7 +1819,7 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1260
1819
|
if (child.type === "image") {
|
|
1261
1820
|
flushText();
|
|
1262
1821
|
const imgToken = child;
|
|
1263
|
-
const initialWidth = Math.min(800,
|
|
1822
|
+
const initialWidth = Math.min(800, availableWidth);
|
|
1264
1823
|
const initialHeight = Math.round(initialWidth * 0.6);
|
|
1265
1824
|
const img = new import_ui.Image(imgToken.href, {
|
|
1266
1825
|
width: initialWidth,
|
|
@@ -1271,7 +1830,7 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1271
1830
|
const bmp = img.bitmap;
|
|
1272
1831
|
if (bmp && bmp.naturalWidth && bmp.naturalHeight) {
|
|
1273
1832
|
const aspect = bmp.naturalHeight / bmp.naturalWidth;
|
|
1274
|
-
img.width = Math.min(bmp.naturalWidth,
|
|
1833
|
+
img.width = Math.min(bmp.naturalWidth, availableWidth);
|
|
1275
1834
|
img.height = Math.round(img.width * aspect);
|
|
1276
1835
|
if (this.scene) this.scene.markDirty();
|
|
1277
1836
|
}
|
|
@@ -1293,8 +1852,8 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1293
1852
|
const mathData = renderMathToSVGDataURI(codeToken.text, true);
|
|
1294
1853
|
if (mathData) {
|
|
1295
1854
|
const mathImg = new import_ui.Image(mathData.uri, {
|
|
1296
|
-
width: Math.min(
|
|
1297
|
-
height: mathData.height * Math.min(1,
|
|
1855
|
+
width: Math.min(availableWidth, mathData.width),
|
|
1856
|
+
height: mathData.height * Math.min(1, availableWidth / mathData.width),
|
|
1298
1857
|
alt: codeToken.text
|
|
1299
1858
|
});
|
|
1300
1859
|
const wrapper = new MarkdownContainer();
|
|
@@ -1306,20 +1865,27 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1306
1865
|
return wrapper;
|
|
1307
1866
|
}
|
|
1308
1867
|
}
|
|
1309
|
-
return new CodeBlock(codeToken.text, lang,
|
|
1868
|
+
return new CodeBlock(codeToken.text, lang, availableWidth, t, this.selectable);
|
|
1310
1869
|
}
|
|
1311
1870
|
// ── Blockquotes ──────────────────────────────────────────────────
|
|
1312
1871
|
case "blockquote": {
|
|
1313
1872
|
const bqToken = token;
|
|
1314
1873
|
const innerStack = new import_ui.Stack({ direction: "vertical", gap: 8 });
|
|
1874
|
+
const indentStart = Math.min(16, availableWidth);
|
|
1875
|
+
const childMetrics = {
|
|
1876
|
+
marginBefore: 0,
|
|
1877
|
+
marginAfter: 0,
|
|
1878
|
+
indentStart,
|
|
1879
|
+
availableWidth: Math.max(0, availableWidth - indentStart)
|
|
1880
|
+
};
|
|
1315
1881
|
if (bqToken.tokens) {
|
|
1316
1882
|
for (const inner of bqToken.tokens) {
|
|
1317
|
-
const el = this.
|
|
1883
|
+
const el = this.renderTokenWithMetrics(inner, childMetrics);
|
|
1318
1884
|
if (el) {
|
|
1319
1885
|
const wrapper = new MarkdownContainer();
|
|
1320
|
-
el.x =
|
|
1886
|
+
el.x = childMetrics.indentStart;
|
|
1321
1887
|
wrapper.add(el);
|
|
1322
|
-
wrapper.width = el.width +
|
|
1888
|
+
wrapper.width = el.width + childMetrics.indentStart;
|
|
1323
1889
|
wrapper.height = el.height;
|
|
1324
1890
|
innerStack.add(wrapper);
|
|
1325
1891
|
}
|
|
@@ -1333,7 +1899,7 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1333
1899
|
innerStack.y = 0;
|
|
1334
1900
|
innerStack.x = 0;
|
|
1335
1901
|
container.add(innerStack);
|
|
1336
|
-
container.width =
|
|
1902
|
+
container.width = availableWidth;
|
|
1337
1903
|
container.height = Math.max(border.height, innerStack.height);
|
|
1338
1904
|
return container;
|
|
1339
1905
|
}
|
|
@@ -1365,7 +1931,7 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1365
1931
|
const itemRt = new import_ui.RichText(itemSpans, {
|
|
1366
1932
|
font: bodyFont,
|
|
1367
1933
|
color: t.textColor,
|
|
1368
|
-
maxWidth:
|
|
1934
|
+
maxWidth: Math.max(0, availableWidth - 24),
|
|
1369
1935
|
linkColor: "#38bdf8",
|
|
1370
1936
|
selectable: this.selectable,
|
|
1371
1937
|
onLinkClick: this.onLinkClick
|
|
@@ -1396,7 +1962,7 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1396
1962
|
return new import_ui.Table({
|
|
1397
1963
|
headers,
|
|
1398
1964
|
rows,
|
|
1399
|
-
width:
|
|
1965
|
+
width: availableWidth,
|
|
1400
1966
|
textColor: t.textColor,
|
|
1401
1967
|
headerTextColor: t.headingColor,
|
|
1402
1968
|
font: `${t.fontSize - 2}px ${t.bodyFont}`,
|
|
@@ -1408,7 +1974,7 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1408
1974
|
}
|
|
1409
1975
|
// ── Horizontal rule ──────────────────────────────────────────────
|
|
1410
1976
|
case "hr":
|
|
1411
|
-
return new HorizontalRule(
|
|
1977
|
+
return new HorizontalRule(availableWidth, t.hrColor);
|
|
1412
1978
|
// ── Whitespace ───────────────────────────────────────────────────
|
|
1413
1979
|
case "space":
|
|
1414
1980
|
return null;
|
|
@@ -1426,7 +1992,7 @@ var Markdown = class extends import_ui.UIComponent {
|
|
|
1426
1992
|
return new import_ui.Text(token.text, {
|
|
1427
1993
|
font: bodyFont,
|
|
1428
1994
|
color: t.textColor,
|
|
1429
|
-
maxWidth:
|
|
1995
|
+
maxWidth: availableWidth,
|
|
1430
1996
|
lineHeight: 24,
|
|
1431
1997
|
selectable: this.selectable
|
|
1432
1998
|
});
|