@ai-react-markdown/engine 2.6.0 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +506 -411
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.dev.cjs +506 -411
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +506 -411
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +506 -411
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -174,7 +174,199 @@ var defaultUrlTransform = (value) => {
|
|
|
174
174
|
|
|
175
175
|
// src/components/incrementalParse/computeFreezeBoundary.ts
|
|
176
176
|
import { htmlBlockNames } from "micromark-util-html-tag-name";
|
|
177
|
+
|
|
178
|
+
// src/components/incrementalParse/mdLineText.ts
|
|
179
|
+
var MD_BLANK_RE = /^[ \t\r]*$/;
|
|
180
|
+
var isMdBlank = (text) => MD_BLANK_RE.test(text);
|
|
181
|
+
var mdTrim = (text) => text.replace(/^[ \t\r]+|[ \t\r]+$/g, "");
|
|
182
|
+
var mdTrimStart = (text) => text.replace(/^[ \t\r]+/, "");
|
|
183
|
+
|
|
184
|
+
// src/components/incrementalParse/referenceTaint.ts
|
|
177
185
|
import { normalizeIdentifier } from "micromark-util-normalize-identifier";
|
|
186
|
+
var FOOTNOTE_DEF_RE = /^ {0,3}\[\^[^\]]*\]:/;
|
|
187
|
+
var DEF_RE = /^ {0,3}\[((?:[^[\]\\]|\\.)+)\]:/;
|
|
188
|
+
var REF_RE = /!?\[((?:[^[\]\\]|\\.)*)\]/g;
|
|
189
|
+
function firstUnescaped(text, ch) {
|
|
190
|
+
for (let i = 0; i < text.length; i++) {
|
|
191
|
+
if (text[i] === "\\") i += 1;
|
|
192
|
+
else if (text[i] === ch) return i;
|
|
193
|
+
}
|
|
194
|
+
return -1;
|
|
195
|
+
}
|
|
196
|
+
function lastUnclosedBracket(text) {
|
|
197
|
+
let open = -1;
|
|
198
|
+
for (let i = 0; i < text.length; i++) {
|
|
199
|
+
const c = text[i];
|
|
200
|
+
if (c === "\\") i += 1;
|
|
201
|
+
else if (c === "[") open = i;
|
|
202
|
+
else if (c === "]") open = -1;
|
|
203
|
+
}
|
|
204
|
+
return open;
|
|
205
|
+
}
|
|
206
|
+
function normalizeLabel(label) {
|
|
207
|
+
const collapsed = label.replace(/[ \t\r\n]+/g, " ").replace(/^ | $/g, "");
|
|
208
|
+
return collapsed ? normalizeIdentifier(collapsed) : "";
|
|
209
|
+
}
|
|
210
|
+
function isPlausibleLinkDefRest(rest) {
|
|
211
|
+
const t = mdTrim(rest);
|
|
212
|
+
if (t === "") return false;
|
|
213
|
+
const destEnd = linkDestinationEnd(t);
|
|
214
|
+
if (destEnd === -1) return false;
|
|
215
|
+
const after = mdTrim(t.slice(destEnd));
|
|
216
|
+
if (after === "") return true;
|
|
217
|
+
const opener = after[0];
|
|
218
|
+
if (opener !== '"' && opener !== "'" && opener !== "(") return false;
|
|
219
|
+
const closer = opener === "(" ? ")" : opener;
|
|
220
|
+
for (let i = 1; i < after.length; i++) {
|
|
221
|
+
if (after[i] === "\\") {
|
|
222
|
+
i += 1;
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (after[i] === closer) return isMdBlank(after.slice(i + 1));
|
|
226
|
+
}
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
function linkDestinationEnd(t) {
|
|
230
|
+
if (t.startsWith("<")) {
|
|
231
|
+
for (let i2 = 1; i2 < t.length; i2++) {
|
|
232
|
+
const ch = t[i2];
|
|
233
|
+
if (ch === "\\" && (t[i2 + 1] === "<" || t[i2 + 1] === ">" || t[i2 + 1] === "\\")) {
|
|
234
|
+
i2 += 1;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (ch === ">") return i2 + 1;
|
|
238
|
+
if (ch === "<") return -1;
|
|
239
|
+
}
|
|
240
|
+
return -1;
|
|
241
|
+
}
|
|
242
|
+
let balance = 0;
|
|
243
|
+
let i = 0;
|
|
244
|
+
for (; i < t.length; i++) {
|
|
245
|
+
const code = t.charCodeAt(i);
|
|
246
|
+
if (code === 32 || code === 9) break;
|
|
247
|
+
if (code < 32 || code === 127) return -1;
|
|
248
|
+
const ch = t[i];
|
|
249
|
+
if (ch === "\\" && (t[i + 1] === "(" || t[i + 1] === ")" || t[i + 1] === "\\")) {
|
|
250
|
+
i += 1;
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (ch === "(") balance += 1;
|
|
254
|
+
else if (ch === ")") {
|
|
255
|
+
if (balance === 0) break;
|
|
256
|
+
balance -= 1;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (balance !== 0 || i === 0) return -1;
|
|
260
|
+
return i;
|
|
261
|
+
}
|
|
262
|
+
function inlineResourceEnd(text, openIdx) {
|
|
263
|
+
let i = openIdx + 1;
|
|
264
|
+
const skipWs = () => {
|
|
265
|
+
while (i < text.length && (text[i] === " " || text[i] === " ")) i += 1;
|
|
266
|
+
};
|
|
267
|
+
skipWs();
|
|
268
|
+
if (text[i] === ")") return i + 1;
|
|
269
|
+
const destEnd = linkDestinationEnd(text.slice(i));
|
|
270
|
+
if (destEnd === -1) return -1;
|
|
271
|
+
i += destEnd;
|
|
272
|
+
const beforeWs = i;
|
|
273
|
+
skipWs();
|
|
274
|
+
if (text[i] === ")") return i + 1;
|
|
275
|
+
if (i === beforeWs) return -1;
|
|
276
|
+
const opener = text[i];
|
|
277
|
+
if (opener !== '"' && opener !== "'" && opener !== "(") return -1;
|
|
278
|
+
const closer = opener === "(" ? ")" : opener;
|
|
279
|
+
for (i += 1; i < text.length; i++) {
|
|
280
|
+
if (text[i] === "\\") {
|
|
281
|
+
i += 1;
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (text[i] === closer) {
|
|
285
|
+
i += 1;
|
|
286
|
+
skipWs();
|
|
287
|
+
return text[i] === ")" ? i + 1 : -1;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return -1;
|
|
291
|
+
}
|
|
292
|
+
function collectRefLine(cp, lnStart, lnEnd, scanText, inRawText, isBlockStart) {
|
|
293
|
+
const defShaped = inRawText ? null : DEF_RE.exec(scanText);
|
|
294
|
+
const def = defShaped !== null && (defShaped[1].startsWith("^") || isPlausibleLinkDefRest(scanText.slice(defShaped.index + defShaped[0].length))) ? defShaped : null;
|
|
295
|
+
const defLineStart = isBlockStart || !cp.prevLineWasText || cp.prevLineWasValidDef;
|
|
296
|
+
const validDef = def !== null && defLineStart;
|
|
297
|
+
if (validDef) {
|
|
298
|
+
const label = def[1];
|
|
299
|
+
if (label.startsWith("^")) {
|
|
300
|
+
const key = normalizeLabel(label.slice(1));
|
|
301
|
+
if (key && !cp.footnoteDefs.has(key)) cp.footnoteDefs.set(key, lnEnd);
|
|
302
|
+
} else {
|
|
303
|
+
const key = normalizeLabel(label);
|
|
304
|
+
if (key && !cp.defs.has(key)) cp.defs.set(key, lnEnd);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (cp.referenceTaint) {
|
|
308
|
+
const pushRef = (offset, inner, followAt) => {
|
|
309
|
+
const follow = scanText[followAt];
|
|
310
|
+
if (follow === "(" && inlineResourceEnd(scanText, followAt) !== -1) return;
|
|
311
|
+
let label;
|
|
312
|
+
let footnote = false;
|
|
313
|
+
if (inner.startsWith("^")) {
|
|
314
|
+
footnote = true;
|
|
315
|
+
label = normalizeLabel(inner.slice(1));
|
|
316
|
+
} else if (follow === "[") {
|
|
317
|
+
const explicit = /^\[((?:[^[\]\\]|\\.)*)\]/.exec(scanText.slice(followAt));
|
|
318
|
+
label = normalizeLabel(explicit && explicit[1] ? explicit[1] : inner);
|
|
319
|
+
} else {
|
|
320
|
+
label = normalizeLabel(inner);
|
|
321
|
+
}
|
|
322
|
+
if (label) cp.unresolvedRefs.push({ offset, label, footnote });
|
|
323
|
+
};
|
|
324
|
+
const pending = cp.openBracket;
|
|
325
|
+
cp.openBracket = null;
|
|
326
|
+
if (pending) {
|
|
327
|
+
const close = firstUnescaped(scanText, "]");
|
|
328
|
+
const open = firstUnescaped(scanText, "[");
|
|
329
|
+
const cont = (t) => t.replace(/^ {0,3}>[ \t]?/, "");
|
|
330
|
+
if (close !== -1 && (open === -1 || close < open)) {
|
|
331
|
+
pushRef(pending.offset, `${pending.text}
|
|
332
|
+
${cont(scanText.slice(0, close))}`, close + 1);
|
|
333
|
+
} else if (close === -1 && open === -1) {
|
|
334
|
+
cp.openBracket = { offset: pending.offset, text: `${pending.text}
|
|
335
|
+
${cont(scanText)}` };
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (scanText.includes("[")) {
|
|
339
|
+
const defBracket = validDef ? def.index + def[0].indexOf("[") : -1;
|
|
340
|
+
REF_RE.lastIndex = 0;
|
|
341
|
+
let m;
|
|
342
|
+
while ((m = REF_RE.exec(scanText)) !== null) {
|
|
343
|
+
const followAt = m.index + m[0].length;
|
|
344
|
+
if (scanText[followAt] === ":" && m.index === defBracket) continue;
|
|
345
|
+
pushRef(lnStart + m.index, m[1], followAt);
|
|
346
|
+
}
|
|
347
|
+
const trailingOpen = lastUnclosedBracket(scanText);
|
|
348
|
+
if (trailingOpen !== -1) {
|
|
349
|
+
cp.openBracket = { offset: lnStart + trailingOpen, text: scanText.slice(trailingOpen + 1) };
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return { validDef, validLinkDef: validDef && !def[1].startsWith("^") };
|
|
354
|
+
}
|
|
355
|
+
function settleRefsAndEarliestUnresolved(cp) {
|
|
356
|
+
if (cp.unresolvedRefs.length > 0) {
|
|
357
|
+
const settled = (defEnd) => cp.lastBlankStart >= defEnd;
|
|
358
|
+
cp.unresolvedRefs = cp.unresolvedRefs.filter((ref) => {
|
|
359
|
+
const table = ref.footnote ? cp.footnoteDefs : cp.defs;
|
|
360
|
+
const defEnd = table.get(ref.label);
|
|
361
|
+
return defEnd === void 0 || !settled(defEnd);
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
let earliestUnresolved = Infinity;
|
|
365
|
+
for (const ref of cp.unresolvedRefs) earliestUnresolved = Math.min(earliestUnresolved, ref.offset);
|
|
366
|
+
return earliestUnresolved;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// src/components/incrementalParse/computeFreezeBoundary.ts
|
|
178
370
|
var TYPE6_NAMES = new Set(htmlBlockNames);
|
|
179
371
|
var TABLE_PART_NAMES = /* @__PURE__ */ new Set(["td", "th", "tr", "tbody", "thead", "tfoot", "caption", "col", "colgroup"]);
|
|
180
372
|
var DOCUMENT_STRUCTURE_NAMES = /* @__PURE__ */ new Set(["html", "head", "body", "frameset"]);
|
|
@@ -197,53 +389,6 @@ function tailCarriesRetroactive(text) {
|
|
|
197
389
|
}
|
|
198
390
|
return false;
|
|
199
391
|
}
|
|
200
|
-
var HTML_BREAKOUT_TAGS = /* @__PURE__ */ new Set([
|
|
201
|
-
"b",
|
|
202
|
-
"big",
|
|
203
|
-
"blockquote",
|
|
204
|
-
"body",
|
|
205
|
-
"br",
|
|
206
|
-
"center",
|
|
207
|
-
"code",
|
|
208
|
-
"dd",
|
|
209
|
-
"div",
|
|
210
|
-
"dl",
|
|
211
|
-
"dt",
|
|
212
|
-
"em",
|
|
213
|
-
"embed",
|
|
214
|
-
"h1",
|
|
215
|
-
"h2",
|
|
216
|
-
"h3",
|
|
217
|
-
"h4",
|
|
218
|
-
"h5",
|
|
219
|
-
"h6",
|
|
220
|
-
"head",
|
|
221
|
-
"hr",
|
|
222
|
-
"i",
|
|
223
|
-
"img",
|
|
224
|
-
"li",
|
|
225
|
-
"listing",
|
|
226
|
-
"menu",
|
|
227
|
-
"meta",
|
|
228
|
-
"nobr",
|
|
229
|
-
"ol",
|
|
230
|
-
"p",
|
|
231
|
-
"pre",
|
|
232
|
-
"ruby",
|
|
233
|
-
"s",
|
|
234
|
-
"small",
|
|
235
|
-
"span",
|
|
236
|
-
"strong",
|
|
237
|
-
"strike",
|
|
238
|
-
"sub",
|
|
239
|
-
"sup",
|
|
240
|
-
"table",
|
|
241
|
-
"tt",
|
|
242
|
-
"u",
|
|
243
|
-
"ul",
|
|
244
|
-
"var"
|
|
245
|
-
]);
|
|
246
|
-
var HTML_INTEGRATION_POINTS = ["foreignobject", "desc", "title", "mi", "mo", "mn", "ms", "mtext", "annotation-xml"];
|
|
247
392
|
var SCOPE_BARRIER_NAMES = /* @__PURE__ */ new Set([
|
|
248
393
|
"applet",
|
|
249
394
|
"caption",
|
|
@@ -281,11 +426,85 @@ var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
|
|
|
281
426
|
// (oracle review of the r2 batch; regression caught before release).
|
|
282
427
|
"plaintext"
|
|
283
428
|
]);
|
|
429
|
+
var P5_MARKUP_RE = /<[!/?A-Za-z]/;
|
|
284
430
|
var TYPE6_START_RE = /^<\/?([A-Za-z][A-Za-z0-9-]*)(?:[ \t\r]|\/?>|$)/;
|
|
285
431
|
var TYPE1_START_RE = /^<(script|pre|style|textarea)(?:[ \t\r]|>|$)/i;
|
|
286
432
|
var TYPE1_CLOSE_RE = /<\/(?:script|pre|style|textarea)>/i;
|
|
287
|
-
var
|
|
288
|
-
var
|
|
433
|
+
var isSpaceTab = (c) => c === 32 || c === 9;
|
|
434
|
+
var isAsciiAlpha = (c) => c >= 65 && c <= 90 || c >= 97 && c <= 122;
|
|
435
|
+
var isAlnum = (c) => isAsciiAlpha(c) || c >= 48 && c <= 57;
|
|
436
|
+
var isAttrNameRest = (c) => isAlnum(c) || c === 45 || c === 46 || c === 58 || c === 95;
|
|
437
|
+
var isUnquotedExit = (c) => Number.isNaN(c) || c === 34 || c === 39 || c === 47 || c === 60 || c === 61 || c === 62 || c === 96 || isSpaceTab(c);
|
|
438
|
+
var completeOpenTagRest = (t, from) => {
|
|
439
|
+
let i = from;
|
|
440
|
+
for (; ; ) {
|
|
441
|
+
const c = t.charCodeAt(i);
|
|
442
|
+
if (c === 47) {
|
|
443
|
+
i += 1;
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
if (isSpaceTab(c)) {
|
|
447
|
+
i += 1;
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
if (!(c === 58 || c === 95 || isAsciiAlpha(c))) break;
|
|
451
|
+
i += 1;
|
|
452
|
+
while (isAttrNameRest(t.charCodeAt(i))) i += 1;
|
|
453
|
+
for (; ; ) {
|
|
454
|
+
while (isSpaceTab(t.charCodeAt(i))) i += 1;
|
|
455
|
+
if (t.charCodeAt(i) !== 61) break;
|
|
456
|
+
i += 1;
|
|
457
|
+
while (isSpaceTab(t.charCodeAt(i))) i += 1;
|
|
458
|
+
const v = t.charCodeAt(i);
|
|
459
|
+
if (Number.isNaN(v) || v === 60 || v === 61 || v === 62 || v === 96) return -1;
|
|
460
|
+
if (v === 34 || v === 39) {
|
|
461
|
+
i += 1;
|
|
462
|
+
while (t.charCodeAt(i) !== v) {
|
|
463
|
+
if (i >= t.length) return -1;
|
|
464
|
+
i += 1;
|
|
465
|
+
}
|
|
466
|
+
i += 1;
|
|
467
|
+
const a = t.charCodeAt(i);
|
|
468
|
+
if (!(a === 47 || a === 62 || isSpaceTab(a))) return -1;
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
while (!isUnquotedExit(t.charCodeAt(i))) i += 1;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return t.charCodeAt(i) === 62 ? i + 1 : -1;
|
|
475
|
+
};
|
|
476
|
+
var isType7Line = (line) => {
|
|
477
|
+
const cr = line.indexOf("\r");
|
|
478
|
+
const t = cr === -1 ? line : line.slice(0, cr);
|
|
479
|
+
if (t.charCodeAt(0) !== 60) return false;
|
|
480
|
+
let i = 1;
|
|
481
|
+
const closing = t.charCodeAt(i) === 47;
|
|
482
|
+
if (closing) i += 1;
|
|
483
|
+
if (!isAsciiAlpha(t.charCodeAt(i))) return false;
|
|
484
|
+
const nameStart = i;
|
|
485
|
+
i += 1;
|
|
486
|
+
while (isAlnum(t.charCodeAt(i)) || t.charCodeAt(i) === 45) i += 1;
|
|
487
|
+
const c = t.charCodeAt(i);
|
|
488
|
+
if (!(Number.isNaN(c) || c === 47 || c === 62 || isSpaceTab(c))) return false;
|
|
489
|
+
const name = t.slice(nameStart, i).toLowerCase();
|
|
490
|
+
if (!closing && c !== 47 && TYPE1_NAMES.has(name)) return false;
|
|
491
|
+
if (TYPE6_NAMES.has(name)) return false;
|
|
492
|
+
if (closing) {
|
|
493
|
+
while (isSpaceTab(t.charCodeAt(i))) i += 1;
|
|
494
|
+
if (t.charCodeAt(i) !== 62) return false;
|
|
495
|
+
i += 1;
|
|
496
|
+
} else {
|
|
497
|
+
i = completeOpenTagRest(t, i);
|
|
498
|
+
if (i === -1) return false;
|
|
499
|
+
}
|
|
500
|
+
while (isSpaceTab(t.charCodeAt(i))) i += 1;
|
|
501
|
+
return i >= t.length;
|
|
502
|
+
};
|
|
503
|
+
var mdHtml = (b, type) => b.kind === "html" && b.type === type;
|
|
504
|
+
var mdHtml25 = (b) => b.kind === "html" && b.type >= 2 && b.type <= 5;
|
|
505
|
+
var commentEitherOpen = (md, p5) => mdHtml(md, 2) || p5.kind === "comment";
|
|
506
|
+
var inRawTextTok = (t) => t.kind === "rawText" || t.kind === "script";
|
|
507
|
+
var rawTextElement = (t) => t.kind === "rawText" ? t.element : t.kind === "script" ? "script" : null;
|
|
289
508
|
var VOID_TAGS = /* @__PURE__ */ new Set([
|
|
290
509
|
"area",
|
|
291
510
|
"base",
|
|
@@ -303,9 +522,11 @@ var VOID_TAGS = /* @__PURE__ */ new Set([
|
|
|
303
522
|
"wbr"
|
|
304
523
|
]);
|
|
305
524
|
var LIST_MARKER_RE = /^ {0,3}(?:[-*+]|\d{1,9}[.)])(?:[ \t]|$)/;
|
|
306
|
-
var
|
|
525
|
+
var ATX_HEADING_RE = /^#{1,6}(?:[ \t]|$)/;
|
|
526
|
+
var THEMATIC_BREAK_RE = /^(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/;
|
|
527
|
+
var BARE_MARKER_RE = /^(?:[-*+]|\d{1,9}[.)])[ \t]*$/;
|
|
528
|
+
var SETEXT_LEFTOVER_RE = /^(?:=+|--)[ \t]*$/;
|
|
307
529
|
var DEF_LIST_DD_RE = /^ {0,3}:[ \t]/;
|
|
308
|
-
var DEF_RE = /^ {0,3}\[((?:[^[\]\\]|\\.)+)\]:/;
|
|
309
530
|
var FENCE_RE = /^ {0,3}(`{3,}|~{3,})/;
|
|
310
531
|
var MATH_RUN_RE = /^ {0,3}(\$\$+)/;
|
|
311
532
|
var TAG_OR_COMMENT_RE = /<(\/?)([A-Za-z][A-Za-z0-9-]*)(?=[\s/>])([^>]*)>|<!--|-->|--!>/g;
|
|
@@ -338,12 +559,7 @@ function scanTagAttrs(text, from, to, out) {
|
|
|
338
559
|
out.state = st;
|
|
339
560
|
return -1;
|
|
340
561
|
}
|
|
341
|
-
var REF_RE = /!?\[((?:[^[\]\\]|\\.)*)\]/g;
|
|
342
562
|
var BACKTICK_RUN_RE = /`+/g;
|
|
343
|
-
var MD_BLANK_RE = /^[ \t\r]*$/;
|
|
344
|
-
var isMdBlank = (text) => MD_BLANK_RE.test(text);
|
|
345
|
-
var mdTrim = (text) => text.replace(/^[ \t\r]+|[ \t\r]+$/g, "");
|
|
346
|
-
var mdTrimStart = (text) => text.replace(/^[ \t\r]+/, "");
|
|
347
563
|
function computeIndent(text) {
|
|
348
564
|
let indent = 0;
|
|
349
565
|
for (const ch of text) {
|
|
@@ -353,27 +569,6 @@ function computeIndent(text) {
|
|
|
353
569
|
}
|
|
354
570
|
return indent;
|
|
355
571
|
}
|
|
356
|
-
function firstUnescaped(text, ch) {
|
|
357
|
-
for (let i = 0; i < text.length; i++) {
|
|
358
|
-
if (text[i] === "\\") i += 1;
|
|
359
|
-
else if (text[i] === ch) return i;
|
|
360
|
-
}
|
|
361
|
-
return -1;
|
|
362
|
-
}
|
|
363
|
-
function lastUnclosedBracket(text) {
|
|
364
|
-
let open = -1;
|
|
365
|
-
for (let i = 0; i < text.length; i++) {
|
|
366
|
-
const c = text[i];
|
|
367
|
-
if (c === "\\") i += 1;
|
|
368
|
-
else if (c === "[") open = i;
|
|
369
|
-
else if (c === "]") open = -1;
|
|
370
|
-
}
|
|
371
|
-
return open;
|
|
372
|
-
}
|
|
373
|
-
function normalizeLabel(label) {
|
|
374
|
-
const collapsed = label.replace(/[ \t\r\n]+/g, " ").replace(/^ | $/g, "");
|
|
375
|
-
return collapsed ? normalizeIdentifier(collapsed) : "";
|
|
376
|
-
}
|
|
377
572
|
function canBecomeDdLine(text, confirmed) {
|
|
378
573
|
let i = 0;
|
|
379
574
|
while (i < text.length && text[i] === " ") i += 1;
|
|
@@ -430,20 +625,9 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
|
|
|
430
625
|
unresolvedRefs: [],
|
|
431
626
|
tagBalance: /* @__PURE__ */ new Map(),
|
|
432
627
|
openTotal: 0,
|
|
433
|
-
|
|
434
|
-
piOpen: false,
|
|
435
|
-
bogusOpen: false,
|
|
436
|
-
rawTextOpen: null,
|
|
628
|
+
p5Tok: { kind: "data" },
|
|
437
629
|
openStack: [],
|
|
438
|
-
|
|
439
|
-
declOpen: false,
|
|
440
|
-
cdataOpen: false,
|
|
441
|
-
inFence: false,
|
|
442
|
-
fenceChar: "",
|
|
443
|
-
fenceLen: 0,
|
|
444
|
-
inMath: false,
|
|
445
|
-
mathFenceLen: 0,
|
|
446
|
-
openIndent: 0,
|
|
630
|
+
mdBlock: { kind: "none" },
|
|
447
631
|
blankRun: 0,
|
|
448
632
|
lastBlankStart: -1,
|
|
449
633
|
hazardVerdict: false,
|
|
@@ -451,103 +635,17 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
|
|
|
451
635
|
// doc start counts as a block start
|
|
452
636
|
prevLineWasText: false,
|
|
453
637
|
prevLineWasValidDef: false,
|
|
638
|
+
prevLineOpenContent: false,
|
|
639
|
+
tableMaybeOpen: false,
|
|
454
640
|
paragraphHasUnpairedRun: false,
|
|
455
641
|
openBracket: null,
|
|
456
|
-
|
|
457
|
-
htmlSeamPending: false,
|
|
642
|
+
p5SealPending: false,
|
|
458
643
|
phasePoisonedAt: Infinity,
|
|
459
644
|
pendingTruncatedTags: [],
|
|
460
645
|
pendingTruncatedCloses: [],
|
|
461
|
-
|
|
462
|
-
tagAcrossLinesIndent: 0,
|
|
463
|
-
tagAcrossLinesState: "outside",
|
|
464
|
-
htmlFlowReal: false,
|
|
465
|
-
type1FlowOpen: false,
|
|
466
|
-
rawTextInline: false
|
|
646
|
+
pendingTag: null
|
|
467
647
|
};
|
|
468
648
|
}
|
|
469
|
-
function isPlausibleLinkDefRest(rest) {
|
|
470
|
-
const t = mdTrim(rest);
|
|
471
|
-
if (t === "") return false;
|
|
472
|
-
const destEnd = linkDestinationEnd(t);
|
|
473
|
-
if (destEnd === -1) return false;
|
|
474
|
-
const after = mdTrim(t.slice(destEnd));
|
|
475
|
-
if (after === "") return true;
|
|
476
|
-
const opener = after[0];
|
|
477
|
-
if (opener !== '"' && opener !== "'" && opener !== "(") return false;
|
|
478
|
-
const closer = opener === "(" ? ")" : opener;
|
|
479
|
-
for (let i = 1; i < after.length; i++) {
|
|
480
|
-
if (after[i] === "\\") {
|
|
481
|
-
i += 1;
|
|
482
|
-
continue;
|
|
483
|
-
}
|
|
484
|
-
if (after[i] === closer) return isMdBlank(after.slice(i + 1));
|
|
485
|
-
}
|
|
486
|
-
return false;
|
|
487
|
-
}
|
|
488
|
-
function linkDestinationEnd(t) {
|
|
489
|
-
if (t.startsWith("<")) {
|
|
490
|
-
for (let i2 = 1; i2 < t.length; i2++) {
|
|
491
|
-
const ch = t[i2];
|
|
492
|
-
if (ch === "\\" && (t[i2 + 1] === "<" || t[i2 + 1] === ">" || t[i2 + 1] === "\\")) {
|
|
493
|
-
i2 += 1;
|
|
494
|
-
continue;
|
|
495
|
-
}
|
|
496
|
-
if (ch === ">") return i2 + 1;
|
|
497
|
-
if (ch === "<") return -1;
|
|
498
|
-
}
|
|
499
|
-
return -1;
|
|
500
|
-
}
|
|
501
|
-
let balance = 0;
|
|
502
|
-
let i = 0;
|
|
503
|
-
for (; i < t.length; i++) {
|
|
504
|
-
const code = t.charCodeAt(i);
|
|
505
|
-
if (code === 32 || code === 9) break;
|
|
506
|
-
if (code < 32 || code === 127) return -1;
|
|
507
|
-
const ch = t[i];
|
|
508
|
-
if (ch === "\\" && (t[i + 1] === "(" || t[i + 1] === ")" || t[i + 1] === "\\")) {
|
|
509
|
-
i += 1;
|
|
510
|
-
continue;
|
|
511
|
-
}
|
|
512
|
-
if (ch === "(") balance += 1;
|
|
513
|
-
else if (ch === ")") {
|
|
514
|
-
if (balance === 0) break;
|
|
515
|
-
balance -= 1;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
if (balance !== 0 || i === 0) return -1;
|
|
519
|
-
return i;
|
|
520
|
-
}
|
|
521
|
-
function inlineResourceEnd(text, openIdx) {
|
|
522
|
-
let i = openIdx + 1;
|
|
523
|
-
const skipWs = () => {
|
|
524
|
-
while (i < text.length && (text[i] === " " || text[i] === " ")) i += 1;
|
|
525
|
-
};
|
|
526
|
-
skipWs();
|
|
527
|
-
if (text[i] === ")") return i + 1;
|
|
528
|
-
const destEnd = linkDestinationEnd(text.slice(i));
|
|
529
|
-
if (destEnd === -1) return -1;
|
|
530
|
-
i += destEnd;
|
|
531
|
-
const beforeWs = i;
|
|
532
|
-
skipWs();
|
|
533
|
-
if (text[i] === ")") return i + 1;
|
|
534
|
-
if (i === beforeWs) return -1;
|
|
535
|
-
const opener = text[i];
|
|
536
|
-
if (opener !== '"' && opener !== "'" && opener !== "(") return -1;
|
|
537
|
-
const closer = opener === "(" ? ")" : opener;
|
|
538
|
-
for (i += 1; i < text.length; i++) {
|
|
539
|
-
if (text[i] === "\\") {
|
|
540
|
-
i += 1;
|
|
541
|
-
continue;
|
|
542
|
-
}
|
|
543
|
-
if (text[i] === closer) {
|
|
544
|
-
i += 1;
|
|
545
|
-
skipWs();
|
|
546
|
-
return text[i] === ")" ? i + 1 : -1;
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
return -1;
|
|
550
|
-
}
|
|
551
649
|
function classifyBlockStart(text, indent, defListEnabled) {
|
|
552
650
|
if (indent >= 4) return true;
|
|
553
651
|
if (LIST_MARKER_RE.test(text) || FOOTNOTE_DEF_RE.test(text)) return true;
|
|
@@ -593,16 +691,7 @@ function computeFreezeBoundary(text, options, resume) {
|
|
|
593
691
|
cp.confirmedOffset = end + 1;
|
|
594
692
|
start = end + 1;
|
|
595
693
|
}
|
|
596
|
-
|
|
597
|
-
const settled = (defEnd) => cp.lastBlankStart >= defEnd;
|
|
598
|
-
cp.unresolvedRefs = cp.unresolvedRefs.filter((ref) => {
|
|
599
|
-
const table = ref.footnote ? cp.footnoteDefs : cp.defs;
|
|
600
|
-
const defEnd = table.get(ref.label);
|
|
601
|
-
return defEnd === void 0 || !settled(defEnd);
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
let earliestUnresolved = Infinity;
|
|
605
|
-
for (const ref of cp.unresolvedRefs) earliestUnresolved = Math.min(earliestUnresolved, ref.offset);
|
|
694
|
+
const earliestUnresolved = settleRefsAndEarliestUnresolved(cp);
|
|
606
695
|
const defListSettled = (c) => {
|
|
607
696
|
if (!options.defListEnabled || c.blankRun >= 2) return true;
|
|
608
697
|
if (c.defListSettled !== null) return c.defListSettled;
|
|
@@ -625,9 +714,8 @@ function computeFreezeBoundary(text, options, resume) {
|
|
|
625
714
|
function pendingFenceCloser(checkpoint) {
|
|
626
715
|
const cp = checkpoint;
|
|
627
716
|
if (cp.phasePoisonedAt !== Infinity) return "";
|
|
628
|
-
if (cp.
|
|
629
|
-
if (cp.
|
|
630
|
-
if (cp.inMath) return "$".repeat(cp.mathFenceLen);
|
|
717
|
+
if (cp.mdBlock.kind === "fence" && cp.mdBlock.indent === 0) return cp.mdBlock.char.repeat(cp.mdBlock.len);
|
|
718
|
+
if (cp.mdBlock.kind === "math" && cp.mdBlock.indent === 0) return "$".repeat(cp.mdBlock.len);
|
|
631
719
|
return "";
|
|
632
720
|
}
|
|
633
721
|
function floatingResidue(text, commentOpenAtStart) {
|
|
@@ -678,53 +766,34 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
678
766
|
newest.defListSettled = ln.blank ? true : !canBecomeDdLine(ln.text, true);
|
|
679
767
|
}
|
|
680
768
|
const isBlockStart = cp.prevLineBlank;
|
|
681
|
-
if (cp.
|
|
769
|
+
if (cp.p5SealPending && !ln.blank && cp.mdBlock.kind !== "html" && !(cp.p5Tok.kind === "comment" || cp.p5Tok.kind === "bogus")) {
|
|
682
770
|
const defShapedLine = DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text);
|
|
683
771
|
const commentOnly = ln.text.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!--[\s\S]*$/, " ").replace(/[ \t\r]/g, "") === "";
|
|
684
772
|
if (!defShapedLine && !commentOnly) {
|
|
685
|
-
cp.
|
|
773
|
+
cp.p5SealPending = false;
|
|
686
774
|
}
|
|
687
775
|
}
|
|
688
|
-
const
|
|
689
|
-
const honoursSelfClosing = (tag) =>
|
|
690
|
-
|
|
691
|
-
if (!inForeignContent() || HTML_BREAKOUT_TAGS.has(tag)) return false;
|
|
692
|
-
for (const ip of HTML_INTEGRATION_POINTS) if ((cp.tagBalance.get(ip) ?? 0) > 0) return false;
|
|
693
|
-
return true;
|
|
694
|
-
};
|
|
695
|
-
const htmlRulesApply = () => {
|
|
696
|
-
if (!inForeignContent()) return true;
|
|
697
|
-
for (const ip of HTML_INTEGRATION_POINTS) if ((cp.tagBalance.get(ip) ?? 0) > 0) return true;
|
|
698
|
-
return false;
|
|
699
|
-
};
|
|
700
|
-
const popForeignRoots = () => {
|
|
701
|
-
for (const name of FOREIGN_ROOT_NAMES) {
|
|
702
|
-
const count = cp.tagBalance.get(name) ?? 0;
|
|
703
|
-
if (count > 0) {
|
|
704
|
-
cp.tagBalance.set(name, 0);
|
|
705
|
-
cp.openTotal -= count;
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
if (cp.openStack.length > 0) cp.openStack = cp.openStack.filter((n) => !FOREIGN_ROOT_NAMES.includes(n));
|
|
709
|
-
};
|
|
710
|
-
const noteBreakout = (tag, closing) => {
|
|
711
|
-
if (closing || cp.rawTextOpen !== null) return;
|
|
712
|
-
if (HTML_BREAKOUT_TAGS.has(tag) && !htmlRulesApply()) popForeignRoots();
|
|
713
|
-
};
|
|
776
|
+
const possiblyInsideForeign = () => FOREIGN_ROOT_NAMES.some((name) => (cp.tagBalance.get(name) ?? 0) > 0);
|
|
777
|
+
const honoursSelfClosing = (tag) => tag === "svg" || tag === "math";
|
|
778
|
+
const foreignRawTextSwitchUnknowable = () => possiblyInsideForeign();
|
|
714
779
|
const applyTag = (tag, closing) => {
|
|
715
|
-
if (cp.
|
|
716
|
-
if (cp.
|
|
717
|
-
cp.
|
|
780
|
+
if (inRawTextTok(cp.p5Tok)) {
|
|
781
|
+
if (cp.p5Tok.kind === "script" && cp.p5Tok.escaped && !closing && tag === "script") {
|
|
782
|
+
cp.p5Tok = { ...cp.p5Tok, double: true };
|
|
783
|
+
}
|
|
784
|
+
if (!(closing && tag === rawTextElement(cp.p5Tok))) return;
|
|
785
|
+
if (cp.p5Tok.kind === "script" && cp.p5Tok.double) {
|
|
786
|
+
cp.p5Tok = { ...cp.p5Tok, double: false };
|
|
787
|
+
return;
|
|
718
788
|
}
|
|
719
|
-
|
|
720
|
-
cp.rawTextOpen = null;
|
|
721
|
-
cp.scriptDataEscaped = false;
|
|
789
|
+
cp.p5Tok = { kind: "data" };
|
|
722
790
|
} else {
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
cp.
|
|
727
|
-
|
|
791
|
+
if (!closing && RAW_TEXT_ELEMENTS.has(tag) && foreignRawTextSwitchUnknowable()) {
|
|
792
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
793
|
+
} else if (!closing && RAW_TEXT_ELEMENTS.has(tag)) {
|
|
794
|
+
if (cp.p5Tok.kind !== "data") cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
795
|
+
const openedInline = cp.mdBlock.kind !== "html";
|
|
796
|
+
cp.p5Tok = tag === "script" ? { kind: "script", escaped: false, double: false, openedInline } : { kind: "rawText", element: tag, openedInline };
|
|
728
797
|
if (tag === "plaintext") cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
729
798
|
}
|
|
730
799
|
}
|
|
@@ -752,15 +821,19 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
752
821
|
cp.openTotal += 1;
|
|
753
822
|
}
|
|
754
823
|
};
|
|
755
|
-
const
|
|
756
|
-
const
|
|
757
|
-
const
|
|
758
|
-
|
|
824
|
+
const definitelyInsideTable = () => (cp.tagBalance.get("table") ?? 0) > 0;
|
|
825
|
+
const strayTablePart = (tag) => TABLE_PART_NAMES.has(tag) && !definitelyInsideTable();
|
|
826
|
+
const commentOpenAtLineStart = commentEitherOpen(cp.mdBlock, cp.p5Tok);
|
|
827
|
+
const bothCommentsOpenAtLineStart = mdHtml(cp.mdBlock, 2) && cp.p5Tok.kind === "comment";
|
|
828
|
+
const inDivergenceWindow = mdHtml(cp.mdBlock, 2) && cp.p5Tok.kind !== "comment" || (mdHtml(cp.mdBlock, 3) || mdHtml(cp.mdBlock, 5)) && cp.p5Tok.kind !== "bogus";
|
|
829
|
+
if (inDivergenceWindow && P5_MARKUP_RE.test(ln.text)) {
|
|
830
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
831
|
+
}
|
|
832
|
+
const rawOpenAtLineStart = mdHtml25(cp.mdBlock) || cp.p5Tok.kind === "comment" || cp.p5Tok.kind === "bogus";
|
|
833
|
+
if (cp.mdBlock.kind === "fence") {
|
|
759
834
|
const close = FENCE_RE.exec(ln.text);
|
|
760
|
-
if (close && close[1][0] === cp.
|
|
761
|
-
cp.
|
|
762
|
-
cp.fenceChar = "";
|
|
763
|
-
cp.fenceLen = 0;
|
|
835
|
+
if (close && close[1][0] === cp.mdBlock.char && close[1].length >= cp.mdBlock.len && isMdBlank(ln.text.slice(close[0].length))) {
|
|
836
|
+
cp.mdBlock = { kind: "none" };
|
|
764
837
|
}
|
|
765
838
|
cp.blankRun = 0;
|
|
766
839
|
cp.paragraphHasUnpairedRun = false;
|
|
@@ -768,36 +841,36 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
768
841
|
cp.prevLineBlank = false;
|
|
769
842
|
cp.prevLineWasText = false;
|
|
770
843
|
cp.prevLineWasValidDef = false;
|
|
844
|
+
cp.prevLineOpenContent = false;
|
|
845
|
+
cp.tableMaybeOpen = false;
|
|
771
846
|
return;
|
|
772
847
|
}
|
|
773
|
-
if (
|
|
848
|
+
if (cp.mdBlock.kind !== "math" && !rawOpenAtLineStart) {
|
|
774
849
|
const open = FENCE_RE.exec(ln.text);
|
|
775
850
|
const bogusInfo = open !== null && open[1][0] === "`" && ln.text.slice(ln.text.indexOf(open[1]) + open[1].length).includes("`");
|
|
776
|
-
if (open && !bogusInfo && cp.
|
|
851
|
+
if (open && !bogusInfo && cp.mdBlock.kind === "html") {
|
|
777
852
|
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
778
853
|
} else if (open && !bogusInfo) {
|
|
779
854
|
if (isBlockStart) {
|
|
780
855
|
const verdict = classifyBlockStart(ln.text, ln.indent, cp.defListEnabled);
|
|
781
856
|
if (verdict !== null) cp.hazardVerdict = verdict;
|
|
782
857
|
}
|
|
783
|
-
cp.
|
|
784
|
-
cp.fenceChar = open[1][0];
|
|
785
|
-
cp.fenceLen = open[1].length;
|
|
786
|
-
cp.openIndent = ln.indent;
|
|
858
|
+
cp.mdBlock = { kind: "fence", char: open[1][0], len: open[1].length, indent: ln.indent };
|
|
787
859
|
cp.blankRun = 0;
|
|
788
860
|
cp.paragraphHasUnpairedRun = false;
|
|
789
861
|
cp.openBracket = null;
|
|
790
862
|
cp.prevLineBlank = false;
|
|
791
863
|
cp.prevLineWasText = false;
|
|
792
864
|
cp.prevLineWasValidDef = false;
|
|
865
|
+
cp.prevLineOpenContent = false;
|
|
866
|
+
cp.tableMaybeOpen = false;
|
|
793
867
|
return;
|
|
794
868
|
}
|
|
795
869
|
}
|
|
796
|
-
if (cp.
|
|
870
|
+
if (cp.mdBlock.kind === "math") {
|
|
797
871
|
const close = MATH_RUN_RE.exec(ln.text);
|
|
798
|
-
if (close && close[1].length >= cp.
|
|
799
|
-
cp.
|
|
800
|
-
cp.mathFenceLen = 0;
|
|
872
|
+
if (close && close[1].length >= cp.mdBlock.len && isMdBlank(ln.text.slice(close[0].length))) {
|
|
873
|
+
cp.mdBlock = { kind: "none" };
|
|
801
874
|
}
|
|
802
875
|
cp.blankRun = 0;
|
|
803
876
|
cp.paragraphHasUnpairedRun = false;
|
|
@@ -805,28 +878,30 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
805
878
|
cp.prevLineBlank = false;
|
|
806
879
|
cp.prevLineWasText = false;
|
|
807
880
|
cp.prevLineWasValidDef = false;
|
|
881
|
+
cp.prevLineOpenContent = false;
|
|
882
|
+
cp.tableMaybeOpen = false;
|
|
808
883
|
return;
|
|
809
884
|
}
|
|
810
885
|
const mathRun = cp.mathFlow && !rawOpenAtLineStart ? MATH_RUN_RE.exec(ln.text) : null;
|
|
811
886
|
if (mathRun) {
|
|
812
887
|
const rest = ln.text.slice(ln.text.indexOf(mathRun[1]) + mathRun[1].length);
|
|
813
888
|
if (!rest.includes("$")) {
|
|
814
|
-
if (cp.
|
|
889
|
+
if (cp.mdBlock.kind === "html") {
|
|
815
890
|
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
816
891
|
} else {
|
|
817
892
|
if (isBlockStart) {
|
|
818
893
|
const verdict = classifyBlockStart(ln.text, ln.indent, cp.defListEnabled);
|
|
819
894
|
if (verdict !== null) cp.hazardVerdict = verdict;
|
|
820
895
|
}
|
|
821
|
-
cp.
|
|
822
|
-
cp.mathFenceLen = mathRun[1].length;
|
|
823
|
-
cp.openIndent = ln.indent;
|
|
896
|
+
cp.mdBlock = { kind: "math", len: mathRun[1].length, indent: ln.indent };
|
|
824
897
|
cp.blankRun = 0;
|
|
825
898
|
cp.paragraphHasUnpairedRun = false;
|
|
826
899
|
cp.openBracket = null;
|
|
827
900
|
cp.prevLineBlank = false;
|
|
828
901
|
cp.prevLineWasText = false;
|
|
829
902
|
cp.prevLineWasValidDef = false;
|
|
903
|
+
cp.prevLineOpenContent = false;
|
|
904
|
+
cp.tableMaybeOpen = false;
|
|
830
905
|
return;
|
|
831
906
|
}
|
|
832
907
|
}
|
|
@@ -837,42 +912,46 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
837
912
|
cp.pendingTruncatedTags = [];
|
|
838
913
|
}
|
|
839
914
|
cp.pendingTruncatedCloses = [];
|
|
840
|
-
if (cp.
|
|
915
|
+
if (cp.pendingTag !== null && (cp.pendingTag.attr === '"' || cp.pendingTag.attr === "'")) {
|
|
841
916
|
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
842
917
|
}
|
|
843
|
-
cp.
|
|
844
|
-
cp.
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
918
|
+
cp.pendingTag = null;
|
|
919
|
+
if (cp.p5Tok.kind === "bogus") {
|
|
920
|
+
if (mdHtml25(cp.mdBlock)) {
|
|
921
|
+
} else {
|
|
922
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
923
|
+
cp.p5Tok = { kind: "data" };
|
|
924
|
+
}
|
|
848
925
|
}
|
|
926
|
+
if (cp.mdBlock.kind === "html" && cp.mdBlock.type >= 6) cp.mdBlock = { kind: "none" };
|
|
849
927
|
cp.blankRun += 1;
|
|
850
928
|
cp.lastBlankStart = ln.start;
|
|
851
929
|
cp.candidates.push({
|
|
852
930
|
offset: Math.min(ln.end + 1, text.length),
|
|
853
931
|
blankRun: cp.blankRun,
|
|
854
|
-
//
|
|
855
|
-
// and everything after it as RAW
|
|
856
|
-
//
|
|
857
|
-
//
|
|
858
|
-
//
|
|
859
|
-
|
|
932
|
+
// The html member covers types 1-5 in one check: an unterminated
|
|
933
|
+
// type-1 block swallows this blank and everything after it as RAW
|
|
934
|
+
// content (its tags are invisible to the balance scan — the raw-text
|
|
935
|
+
// mask suppresses them — which is exactly why `openTotal` reads 0
|
|
936
|
+
// and the candidate looked safe), and the 2-5 interiors are the
|
|
937
|
+
// same construct to both grammars.
|
|
938
|
+
htmlBalanced: cp.openTotal === 0 && cp.mdBlock.kind !== "html" && cp.p5Tok.kind !== "bogus",
|
|
860
939
|
hazard: cp.hazardVerdict,
|
|
861
|
-
seamRisk: cp.
|
|
940
|
+
seamRisk: cp.p5SealPending,
|
|
862
941
|
defListSettled: null
|
|
863
942
|
});
|
|
864
943
|
cp.paragraphHasUnpairedRun = false;
|
|
865
944
|
cp.openBracket = null;
|
|
866
|
-
if (!cp.
|
|
867
|
-
cp.
|
|
868
|
-
cp.htmlFlowReal = false;
|
|
869
|
-
if (cp.rawTextOpen !== null && !cp.rawTextInline) {
|
|
945
|
+
if (!mdHtml(cp.mdBlock, 1)) {
|
|
946
|
+
if (inRawTextTok(cp.p5Tok) && !cp.p5Tok.openedInline) {
|
|
870
947
|
cp.phasePoisonedAt = 0;
|
|
871
948
|
}
|
|
872
949
|
}
|
|
873
950
|
cp.prevLineBlank = true;
|
|
874
951
|
cp.prevLineWasText = false;
|
|
875
952
|
cp.prevLineWasValidDef = false;
|
|
953
|
+
cp.prevLineOpenContent = false;
|
|
954
|
+
cp.tableMaybeOpen = false;
|
|
876
955
|
return;
|
|
877
956
|
}
|
|
878
957
|
if (isBlockStart) {
|
|
@@ -883,86 +962,34 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
883
962
|
}
|
|
884
963
|
const tagStart = ln.indent <= 3 ? /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(mdTrimStart(ln.text)) : null;
|
|
885
964
|
if (tagStart) {
|
|
886
|
-
const noRealBlockOpen =
|
|
887
|
-
cp.
|
|
888
|
-
if (
|
|
889
|
-
if (!TYPE6_NAMES.has(tagStart[1].toLowerCase())) cp.hazardVerdict = true;
|
|
890
|
-
if (!cp.htmlFlowReal) {
|
|
965
|
+
const noRealBlockOpen = cp.mdBlock.kind !== "html";
|
|
966
|
+
if (noRealBlockOpen && TYPE1_START_RE.test(mdTrimStart(ln.text))) cp.mdBlock = { kind: "html", type: 1 };
|
|
967
|
+
if (cp.mdBlock.kind !== "html") {
|
|
891
968
|
const t = mdTrimStart(ln.text);
|
|
892
969
|
const t6 = TYPE6_START_RE.exec(t);
|
|
893
|
-
const
|
|
894
|
-
if (
|
|
895
|
-
//
|
|
896
|
-
|
|
897
|
-
|
|
970
|
+
const realT6 = t6 !== null && TYPE6_NAMES.has(t6[1].toLowerCase());
|
|
971
|
+
if (realT6 || TYPE1_START_RE.test(t) || // Type 7 cannot interrupt CONTENT (micromark's paragraph/definition
|
|
972
|
+
// construct — `prevLineOpenContent`, the exact interrupt input; the
|
|
973
|
+
// old `prevLineWasText` gate refused after headings, terminator
|
|
974
|
+
// lines and fence closes, where micromark measurably opens). The
|
|
975
|
+
// classifier itself is exact too (isType7Line) — including closing
|
|
976
|
+
// raw-text names (`</style>` alone is type 7, measured) and
|
|
977
|
+
// quoted-`>` attribute values.
|
|
978
|
+
!cp.prevLineOpenContent && isType7Line(t)) {
|
|
979
|
+
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: realT6 ? 6 : 7 };
|
|
980
|
+
} else if (cp.prevLineOpenContent && cp.tableMaybeOpen && isType7Line(t)) {
|
|
981
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
898
982
|
}
|
|
899
983
|
}
|
|
900
984
|
}
|
|
901
|
-
const inRawText = cp.htmlFlowSinceBlank || rawOpenAtLineStart;
|
|
902
985
|
const rawFlowStart = ln.indent <= 3 && /^<(?:!--|\?|![A-Za-z]|!\[CDATA\[)/.test(mdTrimStart(ln.text));
|
|
903
|
-
const
|
|
986
|
+
const htmlOwnedLine = cp.mdBlock.kind === "html" || rawOpenAtLineStart || rawFlowStart;
|
|
987
|
+
const maskingSuppressed = htmlOwnedLine || inRawTextTok(cp.p5Tok);
|
|
988
|
+
const { masked, unpaired } = maskingSuppressed ? { masked: null, unpaired: false } : maskIntraLineCodeSpans(ln.text, cp.paragraphHasUnpairedRun);
|
|
904
989
|
if (unpaired) cp.paragraphHasUnpairedRun = true;
|
|
905
990
|
const scanText = masked ?? ln.text;
|
|
906
|
-
const
|
|
907
|
-
const
|
|
908
|
-
const defLineStart = isBlockStart || !cp.prevLineWasText || cp.prevLineWasValidDef;
|
|
909
|
-
const validDef = def !== null && defLineStart;
|
|
910
|
-
if (validDef) {
|
|
911
|
-
const label = def[1];
|
|
912
|
-
if (label.startsWith("^")) {
|
|
913
|
-
const key = normalizeLabel(label.slice(1));
|
|
914
|
-
if (key && !cp.footnoteDefs.has(key)) cp.footnoteDefs.set(key, ln.end);
|
|
915
|
-
} else {
|
|
916
|
-
const key = normalizeLabel(label);
|
|
917
|
-
if (key && !cp.defs.has(key)) cp.defs.set(key, ln.end);
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
if (cp.referenceTaint) {
|
|
921
|
-
const pushRef = (offset, inner, followAt) => {
|
|
922
|
-
const follow = scanText[followAt];
|
|
923
|
-
if (follow === "(" && inlineResourceEnd(scanText, followAt) !== -1) return;
|
|
924
|
-
let label;
|
|
925
|
-
let footnote = false;
|
|
926
|
-
if (inner.startsWith("^")) {
|
|
927
|
-
footnote = true;
|
|
928
|
-
label = normalizeLabel(inner.slice(1));
|
|
929
|
-
} else if (follow === "[") {
|
|
930
|
-
const explicit = /^\[((?:[^[\]\\]|\\.)*)\]/.exec(scanText.slice(followAt));
|
|
931
|
-
label = normalizeLabel(explicit && explicit[1] ? explicit[1] : inner);
|
|
932
|
-
} else {
|
|
933
|
-
label = normalizeLabel(inner);
|
|
934
|
-
}
|
|
935
|
-
if (label) cp.unresolvedRefs.push({ offset, label, footnote });
|
|
936
|
-
};
|
|
937
|
-
const pending = cp.openBracket;
|
|
938
|
-
cp.openBracket = null;
|
|
939
|
-
if (pending) {
|
|
940
|
-
const close = firstUnescaped(scanText, "]");
|
|
941
|
-
const open = firstUnescaped(scanText, "[");
|
|
942
|
-
const cont = (t) => t.replace(/^ {0,3}>[ \t]?/, "");
|
|
943
|
-
if (close !== -1 && (open === -1 || close < open)) {
|
|
944
|
-
pushRef(pending.offset, `${pending.text}
|
|
945
|
-
${cont(scanText.slice(0, close))}`, close + 1);
|
|
946
|
-
} else if (close === -1 && open === -1) {
|
|
947
|
-
cp.openBracket = { offset: pending.offset, text: `${pending.text}
|
|
948
|
-
${cont(scanText)}` };
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
if (scanText.includes("[")) {
|
|
952
|
-
const defBracket = validDef ? def.index + def[0].indexOf("[") : -1;
|
|
953
|
-
REF_RE.lastIndex = 0;
|
|
954
|
-
let m;
|
|
955
|
-
while ((m = REF_RE.exec(scanText)) !== null) {
|
|
956
|
-
const followAt = m.index + m[0].length;
|
|
957
|
-
if (scanText[followAt] === ":" && m.index === defBracket) continue;
|
|
958
|
-
pushRef(ln.start + m.index, m[1], followAt);
|
|
959
|
-
}
|
|
960
|
-
const trailingOpen = lastUnclosedBracket(scanText);
|
|
961
|
-
if (trailingOpen !== -1) {
|
|
962
|
-
cp.openBracket = { offset: ln.start + trailingOpen, text: scanText.slice(trailingOpen + 1) };
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
}
|
|
991
|
+
const defRawToMicromark = cp.mdBlock.kind === "html" || rawOpenAtLineStart || inRawTextTok(cp.p5Tok);
|
|
992
|
+
const { validLinkDef } = collectRefLine(cp, ln.start, ln.end, scanText, defRawToMicromark, isBlockStart);
|
|
966
993
|
const rawSpans = [];
|
|
967
994
|
let pos = 0;
|
|
968
995
|
const poisonRawDivergence = () => {
|
|
@@ -970,60 +997,71 @@ ${cont(scanText)}` };
|
|
|
970
997
|
};
|
|
971
998
|
let inlineRawOpenerIdx = -1;
|
|
972
999
|
while (pos < scanText.length) {
|
|
973
|
-
if (cp.
|
|
974
|
-
const
|
|
975
|
-
const
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1000
|
+
if (mdHtml(cp.mdBlock, 3) || mdHtml(cp.mdBlock, 5)) {
|
|
1001
|
+
const isPi = mdHtml(cp.mdBlock, 3);
|
|
1002
|
+
const term = isPi ? "?>" : "]]>";
|
|
1003
|
+
const c = scanText.indexOf(term, pos);
|
|
1004
|
+
const mdEnd = c === -1 ? scanText.length : c + term.length;
|
|
1005
|
+
if (cp.p5Tok.kind === "bogus") {
|
|
1006
|
+
const gt = scanText.indexOf(">", pos);
|
|
1007
|
+
if (gt !== -1 && (c === -1 || gt !== c + term.length - 1)) {
|
|
1008
|
+
cp.p5Tok = { kind: "data" };
|
|
1009
|
+
rawSpans.push([pos, gt + 1]);
|
|
1010
|
+
if (P5_MARKUP_RE.test(scanText.slice(gt + 1, c === -1 ? scanText.length : c))) {
|
|
1011
|
+
poisonRawDivergence();
|
|
1012
|
+
}
|
|
1013
|
+
} else {
|
|
1014
|
+
rawSpans.push([pos, mdEnd]);
|
|
1015
|
+
if (c !== -1) cp.p5Tok = { kind: "data" };
|
|
1016
|
+
}
|
|
980
1017
|
}
|
|
981
|
-
|
|
982
|
-
cp.
|
|
983
|
-
pos =
|
|
1018
|
+
if (c === -1) break;
|
|
1019
|
+
cp.mdBlock = { kind: "none" };
|
|
1020
|
+
pos = mdEnd;
|
|
984
1021
|
continue;
|
|
985
1022
|
}
|
|
986
|
-
if (cp.
|
|
987
|
-
const c = scanText.indexOf("
|
|
988
|
-
const gt = scanText.indexOf(">", pos);
|
|
989
|
-
if (gt !== -1 && (c === -1 || gt !== c + 2)) poisonRawDivergence();
|
|
1023
|
+
if (mdHtml(cp.mdBlock, 4)) {
|
|
1024
|
+
const c = scanText.indexOf(">", pos);
|
|
990
1025
|
if (c === -1) {
|
|
991
1026
|
rawSpans.push([pos, scanText.length]);
|
|
992
1027
|
break;
|
|
993
1028
|
}
|
|
994
|
-
rawSpans.push([pos, c +
|
|
995
|
-
cp.
|
|
996
|
-
|
|
1029
|
+
rawSpans.push([pos, c + 1]);
|
|
1030
|
+
cp.mdBlock = { kind: "none" };
|
|
1031
|
+
if (cp.p5Tok.kind === "bogus") cp.p5Tok = { kind: "data" };
|
|
1032
|
+
pos = c + 1;
|
|
997
1033
|
continue;
|
|
998
1034
|
}
|
|
999
|
-
if (cp.
|
|
1035
|
+
if (cp.p5Tok.kind === "bogus") {
|
|
1000
1036
|
const c = scanText.indexOf(">", pos);
|
|
1001
1037
|
if (c === -1) {
|
|
1002
1038
|
rawSpans.push([pos, scanText.length]);
|
|
1003
1039
|
break;
|
|
1004
1040
|
}
|
|
1005
1041
|
rawSpans.push([pos, c + 1]);
|
|
1006
|
-
cp.
|
|
1007
|
-
cp.bogusOpen = false;
|
|
1042
|
+
cp.p5Tok = { kind: "data" };
|
|
1008
1043
|
pos = c + 1;
|
|
1009
1044
|
continue;
|
|
1010
1045
|
}
|
|
1046
|
+
if (commentOpenAtLineStart || inRawTextTok(cp.p5Tok) || mdHtml(cp.mdBlock, 1)) break;
|
|
1011
1047
|
const pi = scanText.indexOf("<?", pos);
|
|
1012
1048
|
const cd = scanText.indexOf("<![CDATA[", pos);
|
|
1013
1049
|
const dm = scanText.slice(pos).search(/<![A-Za-z]/);
|
|
1014
1050
|
const decl = dm === -1 ? -1 : pos + dm;
|
|
1015
|
-
const bm = cp.
|
|
1051
|
+
const bm = cp.mdBlock.kind === "html" ? scanText.slice(pos).search(/<!(?!--|[A-Za-z]|\[CDATA\[)|<\/(?![A-Za-z])/) : -1;
|
|
1016
1052
|
const bogus = bm === -1 ? -1 : pos + bm;
|
|
1017
1053
|
const starts = [pi, cd, decl, bogus].filter((x) => x !== -1);
|
|
1018
1054
|
if (starts.length === 0) break;
|
|
1019
1055
|
const first = Math.min(...starts);
|
|
1020
1056
|
if (first === bogus) {
|
|
1021
1057
|
rawSpans.push([bogus, bogus + 2]);
|
|
1022
|
-
cp.
|
|
1058
|
+
if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
|
|
1059
|
+
else cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
1023
1060
|
pos = bogus + 2;
|
|
1024
1061
|
} else if (first === cd) {
|
|
1025
1062
|
rawSpans.push([cd, cd + 9]);
|
|
1026
|
-
cp.
|
|
1063
|
+
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 5 };
|
|
1064
|
+
if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
|
|
1027
1065
|
if (!isMdBlank(scanText.slice(0, cd)) || ln.indent > 3) inlineRawOpenerIdx = cd;
|
|
1028
1066
|
pos = cd + 9;
|
|
1029
1067
|
} else if (first === pi) {
|
|
@@ -1034,18 +1072,20 @@ ${cont(scanText)}` };
|
|
|
1034
1072
|
continue;
|
|
1035
1073
|
}
|
|
1036
1074
|
rawSpans.push([pi, pi + 2]);
|
|
1037
|
-
cp.
|
|
1075
|
+
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 3 };
|
|
1076
|
+
if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
|
|
1038
1077
|
if (!isMdBlank(scanText.slice(0, pi)) || ln.indent > 3) inlineRawOpenerIdx = pi;
|
|
1039
1078
|
pos = pi + 2;
|
|
1040
1079
|
} else {
|
|
1041
1080
|
rawSpans.push([decl, decl + 2]);
|
|
1042
1081
|
if (ln.indent <= 3 && /^doctype/i.test(scanText.slice(decl + 2))) cp.phasePoisonedAt = 0;
|
|
1043
|
-
cp.
|
|
1082
|
+
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 4 };
|
|
1083
|
+
if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
|
|
1044
1084
|
if (!isMdBlank(scanText.slice(0, decl)) || ln.indent > 3) inlineRawOpenerIdx = decl;
|
|
1045
1085
|
pos = decl + 2;
|
|
1046
1086
|
}
|
|
1047
1087
|
}
|
|
1048
|
-
if (inlineRawOpenerIdx !== -1 &&
|
|
1088
|
+
if (inlineRawOpenerIdx !== -1 && cp.mdBlock.kind === "html" && cp.mdBlock.type >= 3) {
|
|
1049
1089
|
cp.phasePoisonedAt = 0;
|
|
1050
1090
|
}
|
|
1051
1091
|
let tagText = scanText;
|
|
@@ -1053,19 +1093,18 @@ ${cont(scanText)}` };
|
|
|
1053
1093
|
tagText = tagText.slice(0, from) + " ".repeat(to - from) + tagText.slice(to);
|
|
1054
1094
|
}
|
|
1055
1095
|
let skipTagScan = false;
|
|
1056
|
-
if (cp.
|
|
1057
|
-
if (ln.indent < cp.
|
|
1058
|
-
const attrs = { state: cp.
|
|
1096
|
+
if (cp.pendingTag !== null) {
|
|
1097
|
+
if (ln.indent < cp.pendingTag.indent) poisonRawDivergence();
|
|
1098
|
+
const attrs = { state: cp.pendingTag.attr };
|
|
1059
1099
|
const gt = scanTagAttrs(ln.text, 0, ln.text.length, attrs);
|
|
1060
1100
|
if (gt === -1) {
|
|
1061
1101
|
scanTagAttrs("\n", 0, 1, attrs);
|
|
1062
|
-
cp.
|
|
1102
|
+
cp.pendingTag = { attr: attrs.state, indent: cp.pendingTag.indent };
|
|
1063
1103
|
skipTagScan = true;
|
|
1064
1104
|
} else {
|
|
1065
1105
|
for (const tag of cp.pendingTruncatedCloses) applyTag(tag, true);
|
|
1066
1106
|
cp.pendingTruncatedCloses = [];
|
|
1067
|
-
cp.
|
|
1068
|
-
cp.tagAcrossLinesState = "outside";
|
|
1107
|
+
cp.pendingTag = null;
|
|
1069
1108
|
tagText = " ".repeat(gt + 1) + tagText.slice(gt + 1);
|
|
1070
1109
|
}
|
|
1071
1110
|
}
|
|
@@ -1075,38 +1114,53 @@ ${cont(scanText)}` };
|
|
|
1075
1114
|
let m;
|
|
1076
1115
|
let lastCommentOpenerIdx = -1;
|
|
1077
1116
|
while ((m = TAG_OR_COMMENT_RE.exec(tagText)) !== null) {
|
|
1078
|
-
if (cp.
|
|
1079
|
-
if (cp.
|
|
1117
|
+
if (inRawTextTok(cp.p5Tok) && (m[0] === "<!--" || m[0] === "-->" || m[0] === "--!>")) {
|
|
1118
|
+
if (cp.p5Tok.kind === "script") {
|
|
1119
|
+
if (m[0] === "<!--") cp.p5Tok = { ...cp.p5Tok, escaped: true };
|
|
1120
|
+
if (m[0] === "-->") cp.p5Tok = { ...cp.p5Tok, escaped: false, double: false };
|
|
1121
|
+
}
|
|
1080
1122
|
continue;
|
|
1081
1123
|
}
|
|
1082
1124
|
if (m[0] === "<!--") {
|
|
1083
1125
|
const next = tagText.slice(m.index + 4, m.index + 6);
|
|
1084
|
-
if (cp.
|
|
1085
|
-
if (next.startsWith(">") || next === "->")
|
|
1086
|
-
|
|
1126
|
+
if (commentEitherOpen(cp.mdBlock, cp.p5Tok)) {
|
|
1127
|
+
if (next.startsWith(">") || next === "->") {
|
|
1128
|
+
if (mdHtml(cp.mdBlock, 2)) cp.mdBlock = { kind: "none" };
|
|
1129
|
+
if (cp.p5Tok.kind === "comment") cp.p5Tok = { kind: "data" };
|
|
1130
|
+
} else if (next === "!>" || next === "-!") {
|
|
1131
|
+
if (cp.p5Tok.kind === "comment") cp.p5Tok = { kind: "data" };
|
|
1132
|
+
if (mdHtml(cp.mdBlock, 2) && P5_MARKUP_RE.test(tagText.slice(m.index + m[0].length))) {
|
|
1133
|
+
poisonRawDivergence();
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1087
1136
|
continue;
|
|
1088
1137
|
}
|
|
1089
1138
|
if (next.startsWith(">") || next === "->") {
|
|
1090
1139
|
continue;
|
|
1091
1140
|
}
|
|
1092
|
-
cp.
|
|
1141
|
+
if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 2 };
|
|
1142
|
+
if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "comment" };
|
|
1093
1143
|
lastCommentOpenerIdx = m.index;
|
|
1094
1144
|
continue;
|
|
1095
1145
|
}
|
|
1096
1146
|
if (m[0] === "-->") {
|
|
1097
|
-
cp.
|
|
1147
|
+
if (mdHtml(cp.mdBlock, 2)) cp.mdBlock = { kind: "none" };
|
|
1148
|
+
if (cp.p5Tok.kind === "comment") cp.p5Tok = { kind: "data" };
|
|
1098
1149
|
continue;
|
|
1099
1150
|
}
|
|
1100
1151
|
if (m[0] === "--!>") {
|
|
1101
|
-
if (cp.
|
|
1152
|
+
if (mdHtml(cp.mdBlock, 2) && P5_MARKUP_RE.test(tagText.slice(m.index + m[0].length))) {
|
|
1153
|
+
poisonRawDivergence();
|
|
1154
|
+
}
|
|
1155
|
+
if (cp.p5Tok.kind === "comment") cp.p5Tok = { kind: "data" };
|
|
1102
1156
|
continue;
|
|
1103
1157
|
}
|
|
1104
|
-
if (cp.
|
|
1158
|
+
if (commentEitherOpen(cp.mdBlock, cp.p5Tok)) continue;
|
|
1105
1159
|
const closing = m[1] === "/";
|
|
1106
1160
|
const tag = m[2].toLowerCase();
|
|
1107
1161
|
if (strayTablePart(tag)) cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start + m.index);
|
|
1108
1162
|
let attrs = m[3] ?? "";
|
|
1109
|
-
if (cp.
|
|
1163
|
+
if (cp.mdBlock.kind === "html" && (!inRawTextTok(cp.p5Tok) || closing && tag === rawTextElement(cp.p5Tok))) {
|
|
1110
1164
|
const attrStart = m.index + 1 + (closing ? 1 : 0) + m[2].length;
|
|
1111
1165
|
const st = { state: "outside" };
|
|
1112
1166
|
const gt = scanTagAttrs(tagText, attrStart, tagText.length, st);
|
|
@@ -1116,9 +1170,7 @@ ${cont(scanText)}` };
|
|
|
1116
1170
|
else applyTag(tag, false);
|
|
1117
1171
|
}
|
|
1118
1172
|
scanTagAttrs("\n", 0, 1, st);
|
|
1119
|
-
cp.
|
|
1120
|
-
cp.tagAcrossLinesIndent = ln.indent;
|
|
1121
|
-
cp.tagAcrossLinesState = st.state;
|
|
1173
|
+
cp.pendingTag = { attr: st.state, indent: ln.indent };
|
|
1122
1174
|
tagHandledAsTruncated = true;
|
|
1123
1175
|
break;
|
|
1124
1176
|
}
|
|
@@ -1127,16 +1179,15 @@ ${cont(scanText)}` };
|
|
|
1127
1179
|
TAG_OR_COMMENT_RE.lastIndex = gt + 1;
|
|
1128
1180
|
}
|
|
1129
1181
|
}
|
|
1130
|
-
if (closing &&
|
|
1182
|
+
if (closing && cp.mdBlock.kind !== "html" && !/^\s*$/.test(attrs)) {
|
|
1131
1183
|
TAG_OR_COMMENT_RE.lastIndex = m.index + 2 + m[2].length;
|
|
1132
1184
|
continue;
|
|
1133
1185
|
}
|
|
1134
1186
|
const selfClosing = /\/\s*$/.test(attrs);
|
|
1135
|
-
noteBreakout(tag, closing);
|
|
1136
1187
|
if (VOID_TAGS.has(tag) || selfClosing && honoursSelfClosing(tag)) continue;
|
|
1137
1188
|
applyTag(tag, closing);
|
|
1138
1189
|
}
|
|
1139
|
-
if (cp.
|
|
1190
|
+
if (commentEitherOpen(cp.mdBlock, cp.p5Tok) && lastCommentOpenerIdx !== -1) {
|
|
1140
1191
|
if (!isMdBlank(tagText.slice(0, lastCommentOpenerIdx)) || ln.indent > 3) {
|
|
1141
1192
|
cp.phasePoisonedAt = 0;
|
|
1142
1193
|
}
|
|
@@ -1149,13 +1200,12 @@ ${cont(scanText)}` };
|
|
|
1149
1200
|
if (mr[0] === "<!--" || mr[0] === "-->" || mr[0] === "--!>") continue;
|
|
1150
1201
|
const startMasked = masked[mr.index] !== ln.text[mr.index];
|
|
1151
1202
|
const wholeVisible = masked.slice(mr.index, mr.index + mr[0].length) === mr[0];
|
|
1152
|
-
if (startMasked || wholeVisible || inRaw(mr.index) || cp.
|
|
1203
|
+
if (startMasked || wholeVisible || inRaw(mr.index) || commentEitherOpen(cp.mdBlock, cp.p5Tok)) continue;
|
|
1153
1204
|
const closing = mr[1] === "/";
|
|
1154
1205
|
const tag = mr[2].toLowerCase();
|
|
1155
1206
|
if (strayTablePart(tag)) cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start + mr.index);
|
|
1156
1207
|
if (closing && mr[3] !== void 0 && !/^\s*$/.test(mr[3])) continue;
|
|
1157
1208
|
const selfClosing = mr[3] !== void 0 && /\/\s*$/.test(mr[3]);
|
|
1158
|
-
noteBreakout(tag, closing);
|
|
1159
1209
|
if (VOID_TAGS.has(tag) || selfClosing && honoursSelfClosing(tag)) continue;
|
|
1160
1210
|
applyTag(tag, closing);
|
|
1161
1211
|
}
|
|
@@ -1166,7 +1216,7 @@ ${cont(scanText)}` };
|
|
|
1166
1216
|
}
|
|
1167
1217
|
cp.pendingTruncatedTags = [];
|
|
1168
1218
|
}
|
|
1169
|
-
if (!cp.
|
|
1219
|
+
if (!commentEitherOpen(cp.mdBlock, cp.p5Tok) && !tagHandledAsTruncated) {
|
|
1170
1220
|
let lastLt = -1;
|
|
1171
1221
|
TAG_START_LT_RE.lastIndex = 0;
|
|
1172
1222
|
for (let ms = TAG_START_LT_RE.exec(tagText); ms !== null; ms = TAG_START_LT_RE.exec(tagText)) {
|
|
@@ -1178,30 +1228,30 @@ ${cont(scanText)}` };
|
|
|
1178
1228
|
if (m2) {
|
|
1179
1229
|
const closing = m2[1] === "/";
|
|
1180
1230
|
const tag = m2[2].toLowerCase();
|
|
1181
|
-
if (strayTablePart(tag) && cp.
|
|
1231
|
+
if (strayTablePart(tag) && cp.mdBlock.kind === "html") {
|
|
1182
1232
|
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start + lastLt);
|
|
1183
1233
|
}
|
|
1184
|
-
if (cp.
|
|
1185
|
-
cp.tagAcrossLines = true;
|
|
1186
|
-
cp.tagAcrossLinesIndent = ln.indent;
|
|
1234
|
+
if (cp.mdBlock.kind === "html") {
|
|
1187
1235
|
const attrs = { state: "outside" };
|
|
1188
1236
|
scanTagAttrs(m2[3] + "\n", 0, m2[3].length + 1, attrs);
|
|
1189
|
-
cp.
|
|
1237
|
+
cp.pendingTag = { attr: attrs.state, indent: ln.indent };
|
|
1190
1238
|
}
|
|
1191
1239
|
if (closing) {
|
|
1192
|
-
if (!VOID_TAGS.has(tag) && cp.
|
|
1240
|
+
if (!VOID_TAGS.has(tag) && cp.mdBlock.kind === "html") cp.pendingTruncatedCloses.push(tag);
|
|
1193
1241
|
} else if (!VOID_TAGS.has(tag)) {
|
|
1194
1242
|
applyTag(tag, closing);
|
|
1195
1243
|
const rawLastLt = ln.text.lastIndexOf("<");
|
|
1196
1244
|
const rawTruncated = rawLastLt !== -1 && !ln.text.includes(">", rawLastLt);
|
|
1197
|
-
if (!closing && !
|
|
1245
|
+
if (!closing && !(htmlOwnedLine || inRawTextTok(cp.p5Tok)) && rawTruncated) {
|
|
1246
|
+
cp.pendingTruncatedTags.push(tag);
|
|
1247
|
+
}
|
|
1198
1248
|
}
|
|
1199
1249
|
}
|
|
1200
1250
|
}
|
|
1201
1251
|
}
|
|
1202
1252
|
}
|
|
1203
1253
|
const effectiveOpen = cp.openTotal - cp.pendingTruncatedTags.length;
|
|
1204
|
-
if ((
|
|
1254
|
+
if ((htmlOwnedLine || inRawTextTok(cp.p5Tok)) && effectiveOpen <= 0) {
|
|
1205
1255
|
let masked2 = "";
|
|
1206
1256
|
let cursor = 0;
|
|
1207
1257
|
for (const [from, to] of rawSpans) {
|
|
@@ -1209,22 +1259,38 @@ ${cont(scanText)}` };
|
|
|
1209
1259
|
cursor = to;
|
|
1210
1260
|
}
|
|
1211
1261
|
masked2 += scanText.slice(cursor);
|
|
1212
|
-
if (floatingResidue(masked2,
|
|
1213
|
-
cp.
|
|
1262
|
+
if (floatingResidue(masked2, bothCommentsOpenAtLineStart).length > 0) {
|
|
1263
|
+
cp.p5SealPending = true;
|
|
1214
1264
|
}
|
|
1215
1265
|
}
|
|
1216
|
-
if (cp.
|
|
1266
|
+
if (inRawTextTok(cp.p5Tok) && cp.p5Tok.openedInline) {
|
|
1217
1267
|
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
1218
1268
|
}
|
|
1219
|
-
if (cp.
|
|
1220
|
-
cp.
|
|
1221
|
-
cp.
|
|
1222
|
-
cp.htmlFlowReal = false;
|
|
1269
|
+
if (mdHtml(cp.mdBlock, 1) && TYPE1_CLOSE_RE.test(ln.text)) {
|
|
1270
|
+
cp.mdBlock = { kind: "none" };
|
|
1271
|
+
if (inRawTextTok(cp.p5Tok)) cp.phasePoisonedAt = 0;
|
|
1223
1272
|
}
|
|
1224
1273
|
cp.blankRun = 0;
|
|
1225
1274
|
cp.prevLineBlank = false;
|
|
1226
1275
|
cp.prevLineWasText = true;
|
|
1227
|
-
|
|
1276
|
+
{
|
|
1277
|
+
const tt = mdTrimStart(ln.text);
|
|
1278
|
+
let openContent;
|
|
1279
|
+
if (htmlOwnedLine) {
|
|
1280
|
+
openContent = false;
|
|
1281
|
+
} else if (ln.indent >= 4) {
|
|
1282
|
+
openContent = cp.prevLineOpenContent;
|
|
1283
|
+
} else if (ATX_HEADING_RE.test(tt) || THEMATIC_BREAK_RE.test(tt) || BARE_MARKER_RE.test(tt)) {
|
|
1284
|
+
openContent = false;
|
|
1285
|
+
} else if (SETEXT_LEFTOVER_RE.test(tt)) {
|
|
1286
|
+
openContent = !cp.prevLineOpenContent;
|
|
1287
|
+
} else {
|
|
1288
|
+
openContent = true;
|
|
1289
|
+
}
|
|
1290
|
+
cp.prevLineOpenContent = openContent;
|
|
1291
|
+
cp.tableMaybeOpen = ln.text.includes("|") || cp.tableMaybeOpen && openContent;
|
|
1292
|
+
}
|
|
1293
|
+
cp.prevLineWasValidDef = validLinkDef;
|
|
1228
1294
|
}
|
|
1229
1295
|
|
|
1230
1296
|
// src/components/incrementalParse/spliceParse.ts
|
|
@@ -1473,6 +1539,33 @@ function headRoutedCaptureUnclosed(values) {
|
|
|
1473
1539
|
return !new RegExp(`</${name}(?=[\\s/>])`, "i").test(after);
|
|
1474
1540
|
}
|
|
1475
1541
|
var STRAY_SYNTHESIZED_END_TAG_RE = /<\/(?:br|p)\b/i;
|
|
1542
|
+
var RAW_TEXT_OPEN_RE = /<(script|style|textarea|title|xmp|iframe|noembed|noframes|plaintext)(?=[\s/>])/gi;
|
|
1543
|
+
function rawTextRegionCrossesOut(values) {
|
|
1544
|
+
for (const value of values) {
|
|
1545
|
+
let pos = 0;
|
|
1546
|
+
for (; ; ) {
|
|
1547
|
+
RAW_TEXT_OPEN_RE.lastIndex = pos;
|
|
1548
|
+
const open = RAW_TEXT_OPEN_RE.exec(value);
|
|
1549
|
+
if (open === null) break;
|
|
1550
|
+
const name = open[1].toLowerCase();
|
|
1551
|
+
const bodyStart = open.index + open[0].length;
|
|
1552
|
+
const closeRe = new RegExp(`</${name}(?=[\\s/>])`, "ig");
|
|
1553
|
+
closeRe.lastIndex = bodyStart;
|
|
1554
|
+
let close = closeRe.exec(value);
|
|
1555
|
+
if (name === "script") {
|
|
1556
|
+
while (close !== null) {
|
|
1557
|
+
const body = value.slice(bodyStart, close.index);
|
|
1558
|
+
const lastOpen = body.lastIndexOf("<!--");
|
|
1559
|
+
if (lastOpen === -1 || body.indexOf("-->", lastOpen + 4) !== -1) break;
|
|
1560
|
+
close = closeRe.exec(value);
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
if (close === null) return true;
|
|
1564
|
+
pos = close.index + close[0].length;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
return false;
|
|
1568
|
+
}
|
|
1476
1569
|
function spliceTrees(input) {
|
|
1477
1570
|
const { prevMdast, prevHast, tailMdast, tailHast, content, boundary, injectionPrefix, injectedSegments } = input;
|
|
1478
1571
|
const injectedLen = injectionPrefix.length;
|
|
@@ -1529,7 +1622,9 @@ function spliceTrees(input) {
|
|
|
1529
1622
|
return !(start !== void 0 && start < injectedLen);
|
|
1530
1623
|
});
|
|
1531
1624
|
const tailWrapVisible = tailMdastChildren.some((child) => !isWrapInvisible(child));
|
|
1532
|
-
|
|
1625
|
+
const prefixHtmlValues = prefixMdast.flatMap((c) => c.type === "html" ? [c.value] : []);
|
|
1626
|
+
if (hasStrayTablePart(prefixHtmlValues)) return null;
|
|
1627
|
+
if (rawTextRegionCrossesOut(prefixHtmlValues)) return null;
|
|
1533
1628
|
const leadingHtml = [];
|
|
1534
1629
|
for (const child of tailMdastChildren) {
|
|
1535
1630
|
if (isWrapInvisible(child)) continue;
|