@ai-matrx/content-ir 0.18.2 → 0.18.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/source.cjs CHANGED
@@ -515,16 +515,27 @@ var BacktickRuns = class {
515
515
  }
516
516
  };
517
517
  function codeSpans(text, from, to, out) {
518
- const runs = new BacktickRuns(text, from, to);
519
- for (let r = 0; r < runs.all.length; ) {
520
- const [start, n] = runs.all[r];
521
- const close = runs.next(n, start + n);
518
+ let runs = null;
519
+ for (let i = from; i < to; ) {
520
+ const ch = text.charCodeAt(i);
521
+ if (ch === 92) {
522
+ i += 2;
523
+ continue;
524
+ }
525
+ if (ch !== 96) {
526
+ i++;
527
+ continue;
528
+ }
529
+ const n = backtickRunLength(text, i);
530
+ const len = Math.min(n, to - i);
531
+ runs ??= new BacktickRuns(text, from, to);
532
+ const close = runs.next(len, i + len);
522
533
  if (close === -1) {
523
- r++;
534
+ i += len;
524
535
  continue;
525
536
  }
526
- out.push({ start, end: close + n, kind: "span" });
527
- r = runs.index(close) + 1;
537
+ out.push({ start: i, end: close + len, kind: "span" });
538
+ i = close + len;
528
539
  }
529
540
  }
530
541
  function findCodeRanges(text) {
@@ -790,6 +801,12 @@ function singleDollarMathEnd(text, open, limit = text.length) {
790
801
  const content = text.slice(open + 1, close);
791
802
  return isSingleDollarMath(content, text[close + 1]) ? close + 1 : -1;
792
803
  }
804
+ var BRACKET_TEX_SIGNAL = /\\[A-Za-z]+|[\^{}=<>+]|_\{|(?:^|[^A-Za-z0-9])[A-Za-z]_[A-Za-z0-9](?![A-Za-z0-9])/;
805
+ function isEscapedBracketMath(content, before) {
806
+ if (!content.trim()) return false;
807
+ if (before !== void 0 && /[A-Za-z0-9_)\]]/.test(before)) return false;
808
+ return BRACKET_TEX_SIGNAL.test(content);
809
+ }
793
810
 
794
811
  // source/xml-tag.ts
795
812
  var XML_NAME_START = /[A-Za-z_]/;
@@ -1846,7 +1863,8 @@ var Tokenizer = class {
1846
1863
  const nextCh = text[i + 1];
1847
1864
  if (nextCh === "(" || nextCh === "[") {
1848
1865
  const close = within(nextCh === "(" ? "\\)" : "\\]", i + 2);
1849
- if (close !== -1) {
1866
+ const isMath = close !== -1 && (nextCh === "(" || isEscapedBracketMath(text.slice(i + 2, close), i > 0 ? text[i - 1] : void 0));
1867
+ if (close !== -1 && isMath) {
1850
1868
  inlines.push(this.island("math_inline", i, close + 2, true, { delimiter: nextCh === "(" ? "\\(" : "\\[" }));
1851
1869
  i = close + 2;
1852
1870
  continue;
@@ -2393,6 +2411,7 @@ exports.fenceNestsInnerFences = fenceNestsInnerFences;
2393
2411
  exports.fenceOpenerOf = fenceOpenerOf;
2394
2412
  exports.fenceParts = fenceParts;
2395
2413
  exports.findCodeRanges = findCodeRanges;
2414
+ exports.isEscapedBracketMath = isEscapedBracketMath;
2396
2415
  exports.isMathPlaceholder = isMathPlaceholder;
2397
2416
  exports.isSingleDollarMath = isSingleDollarMath;
2398
2417
  exports.islandEdit = islandEdit;