@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.d.cts CHANGED
@@ -349,6 +349,19 @@ declare function looksLikeOpenInlineMath(partial: string): boolean;
349
349
  * {@link isSingleDollarMath}. Returns the offset just past the closing `$`.
350
350
  */
351
351
  declare function singleDollarMathEnd(text: string, open: number, limit?: number): number;
352
+ /**
353
+ * THE escaped-bracket rule — whether a closed `\[ … \]` is display math or
354
+ * CommonMark's escaped brackets (literal `[ … ]`). The tokenizer, the
355
+ * renderer's normalizer and the editor all ask it.
356
+ *
357
+ * Math only when the content is real TeX (BRACKET_TEX_SIGNAL) and the `\[`
358
+ * is not an index on an identifier (`arr\[i+1\]`, `f(x)\[k\]`).
359
+ * Everything a person writes with escaped brackets stays text: citations
360
+ * `\[1\]`, dates `\[2026-09-25\]`, task boxes `- \[x\]`, editorial
361
+ * insertions `\[was\]`, placeholders `\[site name\]` (verify-RC-B4 R3-2).
362
+ * `before` is the character just before the `\[` (undefined at the start).
363
+ */
364
+ declare function isEscapedBracketMath(content: string, before: string | undefined): boolean;
352
365
 
