@ai-react-markdown/engine 2.5.3 → 2.5.4

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.js CHANGED
@@ -243,7 +243,8 @@ var HTML_BREAKOUT_TAGS = /* @__PURE__ */ new Set([
243
243
  "ul",
244
244
  "var"
245
245
  ]);
246
- var HTML_INTEGRATION_POINTS = ["foreignobject", "desc", "mi", "mo", "mn", "ms", "mtext", "annotation-xml"];
246
+ var HTML_INTEGRATION_POINTS = ["foreignobject", "desc", "title", "mi", "mo", "mn", "ms", "mtext", "annotation-xml"];
247
+ var FOREIGN_ROOT_NAMES = ["svg", "math"];
247
248
  var TYPE1_NAMES = /* @__PURE__ */ new Set(["script", "pre", "style", "textarea"]);
248
249
  var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
249
250
  "script",
@@ -413,6 +414,7 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
413
414
  piOpen: false,
414
415
  bogusOpen: false,
415
416
  rawTextOpen: null,
417
+ scriptDataEscaped: false,
416
418
  declOpen: false,
417
419
  cdataOpen: false,
418
420
  inFence: false,
@@ -653,7 +655,7 @@ function processConfirmedLine(cp, ln, text) {
653
655
  cp.htmlSeamPending = false;
654
656
  }
655
657
  }
656
- const inForeignContent = () => (cp.tagBalance.get("svg") ?? 0) > 0 || (cp.tagBalance.get("math") ?? 0) > 0;
658
+ const inForeignContent = () => FOREIGN_ROOT_NAMES.some((name) => (cp.tagBalance.get(name) ?? 0) > 0);
657
659
  const honoursSelfClosing = (tag) => {
658
660
  if (tag === "svg" || tag === "math") return true;
659
661
  if (!inForeignContent() || HTML_BREAKOUT_TAGS.has(tag)) return false;
@@ -665,14 +667,35 @@ function processConfirmedLine(cp, ln, text) {
665
667
  for (const ip of HTML_INTEGRATION_POINTS) if ((cp.tagBalance.get(ip) ?? 0) > 0) return true;
666
668
  return false;
667
669
  };
670
+ const popForeignRoots = () => {
671
+ for (const name of FOREIGN_ROOT_NAMES) {
672
+ const count = cp.tagBalance.get(name) ?? 0;
673
+ if (count > 0) {
674
+ cp.tagBalance.set(name, 0);
675
+ cp.openTotal -= count;
676
+ }
677
+ }
678
+ };
679
+ const noteBreakout = (tag, closing) => {
680
+ if (closing || cp.rawTextOpen !== null) return;
681
+ if (HTML_BREAKOUT_TAGS.has(tag) && !htmlRulesApply()) popForeignRoots();
682
+ };
668
683
  const applyTag = (tag, closing) => {
669
684
  if (cp.rawTextOpen !== null) {
685
+ if (cp.scriptDataEscaped && !closing && tag === "script") {
686
+ cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
687
+ }
670
688
  if (!(closing && tag === cp.rawTextOpen)) return;
671
689
  cp.rawTextOpen = null;
672
- } else if (!closing && RAW_TEXT_ELEMENTS.has(tag) && htmlRulesApply()) {
673
- cp.rawTextOpen = tag;
674
- cp.rawTextInline = !cp.htmlFlowReal;
675
- if (tag === "plaintext") cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
690
+ cp.scriptDataEscaped = false;
691
+ } else {
692
+ noteBreakout(tag, closing);
693
+ if (!closing && RAW_TEXT_ELEMENTS.has(tag) && htmlRulesApply()) {
694
+ cp.rawTextOpen = tag;
695
+ cp.scriptDataEscaped = false;
696
+ cp.rawTextInline = !cp.htmlFlowReal;
697
+ if (tag === "plaintext") cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
698
+ }
676
699
  }
677
700
  if (DOCUMENT_STRUCTURE_NAMES.has(tag)) cp.phasePoisonedAt = 0;
678
701
  if (closing) {
@@ -999,7 +1022,10 @@ ${cont(scanText)}` };
999
1022
  let m;
1000
1023
  let lastCommentOpenerIdx = -1;
1001
1024
  while ((m = TAG_OR_COMMENT_RE.exec(tagText)) !== null) {
1002
- if (cp.rawTextOpen !== null && (m[0] === "<!--" || m[0] === "-->" || m[0] === "--!>")) continue;
1025
+ if (cp.rawTextOpen !== null && (m[0] === "<!--" || m[0] === "-->" || m[0] === "--!>")) {
1026
+ if (cp.rawTextOpen === "script" && m[0] === "<!--") cp.scriptDataEscaped = true;
1027
+ continue;
1028
+ }
1003
1029
  if (m[0] === "<!--") {
1004
1030
  const next = tagText.slice(m.index + 4, m.index + 6);
1005
1031
  if (cp.commentOpen) {
@@ -1053,6 +1079,7 @@ ${cont(scanText)}` };
1053
1079
  continue;
1054
1080
  }
1055
1081
  const selfClosing = /\/\s*$/.test(attrs);
1082
+ noteBreakout(tag, closing);
1056
1083
  if (VOID_TAGS.has(tag) || selfClosing && honoursSelfClosing(tag)) continue;
1057
1084
  applyTag(tag, closing);
1058
1085
  }
@@ -1075,6 +1102,7 @@ ${cont(scanText)}` };
1075
1102
  if (strayTablePart(tag)) cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start + mr.index);
1076
1103
  if (closing && mr[3] !== void 0 && !/^\s*$/.test(mr[3])) continue;
1077
1104
  const selfClosing = mr[3] !== void 0 && /\/\s*$/.test(mr[3]);
1105
+ noteBreakout(tag, closing);
1078
1106
  if (VOID_TAGS.has(tag) || selfClosing && honoursSelfClosing(tag)) continue;
1079
1107
  applyTag(tag, closing);
1080
1108
  }