@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 CHANGED
@@ -267,7 +267,199 @@ var defaultUrlTransform = (value) => {
267
267
 
268
268
  // src/components/incrementalParse/computeFreezeBoundary.ts
269
269
  var import_micromark_util_html_tag_name = require("micromark-util-html-tag-name");
270
+
271
+ // src/components/incrementalParse/mdLineText.ts
272
+ var MD_BLANK_RE = /^[ \t\r]*$/;
273
+ var isMdBlank = (text) => MD_BLANK_RE.test(text);
274
+ var mdTrim = (text) => text.replace(/^[ \t\r]+|[ \t\r]+$/g, "");
275
+ var mdTrimStart = (text) => text.replace(/^[ \t\r]+/, "");
276
+
277
+ // src/components/incrementalParse/referenceTaint.ts
270
278
  var import_micromark_util_normalize_identifier = require("micromark-util-normalize-identifier");
279
+ var FOOTNOTE_DEF_RE = /^ {0,3}\[\^[^\]]*\]:/;
280
+ var DEF_RE = /^ {0,3}\[((?:[^[\]\\]|\\.)+)\]:/;
281
+ var REF_RE = /!?\[((?:[^[\]\\]|\\.)*)\]/g;
282
+ function firstUnescaped(text, ch) {
283
+ for (let i = 0; i < text.length; i++) {
284
+ if (text[i] === "\\") i += 1;
285
+ else if (text[i] === ch) return i;
286
+ }
287
+ return -1;
288
+ }
289
+ function lastUnclosedBracket(text) {
290
+ let open = -1;
291
+ for (let i = 0; i < text.length; i++) {
292
+ const c = text[i];
293
+ if (c === "\\") i += 1;
294
+ else if (c === "[") open = i;
295
+ else if (c === "]") open = -1;
296
+ }
297
+ return open;
298
+ }
299
+ function normalizeLabel(label) {
300
+ const collapsed = label.replace(/[ \t\r\n]+/g, " ").replace(/^ | $/g, "");
301
+ return collapsed ? (0, import_micromark_util_normalize_identifier.normalizeIdentifier)(collapsed) : "";
302
+ }
303
+ function isPlausibleLinkDefRest(rest) {
304
+ const t = mdTrim(rest);
305
+ if (t === "") return false;
306
+ const destEnd = linkDestinationEnd(t);
307
+ if (destEnd === -1) return false;
308
+ const after = mdTrim(t.slice(destEnd));
309
+ if (after === "") return true;
310
+ const opener = after[0];
311
+ if (opener !== '"' && opener !== "'" && opener !== "(") return false;
312
+ const closer = opener === "(" ? ")" : opener;
313
+ for (let i = 1; i < after.length; i++) {
314
+ if (after[i] === "\\") {
315
+ i += 1;
316
+ continue;
317
+ }
318
+ if (after[i] === closer) return isMdBlank(after.slice(i + 1));
319
+ }
320
+ return false;
321
+ }
322
+ function linkDestinationEnd(t) {
323
+ if (t.startsWith("<")) {
324
+ for (let i2 = 1; i2 < t.length; i2++) {
325
+ const ch = t[i2];
326
+ if (ch === "\\" && (t[i2 + 1] === "<" || t[i2 + 1] === ">" || t[i2 + 1] === "\\")) {
327
+ i2 += 1;
328
+ continue;
329
+ }
330
+ if (ch === ">") return i2 + 1;
331
+ if (ch === "<") return -1;
332
+ }
333
+ return -1;
334
+ }
335
+ let balance = 0;
336
+ let i = 0;
337
+ for (; i < t.length; i++) {
338
+ const code = t.charCodeAt(i);
339
+ if (code === 32 || code === 9) break;
340
+ if (code < 32 || code === 127) return -1;
341
+ const ch = t[i];
342
+ if (ch === "\\" && (t[i + 1] === "(" || t[i + 1] === ")" || t[i + 1] === "\\")) {
343
+ i += 1;
344
+ continue;
345
+ }
346
+ if (ch === "(") balance += 1;
347
+ else if (ch === ")") {
348
+ if (balance === 0) break;
349
+ balance -= 1;
350
+ }
351
+ }
352
+ if (balance !== 0 || i === 0) return -1;
353
+ return i;
354
+ }
355
+ function inlineResourceEnd(text, openIdx) {
356
+ let i = openIdx + 1;
357
+ const skipWs = () => {
358
+ while (i < text.length && (text[i] === " " || text[i] === " ")) i += 1;
359
+ };
360
+ skipWs();
361
+ if (text[i] === ")") return i + 1;
362
+ const destEnd = linkDestinationEnd(text.slice(i));
363
+ if (destEnd === -1) return -1;
364
+ i += destEnd;
365
+ const beforeWs = i;
366
+ skipWs();
367
+ if (text[i] === ")") return i + 1;
368
+ if (i === beforeWs) return -1;
369
+ const opener = text[i];
370
+ if (opener !== '"' && opener !== "'" && opener !== "(") return -1;
371
+ const closer = opener === "(" ? ")" : opener;
372
+ for (i += 1; i < text.length; i++) {
373
+ if (text[i] === "\\") {
374
+ i += 1;
375
+ continue;
376
+ }
377
+ if (text[i] === closer) {
378
+ i += 1;
379
+ skipWs();
380
+ return text[i] === ")" ? i + 1 : -1;
381
+ }
382
+ }
383
+ return -1;
384
+ }
385
+ function collectRefLine(cp, lnStart, lnEnd, scanText, inRawText, isBlockStart) {
386
+ const defShaped = inRawText ? null : DEF_RE.exec(scanText);
387
+ const def = defShaped !== null && (defShaped[1].startsWith("^") || isPlausibleLinkDefRest(scanText.slice(defShaped.index + defShaped[0].length))) ? defShaped : null;
388
+ const defLineStart = isBlockStart || !cp.prevLineWasText || cp.prevLineWasValidDef;
389
+ const validDef = def !== null && defLineStart;
390
+ if (validDef) {
391
+ const label = def[1];
392
+ if (label.startsWith("^")) {
393
+ const key = normalizeLabel(label.slice(1));
394
+ if (key && !cp.footnoteDefs.has(key)) cp.footnoteDefs.set(key, lnEnd);
395
+ } else {
396
+ const key = normalizeLabel(label);
397
+ if (key && !cp.defs.has(key)) cp.defs.set(key, lnEnd);
398
+ }
399
+ }
400
+ if (cp.referenceTaint) {
401
+ const pushRef = (offset, inner, followAt) => {
402
+ const follow = scanText[followAt];
403
+ if (follow === "(" && inlineResourceEnd(scanText, followAt) !== -1) return;
404
+ let label;
405
+ let footnote = false;
406
+ if (inner.startsWith("^")) {
407
+ footnote = true;
408
+ label = normalizeLabel(inner.slice(1));
409
+ } else if (follow === "[") {
410
+ const explicit = /^\[((?:[^[\]\\]|\\.)*)\]/.exec(scanText.slice(followAt));
411
+ label = normalizeLabel(explicit && explicit[1] ? explicit[1] : inner);
412
+ } else {
413
+ label = normalizeLabel(inner);
414
+ }
415
+ if (label) cp.unresolvedRefs.push({ offset, label, footnote });
416
+ };
417
+ const pending = cp.openBracket;
418
+ cp.openBracket = null;
419
+ if (pending) {
420
+ const close = firstUnescaped(scanText, "]");
421
+ const open = firstUnescaped(scanText, "[");
422
+ const cont = (t) => t.replace(/^ {0,3}>[ \t]?/, "");
423
+ if (close !== -1 && (open === -1 || close < open)) {
424
+ pushRef(pending.offset, `${pending.text}
425
+ ${cont(scanText.slice(0, close))}`, close + 1);
426
+ } else if (close === -1 && open === -1) {
427
+ cp.openBracket = { offset: pending.offset, text: `${pending.text}
428
+ ${cont(scanText)}` };
429
+ }
430
+ }
431
+ if (scanText.includes("[")) {
432
+ const defBracket = validDef ? def.index + def[0].indexOf("[") : -1;
433
+ REF_RE.lastIndex = 0;
434
+ let m;
435
+ while ((m = REF_RE.exec(scanText)) !== null) {
436
+ const followAt = m.index + m[0].length;
437
+ if (scanText[followAt] === ":" && m.index === defBracket) continue;
438
+ pushRef(lnStart + m.index, m[1], followAt);
439
+ }
440
+ const trailingOpen = lastUnclosedBracket(scanText);
441
+ if (trailingOpen !== -1) {
442
+ cp.openBracket = { offset: lnStart + trailingOpen, text: scanText.slice(trailingOpen + 1) };
443
+ }
444
+ }
445
+ }
446
+ return { validDef, validLinkDef: validDef && !def[1].startsWith("^") };
447
+ }
448
+ function settleRefsAndEarliestUnresolved(cp) {
449
+ if (cp.unresolvedRefs.length > 0) {
450
+ const settled = (defEnd) => cp.lastBlankStart >= defEnd;
451
+ cp.unresolvedRefs = cp.unresolvedRefs.filter((ref) => {
452
+ const table = ref.footnote ? cp.footnoteDefs : cp.defs;
453
+ const defEnd = table.get(ref.label);
454
+ return defEnd === void 0 || !settled(defEnd);
455
+ });
456
+ }
457
+ let earliestUnresolved = Infinity;
458
+ for (const ref of cp.unresolvedRefs) earliestUnresolved = Math.min(earliestUnresolved, ref.offset);
459
+ return earliestUnresolved;
460
+ }
461
+
462
+ // src/components/incrementalParse/computeFreezeBoundary.ts
271
463
  var TYPE6_NAMES = new Set(import_micromark_util_html_tag_name.htmlBlockNames);
