@ai-react-markdown/engine 2.5.2 → 2.5.3

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
@@ -177,6 +177,26 @@ import { htmlBlockNames } from "micromark-util-html-tag-name";
177
177
  import { normalizeIdentifier } from "micromark-util-normalize-identifier";
178
178
  var TYPE6_NAMES = new Set(htmlBlockNames);
179
179
  var TABLE_PART_NAMES = /* @__PURE__ */ new Set(["td", "th", "tr", "tbody", "thead", "tfoot", "caption", "col", "colgroup"]);
180
+ var DOCUMENT_STRUCTURE_NAMES = /* @__PURE__ */ new Set(["html", "head", "body", "frameset"]);
181
+ var RETROACTIVE_OPENERS = [
182
+ "<!doctype",
183
+ "<html",
184
+ "<head",
185
+ "<body",
186
+ "<frameset",
187
+ "</html",
188
+ "</head",
189
+ "</body",
190
+ "</frameset"
191
+ ];
192
+ function tailCarriesRetroactive(text) {
193
+ const lower = text.toLowerCase();
194
+ for (let i = lower.indexOf("<"); i !== -1; i = lower.indexOf("<", i + 1)) {
195
+ const rest = lower.slice(i);
196
+ for (const op of RETROACTIVE_OPENERS) if (rest.startsWith(op)) return true;
197
+ }
198
+ return false;
199
+ }
180
200
  var HTML_BREAKOUT_TAGS = /* @__PURE__ */ new Set([
181
201
  "b",
182
202
  "big",
@@ -242,6 +262,7 @@ var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
242
262
  ]);
243
263
  var TYPE6_START_RE = /^<\/?([A-Za-z][A-Za-z0-9-]*)(?:[ \t\r]|\/?>|$)/;
244
264
  var TYPE1_START_RE = /^<(script|pre|style|textarea)(?:[ \t\r]|>|$)/i;
265
+ var TYPE1_CLOSE_RE = /<\/(?:script|pre|style|textarea)>/i;
245
266
  var TYPE7_LINE_RE = /^(?:<[A-Za-z][A-Za-z0-9-]*(?:[ \t\r][^>]*|\/)?>|<\/[A-Za-z][A-Za-z0-9-]*[ \t\r]*>)[ \t\r]*$/;
246
267
  var t7Name = (line) => /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(line)[1];
247
268
  var VOID_TAGS = /* @__PURE__ */ new Set([
@@ -417,7 +438,9 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
417
438
  tagAcrossLines: false,
418
439
  tagAcrossLinesIndent: 0,
419
440
  tagAcrossLinesState: "outside",
420
- htmlFlowReal: false
441
+ htmlFlowReal: false,
442
+ type1FlowOpen: false,
443
+ rawTextInline: false
421
444
  };
422
445
  }
