@mdream/js 1.4.1 → 1.5.2
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 +404 -0
- package/dist/_chunks/parse.mjs +742 -471
- 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 +23 -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 +11 -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];
|
|
@@ -667,303 +1036,6 @@ function buildTagOverrideHandlers(overrides) {
|
|
|
667
1036
|
}
|
|
668
1037
|
return result;
|
|
669
1038
|
}
|
|
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
1039
|
const LT_CHAR = 60;
|
|
968
1040
|
const GT_CHAR = 62;
|
|
969
1041
|
const SLASH_CHAR = 47;
|
|
@@ -977,12 +1049,23 @@ const DASH_CHAR = 45;
|
|
|
977
1049
|
const SPACE_CHAR = 32;
|
|
978
1050
|
const TAB_CHAR = 9;
|
|
979
1051
|
const NEWLINE_CHAR = 10;
|
|
1052
|
+
const FORM_FEED_CHAR = 12;
|
|
980
1053
|
const CARRIAGE_RETURN_CHAR = 13;
|
|
981
1054
|
const BACKTICK_CHAR = 96;
|
|
982
1055
|
const PIPE_CHAR = 124;
|
|
983
1056
|
const OPEN_BRACKET_CHAR = 91;
|
|
984
1057
|
const CLOSE_BRACKET_CHAR = 93;
|
|
985
|
-
const
|
|
1058
|
+
const SCRIPT_DATA = 0;
|
|
1059
|
+
const SCRIPT_DATA_ESCAPED = 1;
|
|
1060
|
+
const SCRIPT_DATA_ESCAPED_DASH = 2;
|
|
1061
|
+
const SCRIPT_DATA_ESCAPED_DASH_DASH = 3;
|
|
1062
|
+
const SCRIPT_DATA_DOUBLE_ESCAPED = 4;
|
|
1063
|
+
const SCRIPT_DATA_DOUBLE_ESCAPED_DASH = 5;
|
|
1064
|
+
const SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH = 6;
|
|
1065
|
+
const SCRIPT_SEQUENCE_NO_MATCH = -1;
|
|
1066
|
+
const SCRIPT_SEQUENCE_INCOMPLETE = -2;
|
|
1067
|
+
const SCRIPT_SCAN_COMPLETE = -1;
|
|
1068
|
+
const HEAD_CONTENT_TAGS = /* @__PURE__ */ new Set([
|
|
986
1069
|
4,
|
|
987
1070
|
5,
|
|
988
1071
|
54,
|
|
@@ -993,7 +1076,7 @@ const HEAD_CONTENT_TAGS = new Set([
|
|
|
993
1076
|
78
|
|
994
1077
|
]);
|
|
995
1078
|
const CLOSES_P = (() => {
|
|
996
|
-
const t = new Uint8Array(
|
|
1079
|
+
const t = /* @__PURE__ */ new Uint8Array(110);
|
|
997
1080
|
for (const id of [
|
|
998
1081
|
36,
|
|
999
1082
|
35,
|
|
@@ -1041,11 +1124,14 @@ const NEEDS_IMPLIED_END_RECOVERY = (() => {
|
|
|
1041
1124
|
30,
|
|
1042
1125
|
29,
|
|
1043
1126
|
38,
|
|
1044
|
-
39
|
|
1127
|
+
39,
|
|
1128
|
+
67,
|
|
1129
|
+
109,
|
|
1130
|
+
65
|
|
1045
1131
|
]) t[id] = 1;
|
|
1046
1132
|
return t;
|
|
1047
1133
|
})();
|
|
1048
|
-
const P_SCOPE_BOUNDARY = new Set([
|
|
1134
|
+
const P_SCOPE_BOUNDARY = /* @__PURE__ */ new Set([
|
|
1049
1135
|
43,
|
|
1050
1136
|
32,
|
|
1051
1137
|
31,
|
|
@@ -1058,7 +1144,7 @@ const P_SCOPE_BOUNDARY = new Set([
|
|
|
1058
1144
|
101,
|
|
1059
1145
|
25
|
|
1060
1146
|
]);
|
|
1061
|
-
const LI_SCOPE_BOUNDARY = new Set([
|
|
1147
|
+
const LI_SCOPE_BOUNDARY = /* @__PURE__ */ new Set([
|
|
1062
1148
|
24,
|
|
1063
1149
|
33,
|
|
1064
1150
|
28,
|
|
@@ -1068,7 +1154,7 @@ const LI_SCOPE_BOUNDARY = new Set([
|
|
|
1068
1154
|
78,
|
|
1069
1155
|
0
|
|
1070
1156
|
]);
|
|
1071
|
-
const DL_SCOPE_BOUNDARY = new Set([
|
|
1157
|
+
const DL_SCOPE_BOUNDARY = /* @__PURE__ */ new Set([
|
|
1072
1158
|
101,
|
|
1073
1159
|
24,
|
|
1074
1160
|
33,
|
|
@@ -1080,7 +1166,7 @@ const DL_SCOPE_BOUNDARY = new Set([
|
|
|
1080
1166
|
78,
|
|
1081
1167
|
0
|
|
1082
1168
|
]);
|
|
1083
|
-
const CELL_SCOPE_BOUNDARY = new Set([
|
|
1169
|
+
const CELL_SCOPE_BOUNDARY = /* @__PURE__ */ new Set([
|
|
1084
1170
|
30,
|
|
1085
1171
|
29,
|
|
1086
1172
|
38,
|
|
@@ -1090,7 +1176,7 @@ const CELL_SCOPE_BOUNDARY = new Set([
|
|
|
1090
1176
|
78,
|
|
1091
1177
|
0
|
|
1092
1178
|
]);
|
|
1093
|
-
const A_SCOPE_BOUNDARY = new Set([
|
|
1179
|
+
const A_SCOPE_BOUNDARY = /* @__PURE__ */ new Set([
|
|
1094
1180
|
35,
|
|
1095
1181
|
36,
|
|
1096
1182
|
25,
|
|
@@ -1125,7 +1211,7 @@ const A_SCOPE_BOUNDARY = new Set([
|
|
|
1125
1211
|
78,
|
|
1126
1212
|
0
|
|
1127
1213
|
]);
|
|
1128
|
-
const HEADINGS = new Set([
|
|
1214
|
+
const HEADINGS = /* @__PURE__ */ new Set([
|
|
1129
1215
|
7,
|
|
1130
1216
|
8,
|
|
1131
1217
|
9,
|
|
@@ -1133,17 +1219,17 @@ const HEADINGS = new Set([
|
|
|
1133
1219
|
11,
|
|
1134
1220
|
12
|
|
1135
1221
|
]);
|
|
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([
|
|
1222
|
+
const SINGLE_P = /* @__PURE__ */ new Set([35]);
|
|
1223
|
+
const SINGLE_LI = /* @__PURE__ */ new Set([25]);
|
|
1224
|
+
const SINGLE_A = /* @__PURE__ */ new Set([26]);
|
|
1225
|
+
const DT_DD = /* @__PURE__ */ new Set([99, 98]);
|
|
1226
|
+
const TD_TH = /* @__PURE__ */ new Set([32, 31]);
|
|
1227
|
+
const TR_CELLS = /* @__PURE__ */ new Set([
|
|
1142
1228
|
32,
|
|
1143
1229
|
31,
|
|
1144
1230
|
30
|
|
1145
1231
|
]);
|
|
1146
|
-
const SECTION_CELLS = new Set([
|
|
1232
|
+
const SECTION_CELLS = /* @__PURE__ */ new Set([
|
|
1147
1233
|
32,
|
|
1148
1234
|
31,
|
|
1149
1235
|
30,
|
|
@@ -1177,28 +1263,189 @@ function closeTableContext(state, closeable, handleEvent) {
|
|
|
1177
1263
|
closeNode(state.currentNode, state, handleEvent);
|
|
1178
1264
|
}
|
|
1179
1265
|
}
|
|
1266
|
+
function closeSelectTo(state, targetId, handleEvent) {
|
|
1267
|
+
let target;
|
|
1268
|
+
for (let node = state.currentNode; node; node = node.parent) {
|
|
1269
|
+
if (node.tagId === targetId) {
|
|
1270
|
+
target = node;
|
|
1271
|
+
break;
|
|
1272
|
+
}
|
|
1273
|
+
if (node.tagId === 65 || node.tagId === 78) break;
|
|
1274
|
+
}
|
|
1275
|
+
if (!target) return false;
|
|
1276
|
+
while (state.currentNode && state.currentNode !== target) closeNode(state.currentNode, state, handleEvent);
|
|
1277
|
+
closeNode(target, state, handleEvent);
|
|
1278
|
+
return true;
|
|
1279
|
+
}
|
|
1180
1280
|
function finalizeParse(leftover, state, handleEvent) {
|
|
1181
|
-
if (
|
|
1281
|
+
if (state.currentNode && isScriptElement(state.currentNode)) {
|
|
1282
|
+
pushScriptTextChunk(state, leftover);
|
|
1283
|
+
const scriptText = takeScriptText(state);
|
|
1284
|
+
if (scriptText) processTextBuffer(scriptText, state, handleEvent);
|
|
1285
|
+
} else if (leftover.length > 0 && leftover.charCodeAt(0) !== LT_CHAR) processTextBuffer(leftover, state, handleEvent);
|
|
1182
1286
|
while (state.currentNode) closeNode(state.currentNode, state, handleEvent);
|
|
1183
1287
|
}
|
|
1184
1288
|
const EMPTY_ATTRIBUTES = Object.freeze({});
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1289
|
+
var ParsedElementNode = class {
|
|
1290
|
+
type = 1;
|
|
1291
|
+
name;
|
|
1292
|
+
attributes;
|
|
1293
|
+
parent;
|
|
1294
|
+
depth;
|
|
1295
|
+
index;
|
|
1296
|
+
tagId;
|
|
1297
|
+
tagHandler;
|
|
1298
|
+
currentWalkIndex;
|
|
1299
|
+
childTextNodeIndex;
|
|
1300
|
+
containsWhitespace;
|
|
1301
|
+
pluginOutput;
|
|
1302
|
+
context;
|
|
1303
|
+
cachedDepthMap;
|
|
1304
|
+
constructor(name, attributes, parent, depth, index, tagId, tagHandler) {
|
|
1305
|
+
this.name = name;
|
|
1306
|
+
this.attributes = attributes;
|
|
1307
|
+
this.parent = parent;
|
|
1308
|
+
this.depth = depth;
|
|
1309
|
+
this.index = index;
|
|
1310
|
+
this.tagId = tagId;
|
|
1311
|
+
this.tagHandler = tagHandler;
|
|
1312
|
+
}
|
|
1313
|
+
get depthMap() {
|
|
1314
|
+
if (this.cachedDepthMap) return this.cachedDepthMap;
|
|
1315
|
+
const depthMap = /* @__PURE__ */ new Uint8Array(110);
|
|
1316
|
+
if (this.tagId >= 0 && this.tagId < 110) depthMap[this.tagId] = 1;
|
|
1317
|
+
let node = this.parent;
|
|
1318
|
+
while (node) {
|
|
1319
|
+
const tagId = node.tagId;
|
|
1320
|
+
if (tagId !== void 0 && tagId >= 0 && tagId < 110) depthMap[tagId] = (depthMap[tagId] || 0) + 1;
|
|
1321
|
+
node = node.parent;
|
|
1322
|
+
}
|
|
1323
|
+
this.cachedDepthMap = depthMap;
|
|
1324
|
+
return depthMap;
|
|
1325
|
+
}
|
|
1326
|
+
};
|
|
1188
1327
|
function isWhitespace(charCode) {
|
|
1189
|
-
return charCode === SPACE_CHAR || charCode === TAB_CHAR || charCode === NEWLINE_CHAR || charCode === CARRIAGE_RETURN_CHAR;
|
|
1328
|
+
return charCode === SPACE_CHAR || charCode === TAB_CHAR || charCode === NEWLINE_CHAR || charCode === FORM_FEED_CHAR || charCode === CARRIAGE_RETURN_CHAR;
|
|
1329
|
+
}
|
|
1330
|
+
function scriptSequenceEnd(html, nameStart) {
|
|
1331
|
+
const name = "script";
|
|
1332
|
+
for (let offset = 0; offset < 6; offset++) {
|
|
1333
|
+
const index = nameStart + offset;
|
|
1334
|
+
if (index >= html.length) return SCRIPT_SEQUENCE_INCOMPLETE;
|
|
1335
|
+
if ((html.charCodeAt(index) | 32) !== name.charCodeAt(offset)) return SCRIPT_SEQUENCE_NO_MATCH;
|
|
1336
|
+
}
|
|
1337
|
+
const delimiterIndex = nameStart + 6;
|
|
1338
|
+
if (delimiterIndex >= html.length) return SCRIPT_SEQUENCE_INCOMPLETE;
|
|
1339
|
+
const delimiter = html.charCodeAt(delimiterIndex);
|
|
1340
|
+
return delimiter === GT_CHAR || delimiter === SLASH_CHAR || isWhitespace(delimiter) ? delimiterIndex + 1 : SCRIPT_SEQUENCE_NO_MATCH;
|
|
1341
|
+
}
|
|
1342
|
+
function isScriptElement(node) {
|
|
1343
|
+
return node.tagId === 52 && node.name === "script";
|
|
1344
|
+
}
|
|
1345
|
+
function scriptScanResult(parseState, scriptState, result) {
|
|
1346
|
+
parseState.scriptDataState = scriptState;
|
|
1347
|
+
return result;
|
|
1348
|
+
}
|
|
1349
|
+
function findScriptEndTag(html, start, parseState) {
|
|
1350
|
+
let state = parseState.scriptDataState ?? SCRIPT_DATA;
|
|
1351
|
+
let i = start;
|
|
1352
|
+
while (i < html.length) {
|
|
1353
|
+
const charCode = html.charCodeAt(i);
|
|
1354
|
+
if (charCode === LT_CHAR) {
|
|
1355
|
+
if (i + 1 === html.length) return scriptScanResult(parseState, state, -i - 2);
|
|
1356
|
+
const next = html.charCodeAt(i + 1);
|
|
1357
|
+
if (state === SCRIPT_DATA) {
|
|
1358
|
+
if (next === SLASH_CHAR) {
|
|
1359
|
+
const sequenceEnd = scriptSequenceEnd(html, i + 2);
|
|
1360
|
+
if (sequenceEnd >= 0) return scriptScanResult(parseState, state, i);
|
|
1361
|
+
if (sequenceEnd === SCRIPT_SEQUENCE_INCOMPLETE) return scriptScanResult(parseState, state, -i - 2);
|
|
1362
|
+
} else if (next === EXCLAMATION_CHAR) {
|
|
1363
|
+
const marker = "<!--";
|
|
1364
|
+
const available = Math.min(html.length - i, 4);
|
|
1365
|
+
if (html.startsWith(marker.substring(0, available), i)) {
|
|
1366
|
+
if (available < 4) return scriptScanResult(parseState, state, -i - 2);
|
|
1367
|
+
state = SCRIPT_DATA_ESCAPED_DASH_DASH;
|
|
1368
|
+
i += 4;
|
|
1369
|
+
continue;
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
} else {
|
|
1373
|
+
const escaped = state < SCRIPT_DATA_DOUBLE_ESCAPED;
|
|
1374
|
+
state = escaped ? SCRIPT_DATA_ESCAPED : SCRIPT_DATA_DOUBLE_ESCAPED;
|
|
1375
|
+
const isEndTag = next === SLASH_CHAR;
|
|
1376
|
+
if (isEndTag || escaped) {
|
|
1377
|
+
const sequenceEnd = scriptSequenceEnd(html, i + (isEndTag ? 2 : 1));
|
|
1378
|
+
if (sequenceEnd >= 0) {
|
|
1379
|
+
if (isEndTag) {
|
|
1380
|
+
if (escaped) return scriptScanResult(parseState, state, i);
|
|
1381
|
+
state = SCRIPT_DATA_ESCAPED;
|
|
1382
|
+
} else state = SCRIPT_DATA_DOUBLE_ESCAPED;
|
|
1383
|
+
i = sequenceEnd;
|
|
1384
|
+
continue;
|
|
1385
|
+
}
|
|
1386
|
+
if (sequenceEnd === SCRIPT_SEQUENCE_INCOMPLETE) return scriptScanResult(parseState, state, -i - 2);
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
} else if (charCode === DASH_CHAR) {
|
|
1390
|
+
if (state === SCRIPT_DATA_ESCAPED || state === SCRIPT_DATA_ESCAPED_DASH) state++;
|
|
1391
|
+
else if (state === SCRIPT_DATA_DOUBLE_ESCAPED || state === SCRIPT_DATA_DOUBLE_ESCAPED_DASH) state++;
|
|
1392
|
+
} 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;
|
|
1393
|
+
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;
|
|
1394
|
+
i++;
|
|
1395
|
+
}
|
|
1396
|
+
return scriptScanResult(parseState, state, SCRIPT_SCAN_COMPLETE);
|
|
1397
|
+
}
|
|
1398
|
+
function pushScriptTextChunk(state, text) {
|
|
1399
|
+
if (!text) return;
|
|
1400
|
+
(state.scriptTextChunks ??= []).push(text);
|
|
1401
|
+
state.textBufferContainsNonWhitespace = true;
|
|
1402
|
+
state.lastCharWasWhitespace = false;
|
|
1403
|
+
state.justClosedTag = false;
|
|
1404
|
+
}
|
|
1405
|
+
function scanScriptChunk(html, start, state) {
|
|
1406
|
+
const result = findScriptEndTag(html, start, state);
|
|
1407
|
+
if (result === SCRIPT_SCAN_COMPLETE) pushScriptTextChunk(state, html.substring(start));
|
|
1408
|
+
else if (result <= SCRIPT_SEQUENCE_INCOMPLETE) pushScriptTextChunk(state, html.substring(start, -result - 2));
|
|
1409
|
+
else pushScriptTextChunk(state, html.substring(start, result));
|
|
1410
|
+
return result;
|
|
1411
|
+
}
|
|
1412
|
+
function takeScriptText(state) {
|
|
1413
|
+
const chunks = state.scriptTextChunks;
|
|
1414
|
+
const text = chunks?.length ? chunks.length === 1 ? chunks[0] : chunks.join("") : "";
|
|
1415
|
+
if (chunks) chunks.length = 0;
|
|
1416
|
+
state.scriptDataState = SCRIPT_DATA;
|
|
1417
|
+
return text;
|
|
1418
|
+
}
|
|
1419
|
+
function normalizeTagName(tagName) {
|
|
1420
|
+
for (let i = 0; i < tagName.length; i++) {
|
|
1421
|
+
const code = tagName.charCodeAt(i);
|
|
1422
|
+
if (code >= 65 && code <= 90) return tagName.toLowerCase();
|
|
1423
|
+
}
|
|
1424
|
+
return tagName;
|
|
1425
|
+
}
|
|
1426
|
+
function effectiveTagId(tagName, fallbackTagId, state) {
|
|
1427
|
+
return state.tagOverrideHandlers?.get(tagName)?.aliasTagId ?? fallbackTagId;
|
|
1428
|
+
}
|
|
1429
|
+
function matchesClosingTag(node, tagName, tagId, closingIsAlias) {
|
|
1430
|
+
if (node.tagId !== tagId) return false;
|
|
1431
|
+
if (tagId === -1) return node.name === tagName;
|
|
1432
|
+
const nodeIsAlias = node.tagHandler?.aliasTagId !== void 0;
|
|
1433
|
+
return node.name === tagName || !nodeIsAlias && !closingIsAlias;
|
|
1190
1434
|
}
|
|
1191
1435
|
function parseHtml(html, options = {}) {
|
|
1192
1436
|
const events = [];
|
|
1437
|
+
const state = {
|
|
1438
|
+
depthMap: /* @__PURE__ */ new Uint8Array(110),
|
|
1439
|
+
depth: 0,
|
|
1440
|
+
resolvedPlugins: options.resolvedPlugins || []
|
|
1441
|
+
};
|
|
1442
|
+
let remainingHtml = parseHtmlInternal(html, state, (event) => {
|
|
1443
|
+
events.push(event);
|
|
1444
|
+
});
|
|
1445
|
+
if (state.scriptTextChunks?.length) remainingHtml = `${takeScriptText(state)}${remainingHtml}`;
|
|
1193
1446
|
return {
|
|
1194
1447
|
events,
|
|
1195
|
-
remainingHtml
|
|
1196
|
-
depthMap: new Uint8Array(109),
|
|
1197
|
-
depth: 0,
|
|
1198
|
-
resolvedPlugins: options.resolvedPlugins || []
|
|
1199
|
-
}, (event) => {
|
|
1200
|
-
events.push(event);
|
|
1201
|
-
})
|
|
1448
|
+
remainingHtml
|
|
1202
1449
|
};
|
|
1203
1450
|
}
|
|
1204
1451
|
function parseHtmlStream(html, state, onEvent) {
|
|
@@ -1206,14 +1453,20 @@ function parseHtmlStream(html, state, onEvent) {
|
|
|
1206
1453
|
}
|
|
1207
1454
|
function parseHtmlInternal(htmlChunk, state, handleEvent) {
|
|
1208
1455
|
let textBuffer = "";
|
|
1209
|
-
state.depthMap ??= new Uint8Array(
|
|
1456
|
+
state.depthMap ??= /* @__PURE__ */ new Uint8Array(110);
|
|
1210
1457
|
state.depth ??= 0;
|
|
1211
1458
|
state.lastCharWasWhitespace ??= true;
|
|
1212
1459
|
state.justClosedTag ??= false;
|
|
1213
1460
|
state.isFirstTextInElement ??= false;
|
|
1214
|
-
state.
|
|
1461
|
+
state.scriptDataState ??= SCRIPT_DATA;
|
|
1215
1462
|
let i = 0;
|
|
1216
1463
|
const chunkLength = htmlChunk.length;
|
|
1464
|
+
if (state.currentNode && isScriptElement(state.currentNode)) {
|
|
1465
|
+
const scanResult = scanScriptChunk(htmlChunk, i, state);
|
|
1466
|
+
if (scanResult < 0) return scanResult <= SCRIPT_SEQUENCE_INCOMPLETE ? htmlChunk.substring(-scanResult - 2) : "";
|
|
1467
|
+
textBuffer = takeScriptText(state);
|
|
1468
|
+
i = scanResult;
|
|
1469
|
+
}
|
|
1217
1470
|
while (i < chunkLength) {
|
|
1218
1471
|
const currentCharCode = htmlChunk.charCodeAt(i);
|
|
1219
1472
|
if (currentCharCode !== LT_CHAR) {
|
|
@@ -1232,25 +1485,16 @@ function parseHtmlInternal(htmlChunk, state, handleEvent) {
|
|
|
1232
1485
|
else if (currentCharCode === SPACE_CHAR || !state.lastCharWasWhitespace) textBuffer += " ";
|
|
1233
1486
|
state.lastCharWasWhitespace = true;
|
|
1234
1487
|
state.textBufferContainsWhitespace = true;
|
|
1235
|
-
state.lastCharWasBackslash = false;
|
|
1236
1488
|
} else {
|
|
1237
1489
|
state.textBufferContainsNonWhitespace = true;
|
|
1238
1490
|
state.lastCharWasWhitespace = false;
|
|
1239
1491
|
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 += "\\>";
|
|
1492
|
+
if (!state.plainText && currentCharCode === PIPE_CHAR && state.depthMap[28]) textBuffer += "\\|";
|
|
1493
|
+
else if (!state.plainText && currentCharCode === BACKTICK_CHAR && (state.depthMap[23] || state.depthMap[34])) textBuffer += "\\`";
|
|
1494
|
+
else if (!state.plainText && currentCharCode === OPEN_BRACKET_CHAR && state.depthMap[26]) textBuffer += "\\[";
|
|
1495
|
+
else if (!state.plainText && currentCharCode === CLOSE_BRACKET_CHAR && state.depthMap[26]) textBuffer += "\\]";
|
|
1496
|
+
else if (!state.plainText && currentCharCode === GT_CHAR && state.depthMap[22]) textBuffer += "\\>";
|
|
1245
1497
|
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
1498
|
}
|
|
1255
1499
|
i++;
|
|
1256
1500
|
continue;
|
|
@@ -1293,18 +1537,16 @@ function parseHtmlInternal(htmlChunk, state, handleEvent) {
|
|
|
1293
1537
|
}
|
|
1294
1538
|
} else if (nextCharCode === SLASH_CHAR) {
|
|
1295
1539
|
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
1540
|
let peekEnd = i + 2;
|
|
1302
1541
|
while (peekEnd < chunkLength) {
|
|
1303
1542
|
const c = htmlChunk.charCodeAt(peekEnd);
|
|
1304
|
-
if (c === GT_CHAR || isWhitespace(c)) break;
|
|
1543
|
+
if (c === GT_CHAR || c === SLASH_CHAR || isWhitespace(c)) break;
|
|
1305
1544
|
peekEnd++;
|
|
1306
1545
|
}
|
|
1307
|
-
|
|
1546
|
+
const peekTagName = normalizeTagName(htmlChunk.substring(i + 2, peekEnd));
|
|
1547
|
+
const peekHandler = state.tagOverrideHandlers?.get(peekTagName);
|
|
1548
|
+
const peekTagId = effectiveTagId(peekTagName, TagIdMap[peekTagName] ?? -1, state);
|
|
1549
|
+
if (!matchesClosingTag(state.currentNode, peekTagName, peekTagId, peekHandler?.aliasTagId !== void 0)) {
|
|
1308
1550
|
textBuffer += htmlChunk[i++];
|
|
1309
1551
|
continue;
|
|
1310
1552
|
}
|
|
@@ -1335,8 +1577,11 @@ function parseHtmlInternal(htmlChunk, state, handleEvent) {
|
|
|
1335
1577
|
textBuffer += htmlChunk.substring(i);
|
|
1336
1578
|
break;
|
|
1337
1579
|
}
|
|
1338
|
-
const
|
|
1339
|
-
|
|
1580
|
+
const rawTagName = htmlChunk.substring(tagNameStart, tagNameEnd);
|
|
1581
|
+
let tagName = rawTagName;
|
|
1582
|
+
if (typeof TagIdMap[tagName] !== "number") tagName = normalizeTagName(rawTagName);
|
|
1583
|
+
const mappedTagId = TagIdMap[tagName];
|
|
1584
|
+
const tagId = effectiveTagId(tagName, typeof mappedTagId === "number" ? mappedTagId : -1, state);
|
|
1340
1585
|
i2 = tagNameEnd;
|
|
1341
1586
|
if (state.currentNode?.tagHandler?.isNonNesting) {
|
|
1342
1587
|
textBuffer += htmlChunk[i++];
|
|
@@ -1351,20 +1596,28 @@ function parseHtmlInternal(htmlChunk, state, handleEvent) {
|
|
|
1351
1596
|
textBuffer = "";
|
|
1352
1597
|
}
|
|
1353
1598
|
const result = processOpeningTag(tagName, tagId, htmlChunk, i2, state, handleEvent);
|
|
1354
|
-
if (result.skip)
|
|
1599
|
+
if (result.skip) i = result.newPosition;
|
|
1355
1600
|
else if (result.complete) {
|
|
1356
1601
|
i = result.newPosition;
|
|
1357
|
-
if (!result.selfClosing)
|
|
1602
|
+
if (!result.selfClosing) {
|
|
1603
|
+
state.isFirstTextInElement = true;
|
|
1604
|
+
if (tagId === 52 && tagName === "script") {
|
|
1605
|
+
const scanResult = scanScriptChunk(htmlChunk, i, state);
|
|
1606
|
+
if (scanResult < 0) {
|
|
1607
|
+
textBuffer = scanResult <= SCRIPT_SEQUENCE_INCOMPLETE ? htmlChunk.substring(-scanResult - 2) : "";
|
|
1608
|
+
break;
|
|
1609
|
+
}
|
|
1610
|
+
textBuffer = takeScriptText(state);
|
|
1611
|
+
i = scanResult;
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1358
1614
|
} else {
|
|
1359
1615
|
textBuffer += result.remainingText;
|
|
1360
1616
|
break;
|
|
1361
1617
|
}
|
|
1362
1618
|
}
|
|
1363
1619
|
}
|
|
1364
|
-
state.
|
|
1365
|
-
state.inDoubleQuote = false;
|
|
1366
|
-
state.inBacktick = false;
|
|
1367
|
-
state.lastCharWasBackslash = false;
|
|
1620
|
+
if (textBuffer.length > 0 && isWhitespace(textBuffer.charCodeAt(0))) state.lastCharWasWhitespace = false;
|
|
1368
1621
|
return textBuffer;
|
|
1369
1622
|
}
|
|
1370
1623
|
function processTextBuffer(textBuffer, state, handleEvent) {
|
|
@@ -1373,7 +1626,6 @@ function processTextBuffer(textBuffer, state, handleEvent) {
|
|
|
1373
1626
|
state.textBufferContainsNonWhitespace = false;
|
|
1374
1627
|
state.textBufferContainsWhitespace = false;
|
|
1375
1628
|
if (!state.currentNode) {
|
|
1376
|
-
if (!containsNonWhitespace) return;
|
|
1377
1629
|
let rootText = textBuffer;
|
|
1378
1630
|
if (rootText.length === 0) return;
|
|
1379
1631
|
if (state.hasEncodedHtmlEntity) {
|
|
@@ -1396,7 +1648,7 @@ function processTextBuffer(textBuffer, state, handleEvent) {
|
|
|
1396
1648
|
state.lastTextNode = rootTextNode;
|
|
1397
1649
|
return;
|
|
1398
1650
|
}
|
|
1399
|
-
const excludesTextNodes = state.currentNode?.tagHandler?.excludesTextNodes;
|
|
1651
|
+
const excludesTextNodes = state.currentNode?.tagHandler?.excludesTextNodes || state.currentNode?.excludedFromMarkdown;
|
|
1400
1652
|
const inPreTag = (state.depthMap[34] || 0) > 0;
|
|
1401
1653
|
if (!inPreTag && !containsNonWhitespace && !state.currentNode.childTextNodeIndex) return;
|
|
1402
1654
|
let text = textBuffer;
|
|
@@ -1432,12 +1684,28 @@ function processClosingTag(htmlChunk, position, state, handleEvent) {
|
|
|
1432
1684
|
let i = position + 2;
|
|
1433
1685
|
const tagNameStart = i;
|
|
1434
1686
|
const chunkLength = htmlChunk.length;
|
|
1687
|
+
let tagNameEnd = -1;
|
|
1688
|
+
let quoteChar = 0;
|
|
1435
1689
|
let foundClose = false;
|
|
1436
1690
|
while (i < chunkLength) {
|
|
1437
|
-
|
|
1691
|
+
const charCode = htmlChunk.charCodeAt(i);
|
|
1692
|
+
if (tagNameEnd !== -1) {
|
|
1693
|
+
if (quoteChar) {
|
|
1694
|
+
if (charCode === quoteChar) quoteChar = 0;
|
|
1695
|
+
i++;
|
|
1696
|
+
continue;
|
|
1697
|
+
}
|
|
1698
|
+
if (charCode === QUOTE_CHAR || charCode === APOS_CHAR) {
|
|
1699
|
+
quoteChar = charCode;
|
|
1700
|
+
i++;
|
|
1701
|
+
continue;
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
if (charCode === GT_CHAR) {
|
|
1438
1705
|
foundClose = true;
|
|
1439
1706
|
break;
|
|
1440
1707
|
}
|
|
1708
|
+
if (tagNameEnd === -1 && (isWhitespace(charCode) || charCode === SLASH_CHAR)) tagNameEnd = i;
|
|
1441
1709
|
i++;
|
|
1442
1710
|
}
|
|
1443
1711
|
if (!foundClose) return {
|
|
@@ -1445,22 +1713,31 @@ function processClosingTag(htmlChunk, position, state, handleEvent) {
|
|
|
1445
1713
|
newPosition: position,
|
|
1446
1714
|
remainingText: htmlChunk.substring(position)
|
|
1447
1715
|
};
|
|
1448
|
-
const
|
|
1449
|
-
|
|
1716
|
+
const rawTagName = htmlChunk.substring(tagNameStart, tagNameEnd === -1 ? i : tagNameEnd);
|
|
1717
|
+
let tagName = rawTagName;
|
|
1718
|
+
if (typeof TagIdMap[tagName] !== "number") tagName = normalizeTagName(rawTagName);
|
|
1719
|
+
const tagHandler = state.tagOverrideHandlers?.get(tagName);
|
|
1720
|
+
const mappedTagId = TagIdMap[tagName];
|
|
1721
|
+
const tagId = effectiveTagId(tagName, typeof mappedTagId === "number" ? mappedTagId : -1, state);
|
|
1722
|
+
const closingIsAlias = tagHandler?.aliasTagId !== void 0;
|
|
1723
|
+
if (state.currentNode?.tagHandler?.isNonNesting && !matchesClosingTag(state.currentNode, tagName, tagId, closingIsAlias)) return {
|
|
1450
1724
|
complete: false,
|
|
1451
1725
|
newPosition: position,
|
|
1452
1726
|
remainingText: htmlChunk.substring(position)
|
|
1453
1727
|
};
|
|
1728
|
+
const stopAtTemplate = tagId !== 78 && (state.depthMap[78] || 0) > 0;
|
|
1454
1729
|
let curr = state.currentNode;
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
curr = curr.parent;
|
|
1460
|
-
match = curr?.tagId !== tagId;
|
|
1730
|
+
while (curr && !matchesClosingTag(curr, tagName, tagId, closingIsAlias)) {
|
|
1731
|
+
if (stopAtTemplate && curr.tagId === 78) {
|
|
1732
|
+
curr = null;
|
|
1733
|
+
break;
|
|
1461
1734
|
}
|
|
1735
|
+
curr = curr.parent;
|
|
1736
|
+
}
|
|
1737
|
+
if (curr) {
|
|
1738
|
+
while (state.currentNode && state.currentNode !== curr) closeNode(state.currentNode, state, handleEvent);
|
|
1739
|
+
closeNode(curr, state, handleEvent);
|
|
1462
1740
|
}
|
|
1463
|
-
if (curr) closeNode(curr, state, handleEvent);
|
|
1464
1741
|
state.justClosedTag = true;
|
|
1465
1742
|
return {
|
|
1466
1743
|
complete: true,
|
|
@@ -1487,14 +1764,8 @@ function closeNode(node, state, handleEvent) {
|
|
|
1487
1764
|
for (const parent of traverseUpToFirstBlockNode(node)) parent.childTextNodeIndex = (parent.childTextNodeIndex || 0) + 1;
|
|
1488
1765
|
}
|
|
1489
1766
|
}
|
|
1490
|
-
|
|
1491
|
-
if (
|
|
1492
|
-
state.inSingleQuote = false;
|
|
1493
|
-
state.inDoubleQuote = false;
|
|
1494
|
-
state.inBacktick = false;
|
|
1495
|
-
state.lastCharWasBackslash = false;
|
|
1496
|
-
state.inRawTextQuoteAware = false;
|
|
1497
|
-
}
|
|
1767
|
+
const tagId = node.tagId;
|
|
1768
|
+
if (tagId !== void 0 && tagId >= 0 && tagId < 110) state.depthMap[tagId] = Math.max(0, (state.depthMap[tagId] || 0) - 1);
|
|
1498
1769
|
state.depth--;
|
|
1499
1770
|
handleEvent({
|
|
1500
1771
|
type: 1,
|
|
@@ -1569,6 +1840,7 @@ function processCdataSection(content, state, handleEvent) {
|
|
|
1569
1840
|
closeNode(state.currentNode ?? null, state, handleEvent);
|
|
1570
1841
|
}
|
|
1571
1842
|
function processOpeningTag(tagName, tagId, htmlChunk, i, state, handleEvent) {
|
|
1843
|
+
tagId = effectiveTagId(tagName, tagId, state);
|
|
1572
1844
|
if (state.currentNode?.tagHandler?.isNonNesting) closeNode(state.currentNode, state, handleEvent);
|
|
1573
1845
|
const tagHandler = state.tagOverrideHandlers?.get(tagName) ?? tagHandlers[tagId];
|
|
1574
1846
|
const result = processTagAttributes(htmlChunk, i, tagHandler);
|
|
@@ -1578,12 +1850,26 @@ function processOpeningTag(tagName, tagId, htmlChunk, i, state, handleEvent) {
|
|
|
1578
1850
|
remainingText: `<${tagName}${result.attrBuffer}`,
|
|
1579
1851
|
selfClosing: false
|
|
1580
1852
|
};
|
|
1581
|
-
if ((state.depthMap[1] || 0) > 0 && !HEAD_CONTENT_TAGS.has(tagId)) {
|
|
1853
|
+
if ((state.depthMap[1] || 0) > 0 && (state.depthMap[78] || 0) === 0 && !HEAD_CONTENT_TAGS.has(tagId)) {
|
|
1582
1854
|
while (state.currentNode && state.currentNode.tagId !== 1) closeNode(state.currentNode, state, handleEvent);
|
|
1583
1855
|
const headNode = state.currentNode;
|
|
1584
1856
|
if (headNode && headNode.tagId === 1) closeNode(headNode, state, handleEvent);
|
|
1585
1857
|
}
|
|
1586
|
-
if (tagId >= 0 && tagId <
|
|
1858
|
+
if (tagId >= 0 && tagId < 110 && NEEDS_IMPLIED_END_RECOVERY[tagId] === 1) if (tagId === 65 && (state.depthMap[65] || 0) > 0) {
|
|
1859
|
+
if (closeSelectTo(state, 65, handleEvent)) return {
|
|
1860
|
+
complete: true,
|
|
1861
|
+
newPosition: result.newPosition,
|
|
1862
|
+
remainingText: "",
|
|
1863
|
+
selfClosing: false,
|
|
1864
|
+
skip: true
|
|
1865
|
+
};
|
|
1866
|
+
} else if (tagId === 67) {
|
|
1867
|
+
if ((state.depthMap[65] || 0) > 0) closeSelectTo(state, 67, handleEvent);
|
|
1868
|
+
else if (state.currentNode?.tagId === 67) closeNode(state.currentNode, state, handleEvent);
|
|
1869
|
+
} else if (tagId === 109 && (state.depthMap[65] || 0) > 0) {
|
|
1870
|
+
closeSelectTo(state, 67, handleEvent);
|
|
1871
|
+
closeSelectTo(state, 109, handleEvent);
|
|
1872
|
+
} else if (tagId === 26) {
|
|
1587
1873
|
if ((state.depthMap[26] || 0) > 0) closeImpliedTo(state, SINGLE_A, A_SCOPE_BOUNDARY, handleEvent);
|
|
1588
1874
|
} else if (tagId === 32 || tagId === 31 || tagId === 30 || tagId === 29 || tagId === 38 || tagId === 39) {
|
|
1589
1875
|
if ((state.depthMap[28] || 0) > 0) if (tagId === 32 || tagId === 31) {
|
|
@@ -1602,23 +1888,13 @@ function processOpeningTag(tagName, tagId, htmlChunk, i, state, handleEvent) {
|
|
|
1602
1888
|
if ((state.depthMap[99] || 0) > 0 || (state.depthMap[98] || 0) > 0) closeImpliedTo(state, DT_DD, DL_SCOPE_BOUNDARY, handleEvent);
|
|
1603
1889
|
}
|
|
1604
1890
|
}
|
|
1605
|
-
|
|
1606
|
-
state.depthMap[tagId] = (currentTagCount || 0) + 1;
|
|
1891
|
+
if (tagId >= 0 && tagId < 110) state.depthMap[tagId] = (state.depthMap[tagId] || 0) + 1;
|
|
1607
1892
|
state.depth++;
|
|
1608
1893
|
i = result.newPosition;
|
|
1609
1894
|
if (state.currentNode) state.currentNode.currentWalkIndex = state.currentNode.currentWalkIndex || 0;
|
|
1610
1895
|
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
|
-
};
|
|
1896
|
+
const tag = new ParsedElementNode(tagName, result.attributes, state.currentNode, state.depth, currentWalkIndex, tagId, tagHandler);
|
|
1897
|
+
if (tagId === 78 || state.currentNode?.excludedFromMarkdown) tag.excludedFromMarkdown = true;
|
|
1622
1898
|
state.lastTextNode = tag;
|
|
1623
1899
|
handleEvent({
|
|
1624
1900
|
type: 0,
|
|
@@ -1628,13 +1904,6 @@ function processOpeningTag(tagName, tagId, htmlChunk, i, state, handleEvent) {
|
|
|
1628
1904
|
parentNode.currentWalkIndex = 0;
|
|
1629
1905
|
state.currentNode = parentNode;
|
|
1630
1906
|
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
1907
|
if (result.selfClosing) {
|
|
1639
1908
|
closeNode(tag, state, handleEvent);
|
|
1640
1909
|
state.justClosedTag = true;
|
|
@@ -1653,6 +1922,7 @@ function processTagAttributes(htmlChunk, position, tagHandler) {
|
|
|
1653
1922
|
const attrStartPos = i;
|
|
1654
1923
|
let insideQuote = false;
|
|
1655
1924
|
let quoteChar = 0;
|
|
1925
|
+
let hasAttributeContent = false;
|
|
1656
1926
|
let prevChar = 0;
|
|
1657
1927
|
while (i < chunkLength) {
|
|
1658
1928
|
const c = htmlChunk.charCodeAt(i);
|
|
@@ -1663,25 +1933,26 @@ function processTagAttributes(htmlChunk, position, tagHandler) {
|
|
|
1663
1933
|
} else if (c === QUOTE_CHAR || c === APOS_CHAR) {
|
|
1664
1934
|
insideQuote = true;
|
|
1665
1935
|
quoteChar = c;
|
|
1936
|
+
hasAttributeContent = true;
|
|
1666
1937
|
} else if (c === SLASH_CHAR && i + 1 < chunkLength && htmlChunk.charCodeAt(i + 1) === GT_CHAR) {
|
|
1667
|
-
const attrStr = htmlChunk.substring(attrStartPos, i).trim();
|
|
1938
|
+
const attrStr = hasAttributeContent ? htmlChunk.substring(attrStartPos, i).trim() : "";
|
|
1668
1939
|
return {
|
|
1669
1940
|
complete: true,
|
|
1670
1941
|
newPosition: i + 2,
|
|
1671
|
-
attributes: parseAttributes(attrStr),
|
|
1942
|
+
attributes: hasAttributeContent ? parseAttributes(attrStr) : EMPTY_ATTRIBUTES,
|
|
1672
1943
|
selfClosing: true,
|
|
1673
1944
|
attrBuffer: attrStr
|
|
1674
1945
|
};
|
|
1675
1946
|
} else if (c === GT_CHAR) {
|
|
1676
|
-
const attrStr = htmlChunk.substring(attrStartPos, i).trim();
|
|
1947
|
+
const attrStr = hasAttributeContent ? htmlChunk.substring(attrStartPos, i).trim() : "";
|
|
1677
1948
|
return {
|
|
1678
1949
|
complete: true,
|
|
1679
1950
|
newPosition: i + 1,
|
|
1680
|
-
attributes: parseAttributes(attrStr),
|
|
1951
|
+
attributes: hasAttributeContent ? parseAttributes(attrStr) : EMPTY_ATTRIBUTES,
|
|
1681
1952
|
selfClosing,
|
|
1682
1953
|
attrBuffer: attrStr
|
|
1683
1954
|
};
|
|
1684
|
-
}
|
|
1955
|
+
} else if (!isWhitespace(c)) hasAttributeContent = true;
|
|
1685
1956
|
i++;
|
|
1686
1957
|
prevChar = c;
|
|
1687
1958
|
}
|
|
@@ -1751,14 +2022,14 @@ function parseAttributes(attrStr) {
|
|
|
1751
2022
|
if (charCode === BACKSLASH_CHAR && i + 1 < len) i++;
|
|
1752
2023
|
else if (charCode === quoteChar) {
|
|
1753
2024
|
const raw = attrStr.substring(valueStart, i);
|
|
1754
|
-
result[name] = raw.includes("&") ? decodeHTMLEntities(raw) : raw;
|
|
2025
|
+
result[name] = raw.includes("&") ? decodeHTMLEntities(raw, true) : raw;
|
|
1755
2026
|
state = WHITESPACE;
|
|
1756
2027
|
}
|
|
1757
2028
|
break;
|
|
1758
2029
|
case UNQUOTED_VALUE:
|
|
1759
2030
|
if (isSpace || charCode === GT_CHAR) {
|
|
1760
2031
|
const raw = attrStr.substring(valueStart, i);
|
|
1761
|
-
result[name] = raw.includes("&") ? decodeHTMLEntities(raw) : raw;
|
|
2032
|
+
result[name] = raw.includes("&") ? decodeHTMLEntities(raw, true) : raw;
|
|
1762
2033
|
state = WHITESPACE;
|
|
1763
2034
|
}
|
|
1764
2035
|
break;
|
|
@@ -1768,7 +2039,7 @@ function parseAttributes(attrStr) {
|
|
|
1768
2039
|
if (state === QUOTED_VALUE || state === UNQUOTED_VALUE) {
|
|
1769
2040
|
if (name) {
|
|
1770
2041
|
const raw = attrStr.substring(valueStart, i);
|
|
1771
|
-
result[name] = raw.includes("&") ? decodeHTMLEntities(raw) : raw;
|
|
2042
|
+
result[name] = raw.includes("&") ? decodeHTMLEntities(raw, true) : raw;
|
|
1772
2043
|
}
|
|
1773
2044
|
} else if (state === NAME || state === AFTER_NAME || state === BEFORE_VALUE) {
|
|
1774
2045
|
nameEnd = nameEnd || i;
|
|
@@ -1777,4 +2048,4 @@ function parseAttributes(attrStr) {
|
|
|
1777
2048
|
}
|
|
1778
2049
|
return result;
|
|
1779
2050
|
}
|
|
1780
|
-
export { buildTagOverrideHandlers, finalizeParse, parseAttributes, parseHtml, parseHtmlStream };
|
|
2051
|
+
export { buildTagOverrideHandlers, continuationPrefix, finalizeParse, parseAttributes, parseHtml, parseHtmlStream };
|