272
464
  var TABLE_PART_NAMES = /* @__PURE__ */ new Set(["td", "th", "tr", "tbody", "thead", "tfoot", "caption", "col", "colgroup"]);
273
465
  var DOCUMENT_STRUCTURE_NAMES = /* @__PURE__ */ new Set(["html", "head", "body", "frameset"]);
@@ -290,53 +482,6 @@ function tailCarriesRetroactive(text) {
290
482
  }
291
483
  return false;
292
484
  }
293
- var HTML_BREAKOUT_TAGS = /* @__PURE__ */ new Set([
294
- "b",
295
- "big",
296
- "blockquote",
297
- "body",
298
- "br",
299
- "center",
300
- "code",
301
- "dd",
302
- "div",
303
- "dl",
304
- "dt",
305
- "em",
306
- "embed",
307
- "h1",
308
- "h2",
309
- "h3",
310
- "h4",
311
- "h5",
312
- "h6",
313
- "head",
314
- "hr",
315
- "i",
316
- "img",
317
- "li",
318
- "listing",
319
- "menu",
320
- "meta",
321
- "nobr",
322
- "ol",
323
- "p",
324
- "pre",
325
- "ruby",
326
- "s",
327
- "small",
328
- "span",
329
- "strong",
330
- "strike",
331
- "sub",
332
- "sup",
333
- "table",
334
- "tt",
335
- "u",
336
- "ul",
337
- "var"
338
- ]);
339
- var HTML_INTEGRATION_POINTS = ["foreignobject", "desc", "title", "mi", "mo", "mn", "ms", "mtext", "annotation-xml"];
340
485
  var SCOPE_BARRIER_NAMES = /* @__PURE__ */ new Set([
341
486
  "applet",
342
487
  "caption",
@@ -374,11 +519,85 @@ var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
374
519
  // (oracle review of the r2 batch; regression caught before release).
375
520
  "plaintext"
376
521
  ]);
522
+ var P5_MARKUP_RE = /<[!/?A-Za-z]/;
377
523
  var TYPE6_START_RE = /^<\/?([A-Za-z][A-Za-z0-9-]*)(?:[ \t\r]|\/?>|$)/;
378
524
  var TYPE1_START_RE = /^<(script|pre|style|textarea)(?:[ \t\r]|>|$)/i;
379
525
  var TYPE1_CLOSE_RE = /<\/(?:script|pre|style|textarea)>/i;
380
- var TYPE7_LINE_RE = /^(?:<[A-Za-z][A-Za-z0-9-]*(?:[ \t\r][^>]*|\/)?>|<\/[A-Za-z][A-Za-z0-9-]*[ \t\r]*>)[ \t\r]*$/;
381
- var t7Name = (line) => /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(line)[1];
526
+ var isSpaceTab = (c) => c === 32 || c === 9;
527
+ var isAsciiAlpha = (c) => c >= 65 && c <= 90 || c >= 97 && c <= 122;
528
+ var isAlnum = (c) => isAsciiAlpha(c) || c >= 48 && c <= 57;
529
+ var isAttrNameRest = (c) => isAlnum(c) || c === 45 || c === 46 || c === 58 || c === 95;
530
+ var isUnquotedExit = (c) => Number.isNaN(c) || c === 34 || c === 39 || c === 47 || c === 60 || c === 61 || c === 62 || c === 96 || isSpaceTab(c);
531
+ var completeOpenTagRest = (t, from) => {
532
+ let i = from;
533
+ for (; ; ) {
534
+ const c = t.charCodeAt(i);
535
+ if (c === 47) {
536
+ i += 1;
537
+ break;
538
+ }
539
+ if (isSpaceTab(c)) {
540
+ i += 1;
541
+ continue;
542
+ }
543
+ if (!(c === 58 || c === 95 || isAsciiAlpha(c))) break;
544
+ i += 1;
545
+ while (isAttrNameRest(t.charCodeAt(i))) i += 1;
546
+ for (; ; ) {
547
+ while (isSpaceTab(t.charCodeAt(i))) i += 1;
548
+ if (t.charCodeAt(i) !== 61) break;
549
+ i += 1;
550
+ while (isSpaceTab(t.charCodeAt(i))) i += 1;
551
+ const v = t.charCodeAt(i);
552
+ if (Number.isNaN(v) || v === 60 || v === 61 || v === 62 || v === 96) return -1;
553
+ if (v === 34 || v === 39) {
554
+ i += 1;
555
+ while (t.charCodeAt(i) !== v) {
556
+ if (i >= t.length) return -1;
557
+ i += 1;
558
+ }
559
+ i += 1;
560
+ const a = t.charCodeAt(i);
561
+ if (!(a === 47 || a === 62 || isSpaceTab(a))) return -1;
562
+ break;
563
+ }
564
+ while (!isUnquotedExit(t.charCodeAt(i))) i += 1;
565
+ }
566
+ }
567
+ return t.charCodeAt(i) === 62 ? i + 1 : -1;
568
+ };
569
+ var isType7Line = (line) => {
570
+ const cr = line.indexOf("\r");
571
+ const t = cr === -1 ? line : line.slice(0, cr);
572
+ if (t.charCodeAt(0) !== 60) return false;
573
+ let i = 1;
574
+ const closing = t.charCodeAt(i) === 47;
575
+ if (closing) i += 1;
576
+ if (!isAsciiAlpha(t.charCodeAt(i))) return false;
577
+ const nameStart = i;
578
+ i += 1;
579
+ while (isAlnum(t.charCodeAt(i)) || t.charCodeAt(i) === 45) i += 1;
580
+ const c = t.charCodeAt(i);
581
+ if (!(Number.isNaN(c) || c === 47 || c === 62 || isSpaceTab(c))) return false;
582
+ const name = t.slice(nameStart, i).toLowerCase();
583
+ if (!closing && c !== 47 && TYPE1_NAMES.has(name)) return false;
584
+ if (TYPE6_NAMES.has(name)) return false;
585
+ if (closing) {
586
+ while (isSpaceTab(t.charCodeAt(i))) i += 1;
587
+ if (t.charCodeAt(i) !== 62) return false;
588
+ i += 1;
589
+ } else {
590
+ i = completeOpenTagRest(t, i);
591
+ if (i === -1) return false;
592
+ }
593
+ while (isSpaceTab(t.charCodeAt(i))) i += 1;
594
+ return i >= t.length;
595
+ };
596
+ var mdHtml = (b, type) => b.kind === "html" && b.type === type;
597
+ var mdHtml25 = (b) => b.kind === "html" && b.type >= 2 && b.type <= 5;
598
+ var commentEitherOpen = (md, p5) => mdHtml(md, 2) || p5.kind === "comment";
599
+ var inRawTextTok = (t) => t.kind === "rawText" || t.kind === "script";
600
+ var rawTextElement = (t) => t.kind === "rawText" ? t.element : t.kind === "script" ? "script" : null;
382
601
  var VOID_TAGS = /* @__PURE__ */ new Set([
383
602
  "area",
384
603
  "base",
@@ -396,9 +615,11 @@ var VOID_TAGS = /* @__PURE__ */ new Set([
396
615
  "wbr"
397
616
  ]);
398
617
  var LIST_MARKER_RE = /^ {0,3}(?:[-*+]|\d{1,9}[.)])(?:[ \t]|$)/;
399
- var FOOTNOTE_DEF_RE = /^ {0,3}\[\^[^\]]*\]:/;
618
+ var ATX_HEADING_RE = /^#{1,6}(?:[ \t]|$)/;
619
+ var THEMATIC_BREAK_RE = /^(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/;
620
+ var BARE_MARKER_RE = /^(?:[-*+]|\d{1,9}[.)])[ \t]*$/;
621
+ var SETEXT_LEFTOVER_RE = /^(?:=+|--)[ \t]*$/;
400
622
  var DEF_LIST_DD_RE = /^ {0,3}:[ \t]/;
