@ai-react-markdown/engine 2.8.2 → 2.9.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.dev.js CHANGED
@@ -289,9 +289,9 @@ function inlineResourceEnd(text, openIdx) {
289
289
  }
290
290
  return -1;
291
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;
292
+ function collectRefLine(cp, lnStart, lnEnd, scanText, rawText, inRawText, isBlockStart) {
293
+ const defShaped = inRawText ? null : DEF_RE.exec(rawText);
294
+ const def = defShaped !== null && (defShaped[1].startsWith("^") || isPlausibleLinkDefRest(rawText.slice(defShaped.index + defShaped[0].length))) ? defShaped : null;
295
295
  const defLineStart = isBlockStart || !cp.prevLineWasText || cp.prevLineWasValidDef;
296
296
  const validDef = def !== null && defLineStart;
297
297
  if (validDef) {
@@ -509,12 +509,15 @@ var rawTextElement = (t) => t.kind === "rawText" ? t.element : t.kind === "scrip
509
509
  var VOID_TAGS = /* @__PURE__ */ new Set([
510
510
  "area",
511
511
  "base",
512
+ "basefont",
513
+ "bgsound",
512
514
  "br",
513
515
  "col",
514
516
  "embed",
515
517
  "hr",
516
518
  "img",
517
519
  "input",
520
+ "keygen",
518
521
  "link",
519
522
  "meta",
520
523
  "param",
@@ -766,6 +769,24 @@ function floatingResidue(text, commentOpenAtStart) {
766
769
  if (!open) out += text.slice(last);
767
770
  return out;
768
771
  }
772
+ var RAW_CONSTRUCT_START_RE = /^<(?:!--|\?|![A-Za-z]|!\[CDATA\[)/;
773
+ var sealResumableAbove = (cp) => cp.defBlockMaybeOpen || cp.fnDefResumable || cp.containerMaybeOpen;
774
+ function sealReleaseDerived(cp, ln, isBlockStart) {
775
+ if (sealResumableAbove(cp) && !(isBlockStart && ln.indent <= 3)) return false;
776
+ if (cp.prevLineOpenContent) return false;
777
+ if (cp.tableMaybeOpen) return false;
778
+ const head = mdTrimStart(ln.text);
779
+ if (RAW_CONSTRUCT_START_RE.test(head) || TYPE1_START_RE.test(head) || isType7Line(head)) return false;
780
+ const t6 = TYPE6_START_RE.exec(head);
781
+ if (t6 !== null && TYPE6_NAMES.has(t6[1].toLowerCase())) return false;
782
+ if (DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text)) return false;
783
+ return true;
784
+ }
785
+ function sealReleaseEnumerated(cp, ln, isBlockStart) {
786
+ const defShapedLine = DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text) || cp.defBlockMaybeOpen || cp.fnDefResumable && !(isBlockStart && ln.indent <= 3);
787
+ const commentOnly = ln.text.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!--[\s\S]*$/, " ").replace(/[ \t\r]/g, "") === "";
788
+ return !defShapedLine && !commentOnly && !CLOSE_TAG_ONLY_RE.test(ln.text);
789
+ }
769
790
  function processConfirmedLine(cp, ln, text) {
770
791
  const newest = cp.candidates[cp.candidates.length - 1];
771
792
  if (newest && newest.defListSettled === null) {
@@ -773,16 +794,19 @@ function processConfirmedLine(cp, ln, text) {
773
794
  }
774
795
  const isBlockStart = cp.prevLineBlank;
775
796
  if (cp.p5SealPending && !ln.blank && cp.mdBlock.kind !== "html" && !(cp.p5Tok.kind === "comment" || cp.p5Tok.kind === "bogus")) {
776
- const defShapedLine = DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text) || cp.defBlockMaybeOpen || cp.fnDefResumable && !(isBlockStart && ln.indent <= 3);
777
- const commentOnly = ln.text.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!--[\s\S]*$/, " ").replace(/[ \t\r]/g, "") === "";
778
- const closeTagOnly = CLOSE_TAG_ONLY_RE.test(ln.text);
779
- if (!defShapedLine && !commentOnly && !closeTagOnly) {
797
+ if (sealReleaseDerived(cp, ln, isBlockStart)) {
780
798
  cp.p5SealPending = false;
799
+ if (!sealReleaseEnumerated(cp, ln, isBlockStart)) {
800
+ console.error(
801
+ `[ai-react-markdown] seal-release containment broken at offset ${ln.start}: the derived predicate released a line the retired enumeration withheld (${JSON.stringify(ln.text.slice(0, 80))}).`
802
+ );
803
+ }
781
804
  }
782
805
  }
783
806
  const possiblyInsideForeign = () => FOREIGN_ROOT_NAMES.some((name) => (cp.tagBalance.get(name) ?? 0) > 0);
784
807
  const honoursSelfClosing = (tag) => tag === "svg" || tag === "math";
785
808
  const foreignRawTextSwitchUnknowable = () => possiblyInsideForeign();
809
+ let discardedEndTag = false;
786
810
  const applyTag = (tag, closing) => {
787
811
  if (inRawTextTok(cp.p5Tok)) {
788
812
  if (cp.p5Tok.kind === "script" && cp.p5Tok.escaped && !closing && tag === "script") {
@@ -815,7 +839,10 @@ function processConfirmedLine(cp, ln, text) {
815
839
  }
816
840
  if (SCOPE_BARRIER_NAMES.has(cp.openStack[i])) break;
817
841
  }
818
- if (idx === -1) return;
842
+ if (idx === -1) {
843
+ discardedEndTag = true;
844
+ return;
845
+ }
819
846
  cp.openStack.splice(idx, 1);
820
847
  const count = cp.tagBalance.get(tag) ?? 0;
821
848
  if (count > 0) {
@@ -934,6 +961,9 @@ function processConfirmedLine(cp, ln, text) {
934
961
  cp.p5Tok = { kind: "data" };
935
962
  }
936
963
  }
964
+ if (cp.p5Tok.kind === "comment" && !mdHtml(cp.mdBlock, 2)) {
965
+ cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
966
+ }
937
967
  if (cp.mdBlock.kind === "html" && cp.mdBlock.type >= 6) cp.mdBlock = { kind: "none" };
938
968
  cp.blankRun += 1;
939
969
  cp.lastBlankStart = ln.start;
@@ -1001,14 +1031,14 @@ function processConfirmedLine(cp, ln, text) {
1001
1031
  }
1002
1032
  }
1003
1033
  }
1004
- const rawFlowStart = ln.indent <= 3 && /^<(?:!--|\?|![A-Za-z]|!\[CDATA\[)/.test(mdTrimStart(ln.text));
1034
+ const rawFlowStart = ln.indent <= 3 && RAW_CONSTRUCT_START_RE.test(mdTrimStart(ln.text));
1005
1035
  const htmlOwnedLine = cp.mdBlock.kind === "html" || rawOpenAtLineStart || rawFlowStart;
1006
1036
  const maskingSuppressed = htmlOwnedLine || inRawTextTok(cp.p5Tok);
1007
1037
  const { masked, unpaired } = maskingSuppressed ? { masked: null, unpaired: false } : maskIntraLineCodeSpans(ln.text, cp.paragraphHasUnpairedRun);
1008
1038
  if (unpaired) cp.paragraphHasUnpairedRun = true;
1009
1039
  const scanText = masked ?? ln.text;
1010
1040
  const defRawToMicromark = cp.mdBlock.kind === "html" || rawOpenAtLineStart || inRawTextTok(cp.p5Tok);
1011
- const { validLinkDef } = collectRefLine(cp, ln.start, ln.end, scanText, defRawToMicromark, isBlockStart);
1041
+ const { validLinkDef } = collectRefLine(cp, ln.start, ln.end, scanText, ln.text, defRawToMicromark, isBlockStart);
1012
1042
  const rawSpans = [];
1013
1043
  let pos = 0;
1014
1044
  const poisonRawDivergence = () => {
@@ -1283,7 +1313,7 @@ function processConfirmedLine(cp, ln, text) {
1283
1313
  cursor = to;
1284
1314
  }
1285
1315
  masked2 += scanText.slice(cursor);
1286
- if (floatingResidue(masked2, bothCommentsOpenAtLineStart).length > 0) {
1316
+ if (floatingResidue(masked2, bothCommentsOpenAtLineStart).length > 0 || discardedEndTag) {
1287
1317
  cp.p5SealPending = true;
1288
1318
  }
1289
1319
  }
@@ -1336,6 +1366,16 @@ function processConfirmedLine(cp, ln, text) {
1336
1366
  }
1337
1367
  }
1338
1368
  }
1369
+ var SCANNER_NAME_LISTS = [
1370
+ ["type1", TYPE1_NAMES],
1371
+ ["rawText", RAW_TEXT_ELEMENTS],
1372
+ ["type6", TYPE6_NAMES],
1373
+ ["void", VOID_TAGS],
1374
+ ["documentStructure", DOCUMENT_STRUCTURE_NAMES],
1375
+ ["tablePart", TABLE_PART_NAMES],
1376
+ ["scopeBarrier", SCOPE_BARRIER_NAMES],
1377
+ ["foreignRoot", new Set(FOREIGN_ROOT_NAMES)]
1378
+ ];
1339
1379
 
1340
1380
  // src/components/incrementalParse/spliceParse.ts
1341
1381
  import { normalizeIdentifier as normalizeIdentifier2 } from "micromark-util-normalize-identifier";