423
446
  function isPlausibleLinkDefRest(rest) {
@@ -562,8 +585,9 @@ function computeFreezeBoundary(text, options, resume) {
562
585
  if (tailLine) return !canBecomeDdLine(tailLine.text, false);
563
586
  return false;
564
587
  };
588
+ const tailRetroactive = tailLine !== null && tailCarriesRetroactive(tailLine.text);
565
589
  let boundary = 0;
566
- for (let i = cp.candidates.length - 1; i >= 0; i--) {
590
+ for (let i = cp.candidates.length - 1; i >= 0 && !tailRetroactive; i--) {
567
591
  const c = cp.candidates[i];
568
592
  if (!c.htmlBalanced || c.hazard || c.seamRisk) continue;
569
593
  if (c.offset > cp.phasePoisonedAt) continue;
@@ -647,8 +671,10 @@ function processConfirmedLine(cp, ln, text) {
647
671
  cp.rawTextOpen = null;
648
672
  } else if (!closing && RAW_TEXT_ELEMENTS.has(tag) && htmlRulesApply()) {
649
673
  cp.rawTextOpen = tag;
674
+ cp.rawTextInline = !cp.htmlFlowReal;
650
675
  if (tag === "plaintext") cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
651
676
  }
677
+ if (DOCUMENT_STRUCTURE_NAMES.has(tag)) cp.phasePoisonedAt = 0;
652
678
  if (closing) {
653
679
  const count = cp.tagBalance.get(tag) ?? 0;
654
680
  if (count > 0) {
@@ -759,15 +785,22 @@ function processConfirmedLine(cp, ln, text) {
759
785
  cp.candidates.push({
760
786
  offset: Math.min(ln.end + 1, text.length),
761
787
  blankRun: cp.blankRun,
762
- htmlBalanced: cp.openTotal === 0 && !cp.commentOpen && !cp.piOpen && !cp.declOpen && !cp.cdataOpen && !cp.bogusOpen,
788
+ // `type1FlowOpen`: an unterminated type-1 block swallows this blank
789
+ // and everything after it as RAW content, so nothing here is a block
790
+ // boundary at all. Its tags are invisible to the balance scan
791
+ // (`rawTextOpen` suppresses them), which is exactly why `openTotal`
792
+ // reads 0 and the candidate looked safe.
793
+ htmlBalanced: cp.openTotal === 0 && !cp.commentOpen && !cp.piOpen && !cp.declOpen && !cp.cdataOpen && !cp.bogusOpen && !cp.type1FlowOpen,
763
794
  hazard: cp.hazardVerdict,
764
795
  seamRisk: cp.htmlSeamPending,
765
796
  defListSettled: null
766
797
  });
767
798
  cp.paragraphHasUnpairedRun = false;
768
799
  cp.openBracket = null;
769
- cp.htmlFlowSinceBlank = false;
770
- cp.htmlFlowReal = false;
800
+ if (!cp.type1FlowOpen) {
801
+ cp.htmlFlowSinceBlank = false;
802
+ cp.htmlFlowReal = false;
803
+ }
771
804
  cp.prevLineBlank = true;
772
805
  cp.prevLineWasText = false;
773
806
  cp.prevLineWasValidDef = false;
@@ -781,7 +814,9 @@ function processConfirmedLine(cp, ln, text) {
781
814
  }
782
815
  const tagStart = ln.indent <= 3 ? /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(mdTrimStart(ln.text)) : null;
783
816
  if (tagStart) {
817
+ const noRealBlockOpen = !cp.htmlFlowReal;
784
818
  cp.htmlFlowSinceBlank = true;
819
+ if (noRealBlockOpen && TYPE1_START_RE.test(mdTrimStart(ln.text))) cp.type1FlowOpen = true;
785
820
  if (!TYPE6_NAMES.has(tagStart[1].toLowerCase())) cp.hazardVerdict = true;
786
821
  if (!cp.htmlFlowReal) {
787
822
  const t = mdTrimStart(ln.text);
@@ -932,6 +967,7 @@ ${cont(scanText)}` };
932
967
  pos = pi + 2;
933
968
  } else {
934
969
  rawSpans.push([decl, decl + 2]);
970
+ if (ln.indent <= 3 && /^doctype/i.test(scanText.slice(decl + 2))) cp.phasePoisonedAt = 0;
935
971
  cp.declOpen = true;
936
972
  pos = decl + 2;
937
973
  }
@@ -1012,7 +1048,10 @@ ${cont(scanText)}` };
1012
1048
  TAG_OR_COMMENT_RE.lastIndex = gt + 1;
1013
1049
  }
1014
1050
  }
1015
- if (closing && !cp.htmlFlowReal && !/^\s*$/.test(attrs)) continue;
1051
+ if (closing && !cp.htmlFlowReal && !/^\s*$/.test(attrs)) {
1052
+ TAG_OR_COMMENT_RE.lastIndex = m.index + 2 + m[2].length;
1053
+ continue;
1054
+ }
1016
1055
  const selfClosing = /\/\s*$/.test(attrs);
1017
1056
  if (VOID_TAGS.has(tag) || selfClosing && honoursSelfClosing(tag)) continue;
1018
1057
  applyTag(tag, closing);
@@ -1093,6 +1132,14 @@ ${cont(scanText)}` };
1093
1132
  cp.htmlSeamPending = true;
1094
1133
  }
1095
1134
  }
1135
+ if (cp.rawTextOpen !== null && cp.rawTextInline) {
1136
+ cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
1137
+ }
1138
+ if (cp.type1FlowOpen && TYPE1_CLOSE_RE.test(ln.text)) {
1139
+ cp.type1FlowOpen = false;
1140
+ cp.htmlFlowSinceBlank = false;
1141
+ cp.htmlFlowReal = false;
1142
+ }
1096
1143
  cp.blankRun = 0;
1097
1144
  cp.prevLineBlank = false;
1098
1145
  cp.prevLineWasText = true;