353
366
  interface ReadXmlTag {
354
367
  tagName: string;
@@ -572,4 +585,4 @@ declare function pendingDisplayMathOpener(text: string): number;
572
585
  /** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
573
586
  declare function pairDisplayMath(text: string): Map<number, number>;
574
587
 
575
- export { BacktickRuns, type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, type CodeRange, type DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, type FenceEnd, type FenceLineKind, type FenceLines, type FenceOpener, FenceReader, type InlineIslandType, type InnerFenceLine, type IslandMeta, type IslandType, type MapOptions, type MappedPosition, type MappedRange, NESTING_FENCE_LANGUAGES, type ReadXmlTag, type SourceBlock, type SourceBlockKind, type SourceChange, type SourceEdit, type SourceIsland, type SourceSpan, SourceSpliceError, type SourceSpliceErrorCode, type SpliceIntegrity, type SpliceOptions, type SpliceResult, type TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
588
+ export { BacktickRuns, type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, type CodeRange, type DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, type FenceEnd, type FenceLineKind, type FenceLines, type FenceOpener, FenceReader, type InlineIslandType, type InnerFenceLine, type IslandMeta, type IslandType, type MapOptions, type MappedPosition, type MappedRange, NESTING_FENCE_LANGUAGES, type ReadXmlTag, type SourceBlock, type SourceBlockKind, type SourceChange, type SourceEdit, type SourceIsland, type SourceSpan, SourceSpliceError, type SourceSpliceErrorCode, type SpliceIntegrity, type SpliceOptions, type SpliceResult, type TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, isEscapedBracketMath, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
package/dist/source.d.ts CHANGED
@@ -349,6 +349,19 @@ declare function looksLikeOpenInlineMath(partial: string): boolean;
349
349
  * {@link isSingleDollarMath}. Returns the offset just past the closing `$`.
350
350
  */
351
351
  declare function singleDollarMathEnd(text: string, open: number, limit?: number): number;
352
+ /**
353
+ * THE escaped-bracket rule — whether a closed `\[ … \]` is display math or
354
+ * CommonMark's escaped brackets (literal `[ … ]`). The tokenizer, the
355
+ * renderer's normalizer and the editor all ask it.
356
+ *
357
+ * Math only when the content is real TeX (BRACKET_TEX_SIGNAL) and the `\[`
358
+ * is not an index on an identifier (`arr\[i+1\]`, `f(x)\[k\]`).
359
+ * Everything a person writes with escaped brackets stays text: citations
360
+ * `\[1\]`, dates `\[2026-09-25\]`, task boxes `- \[x\]`, editorial
361
+ * insertions `\[was\]`, placeholders `\[site name\]` (verify-RC-B4 R3-2).
362
+ * `before` is the character just before the `\[` (undefined at the start).
363
+ */
364
+ declare function isEscapedBracketMath(content: string, before: string | undefined): boolean;
352
365
 
353
366
  interface ReadXmlTag {
354
367
  tagName: string;
@@ -572,4 +585,4 @@ declare function pendingDisplayMathOpener(text: string): number;
572
585
  /** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
573
586
  declare function pairDisplayMath(text: string): Map<number, number>;
574
587
 
575
- export { BacktickRuns, type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, type CodeRange, type DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, type FenceEnd, type FenceLineKind, type FenceLines, type FenceOpener, FenceReader, type InlineIslandType, type InnerFenceLine, type IslandMeta, type IslandType, type MapOptions, type MappedPosition, type MappedRange, NESTING_FENCE_LANGUAGES, type ReadXmlTag, type SourceBlock, type SourceBlockKind, type SourceChange, type SourceEdit, type SourceIsland, type SourceSpan, SourceSpliceError, type SourceSpliceErrorCode, type SpliceIntegrity, type SpliceOptions, type SpliceResult, type TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
588
+ export { BacktickRuns, type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, type CodeRange, type DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, type FenceEnd, type FenceLineKind, type FenceLines, type FenceOpener, FenceReader, type InlineIslandType, type InnerFenceLine, type IslandMeta, type IslandType, type MapOptions, type MappedPosition, type MappedRange, NESTING_FENCE_LANGUAGES, type ReadXmlTag, type SourceBlock, type SourceBlockKind, type SourceChange, type SourceEdit, type SourceIsland, type SourceSpan, SourceSpliceError, type SourceSpliceErrorCode, type SpliceIntegrity, type SpliceOptions, type SpliceResult, type TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, isEscapedBracketMath, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
package/dist/source.js CHANGED
@@ -513,16 +513,27 @@ var BacktickRuns = class {
513
513
  }
514
514
  };
515
515
  function codeSpans(text, from, to, out) {
516
- const runs = new BacktickRuns(text, from, to);
517
- for (let r = 0; r < runs.all.length; ) {
518
- const [start, n] = runs.all[r];
519
- const close = runs.next(n, start + n);
516
+ let runs = null;
517
+ for (let i = from; i < to; ) {
518
+ const ch = text.charCodeAt(i);
519
+ if (ch === 92) {
520
+ i += 2;
521
+ continue;
522
+ }
523
+ if (ch !== 96) {
524
+ i++;
525
+ continue;
526
+ }
527
+ const n = backtickRunLength(text, i);
528
+ const len = Math.min(n, to - i);
529
+ runs ??= new BacktickRuns(text, from, to);
530
+ const close = runs.next(len, i + len);
520
531
  if (close === -1) {
521
- r++;
532
+ i += len;
522
533
  continue;
523
534
  }
524
- out.push({ start, end: close + n, kind: "span" });
525
- r = runs.index(close) + 1;
535
+ out.push({ start: i, end: close + len, kind: "span" });
536
+ i = close + len;
526
537
  }
527
538
  }
528
539
  function findCodeRanges(text) {
@@ -788,6 +799,12 @@ function singleDollarMathEnd(text, open, limit = text.length) {
788
799
  const content = text.slice(open + 1, close);
789
800
  return isSingleDollarMath(content, text[close + 1]) ? close + 1 : -1;
790
801
  }
802
+ var BRACKET_TEX_SIGNAL = /\\[A-Za-z]+|[\^{}=<>+]|_\{|(?:^|[^A-Za-z0-9])[A-Za-z]_[A-Za-z0-9](?![A-Za-z0-9])/;
803
+ function isEscapedBracketMath(content, before) {
804
+ if (!content.trim()) return false;
805
+ if (before !== void 0 && /[A-Za-z0-9_)\]]/.test(before)) return false;
806
+ return BRACKET_TEX_SIGNAL.test(content);
807
+ }
791
808
 
792
809
  // source/xml-tag.ts
793
810
  var XML_NAME_START = /[A-Za-z_]/;
@@ -1844,7 +1861,8 @@ var Tokenizer = class {
1844
1861
  const nextCh = text[i + 1];
1845
1862
  if (nextCh === "(" || nextCh === "[") {
1846
1863
  const close = within(nextCh === "(" ? "\\)" : "\\]", i + 2);
1847
- if (close !== -1) {
1864
+ const isMath = close !== -1 && (nextCh === "(" || isEscapedBracketMath(text.slice(i + 2, close), i > 0 ? text[i - 1] : void 0));
1865
+ if (close !== -1 && isMath) {
1848
1866
  inlines.push(this.island("math_inline", i, close + 2, true, { delimiter: nextCh === "(" ? "\\(" : "\\[" }));
1849
1867
  i = close + 2;
1850
1868
  continue;
@@ -2371,6 +2389,6 @@ function mapRange(changes, start, end, unit = "utf16") {
2371
2389
  return { start: newStart, end: newEnd, touched, collapsed: newEnd === newStart && end > start };
2372
2390
  }
2373
2391
 
2374
- export { BacktickRuns, CALLOUT_NAMES, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceReader, NESTING_FENCE_LANGUAGES, SourceSpliceError, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
2392
+ export { BacktickRuns, CALLOUT_NAMES, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceReader, NESTING_FENCE_LANGUAGES, SourceSpliceError, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, isEscapedBracketMath, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
2375
2393
  //# sourceMappingURL=source.js.map
2376
2394
  //# sourceMappingURL=source.js.map