@ai-react-markdown/engine 2.8.0 → 2.8.2

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
@@ -501,6 +501,7 @@ var isType7Line = (line) => {
501
501
  return i >= t.length;
502
502
  };
503
503
  var mdHtml = (b, type) => b.kind === "html" && b.type === type;
504
+ var mdType1RawText = (b) => b.kind === "html" && b.type === 1 && b.raw;
504
505
  var mdHtml25 = (b) => b.kind === "html" && b.type >= 2 && b.type <= 5;
505
506
  var commentEitherOpen = (md, p5) => mdHtml(md, 2) || p5.kind === "comment";
506
507
  var inRawTextTok = (t) => t.kind === "rawText" || t.kind === "script";
@@ -522,11 +523,13 @@ var VOID_TAGS = /* @__PURE__ */ new Set([
522
523
  "wbr"
523
524
  ]);
524
525
  var LIST_MARKER_RE = /^ {0,3}(?:[-*+]|\d{1,9}[.)])(?:[ \t]|$)/;
526
+ var CONTAINER_MARKER_RE = /^ {0,3}(?:>|(?:[-*+]|\d{1,9}[.)])[ \t]+\S)/;
525
527
  var ATX_HEADING_RE = /^#{1,6}(?:[ \t]|$)/;
526
528
  var THEMATIC_BREAK_RE = /^(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/;
527
529
  var BARE_MARKER_RE = /^(?:[-*+]|\d{1,9}[.)])[ \t]*$/;
528
530
  var SETEXT_LEFTOVER_RE = /^(?:=+|--)[ \t]*$/;
529
531
  var DEF_LIST_DD_RE = /^ {0,3}:[ \t]/;
