@ai-react-markdown/engine 2.5.1 → 2.5.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.cjs CHANGED
@@ -65,6 +65,8 @@ __export(src_exports, {
65
65
  hasLoneSurrogate: () => hasLoneSurrogate,
66
66
  highlight: () => highlight,
67
67
  isFootnoteSection: () => isFootnoteSection,
68
+ isWhitespaceText: () => isWhitespaceText,
69
+ lastMeaningfulIdx: () => lastMeaningfulIdx,
68
70
  measureStage: () => measureStage,
69
71
  mergeClassNameAllowlist: () => mergeClassNameAllowlist,
70
72
  normalizeForMatch: () => normalizeForMatch,
@@ -1199,6 +1201,15 @@ function isFootnoteSection(node) {
1199
1201
  const props = node.properties;
1200
1202
  return props?.dataFootnotes !== void 0;
1201
1203
  }
1204
+ function isWhitespaceText(c) {
1205
+ return c.type === "text" && /^\s*$/.test(c.value);
1206
+ }
1207
+ function lastMeaningfulIdx(children) {
1208
+ for (let i = children.length - 1; i >= 0; i--) {
1209
+ if (!isWhitespaceText(children[i])) return i;
1210
+ }
1211
+ return -1;
1212
+ }
1202
1213
 
1203
1214
  // src/components/incrementalParse/attributeHastChildren.ts
1204
1215
  function attributeHastChildren(mdast, hast, stopAt = Infinity) {
@@ -1981,16 +1992,6 @@ function isBackrefAnchor(c) {
1981
1992
  if (el.tagName !== "a") return false;
1982
1993
  return Boolean(el.properties && "dataFootnoteBackref" in el.properties);
1983
1994
  }
1984
- function isWhitespaceText(c) {
1985
- if (c.type !== "text") return false;
1986
- return /^\s*$/.test(c.value);
1987
- }
1988
- function lastMeaningfulIdx(children) {
1989
- for (let i = children.length - 1; i >= 0; i--) {
1990
- if (!isWhitespaceText(children[i])) return i;
1991
- }
1992
- return -1;
1993
- }
1994
1995
  function dropTrailingBackrefs(children) {
1995
1996
  let trailingWsStart = children.length;
1996
1997
  while (trailingWsStart > 0 && isWhitespaceText(children[trailingWsStart - 1])) {
@@ -4657,21 +4658,7 @@ function convertSingleToDoubleDollar(text) {
4657
4658
  }
4658
4659
  function preprocessLaTeX(str) {
4659
4660
  if (!hasLatexTrigger(str)) return str;
4660
- const segments = splitByProtectedRegions(str);
4661
- const result = segments.map((segment) => {
4662
- if (segment.isCode) return segment.text;
4663
- let text = segment.text;
4664
- text = escapeMhchemCommands(text);
4665
- text = escapeCurrencyDollarSigns(text);
4666
- text = convertLatexDelimiters(text);
4667
- text = escapeLatexPipes(text);
4668
- text = escapeLatexPipesInUnclosed(text);
4669
- text = escapeTextUnderscores(text);
4670
- text = convertSingleToDoubleDollar(text);
4671
- text = truncateUnclosedLatexBlock(text);
4672
- return text;
4673
- });
4674
- return result.join("");
4661
+ return processSlice(str, false).out;
4675
4662
  }
4676
4663
  function hasLatexTrigger(str) {
4677
4664
  return str.includes("$") || str.includes("\\[") || str.includes("\\(");
@@ -4700,7 +4687,7 @@ function hasUnclosedTextCommand(text) {
4700
4687
  }
4701
4688
  var RESIDUAL_OPEN_BRACKET_RE = /(?<!!)\\\[/;
4702
4689
  var LEADING_DOUBLE_DOLLAR_RE = /^\s*\$\$/;
4703
- function processSliceInstrumented(slice, probe = true) {
4690
+ function processSlice(slice, probe = true) {
4704
4691
  const segments = splitByProtectedRegions(slice);
4705
4692
  const parts = [];
4706
4693
  let quiescent = true;
@@ -4824,13 +4811,13 @@ function createIncrementalLatexPreprocessor(options) {
4824
4811
  };
4825
4812
  const cut = findRawSafeCut(active);
4826
4813
  if (cut > 0) {
4827
- const candidate = processSliceInstrumented(active.slice(0, cut));
4814
+ const candidate = processSlice(active.slice(0, cut));
4828
4815
  if (candidate.quiescent) freeze(cut, candidate);
4829
4816
  }
4830
4817
  nextAttemptLen = advanced || !backoff ? 0 : active.length * 2;
4831
4818
  onAttempt?.({ activeLength, frozenBytes });
4832
4819
  }
4833
- const tail = processSliceInstrumented(active, false);
4820
+ const tail = processSlice(active, false);
4834
4821
  const head = tail.truncatedAtSeamStart ? frozenOut.replace(/\s+$/, "") : frozenOut;
4835
4822
  const out = head + tail.out;
4836
4823
  prevSource = source;
@@ -4895,6 +4882,8 @@ function createRemendPreprocessor(options) {
4895
4882
  hasLoneSurrogate,
4896
4883
  highlight,
4897
4884
  isFootnoteSection,
4885
+ isWhitespaceText,
4886
+ lastMeaningfulIdx,
4898
4887
  measureStage,
4899
4888
  mergeClassNameAllowlist,
4900
4889
  normalizeForMatch,