@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.cjs CHANGED
@@ -336,7 +336,8 @@ var HTML_BREAKOUT_TAGS = /* @__PURE__ */ new Set([
336
336
  "ul",
337
337
  "var"
338
338
  ]);
339
- var HTML_INTEGRATION_POINTS = ["foreignobject", "desc", "mi", "mo", "mn", "ms", "mtext", "annotation-xml"];
339
+ var HTML_INTEGRATION_POINTS = ["foreignobject", "desc", "title", "mi", "mo", "mn", "ms", "mtext", "annotation-xml"];
340
+ var FOREIGN_ROOT_NAMES = ["svg", "math"];
340
341
  var TYPE1_NAMES = /* @__PURE__ */ new Set(["script", "pre", "style", "textarea"]);
341
342
  var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
342
343
  "script",
@@ -506,6 +507,7 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
506
507
  piOpen: false,
507
508
  bogusOpen: false,
508
509
  rawTextOpen: null,
510
+ scriptDataEscaped: false,
509
511
  declOpen: false,
510
512
  cdataOpen: false,
511
513
  inFence: false,
@@ -746,7 +748,7 @@ function processConfirmedLine(cp, ln, text) {
746
748
  cp.htmlSeamPending = false;
747
749
  }
748
750
  }
749
- const inForeignContent = () => (cp.tagBalance.get("svg") ?? 0) > 0 || (cp.tagBalance.get("math") ?? 0) > 0;
751
+ const inForeignContent = () => FOREIGN_ROOT_NAMES.some((name) => (cp.tagBalance.get(name) ?? 0) > 0);
750
752
  const honoursSelfClosing = (tag) => {
751
753
  if (tag === "svg" || tag === "math") return true;
752
754
  if (!inForeignContent() || HTML_BREAKOUT_TAGS.has(tag)) return false;
@@ -758,14 +760,35 @@ function processConfirmedLine(cp, ln, text) {
758
760
  for (const ip of HTML_INTEGRATION_POINTS) if ((cp.tagBalance.get(ip) ?? 0) > 0) return true;
759
761
  return false;
760
762
  };
763
+ const popForeignRoots = () => {
764
+ for (const name of FOREIGN_ROOT_NAMES) {
765
+ const count = cp.tagBalance.get(name) ?? 0;
766
+ if (count > 0) {
767
+ cp.tagBalance.set(name, 0);
768
+ cp.openTotal -= count;
769
+ }
770
+ }
771
+ };
772
+ const noteBreakout = (tag, closing) => {
773
+ if (closing || cp.rawTextOpen !== null) return;
774
+ if (HTML_BREAKOUT_TAGS.has(tag) && !htmlRulesApply()) popForeignRoots();
775
+ };
761
776
  const applyTag = (tag, closing) => {
762
777
  if (cp.rawTextOpen !== null) {
778
+ if (cp.scriptDataEscaped && !closing && tag === "script") {
779
+ cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
780
+ }
763
781
  if (!(closing && tag === cp.rawTextOpen)) return;
764
782
  cp.rawTextOpen = null;
765
- } else if (!closing && RAW_TEXT_ELEMENTS.has(tag) && htmlRulesApply()) {
766
- cp.rawTextOpen = tag;
767
- cp.rawTextInline = !cp.htmlFlowReal;
768
- if (tag === "plaintext") cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
783
+ cp.scriptDataEscaped = false;
784
+ } else {
785
+ noteBreakout(tag, closing);
786
+ if (!closing && RAW_TEXT_ELEMENTS.has(tag) && htmlRulesApply()) {
787
+ cp.rawTextOpen = tag;
788
+ cp.scriptDataEscaped = false;
789
+ cp.rawTextInline = !cp.htmlFlowReal;
790
+ if (tag === "plaintext") cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
791
+ }
769
792
  }
770
793
  if (DOCUMENT_STRUCTURE_NAMES.has(tag)) cp.phasePoisonedAt = 0;
771
794
  if (closing) {
@@ -1092,7 +1115,10 @@ ${cont(scanText)}` };
1092
1115
  let m;
1093
1116
  let lastCommentOpenerIdx = -1;
1094
1117
  while ((m = TAG_OR_COMMENT_RE.exec(tagText)) !== null) {
1095
- if (cp.rawTextOpen !== null && (m[0] === "<!--" || m[0] === "-->" || m[0] === "--!>")) continue;
1118
+ if (cp.rawTextOpen !== null && (m[0] === "<!--" || m[0] === "-->" || m[0] === "--!>")) {
1119
+ if (cp.rawTextOpen === "script" && m[0] === "<!--") cp.scriptDataEscaped = true;
1120
+ continue;
1121
+ }
1096
1122
  if (m[0] === "<!--") {
1097
1123
  const next = tagText.slice(m.index + 4, m.index + 6);
1098
1124
  if (cp.commentOpen) {
@@ -1146,6 +1172,7 @@ ${cont(scanText)}` };
1146
1172
  continue;
1147
1173
  }
1148
1174
  const selfClosing = /\/\s*$/.test(attrs);
1175
+ noteBreakout(tag, closing);
1149
1176
  if (VOID_TAGS.has(tag) || selfClosing && honoursSelfClosing(tag)) continue;
1150
1177
  applyTag(tag, closing);
1151
1178
  }
@@ -1168,6 +1195,7 @@ ${cont(scanText)}` };
1168
1195
  if (strayTablePart(tag)) cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start + mr.index);
1169
1196
  if (closing && mr[3] !== void 0 && !/^\s*$/.test(mr[3])) continue;
1170
1197
  const selfClosing = mr[3] !== void 0 && /\/\s*$/.test(mr[3]);
1198
+ noteBreakout(tag, closing);
1171
1199
  if (VOID_TAGS.has(tag) || selfClosing && honoursSelfClosing(tag)) continue;
1172
1200
  applyTag(tag, closing);
1173
1201
  }