532
+ var CLOSE_TAG_ONLY_RE = /^[ \t]*<\/[A-Za-z][A-Za-z0-9-]*[ \t]*>[ \t\r]*$/;
530
533
  var FENCE_RE = /^ {0,3}(`{3,}|~{3,})/;
531
534
  var MATH_RUN_RE = /^ {0,3}(\$\$+)/;
532
535
  var TAG_OR_COMMENT_RE = /<(\/?)([A-Za-z][A-Za-z0-9-]*)(?=[\s/>])([^>]*)>|<!--|-->|--!>/g;
@@ -637,9 +640,12 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
637
640
  prevLineWasValidDef: false,
638
641
  prevLineOpenContent: false,
639
642
  tableMaybeOpen: false,
643
+ containerMaybeOpen: false,
640
644
  paragraphHasUnpairedRun: false,
641
645
  openBracket: null,
642
646
  p5SealPending: false,
647
+ defBlockMaybeOpen: false,
648
+ fnDefResumable: false,
643
649
  phasePoisonedAt: Infinity,
644
650
  pendingTruncatedTags: [],
645
651
  pendingTruncatedCloses: [],
@@ -767,9 +773,10 @@ function processConfirmedLine(cp, ln, text) {
767
773
  }
768
774
  const isBlockStart = cp.prevLineBlank;
769
775
  if (cp.p5SealPending && !ln.blank && cp.mdBlock.kind !== "html" && !(cp.p5Tok.kind === "comment" || cp.p5Tok.kind === "bogus")) {
770
- const defShapedLine = DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text);
776
+ const defShapedLine = DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text) || cp.defBlockMaybeOpen || cp.fnDefResumable && !(isBlockStart && ln.indent <= 3);
771
777
  const commentOnly = ln.text.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!--[\s\S]*$/, " ").replace(/[ \t\r]/g, "") === "";
772
- if (!defShapedLine && !commentOnly) {
778
+ const closeTagOnly = CLOSE_TAG_ONLY_RE.test(ln.text);
779
+ if (!defShapedLine && !commentOnly && !closeTagOnly) {
773
780
  cp.p5SealPending = false;
774
781
  }
775
782
  }
@@ -821,7 +828,7 @@ function processConfirmedLine(cp, ln, text) {
821
828
  cp.openTotal += 1;
822
829
  }
823
830
  };
824
- const definitelyInsideTable = () => (cp.tagBalance.get("table") ?? 0) > 0;
831
+ const definitelyInsideTable = () => (cp.tagBalance.get("table") ?? 0) > cp.pendingTruncatedTags.filter((t) => t === "table").length;
825
832
  const strayTablePart = (tag) => TABLE_PART_NAMES.has(tag) && !definitelyInsideTable();
826
833
  const commentOpenAtLineStart = commentEitherOpen(cp.mdBlock, cp.p5Tok);
827
834
  const bothCommentsOpenAtLineStart = mdHtml(cp.mdBlock, 2) && cp.p5Tok.kind === "comment";
@@ -843,6 +850,7 @@ function processConfirmedLine(cp, ln, text) {
843
850
  cp.prevLineWasValidDef = false;
844
851
  cp.prevLineOpenContent = false;
845
852
  cp.tableMaybeOpen = false;
853
+ cp.containerMaybeOpen = false;
846
854
  return;
847
855
  }
848
856
  if (cp.mdBlock.kind !== "math" && !rawOpenAtLineStart) {
@@ -864,6 +872,7 @@ function processConfirmedLine(cp, ln, text) {
864
872
  cp.prevLineWasValidDef = false;
865
873
  cp.prevLineOpenContent = false;
866
874
  cp.tableMaybeOpen = false;
875
+ cp.containerMaybeOpen = false;
867
876
  return;
868
877
  }
869
878
  }
@@ -880,6 +889,7 @@ function processConfirmedLine(cp, ln, text) {
880
889
  cp.prevLineWasValidDef = false;
881
890
  cp.prevLineOpenContent = false;
882
891
  cp.tableMaybeOpen = false;
892
+ cp.containerMaybeOpen = false;
883
893
  return;
884
894
  }
885
895
  const mathRun = cp.mathFlow && !rawOpenAtLineStart ? MATH_RUN_RE.exec(ln.text) : null;
@@ -902,6 +912,7 @@ function processConfirmedLine(cp, ln, text) {
902
912
  cp.prevLineWasValidDef = false;
903
913
  cp.prevLineOpenContent = false;
904
914
  cp.tableMaybeOpen = false;
915
+ cp.containerMaybeOpen = false;
905
916
  return;
906
917
  }
907
918
  }
@@ -950,8 +961,10 @@ function processConfirmedLine(cp, ln, text) {
950
961
  cp.prevLineBlank = true;
951
962
  cp.prevLineWasText = false;
952
963
  cp.prevLineWasValidDef = false;
964
+ cp.defBlockMaybeOpen = false;
953
965
  cp.prevLineOpenContent = false;
954
966
  cp.tableMaybeOpen = false;
967
+ cp.containerMaybeOpen = false;
955
968
  return;
956
969
  }
957
970
  if (isBlockStart) {
@@ -963,21 +976,27 @@ function processConfirmedLine(cp, ln, text) {
963
976
  const tagStart = ln.indent <= 3 ? /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(mdTrimStart(ln.text)) : null;
964
977
  if (tagStart) {
965
978
  const noRealBlockOpen = cp.mdBlock.kind !== "html";
966
- if (noRealBlockOpen && TYPE1_START_RE.test(mdTrimStart(ln.text))) cp.mdBlock = { kind: "html", type: 1 };
979
+ const t1 = noRealBlockOpen ? TYPE1_START_RE.exec(mdTrimStart(ln.text)) : null;
980
+ if (t1) cp.mdBlock = { kind: "html", type: 1, raw: RAW_TEXT_ELEMENTS.has(t1[1].toLowerCase()), indent: ln.indent };
967
981
  if (cp.mdBlock.kind !== "html") {
968
982
  const t = mdTrimStart(ln.text);
969
983
  const t6 = TYPE6_START_RE.exec(t);
970
984
  const realT6 = t6 !== null && TYPE6_NAMES.has(t6[1].toLowerCase());
971
- if (realT6 || TYPE1_START_RE.test(t) || // Type 7 cannot interrupt CONTENT (micromark's paragraph/definition
985
+ const t1Line = TYPE1_START_RE.test(t);
986
+ const type7Shaped = !realT6 && !t1Line && isType7Line(t);
987
+ if (realT6 || t1Line || // Type 7 cannot interrupt CONTENT (micromark's paragraph/definition
972
988
  // construct — `prevLineOpenContent`, the exact interrupt input; the
973
989
  // old `prevLineWasText` gate refused after headings, terminator
974
990
  // lines and fence closes, where micromark measurably opens). The
975
991
  // classifier itself is exact too (isType7Line) — including closing
976
992
  // raw-text names (`</style>` alone is type 7, measured) and
977
993
  // quoted-`>` attribute values.
978
- !cp.prevLineOpenContent && isType7Line(t)) {
979
- if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: realT6 ? 6 : 7 };
980
- } else if (cp.prevLineOpenContent && cp.tableMaybeOpen && isType7Line(t)) {
994
+ !cp.prevLineOpenContent && type7Shaped) {
995
+ if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: realT6 ? 6 : 7, indent: ln.indent };
996
+ } else if (cp.prevLineOpenContent && cp.tableMaybeOpen && type7Shaped) {
997
+ cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
998
+ }
999
+ if (type7Shaped && cp.containerMaybeOpen) {
981
1000
  cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
982
1001
  }
983
1002
  }
@@ -1043,7 +1062,12 @@ function processConfirmedLine(cp, ln, text) {
1043
1062
  pos = c + 1;
1044
1063
  continue;
1045
1064
  }
1046
- if (commentOpenAtLineStart || inRawTextTok(cp.p5Tok) || mdHtml(cp.mdBlock, 1)) break;
1065
+ if (commentOpenAtLineStart || inRawTextTok(cp.p5Tok) || mdType1RawText(cp.mdBlock)) {
1066
+ if (inRawTextTok(cp.p5Tok) && cp.p5Tok.openedInline && (tailCarriesRetroactive(ln.text) || /<template(?![a-z0-9-])/i.test(ln.text))) {
1067
+ cp.phasePoisonedAt = 0;
1068
+ }
1069
+ break;
1070
+ }
1047
1071
  const pi = scanText.indexOf("<?", pos);
1048
1072
  const cd = scanText.indexOf("<![CDATA[", pos);
1049
1073
  const dm = scanText.slice(pos).search(/<![A-Za-z]/);
@@ -1060,7 +1084,7 @@ function processConfirmedLine(cp, ln, text) {
1060
1084
  pos = bogus + 2;
1061
1085
  } else if (first === cd) {
1062
1086
  rawSpans.push([cd, cd + 9]);
1063
- if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 5 };
1087
+ if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 5, indent: ln.indent };
1064
1088
  if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
1065
1089
  if (!isMdBlank(scanText.slice(0, cd)) || ln.indent > 3) inlineRawOpenerIdx = cd;
1066
1090
  pos = cd + 9;
@@ -1072,14 +1096,14 @@ function processConfirmedLine(cp, ln, text) {
1072
1096
  continue;
1073
1097
  }
1074
1098
  rawSpans.push([pi, pi + 2]);
1075
- if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 3 };
1099
+ if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 3, indent: ln.indent };
1076
1100
  if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
1077
1101
  if (!isMdBlank(scanText.slice(0, pi)) || ln.indent > 3) inlineRawOpenerIdx = pi;
1078
1102
  pos = pi + 2;
1079
1103
  } else {
1080
1104
  rawSpans.push([decl, decl + 2]);
1081
1105
  if (ln.indent <= 3 && /^doctype/i.test(scanText.slice(decl + 2))) cp.phasePoisonedAt = 0;
1082
- if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 4 };
1106
+ if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 4, indent: ln.indent };
1083
1107
  if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
1084
1108
  if (!isMdBlank(scanText.slice(0, decl)) || ln.indent > 3) inlineRawOpenerIdx = decl;
1085
1109
  pos = decl + 2;
@@ -1138,7 +1162,7 @@ function processConfirmedLine(cp, ln, text) {
1138
1162
  if (next.startsWith(">") || next === "->") {
1139
1163
  continue;
1140
1164
  }
1141
- if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 2 };
1165
+ if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 2, indent: ln.indent };
1142
1166
  if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "comment" };
1143
1167
  lastCommentOpenerIdx = m.index;
1144
1168
  continue;
@@ -1280,17 +1304,37 @@ function processConfirmedLine(cp, ln, text) {
1280
1304
  openContent = false;
1281
1305
  } else if (ln.indent >= 4) {
1282
1306
  openContent = cp.prevLineOpenContent;
1283
- } else if (ATX_HEADING_RE.test(tt) || THEMATIC_BREAK_RE.test(tt) || BARE_MARKER_RE.test(tt)) {
1307
+ } else if (ATX_HEADING_RE.test(tt) || THEMATIC_BREAK_RE.test(tt)) {
1284
1308
  openContent = false;
1309
+ } else if (BARE_MARKER_RE.test(tt)) {
1310
+ openContent = tt[0] === "-" ? false : cp.prevLineOpenContent;
1285
1311
  } else if (SETEXT_LEFTOVER_RE.test(tt)) {
1286
- openContent = !cp.prevLineOpenContent;
1312
+ openContent = cp.tableMaybeOpen && cp.prevLineOpenContent ? true : !cp.prevLineOpenContent;
1287
1313
  } else {
1288
1314
  openContent = true;
1289
1315
  }
1290
1316
  cp.prevLineOpenContent = openContent;
1291
- cp.tableMaybeOpen = ln.text.includes("|") || cp.tableMaybeOpen && openContent;
1317
+ cp.tableMaybeOpen = !htmlOwnedLine && ln.text.includes("|") || cp.tableMaybeOpen && openContent;
1318
+ const containerMarker = CONTAINER_MARKER_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text) || cp.defListEnabled && DEF_LIST_DD_RE.test(ln.text);
1319
+ cp.containerMaybeOpen = openContent && (containerMarker || cp.containerMaybeOpen);
1292
1320
  }
1293
1321
  cp.prevLineWasValidDef = validLinkDef;
1322
+ cp.defBlockMaybeOpen = cp.defBlockMaybeOpen || DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text);
1323
+ if (FOOTNOTE_DEF_RE.test(ln.text)) cp.fnDefResumable = true;
1324
+ else if (isBlockStart && ln.indent <= 3) cp.fnDefResumable = false;
1325
+ const isBarrier = (name) => SCOPE_BARRIER_NAMES.has(name);
1326
+ const topLevelHtmlBlock = cp.mdBlock.kind === "html" && cp.mdBlock.indent === 0;
1327
+ const confirmedBarriers = cp.openStack.filter(isBarrier).length - cp.pendingTruncatedTags.filter(isBarrier).length;
1328
+ if (!topLevelHtmlBlock && confirmedBarriers > 0) {
1329
+ cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
1330
+ }
1331
+ const maskUnbacked = mdType1RawText(cp.mdBlock) && !inRawTextTok(cp.p5Tok);
1332
+ if (maskUnbacked) {
1333
+ cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
1334
+ if (tailCarriesRetroactive(ln.text) || /<template(?![a-z0-9-])/i.test(ln.text)) {
1335
+ cp.phasePoisonedAt = 0;
1336
+ }
1337
+ }
1294
1338
  }
1295
1339
 
1296
1340
  // src/components/incrementalParse/spliceParse.ts
@@ -1805,7 +1849,7 @@ function alignPrefixCut(prefixMdast, cutRegion, tailWrapVisible) {
1805
1849
  if (sepBuffer.length !== trailingGaps && sepBuffer.length !== trailingGaps + 1) return null;
1806
1850
  for (let j = pairIdx + 1; j < visibles.length; j++) {
1807
1851
  const v = visibles[j];
1808
- if (v.type === "html" && !/^\s*<[!?]/.test(v.value)) return null;
1852
+ if (v.type === "html" && !isExactSanitizeStrippedConstruct(v.value)) return null;
1809
1853
  }
1810
1854
  for (let i = 0; i < trailingGaps + seam; i++) {
1811
1855
  out.push({ type: "text", value: "\n" });
@@ -1855,7 +1899,7 @@ function tailLeadingTextIsHoist(tailMdastChildren, tailHastChildren) {
1855
1899
  if (!isSeparatorText(firstText)) {
1856
1900
  if (firstText.type === "text" && firstText.position === void 0 && firstVisible?.type === "html") {
1857
1901
  if (/^\s*<\/[A-Za-z][A-Za-z0-9-]*\s*>/.test(firstVisible.value)) return true;
1858
- if (isCompleteRawConstruct(firstVisible.value)) return false;
1902
+ if (isSanitizeStrippedConstruct(firstVisible.value)) return false;
1859
1903
  return null;
1860
1904
  }
1861
1905
  return false;
@@ -1871,12 +1915,26 @@ function tailLeadingTextIsHoist(tailMdastChildren, tailHastChildren) {
1871
1915
  }
1872
1916
  }
1873
1917
  if (firstVisible.type === "math") return false;
1874
- if (firstVisible.type === "html" && isCompleteRawConstruct(firstVisible.value)) return false;
1918
+ if (firstVisible.type === "html" && isSanitizeStrippedConstruct(firstVisible.value)) return false;
1875
1919
  return null;
1876
1920
  }
1877
- function isCompleteRawConstruct(value) {
1921
+ function isSanitizeStrippedConstruct(value) {
1878
1922
  const v = value.trim();
1879
- return v.startsWith("<!--") && v.endsWith("-->") || v.startsWith("<?") && v.endsWith("?>") || v.startsWith("<![CDATA[") && v.endsWith("]]>") || /^<![A-Za-z]/.test(v) && v.endsWith(">");
1923
+ return v.startsWith("<!--") && v.endsWith("-->") || v.startsWith("<?") && v.endsWith("?>") || v.startsWith("<![CDATA[") && v.endsWith("]]>") || /^<![A-Za-z]/.test(v) && !/^<!doctype/i.test(v) && v.endsWith(">");
1924
+ }
1925
+ function isExactSanitizeStrippedConstruct(value) {
1926
+ if (value.startsWith("<!--")) {
1927
+ if (value.length < 7 || !value.endsWith("-->")) return false;
1928
+ const close = value.indexOf("-->", 4);
1929
+ const bangClose = value.indexOf("--!>", 4);
1930
+ if (close !== value.length - 3) return false;
1931
+ return bangClose === -1 || bangClose > close;
1932
+ }
1933
+ if (/^<!doctype/i.test(value)) return false;
1934
+ if (value.startsWith("<?") || /^<!(?:[A-Za-z]|\[CDATA\[)/.test(value)) {
1935
+ return value.indexOf(">") === value.length - 1;
1936
+ }
1937
+ return false;
1880
1938
  }
1881
1939
  function isSeparatorText(node) {
1882
1940
  return node.type === "text" && node.position === void 0 && node.value.trim() === "";
@@ -5041,7 +5099,6 @@ export {
5041
5099
  collectDefLabels,
5042
5100
  computeFreezeBoundary,
5043
5101
  createDefLabelScanner,
5044
- createFile,
5045
5102
  createIncrementalLatexPreprocessor,
5046
5103
  createProcessor,
5047
5104
  createRegistry,
@@ -5058,10 +5115,8 @@ export {
5058
5115
  hasLoneSurrogate,
5059
5116
  highlight,
5060
5117
  isFootnoteSection,
5061
- isWhitespaceText,
5062
5118
  lastMeaningfulIdx,
5063
5119
  measureStage,
5064
- mergeClassNameAllowlist,
5065
5120
  normalizeForMatch,
5066
5121
  normalizeId,
5067
5122
  pangu,
@@ -5077,7 +5132,6 @@ export {
5077
5132
  shortenDocumentId,
5078
5133
  smartypants,
5079
5134
  sourceIdFromFootnoteLiId,
5080
- splitByProtectedRegions,
5081
5135
  subscribeStageTimings,
5082
5136
  transformStage,
5083
5137
  withDefs