401
- var DEF_RE = /^ {0,3}\[((?:[^[\]\\]|\\.)+)\]:/;
402
623
  var FENCE_RE = /^ {0,3}(`{3,}|~{3,})/;
403
624
  var MATH_RUN_RE = /^ {0,3}(\$\$+)/;
404
625
  var TAG_OR_COMMENT_RE = /<(\/?)([A-Za-z][A-Za-z0-9-]*)(?=[\s/>])([^>]*)>|<!--|-->|--!>/g;
@@ -431,12 +652,7 @@ function scanTagAttrs(text, from, to, out) {
431
652
  out.state = st;
432
653
  return -1;
433
654
  }
434
- var REF_RE = /!?\[((?:[^[\]\\]|\\.)*)\]/g;
435
655
  var BACKTICK_RUN_RE = /`+/g;
436
- var MD_BLANK_RE = /^[ \t\r]*$/;
437
- var isMdBlank = (text) => MD_BLANK_RE.test(text);
438
- var mdTrim = (text) => text.replace(/^[ \t\r]+|[ \t\r]+$/g, "");
439
- var mdTrimStart = (text) => text.replace(/^[ \t\r]+/, "");
440
656
  function computeIndent(text) {
441
657
  let indent = 0;
442
658
  for (const ch of text) {
@@ -446,27 +662,6 @@ function computeIndent(text) {
446
662
  }
447
663
  return indent;
448
664
  }
449
- function firstUnescaped(text, ch) {
450
- for (let i = 0; i < text.length; i++) {
451
- if (text[i] === "\\") i += 1;
452
- else if (text[i] === ch) return i;
453
- }
454
- return -1;
455
- }
456
- function lastUnclosedBracket(text) {
457
- let open = -1;
458
- for (let i = 0; i < text.length; i++) {
459
- const c = text[i];
460
- if (c === "\\") i += 1;
461
- else if (c === "[") open = i;
462
- else if (c === "]") open = -1;
463
- }
464
- return open;
465
- }
466
- function normalizeLabel(label) {
467
- const collapsed = label.replace(/[ \t\r\n]+/g, " ").replace(/^ | $/g, "");
468
- return collapsed ? (0, import_micromark_util_normalize_identifier.normalizeIdentifier)(collapsed) : "";
469
- }
470
665
  function canBecomeDdLine(text, confirmed) {
471
666
  let i = 0;
472
667
  while (i < text.length && text[i] === " ") i += 1;
@@ -523,20 +718,9 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
523
718
  unresolvedRefs: [],
524
719
  tagBalance: /* @__PURE__ */ new Map(),
525
720
  openTotal: 0,
526
- commentOpen: false,
527
- piOpen: false,
528
- bogusOpen: false,
529
- rawTextOpen: null,
721
+ p5Tok: { kind: "data" },
530
722
  openStack: [],
531
- scriptDataEscaped: false,
532
- declOpen: false,
533
- cdataOpen: false,
534
- inFence: false,
535
- fenceChar: "",
536
- fenceLen: 0,
537
- inMath: false,
538
- mathFenceLen: 0,
539
- openIndent: 0,
723
+ mdBlock: { kind: "none" },
540
724
  blankRun: 0,
541
725
  lastBlankStart: -1,
542
726
  hazardVerdict: false,
@@ -544,103 +728,17 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
544
728
  // doc start counts as a block start
545
729
  prevLineWasText: false,
546
730
  prevLineWasValidDef: false,
731
+ prevLineOpenContent: false,
732
+ tableMaybeOpen: false,
547
733
  paragraphHasUnpairedRun: false,
548
734
  openBracket: null,
549
- htmlFlowSinceBlank: false,
550
- htmlSeamPending: false,
735
+ p5SealPending: false,
551
736
  phasePoisonedAt: Infinity,
552
737
  pendingTruncatedTags: [],
553
738
  pendingTruncatedCloses: [],
554
- tagAcrossLines: false,
555
- tagAcrossLinesIndent: 0,
556
- tagAcrossLinesState: "outside",
557
- htmlFlowReal: false,
558
- type1FlowOpen: false,
559
- rawTextInline: false
739
+ pendingTag: null
560
740
  };
561
741
  }
562
- function isPlausibleLinkDefRest(rest) {
563
- const t = mdTrim(rest);
564
- if (t === "") return false;
565
- const destEnd = linkDestinationEnd(t);
566
- if (destEnd === -1) return false;
567
- const after = mdTrim(t.slice(destEnd));
568
- if (after === "") return true;
569
- const opener = after[0];
570
- if (opener !== '"' && opener !== "'" && opener !== "(") return false;
571
- const closer = opener === "(" ? ")" : opener;
572
- for (let i = 1; i < after.length; i++) {
573
- if (after[i] === "\\") {
574
- i += 1;
575
- continue;
576
- }
577
- if (after[i] === closer) return isMdBlank(after.slice(i + 1));
578
- }
579
- return false;
580
- }
581
- function linkDestinationEnd(t) {
582
- if (t.startsWith("<")) {
583
- for (let i2 = 1; i2 < t.length; i2++) {
584
- const ch = t[i2];
585
- if (ch === "\\" && (t[i2 + 1] === "<" || t[i2 + 1] === ">" || t[i2 + 1] === "\\")) {
586
- i2 += 1;
587
- continue;
588
- }
589
- if (ch === ">") return i2 + 1;
590
- if (ch === "<") return -1;
591
- }
592
- return -1;
593
- }
594
- let balance = 0;
595
- let i = 0;
596
- for (; i < t.length; i++) {
597
- const code = t.charCodeAt(i);
598
- if (code === 32 || code === 9) break;
599
- if (code < 32 || code === 127) return -1;
600
- const ch = t[i];
601
- if (ch === "\\" && (t[i + 1] === "(" || t[i + 1] === ")" || t[i + 1] === "\\")) {
602
- i += 1;
603
- continue;
604
- }
605
- if (ch === "(") balance += 1;
606
- else if (ch === ")") {
607
- if (balance === 0) break;
608
- balance -= 1;
609
- }
610
- }
611
- if (balance !== 0 || i === 0) return -1;
612
- return i;
613
- }
614
- function inlineResourceEnd(text, openIdx) {
615
- let i = openIdx + 1;
616
- const skipWs = () => {
617
- while (i < text.length && (text[i] === " " || text[i] === " ")) i += 1;
618
- };
619
- skipWs();
620
- if (text[i] === ")") return i + 1;
621
- const destEnd = linkDestinationEnd(text.slice(i));
622
- if (destEnd === -1) return -1;
623
- i += destEnd;
624
- const beforeWs = i;
625
- skipWs();
626
- if (text[i] === ")") return i + 1;
627
- if (i === beforeWs) return -1;
628
- const opener = text[i];
629
- if (opener !== '"' && opener !== "'" && opener !== "(") return -1;
630
- const closer = opener === "(" ? ")" : opener;
631
- for (i += 1; i < text.length; i++) {
632
- if (text[i] === "\\") {
633
- i += 1;
634
- continue;
635
- }
636
- if (text[i] === closer) {
637
- i += 1;
638
- skipWs();
639
- return text[i] === ")" ? i + 1 : -1;
640
- }
641
- }
642
- return -1;
643
- }
644
742
  function classifyBlockStart(text, indent, defListEnabled) {
645
743
  if (indent >= 4) return true;
646
744
  if (LIST_MARKER_RE.test(text) || FOOTNOTE_DEF_RE.test(text)) return true;
@@ -686,16 +784,7 @@ function computeFreezeBoundary(text, options, resume) {
686
784
  cp.confirmedOffset = end + 1;
687
785
  start = end + 1;
688
786
  }
689
- if (cp.unresolvedRefs.length > 0) {
690
- const settled = (defEnd) => cp.lastBlankStart >= defEnd;
691
- cp.unresolvedRefs = cp.unresolvedRefs.filter((ref) => {
692
- const table = ref.footnote ? cp.footnoteDefs : cp.defs;
693
- const defEnd = table.get(ref.label);
694
- return defEnd === void 0 || !settled(defEnd);
695
- });
696
- }
697
- let earliestUnresolved = Infinity;
698
- for (const ref of cp.unresolvedRefs) earliestUnresolved = Math.min(earliestUnresolved, ref.offset);
787
+ const earliestUnresolved = settleRefsAndEarliestUnresolved(cp);
699
788
  const defListSettled = (c) => {
700
789
  if (!options.defListEnabled || c.blankRun >= 2) return true;
701
790
  if (c.defListSettled !== null) return c.defListSettled;
@@ -718,9 +807,8 @@ function computeFreezeBoundary(text, options, resume) {
718
807
  function pendingFenceCloser(checkpoint) {
719
808
  const cp = checkpoint;
720
809
  if (cp.phasePoisonedAt !== Infinity) return "";
721
- if (cp.openIndent !== 0) return "";
722
- if (cp.inFence) return cp.fenceChar.repeat(cp.fenceLen);
723
- if (cp.inMath) return "$".repeat(cp.mathFenceLen);
810
+ if (cp.mdBlock.kind === "fence" && cp.mdBlock.indent === 0) return cp.mdBlock.char.repeat(cp.mdBlock.len);
811
+ if (cp.mdBlock.kind === "math" && cp.mdBlock.indent === 0) return "$".repeat(cp.mdBlock.len);
724
812
  return "";
725
813
  }
726
814
  function floatingResidue(text, commentOpenAtStart) {
@@ -771,53 +859,34 @@ function processConfirmedLine(cp, ln, text) {
771
859
  newest.defListSettled = ln.blank ? true : !canBecomeDdLine(ln.text, true);
772
860
  }
773
861
  const isBlockStart = cp.prevLineBlank;
774
- if (cp.htmlSeamPending && !ln.blank && !cp.htmlFlowSinceBlank && !(cp.commentOpen || cp.piOpen || cp.declOpen || cp.cdataOpen || cp.bogusOpen)) {
862
+ if (cp.p5SealPending && !ln.blank && cp.mdBlock.kind !== "html" && !(cp.p5Tok.kind === "comment" || cp.p5Tok.kind === "bogus")) {
775
863
  const defShapedLine = DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text);
776
864
  const commentOnly = ln.text.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!--[\s\S]*$/, " ").replace(/[ \t\r]/g, "") === "";
777
865
  if (!defShapedLine && !commentOnly) {
778
- cp.htmlSeamPending = false;
866
+ cp.p5SealPending = false;
779
867
  }
780
868
  }
781
- const inForeignContent = () => FOREIGN_ROOT_NAMES.some((name) => (cp.tagBalance.get(name) ?? 0) > 0);
782
- const honoursSelfClosing = (tag) => {
783
- if (tag === "svg" || tag === "math") return true;
784
- if (!inForeignContent() || HTML_BREAKOUT_TAGS.has(tag)) return false;
785
- for (const ip of HTML_INTEGRATION_POINTS) if ((cp.tagBalance.get(ip) ?? 0) > 0) return false;
786
- return true;
787
- };
788
- const htmlRulesApply = () => {
789
- if (!inForeignContent()) return true;
790
- for (const ip of HTML_INTEGRATION_POINTS) if ((cp.tagBalance.get(ip) ?? 0) > 0) return true;
791
- return false;
792
- };
793
- const popForeignRoots = () => {
794
- for (const name of FOREIGN_ROOT_NAMES) {
795
- const count = cp.tagBalance.get(name) ?? 0;
796
- if (count > 0) {
797
- cp.tagBalance.set(name, 0);
798
- cp.openTotal -= count;
799
- }
800
- }
801
- if (cp.openStack.length > 0) cp.openStack = cp.openStack.filter((n) => !FOREIGN_ROOT_NAMES.includes(n));
802
- };
803
- const noteBreakout = (tag, closing) => {
804
- if (closing || cp.rawTextOpen !== null) return;
805
- if (HTML_BREAKOUT_TAGS.has(tag) && !htmlRulesApply()) popForeignRoots();
806
- };
869
+ const possiblyInsideForeign = () => FOREIGN_ROOT_NAMES.some((name) => (cp.tagBalance.get(name) ?? 0) > 0);
870
+ const honoursSelfClosing = (tag) => tag === "svg" || tag === "math";
871
+ const foreignRawTextSwitchUnknowable = () => possiblyInsideForeign();
807
872
  const applyTag = (tag, closing) => {
808
- if (cp.rawTextOpen !== null) {
809
- if (cp.scriptDataEscaped && !closing && tag === "script") {
810
- cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
873
+ if (inRawTextTok(cp.p5Tok)) {
874
+ if (cp.p5Tok.kind === "script" && cp.p5Tok.escaped && !closing && tag === "script") {
875
+ cp.p5Tok = { ...cp.p5Tok, double: true };
876
+ }
877
+ if (!(closing && tag === rawTextElement(cp.p5Tok))) return;
878
+ if (cp.p5Tok.kind === "script" && cp.p5Tok.double) {
879
+ cp.p5Tok = { ...cp.p5Tok, double: false };
880
+ return;
811
881
  }
812
- if (!(closing && tag === cp.rawTextOpen)) return;
813
- cp.rawTextOpen = null;
814
- cp.scriptDataEscaped = false;
882
+ cp.p5Tok = { kind: "data" };
815
883
  } else {
816
- noteBreakout(tag, closing);
817
- if (!closing && RAW_TEXT_ELEMENTS.has(tag) && htmlRulesApply()) {
818
- cp.rawTextOpen = tag;
819
- cp.scriptDataEscaped = false;
820
- cp.rawTextInline = !cp.htmlFlowReal;
884
+ if (!closing && RAW_TEXT_ELEMENTS.has(tag) && foreignRawTextSwitchUnknowable()) {
885
+ cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
886
+ } else if (!closing && RAW_TEXT_ELEMENTS.has(tag)) {
887
+ if (cp.p5Tok.kind !== "data") cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
888
+ const openedInline = cp.mdBlock.kind !== "html";
889
+ cp.p5Tok = tag === "script" ? { kind: "script", escaped: false, double: false, openedInline } : { kind: "rawText", element: tag, openedInline };
821
890
  if (tag === "plaintext") cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
822
891
  }
823
892
  }
@@ -845,15 +914,19 @@ function processConfirmedLine(cp, ln, text) {
845
914
  cp.openTotal += 1;
846
915
  }
847
916
  };
848
- const strayTablePart = (tag) => TABLE_PART_NAMES.has(tag) && (cp.tagBalance.get("table") ?? 0) === 0;
849
- const commentOpenAtLineStart = cp.commentOpen;
850
- const rawOpenAtLineStart = cp.commentOpen || cp.piOpen || cp.declOpen || cp.cdataOpen || cp.bogusOpen;
851
- if (cp.inFence) {
917
+ const definitelyInsideTable = () => (cp.tagBalance.get("table") ?? 0) > 0;
918
+ const strayTablePart = (tag) => TABLE_PART_NAMES.has(tag) && !definitelyInsideTable();
919
+ const commentOpenAtLineStart = commentEitherOpen(cp.mdBlock, cp.p5Tok);
920
+ const bothCommentsOpenAtLineStart = mdHtml(cp.mdBlock, 2) && cp.p5Tok.kind === "comment";
921
+ const inDivergenceWindow = mdHtml(cp.mdBlock, 2) && cp.p5Tok.kind !== "comment" || (mdHtml(cp.mdBlock, 3) || mdHtml(cp.mdBlock, 5)) && cp.p5Tok.kind !== "bogus";
922
+ if (inDivergenceWindow && P5_MARKUP_RE.test(ln.text)) {
923
+ cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
924
+ }
925
+ const rawOpenAtLineStart = mdHtml25(cp.mdBlock) || cp.p5Tok.kind === "comment" || cp.p5Tok.kind === "bogus";
926
+ if (cp.mdBlock.kind === "fence") {
852
927
  const close = FENCE_RE.exec(ln.text);
853
- if (close && close[1][0] === cp.fenceChar && close[1].length >= cp.fenceLen && isMdBlank(ln.text.slice(close[0].length))) {
854
- cp.inFence = false;
855
- cp.fenceChar = "";
856
- cp.fenceLen = 0;
928
+ if (close && close[1][0] === cp.mdBlock.char && close[1].length >= cp.mdBlock.len && isMdBlank(ln.text.slice(close[0].length))) {
929
+ cp.mdBlock = { kind: "none" };
857
930
  }
858
931
  cp.blankRun = 0;
859
932
  cp.paragraphHasUnpairedRun = false;
@@ -861,36 +934,36 @@ function processConfirmedLine(cp, ln, text) {
861
934
  cp.prevLineBlank = false;
862
935
  cp.prevLineWasText = false;
863
936
  cp.prevLineWasValidDef = false;
937
+ cp.prevLineOpenContent = false;
938
+ cp.tableMaybeOpen = false;
864
939
  return;
865
940
  }
866
- if (!cp.inMath && !rawOpenAtLineStart) {
941
+ if (cp.mdBlock.kind !== "math" && !rawOpenAtLineStart) {
867
942
  const open = FENCE_RE.exec(ln.text);
868
943
  const bogusInfo = open !== null && open[1][0] === "`" && ln.text.slice(ln.text.indexOf(open[1]) + open[1].length).includes("`");
869
- if (open && !bogusInfo && cp.htmlFlowSinceBlank) {
944
+ if (open && !bogusInfo && cp.mdBlock.kind === "html") {
870
945
  cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
871
946
  } else if (open && !bogusInfo) {
872
947
  if (isBlockStart) {
873
948
  const verdict = classifyBlockStart(ln.text, ln.indent, cp.defListEnabled);
874
949
  if (verdict !== null) cp.hazardVerdict = verdict;
875
950
  }
876
- cp.inFence = true;
877
- cp.fenceChar = open[1][0];
878
- cp.fenceLen = open[1].length;
879
- cp.openIndent = ln.indent;
951
+ cp.mdBlock = { kind: "fence", char: open[1][0], len: open[1].length, indent: ln.indent };
880
952
  cp.blankRun = 0;
881
953
  cp.paragraphHasUnpairedRun = false;
882
954
  cp.openBracket = null;
883
955
  cp.prevLineBlank = false;
884
956
  cp.prevLineWasText = false;
885
957
  cp.prevLineWasValidDef = false;
958
+ cp.prevLineOpenContent = false;
959
+ cp.tableMaybeOpen = false;
886
960
  return;
887
961
  }
888
962
  }
889
- if (cp.inMath) {
963
+ if (cp.mdBlock.kind === "math") {
890
964
  const close = MATH_RUN_RE.exec(ln.text);
891
- if (close && close[1].length >= cp.mathFenceLen && isMdBlank(ln.text.slice(close[0].length))) {
892
- cp.inMath = false;
893
- cp.mathFenceLen = 0;
965
+ if (close && close[1].length >= cp.mdBlock.len && isMdBlank(ln.text.slice(close[0].length))) {
966
+ cp.mdBlock = { kind: "none" };
894
967
  }
895
968
  cp.blankRun = 0;
896
969
  cp.paragraphHasUnpairedRun = false;
@@ -898,28 +971,30 @@ function processConfirmedLine(cp, ln, text) {
898
971
  cp.prevLineBlank = false;
899
972
  cp.prevLineWasText = false;
900
973
  cp.prevLineWasValidDef = false;
974
+ cp.prevLineOpenContent = false;
975
+ cp.tableMaybeOpen = false;
901
976
  return;
902
977
  }
903
978
  const mathRun = cp.mathFlow && !rawOpenAtLineStart ? MATH_RUN_RE.exec(ln.text) : null;
904
979
  if (mathRun) {
905
980
  const rest = ln.text.slice(ln.text.indexOf(mathRun[1]) + mathRun[1].length);
906
981
  if (!rest.includes("$")) {
907
- if (cp.htmlFlowSinceBlank) {
982
+ if (cp.mdBlock.kind === "html") {
908
983
  cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
909
984
  } else {
910
985
  if (isBlockStart) {
911
986
  const verdict = classifyBlockStart(ln.text, ln.indent, cp.defListEnabled);
912
987
  if (verdict !== null) cp.hazardVerdict = verdict;
913
988
  }
914
- cp.inMath = true;
915
- cp.mathFenceLen = mathRun[1].length;
916
- cp.openIndent = ln.indent;
989
+ cp.mdBlock = { kind: "math", len: mathRun[1].length, indent: ln.indent };
917
990
  cp.blankRun = 0;
918
991
  cp.paragraphHasUnpairedRun = false;
919
992
  cp.openBracket = null;
920
993
  cp.prevLineBlank = false;
921
994
  cp.prevLineWasText = false;
922
995
  cp.prevLineWasValidDef = false;
996
+ cp.prevLineOpenContent = false;
997
+ cp.tableMaybeOpen = false;
923
998
  return;
924
999
  }
925
1000
  }
@@ -930,42 +1005,46 @@ function processConfirmedLine(cp, ln, text) {
930
1005
  cp.pendingTruncatedTags = [];
931
1006
  }
932
1007
  cp.pendingTruncatedCloses = [];
933
- if (cp.tagAcrossLines && (cp.tagAcrossLinesState === '"' || cp.tagAcrossLinesState === "'")) {
1008
+ if (cp.pendingTag !== null && (cp.pendingTag.attr === '"' || cp.pendingTag.attr === "'")) {
934
1009
  cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
935
1010
  }
936
- cp.tagAcrossLines = false;
937
- cp.tagAcrossLinesState = "outside";
938
- if (cp.bogusOpen) {
939
- cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
940
- cp.bogusOpen = false;
1011
+ cp.pendingTag = null;
1012
+ if (cp.p5Tok.kind === "bogus") {
1013
+ if (mdHtml25(cp.mdBlock)) {
1014
+ } else {
1015
+ cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
1016
+ cp.p5Tok = { kind: "data" };
1017
+ }
941
1018
  }
1019
+ if (cp.mdBlock.kind === "html" && cp.mdBlock.type >= 6) cp.mdBlock = { kind: "none" };
942
1020
  cp.blankRun += 1;
943
1021
  cp.lastBlankStart = ln.start;
944
1022
  cp.candidates.push({
945
1023
  offset: Math.min(ln.end + 1, text.length),
946
1024
  blankRun: cp.blankRun,
947
- // `type1FlowOpen`: an unterminated type-1 block swallows this blank
948
- // and everything after it as RAW content, so nothing here is a block
949
- // boundary at all. Its tags are invisible to the balance scan
950
- // (`rawTextOpen` suppresses them), which is exactly why `openTotal`
951
- // reads 0 and the candidate looked safe.
952
- htmlBalanced: cp.openTotal === 0 && !cp.commentOpen && !cp.piOpen && !cp.declOpen && !cp.cdataOpen && !cp.bogusOpen && !cp.type1FlowOpen,
1025
+ // The html member covers types 1-5 in one check: an unterminated
1026
+ // type-1 block swallows this blank and everything after it as RAW
1027
+ // content (its tags are invisible to the balance scan — the raw-text
1028
+ // mask suppresses them which is exactly why `openTotal` reads 0
1029
+ // and the candidate looked safe), and the 2-5 interiors are the
1030
+ // same construct to both grammars.
1031
+ htmlBalanced: cp.openTotal === 0 && cp.mdBlock.kind !== "html" && cp.p5Tok.kind !== "bogus",
953
1032
  hazard: cp.hazardVerdict,
954
- seamRisk: cp.htmlSeamPending,
1033
+ seamRisk: cp.p5SealPending,
955
1034
  defListSettled: null
956
1035
  });
957
1036
  cp.paragraphHasUnpairedRun = false;
958
1037
  cp.openBracket = null;
959
- if (!cp.type1FlowOpen) {
960
- cp.htmlFlowSinceBlank = false;
961
- cp.htmlFlowReal = false;
962
- if (cp.rawTextOpen !== null && !cp.rawTextInline) {
1038
+ if (!mdHtml(cp.mdBlock, 1)) {
1039
+ if (inRawTextTok(cp.p5Tok) && !cp.p5Tok.openedInline) {
963
1040
  cp.phasePoisonedAt = 0;
964
1041
  }
965
1042
  }
966
1043
  cp.prevLineBlank = true;
967
1044
  cp.prevLineWasText = false;
968
1045
  cp.prevLineWasValidDef = false;
1046
+ cp.prevLineOpenContent = false;
1047
+ cp.tableMaybeOpen = false;
969
1048
  return;
970
1049
  }
971
1050
  if (isBlockStart) {
@@ -976,86 +1055,34 @@ function processConfirmedLine(cp, ln, text) {
976
1055
  }
977
1056
  const tagStart = ln.indent <= 3 ? /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(mdTrimStart(ln.text)) : null;
978
1057
  if (tagStart) {
979
- const noRealBlockOpen = !cp.htmlFlowReal;
980
- cp.htmlFlowSinceBlank = true;
981
- if (noRealBlockOpen && TYPE1_START_RE.test(mdTrimStart(ln.text))) cp.type1FlowOpen = true;
982
- if (!TYPE6_NAMES.has(tagStart[1].toLowerCase())) cp.hazardVerdict = true;
983
- if (!cp.htmlFlowReal) {
1058
+ const noRealBlockOpen = cp.mdBlock.kind !== "html";
1059
+ if (noRealBlockOpen && TYPE1_START_RE.test(mdTrimStart(ln.text))) cp.mdBlock = { kind: "html", type: 1 };
1060
+ if (cp.mdBlock.kind !== "html") {
984
1061
  const t = mdTrimStart(ln.text);
985
1062
  const t6 = TYPE6_START_RE.exec(t);
986
- const t7 = TYPE7_LINE_RE.exec(t);
987
- if (t6 !== null && TYPE6_NAMES.has(t6[1].toLowerCase()) || TYPE1_START_RE.test(t) || // Type 7 cannot interrupt a paragraph, and excludes the raw-text
988
- // names (those are type 1 as start tags, paragraph as end tags).
989
- t7 !== null && !cp.prevLineWasText && !TYPE1_NAMES.has(t7Name(t).toLowerCase())) {
990
- cp.htmlFlowReal = true;
1063
+ const realT6 = t6 !== null && TYPE6_NAMES.has(t6[1].toLowerCase());
1064
+ if (realT6 || TYPE1_START_RE.test(t) || // Type 7 cannot interrupt CONTENT (micromark's paragraph/definition
1065
+ // construct `prevLineOpenContent`, the exact interrupt input; the
1066
+ // old `prevLineWasText` gate refused after headings, terminator
1067
+ // lines and fence closes, where micromark measurably opens). The
1068
+ // classifier itself is exact too (isType7Line) — including closing
1069
+ // raw-text names (`</style>` alone is type 7, measured) and
1070
+ // quoted-`>` attribute values.
1071
+ !cp.prevLineOpenContent && isType7Line(t)) {
1072
+ if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: realT6 ? 6 : 7 };
1073
+ } else if (cp.prevLineOpenContent && cp.tableMaybeOpen && isType7Line(t)) {
1074
+ cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
991
1075
  }
992
1076
  }
993
1077
  }
994
- const inRawText = cp.htmlFlowSinceBlank || rawOpenAtLineStart;
995
1078
  const rawFlowStart = ln.indent <= 3 && /^<(?:!--|\?|![A-Za-z]|!\[CDATA\[)/.test(mdTrimStart(ln.text));
996
- const { masked, unpaired } = inRawText ? { masked: null, unpaired: false } : maskIntraLineCodeSpans(ln.text, cp.paragraphHasUnpairedRun);
1079
+ const htmlOwnedLine = cp.mdBlock.kind === "html" || rawOpenAtLineStart || rawFlowStart;
1080
+ const maskingSuppressed = htmlOwnedLine || inRawTextTok(cp.p5Tok);
1081
+ const { masked, unpaired } = maskingSuppressed ? { masked: null, unpaired: false } : maskIntraLineCodeSpans(ln.text, cp.paragraphHasUnpairedRun);
997
1082
  if (unpaired) cp.paragraphHasUnpairedRun = true;
998
1083
  const scanText = masked ?? ln.text;
999
- const defShaped = inRawText ? null : DEF_RE.exec(scanText);
1000
- const def = defShaped !== null && (defShaped[1].startsWith("^") || isPlausibleLinkDefRest(scanText.slice(defShaped.index + defShaped[0].length))) ? defShaped : null;
1001
- const defLineStart = isBlockStart || !cp.prevLineWasText || cp.prevLineWasValidDef;
1002
- const validDef = def !== null && defLineStart;
1003
- if (validDef) {
1004
- const label = def[1];
1005
- if (label.startsWith("^")) {
1006
- const key = normalizeLabel(label.slice(1));
1007
- if (key && !cp.footnoteDefs.has(key)) cp.footnoteDefs.set(key, ln.end);
1008
- } else {
1009
- const key = normalizeLabel(label);
1010
- if (key && !cp.defs.has(key)) cp.defs.set(key, ln.end);
1011
- }
1012
- }
1013
- if (cp.referenceTaint) {
1014
- const pushRef = (offset, inner, followAt) => {
1015
- const follow = scanText[followAt];
1016
- if (follow === "(" && inlineResourceEnd(scanText, followAt) !== -1) return;
1017
- let label;
1018
- let footnote = false;
1019
- if (inner.startsWith("^")) {
1020
- footnote = true;
1021
- label = normalizeLabel(inner.slice(1));
1022
- } else if (follow === "[") {
1023
- const explicit = /^\[((?:[^[\]\\]|\\.)*)\]/.exec(scanText.slice(followAt));
1024
- label = normalizeLabel(explicit && explicit[1] ? explicit[1] : inner);
1025
- } else {
1026
- label = normalizeLabel(inner);
1027
- }
1028
- if (label) cp.unresolvedRefs.push({ offset, label, footnote });
1029
- };
1030
- const pending = cp.openBracket;
1031
- cp.openBracket = null;
1032
- if (pending) {
1033
- const close = firstUnescaped(scanText, "]");
1034
- const open = firstUnescaped(scanText, "[");
1035
- const cont = (t) => t.replace(/^ {0,3}>[ \t]?/, "");
1036
- if (close !== -1 && (open === -1 || close < open)) {
1037
- pushRef(pending.offset, `${pending.text}
1038
- ${cont(scanText.slice(0, close))}`, close + 1);
1039
- } else if (close === -1 && open === -1) {
1040
- cp.openBracket = { offset: pending.offset, text: `${pending.text}
1041
- ${cont(scanText)}` };
1042
- }
1043
- }
1044
- if (scanText.includes("[")) {
1045
- const defBracket = validDef ? def.index + def[0].indexOf("[") : -1;
1046
- REF_RE.lastIndex = 0;
1047
- let m;
1048
- while ((m = REF_RE.exec(scanText)) !== null) {
1049
- const followAt = m.index + m[0].length;
1050
- if (scanText[followAt] === ":" && m.index === defBracket) continue;
1051
- pushRef(ln.start + m.index, m[1], followAt);
1052
- }
1053
- const trailingOpen = lastUnclosedBracket(scanText);
1054
- if (trailingOpen !== -1) {
1055
- cp.openBracket = { offset: ln.start + trailingOpen, text: scanText.slice(trailingOpen + 1) };
1056
- }
1057
- }
1058
- }
1084
+ const defRawToMicromark = cp.mdBlock.kind === "html" || rawOpenAtLineStart || inRawTextTok(cp.p5Tok);
1085
+ const { validLinkDef } = collectRefLine(cp, ln.start, ln.end, scanText, defRawToMicromark, isBlockStart);
1059
1086
  const rawSpans = [];
1060
1087
  let pos = 0;
1061
1088
  const poisonRawDivergence = () => {
@@ -1063,60 +1090,71 @@ ${cont(scanText)}` };
1063
1090
  };
1064
1091
  let inlineRawOpenerIdx = -1;
1065
1092
  while (pos < scanText.length) {
1066
- if (cp.piOpen) {
1067
- const c = scanText.indexOf("?>", pos);
1068
- const gt = scanText.indexOf(">", pos);
1069
- if (gt !== -1 && (c === -1 || gt !== c + 1)) poisonRawDivergence();
1070
- if (c === -1) {
1071
- rawSpans.push([pos, scanText.length]);
1072
- break;
1093
+ if (mdHtml(cp.mdBlock, 3) || mdHtml(cp.mdBlock, 5)) {
1094
+ const isPi = mdHtml(cp.mdBlock, 3);
1095
+ const term = isPi ? "?>" : "]]>";
1096
+ const c = scanText.indexOf(term, pos);
1097
+ const mdEnd = c === -1 ? scanText.length : c + term.length;
1098
+ if (cp.p5Tok.kind === "bogus") {
1099
+ const gt = scanText.indexOf(">", pos);
1100
+ if (gt !== -1 && (c === -1 || gt !== c + term.length - 1)) {
1101
+ cp.p5Tok = { kind: "data" };
1102
+ rawSpans.push([pos, gt + 1]);
1103
+ if (P5_MARKUP_RE.test(scanText.slice(gt + 1, c === -1 ? scanText.length : c))) {
1104
+ poisonRawDivergence();
1105
+ }
1106
+ } else {
1107
+ rawSpans.push([pos, mdEnd]);
1108
+ if (c !== -1) cp.p5Tok = { kind: "data" };
1109
+ }
1073
1110
  }
1074
- rawSpans.push([pos, c + 2]);
1075
- cp.piOpen = false;
1076
- pos = c + 2;
1111
+ if (c === -1) break;
1112
+ cp.mdBlock = { kind: "none" };
1113
+ pos = mdEnd;
1077
1114
  continue;
1078
1115
  }
1079
- if (cp.cdataOpen) {
1080
- const c = scanText.indexOf("]]>", pos);
1081
- const gt = scanText.indexOf(">", pos);
1082
- if (gt !== -1 && (c === -1 || gt !== c + 2)) poisonRawDivergence();
1116
+ if (mdHtml(cp.mdBlock, 4)) {
1117
+ const c = scanText.indexOf(">", pos);
1083
1118
  if (c === -1) {
1084
1119
  rawSpans.push([pos, scanText.length]);
1085
1120
  break;
1086
1121
  }
1087
- rawSpans.push([pos, c + 3]);
1088
- cp.cdataOpen = false;
1089
- pos = c + 3;
1122
+ rawSpans.push([pos, c + 1]);
1123
+ cp.mdBlock = { kind: "none" };
1124
+ if (cp.p5Tok.kind === "bogus") cp.p5Tok = { kind: "data" };
1125
+ pos = c + 1;
1090
1126
  continue;
1091
1127
  }
1092
- if (cp.declOpen || cp.bogusOpen) {
1128
+ if (cp.p5Tok.kind === "bogus") {
1093
1129
  const c = scanText.indexOf(">", pos);
1094
1130
  if (c === -1) {
1095
1131
  rawSpans.push([pos, scanText.length]);
1096
1132
  break;
1097
1133
  }
1098
1134
  rawSpans.push([pos, c + 1]);
1099
- cp.declOpen = false;
1100
- cp.bogusOpen = false;
1135
+ cp.p5Tok = { kind: "data" };
1101
1136
  pos = c + 1;
1102
1137
  continue;
1103
1138
  }
1139
+ if (commentOpenAtLineStart || inRawTextTok(cp.p5Tok) || mdHtml(cp.mdBlock, 1)) break;
1104
1140
  const pi = scanText.indexOf("<?", pos);
1105
1141
  const cd = scanText.indexOf("<![CDATA[", pos);
1106
1142
  const dm = scanText.slice(pos).search(/<![A-Za-z]/);
1107
1143
  const decl = dm === -1 ? -1 : pos + dm;
1108
- const bm = cp.htmlFlowReal ? scanText.slice(pos).search(/<!(?!--|[A-Za-z]|\[CDATA\[)|<\/(?![A-Za-z])/) : -1;
1144
+ const bm = cp.mdBlock.kind === "html" ? scanText.slice(pos).search(/<!(?!--|[A-Za-z]|\[CDATA\[)|<\/(?![A-Za-z])/) : -1;
1109
1145
  const bogus = bm === -1 ? -1 : pos + bm;
1110
1146
  const starts = [pi, cd, decl, bogus].filter((x) => x !== -1);
1111
1147
  if (starts.length === 0) break;
1112
1148
  const first = Math.min(...starts);
1113
1149
  if (first === bogus) {
1114
1150
  rawSpans.push([bogus, bogus + 2]);
1115
- cp.bogusOpen = true;
1151
+ if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
1152
+ else cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
1116
1153
  pos = bogus + 2;
1117
1154
  } else if (first === cd) {
1118
1155
  rawSpans.push([cd, cd + 9]);
1119
- cp.cdataOpen = true;
1156
+ if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 5 };
1157
+ if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
1120
1158
  if (!isMdBlank(scanText.slice(0, cd)) || ln.indent > 3) inlineRawOpenerIdx = cd;
1121
1159
  pos = cd + 9;
1122
1160
  } else if (first === pi) {
@@ -1127,18 +1165,20 @@ ${cont(scanText)}` };
1127
1165
  continue;
1128
1166
  }
1129
1167
  rawSpans.push([pi, pi + 2]);
1130
- cp.piOpen = true;
1168
+ if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 3 };
1169
+ if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
1131
1170
  if (!isMdBlank(scanText.slice(0, pi)) || ln.indent > 3) inlineRawOpenerIdx = pi;
1132
1171
  pos = pi + 2;
1133
1172
  } else {
1134
1173
  rawSpans.push([decl, decl + 2]);
1135
1174
  if (ln.indent <= 3 && /^doctype/i.test(scanText.slice(decl + 2))) cp.phasePoisonedAt = 0;
1136
- cp.declOpen = true;
1175
+ if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 4 };
1176
+ if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
1137
1177
  if (!isMdBlank(scanText.slice(0, decl)) || ln.indent > 3) inlineRawOpenerIdx = decl;
1138
1178
  pos = decl + 2;
1139
1179
  }
1140
1180
  }
1141
- if (inlineRawOpenerIdx !== -1 && (cp.piOpen || cp.declOpen || cp.cdataOpen)) {
1181
+ if (inlineRawOpenerIdx !== -1 && cp.mdBlock.kind === "html" && cp.mdBlock.type >= 3) {
1142
1182
  cp.phasePoisonedAt = 0;
1143
1183
  }
1144
1184
  let tagText = scanText;
@@ -1146,19 +1186,18 @@ ${cont(scanText)}` };
1146
1186
  tagText = tagText.slice(0, from) + " ".repeat(to - from) + tagText.slice(to);
1147
1187
  }
1148
1188
  let skipTagScan = false;
1149
- if (cp.tagAcrossLines) {
1150
- if (ln.indent < cp.tagAcrossLinesIndent) poisonRawDivergence();
1151
- const attrs = { state: cp.tagAcrossLinesState };
1189
+ if (cp.pendingTag !== null) {
1190
+ if (ln.indent < cp.pendingTag.indent) poisonRawDivergence();
1191
+ const attrs = { state: cp.pendingTag.attr };
1152
1192
  const gt = scanTagAttrs(ln.text, 0, ln.text.length, attrs);
1153
1193
  if (gt === -1) {
1154
1194
  scanTagAttrs("\n", 0, 1, attrs);
1155
- cp.tagAcrossLinesState = attrs.state;
1195
+ cp.pendingTag = { attr: attrs.state, indent: cp.pendingTag.indent };
1156
1196
  skipTagScan = true;
1157
1197
  } else {
1158
1198
  for (const tag of cp.pendingTruncatedCloses) applyTag(tag, true);
1159
1199
  cp.pendingTruncatedCloses = [];
1160
- cp.tagAcrossLines = false;
1161
- cp.tagAcrossLinesState = "outside";
1200
+ cp.pendingTag = null;
1162
1201
  tagText = " ".repeat(gt + 1) + tagText.slice(gt + 1);
1163
1202
  }
1164
1203
  }
@@ -1168,38 +1207,53 @@ ${cont(scanText)}` };
1168
1207
  let m;
1169
1208
  let lastCommentOpenerIdx = -1;
1170
1209
  while ((m = TAG_OR_COMMENT_RE.exec(tagText)) !== null) {
1171
- if (cp.rawTextOpen !== null && (m[0] === "<!--" || m[0] === "-->" || m[0] === "--!>")) {
1172
- if (cp.rawTextOpen === "script" && m[0] === "<!--") cp.scriptDataEscaped = true;
1210
+ if (inRawTextTok(cp.p5Tok) && (m[0] === "<!--" || m[0] === "-->" || m[0] === "--!>")) {
1211
+ if (cp.p5Tok.kind === "script") {
1212
+ if (m[0] === "<!--") cp.p5Tok = { ...cp.p5Tok, escaped: true };
1213
+ if (m[0] === "-->") cp.p5Tok = { ...cp.p5Tok, escaped: false, double: false };
1214
+ }
1173
1215
  continue;
1174
1216
  }
1175
1217
  if (m[0] === "<!--") {
1176
1218
  const next = tagText.slice(m.index + 4, m.index + 6);
1177
- if (cp.commentOpen) {
1178
- if (next.startsWith(">") || next === "->") cp.commentOpen = false;
1179
- else if (next === "!>" || next === "-!") poisonRawDivergence();
1219
+ if (commentEitherOpen(cp.mdBlock, cp.p5Tok)) {
1220
+ if (next.startsWith(">") || next === "->") {
1221
+ if (mdHtml(cp.mdBlock, 2)) cp.mdBlock = { kind: "none" };
1222
+ if (cp.p5Tok.kind === "comment") cp.p5Tok = { kind: "data" };
1223
+ } else if (next === "!>" || next === "-!") {
1224
+ if (cp.p5Tok.kind === "comment") cp.p5Tok = { kind: "data" };
1225
+ if (mdHtml(cp.mdBlock, 2) && P5_MARKUP_RE.test(tagText.slice(m.index + m[0].length))) {
1226
+ poisonRawDivergence();
1227
+ }
1228
+ }
1180
1229
  continue;
1181
1230
  }
1182
1231
  if (next.startsWith(">") || next === "->") {
1183
1232
  continue;
1184
1233
  }
1185
- cp.commentOpen = true;
1234
+ if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 2 };
1235
+ if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "comment" };
1186
1236
  lastCommentOpenerIdx = m.index;
1187
1237
  continue;
1188
1238
  }
1189
1239
  if (m[0] === "-->") {
1190
- cp.commentOpen = false;
1240
+ if (mdHtml(cp.mdBlock, 2)) cp.mdBlock = { kind: "none" };
1241
+ if (cp.p5Tok.kind === "comment") cp.p5Tok = { kind: "data" };
1191
1242
  continue;
1192
1243
  }
1193
1244
  if (m[0] === "--!>") {
1194
- if (cp.commentOpen) poisonRawDivergence();
1245
+ if (mdHtml(cp.mdBlock, 2) && P5_MARKUP_RE.test(tagText.slice(m.index + m[0].length))) {
1246
+ poisonRawDivergence();
1247
+ }
1248
+ if (cp.p5Tok.kind === "comment") cp.p5Tok = { kind: "data" };
1195
1249
  continue;
1196
1250
  }
1197
- if (cp.commentOpen) continue;
1251
+ if (commentEitherOpen(cp.mdBlock, cp.p5Tok)) continue;
1198
1252
  const closing = m[1] === "/";
1199
1253
  const tag = m[2].toLowerCase();
1200
1254
  if (strayTablePart(tag)) cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start + m.index);
1201
1255
  let attrs = m[3] ?? "";
1202
- if (cp.htmlFlowReal && (cp.rawTextOpen === null || closing && tag === cp.rawTextOpen)) {
1256
+ if (cp.mdBlock.kind === "html" && (!inRawTextTok(cp.p5Tok) || closing && tag === rawTextElement(cp.p5Tok))) {
1203
1257
  const attrStart = m.index + 1 + (closing ? 1 : 0) + m[2].length;
1204
1258
  const st = { state: "outside" };
1205
1259
  const gt = scanTagAttrs(tagText, attrStart, tagText.length, st);
@@ -1209,9 +1263,7 @@ ${cont(scanText)}` };
1209
1263
  else applyTag(tag, false);
1210
1264
  }
1211
1265
  scanTagAttrs("\n", 0, 1, st);
1212
- cp.tagAcrossLines = true;
1213
- cp.tagAcrossLinesIndent = ln.indent;
1214
- cp.tagAcrossLinesState = st.state;
1266
+ cp.pendingTag = { attr: st.state, indent: ln.indent };
1215
1267
  tagHandledAsTruncated = true;
1216
1268
  break;
1217
1269
  }
@@ -1220,16 +1272,15 @@ ${cont(scanText)}` };
1220
1272
  TAG_OR_COMMENT_RE.lastIndex = gt + 1;
1221
1273
  }
1222
1274
  }
1223
- if (closing && !cp.htmlFlowReal && !/^\s*$/.test(attrs)) {
1275
+ if (closing && cp.mdBlock.kind !== "html" && !/^\s*$/.test(attrs)) {
1224
1276
  TAG_OR_COMMENT_RE.lastIndex = m.index + 2 + m[2].length;
1225
1277
  continue;
1226
1278
  }
1227
1279
  const selfClosing = /\/\s*$/.test(attrs);
1228
- noteBreakout(tag, closing);
1229
1280
  if (VOID_TAGS.has(tag) || selfClosing && honoursSelfClosing(tag)) continue;
1230
1281
  applyTag(tag, closing);
1231
1282
  }
1232
- if (cp.commentOpen && lastCommentOpenerIdx !== -1) {
1283
+ if (commentEitherOpen(cp.mdBlock, cp.p5Tok) && lastCommentOpenerIdx !== -1) {
1233
1284
  if (!isMdBlank(tagText.slice(0, lastCommentOpenerIdx)) || ln.indent > 3) {
1234
1285
  cp.phasePoisonedAt = 0;
1235
1286
  }
@@ -1242,13 +1293,12 @@ ${cont(scanText)}` };
1242
1293
  if (mr[0] === "<!--" || mr[0] === "-->" || mr[0] === "--!>") continue;
1243
1294
  const startMasked = masked[mr.index] !== ln.text[mr.index];
1244
1295
  const wholeVisible = masked.slice(mr.index, mr.index + mr[0].length) === mr[0];
1245
- if (startMasked || wholeVisible || inRaw(mr.index) || cp.commentOpen) continue;
1296
+ if (startMasked || wholeVisible || inRaw(mr.index) || commentEitherOpen(cp.mdBlock, cp.p5Tok)) continue;
1246
1297
  const closing = mr[1] === "/";
1247
1298
  const tag = mr[2].toLowerCase();
1248
1299
  if (strayTablePart(tag)) cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start + mr.index);
1249
1300
  if (closing && mr[3] !== void 0 && !/^\s*$/.test(mr[3])) continue;
1250
1301
  const selfClosing = mr[3] !== void 0 && /\/\s*$/.test(mr[3]);
1251
- noteBreakout(tag, closing);
1252
1302
  if (VOID_TAGS.has(tag) || selfClosing && honoursSelfClosing(tag)) continue;
1253
1303
  applyTag(tag, closing);
1254
1304
  }
@@ -1259,7 +1309,7 @@ ${cont(scanText)}` };
1259
1309
  }
1260
1310
  cp.pendingTruncatedTags = [];
1261
1311
  }
1262
- if (!cp.commentOpen && !tagHandledAsTruncated) {
1312
+ if (!commentEitherOpen(cp.mdBlock, cp.p5Tok) && !tagHandledAsTruncated) {
1263
1313
  let lastLt = -1;
1264
1314
  TAG_START_LT_RE.lastIndex = 0;
1265
1315
  for (let ms = TAG_START_LT_RE.exec(tagText); ms !== null; ms = TAG_START_LT_RE.exec(tagText)) {
@@ -1271,30 +1321,30 @@ ${cont(scanText)}` };
1271
1321
  if (m2) {
1272
1322
  const closing = m2[1] === "/";
1273
1323
  const tag = m2[2].toLowerCase();
1274
- if (strayTablePart(tag) && cp.htmlFlowReal) {
1324
+ if (strayTablePart(tag) && cp.mdBlock.kind === "html") {
1275
1325
  cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start + lastLt);
1276
1326
  }
1277
- if (cp.htmlFlowReal) {
1278
- cp.tagAcrossLines = true;
1279
- cp.tagAcrossLinesIndent = ln.indent;
1327
+ if (cp.mdBlock.kind === "html") {
1280
1328
  const attrs = { state: "outside" };
1281
1329
  scanTagAttrs(m2[3] + "\n", 0, m2[3].length + 1, attrs);
1282
- cp.tagAcrossLinesState = attrs.state;
1330
+ cp.pendingTag = { attr: attrs.state, indent: ln.indent };
1283
1331
  }
1284
1332
  if (closing) {
1285
- if (!VOID_TAGS.has(tag) && cp.htmlFlowReal) cp.pendingTruncatedCloses.push(tag);
1333
+ if (!VOID_TAGS.has(tag) && cp.mdBlock.kind === "html") cp.pendingTruncatedCloses.push(tag);
1286
1334
  } else if (!VOID_TAGS.has(tag)) {
1287
1335
  applyTag(tag, closing);
1288
1336
  const rawLastLt = ln.text.lastIndexOf("<");
1289
1337
  const rawTruncated = rawLastLt !== -1 && !ln.text.includes(">", rawLastLt);
1290
- if (!closing && !inRawText && rawTruncated) cp.pendingTruncatedTags.push(tag);
1338
+ if (!closing && !(htmlOwnedLine || inRawTextTok(cp.p5Tok)) && rawTruncated) {
1339
+ cp.pendingTruncatedTags.push(tag);
1340
+ }
1291
1341
  }
1292
1342
  }
1293
1343
  }
1294
1344
  }
1295
1345
  }
1296
1346
  const effectiveOpen = cp.openTotal - cp.pendingTruncatedTags.length;
1297
- if ((inRawText || rawFlowStart) && effectiveOpen <= 0) {
1347
+ if ((htmlOwnedLine || inRawTextTok(cp.p5Tok)) && effectiveOpen <= 0) {
1298
1348
  let masked2 = "";
1299
1349
  let cursor = 0;
1300
1350
  for (const [from, to] of rawSpans) {
@@ -1302,22 +1352,38 @@ ${cont(scanText)}` };
1302
1352
  cursor = to;
1303
1353
  }
1304
1354
  masked2 += scanText.slice(cursor);
1305
- if (floatingResidue(masked2, commentOpenAtLineStart).length > 0) {
1306
- cp.htmlSeamPending = true;
1355
+ if (floatingResidue(masked2, bothCommentsOpenAtLineStart).length > 0) {
1356
+ cp.p5SealPending = true;
1307
1357
  }
1308
1358
  }
1309
- if (cp.rawTextOpen !== null && cp.rawTextInline) {
1359
+ if (inRawTextTok(cp.p5Tok) && cp.p5Tok.openedInline) {
1310
1360
  cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
1311
1361
  }
1312
- if (cp.type1FlowOpen && TYPE1_CLOSE_RE.test(ln.text)) {
1313
- cp.type1FlowOpen = false;
1314
- cp.htmlFlowSinceBlank = false;
1315
- cp.htmlFlowReal = false;
1362
+ if (mdHtml(cp.mdBlock, 1) && TYPE1_CLOSE_RE.test(ln.text)) {
1363
+ cp.mdBlock = { kind: "none" };
1364
+ if (inRawTextTok(cp.p5Tok)) cp.phasePoisonedAt = 0;
1316
1365
  }
1317
1366
  cp.blankRun = 0;
1318
1367
  cp.prevLineBlank = false;
1319
1368
  cp.prevLineWasText = true;
1320
- cp.prevLineWasValidDef = validDef && !def[1].startsWith("^");
1369
+ {
1370
+ const tt = mdTrimStart(ln.text);
1371
+ let openContent;
1372
+ if (htmlOwnedLine) {
1373
+ openContent = false;
1374
+ } else if (ln.indent >= 4) {
1375
+ openContent = cp.prevLineOpenContent;
1376
+ } else if (ATX_HEADING_RE.test(tt) || THEMATIC_BREAK_RE.test(tt) || BARE_MARKER_RE.test(tt)) {
1377
+ openContent = false;
1378
+ } else if (SETEXT_LEFTOVER_RE.test(tt)) {
1379
+ openContent = !cp.prevLineOpenContent;
1380
+ } else {
1381
+ openContent = true;
1382
+ }
1383
+ cp.prevLineOpenContent = openContent;
1384
+ cp.tableMaybeOpen = ln.text.includes("|") || cp.tableMaybeOpen && openContent;
1385
+ }
1386
+ cp.prevLineWasValidDef = validLinkDef;
1321
1387
  }
1322
1388
 
1323
1389
  // src/components/incrementalParse/spliceParse.ts
@@ -1566,6 +1632,33 @@ function headRoutedCaptureUnclosed(values) {
1566
1632
  return !new RegExp(`</${name}(?=[\\s/>])`, "i").test(after);
1567
1633
  }
1568
1634
  var STRAY_SYNTHESIZED_END_TAG_RE = /<\/(?:br|p)\b/i;
1635
+ var RAW_TEXT_OPEN_RE = /<(script|style|textarea|title|xmp|iframe|noembed|noframes|plaintext)(?=[\s/>])/gi;
1636
+ function rawTextRegionCrossesOut(values) {
1637
+ for (const value of values) {
1638
+ let pos = 0;
1639
+ for (; ; ) {
1640
+ RAW_TEXT_OPEN_RE.lastIndex = pos;
1641
+ const open = RAW_TEXT_OPEN_RE.exec(value);
1642
+ if (open === null) break;
1643
+ const name = open[1].toLowerCase();
1644
+ const bodyStart = open.index + open[0].length;
1645
+ const closeRe = new RegExp(`</${name}(?=[\\s/>])`, "ig");
1646
+ closeRe.lastIndex = bodyStart;
1647
+ let close = closeRe.exec(value);
1648
+ if (name === "script") {
1649
+ while (close !== null) {
1650
+ const body = value.slice(bodyStart, close.index);
1651
+ const lastOpen = body.lastIndexOf("<!--");
1652
+ if (lastOpen === -1 || body.indexOf("-->", lastOpen + 4) !== -1) break;
1653
+ close = closeRe.exec(value);
1654
+ }
1655
+ }
1656
+ if (close === null) return true;
1657
+ pos = close.index + close[0].length;
1658
+ }
1659
+ }
1660
+ return false;
1661
+ }
1569
1662
  function spliceTrees(input) {
1570
1663
  const { prevMdast, prevHast, tailMdast, tailHast, content, boundary, injectionPrefix, injectedSegments } = input;
1571
1664
  const injectedLen = injectionPrefix.length;
@@ -1622,7 +1715,9 @@ function spliceTrees(input) {
1622
1715
  return !(start !== void 0 && start < injectedLen);
1623
1716
  });
1624
1717
  const tailWrapVisible = tailMdastChildren.some((child) => !isWrapInvisible(child));
1625
- if (hasStrayTablePart(prefixMdast.flatMap((c) => c.type === "html" ? [c.value] : []))) return null;
1718
+ const prefixHtmlValues = prefixMdast.flatMap((c) => c.type === "html" ? [c.value] : []);
1719
+ if (hasStrayTablePart(prefixHtmlValues)) return null;
1720
+ if (rawTextRegionCrossesOut(prefixHtmlValues)) return null;
1626
1721
  const leadingHtml = [];
1627
1722
  for (const child of tailMdastChildren) {
1628
1723
  if (isWrapInvisible(child)) continue;