@mdream/js 1.4.1 → 1.5.3
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 +43 -7
- package/dist/_chunks/const.mjs +2 -2
- package/dist/_chunks/index.d.mts +1 -0
- package/dist/_chunks/markdown-processor.mjs +464 -0
- package/dist/_chunks/parse.mjs +757 -473
- package/dist/_chunks/plugins.mjs +18 -19
- package/dist/_chunks/resolve-plugins.mjs +1 -341
- package/dist/_chunks/src.mjs +5 -36
- package/dist/_chunks/stream.mjs +35 -0
- package/dist/_chunks/types.d.mts +25 -6
- package/dist/cli.mjs +9 -2
- package/dist/core.d.mts +16 -0
- package/dist/core.mjs +26 -0
- package/dist/parse.d.mts +13 -8
- package/dist/plugins.d.mts +6 -5
- package/dist/splitter.mjs +11 -2
- package/package.json +12 -2
package/dist/_chunks/parse.mjs
CHANGED
|
@@ -1,4 +1,365 @@
|
|
|
1
1
|
import { BLOCKQUOTE_SPACING, LIST_ITEM_SPACING, NO_SPACING, TABLE_ROW_SPACING, TagIdMap } from "./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 continuationPrefix(node, listIndentWidths) {
|
|
257
|
+
const chain = [];
|
|
258
|
+
let current = node.parent;
|
|
259
|
+
while (current) {
|
|
260
|
+
chain.push(current);
|
|
261
|
+
current = current.parent;
|
|
262
|
+
}
|
|
263
|
+
let prefix = "";
|
|
264
|
+
let listIndex = 0;
|
|
265
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
266
|
+
const tagId = chain[i].tagId;
|
|
267
|
+
if (tagId === 22) prefix += "> ";
|
|
268
|
+
else if (tagId === 25) {
|
|
269
|
+
prefix += " ".repeat(listIndentWidths[listIndex] ?? 2);
|
|
270
|
+
listIndex++;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return prefix;
|
|
274
|
+
}
|
|
275
|
+
const C1_REPLACEMENTS = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ";
|
|
276
|
+
function isAsciiAlphaNumeric(code) {
|
|
277
|
+
return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
278
|
+
}
|
|
279
|
+
function numericReplacement(codePoint) {
|
|
280
|
+
if (codePoint === 0 || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343) return "�";
|
|
281
|
+
if (codePoint >= 128 && codePoint <= 159) return C1_REPLACEMENTS[codePoint - 128];
|
|
282
|
+
return String.fromCodePoint(codePoint);
|
|
283
|
+
}
|
|
284
|
+
function decodeHTMLEntities(text, inAttribute = false) {
|
|
285
|
+
let result = "";
|
|
286
|
+
let i = 0;
|
|
287
|
+
const len = text.length;
|
|
288
|
+
while (i < len) {
|
|
289
|
+
if (text.charCodeAt(i) !== 38) {
|
|
290
|
+
const plainStart = i;
|
|
291
|
+
while (i < len && text.charCodeAt(i) !== 38) i++;
|
|
292
|
+
result += text.slice(plainStart, i);
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (i + 2 < len && text.charCodeAt(i + 1) === 35) {
|
|
296
|
+
let end = i + 2;
|
|
297
|
+
const isHex = text.charCodeAt(end) === 120 || text.charCodeAt(end) === 88;
|
|
298
|
+
if (isHex) end++;
|
|
299
|
+
const digitStart = end;
|
|
300
|
+
let codePoint = 0;
|
|
301
|
+
while (end < len) {
|
|
302
|
+
const code = text.charCodeAt(end);
|
|
303
|
+
let digit = -1;
|
|
304
|
+
if (code >= 48 && code <= 57) digit = code - 48;
|
|
305
|
+
else if (isHex && code >= 65 && code <= 70) digit = code - 55;
|
|
306
|
+
else if (isHex && code >= 97 && code <= 102) digit = code - 87;
|
|
307
|
+
if (digit < 0) break;
|
|
308
|
+
codePoint = codePoint * (isHex ? 16 : 10) + digit;
|
|
309
|
+
end++;
|
|
310
|
+
}
|
|
311
|
+
if (end > digitStart) {
|
|
312
|
+
result += numericReplacement(codePoint);
|
|
313
|
+
if (text.charCodeAt(end) === 59) end++;
|
|
314
|
+
i = end;
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const nameStart = i + 1;
|
|
319
|
+
let nameEnd = nameStart;
|
|
320
|
+
const scanEnd = Math.min(len, nameStart + 8);
|
|
321
|
+
while (nameEnd < scanEnd && isAsciiAlphaNumeric(text.charCodeAt(nameEnd))) nameEnd++;
|
|
322
|
+
if (nameEnd > nameStart && text.charCodeAt(nameEnd) === 59) {
|
|
323
|
+
const name = text.slice(nameStart, nameEnd);
|
|
324
|
+
const direct = HTML_ENTITIES[name];
|
|
325
|
+
const replacement = typeof direct === "string" ? direct : HTML_ENTITIES[`$${name}`];
|
|
326
|
+
if (replacement !== void 0) {
|
|
327
|
+
result += replacement;
|
|
328
|
+
i = nameEnd + 1;
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
let legacyEnd = Math.min(nameEnd, nameStart + 6);
|
|
333
|
+
let decodedLegacy = false;
|
|
334
|
+
while (legacyEnd > nameStart) {
|
|
335
|
+
const replacement = HTML_ENTITIES[text.slice(nameStart, legacyEnd)];
|
|
336
|
+
if (typeof replacement === "string") {
|
|
337
|
+
const next = text.charCodeAt(legacyEnd);
|
|
338
|
+
if (replacement !== void 0 && !(inAttribute && (next === 61 || isAsciiAlphaNumeric(next)))) {
|
|
339
|
+
result += replacement;
|
|
340
|
+
i = legacyEnd;
|
|
341
|
+
decodedLegacy = true;
|
|
342
|
+
}
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
legacyEnd--;
|
|
346
|
+
}
|
|
347
|
+
if (decodedLegacy) continue;
|
|
348
|
+
result += "&";
|
|
349
|
+
i++;
|
|
350
|
+
}
|
|
351
|
+
return result;
|
|
352
|
+
}
|
|
353
|
+
function traverseUpToFirstBlockNode(node) {
|
|
354
|
+
let firstBlockParent = node;
|
|
355
|
+
const parentsToIncrement = [firstBlockParent];
|
|
356
|
+
while (firstBlockParent.tagHandler?.isInline) {
|
|
357
|
+
if (!firstBlockParent.parent) break;
|
|
358
|
+
firstBlockParent = firstBlockParent.parent;
|
|
359
|
+
parentsToIncrement.push(firstBlockParent);
|
|
360
|
+
}
|
|
361
|
+
return parentsToIncrement;
|
|
362
|
+
}
|
|
2
363
|
function resolveUrl(url, origin) {
|
|
3
364
|
if (!url) return url;
|
|
4
365
|
if (url.startsWith("//")) return `https:${url}`;
|
|
@@ -18,8 +379,13 @@ function isAutolinkUri(s) {
|
|
|
18
379
|
}
|
|
19
380
|
return true;
|
|
20
381
|
}
|
|
21
|
-
function isInsideTableCell(
|
|
22
|
-
|
|
382
|
+
function isInsideTableCell(state) {
|
|
383
|
+
const depthMap = state.depthMap;
|
|
384
|
+
return (depthMap[32] || 0) > 0 || (depthMap[31] || 0) > 0;
|
|
385
|
+
}
|
|
386
|
+
function isInsideRawHtmlBlock(state) {
|
|
387
|
+
const depthMap = state.depthMap;
|
|
388
|
+
return Boolean(depthMap[2] || depthMap[3] || depthMap[100] || depthMap[101] || depthMap[99] || depthMap[98]);
|
|
23
389
|
}
|
|
24
390
|
function getLanguageFromClass(className) {
|
|
25
391
|
if (!className) return "";
|
|
@@ -28,23 +394,23 @@ function getLanguageFromClass(className) {
|
|
|
28
394
|
}
|
|
29
395
|
function handleHeading(depth) {
|
|
30
396
|
return {
|
|
31
|
-
enter: ({
|
|
32
|
-
if ((
|
|
397
|
+
enter: ({ state }) => {
|
|
398
|
+
if ((state.depthMap?.[26] || 0) > 0) return `<h${depth}>`;
|
|
33
399
|
return `${"#".repeat(depth)} `;
|
|
34
400
|
},
|
|
35
|
-
exit: ({
|
|
36
|
-
if ((
|
|
401
|
+
exit: ({ state }) => {
|
|
402
|
+
if ((state.depthMap?.[26] || 0) > 0) return `</h${depth}>`;
|
|
37
403
|
},
|
|
38
404
|
collapsesInnerWhiteSpace: true
|
|
39
405
|
};
|
|
40
406
|
}
|
|
41
407
|
const Strong = {
|
|
42
|
-
enter: ({
|
|
43
|
-
if ((
|
|
408
|
+
enter: ({ state }) => {
|
|
409
|
+
if ((state.depthMap?.[15] || 0) > 1) return "";
|
|
44
410
|
return "**";
|
|
45
411
|
},
|
|
46
|
-
exit: ({ node }) => {
|
|
47
|
-
if ((
|
|
412
|
+
exit: ({ node, state }) => {
|
|
413
|
+
if ((state.depthMap?.[15] || 0) + (node.tagId === 15 ? 1 : 0) > 1) return "";
|
|
48
414
|
return "**";
|
|
49
415
|
},
|
|
50
416
|
collapsesInnerWhiteSpace: true,
|
|
@@ -52,12 +418,12 @@ const Strong = {
|
|
|
52
418
|
isInline: true
|
|
53
419
|
};
|
|
54
420
|
const Emphasis = {
|
|
55
|
-
enter: ({
|
|
56
|
-
if ((
|
|
421
|
+
enter: ({ state }) => {
|
|
422
|
+
if ((state.depthMap?.[17] || 0) > 1) return "";
|
|
57
423
|
return "_";
|
|
58
424
|
},
|
|
59
|
-
exit: ({ node }) => {
|
|
60
|
-
if ((
|
|
425
|
+
exit: ({ node, state }) => {
|
|
426
|
+
if ((state.depthMap?.[17] || 0) + (node.tagId === 17 ? 1 : 0) > 1) return "";
|
|
61
427
|
return "_";
|
|
62
428
|
},
|
|
63
429
|
collapsesInnerWhiteSpace: true,
|
|
@@ -96,8 +462,10 @@ const tagHandlers = {
|
|
|
96
462
|
spacing: NO_SPACING
|
|
97
463
|
},
|
|
98
464
|
[6]: {
|
|
99
|
-
enter: ({ node }) => {
|
|
100
|
-
|
|
465
|
+
enter: ({ node, state }) => {
|
|
466
|
+
const depthMap = state.depthMap;
|
|
467
|
+
if (isInsideTableCell(state) || isInsideRawHtmlBlock(state) || depthMap[7] || depthMap[8] || depthMap[9] || depthMap[10] || depthMap[11] || depthMap[12]) return "<br>";
|
|
468
|
+
return `\n${continuationPrefix(node, state.listIndentWidths || [])}`;
|
|
101
469
|
},
|
|
102
470
|
isSelfClosing: true,
|
|
103
471
|
spacing: NO_SPACING,
|
|
@@ -147,10 +515,10 @@ const tagHandlers = {
|
|
|
147
515
|
isInline: true
|
|
148
516
|
},
|
|
149
517
|
[22]: {
|
|
150
|
-
enter: ({
|
|
151
|
-
const depth =
|
|
518
|
+
enter: ({ state }) => {
|
|
519
|
+
const depth = state.depthMap?.[22] || 1;
|
|
152
520
|
let prefix = "> ".repeat(depth);
|
|
153
|
-
if ((
|
|
521
|
+
if ((state.depthMap?.[25] || 0) > 0) prefix = `\n${state.listIndent}${prefix}`;
|
|
154
522
|
return prefix;
|
|
155
523
|
},
|
|
156
524
|
spacing: BLOCKQUOTE_SPACING
|
|
@@ -161,12 +529,12 @@ const tagHandlers = {
|
|
|
161
529
|
state.preOwnFence = false;
|
|
162
530
|
state.preFenceLang = getLanguageFromClass(node.attributes?.class);
|
|
163
531
|
},
|
|
164
|
-
exit: ({
|
|
532
|
+
exit: ({ state }) => {
|
|
165
533
|
const ownFence = state.preOwnFence;
|
|
166
534
|
state.preFencePending = false;
|
|
167
535
|
state.preOwnFence = false;
|
|
168
536
|
if (!ownFence) return;
|
|
169
|
-
if ((
|
|
537
|
+
if ((state.depthMap?.[25] || 0) > 0) {
|
|
170
538
|
const indent = state.listIndent;
|
|
171
539
|
return `\n${indent}\`\`\`\n\n${indent}`;
|
|
172
540
|
}
|
|
@@ -175,24 +543,24 @@ const tagHandlers = {
|
|
|
175
543
|
},
|
|
176
544
|
[23]: {
|
|
177
545
|
enter: ({ node, state }) => {
|
|
178
|
-
if ((
|
|
546
|
+
if ((state.depthMap?.[34] || 0) > 0) {
|
|
179
547
|
if (state.preOwnFence) return;
|
|
180
548
|
state.preFencePending = false;
|
|
181
549
|
const language = getLanguageFromClass(node.attributes?.class);
|
|
182
|
-
if ((
|
|
550
|
+
if ((state.depthMap?.[25] || 0) > 0) return `\n\n${state.listIndent}\`\`\`${language}\n`;
|
|
183
551
|
return `\`\`\`${language}\n`;
|
|
184
552
|
}
|
|
185
|
-
if ((
|
|
553
|
+
if ((state.depthMap?.[25] || 0) > 0) {
|
|
186
554
|
const lastEntry = state.buffer.at(-1);
|
|
187
555
|
const lastChar = lastEntry?.charAt(lastEntry.length - 1) || "";
|
|
188
556
|
if (lastChar && lastChar !== " " && lastChar !== "\n" && lastChar !== " " && lastChar !== "*" && lastChar !== "_" && lastChar !== "~" && lastChar !== "[" && lastChar !== ">") return ` \``;
|
|
189
557
|
}
|
|
190
558
|
return "`";
|
|
191
559
|
},
|
|
192
|
-
exit: ({
|
|
193
|
-
if ((
|
|
560
|
+
exit: ({ state }) => {
|
|
561
|
+
if ((state.depthMap?.[34] || 0) > 0) {
|
|
194
562
|
if (state.preOwnFence) return;
|
|
195
|
-
if ((
|
|
563
|
+
if ((state.depthMap?.[25] || 0) > 0) {
|
|
196
564
|
const indent = state.listIndent;
|
|
197
565
|
return `\n${indent}\`\`\`\n\n${indent}`;
|
|
198
566
|
}
|
|
@@ -205,20 +573,20 @@ const tagHandlers = {
|
|
|
205
573
|
isInline: true
|
|
206
574
|
},
|
|
207
575
|
[24]: {
|
|
208
|
-
enter: ({
|
|
209
|
-
exit: ({
|
|
576
|
+
enter: ({ state }) => isInsideTableCell(state) ? "<ul>" : void 0,
|
|
577
|
+
exit: ({ state }) => isInsideTableCell(state) ? "</ul>" : void 0
|
|
210
578
|
},
|
|
211
579
|
[33]: {
|
|
212
|
-
enter: ({
|
|
213
|
-
exit: ({
|
|
580
|
+
enter: ({ state }) => isInsideTableCell(state) ? "<ol>" : void 0,
|
|
581
|
+
exit: ({ state }) => isInsideTableCell(state) ? "</ol>" : void 0
|
|
214
582
|
},
|
|
215
583
|
[25]: {
|
|
216
584
|
enter: ({ node, state }) => {
|
|
217
|
-
if (isInsideTableCell(
|
|
585
|
+
if (isInsideTableCell(state)) return "<li>";
|
|
218
586
|
const marker = node.parent?.tagId === 33 ? `${node.index + 1}. ` : "- ";
|
|
219
587
|
return `${state.listIndent}${marker}`;
|
|
220
588
|
},
|
|
221
|
-
exit: ({
|
|
589
|
+
exit: ({ state }) => isInsideTableCell(state) ? "</li>" : void 0,
|
|
222
590
|
spacing: LIST_ITEM_SPACING
|
|
223
591
|
},
|
|
224
592
|
[26]: {
|
|
@@ -264,29 +632,29 @@ const tagHandlers = {
|
|
|
264
632
|
isInline: true
|
|
265
633
|
},
|
|
266
634
|
[28]: {
|
|
267
|
-
enter: ({
|
|
268
|
-
if (isInsideTableCell(
|
|
269
|
-
if ((
|
|
635
|
+
enter: ({ state }) => {
|
|
636
|
+
if (isInsideTableCell(state)) return "<table>";
|
|
637
|
+
if ((state.depthMap?.[28] || 0) <= 1) state.tableRenderedTable = false;
|
|
270
638
|
state.tableColumnAlignments = [];
|
|
271
639
|
},
|
|
272
|
-
exit: ({
|
|
640
|
+
exit: ({ state }) => isInsideTableCell(state) ? "</table>" : void 0
|
|
273
641
|
},
|
|
274
642
|
[29]: {
|
|
275
|
-
enter: ({
|
|
276
|
-
if (isInsideTableCell(
|
|
643
|
+
enter: ({ state }) => {
|
|
644
|
+
if (isInsideTableCell(state)) return "<thead>";
|
|
277
645
|
},
|
|
278
|
-
exit: ({
|
|
646
|
+
exit: ({ state }) => isInsideTableCell(state) ? "</thead>" : void 0,
|
|
279
647
|
spacing: TABLE_ROW_SPACING,
|
|
280
648
|
excludesTextNodes: true
|
|
281
649
|
},
|
|
282
650
|
[30]: {
|
|
283
|
-
enter: ({
|
|
284
|
-
if (isInsideTableCell(
|
|
651
|
+
enter: ({ state }) => {
|
|
652
|
+
if (isInsideTableCell(state)) return "<tr>";
|
|
285
653
|
state.tableCurrentRowCells = 0;
|
|
286
654
|
return "| ";
|
|
287
655
|
},
|
|
288
|
-
exit: ({
|
|
289
|
-
if (isInsideTableCell(
|
|
656
|
+
exit: ({ state }) => {
|
|
657
|
+
if (isInsideTableCell(state) || (state.depthMap?.[28] || 0) > 1) return "</tr>";
|
|
290
658
|
if (!state.tableRenderedTable) {
|
|
291
659
|
state.tableRenderedTable = true;
|
|
292
660
|
const alignments = state.tableColumnAlignments;
|
|
@@ -307,33 +675,33 @@ const tagHandlers = {
|
|
|
307
675
|
},
|
|
308
676
|
[31]: {
|
|
309
677
|
enter: ({ node, state }) => {
|
|
310
|
-
if ((
|
|
678
|
+
if ((state.depthMap?.[28] || 0) > 1) return "<th>";
|
|
311
679
|
const align = node.attributes?.align?.toLowerCase();
|
|
312
680
|
if (align) state.tableColumnAlignments.push(align);
|
|
313
681
|
else if (state.tableColumnAlignments.length <= state.tableCurrentRowCells) state.tableColumnAlignments.push("");
|
|
314
682
|
return node.index === 0 ? "" : " | ";
|
|
315
683
|
},
|
|
316
|
-
exit: ({
|
|
317
|
-
if ((
|
|
684
|
+
exit: ({ state }) => {
|
|
685
|
+
if ((state.depthMap?.[28] || 0) > 1) return "</th>";
|
|
318
686
|
state.tableCurrentRowCells++;
|
|
319
687
|
},
|
|
320
688
|
collapsesInnerWhiteSpace: true,
|
|
321
689
|
spacing: NO_SPACING
|
|
322
690
|
},
|
|
323
691
|
[32]: {
|
|
324
|
-
enter: ({ node }) => {
|
|
325
|
-
if ((
|
|
692
|
+
enter: ({ node, state }) => {
|
|
693
|
+
if ((state.depthMap?.[28] || 0) > 1) return "<td>";
|
|
326
694
|
return node.index === 0 ? "" : " | ";
|
|
327
695
|
},
|
|
328
|
-
exit: ({
|
|
329
|
-
if ((
|
|
696
|
+
exit: ({ state }) => {
|
|
697
|
+
if ((state.depthMap?.[28] || 0) > 1) return "</td>";
|
|
330
698
|
state.tableCurrentRowCells++;
|
|
331
699
|
},
|
|
332
700
|
collapsesInnerWhiteSpace: true,
|
|
333
701
|
spacing: NO_SPACING
|
|
334
702
|
},
|
|
335
|
-
[35]: { enter: ({
|
|
336
|
-
const bqDepth =
|
|
703
|
+
[35]: { enter: ({ state }) => {
|
|
704
|
+
const bqDepth = state.depthMap?.[22] || 0;
|
|
337
705
|
if (bqDepth > 0) {
|
|
338
706
|
const lastEntry = state.buffer.at(-1);
|
|
339
707
|
const lastChar = lastEntry?.charAt(lastEntry.length - 1) || "";
|
|
@@ -342,7 +710,7 @@ const tagHandlers = {
|
|
|
342
710
|
return `\n${prefix.trimEnd()}\n${prefix}`;
|
|
343
711
|
}
|
|
344
712
|
}
|
|
345
|
-
if ((
|
|
713
|
+
if ((state.depthMap?.[25] || 0) > 0 && !isInsideTableCell(state)) {
|
|
346
714
|
const lastEntry = state.buffer.at(-1);
|
|
347
715
|
const lastChar = lastEntry?.charAt(lastEntry.length - 1) || "";
|
|
348
716
|
if (lastChar && lastChar !== " " && lastChar !== "\n") return `\n\n${state.listIndent}`;
|
|
@@ -362,15 +730,16 @@ const tagHandlers = {
|
|
|
362
730
|
},
|
|
363
731
|
[43]: {
|
|
364
732
|
collapsesInnerWhiteSpace: true,
|
|
733
|
+
spacing: NO_SPACING,
|
|
365
734
|
isInline: true
|
|
366
735
|
},
|
|
367
736
|
[44]: { spacing: NO_SPACING },
|
|
368
737
|
[45]: {
|
|
369
|
-
enter: ({
|
|
370
|
-
if ((
|
|
738
|
+
enter: ({ state }) => {
|
|
739
|
+
if ((state.depthMap?.[28] || 0) > 1) return "<center>";
|
|
371
740
|
},
|
|
372
|
-
exit: ({
|
|
373
|
-
if ((
|
|
741
|
+
exit: ({ state }) => {
|
|
742
|
+
if ((state.depthMap?.[28] || 0) > 1) return "</center>";
|
|
374
743
|
},
|
|
375
744
|
spacing: NO_SPACING
|
|
376
745
|
},
|
|
@@ -453,10 +822,8 @@ const tagHandlers = {
|
|
|
453
822
|
isNonNesting: true,
|
|
454
823
|
spacing: NO_SPACING
|
|
455
824
|
},
|
|
456
|
-
[67]: {
|
|
457
|
-
|
|
458
|
-
spacing: NO_SPACING
|
|
459
|
-
},
|
|
825
|
+
[67]: { spacing: NO_SPACING },
|
|
826
|
+
[109]: { spacing: NO_SPACING },
|
|
460
827
|
[68]: { spacing: NO_SPACING },
|
|
461
828
|
[69]: { spacing: NO_SPACING },
|
|
462
829
|
[70]: { spacing: NO_SPACING },
|
|
@@ -471,7 +838,6 @@ const tagHandlers = {
|
|
|
471
838
|
[76]: { spacing: NO_SPACING },
|
|
472
839
|
[77]: { spacing: NO_SPACING },
|
|
473
840
|
[78]: {
|
|
474
|
-
isNonNesting: true,
|
|
475
841
|
excludesTextNodes: true,
|
|
476
842
|
spacing: NO_SPACING
|
|
477
843
|
},
|
|
@@ -643,7 +1009,10 @@ function buildTagOverrideHandlers(overrides) {
|
|
|
643
1009
|
const targetId = TagIdMap[override];
|
|
644
1010
|
if (targetId !== void 0) {
|
|
645
1011
|
const baseHandler = tagHandlers[targetId];
|
|
646
|
-
if (baseHandler) result.set(tagName, {
|
|
1012
|
+
if (baseHandler) result.set(tagName, {
|
|
1013
|
+
...baseHandler,
|
|
1014
|
+
aliasTagId: targetId
|
|
1015
|
+
});
|
|
647
1016
|
}
|
|
648
1017
|
} else {
|
|
649
1018
|
const baseId = TagIdMap[tagName];
|
|
@@ -657,6 +1026,7 @@ function buildTagOverrideHandlers(overrides) {
|
|
|
657
1026
|
if (override.exit !== void 0) {
|
|
658
1027
|
const exitStr = override.exit;
|
|
659
1028
|
handler.exit = () => exitStr;
|
|
1029
|
+
handler.literalExit = true;
|
|
660
1030
|
}
|
|
661
1031
|
if (override.spacing !== void 0) handler.spacing = override.spacing;
|
|
662
1032
|
if (override.isInline !== void 0) handler.isInline = override.isInline;
|
|
@@ -667,303 +1037,6 @@ function buildTagOverrideHandlers(overrides) {
|
|
|
667
1037
|
}
|
|
668
1038
|
return result;
|
|
669
1039
|
}
|
|
670
|
-
const HTML_ENTITIES = {
|
|
671
|
-
"á": "á",
|
|
672
|
-
"Á": "Á",
|
|
673
|
-
"â": "â",
|
|
674
|
-
"Â": "Â",
|
|
675
|
-
"´": "´",
|
|
676
|
-
"æ": "æ",
|
|
677
|
-
"Æ": "Æ",
|
|
678
|
-
"à": "à",
|
|
679
|
-
"À": "À",
|
|
680
|
-
"ℵ": "ℵ",
|
|
681
|
-
"α": "α",
|
|
682
|
-
"Α": "Α",
|
|
683
|
-
"&": "&",
|
|
684
|
-
"∧": "∧",
|
|
685
|
-
"∠": "∠",
|
|
686
|
-
"'": "'",
|
|
687
|
-
"å": "å",
|
|
688
|
-
"Å": "Å",
|
|
689
|
-
"≈": "≈",
|
|
690
|
-
"ã": "ã",
|
|
691
|
-
"Ã": "Ã",
|
|
692
|
-
"ä": "ä",
|
|
693
|
-
"Ä": "Ä",
|
|
694
|
-
"„": "„",
|
|
695
|
-
"β": "β",
|
|
696
|
-
"Β": "Β",
|
|
697
|
-
"¦": "¦",
|
|
698
|
-
"•": "•",
|
|
699
|
-
"∩": "∩",
|
|
700
|
-
"ç": "ç",
|
|
701
|
-
"Ç": "Ç",
|
|
702
|
-
"¸": "¸",
|
|
703
|
-
"¢": "¢",
|
|
704
|
-
"χ": "χ",
|
|
705
|
-
"Χ": "Χ",
|
|
706
|
-
"ˆ": "ˆ",
|
|
707
|
-
"♣": "♣",
|
|
708
|
-
"≅": "≅",
|
|
709
|
-
"©": "©",
|
|
710
|
-
"↵": "↵",
|
|
711
|
-
"∪": "∪",
|
|
712
|
-
"¤": "¤",
|
|
713
|
-
"†": "†",
|
|
714
|
-
"‡": "‡",
|
|
715
|
-
"↓": "↓",
|
|
716
|
-
"⇓": "⇓",
|
|
717
|
-
"°": "°",
|
|
718
|
-
"δ": "δ",
|
|
719
|
-
"Δ": "Δ",
|
|
720
|
-
"♦": "♦",
|
|
721
|
-
"÷": "÷",
|
|
722
|
-
"é": "é",
|
|
723
|
-
"É": "É",
|
|
724
|
-
"ê": "ê",
|
|
725
|
-
"Ê": "Ê",
|
|
726
|
-
"è": "è",
|
|
727
|
-
"È": "È",
|
|
728
|
-
"∅": "∅",
|
|
729
|
-
"ε": "ε",
|
|
730
|
-
"Ε": "Ε",
|
|
731
|
-
"≡": "≡",
|
|
732
|
-
"η": "η",
|
|
733
|
-
"Η": "Η",
|
|
734
|
-
"ð": "ð",
|
|
735
|
-
"Ð": "Ð",
|
|
736
|
-
"ë": "ë",
|
|
737
|
-
"Ë": "Ë",
|
|
738
|
-
"€": "€",
|
|
739
|
-
"∃": "∃",
|
|
740
|
-
"ƒ": "ƒ",
|
|
741
|
-
"∀": "∀",
|
|
742
|
-
"½": "½",
|
|
743
|
-
"¼": "¼",
|
|
744
|
-
"¾": "¾",
|
|
745
|
-
"⁄": "⁄",
|
|
746
|
-
"γ": "γ",
|
|
747
|
-
"Γ": "Γ",
|
|
748
|
-
"≥": "≥",
|
|
749
|
-
">": ">",
|
|
750
|
-
"↔": "↔",
|
|
751
|
-
"⇔": "⇔",
|
|
752
|
-
"♥": "♥",
|
|
753
|
-
"…": "…",
|
|
754
|
-
"í": "í",
|
|
755
|
-
"Í": "Í",
|
|
756
|
-
"î": "î",
|
|
757
|
-
"Î": "Î",
|
|
758
|
-
"¡": "¡",
|
|
759
|
-
"ì": "ì",
|
|
760
|
-
"Ì": "Ì",
|
|
761
|
-
"ℑ": "ℑ",
|
|
762
|
-
"∞": "∞",
|
|
763
|
-
"∫": "∫",
|
|
764
|
-
"ι": "ι",
|
|
765
|
-
"Ι": "Ι",
|
|
766
|
-
"¿": "¿",
|
|
767
|
-
"∈": "∈",
|
|
768
|
-
"ï": "ï",
|
|
769
|
-
"Ï": "Ï",
|
|
770
|
-
"κ": "κ",
|
|
771
|
-
"Κ": "Κ",
|
|
772
|
-
"λ": "λ",
|
|
773
|
-
"Λ": "Λ",
|
|
774
|
-
"⟨": "⟨",
|
|
775
|
-
"«": "«",
|
|
776
|
-
"←": "←",
|
|
777
|
-
"⇐": "⇐",
|
|
778
|
-
"⌈": "⌈",
|
|
779
|
-
"“": "“",
|
|
780
|
-
"≤": "≤",
|
|
781
|
-
"⌊": "⌊",
|
|
782
|
-
"∗": "∗",
|
|
783
|
-
"◊": "◊",
|
|
784
|
-
"‹": "‹",
|
|
785
|
-
"‘": "‘",
|
|
786
|
-
"<": "<",
|
|
787
|
-
"¯": "¯",
|
|
788
|
-
"—": "—",
|
|
789
|
-
"µ": "µ",
|
|
790
|
-
"·": "·",
|
|
791
|
-
"−": "−",
|
|
792
|
-
"μ": "μ",
|
|
793
|
-
"Μ": "Μ",
|
|
794
|
-
"∇": "∇",
|
|
795
|
-
" ": " ",
|
|
796
|
-
"–": "–",
|
|
797
|
-
"≠": "≠",
|
|
798
|
-
"∋": "∋",
|
|
799
|
-
"¬": "¬",
|
|
800
|
-
"∉": "∉",
|
|
801
|
-
"⊄": "⊄",
|
|
802
|
-
"ñ": "ñ",
|
|
803
|
-
"Ñ": "Ñ",
|
|
804
|
-
"ν": "ν",
|
|
805
|
-
"Ν": "Ν",
|
|
806
|
-
"ó": "ó",
|
|
807
|
-
"Ó": "Ó",
|
|
808
|
-
"ô": "ô",
|
|
809
|
-
"Ô": "Ô",
|
|
810
|
-
"œ": "œ",
|
|
811
|
-
"Œ": "Œ",
|
|
812
|
-
"ò": "ò",
|
|
813
|
-
"Ò": "Ò",
|
|
814
|
-
"‾": "‾",
|
|
815
|
-
"ω": "ω",
|
|
816
|
-
"Ω": "Ω",
|
|
817
|
-
"ο": "ο",
|
|
818
|
-
"Ο": "Ο",
|
|
819
|
-
"⊕": "⊕",
|
|
820
|
-
"∨": "∨",
|
|
821
|
-
"ª": "ª",
|
|
822
|
-
"º": "º",
|
|
823
|
-
"ø": "ø",
|
|
824
|
-
"Ø": "Ø",
|
|
825
|
-
"õ": "õ",
|
|
826
|
-
"Õ": "Õ",
|
|
827
|
-
"⊗": "⊗",
|
|
828
|
-
"ö": "ö",
|
|
829
|
-
"Ö": "Ö",
|
|
830
|
-
"¶": "¶",
|
|
831
|
-
"∂": "∂",
|
|
832
|
-
"‰": "‰",
|
|
833
|
-
"⊥": "⊥",
|
|
834
|
-
"φ": "φ",
|
|
835
|
-
"Φ": "Φ",
|
|
836
|
-
"π": "π",
|
|
837
|
-
"Π": "Π",
|
|
838
|
-
"ϖ": "ϖ",
|
|
839
|
-
"±": "±",
|
|
840
|
-
"£": "£",
|
|
841
|
-
"′": "′",
|
|
842
|
-
"″": "″",
|
|
843
|
-
"∏": "∏",
|
|
844
|
-
"∝": "∝",
|
|
845
|
-
"ψ": "ψ",
|
|
846
|
-
"Ψ": "Ψ",
|
|
847
|
-
""": "\"",
|
|
848
|
-
"√": "√",
|
|
849
|
-
"⟩": "⟩",
|
|
850
|
-
"»": "»",
|
|
851
|
-
"→": "→",
|
|
852
|
-
"⇒": "⇒",
|
|
853
|
-
"⌉": "⌉",
|
|
854
|
-
"”": "”",
|
|
855
|
-
"ℜ": "ℜ",
|
|
856
|
-
"®": "®",
|
|
857
|
-
"⌋": "⌋",
|
|
858
|
-
"ρ": "ρ",
|
|
859
|
-
"Ρ": "Ρ",
|
|
860
|
-
"›": "›",
|
|
861
|
-
"’": "’",
|
|
862
|
-
"‚": "‚",
|
|
863
|
-
"š": "š",
|
|
864
|
-
"Š": "Š",
|
|
865
|
-
"⋅": "⋅",
|
|
866
|
-
"§": "§",
|
|
867
|
-
"σ": "σ",
|
|
868
|
-
"Σ": "Σ",
|
|
869
|
-
"ς": "ς",
|
|
870
|
-
"∼": "∼",
|
|
871
|
-
"♠": "♠",
|
|
872
|
-
"⊂": "⊂",
|
|
873
|
-
"⊆": "⊆",
|
|
874
|
-
"∑": "∑",
|
|
875
|
-
"⊃": "⊃",
|
|
876
|
-
"¹": "¹",
|
|
877
|
-
"²": "²",
|
|
878
|
-
"³": "³",
|
|
879
|
-
"⊇": "⊇",
|
|
880
|
-
"ß": "ß",
|
|
881
|
-
"τ": "τ",
|
|
882
|
-
"Τ": "Τ",
|
|
883
|
-
"∴": "∴",
|
|
884
|
-
"θ": "θ",
|
|
885
|
-
"Θ": "Θ",
|
|
886
|
-
"ϑ": "ϑ",
|
|
887
|
-
"þ": "þ",
|
|
888
|
-
"Þ": "Þ",
|
|
889
|
-
"˜": "˜",
|
|
890
|
-
"×": "×",
|
|
891
|
-
"™": "™",
|
|
892
|
-
"ú": "ú",
|
|
893
|
-
"Ú": "Ú",
|
|
894
|
-
"↑": "↑",
|
|
895
|
-
"⇑": "⇑",
|
|
896
|
-
"û": "û",
|
|
897
|
-
"Û": "Û",
|
|
898
|
-
"ù": "ù",
|
|
899
|
-
"Ù": "Ù",
|
|
900
|
-
"¨": "¨",
|
|
901
|
-
"ϒ": "ϒ",
|
|
902
|
-
"υ": "υ",
|
|
903
|
-
"Υ": "Υ",
|
|
904
|
-
"ü": "ü",
|
|
905
|
-
"Ü": "Ü",
|
|
906
|
-
"℘": "℘",
|
|
907
|
-
"ξ": "ξ",
|
|
908
|
-
"Ξ": "Ξ",
|
|
909
|
-
"ý": "ý",
|
|
910
|
-
"Ý": "Ý",
|
|
911
|
-
"¥": "¥",
|
|
912
|
-
"ÿ": "ÿ",
|
|
913
|
-
"Ÿ": "Ÿ",
|
|
914
|
-
"ζ": "ζ",
|
|
915
|
-
"Ζ": "Ζ"
|
|
916
|
-
};
|
|
917
|
-
function decodeHTMLEntities(text) {
|
|
918
|
-
let result = "";
|
|
919
|
-
let i = 0;
|
|
920
|
-
const len = text.length;
|
|
921
|
-
while (i < len) {
|
|
922
|
-
if (text.charCodeAt(i) === 38) if (i + 2 < len && text.charCodeAt(i + 1) === 35) {
|
|
923
|
-
const start = i;
|
|
924
|
-
i += 2;
|
|
925
|
-
const isHex = text.charCodeAt(i) === 120 || text.charCodeAt(i) === 88;
|
|
926
|
-
if (isHex) i++;
|
|
927
|
-
const numStart = i;
|
|
928
|
-
const maxDigits = i + (isHex ? 7 : 8);
|
|
929
|
-
while (i < len && i < maxDigits && text.charCodeAt(i) !== 59) i++;
|
|
930
|
-
if (i < len && text.charCodeAt(i) === 59) {
|
|
931
|
-
const codePoint = Number.parseInt(text.substring(numStart, i), isHex ? 16 : 10);
|
|
932
|
-
if (codePoint >= 0 && codePoint <= 1114111 && !Number.isNaN(codePoint)) {
|
|
933
|
-
result += String.fromCodePoint(codePoint);
|
|
934
|
-
i++;
|
|
935
|
-
continue;
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
i = start;
|
|
939
|
-
} else {
|
|
940
|
-
const maxEnd = i + 33 < len ? i + 33 : len;
|
|
941
|
-
let j = i + 1;
|
|
942
|
-
while (j < maxEnd && text.charCodeAt(j) !== 59) j++;
|
|
943
|
-
if (j < maxEnd && text.charCodeAt(j) === 59) {
|
|
944
|
-
const replacement = HTML_ENTITIES[text.substring(i, j + 1)];
|
|
945
|
-
if (replacement !== void 0) {
|
|
946
|
-
result += replacement;
|
|
947
|
-
i = j + 1;
|
|
948
|
-
continue;
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
result += text[i];
|
|
953
|
-
i++;
|
|
954
|
-
}
|
|
955
|
-
return result;
|
|
956
|
-
}
|
|
957
|
-
function traverseUpToFirstBlockNode(node) {
|
|
958
|
-
let firstBlockParent = node;
|
|
959
|
-
const parentsToIncrement = [firstBlockParent];
|
|
960
|
-
while (firstBlockParent.tagHandler?.isInline) {
|
|
961
|
-
if (!firstBlockParent.parent) break;
|
|
962
|
-
firstBlockParent = firstBlockParent.parent;
|
|
963
|
-
parentsToIncrement.push(firstBlockParent);
|
|
964
|
-
}
|
|
965
|
-
return parentsToIncrement;
|
|
966
|
-
}
|
|
967
1040
|
const LT_CHAR = 60;
|
|
968
1041
|
const GT_CHAR = 62;
|
|
969
1042
|
const SLASH_CHAR = 47;
|
|
@@ -977,12 +1050,24 @@ const DASH_CHAR = 45;
|
|
|
977
1050
|
const SPACE_CHAR = 32;
|
|
978
1051
|
const TAB_CHAR = 9;
|
|
979
1052
|
const NEWLINE_CHAR = 10;
|
|
1053
|
+
const FORM_FEED_CHAR = 12;
|
|
980
1054
|
const CARRIAGE_RETURN_CHAR = 13;
|
|
981
1055
|
const BACKTICK_CHAR = 96;
|
|
982
1056
|
const PIPE_CHAR = 124;
|
|
983
1057
|
const OPEN_BRACKET_CHAR = 91;
|
|
984
1058
|
const CLOSE_BRACKET_CHAR = 93;
|
|
985
|
-
const
|
|
1059
|
+
const SCRIPT_DATA = 0;
|
|
1060
|
+
const SCRIPT_DATA_ESCAPED = 1;
|
|
1061
|
+
const SCRIPT_DATA_ESCAPED_DASH = 2;
|
|
1062
|
+
const SCRIPT_DATA_ESCAPED_DASH_DASH = 3;
|
|
1063
|
+
const SCRIPT_DATA_DOUBLE_ESCAPED = 4;
|
|
1064
|
+
const SCRIPT_DATA_DOUBLE_ESCAPED_DASH = 5;
|
|
1065
|
+
const SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH = 6;
|
|
1066
|
+
const SCRIPT_SEQUENCE_NO_MATCH = -1;
|
|
1067
|
+
const SCRIPT_SEQUENCE_INCOMPLETE = -2;
|
|
1068
|
+
const SCRIPT_SCAN_COMPLETE = -1;
|
|
1069
|
+
const MAX_ELEMENT_DEPTH = 512;
|
|
1070
|
+
const HEAD_CONTENT_TAGS = /* @__PURE__ */ new Set([
|
|
986
1071
|
4,
|
|
987
1072
|
5,
|
|
988
1073
|
54,
|
|
@@ -993,7 +1078,7 @@ const HEAD_CONTENT_TAGS = new Set([
|
|
|
993
1078
|
78
|
|
994
1079
|
]);
|
|
995
1080
|
const CLOSES_P = (() => {
|
|
996
|
-
const t = new Uint8Array(
|
|
1081
|
+
const t = /* @__PURE__ */ new Uint8Array(110);
|
|
997
1082
|
for (const id of [
|
|
998
1083
|
36,
|
|
999
1084
|
35,
|
|
@@ -1041,11 +1126,14 @@ const NEEDS_IMPLIED_END_RECOVERY = (() => {
|
|
|
1041
1126
|
30,
|
|
1042
1127
|
29,
|
|
1043
1128
|
38,
|
|
1044
|
-
39
|
|
1129
|
+
39,
|
|
1130
|
+
67,
|
|
1131
|
+
109,
|
|
1132
|
+
65
|
|
1045
1133
|
]) t[id] = 1;
|
|
1046
1134
|
return t;
|
|
1047
1135
|
})();
|
|
1048
|
-
const P_SCOPE_BOUNDARY = new Set([
|
|
1136
|
+
const P_SCOPE_BOUNDARY = /* @__PURE__ */ new Set([
|
|
1049
1137
|
43,
|
|
1050
1138
|
32,
|
|
1051
1139
|
31,
|
|
@@ -1058,7 +1146,7 @@ const P_SCOPE_BOUNDARY = new Set([
|
|
|
1058
1146
|
101,
|
|
1059
1147
|
25
|
|
1060
1148
|
]);
|
|
1061
|
-
const LI_SCOPE_BOUNDARY = new Set([
|
|
1149
|
+
const LI_SCOPE_BOUNDARY = /* @__PURE__ */ new Set([
|
|
1062
1150
|
24,
|
|
1063
1151
|
33,
|
|
1064
1152
|
28,
|
|
@@ -1068,7 +1156,7 @@ const LI_SCOPE_BOUNDARY = new Set([
|
|
|
1068
1156
|
78,
|
|
1069
1157
|
0
|
|
1070
1158
|
]);
|
|
1071
|
-
const DL_SCOPE_BOUNDARY = new Set([
|
|
1159
|
+
const DL_SCOPE_BOUNDARY = /* @__PURE__ */ new Set([
|
|
1072
1160
|
101,
|
|
1073
1161
|
24,
|
|
1074
1162
|
33,
|
|
@@ -1080,7 +1168,7 @@ const DL_SCOPE_BOUNDARY = new Set([
|
|
|
1080
1168
|
78,
|
|
1081
1169
|
0
|
|
1082
1170
|
]);
|
|
1083
|
-
const CELL_SCOPE_BOUNDARY = new Set([
|
|
1171
|
+
const CELL_SCOPE_BOUNDARY = /* @__PURE__ */ new Set([
|
|
1084
1172
|
30,
|
|
1085
1173
|
29,
|
|
1086
1174
|
38,
|
|
@@ -1090,7 +1178,7 @@ const CELL_SCOPE_BOUNDARY = new Set([
|
|
|
1090
1178
|
78,
|
|
1091
1179
|
0
|
|
1092
1180
|
]);
|
|
1093
|
-
const A_SCOPE_BOUNDARY = new Set([
|
|
1181
|
+
const A_SCOPE_BOUNDARY = /* @__PURE__ */ new Set([
|
|
1094
1182
|
35,
|
|
1095
1183
|
36,
|
|
1096
1184
|
25,
|
|
@@ -1125,7 +1213,7 @@ const A_SCOPE_BOUNDARY = new Set([
|
|
|
1125
1213
|
78,
|
|
1126
1214
|
0
|
|
1127
1215
|
]);
|
|
1128
|
-
const HEADINGS = new Set([
|
|
1216
|
+
const HEADINGS = /* @__PURE__ */ new Set([
|
|
1129
1217
|
7,
|
|
1130
1218
|
8,
|
|
1131
1219
|
9,
|
|
@@ -1133,17 +1221,17 @@ const HEADINGS = new Set([
|
|
|
1133
1221
|
11,
|
|
1134
1222
|
12
|
|
1135
1223
|
]);
|
|
1136
|
-
const SINGLE_P = new Set([35]);
|
|
1137
|
-
const SINGLE_LI = new Set([25]);
|
|
1138
|
-
const SINGLE_A = new Set([26]);
|
|
1139
|
-
const DT_DD = new Set([99, 98]);
|
|
1140
|
-
const TD_TH = new Set([32, 31]);
|
|
1141
|
-
const TR_CELLS = new Set([
|
|
1224
|
+
const SINGLE_P = /* @__PURE__ */ new Set([35]);
|
|
1225
|
+
const SINGLE_LI = /* @__PURE__ */ new Set([25]);
|
|
1226
|
+
const SINGLE_A = /* @__PURE__ */ new Set([26]);
|
|
1227
|
+
const DT_DD = /* @__PURE__ */ new Set([99, 98]);
|
|
1228
|
+
const TD_TH = /* @__PURE__ */ new Set([32, 31]);
|
|
1229
|
+
const TR_CELLS = /* @__PURE__ */ new Set([
|
|
1142
1230
|
32,
|
|
1143
1231
|
31,
|
|
1144
1232
|
30
|
|
1145
1233
|
]);
|
|
1146
|
-
const SECTION_CELLS = new Set([
|
|
1234
|
+
const SECTION_CELLS = /* @__PURE__ */ new Set([
|
|
1147
1235
|
32,
|
|
1148
1236
|
31,
|
|
1149
1237
|
30,
|
|
@@ -1177,44 +1265,212 @@ function closeTableContext(state, closeable, handleEvent) {
|
|
|
1177
1265
|
closeNode(state.currentNode, state, handleEvent);
|
|
1178
1266
|
}
|
|
1179
1267
|
}
|
|
1268
|
+
function closeSelectTo(state, targetId, handleEvent) {
|
|
1269
|
+
let target;
|
|
1270
|
+
for (let node = state.currentNode; node; node = node.parent) {
|
|
1271
|
+
if (node.tagId === targetId) {
|
|
1272
|
+
target = node;
|
|
1273
|
+
break;
|
|
1274
|
+
}
|
|
1275
|
+
if (node.tagId === 65 || node.tagId === 78) break;
|
|
1276
|
+
}
|
|
1277
|
+
if (!target) return false;
|
|
1278
|
+
while (state.currentNode && state.currentNode !== target) closeNode(state.currentNode, state, handleEvent);
|
|
1279
|
+
closeNode(target, state, handleEvent);
|
|
1280
|
+
return true;
|
|
1281
|
+
}
|
|
1180
1282
|
function finalizeParse(leftover, state, handleEvent) {
|
|
1181
|
-
if (
|
|
1283
|
+
if (state.currentNode && isScriptElement(state.currentNode)) {
|
|
1284
|
+
pushScriptTextChunk(state, leftover);
|
|
1285
|
+
const scriptText = takeScriptText(state);
|
|
1286
|
+
if (scriptText) processTextBuffer(scriptText, state, handleEvent);
|
|
1287
|
+
} else if (leftover.length > 0 && leftover.charCodeAt(0) !== LT_CHAR) processTextBuffer(leftover, state, handleEvent);
|
|
1182
1288
|
while (state.currentNode) closeNode(state.currentNode, state, handleEvent);
|
|
1183
1289
|
}
|
|
1184
1290
|
const EMPTY_ATTRIBUTES = Object.freeze({});
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1291
|
+
var ParsedElementNode = class {
|
|
1292
|
+
type = 1;
|
|
1293
|
+
name;
|
|
1294
|
+
attributes;
|
|
1295
|
+
parent;
|
|
1296
|
+
depth;
|
|
1297
|
+
index;
|
|
1298
|
+
tagId;
|
|
1299
|
+
tagHandler;
|
|
1300
|
+
currentWalkIndex;
|
|
1301
|
+
childTextNodeIndex;
|
|
1302
|
+
containsWhitespace;
|
|
1303
|
+
pluginOutput;
|
|
1304
|
+
context;
|
|
1305
|
+
cachedDepthMap;
|
|
1306
|
+
constructor(name, attributes, parent, depth, index, tagId, tagHandler) {
|
|
1307
|
+
this.name = name;
|
|
1308
|
+
this.attributes = attributes;
|
|
1309
|
+
this.parent = parent;
|
|
1310
|
+
this.depth = depth;
|
|
1311
|
+
this.index = index;
|
|
1312
|
+
this.tagId = tagId;
|
|
1313
|
+
this.tagHandler = tagHandler;
|
|
1314
|
+
}
|
|
1315
|
+
get depthMap() {
|
|
1316
|
+
if (this.cachedDepthMap) return this.cachedDepthMap;
|
|
1317
|
+
const depthMap = /* @__PURE__ */ new Uint8Array(110);
|
|
1318
|
+
if (this.tagId >= 0 && this.tagId < 110) depthMap[this.tagId] = 1;
|
|
1319
|
+
let node = this.parent;
|
|
1320
|
+
while (node) {
|
|
1321
|
+
const tagId = node.tagId;
|
|
1322
|
+
if (tagId !== void 0 && tagId >= 0 && tagId < 110) depthMap[tagId] = (depthMap[tagId] || 0) + 1;
|
|
1323
|
+
node = node.parent;
|
|
1324
|
+
}
|
|
1325
|
+
this.cachedDepthMap = depthMap;
|
|
1326
|
+
return depthMap;
|
|
1327
|
+
}
|
|
1328
|
+
};
|
|
1188
1329
|
function isWhitespace(charCode) {
|
|
1189
|
-
return charCode === SPACE_CHAR || charCode === TAB_CHAR || charCode === NEWLINE_CHAR || charCode === CARRIAGE_RETURN_CHAR;
|
|
1330
|
+
return charCode === SPACE_CHAR || charCode === TAB_CHAR || charCode === NEWLINE_CHAR || charCode === FORM_FEED_CHAR || charCode === CARRIAGE_RETURN_CHAR;
|
|
1331
|
+
}
|
|
1332
|
+
function scriptSequenceEnd(html, nameStart) {
|
|
1333
|
+
const name = "script";
|
|
1334
|
+
for (let offset = 0; offset < 6; offset++) {
|
|
1335
|
+
const index = nameStart + offset;
|
|
1336
|
+
if (index >= html.length) return SCRIPT_SEQUENCE_INCOMPLETE;
|
|
1337
|
+
if ((html.charCodeAt(index) | 32) !== name.charCodeAt(offset)) return SCRIPT_SEQUENCE_NO_MATCH;
|
|
1338
|
+
}
|
|
1339
|
+
const delimiterIndex = nameStart + 6;
|
|
1340
|
+
if (delimiterIndex >= html.length) return SCRIPT_SEQUENCE_INCOMPLETE;
|
|
1341
|
+
const delimiter = html.charCodeAt(delimiterIndex);
|
|
1342
|
+
return delimiter === GT_CHAR || delimiter === SLASH_CHAR || isWhitespace(delimiter) ? delimiterIndex + 1 : SCRIPT_SEQUENCE_NO_MATCH;
|
|
1343
|
+
}
|
|
1344
|
+
function isScriptElement(node) {
|
|
1345
|
+
return node.tagId === 52 && node.name === "script";
|
|
1346
|
+
}
|
|
1347
|
+
function scriptScanResult(parseState, scriptState, result) {
|
|
1348
|
+
parseState.scriptDataState = scriptState;
|
|
1349
|
+
return result;
|
|
1350
|
+
}
|
|
1351
|
+
function findScriptEndTag(html, start, parseState) {
|
|
1352
|
+
let state = parseState.scriptDataState ?? SCRIPT_DATA;
|
|
1353
|
+
let i = start;
|
|
1354
|
+
while (i < html.length) {
|
|
1355
|
+
const charCode = html.charCodeAt(i);
|
|
1356
|
+
if (charCode === LT_CHAR) {
|
|
1357
|
+
if (i + 1 === html.length) return scriptScanResult(parseState, state, -i - 2);
|
|
1358
|
+
const next = html.charCodeAt(i + 1);
|
|
1359
|
+
if (state === SCRIPT_DATA) {
|
|
1360
|
+
if (next === SLASH_CHAR) {
|
|
1361
|
+
const sequenceEnd = scriptSequenceEnd(html, i + 2);
|
|
1362
|
+
if (sequenceEnd >= 0) return scriptScanResult(parseState, state, i);
|
|
1363
|
+
if (sequenceEnd === SCRIPT_SEQUENCE_INCOMPLETE) return scriptScanResult(parseState, state, -i - 2);
|
|
1364
|
+
} else if (next === EXCLAMATION_CHAR) {
|
|
1365
|
+
const marker = "<!--";
|
|
1366
|
+
const available = Math.min(html.length - i, 4);
|
|
1367
|
+
if (html.startsWith(marker.substring(0, available), i)) {
|
|
1368
|
+
if (available < 4) return scriptScanResult(parseState, state, -i - 2);
|
|
1369
|
+
state = SCRIPT_DATA_ESCAPED_DASH_DASH;
|
|
1370
|
+
i += 4;
|
|
1371
|
+
continue;
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
} else {
|
|
1375
|
+
const escaped = state < SCRIPT_DATA_DOUBLE_ESCAPED;
|
|
1376
|
+
state = escaped ? SCRIPT_DATA_ESCAPED : SCRIPT_DATA_DOUBLE_ESCAPED;
|
|
1377
|
+
const isEndTag = next === SLASH_CHAR;
|
|
1378
|
+
if (isEndTag || escaped) {
|
|
1379
|
+
const sequenceEnd = scriptSequenceEnd(html, i + (isEndTag ? 2 : 1));
|
|
1380
|
+
if (sequenceEnd >= 0) {
|
|
1381
|
+
if (isEndTag) {
|
|
1382
|
+
if (escaped) return scriptScanResult(parseState, state, i);
|
|
1383
|
+
state = SCRIPT_DATA_ESCAPED;
|
|
1384
|
+
} else state = SCRIPT_DATA_DOUBLE_ESCAPED;
|
|
1385
|
+
i = sequenceEnd;
|
|
1386
|
+
continue;
|
|
1387
|
+
}
|
|
1388
|
+
if (sequenceEnd === SCRIPT_SEQUENCE_INCOMPLETE) return scriptScanResult(parseState, state, -i - 2);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
} else if (charCode === DASH_CHAR) {
|
|
1392
|
+
if (state === SCRIPT_DATA_ESCAPED || state === SCRIPT_DATA_ESCAPED_DASH) state++;
|
|
1393
|
+
else if (state === SCRIPT_DATA_DOUBLE_ESCAPED || state === SCRIPT_DATA_DOUBLE_ESCAPED_DASH) state++;
|
|
1394
|
+
} else if (state === SCRIPT_DATA_ESCAPED_DASH || state === SCRIPT_DATA_ESCAPED_DASH_DASH) state = charCode === GT_CHAR && state === SCRIPT_DATA_ESCAPED_DASH_DASH ? SCRIPT_DATA : SCRIPT_DATA_ESCAPED;
|
|
1395
|
+
else if (state === SCRIPT_DATA_DOUBLE_ESCAPED_DASH || state === SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH) state = charCode === GT_CHAR && state === SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH ? SCRIPT_DATA : SCRIPT_DATA_DOUBLE_ESCAPED;
|
|
1396
|
+
i++;
|
|
1397
|
+
}
|
|
1398
|
+
return scriptScanResult(parseState, state, SCRIPT_SCAN_COMPLETE);
|
|
1399
|
+
}
|
|
1400
|
+
function pushScriptTextChunk(state, text) {
|
|
1401
|
+
if (!text) return;
|
|
1402
|
+
(state.scriptTextChunks ??= []).push(text);
|
|
1403
|
+
state.textBufferContainsNonWhitespace = true;
|
|
1404
|
+
state.lastCharWasWhitespace = false;
|
|
1405
|
+
state.justClosedTag = false;
|
|
1406
|
+
}
|
|
1407
|
+
function scanScriptChunk(html, start, state) {
|
|
1408
|
+
const result = findScriptEndTag(html, start, state);
|
|
1409
|
+
if (result === SCRIPT_SCAN_COMPLETE) pushScriptTextChunk(state, html.substring(start));
|
|
1410
|
+
else if (result <= SCRIPT_SEQUENCE_INCOMPLETE) pushScriptTextChunk(state, html.substring(start, -result - 2));
|
|
1411
|
+
else pushScriptTextChunk(state, html.substring(start, result));
|
|
1412
|
+
return result;
|
|
1413
|
+
}
|
|
1414
|
+
function takeScriptText(state) {
|
|
1415
|
+
const chunks = state.scriptTextChunks;
|
|
1416
|
+
const text = chunks?.length ? chunks.length === 1 ? chunks[0] : chunks.join("") : "";
|
|
1417
|
+
if (chunks) chunks.length = 0;
|
|
1418
|
+
state.scriptDataState = SCRIPT_DATA;
|
|
1419
|
+
return text;
|
|
1420
|
+
}
|
|
1421
|
+
function normalizeTagName(tagName) {
|
|
1422
|
+
for (let i = 0; i < tagName.length; i++) {
|
|
1423
|
+
const code = tagName.charCodeAt(i);
|
|
1424
|
+
if (code >= 65 && code <= 90) return tagName.toLowerCase();
|
|
1425
|
+
}
|
|
1426
|
+
return tagName;
|
|
1427
|
+
}
|
|
1428
|
+
function effectiveTagId(tagName, fallbackTagId, state) {
|
|
1429
|
+
return state.tagOverrideHandlers?.get(tagName)?.aliasTagId ?? fallbackTagId;
|
|
1430
|
+
}
|
|
1431
|
+
function matchesClosingTag(node, tagName, tagId, closingIsAlias) {
|
|
1432
|
+
if (node.tagId !== tagId) return false;
|
|
1433
|
+
if (tagId === -1) return node.name === tagName;
|
|
1434
|
+
const nodeIsAlias = node.tagHandler?.aliasTagId !== void 0;
|
|
1435
|
+
return node.name === tagName || !nodeIsAlias && !closingIsAlias;
|
|
1190
1436
|
}
|
|
1191
1437
|
function parseHtml(html, options = {}) {
|
|
1192
1438
|
const events = [];
|
|
1439
|
+
const state = {
|
|
1440
|
+
depthMap: /* @__PURE__ */ new Uint8Array(110),
|
|
1441
|
+
depth: 0,
|
|
1442
|
+
resolvedPlugins: options.resolvedPlugins || []
|
|
1443
|
+
};
|
|
1444
|
+
let remainingHtml = parseHtmlInternal(html, state, (event) => {
|
|
1445
|
+
events.push(event);
|
|
1446
|
+
});
|
|
1447
|
+
if (state.scriptTextChunks?.length) remainingHtml = `${takeScriptText(state)}${remainingHtml}`;
|
|
1193
1448
|
return {
|
|
1194
1449
|
events,
|
|
1195
|
-
remainingHtml
|
|
1196
|
-
depthMap: new Uint8Array(109),
|
|
1197
|
-
depth: 0,
|
|
1198
|
-
resolvedPlugins: options.resolvedPlugins || []
|
|
1199
|
-
}, (event) => {
|
|
1200
|
-
events.push(event);
|
|
1201
|
-
})
|
|
1450
|
+
remainingHtml
|
|
1202
1451
|
};
|
|
1203
1452
|
}
|
|
1204
1453
|
function parseHtmlStream(html, state, onEvent) {
|
|
1205
1454
|
return parseHtmlInternal(html, state, onEvent);
|
|
1206
1455
|
}
|
|
1207
1456
|
function parseHtmlInternal(htmlChunk, state, handleEvent) {
|
|
1457
|
+
if (state.depthLimitReached) return "";
|
|
1208
1458
|
let textBuffer = "";
|
|
1209
|
-
state.depthMap ??= new Uint8Array(
|
|
1459
|
+
state.depthMap ??= /* @__PURE__ */ new Uint8Array(110);
|
|
1210
1460
|
state.depth ??= 0;
|
|
1211
1461
|
state.lastCharWasWhitespace ??= true;
|
|
1212
1462
|
state.justClosedTag ??= false;
|
|
1213
1463
|
state.isFirstTextInElement ??= false;
|
|
1214
|
-
state.
|
|
1464
|
+
state.scriptDataState ??= SCRIPT_DATA;
|
|
1215
1465
|
let i = 0;
|
|
1216
1466
|
const chunkLength = htmlChunk.length;
|
|
1217
|
-
|
|
1467
|
+
if (state.currentNode && isScriptElement(state.currentNode)) {
|
|
1468
|
+
const scanResult = scanScriptChunk(htmlChunk, i, state);
|
|
1469
|
+
if (scanResult < 0) return scanResult <= SCRIPT_SEQUENCE_INCOMPLETE ? htmlChunk.substring(-scanResult - 2) : "";
|
|
1470
|
+
textBuffer = takeScriptText(state);
|
|
1471
|
+
i = scanResult;
|
|
1472
|
+
}
|
|
1473
|
+
while (i < chunkLength && !state.depthLimitReached) {
|
|
1218
1474
|
const currentCharCode = htmlChunk.charCodeAt(i);
|
|
1219
1475
|
if (currentCharCode !== LT_CHAR) {
|
|
1220
1476
|
if (currentCharCode === AMPERSAND_CHAR) state.hasEncodedHtmlEntity = true;
|
|
@@ -1232,25 +1488,16 @@ function parseHtmlInternal(htmlChunk, state, handleEvent) {
|
|
|
1232
1488
|
else if (currentCharCode === SPACE_CHAR || !state.lastCharWasWhitespace) textBuffer += " ";
|
|
1233
1489
|
state.lastCharWasWhitespace = true;
|
|
1234
1490
|
state.textBufferContainsWhitespace = true;
|
|
1235
|
-
state.lastCharWasBackslash = false;
|
|
1236
1491
|
} else {
|
|
1237
1492
|
state.textBufferContainsNonWhitespace = true;
|
|
1238
1493
|
state.lastCharWasWhitespace = false;
|
|
1239
1494
|
state.justClosedTag = false;
|
|
1240
|
-
if (currentCharCode === PIPE_CHAR && state.depthMap[28]) textBuffer += "\\|";
|
|
1241
|
-
else if (currentCharCode === BACKTICK_CHAR && (state.depthMap[23] || state.depthMap[34])) textBuffer += "\\`";
|
|
1242
|
-
else if (currentCharCode === OPEN_BRACKET_CHAR && state.depthMap[26]) textBuffer += "\\[";
|
|
1243
|
-
else if (currentCharCode === CLOSE_BRACKET_CHAR && state.depthMap[26]) textBuffer += "\\]";
|
|
1244
|
-
else if (currentCharCode === GT_CHAR && state.depthMap[22]) textBuffer += "\\>";
|
|
1495
|
+
if (!state.plainText && currentCharCode === PIPE_CHAR && state.depthMap[28]) textBuffer += "\\|";
|
|
1496
|
+
else if (!state.plainText && currentCharCode === BACKTICK_CHAR && (state.depthMap[23] || state.depthMap[34])) textBuffer += "\\`";
|
|
1497
|
+
else if (!state.plainText && currentCharCode === OPEN_BRACKET_CHAR && state.depthMap[26]) textBuffer += "\\[";
|
|
1498
|
+
else if (!state.plainText && currentCharCode === CLOSE_BRACKET_CHAR && state.depthMap[26]) textBuffer += "\\]";
|
|
1499
|
+
else if (!state.plainText && currentCharCode === GT_CHAR && state.depthMap[22]) textBuffer += "\\>";
|
|
1245
1500
|
else textBuffer += htmlChunk[i];
|
|
1246
|
-
if (state.inRawTextQuoteAware) {
|
|
1247
|
-
if (!state.lastCharWasBackslash) {
|
|
1248
|
-
if (currentCharCode === APOS_CHAR && !state.inDoubleQuote && !state.inBacktick) state.inSingleQuote = !state.inSingleQuote;
|
|
1249
|
-
else if (currentCharCode === QUOTE_CHAR && !state.inSingleQuote && !state.inBacktick) state.inDoubleQuote = !state.inDoubleQuote;
|
|
1250
|
-
else if (currentCharCode === BACKTICK_CHAR && !state.inSingleQuote && !state.inDoubleQuote) state.inBacktick = !state.inBacktick;
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
state.lastCharWasBackslash = currentCharCode === BACKSLASH_CHAR && !state.lastCharWasBackslash;
|
|
1254
1501
|
}
|
|
1255
1502
|
i++;
|
|
1256
1503
|
continue;
|
|
@@ -1293,18 +1540,16 @@ function parseHtmlInternal(htmlChunk, state, handleEvent) {
|
|
|
1293
1540
|
}
|
|
1294
1541
|
} else if (nextCharCode === SLASH_CHAR) {
|
|
1295
1542
|
if (state.currentNode?.tagHandler?.isNonNesting) {
|
|
1296
|
-
if (state.inRawTextQuoteAware && (state.inSingleQuote || state.inDoubleQuote || state.inBacktick)) {
|
|
1297
|
-
textBuffer += htmlChunk[i];
|
|
1298
|
-
i++;
|
|
1299
|
-
continue;
|
|
1300
|
-
}
|
|
1301
1543
|
let peekEnd = i + 2;
|
|
1302
1544
|
while (peekEnd < chunkLength) {
|
|
1303
1545
|
const c = htmlChunk.charCodeAt(peekEnd);
|
|
1304
|
-
if (c === GT_CHAR || isWhitespace(c)) break;
|
|
1546
|
+
if (c === GT_CHAR || c === SLASH_CHAR || isWhitespace(c)) break;
|
|
1305
1547
|
peekEnd++;
|
|
1306
1548
|
}
|
|
1307
|
-
|
|
1549
|
+
const peekTagName = normalizeTagName(htmlChunk.substring(i + 2, peekEnd));
|
|
1550
|
+
const peekHandler = state.tagOverrideHandlers?.get(peekTagName);
|
|
1551
|
+
const peekTagId = effectiveTagId(peekTagName, TagIdMap[peekTagName] ?? -1, state);
|
|
1552
|
+
if (!matchesClosingTag(state.currentNode, peekTagName, peekTagId, peekHandler?.aliasTagId !== void 0)) {
|
|
1308
1553
|
textBuffer += htmlChunk[i++];
|
|
1309
1554
|
continue;
|
|
1310
1555
|
}
|
|
@@ -1335,8 +1580,11 @@ function parseHtmlInternal(htmlChunk, state, handleEvent) {
|
|
|
1335
1580
|
textBuffer += htmlChunk.substring(i);
|
|
1336
1581
|
break;
|
|
1337
1582
|
}
|
|
1338
|
-
const
|
|
1339
|
-
|
|
1583
|
+
const rawTagName = htmlChunk.substring(tagNameStart, tagNameEnd);
|
|
1584
|
+
let tagName = rawTagName;
|
|
1585
|
+
if (typeof TagIdMap[tagName] !== "number") tagName = normalizeTagName(rawTagName);
|
|
1586
|
+
const mappedTagId = TagIdMap[tagName];
|
|
1587
|
+
const tagId = effectiveTagId(tagName, typeof mappedTagId === "number" ? mappedTagId : -1, state);
|
|
1340
1588
|
i2 = tagNameEnd;
|
|
1341
1589
|
if (state.currentNode?.tagHandler?.isNonNesting) {
|
|
1342
1590
|
textBuffer += htmlChunk[i++];
|
|
@@ -1351,20 +1599,28 @@ function parseHtmlInternal(htmlChunk, state, handleEvent) {
|
|
|
1351
1599
|
textBuffer = "";
|
|
1352
1600
|
}
|
|
1353
1601
|
const result = processOpeningTag(tagName, tagId, htmlChunk, i2, state, handleEvent);
|
|
1354
|
-
if (result.skip)
|
|
1602
|
+
if (result.skip) i = result.newPosition;
|
|
1355
1603
|
else if (result.complete) {
|
|
1356
1604
|
i = result.newPosition;
|
|
1357
|
-
if (!result.selfClosing)
|
|
1605
|
+
if (!result.selfClosing) {
|
|
1606
|
+
state.isFirstTextInElement = true;
|
|
1607
|
+
if (tagId === 52 && tagName === "script") {
|
|
1608
|
+
const scanResult = scanScriptChunk(htmlChunk, i, state);
|
|
1609
|
+
if (scanResult < 0) {
|
|
1610
|
+
textBuffer = scanResult <= SCRIPT_SEQUENCE_INCOMPLETE ? htmlChunk.substring(-scanResult - 2) : "";
|
|
1611
|
+
break;
|
|
1612
|
+
}
|
|
1613
|
+
textBuffer = takeScriptText(state);
|
|
1614
|
+
i = scanResult;
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1358
1617
|
} else {
|
|
1359
1618
|
textBuffer += result.remainingText;
|
|
1360
1619
|
break;
|
|
1361
1620
|
}
|
|
1362
1621
|
}
|
|
1363
1622
|
}
|
|
1364
|
-
state.
|
|
1365
|
-
state.inDoubleQuote = false;
|
|
1366
|
-
state.inBacktick = false;
|
|
1367
|
-
state.lastCharWasBackslash = false;
|
|
1623
|
+
if (textBuffer.length > 0 && isWhitespace(textBuffer.charCodeAt(0))) state.lastCharWasWhitespace = false;
|
|
1368
1624
|
return textBuffer;
|
|
1369
1625
|
}
|
|
1370
1626
|
function processTextBuffer(textBuffer, state, handleEvent) {
|
|
@@ -1373,7 +1629,6 @@ function processTextBuffer(textBuffer, state, handleEvent) {
|
|
|
1373
1629
|
state.textBufferContainsNonWhitespace = false;
|
|
1374
1630
|
state.textBufferContainsWhitespace = false;
|
|
1375
1631
|
if (!state.currentNode) {
|
|
1376
|
-
if (!containsNonWhitespace) return;
|
|
1377
1632
|
let rootText = textBuffer;
|
|
1378
1633
|
if (rootText.length === 0) return;
|
|
1379
1634
|
if (state.hasEncodedHtmlEntity) {
|
|
@@ -1396,7 +1651,7 @@ function processTextBuffer(textBuffer, state, handleEvent) {
|
|
|
1396
1651
|
state.lastTextNode = rootTextNode;
|
|
1397
1652
|
return;
|
|
1398
1653
|
}
|
|
1399
|
-
const excludesTextNodes = state.currentNode?.tagHandler?.excludesTextNodes;
|
|
1654
|
+
const excludesTextNodes = state.currentNode?.tagHandler?.excludesTextNodes || state.currentNode?.excludedFromMarkdown;
|
|
1400
1655
|
const inPreTag = (state.depthMap[34] || 0) > 0;
|
|
1401
1656
|
if (!inPreTag && !containsNonWhitespace && !state.currentNode.childTextNodeIndex) return;
|
|
1402
1657
|
let text = textBuffer;
|
|
@@ -1432,12 +1687,28 @@ function processClosingTag(htmlChunk, position, state, handleEvent) {
|
|
|
1432
1687
|
let i = position + 2;
|
|
1433
1688
|
const tagNameStart = i;
|
|
1434
1689
|
const chunkLength = htmlChunk.length;
|
|
1690
|
+
let tagNameEnd = -1;
|
|
1691
|
+
let quoteChar = 0;
|
|
1435
1692
|
let foundClose = false;
|
|
1436
1693
|
while (i < chunkLength) {
|
|
1437
|
-
|
|
1694
|
+
const charCode = htmlChunk.charCodeAt(i);
|
|
1695
|
+
if (tagNameEnd !== -1) {
|
|
1696
|
+
if (quoteChar) {
|
|
1697
|
+
if (charCode === quoteChar) quoteChar = 0;
|
|
1698
|
+
i++;
|
|
1699
|
+
continue;
|
|
1700
|
+
}
|
|
1701
|
+
if (charCode === QUOTE_CHAR || charCode === APOS_CHAR) {
|
|
1702
|
+
quoteChar = charCode;
|
|
1703
|
+
i++;
|
|
1704
|
+
continue;
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
if (charCode === GT_CHAR) {
|
|
1438
1708
|
foundClose = true;
|
|
1439
1709
|
break;
|
|
1440
1710
|
}
|
|
1711
|
+
if (tagNameEnd === -1 && (isWhitespace(charCode) || charCode === SLASH_CHAR)) tagNameEnd = i;
|
|
1441
1712
|
i++;
|
|
1442
1713
|
}
|
|
1443
1714
|
if (!foundClose) return {
|
|
@@ -1445,22 +1716,31 @@ function processClosingTag(htmlChunk, position, state, handleEvent) {
|
|
|
1445
1716
|
newPosition: position,
|
|
1446
1717
|
remainingText: htmlChunk.substring(position)
|
|
1447
1718
|
};
|
|
1448
|
-
const
|
|
1449
|
-
|
|
1719
|
+
const rawTagName = htmlChunk.substring(tagNameStart, tagNameEnd === -1 ? i : tagNameEnd);
|
|
1720
|
+
let tagName = rawTagName;
|
|
1721
|
+
if (typeof TagIdMap[tagName] !== "number") tagName = normalizeTagName(rawTagName);
|
|
1722
|
+
const tagHandler = state.tagOverrideHandlers?.get(tagName);
|
|
1723
|
+
const mappedTagId = TagIdMap[tagName];
|
|
1724
|
+
const tagId = effectiveTagId(tagName, typeof mappedTagId === "number" ? mappedTagId : -1, state);
|
|
1725
|
+
const closingIsAlias = tagHandler?.aliasTagId !== void 0;
|
|
1726
|
+
if (state.currentNode?.tagHandler?.isNonNesting && !matchesClosingTag(state.currentNode, tagName, tagId, closingIsAlias)) return {
|
|
1450
1727
|
complete: false,
|
|
1451
1728
|
newPosition: position,
|
|
1452
1729
|
remainingText: htmlChunk.substring(position)
|
|
1453
1730
|
};
|
|
1731
|
+
const stopAtTemplate = tagId !== 78 && (state.depthMap[78] || 0) > 0;
|
|
1454
1732
|
let curr = state.currentNode;
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
curr = curr.parent;
|
|
1460
|
-
match = curr?.tagId !== tagId;
|
|
1733
|
+
while (curr && !matchesClosingTag(curr, tagName, tagId, closingIsAlias)) {
|
|
1734
|
+
if (stopAtTemplate && curr.tagId === 78) {
|
|
1735
|
+
curr = null;
|
|
1736
|
+
break;
|
|
1461
1737
|
}
|
|
1738
|
+
curr = curr.parent;
|
|
1739
|
+
}
|
|
1740
|
+
if (curr) {
|
|
1741
|
+
while (state.currentNode && state.currentNode !== curr) closeNode(state.currentNode, state, handleEvent);
|
|
1742
|
+
closeNode(curr, state, handleEvent);
|
|
1462
1743
|
}
|
|
1463
|
-
if (curr) closeNode(curr, state, handleEvent);
|
|
1464
1744
|
state.justClosedTag = true;
|
|
1465
1745
|
return {
|
|
1466
1746
|
complete: true,
|
|
@@ -1487,14 +1767,8 @@ function closeNode(node, state, handleEvent) {
|
|
|
1487
1767
|
for (const parent of traverseUpToFirstBlockNode(node)) parent.childTextNodeIndex = (parent.childTextNodeIndex || 0) + 1;
|
|
1488
1768
|
}
|
|
1489
1769
|
}
|
|
1490
|
-
|
|
1491
|
-
if (
|
|
1492
|
-
state.inSingleQuote = false;
|
|
1493
|
-
state.inDoubleQuote = false;
|
|
1494
|
-
state.inBacktick = false;
|
|
1495
|
-
state.lastCharWasBackslash = false;
|
|
1496
|
-
state.inRawTextQuoteAware = false;
|
|
1497
|
-
}
|
|
1770
|
+
const tagId = node.tagId;
|
|
1771
|
+
if (tagId !== void 0 && tagId >= 0 && tagId < 110) state.depthMap[tagId] = Math.max(0, (state.depthMap[tagId] || 0) - 1);
|
|
1498
1772
|
state.depth--;
|
|
1499
1773
|
handleEvent({
|
|
1500
1774
|
type: 1,
|
|
@@ -1548,7 +1822,7 @@ function processCommentOrDoctype(htmlChunk, position) {
|
|
|
1548
1822
|
function processCdataSection(content, state, handleEvent) {
|
|
1549
1823
|
if (!state.tagOverrideHandlers?.has("#cdata-section")) return;
|
|
1550
1824
|
const open = processOpeningTag("#cdata-section", -1, ">", 0, state, handleEvent);
|
|
1551
|
-
if (!open.complete || open.selfClosing) return;
|
|
1825
|
+
if (!open.complete || open.selfClosing || open.skip) return;
|
|
1552
1826
|
const node = state.currentNode;
|
|
1553
1827
|
if (content.length > 0 && !node.tagHandler?.excludesTextNodes) {
|
|
1554
1828
|
const textNode = {
|
|
@@ -1569,6 +1843,7 @@ function processCdataSection(content, state, handleEvent) {
|
|
|
1569
1843
|
closeNode(state.currentNode ?? null, state, handleEvent);
|
|
1570
1844
|
}
|
|
1571
1845
|
function processOpeningTag(tagName, tagId, htmlChunk, i, state, handleEvent) {
|
|
1846
|
+
tagId = effectiveTagId(tagName, tagId, state);
|
|
1572
1847
|
if (state.currentNode?.tagHandler?.isNonNesting) closeNode(state.currentNode, state, handleEvent);
|
|
1573
1848
|
const tagHandler = state.tagOverrideHandlers?.get(tagName) ?? tagHandlers[tagId];
|
|
1574
1849
|
const result = processTagAttributes(htmlChunk, i, tagHandler);
|
|
@@ -1578,12 +1853,26 @@ function processOpeningTag(tagName, tagId, htmlChunk, i, state, handleEvent) {
|
|
|
1578
1853
|
remainingText: `<${tagName}${result.attrBuffer}`,
|
|
1579
1854
|
selfClosing: false
|
|
1580
1855
|
};
|
|
1581
|
-
if ((state.depthMap[1] || 0) > 0 && !HEAD_CONTENT_TAGS.has(tagId)) {
|
|
1856
|
+
if ((state.depthMap[1] || 0) > 0 && (state.depthMap[78] || 0) === 0 && !HEAD_CONTENT_TAGS.has(tagId)) {
|
|
1582
1857
|
while (state.currentNode && state.currentNode.tagId !== 1) closeNode(state.currentNode, state, handleEvent);
|
|
1583
1858
|
const headNode = state.currentNode;
|
|
1584
1859
|
if (headNode && headNode.tagId === 1) closeNode(headNode, state, handleEvent);
|
|
1585
1860
|
}
|
|
1586
|
-
if (tagId >= 0 && tagId <
|
|
1861
|
+
if (tagId >= 0 && tagId < 110 && NEEDS_IMPLIED_END_RECOVERY[tagId] === 1) if (tagId === 65 && (state.depthMap[65] || 0) > 0) {
|
|
1862
|
+
if (closeSelectTo(state, 65, handleEvent)) return {
|
|
1863
|
+
complete: true,
|
|
1864
|
+
newPosition: result.newPosition,
|
|
1865
|
+
remainingText: "",
|
|
1866
|
+
selfClosing: false,
|
|
1867
|
+
skip: true
|
|
1868
|
+
};
|
|
1869
|
+
} else if (tagId === 67) {
|
|
1870
|
+
if ((state.depthMap[65] || 0) > 0) closeSelectTo(state, 67, handleEvent);
|
|
1871
|
+
else if (state.currentNode?.tagId === 67) closeNode(state.currentNode, state, handleEvent);
|
|
1872
|
+
} else if (tagId === 109 && (state.depthMap[65] || 0) > 0) {
|
|
1873
|
+
closeSelectTo(state, 67, handleEvent);
|
|
1874
|
+
closeSelectTo(state, 109, handleEvent);
|
|
1875
|
+
} else if (tagId === 26) {
|
|
1587
1876
|
if ((state.depthMap[26] || 0) > 0) closeImpliedTo(state, SINGLE_A, A_SCOPE_BOUNDARY, handleEvent);
|
|
1588
1877
|
} else if (tagId === 32 || tagId === 31 || tagId === 30 || tagId === 29 || tagId === 38 || tagId === 39) {
|
|
1589
1878
|
if ((state.depthMap[28] || 0) > 0) if (tagId === 32 || tagId === 31) {
|
|
@@ -1602,23 +1891,23 @@ function processOpeningTag(tagName, tagId, htmlChunk, i, state, handleEvent) {
|
|
|
1602
1891
|
if ((state.depthMap[99] || 0) > 0 || (state.depthMap[98] || 0) > 0) closeImpliedTo(state, DT_DD, DL_SCOPE_BOUNDARY, handleEvent);
|
|
1603
1892
|
}
|
|
1604
1893
|
}
|
|
1605
|
-
|
|
1606
|
-
|
|
1894
|
+
if (!result.selfClosing && state.depth >= MAX_ELEMENT_DEPTH) {
|
|
1895
|
+
state.depthLimitReached = true;
|
|
1896
|
+
return {
|
|
1897
|
+
complete: true,
|
|
1898
|
+
newPosition: result.newPosition,
|
|
1899
|
+
remainingText: "",
|
|
1900
|
+
selfClosing: false,
|
|
1901
|
+
skip: true
|
|
1902
|
+
};
|
|
1903
|
+
}
|
|
1904
|
+
if (tagId >= 0 && tagId < 110) state.depthMap[tagId] = (state.depthMap[tagId] || 0) + 1;
|
|
1607
1905
|
state.depth++;
|
|
1608
1906
|
i = result.newPosition;
|
|
1609
1907
|
if (state.currentNode) state.currentNode.currentWalkIndex = state.currentNode.currentWalkIndex || 0;
|
|
1610
1908
|
const currentWalkIndex = state.currentNode ? state.currentNode.currentWalkIndex++ : 0;
|
|
1611
|
-
const tag =
|
|
1612
|
-
|
|
1613
|
-
name: tagName,
|
|
1614
|
-
attributes: result.attributes,
|
|
1615
|
-
parent: state.currentNode,
|
|
1616
|
-
depthMap: copyDepthMap(state.depthMap),
|
|
1617
|
-
depth: state.depth,
|
|
1618
|
-
index: currentWalkIndex,
|
|
1619
|
-
tagId,
|
|
1620
|
-
tagHandler
|
|
1621
|
-
};
|
|
1909
|
+
const tag = new ParsedElementNode(tagName, result.attributes, state.currentNode, state.depth, currentWalkIndex, tagId, tagHandler);
|
|
1910
|
+
if (tagId === 78 || state.currentNode?.excludedFromMarkdown) tag.excludedFromMarkdown = true;
|
|
1622
1911
|
state.lastTextNode = tag;
|
|
1623
1912
|
handleEvent({
|
|
1624
1913
|
type: 0,
|
|
@@ -1628,13 +1917,6 @@ function processOpeningTag(tagName, tagId, htmlChunk, i, state, handleEvent) {
|
|
|
1628
1917
|
parentNode.currentWalkIndex = 0;
|
|
1629
1918
|
state.currentNode = parentNode;
|
|
1630
1919
|
state.hasEncodedHtmlEntity = false;
|
|
1631
|
-
if (tagHandler?.isNonNesting && !result.selfClosing) {
|
|
1632
|
-
state.inSingleQuote = false;
|
|
1633
|
-
state.inDoubleQuote = false;
|
|
1634
|
-
state.inBacktick = false;
|
|
1635
|
-
state.lastCharWasBackslash = false;
|
|
1636
|
-
state.inRawTextQuoteAware = tag.tagId === 52 || tag.tagId === 53;
|
|
1637
|
-
}
|
|
1638
1920
|
if (result.selfClosing) {
|
|
1639
1921
|
closeNode(tag, state, handleEvent);
|
|
1640
1922
|
state.justClosedTag = true;
|
|
@@ -1653,6 +1935,7 @@ function processTagAttributes(htmlChunk, position, tagHandler) {
|
|
|
1653
1935
|
const attrStartPos = i;
|
|
1654
1936
|
let insideQuote = false;
|
|
1655
1937
|
let quoteChar = 0;
|
|
1938
|
+
let hasAttributeContent = false;
|
|
1656
1939
|
let prevChar = 0;
|
|
1657
1940
|
while (i < chunkLength) {
|
|
1658
1941
|
const c = htmlChunk.charCodeAt(i);
|
|
@@ -1663,25 +1946,26 @@ function processTagAttributes(htmlChunk, position, tagHandler) {
|
|
|
1663
1946
|
} else if (c === QUOTE_CHAR || c === APOS_CHAR) {
|
|
1664
1947
|
insideQuote = true;
|
|
1665
1948
|
quoteChar = c;
|
|
1949
|
+
hasAttributeContent = true;
|
|
1666
1950
|
} else if (c === SLASH_CHAR && i + 1 < chunkLength && htmlChunk.charCodeAt(i + 1) === GT_CHAR) {
|
|
1667
|
-
const attrStr = htmlChunk.substring(attrStartPos, i).trim();
|
|
1951
|
+
const attrStr = hasAttributeContent ? htmlChunk.substring(attrStartPos, i).trim() : "";
|
|
1668
1952
|
return {
|
|
1669
1953
|
complete: true,
|
|
1670
1954
|
newPosition: i + 2,
|
|
1671
|
-
attributes: parseAttributes(attrStr),
|
|
1955
|
+
attributes: hasAttributeContent ? parseAttributes(attrStr) : EMPTY_ATTRIBUTES,
|
|
1672
1956
|
selfClosing: true,
|
|
1673
1957
|
attrBuffer: attrStr
|
|
1674
1958
|
};
|
|
1675
1959
|
} else if (c === GT_CHAR) {
|
|
1676
|
-
const attrStr = htmlChunk.substring(attrStartPos, i).trim();
|
|
1960
|
+
const attrStr = hasAttributeContent ? htmlChunk.substring(attrStartPos, i).trim() : "";
|
|
1677
1961
|
return {
|
|
1678
1962
|
complete: true,
|
|
1679
1963
|
newPosition: i + 1,
|
|
1680
|
-
attributes: parseAttributes(attrStr),
|
|
1964
|
+
attributes: hasAttributeContent ? parseAttributes(attrStr) : EMPTY_ATTRIBUTES,
|
|
1681
1965
|
selfClosing,
|
|
1682
1966
|
attrBuffer: attrStr
|
|
1683
1967
|
};
|
|
1684
|
-
}
|
|
1968
|
+
} else if (!isWhitespace(c)) hasAttributeContent = true;
|
|
1685
1969
|
i++;
|
|
1686
1970
|
prevChar = c;
|
|
1687
1971
|
}
|
|
@@ -1751,14 +2035,14 @@ function parseAttributes(attrStr) {
|
|
|
1751
2035
|
if (charCode === BACKSLASH_CHAR && i + 1 < len) i++;
|
|
1752
2036
|
else if (charCode === quoteChar) {
|
|
1753
2037
|
const raw = attrStr.substring(valueStart, i);
|
|
1754
|
-
result[name] = raw.includes("&") ? decodeHTMLEntities(raw) : raw;
|
|
2038
|
+
result[name] = raw.includes("&") ? decodeHTMLEntities(raw, true) : raw;
|
|
1755
2039
|
state = WHITESPACE;
|
|
1756
2040
|
}
|
|
1757
2041
|
break;
|
|
1758
2042
|
case UNQUOTED_VALUE:
|
|
1759
2043
|
if (isSpace || charCode === GT_CHAR) {
|
|
1760
2044
|
const raw = attrStr.substring(valueStart, i);
|
|
1761
|
-
result[name] = raw.includes("&") ? decodeHTMLEntities(raw) : raw;
|
|
2045
|
+
result[name] = raw.includes("&") ? decodeHTMLEntities(raw, true) : raw;
|
|
1762
2046
|
state = WHITESPACE;
|
|
1763
2047
|
}
|
|
1764
2048
|
break;
|
|
@@ -1768,7 +2052,7 @@ function parseAttributes(attrStr) {
|
|
|
1768
2052
|
if (state === QUOTED_VALUE || state === UNQUOTED_VALUE) {
|
|
1769
2053
|
if (name) {
|
|
1770
2054
|
const raw = attrStr.substring(valueStart, i);
|
|
1771
|
-
result[name] = raw.includes("&") ? decodeHTMLEntities(raw) : raw;
|
|
2055
|
+
result[name] = raw.includes("&") ? decodeHTMLEntities(raw, true) : raw;
|
|
1772
2056
|
}
|
|
1773
2057
|
} else if (state === NAME || state === AFTER_NAME || state === BEFORE_VALUE) {
|
|
1774
2058
|
nameEnd = nameEnd || i;
|
|
@@ -1777,4 +2061,4 @@ function parseAttributes(attrStr) {
|
|
|
1777
2061
|
}
|
|
1778
2062
|
return result;
|
|
1779
2063
|
}
|
|
1780
|
-
export { buildTagOverrideHandlers, finalizeParse, parseAttributes, parseHtml, parseHtmlStream };
|
|
2064
|
+
export { buildTagOverrideHandlers, continuationPrefix, finalizeParse, parseAttributes, parseHtml, parseHtmlStream };
|