@mdream/js 2.0.3 → 2.1.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/dist/_chunks/clean.mjs +1 -2
- package/dist/_chunks/extraction.d.mts +2 -1
- package/dist/_chunks/html.mjs +18 -8
- package/dist/_chunks/markdown-processor.mjs +746 -144
- package/dist/_chunks/output-runner.mjs +2 -1
- package/dist/_chunks/parse.mjs +148 -27
- package/dist/_chunks/src.mjs +25 -6
- package/dist/_chunks/tag-overrides.mjs +12 -2
- package/dist/_chunks/tailwind.mjs +66 -32
- package/dist/_chunks/text.mjs +10 -9
- package/dist/_chunks/types.d.mts +34 -0
- package/dist/_chunks/url.mjs +670 -2
- package/dist/clean.mjs +1 -2
- package/dist/html.mjs +1 -2
- package/dist/negotiate.d.mts +2 -1
- package/dist/negotiate.mjs +43 -29
- package/dist/parse.d.mts +16 -1
- package/dist/parse.mjs +1 -2
- package/dist/preset/minimal.d.mts +2 -1
- package/dist/preset/minimal.mjs +1 -2
- package/dist/splitter.mjs +3 -2
- package/dist/text.mjs +1 -2
- package/package.json +2 -2
- package/dist/_chunks/utils.mjs +0 -659
package/dist/_chunks/url.mjs
CHANGED
|
@@ -1,4 +1,672 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./const.mjs";
|
|
2
|
+
const HTML_ENTITIES = {
|
|
3
|
+
AElig: "Æ",
|
|
4
|
+
AMP: "&",
|
|
5
|
+
Aacute: "Á",
|
|
6
|
+
Acirc: "Â",
|
|
7
|
+
Agrave: "À",
|
|
8
|
+
$Alpha: "Α",
|
|
9
|
+
Aring: "Å",
|
|
10
|
+
Atilde: "Ã",
|
|
11
|
+
Auml: "Ä",
|
|
12
|
+
$Beta: "Β",
|
|
13
|
+
COPY: "©",
|
|
14
|
+
Ccedil: "Ç",
|
|
15
|
+
$Chi: "Χ",
|
|
16
|
+
$Dagger: "‡",
|
|
17
|
+
$Delta: "Δ",
|
|
18
|
+
ETH: "Ð",
|
|
19
|
+
Eacute: "É",
|
|
20
|
+
Ecirc: "Ê",
|
|
21
|
+
Egrave: "È",
|
|
22
|
+
$Epsilon: "Ε",
|
|
23
|
+
$Eta: "Η",
|
|
24
|
+
Euml: "Ë",
|
|
25
|
+
GT: ">",
|
|
26
|
+
$Gamma: "Γ",
|
|
27
|
+
Iacute: "Í",
|
|
28
|
+
Icirc: "Î",
|
|
29
|
+
Igrave: "Ì",
|
|
30
|
+
$Iota: "Ι",
|
|
31
|
+
Iuml: "Ï",
|
|
32
|
+
$Kappa: "Κ",
|
|
33
|
+
LT: "<",
|
|
34
|
+
$Lambda: "Λ",
|
|
35
|
+
$Mu: "Μ",
|
|
36
|
+
Ntilde: "Ñ",
|
|
37
|
+
$Nu: "Ν",
|
|
38
|
+
$OElig: "Œ",
|
|
39
|
+
Oacute: "Ó",
|
|
40
|
+
Ocirc: "Ô",
|
|
41
|
+
Ograve: "Ò",
|
|
42
|
+
$Omega: "Ω",
|
|
43
|
+
$Omicron: "Ο",
|
|
44
|
+
Oslash: "Ø",
|
|
45
|
+
Otilde: "Õ",
|
|
46
|
+
Ouml: "Ö",
|
|
47
|
+
$Phi: "Φ",
|
|
48
|
+
$Pi: "Π",
|
|
49
|
+
$Prime: "″",
|
|
50
|
+
$Psi: "Ψ",
|
|
51
|
+
QUOT: "\"",
|
|
52
|
+
REG: "®",
|
|
53
|
+
$Rho: "Ρ",
|
|
54
|
+
$Scaron: "Š",
|
|
55
|
+
$Sigma: "Σ",
|
|
56
|
+
THORN: "Þ",
|
|
57
|
+
$Tau: "Τ",
|
|
58
|
+
$Theta: "Θ",
|
|
59
|
+
Uacute: "Ú",
|
|
60
|
+
Ucirc: "Û",
|
|
61
|
+
Ugrave: "Ù",
|
|
62
|
+
$Upsilon: "Υ",
|
|
63
|
+
Uuml: "Ü",
|
|
64
|
+
$Xi: "Ξ",
|
|
65
|
+
Yacute: "Ý",
|
|
66
|
+
$Yuml: "Ÿ",
|
|
67
|
+
$Zeta: "Ζ",
|
|
68
|
+
aacute: "á",
|
|
69
|
+
acirc: "â",
|
|
70
|
+
acute: "´",
|
|
71
|
+
aelig: "æ",
|
|
72
|
+
agrave: "à",
|
|
73
|
+
$alefsym: "ℵ",
|
|
74
|
+
$alpha: "α",
|
|
75
|
+
amp: "&",
|
|
76
|
+
$and: "∧",
|
|
77
|
+
$ang: "∠",
|
|
78
|
+
$apos: "'",
|
|
79
|
+
aring: "å",
|
|
80
|
+
$asymp: "≈",
|
|
81
|
+
atilde: "ã",
|
|
82
|
+
auml: "ä",
|
|
83
|
+
$bdquo: "„",
|
|
84
|
+
$beta: "β",
|
|
85
|
+
brvbar: "¦",
|
|
86
|
+
$bull: "•",
|
|
87
|
+
$cap: "∩",
|
|
88
|
+
ccedil: "ç",
|
|
89
|
+
cedil: "¸",
|
|
90
|
+
cent: "¢",
|
|
91
|
+
$chi: "χ",
|
|
92
|
+
$circ: "ˆ",
|
|
93
|
+
$clubs: "♣",
|
|
94
|
+
$cong: "≅",
|
|
95
|
+
copy: "©",
|
|
96
|
+
$crarr: "↵",
|
|
97
|
+
$cup: "∪",
|
|
98
|
+
curren: "¤",
|
|
99
|
+
$dArr: "⇓",
|
|
100
|
+
$dagger: "†",
|
|
101
|
+
$darr: "↓",
|
|
102
|
+
deg: "°",
|
|
103
|
+
$delta: "δ",
|
|
104
|
+
$diams: "♦",
|
|
105
|
+
divide: "÷",
|
|
106
|
+
eacute: "é",
|
|
107
|
+
ecirc: "ê",
|
|
108
|
+
egrave: "è",
|
|
109
|
+
$empty: "∅",
|
|
110
|
+
$epsilon: "ε",
|
|
111
|
+
$equiv: "≡",
|
|
112
|
+
$eta: "η",
|
|
113
|
+
eth: "ð",
|
|
114
|
+
euml: "ë",
|
|
115
|
+
$euro: "€",
|
|
116
|
+
$exist: "∃",
|
|
117
|
+
$fnof: "ƒ",
|
|
118
|
+
$forall: "∀",
|
|
119
|
+
frac12: "½",
|
|
120
|
+
frac14: "¼",
|
|
121
|
+
frac34: "¾",
|
|
122
|
+
$frasl: "⁄",
|
|
123
|
+
$gamma: "γ",
|
|
124
|
+
$ge: "≥",
|
|
125
|
+
gt: ">",
|
|
126
|
+
$hArr: "⇔",
|
|
127
|
+
$harr: "↔",
|
|
128
|
+
$hearts: "♥",
|
|
129
|
+
$hellip: "…",
|
|
130
|
+
iacute: "í",
|
|
131
|
+
icirc: "î",
|
|
132
|
+
iexcl: "¡",
|
|
133
|
+
igrave: "ì",
|
|
134
|
+
$image: "ℑ",
|
|
135
|
+
$infin: "∞",
|
|
136
|
+
$int: "∫",
|
|
137
|
+
$iota: "ι",
|
|
138
|
+
iquest: "¿",
|
|
139
|
+
$isin: "∈",
|
|
140
|
+
iuml: "ï",
|
|
141
|
+
$kappa: "κ",
|
|
142
|
+
$lArr: "⇐",
|
|
143
|
+
$lambda: "λ",
|
|
144
|
+
$lang: "⟨",
|
|
145
|
+
laquo: "«",
|
|
146
|
+
$larr: "←",
|
|
147
|
+
$lceil: "⌈",
|
|
148
|
+
$ldquo: "“",
|
|
149
|
+
$le: "≤",
|
|
150
|
+
$lfloor: "⌊",
|
|
151
|
+
$lowast: "∗",
|
|
152
|
+
$loz: "◊",
|
|
153
|
+
$lsaquo: "‹",
|
|
154
|
+
$lsquo: "‘",
|
|
155
|
+
lt: "<",
|
|
156
|
+
macr: "¯",
|
|
157
|
+
$mdash: "—",
|
|
158
|
+
micro: "µ",
|
|
159
|
+
middot: "·",
|
|
160
|
+
$minus: "−",
|
|
161
|
+
$mu: "μ",
|
|
162
|
+
$nabla: "∇",
|
|
163
|
+
nbsp: "\xA0",
|
|
164
|
+
$ndash: "–",
|
|
165
|
+
$ne: "≠",
|
|
166
|
+
$ni: "∋",
|
|
167
|
+
not: "¬",
|
|
168
|
+
$notin: "∉",
|
|
169
|
+
$nsub: "⊄",
|
|
170
|
+
ntilde: "ñ",
|
|
171
|
+
$nu: "ν",
|
|
172
|
+
oacute: "ó",
|
|
173
|
+
ocirc: "ô",
|
|
174
|
+
$oelig: "œ",
|
|
175
|
+
ograve: "ò",
|
|
176
|
+
$oline: "‾",
|
|
177
|
+
$omega: "ω",
|
|
178
|
+
$omicron: "ο",
|
|
179
|
+
$oplus: "⊕",
|
|
180
|
+
$or: "∨",
|
|
181
|
+
ordf: "ª",
|
|
182
|
+
ordm: "º",
|
|
183
|
+
oslash: "ø",
|
|
184
|
+
otilde: "õ",
|
|
185
|
+
$otimes: "⊗",
|
|
186
|
+
ouml: "ö",
|
|
187
|
+
para: "¶",
|
|
188
|
+
$part: "∂",
|
|
189
|
+
$permil: "‰",
|
|
190
|
+
$perp: "⊥",
|
|
191
|
+
$phi: "φ",
|
|
192
|
+
$pi: "π",
|
|
193
|
+
$piv: "ϖ",
|
|
194
|
+
plusmn: "±",
|
|
195
|
+
pound: "£",
|
|
196
|
+
$prime: "′",
|
|
197
|
+
$prod: "∏",
|
|
198
|
+
$prop: "∝",
|
|
199
|
+
$psi: "ψ",
|
|
200
|
+
quot: "\"",
|
|
201
|
+
$rArr: "⇒",
|
|
202
|
+
$radic: "√",
|
|
203
|
+
$rang: "⟩",
|
|
204
|
+
raquo: "»",
|
|
205
|
+
$rarr: "→",
|
|
206
|
+
$rceil: "⌉",
|
|
207
|
+
$rdquo: "”",
|
|
208
|
+
$real: "ℜ",
|
|
209
|
+
reg: "®",
|
|
210
|
+
$rfloor: "⌋",
|
|
211
|
+
$rho: "ρ",
|
|
212
|
+
$rsaquo: "›",
|
|
213
|
+
$rsquo: "’",
|
|
214
|
+
$sbquo: "‚",
|
|
215
|
+
$scaron: "š",
|
|
216
|
+
$sdot: "⋅",
|
|
217
|
+
sect: "§",
|
|
218
|
+
shy: "",
|
|
219
|
+
$sigma: "σ",
|
|
220
|
+
$sigmaf: "ς",
|
|
221
|
+
$sim: "∼",
|
|
222
|
+
$spades: "♠",
|
|
223
|
+
$sub: "⊂",
|
|
224
|
+
$sube: "⊆",
|
|
225
|
+
$sum: "∑",
|
|
226
|
+
$sup: "⊃",
|
|
227
|
+
sup1: "¹",
|
|
228
|
+
sup2: "²",
|
|
229
|
+
sup3: "³",
|
|
230
|
+
$supe: "⊇",
|
|
231
|
+
szlig: "ß",
|
|
232
|
+
$tau: "τ",
|
|
233
|
+
$there4: "∴",
|
|
234
|
+
$theta: "θ",
|
|
235
|
+
$thetasym: "ϑ",
|
|
236
|
+
thorn: "þ",
|
|
237
|
+
$tilde: "˜",
|
|
238
|
+
times: "×",
|
|
239
|
+
$trade: "™",
|
|
240
|
+
$uArr: "⇑",
|
|
241
|
+
uacute: "ú",
|
|
242
|
+
$uarr: "↑",
|
|
243
|
+
ucirc: "û",
|
|
244
|
+
ugrave: "ù",
|
|
245
|
+
uml: "¨",
|
|
246
|
+
$upsih: "ϒ",
|
|
247
|
+
$upsilon: "υ",
|
|
248
|
+
uuml: "ü",
|
|
249
|
+
$weierp: "℘",
|
|
250
|
+
$xi: "ξ",
|
|
251
|
+
yacute: "ý",
|
|
252
|
+
yen: "¥",
|
|
253
|
+
yuml: "ÿ",
|
|
254
|
+
$zeta: "ζ"
|
|
255
|
+
};
|
|
256
|
+
function lowerAscii(code) {
|
|
257
|
+
return code >= 65 && code <= 90 ? code + 32 : code;
|
|
258
|
+
}
|
|
259
|
+
function noteBufferRewrite(state) {
|
|
260
|
+
if (state.markerLine !== void 0) state.markerLine = void 0;
|
|
261
|
+
}
|
|
262
|
+
function isInsideHeading(depthMap) {
|
|
263
|
+
for (let tagId = 7; tagId <= 12; tagId++) if (depthMap[tagId]) return true;
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
function isInsideTableCell(state) {
|
|
267
|
+
const depthMap = state.depthMap;
|
|
268
|
+
return depthMap[32] > 0 || depthMap[31] > 0;
|
|
269
|
+
}
|
|
270
|
+
function schemeMatches(href, start, end, scheme) {
|
|
271
|
+
let matched = 0;
|
|
272
|
+
for (let index = start; index < end; index++) {
|
|
273
|
+
const code = href.charCodeAt(index);
|
|
274
|
+
if (code === 9 || code === 10 || code === 13) continue;
|
|
275
|
+
if (lowerAscii(code) !== scheme.charCodeAt(matched)) return false;
|
|
276
|
+
if (++matched === scheme.length) return true;
|
|
277
|
+
}
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
function isDataUrl(src) {
|
|
281
|
+
let start = 0;
|
|
282
|
+
while (start < src.length && src.charCodeAt(start) <= 32) start++;
|
|
283
|
+
let end = src.length;
|
|
284
|
+
while (end > start && src.charCodeAt(end - 1) <= 32) end--;
|
|
285
|
+
return schemeMatches(src, start, end, "data:");
|
|
286
|
+
}
|
|
287
|
+
function isEmptyLinkHref(href) {
|
|
288
|
+
let start = 0;
|
|
289
|
+
while (start < href.length && href.charCodeAt(start) <= 32) start++;
|
|
290
|
+
let end = href.length;
|
|
291
|
+
while (end > start && href.charCodeAt(end - 1) <= 32) end--;
|
|
292
|
+
switch (lowerAscii(href.charCodeAt(start))) {
|
|
293
|
+
case 35: return end - start === 1;
|
|
294
|
+
case 106: return schemeMatches(href, start, end, "javascript:");
|
|
295
|
+
case 100: return schemeMatches(href, start, end, "data:");
|
|
296
|
+
case 118: return schemeMatches(href, start, end, "vbscript:");
|
|
297
|
+
default: return false;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function isSafeHtmlUrl(href, image = false) {
|
|
301
|
+
let start = 0;
|
|
302
|
+
while (start < href.length && href.charCodeAt(start) <= 32) start++;
|
|
303
|
+
let end = href.length;
|
|
304
|
+
while (end > start && href.charCodeAt(end - 1) <= 32) end--;
|
|
305
|
+
if (start === end) return false;
|
|
306
|
+
for (let index = start; index < end; index++) {
|
|
307
|
+
const code = href.charCodeAt(index);
|
|
308
|
+
if (code === 9 || code === 10 || code === 13) continue;
|
|
309
|
+
if (code === 58) switch (lowerAscii(href.charCodeAt(start))) {
|
|
310
|
+
case 104: return schemeMatches(href, start, end, "http:") || schemeMatches(href, start, end, "https:");
|
|
311
|
+
case 109: return !image && schemeMatches(href, start, end, "mailto:");
|
|
312
|
+
case 116: return !image && schemeMatches(href, start, end, "tel:");
|
|
313
|
+
case 102: return !image && schemeMatches(href, start, end, "ftp:");
|
|
314
|
+
default: return false;
|
|
315
|
+
}
|
|
316
|
+
if (code === 47 || code === 63 || code === 35) return true;
|
|
317
|
+
const lower = lowerAscii(code);
|
|
318
|
+
if (!(lower >= 97 && lower <= 122 || code >= 48 && code <= 57 || code === 43 || code === 45 || code === 46)) return true;
|
|
319
|
+
}
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
function escapeHtml(value, attribute = false, protectMarkdown = false) {
|
|
323
|
+
let escaped = "";
|
|
324
|
+
let copiedUntil = 0;
|
|
325
|
+
for (let index = 0; index < value.length; index++) {
|
|
326
|
+
const code = value.charCodeAt(index);
|
|
327
|
+
let replacement;
|
|
328
|
+
if (code === 38) replacement = "&";
|
|
329
|
+
else if (code === 60) replacement = "<";
|
|
330
|
+
else if (code === 62) replacement = ">";
|
|
331
|
+
else if (attribute && code === 34) replacement = """;
|
|
332
|
+
else if (protectMarkdown && code === 91) replacement = "[";
|
|
333
|
+
else if (protectMarkdown && code === 93) replacement = "]";
|
|
334
|
+
if (replacement !== void 0) {
|
|
335
|
+
escaped += value.slice(copiedUntil, index) + replacement;
|
|
336
|
+
copiedUntil = index + 1;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return copiedUntil === 0 ? value : escaped + value.slice(copiedUntil);
|
|
340
|
+
}
|
|
341
|
+
const C1_REPLACEMENTS = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ";
|
|
342
|
+
function isAsciiAlphaNumeric(code) {
|
|
343
|
+
return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
344
|
+
}
|
|
345
|
+
function isHtmlAsciiWhitespace(code) {
|
|
346
|
+
return code === 32 || code === 9 || code === 10 || code === 12 || code === 13;
|
|
347
|
+
}
|
|
348
|
+
const LANGUAGE_PREFIX = [
|
|
349
|
+
108,
|
|
350
|
+
97,
|
|
351
|
+
110,
|
|
352
|
+
103,
|
|
353
|
+
117,
|
|
354
|
+
97,
|
|
355
|
+
103,
|
|
356
|
+
101,
|
|
357
|
+
45
|
|
358
|
+
];
|
|
359
|
+
function hasLanguagePrefix(value, start) {
|
|
360
|
+
for (let offset = 0; offset < 9; offset++) if (value.charCodeAt(start + offset) !== LANGUAGE_PREFIX[offset]) return false;
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
function isUnsafeFenceInfoCode(code) {
|
|
364
|
+
if (code < 32 || code === 127) return true;
|
|
365
|
+
return code === 34 || code === 39 || code === 38 || code === 60 || code === 62 || code === 96 || code === 126;
|
|
366
|
+
}
|
|
367
|
+
function getLanguageFromClass(className) {
|
|
368
|
+
if (!className) return "";
|
|
369
|
+
const length = className.length;
|
|
370
|
+
let index = 0;
|
|
371
|
+
while (index < length) {
|
|
372
|
+
if (isHtmlAsciiWhitespace(className.charCodeAt(index))) {
|
|
373
|
+
index++;
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
const tokenStart = index;
|
|
377
|
+
do
|
|
378
|
+
index++;
|
|
379
|
+
while (index < length && !isHtmlAsciiWhitespace(className.charCodeAt(index)));
|
|
380
|
+
const tokenEnd = index;
|
|
381
|
+
const languageStart = tokenStart + 9;
|
|
382
|
+
if (languageStart >= tokenEnd || !hasLanguagePrefix(className, tokenStart)) continue;
|
|
383
|
+
let valid = true;
|
|
384
|
+
for (let cursor = languageStart; cursor < tokenEnd; cursor++) if (isUnsafeFenceInfoCode(className.charCodeAt(cursor))) {
|
|
385
|
+
valid = false;
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
if (valid) return className.slice(languageStart, tokenEnd);
|
|
389
|
+
}
|
|
390
|
+
return "";
|
|
391
|
+
}
|
|
392
|
+
const DATA_LANGUAGE_RE = /^[\t\n\f\r ]*([^\0-\x20"&'<>`~\x7F]+)[\t\n\f\r ]*$/;
|
|
393
|
+
function getLanguageFromDataAttribute(value) {
|
|
394
|
+
return value ? DATA_LANGUAGE_RE.exec(value)?.[1] ?? "" : "";
|
|
395
|
+
}
|
|
396
|
+
function getLanguageFromAttributes(attributes) {
|
|
397
|
+
return getLanguageFromClass(attributes?.class) || getLanguageFromDataAttribute(attributes?.["data-language"]) || getLanguageFromDataAttribute(attributes?.["data-lang"]);
|
|
398
|
+
}
|
|
399
|
+
function hasNonWhitespace(value) {
|
|
400
|
+
for (let i = 0; i < value.length; i++) {
|
|
401
|
+
const c = value.charCodeAt(i);
|
|
402
|
+
if (c !== 32 && c !== 9 && c !== 10 && c !== 12 && c !== 13) return true;
|
|
403
|
+
}
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
function suppressesFormattingInPre(tagId) {
|
|
407
|
+
return tagId === 26 || tagId === 46 || tagId === 110 || tagId === 111 || tagId === 106 || tagId >= 14 && tagId <= 21 || tagId >= 79 && tagId <= 83 || tagId >= 89 && tagId <= 94;
|
|
408
|
+
}
|
|
409
|
+
function parseUnsignedInteger(raw) {
|
|
410
|
+
if (raw === void 0 || !/^[\t\n\f\r ]*\+?\d+[\t\n\f\r ]*$/.test(raw)) return void 0;
|
|
411
|
+
const value = Number(raw);
|
|
412
|
+
return value <= 4294967295 ? value : void 0;
|
|
413
|
+
}
|
|
414
|
+
function trimOutputStart(value) {
|
|
415
|
+
let start = 0;
|
|
416
|
+
while (start < value.length) {
|
|
417
|
+
const code = value.charCodeAt(start);
|
|
418
|
+
if (code === 32 || code >= 9 && code <= 13) {
|
|
419
|
+
start++;
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
if (code < 133 || !(code === 133 || code === 160 || code === 5760 || code >= 8192 && code <= 8202 || code === 8232 || code === 8233 || code === 8239 || code === 8287 || code === 12288)) break;
|
|
423
|
+
start++;
|
|
424
|
+
}
|
|
425
|
+
return start === 0 ? value : value.slice(start);
|
|
426
|
+
}
|
|
427
|
+
function trimTextAtLineStart(node, buffer) {
|
|
428
|
+
const last = lastOutputChar(buffer);
|
|
429
|
+
if (last !== -1 && last !== 10) return;
|
|
430
|
+
const value = node.value;
|
|
431
|
+
let start = 0;
|
|
432
|
+
while (start < value.length) {
|
|
433
|
+
const code = value.charCodeAt(start);
|
|
434
|
+
if (code !== 32 && code !== 10 && code !== 9 && code !== 13 && code !== 12) break;
|
|
435
|
+
start++;
|
|
436
|
+
}
|
|
437
|
+
if (start !== 0) node.value = value.slice(start);
|
|
438
|
+
}
|
|
439
|
+
function needsSpacing(lastChar, firstChar) {
|
|
440
|
+
if (!lastChar || " \n ".includes(lastChar) || " \n ".includes(firstChar)) return false;
|
|
441
|
+
if (lastChar === "|" && firstChar === "<") return true;
|
|
442
|
+
return !"[(>*_`".includes(lastChar) && !"])<.,!?:;*_`".includes(firstChar);
|
|
443
|
+
}
|
|
444
|
+
function lastOutputChar(buffer, end = buffer.length) {
|
|
445
|
+
for (let index = end - 1; index >= 0; index--) {
|
|
446
|
+
const fragment = buffer[index];
|
|
447
|
+
if (fragment.length > 0) return fragment.charCodeAt(fragment.length - 1);
|
|
448
|
+
}
|
|
449
|
+
return -1;
|
|
450
|
+
}
|
|
451
|
+
function endsAtHardBreak(buffer) {
|
|
452
|
+
let fragment = buffer.length - 1;
|
|
453
|
+
let index = fragment >= 0 ? buffer[fragment].length : 0;
|
|
454
|
+
let sawNewline = false;
|
|
455
|
+
let breakSpaces = 0;
|
|
456
|
+
for (;;) {
|
|
457
|
+
while (index === 0) {
|
|
458
|
+
if (--fragment < 0) return false;
|
|
459
|
+
index = buffer[fragment].length;
|
|
460
|
+
}
|
|
461
|
+
const code = buffer[fragment].charCodeAt(--index);
|
|
462
|
+
if (!sawNewline) {
|
|
463
|
+
if (code === 10) sawNewline = true;
|
|
464
|
+
else if (code !== 32) return false;
|
|
465
|
+
} else if (code === 32) {
|
|
466
|
+
if (++breakSpaces === 2) return true;
|
|
467
|
+
} else return false;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
function blockOpenPrefix(state, prefix, end = state.buffer.length) {
|
|
471
|
+
const buffer = state.buffer;
|
|
472
|
+
switch (lastOutputChar(buffer, end)) {
|
|
473
|
+
case -1: return;
|
|
474
|
+
case 32: {
|
|
475
|
+
let fragment = end - 1;
|
|
476
|
+
let index = buffer[fragment].length;
|
|
477
|
+
for (;;) {
|
|
478
|
+
if (index === 0) {
|
|
479
|
+
if (--fragment < 0) return void 0;
|
|
480
|
+
index = buffer[fragment].length;
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
const code = buffer[fragment].charCodeAt(--index);
|
|
484
|
+
if (code !== 32) return code === 10 || listMarkerLineStart(buffer, fragment, index, pendingMarkerIndent(state)) ? void 0 : `\n\n${prefix ?? ""}`;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
case 10: return prefix || void 0;
|
|
488
|
+
default: return `\n\n${prefix ?? ""}`;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
function figcaptionOwnsBlockSpacing(node, plainText) {
|
|
492
|
+
let parent = node.parent;
|
|
493
|
+
while (parent) {
|
|
494
|
+
if (parent.tagId === 32 || parent.tagId === 31) return false;
|
|
495
|
+
if (!plainText && parent.tagId !== 37 && parent.tagHandler?.collapsesInnerWhiteSpace) return false;
|
|
496
|
+
parent = parent.parent;
|
|
497
|
+
}
|
|
498
|
+
return true;
|
|
499
|
+
}
|
|
500
|
+
function pendingMarkerIndent(state) {
|
|
501
|
+
const widths = state.listIndentWidths;
|
|
502
|
+
return widths?.length ? state.listIndent.length - widths[widths.length - 1] : 3;
|
|
503
|
+
}
|
|
504
|
+
function listMarkerLineStart(buffer, fragmentIndex, markerIndex, maxIndent = 3) {
|
|
505
|
+
const marker = buffer[fragmentIndex].charCodeAt(markerIndex);
|
|
506
|
+
const ordered = marker === 46 || marker === 41;
|
|
507
|
+
if (!ordered && marker !== 45 && marker !== 42 && marker !== 43) return false;
|
|
508
|
+
let digits = 0;
|
|
509
|
+
let spaces = 0;
|
|
510
|
+
let fragment = fragmentIndex;
|
|
511
|
+
let cursor = markerIndex;
|
|
512
|
+
for (;;) {
|
|
513
|
+
if (cursor === 0) {
|
|
514
|
+
if (--fragment < 0) return !ordered || digits > 0;
|
|
515
|
+
cursor = buffer[fragment].length;
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
const code = buffer[fragment].charCodeAt(--cursor);
|
|
519
|
+
if (ordered && spaces === 0 && code >= 48 && code <= 57) {
|
|
520
|
+
if (++digits > 9) return false;
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
523
|
+
if (ordered && digits === 0) return false;
|
|
524
|
+
if (code === 32) {
|
|
525
|
+
if (!(cursor > 0 ? buffer[fragment].charCodeAt(cursor - 1) === 13 : fragment > 0 && buffer[fragment - 1].endsWith("\r")) && ++spaces > maxIndent) return false;
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
return code === 10 || code === 13;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
const MAX_ORDERED_START = 999999999;
|
|
532
|
+
function orderedItemNumber(list, index) {
|
|
533
|
+
const raw = list?.attributes?.start;
|
|
534
|
+
if (raw === void 0) return index + 1;
|
|
535
|
+
const start = parseUnsignedInteger(raw);
|
|
536
|
+
if (start === void 0 || start > MAX_ORDERED_START) return Math.min(1 + index, MAX_ORDERED_START);
|
|
537
|
+
return Math.min(start + index, MAX_ORDERED_START);
|
|
538
|
+
}
|
|
539
|
+
function numericReplacement(codePoint) {
|
|
540
|
+
if (codePoint === 0 || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343) return "�";
|
|
541
|
+
if (codePoint >= 128 && codePoint <= 159) return C1_REPLACEMENTS[codePoint - 128];
|
|
542
|
+
return String.fromCodePoint(codePoint);
|
|
543
|
+
}
|
|
544
|
+
function isCharacterReferenceTail(text, start) {
|
|
545
|
+
let index = start;
|
|
546
|
+
if (text.charCodeAt(index) === 35) {
|
|
547
|
+
index++;
|
|
548
|
+
const hex = text.charCodeAt(index) === 120 || text.charCodeAt(index) === 88;
|
|
549
|
+
if (hex) index++;
|
|
550
|
+
const digitStart = index;
|
|
551
|
+
while (index < text.length) {
|
|
552
|
+
const code = text.charCodeAt(index);
|
|
553
|
+
if (!(code >= 48 && code <= 57) && !(hex && (code >= 65 && code <= 70 || code >= 97 && code <= 102))) break;
|
|
554
|
+
index++;
|
|
555
|
+
}
|
|
556
|
+
return index > digitStart && text.charCodeAt(index) === 59;
|
|
557
|
+
}
|
|
558
|
+
const nameStart = index;
|
|
559
|
+
while (index < text.length && isAsciiAlphaNumeric(text.charCodeAt(index))) index++;
|
|
560
|
+
return index > nameStart && text.charCodeAt(index) === 59;
|
|
561
|
+
}
|
|
562
|
+
function decodedReference(replacement, text, next, protectDecodedEntityReferences) {
|
|
563
|
+
return replacement === "&" && protectDecodedEntityReferences && isCharacterReferenceTail(text, next) ? "\\&" : replacement;
|
|
564
|
+
}
|
|
565
|
+
function decodeHTMLEntities(text, inAttribute = false, protectDecodedEntityReferences = false) {
|
|
566
|
+
let result = "";
|
|
567
|
+
let i = 0;
|
|
568
|
+
const len = text.length;
|
|
569
|
+
while (i < len) {
|
|
570
|
+
if (text.charCodeAt(i) !== 38) {
|
|
571
|
+
const plainStart = i;
|
|
572
|
+
while (i < len && text.charCodeAt(i) !== 38) i++;
|
|
573
|
+
result += text.slice(plainStart, i);
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
576
|
+
if (i + 2 < len && text.charCodeAt(i + 1) === 35) {
|
|
577
|
+
let end = i + 2;
|
|
578
|
+
const isHex = text.charCodeAt(end) === 120 || text.charCodeAt(end) === 88;
|
|
579
|
+
if (isHex) end++;
|
|
580
|
+
const digitStart = end;
|
|
581
|
+
let codePoint = 0;
|
|
582
|
+
while (end < len) {
|
|
583
|
+
const code = text.charCodeAt(end);
|
|
584
|
+
let digit = -1;
|
|
585
|
+
if (code >= 48 && code <= 57) digit = code - 48;
|
|
586
|
+
else if (isHex && code >= 65 && code <= 70) digit = code - 55;
|
|
587
|
+
else if (isHex && code >= 97 && code <= 102) digit = code - 87;
|
|
588
|
+
if (digit < 0) break;
|
|
589
|
+
codePoint = codePoint * (isHex ? 16 : 10) + digit;
|
|
590
|
+
end++;
|
|
591
|
+
}
|
|
592
|
+
if (end > digitStart) {
|
|
593
|
+
result += decodedReference(numericReplacement(codePoint), text, text.charCodeAt(end) === 59 ? end + 1 : end, protectDecodedEntityReferences);
|
|
594
|
+
if (text.charCodeAt(end) === 59) end++;
|
|
595
|
+
i = end;
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
const nameStart = i + 1;
|
|
600
|
+
let nameEnd = nameStart;
|
|
601
|
+
const scanEnd = Math.min(len, nameStart + 8);
|
|
602
|
+
while (nameEnd < scanEnd && isAsciiAlphaNumeric(text.charCodeAt(nameEnd))) nameEnd++;
|
|
603
|
+
if (nameEnd > nameStart && text.charCodeAt(nameEnd) === 59) {
|
|
604
|
+
const name = text.slice(nameStart, nameEnd);
|
|
605
|
+
const direct = HTML_ENTITIES[name];
|
|
606
|
+
const replacement = typeof direct === "string" ? direct : HTML_ENTITIES[`$${name}`];
|
|
607
|
+
if (replacement !== void 0) {
|
|
608
|
+
result += decodedReference(replacement, text, nameEnd + 1, protectDecodedEntityReferences);
|
|
609
|
+
i = nameEnd + 1;
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
let legacyEnd = Math.min(nameEnd, nameStart + 6);
|
|
614
|
+
let decodedLegacy = false;
|
|
615
|
+
while (legacyEnd > nameStart) {
|
|
616
|
+
const name = text.slice(nameStart, legacyEnd);
|
|
617
|
+
const replacement = HTML_ENTITIES[name];
|
|
618
|
+
if (typeof replacement === "string") {
|
|
619
|
+
const next = text.charCodeAt(legacyEnd);
|
|
620
|
+
if (replacement !== void 0 && !(inAttribute && (next === 61 || isAsciiAlphaNumeric(next)))) {
|
|
621
|
+
result += decodedReference(replacement, text, legacyEnd, protectDecodedEntityReferences);
|
|
622
|
+
i = legacyEnd;
|
|
623
|
+
decodedLegacy = true;
|
|
624
|
+
}
|
|
625
|
+
break;
|
|
626
|
+
}
|
|
627
|
+
legacyEnd--;
|
|
628
|
+
}
|
|
629
|
+
if (decodedLegacy) continue;
|
|
630
|
+
result += "&";
|
|
631
|
+
i++;
|
|
632
|
+
}
|
|
633
|
+
return result;
|
|
634
|
+
}
|
|
635
|
+
function isInlineNode(node) {
|
|
636
|
+
const isInline = node.tagHandler?.isInline;
|
|
637
|
+
return isInline === void 0 ? node.tagId === -1 : isInline;
|
|
638
|
+
}
|
|
639
|
+
function traverseUpToFirstBlockNode(node) {
|
|
640
|
+
let firstBlockParent = node;
|
|
641
|
+
const parentsToIncrement = [firstBlockParent];
|
|
642
|
+
while (isInlineNode(firstBlockParent)) {
|
|
643
|
+
if (!firstBlockParent.parent) break;
|
|
644
|
+
firstBlockParent = firstBlockParent.parent;
|
|
645
|
+
parentsToIncrement.push(firstBlockParent);
|
|
646
|
+
}
|
|
647
|
+
return parentsToIncrement;
|
|
648
|
+
}
|
|
649
|
+
function markRenderedChildContent(node) {
|
|
650
|
+
let parent = node.parent;
|
|
651
|
+
let anchorInScope = false;
|
|
652
|
+
while (parent) {
|
|
653
|
+
parent.childTextNodeIndex = (parent.childTextNodeIndex || 0) + 1;
|
|
654
|
+
if (parent.tagId === 26) anchorInScope = true;
|
|
655
|
+
if (!isInlineNode(parent)) break;
|
|
656
|
+
parent = parent.parent;
|
|
657
|
+
}
|
|
658
|
+
if (anchorInScope) return;
|
|
659
|
+
let anchorFound = false;
|
|
660
|
+
while (parent?.parent) {
|
|
661
|
+
parent = parent.parent;
|
|
662
|
+
if (!anchorFound) {
|
|
663
|
+
if (parent.tagId !== 26) continue;
|
|
664
|
+
anchorFound = true;
|
|
665
|
+
}
|
|
666
|
+
parent.childTextNodeIndex = (parent.childTextNodeIndex || 0) + 1;
|
|
667
|
+
if (!isInlineNode(parent)) return;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
2
670
|
const URL_SCHEME_RE = /^[A-Z][\dA-Z+.-]*:/i;
|
|
3
671
|
const SLASH_CHAR = 47;
|
|
4
672
|
function pathEnd(value, from) {
|
|
@@ -79,4 +747,4 @@ function safeAnchorOutput(node, options, entering, protectMarkdown = false) {
|
|
|
79
747
|
if (!entering) return "</a>";
|
|
80
748
|
return `<a href="${escapeHtml(resolved, true, protectMarkdown)}"${node.attributes?.title === void 0 ? "" : ` title="${escapeHtml(node.attributes.title, true, protectMarkdown)}"`}>`;
|
|
81
749
|
}
|
|
82
|
-
export { resolveUrl, safeAnchorOutput };
|
|
750
|
+
export { blockOpenPrefix, decodeHTMLEntities, endsAtHardBreak, escapeHtml, figcaptionOwnsBlockSpacing, getLanguageFromAttributes, hasNonWhitespace, isCharacterReferenceTail, isDataUrl, isEmptyLinkHref, isInsideHeading, isInsideTableCell, isSafeHtmlUrl, lastOutputChar, listMarkerLineStart, markRenderedChildContent, needsSpacing, noteBufferRewrite, orderedItemNumber, parseUnsignedInteger, pendingMarkerIndent, resolveUrl, safeAnchorOutput, suppressesFormattingInPre, traverseUpToFirstBlockNode, trimOutputStart, trimTextAtLineStart };
|
package/dist/clean.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { clean, slugify, stripHeadingFormatting };
|
|
1
|
+
export { clean, slugify, stripHeadingFormatting } from "./_chunks/clean.mjs";
|
package/dist/html.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { htmlToSafeHtml, streamHtmlToSafeHtml };
|
|
1
|
+
export { htmlToSafeHtml, streamHtmlToSafeHtml } from "./_chunks/html.mjs";
|
package/dist/negotiate.d.mts
CHANGED
|
@@ -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 {};
|