@mdream/js 2.0.3 → 2.2.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.
@@ -1,4 +1,605 @@
1
- import { escapeHtml, isSafeHtmlUrl } from "./utils.mjs";
1
+ import "./const.mjs";
2
+ const selfClosing = { isSelfClosing: true };
3
+ const rawText = { isNonNesting: true };
4
+ const inertRawText = {
5
+ isNonNesting: true,
6
+ excludesTextNodes: true
7
+ };
8
+ const parserTagHandlers = {
9
+ [4]: inertRawText,
10
+ [52]: inertRawText,
11
+ [53]: inertRawText,
12
+ [5]: selfClosing,
13
+ [6]: selfClosing,
14
+ [13]: selfClosing,
15
+ [27]: selfClosing,
16
+ [29]: { excludesTextNodes: true },
17
+ [30]: { excludesTextNodes: true },
18
+ [38]: { excludesTextNodes: true },
19
+ [39]: { excludesTextNodes: true },
20
+ [54]: selfClosing,
21
+ [55]: selfClosing,
22
+ [56]: selfClosing,
23
+ [57]: selfClosing,
24
+ [58]: selfClosing,
25
+ [59]: selfClosing,
26
+ [60]: selfClosing,
27
+ [61]: selfClosing,
28
+ [62]: selfClosing,
29
+ [63]: selfClosing,
30
+ [64]: selfClosing,
31
+ [66]: rawText,
32
+ [73]: inertRawText,
33
+ [78]: { excludesTextNodes: true },
34
+ [84]: inertRawText,
35
+ [112]: inertRawText,
36
+ [108]: inertRawText,
37
+ [85]: inertRawText,
38
+ [86]: rawText,
39
+ [87]: rawText
40
+ };
41
+ function isOpenVoidTag(handler, tagId) {
42
+ return handler?.isSelfClosing === false && !!parserTagHandlers[tagId ?? -1]?.isSelfClosing;
43
+ }
44
+ const HTML_ENTITIES = /* @__PURE__ */ (() => {
45
+ const entities = Object.setPrototypeOf({
46
+ AMP: "&",
47
+ $Dagger: "‡",
48
+ GT: ">",
49
+ LT: "<",
50
+ $OElig: "Œ",
51
+ $Prime: "″",
52
+ QUOT: "\"",
53
+ $Scaron: "Š",
54
+ $Yuml: "Ÿ",
55
+ $alefsym: "ℵ",
56
+ amp: "&",
57
+ $and: "∧",
58
+ $ang: "∠",
59
+ $apos: "'",
60
+ $asymp: "≈",
61
+ $bdquo: "„",
62
+ $bull: "•",
63
+ $cap: "∩",
64
+ $circ: "ˆ",
65
+ $clubs: "♣",
66
+ $cong: "≅",
67
+ copy: "©",
68
+ $crarr: "↵",
69
+ $cup: "∪",
70
+ $dArr: "⇓",
71
+ $dagger: "†",
72
+ $darr: "↓",
73
+ $diams: "♦",
74
+ $empty: "∅",
75
+ $equiv: "≡",
76
+ $euro: "€",
77
+ $exist: "∃",
78
+ $fnof: "ƒ",
79
+ $forall: "∀",
80
+ $frasl: "⁄",
81
+ $ge: "≥",
82
+ gt: ">",
83
+ $hArr: "⇔",
84
+ $harr: "↔",
85
+ $hearts: "♥",
86
+ $hellip: "…",
87
+ $image: "ℑ",
88
+ $infin: "∞",
89
+ $int: "∫",
90
+ $isin: "∈",
91
+ $lArr: "⇐",
92
+ $lang: "⟨",
93
+ $larr: "←",
94
+ $lceil: "⌈",
95
+ $ldquo: "“",
96
+ $le: "≤",
97
+ $lfloor: "⌊",
98
+ $lowast: "∗",
99
+ $loz: "◊",
100
+ $lsaquo: "‹",
101
+ $lsquo: "‘",
102
+ lt: "<",
103
+ $mdash: "—",
104
+ $minus: "−",
105
+ $nabla: "∇",
106
+ $ndash: "–",
107
+ $ne: "≠",
108
+ $ni: "∋",
109
+ $notin: "∉",
110
+ $nsub: "⊄",
111
+ $oelig: "œ",
112
+ $oline: "‾",
113
+ $oplus: "⊕",
114
+ $or: "∨",
115
+ $otimes: "⊗",
116
+ $part: "∂",
117
+ $permil: "‰",
118
+ $perp: "⊥",
119
+ $piv: "ϖ",
120
+ $prime: "′",
121
+ $prod: "∏",
122
+ $prop: "∝",
123
+ quot: "\"",
124
+ $rArr: "⇒",
125
+ $radic: "√",
126
+ $rang: "⟩",
127
+ $rarr: "→",
128
+ $rceil: "⌉",
129
+ $rdquo: "”",
130
+ $real: "ℜ",
131
+ reg: "®",
132
+ $rfloor: "⌋",
133
+ $rsaquo: "›",
134
+ $rsquo: "’",
135
+ $sbquo: "‚",
136
+ $scaron: "š",
137
+ $sdot: "⋅",
138
+ $sigmaf: "ς",
139
+ $sim: "∼",
140
+ $spades: "♠",
141
+ $sub: "⊂",
142
+ $sube: "⊆",
143
+ $sum: "∑",
144
+ $sup: "⊃",
145
+ $supe: "⊇",
146
+ $there4: "∴",
147
+ $thetasym: "ϑ",
148
+ $tilde: "˜",
149
+ $trade: "™",
150
+ $uArr: "⇑",
151
+ $uarr: "↑",
152
+ $upsih: "ϒ",
153
+ $weierp: "℘"
154
+ }, null);
155
+ const latin1Names = "nbsp iexcl cent pound curren yen brvbar sect uml COPY ordf laquo not shy REG macr deg plusmn sup2 sup3 acute micro para middot cedil sup1 ordm raquo frac14 frac12 frac34 iquest Agrave Aacute Acirc Atilde Auml Aring AElig Ccedil Egrave Eacute Ecirc Euml Igrave Iacute Icirc Iuml ETH Ntilde Ograve Oacute Ocirc Otilde Ouml times Oslash Ugrave Uacute Ucirc Uuml Yacute THORN szlig agrave aacute acirc atilde auml aring aelig ccedil egrave eacute ecirc euml igrave iacute icirc iuml eth ntilde ograve oacute ocirc otilde ouml divide oslash ugrave uacute ucirc uuml yacute thorn yuml".split(" ");
156
+ for (const [index, name] of latin1Names.entries()) if (name) entities[name] = String.fromCharCode(160 + index);
157
+ const greekNames = "alpha beta gamma delta epsilon zeta eta theta iota kappa lambda mu nu xi omicron pi rho sigma tau upsilon phi chi psi omega".split(" ");
158
+ for (const [index, name] of greekNames.entries()) {
159
+ if (!name) continue;
160
+ entities[`$${name}`] = String.fromCharCode(945 + index);
161
+ entities[`$${name[0].toUpperCase()}${name.slice(1)}`] = String.fromCharCode(913 + index);
162
+ }
163
+ return entities;
164
+ })();
165
+ function isBlockChildOfOpenVoid(node) {
166
+ const tagId = node.tagId;
167
+ if (tagId === void 0 || tagId < 0 || node.tagHandler?.isInline) return false;
168
+ const spanExempt = tagId === 35 || tagId === 36 || tagId === 25;
169
+ for (let parent = node.parent; parent; parent = parent.parent) {
170
+ if (!parent.tagHandler?.collapsesInnerWhiteSpace) continue;
171
+ const parentId = parent.tagId;
172
+ if (parentId !== void 0 && parserTagHandlers[parentId]?.isSelfClosing) continue;
173
+ if (parentId === 37 && spanExempt) continue;
174
+ return false;
175
+ }
176
+ return true;
177
+ }
178
+ function lowerAscii(code) {
179
+ return code >= 65 && code <= 90 ? code + 32 : code;
180
+ }
181
+ function noteBufferRewrite(state) {
182
+ if (state.markerLine !== void 0) state.markerLine = void 0;
183
+ }
184
+ function isInsideHeading(depthMap) {
185
+ for (let tagId = 7; tagId <= 12; tagId++) if (depthMap[tagId]) return true;
186
+ return false;
187
+ }
188
+ function isInsideTableCell(state) {
189
+ const depthMap = state.depthMap;
190
+ return depthMap[32] > 0 || depthMap[31] > 0;
191
+ }
192
+ function schemeMatches(href, start, end, scheme) {
193
+ let matched = 0;
194
+ for (let index = start; index < end; index++) {
195
+ const code = href.charCodeAt(index);
196
+ if (code === 9 || code === 10 || code === 13) continue;
197
+ if (lowerAscii(code) !== scheme.charCodeAt(matched)) return false;
198
+ if (++matched === scheme.length) return true;
199
+ }
200
+ return false;
201
+ }
202
+ function isDataUrl(src) {
203
+ let start = 0;
204
+ while (start < src.length && src.charCodeAt(start) <= 32) start++;
205
+ let end = src.length;
206
+ while (end > start && src.charCodeAt(end - 1) <= 32) end--;
207
+ return schemeMatches(src, start, end, "data:");
208
+ }
209
+ function isEmptyLinkHref(href) {
210
+ let start = 0;
211
+ while (start < href.length && href.charCodeAt(start) <= 32) start++;
212
+ let end = href.length;
213
+ while (end > start && href.charCodeAt(end - 1) <= 32) end--;
214
+ switch (lowerAscii(href.charCodeAt(start))) {
215
+ case 35: return end - start === 1;
216
+ case 106: return schemeMatches(href, start, end, "javascript:");
217
+ case 100: return schemeMatches(href, start, end, "data:");
218
+ case 118: return schemeMatches(href, start, end, "vbscript:");
219
+ default: return false;
220
+ }
221
+ }
222
+ function isSafeHtmlUrl(href, image = false) {
223
+ let start = 0;
224
+ while (start < href.length && href.charCodeAt(start) <= 32) start++;
225
+ let end = href.length;
226
+ while (end > start && href.charCodeAt(end - 1) <= 32) end--;
227
+ if (start === end) return false;
228
+ for (let index = start; index < end; index++) {
229
+ const code = href.charCodeAt(index);
230
+ if (code === 9 || code === 10 || code === 13) continue;
231
+ if (code === 58) switch (lowerAscii(href.charCodeAt(start))) {
232
+ case 104: return schemeMatches(href, start, end, "http:") || schemeMatches(href, start, end, "https:");
233
+ case 109: return !image && schemeMatches(href, start, end, "mailto:");
234
+ case 116: return !image && schemeMatches(href, start, end, "tel:");
235
+ case 102: return !image && schemeMatches(href, start, end, "ftp:");
236
+ default: return false;
237
+ }
238
+ if (code === 47 || code === 63 || code === 35) return true;
239
+ const lower = lowerAscii(code);
240
+ if (!(lower >= 97 && lower <= 122 || code >= 48 && code <= 57 || code === 43 || code === 45 || code === 46)) return true;
241
+ }
242
+ return true;
243
+ }
244
+ function escapeHtml(value, attribute = false, protectMarkdown = false) {
245
+ let escaped = "";
246
+ let copiedUntil = 0;
247
+ for (let index = 0; index < value.length; index++) {
248
+ const code = value.charCodeAt(index);
249
+ let replacement;
250
+ if (code === 38) replacement = "&amp;";
251
+ else if (code === 60) replacement = "&lt;";
252
+ else if (code === 62) replacement = "&gt;";
253
+ else if (attribute && code === 34) replacement = "&quot;";
254
+ else if (protectMarkdown && code === 91) replacement = "&#91;";
255
+ else if (protectMarkdown && code === 93) replacement = "&#93;";
256
+ if (replacement !== void 0) {
257
+ escaped += value.slice(copiedUntil, index) + replacement;
258
+ copiedUntil = index + 1;
259
+ }
260
+ }
261
+ return copiedUntil === 0 ? value : escaped + value.slice(copiedUntil);
262
+ }
263
+ const C1_REPLACEMENTS = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ";
264
+ function isAsciiAlphaNumeric(code) {
265
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122;
266
+ }
267
+ function isHtmlAsciiWhitespace(code) {
268
+ return code === 32 || code === 9 || code === 10 || code === 12 || code === 13;
269
+ }
270
+ const LANGUAGE_PREFIX = [
271
+ 108,
272
+ 97,
273
+ 110,
274
+ 103,
275
+ 117,
276
+ 97,
277
+ 103,
278
+ 101,
279
+ 45
280
+ ];
281
+ function hasLanguagePrefix(value, start) {
282
+ for (let offset = 0; offset < 9; offset++) if (value.charCodeAt(start + offset) !== LANGUAGE_PREFIX[offset]) return false;
283
+ return true;
284
+ }
285
+ function isUnsafeFenceInfoCode(code) {
286
+ if (code < 32 || code === 127) return true;
287
+ return code === 34 || code === 39 || code === 38 || code === 60 || code === 62 || code === 96 || code === 126;
288
+ }
289
+ function getLanguageFromClass(className) {
290
+ if (!className) return "";
291
+ const length = className.length;
292
+ let index = 0;
293
+ while (index < length) {
294
+ if (isHtmlAsciiWhitespace(className.charCodeAt(index))) {
295
+ index++;
296
+ continue;
297
+ }
298
+ const tokenStart = index;
299
+ do
300
+ index++;
301
+ while (index < length && !isHtmlAsciiWhitespace(className.charCodeAt(index)));
302
+ const tokenEnd = index;
303
+ const languageStart = tokenStart + 9;
304
+ if (languageStart >= tokenEnd || !hasLanguagePrefix(className, tokenStart)) continue;
305
+ let valid = true;
306
+ for (let cursor = languageStart; cursor < tokenEnd; cursor++) if (isUnsafeFenceInfoCode(className.charCodeAt(cursor))) {
307
+ valid = false;
308
+ break;
309
+ }
310
+ if (valid) return className.slice(languageStart, tokenEnd);
311
+ }
312
+ return "";
313
+ }
314
+ const DATA_LANGUAGE_RE = /^[\t\n\f\r ]*([^\0-\x20"&'<>`~\x7F]+)[\t\n\f\r ]*$/;
315
+ function getLanguageFromDataAttribute(value) {
316
+ return value ? DATA_LANGUAGE_RE.exec(value)?.[1] ?? "" : "";
317
+ }
318
+ function getLanguageFromAttributes(attributes) {
319
+ return getLanguageFromClass(attributes?.class) || getLanguageFromDataAttribute(attributes?.["data-language"]) || getLanguageFromDataAttribute(attributes?.["data-lang"]);
320
+ }
321
+ function hasNonWhitespace(value) {
322
+ for (let i = 0; i < value.length; i++) {
323
+ const c = value.charCodeAt(i);
324
+ if (c !== 32 && c !== 9 && c !== 10 && c !== 12 && c !== 13) return true;
325
+ }
326
+ return false;
327
+ }
328
+ function suppressesFormattingInPre(tagId) {
329
+ return tagId === 26 || tagId === 46 || tagId === 110 || tagId === 111 || tagId === 106 || tagId >= 14 && tagId <= 21 || tagId >= 79 && tagId <= 83 || tagId >= 89 && tagId <= 94;
330
+ }
331
+ function parseUnsignedInteger(raw) {
332
+ if (raw === void 0 || !/^[\t\n\f\r ]*\+?\d+[\t\n\f\r ]*$/.test(raw)) return void 0;
333
+ const value = Number(raw);
334
+ return value <= 4294967295 ? value : void 0;
335
+ }
336
+ function outputLeadLength(value) {
337
+ let start = 0;
338
+ while (start < value.length) {
339
+ const code = value.charCodeAt(start);
340
+ if (code === 32 || code >= 9 && code <= 13) {
341
+ start++;
342
+ continue;
343
+ }
344
+ if (code < 133 || !(code === 133 || code === 160 || code === 5760 || code >= 8192 && code <= 8202 || code === 8232 || code === 8233 || code === 8239 || code === 8287 || code === 12288)) break;
345
+ start++;
346
+ }
347
+ return start;
348
+ }
349
+ function trimOutputStart(value) {
350
+ const start = outputLeadLength(value);
351
+ return start === 0 ? value : value.slice(start);
352
+ }
353
+ function leadingWhitespaceLength(value) {
354
+ let start = 0;
355
+ while (start < value.length) {
356
+ const code = value.charCodeAt(start);
357
+ if (code !== 32 && code !== 10 && code !== 9 && code !== 13 && code !== 12) break;
358
+ start++;
359
+ }
360
+ return start;
361
+ }
362
+ function dropSourceLead(node) {
363
+ const start = Math.min(node.sourceLead, leadingWhitespaceLength(node.value));
364
+ node.sourceLead = 0;
365
+ if (start !== 0) node.value = node.value.slice(start);
366
+ }
367
+ function trimTextAtLineStart(node, buffer) {
368
+ if (!node.sourceLead) return;
369
+ const last = lastOutputChar(buffer);
370
+ if (last === -1 || last === 10) dropSourceLead(node);
371
+ }
372
+ function needsSpacing(lastChar, firstChar) {
373
+ if (!lastChar || " \n ".includes(lastChar) || " \n ".includes(firstChar)) return false;
374
+ if (lastChar === "|" && firstChar === "<") return true;
375
+ return !"[(>*_`".includes(lastChar) && !"])<.,!?:;*_`".includes(firstChar);
376
+ }
377
+ function lastOutputChar(buffer, end = buffer.length) {
378
+ for (let index = end - 1; index >= 0; index--) {
379
+ const fragment = buffer[index];
380
+ if (fragment.length > 0) return fragment.charCodeAt(fragment.length - 1);
381
+ }
382
+ return -1;
383
+ }
384
+ function endsAtHardBreak(buffer) {
385
+ let fragment = buffer.length - 1;
386
+ let index = fragment >= 0 ? buffer[fragment].length : 0;
387
+ let sawNewline = false;
388
+ let breakSpaces = 0;
389
+ for (;;) {
390
+ while (index === 0) {
391
+ if (--fragment < 0) return false;
392
+ index = buffer[fragment].length;
393
+ }
394
+ const code = buffer[fragment].charCodeAt(--index);
395
+ if (!sawNewline) {
396
+ if (code === 10) sawNewline = true;
397
+ else if (code !== 32) return false;
398
+ } else if (code === 32) {
399
+ if (++breakSpaces === 2) return true;
400
+ } else return false;
401
+ }
402
+ }
403
+ function blockOpenPrefix(state, prefix, end = state.buffer.length) {
404
+ const buffer = state.buffer;
405
+ switch (lastOutputChar(buffer, end)) {
406
+ case -1: return;
407
+ case 32: {
408
+ let fragment = end - 1;
409
+ let index = buffer[fragment].length;
410
+ for (;;) {
411
+ if (index === 0) {
412
+ if (--fragment < 0) return void 0;
413
+ index = buffer[fragment].length;
414
+ continue;
415
+ }
416
+ const code = buffer[fragment].charCodeAt(--index);
417
+ if (code !== 32) return code === 10 || listMarkerLineStart(buffer, fragment, index, pendingMarkerIndent(state)) ? void 0 : `\n\n${prefix ?? ""}`;
418
+ }
419
+ }
420
+ case 10: return prefix || void 0;
421
+ default: return `\n\n${prefix ?? ""}`;
422
+ }
423
+ }
424
+ function figcaptionOwnsBlockSpacing(node, plainText) {
425
+ let parent = node.parent;
426
+ while (parent) {
427
+ if (parent.tagId === 32 || parent.tagId === 31) return false;
428
+ if (!plainText && parent.tagId !== 37 && parent.tagHandler?.collapsesInnerWhiteSpace) return false;
429
+ parent = parent.parent;
430
+ }
431
+ return true;
432
+ }
433
+ function pendingMarkerIndent(state) {
434
+ const widths = state.listIndentWidths;
435
+ return widths?.length ? state.listIndent.length - widths[widths.length - 1] : 3;
436
+ }
437
+ function listMarkerLineStart(buffer, fragmentIndex, markerIndex, maxIndent = 3) {
438
+ const marker = buffer[fragmentIndex].charCodeAt(markerIndex);
439
+ const ordered = marker === 46 || marker === 41;
440
+ if (!ordered && marker !== 45 && marker !== 42 && marker !== 43) return false;
441
+ let digits = 0;
442
+ let spaces = 0;
443
+ let fragment = fragmentIndex;
444
+ let cursor = markerIndex;
445
+ for (;;) {
446
+ if (cursor === 0) {
447
+ if (--fragment < 0) return !ordered || digits > 0;
448
+ cursor = buffer[fragment].length;
449
+ continue;
450
+ }
451
+ const code = buffer[fragment].charCodeAt(--cursor);
452
+ if (ordered && spaces === 0 && code >= 48 && code <= 57) {
453
+ if (++digits > 9) return false;
454
+ continue;
455
+ }
456
+ if (ordered && digits === 0) return false;
457
+ if (code === 32) {
458
+ if (!(cursor > 0 ? buffer[fragment].charCodeAt(cursor - 1) === 13 : fragment > 0 && buffer[fragment - 1].endsWith("\r")) && ++spaces > maxIndent) return false;
459
+ continue;
460
+ }
461
+ return code === 10 || code === 13;
462
+ }
463
+ }
464
+ const MAX_ORDERED_START = 999999999;
465
+ function orderedItemNumber(list, index) {
466
+ const raw = list?.attributes?.start;
467
+ if (raw === void 0) return index + 1;
468
+ const start = parseUnsignedInteger(raw);
469
+ if (start === void 0 || start > MAX_ORDERED_START) return Math.min(1 + index, MAX_ORDERED_START);
470
+ return Math.min(start + index, MAX_ORDERED_START);
471
+ }
472
+ function numericReplacement(codePoint) {
473
+ if (codePoint === 0 || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343) return "�";
474
+ if (codePoint >= 128 && codePoint <= 159) return C1_REPLACEMENTS[codePoint - 128];
475
+ return String.fromCodePoint(codePoint);
476
+ }
477
+ function isCharacterReferenceTail(text, start) {
478
+ let index = start;
479
+ if (text.charCodeAt(index) === 35) {
480
+ index++;
481
+ const hex = text.charCodeAt(index) === 120 || text.charCodeAt(index) === 88;
482
+ if (hex) index++;
483
+ const digitStart = index;
484
+ while (index < text.length) {
485
+ const code = text.charCodeAt(index);
486
+ if (!(code >= 48 && code <= 57) && !(hex && (code >= 65 && code <= 70 || code >= 97 && code <= 102))) break;
487
+ index++;
488
+ }
489
+ return index > digitStart && text.charCodeAt(index) === 59;
490
+ }
491
+ const nameStart = index;
492
+ while (index < text.length && isAsciiAlphaNumeric(text.charCodeAt(index))) index++;
493
+ return index > nameStart && text.charCodeAt(index) === 59;
494
+ }
495
+ function decodedReference(replacement, text, next, protectDecodedEntityReferences) {
496
+ return replacement === "&" && protectDecodedEntityReferences && isCharacterReferenceTail(text, next) ? "\\&" : replacement;
497
+ }
498
+ function decodeHTMLEntities(text, inAttribute = false, protectDecodedEntityReferences = false) {
499
+ let result = "";
500
+ let i = 0;
501
+ const len = text.length;
502
+ while (i < len) {
503
+ if (text.charCodeAt(i) !== 38) {
504
+ const plainStart = i;
505
+ while (i < len && text.charCodeAt(i) !== 38) i++;
506
+ result += text.slice(plainStart, i);
507
+ continue;
508
+ }
509
+ if (i + 2 < len && text.charCodeAt(i + 1) === 35) {
510
+ let end = i + 2;
511
+ const isHex = text.charCodeAt(end) === 120 || text.charCodeAt(end) === 88;
512
+ if (isHex) end++;
513
+ const digitStart = end;
514
+ let codePoint = 0;
515
+ while (end < len) {
516
+ const code = text.charCodeAt(end);
517
+ let digit = -1;
518
+ if (code >= 48 && code <= 57) digit = code - 48;
519
+ else if (isHex && code >= 65 && code <= 70) digit = code - 55;
520
+ else if (isHex && code >= 97 && code <= 102) digit = code - 87;
521
+ if (digit < 0) break;
522
+ codePoint = codePoint * (isHex ? 16 : 10) + digit;
523
+ end++;
524
+ }
525
+ if (end > digitStart) {
526
+ result += decodedReference(numericReplacement(codePoint), text, text.charCodeAt(end) === 59 ? end + 1 : end, protectDecodedEntityReferences);
527
+ if (text.charCodeAt(end) === 59) end++;
528
+ i = end;
529
+ continue;
530
+ }
531
+ }
532
+ const nameStart = i + 1;
533
+ let nameEnd = nameStart;
534
+ const scanEnd = Math.min(len, nameStart + 8);
535
+ while (nameEnd < scanEnd && isAsciiAlphaNumeric(text.charCodeAt(nameEnd))) nameEnd++;
536
+ if (nameEnd > nameStart && text.charCodeAt(nameEnd) === 59) {
537
+ const name = text.slice(nameStart, nameEnd);
538
+ const direct = HTML_ENTITIES[name];
539
+ const replacement = typeof direct === "string" ? direct : HTML_ENTITIES[`$${name}`];
540
+ if (replacement !== void 0) {
541
+ result += decodedReference(replacement, text, nameEnd + 1, protectDecodedEntityReferences);
542
+ i = nameEnd + 1;
543
+ continue;
544
+ }
545
+ }
546
+ let legacyEnd = Math.min(nameEnd, nameStart + 6);
547
+ let decodedLegacy = false;
548
+ while (legacyEnd > nameStart) {
549
+ const name = text.slice(nameStart, legacyEnd);
550
+ const replacement = HTML_ENTITIES[name];
551
+ if (typeof replacement === "string") {
552
+ const next = text.charCodeAt(legacyEnd);
553
+ if (replacement !== void 0 && !(inAttribute && (next === 61 || isAsciiAlphaNumeric(next)))) {
554
+ result += decodedReference(replacement, text, legacyEnd, protectDecodedEntityReferences);
555
+ i = legacyEnd;
556
+ decodedLegacy = true;
557
+ }
558
+ break;
559
+ }
560
+ legacyEnd--;
561
+ }
562
+ if (decodedLegacy) continue;
563
+ result += "&";
564
+ i++;
565
+ }
566
+ return result;
567
+ }
568
+ function isInlineNode(node) {
569
+ const isInline = node.tagHandler?.isInline;
570
+ return isInline === void 0 ? node.tagId === -1 : isInline;
571
+ }
572
+ function traverseUpToFirstBlockNode(node) {
573
+ let firstBlockParent = node;
574
+ const parentsToIncrement = [firstBlockParent];
575
+ while (isInlineNode(firstBlockParent)) {
576
+ if (!firstBlockParent.parent) break;
577
+ firstBlockParent = firstBlockParent.parent;
578
+ parentsToIncrement.push(firstBlockParent);
579
+ }
580
+ return parentsToIncrement;
581
+ }
582
+ function markRenderedChildContent(node) {
583
+ let parent = node.parent;
584
+ let anchorInScope = false;
585
+ while (parent) {
586
+ parent.childTextNodeIndex = (parent.childTextNodeIndex || 0) + 1;
587
+ if (parent.tagId === 26) anchorInScope = true;
588
+ if (!isInlineNode(parent)) break;
589
+ parent = parent.parent;
590
+ }
591
+ if (anchorInScope) return;
592
+ let anchorFound = false;
593
+ while (parent?.parent) {
594
+ parent = parent.parent;
595
+ if (!anchorFound) {
596
+ if (parent.tagId !== 26) continue;
597
+ anchorFound = true;
598
+ }
599
+ parent.childTextNodeIndex = (parent.childTextNodeIndex || 0) + 1;
600
+ if (!isInlineNode(parent)) return;
601
+ }
602
+ }
2
603
  const URL_SCHEME_RE = /^[A-Z][\dA-Z+.-]*:/i;
3
604
  const SLASH_CHAR = 47;
4
605
  function pathEnd(value, from) {
@@ -59,7 +660,15 @@ function resolveAgainstBase(origin, url) {
59
660
  if (path.charCodeAt(0) === SLASH_CHAR) return `${baseRoot}${dot ? mergeDotSegments("/", path.slice(1)) : path}${suffix}`;
60
661
  return `${baseRoot}${dot ? mergeDotSegments(baseDirectory, path) : baseDirectory + path}${suffix}`;
61
662
  }
663
+ function trimUrl(url) {
664
+ let start = 0;
665
+ let end = url.length;
666
+ while (start < end && url.charCodeAt(start) <= 32) start++;
667
+ while (end > start && url.charCodeAt(end - 1) <= 32) end--;
668
+ return start === 0 && end === url.length ? url : url.slice(start, end);
669
+ }
62
670
  function resolveUrl(url, origin, clean) {
671
+ url = trimUrl(url);
63
672
  if (!url || url[0] === "#") return url;
64
673
  const isSlash = url.charCodeAt(0) === SLASH_CHAR;
65
674
  let resolved = url;
@@ -79,4 +688,4 @@ function safeAnchorOutput(node, options, entering, protectMarkdown = false) {
79
688
  if (!entering) return "</a>";
80
689
  return `<a href="${escapeHtml(resolved, true, protectMarkdown)}"${node.attributes?.title === void 0 ? "" : ` title="${escapeHtml(node.attributes.title, true, protectMarkdown)}"`}>`;
81
690
  }
82
- export { resolveUrl, safeAnchorOutput };
691
+ export { blockOpenPrefix, decodeHTMLEntities, dropSourceLead, endsAtHardBreak, escapeHtml, figcaptionOwnsBlockSpacing, getLanguageFromAttributes, hasNonWhitespace, isBlockChildOfOpenVoid, isCharacterReferenceTail, isDataUrl, isEmptyLinkHref, isInsideHeading, isInsideTableCell, isOpenVoidTag, isSafeHtmlUrl, lastOutputChar, leadingWhitespaceLength, listMarkerLineStart, markRenderedChildContent, needsSpacing, noteBufferRewrite, orderedItemNumber, outputLeadLength, parseUnsignedInteger, parserTagHandlers, pendingMarkerIndent, resolveUrl, safeAnchorOutput, suppressesFormattingInPre, traverseUpToFirstBlockNode, trimOutputStart, trimTextAtLineStart, trimUrl };
package/dist/clean.mjs CHANGED
@@ -1,2 +1 @@
1
- import { clean, slugify, stripHeadingFormatting } from "./_chunks/clean.mjs";
2
- export { clean, slugify, stripHeadingFormatting };
1
+ export { clean, slugify, stripHeadingFormatting } from "./_chunks/clean.mjs";
package/dist/html.mjs CHANGED
@@ -1,2 +1 @@
1
- import { htmlToSafeHtml, streamHtmlToSafeHtml } from "./_chunks/html.mjs";
2
- export { htmlToSafeHtml, streamHtmlToSafeHtml };
1
+ export { htmlToSafeHtml, streamHtmlToSafeHtml } from "./_chunks/html.mjs";
@@ -32,4 +32,5 @@ export declare function negotiateContent(acceptHeader?: string, secFetchDest?: s
32
32
  * {@link negotiateContent}; treats `'not-acceptable'` the same as `'html'`
33
33
  * (callers that want 406 semantics should use `negotiateContent` directly).
34
34
  */
35
- export declare function shouldServeMarkdown(acceptHeader?: string, secFetchDest?: string): boolean;
35
+ export declare function shouldServeMarkdown(acceptHeader?: string, secFetchDest?: string): boolean;
36
+ export {};