@ai-matrx/content-ir 0.18.1 → 0.18.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/source.d.cts CHANGED
@@ -521,6 +521,24 @@ declare class BacktickRuns {
521
521
  * each paragraph's backtick runs.
522
522
  */
523
523
  declare function findCodeRanges(text: string): CodeRange[];
524
+ /**
525
+ * Rewrite every code range (fences and spans, by THE rule) through `fn`; text
526
+ * outside code is kept byte for byte. The one way to strip, replace or
527
+ * placeholder code in markdown — never a private /```…```/ regex.
528
+ */
529
+ declare function mapCodeRanges(text: string, fn: (range: CodeRange, raw: string) => string): string;
530
+ /** A code span's text (CommonMark): the backtick runs off, then one padding space each side when both are there and the content is not all spaces. */
531
+ declare function codeSpanText(raw: string): string;
532
+ /**
533
+ * A fence range's parts: its opener, its body (the lines between the opener
534
+ * and the closer, blockquote prefixes kept), and whether it closed. Reads
535
+ * `raw` exactly as `findCodeRanges` returned it.
536
+ */
537
+ declare function fenceParts(raw: string): {
538
+ opener: FenceOpener;
539
+ body: string;
540
+ closed: boolean;
541
+ } | null;
524
542
  type FenceLineKind = "prose" | "open" | "body" | "close";
525
543
  /**
526
544
  * Where each line (the text split on "\n") sits relative to the fences
@@ -554,4 +572,4 @@ declare function pendingDisplayMathOpener(text: string): number;
554
572
  /** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
555
573
  declare function pairDisplayMath(text: string): Map<number, number>;
556
574
 
557
- 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, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, findCodeRanges, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
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 };
package/dist/source.d.ts CHANGED
@@ -521,6 +521,24 @@ declare class BacktickRuns {
521
521
  * each paragraph's backtick runs.
522
522
  */
523
523
  declare function findCodeRanges(text: string): CodeRange[];
524
+ /**
525
+ * Rewrite every code range (fences and spans, by THE rule) through `fn`; text
526
+ * outside code is kept byte for byte. The one way to strip, replace or
527
+ * placeholder code in markdown — never a private /```…```/ regex.
528
+ */
529
+ declare function mapCodeRanges(text: string, fn: (range: CodeRange, raw: string) => string): string;
530
+ /** A code span's text (CommonMark): the backtick runs off, then one padding space each side when both are there and the content is not all spaces. */
531
+ declare function codeSpanText(raw: string): string;
532
+ /**
533
+ * A fence range's parts: its opener, its body (the lines between the opener
534
+ * and the closer, blockquote prefixes kept), and whether it closed. Reads
535
+ * `raw` exactly as `findCodeRanges` returned it.
536
+ */
537
+ declare function fenceParts(raw: string): {
538
+ opener: FenceOpener;
539
+ body: string;
540
+ closed: boolean;
541
+ } | null;
524
542
  type FenceLineKind = "prose" | "open" | "body" | "close";
525
543
  /**
526
544
  * Where each line (the text split on "\n") sits relative to the fences
@@ -554,4 +572,4 @@ declare function pendingDisplayMathOpener(text: string): number;
554
572
  /** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
555
573
  declare function pairDisplayMath(text: string): Map<number, number>;
556
574
 
557
- 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, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, findCodeRanges, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
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 };
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) {
@@ -531,6 +542,33 @@ function findCodeRanges(text) {
531
542
  for (const [from, to] of s.paragraphs) codeSpans(text, from, to, ranges);
532
543
  return ranges.sort((a, b) => a.start - b.start);
533
544
  }
545
+ function mapCodeRanges(text, fn) {
546
+ let out = "";
547
+ let at = 0;
548
+ for (const r of findCodeRanges(text)) {
549
+ if (r.start < at) continue;
550
+ out += text.slice(at, r.start) + fn(r, text.slice(r.start, r.end));
551
+ at = r.end;
552
+ }
553
+ return out + text.slice(at);
554
+ }
555
+ function codeSpanText(raw) {
556
+ const ticks = backtickRunLength(raw, 0);
557
+ const inner = raw.slice(ticks, raw.length - ticks);
558
+ return inner.length >= 2 && inner.startsWith(" ") && inner.endsWith(" ") && inner.trim() !== "" ? inner.slice(1, -1) : inner;
559
+ }
560
+ function fenceParts(raw) {
561
+ const lines = raw.split("\n").map((l) => l.endsWith("\r") ? l.slice(0, -1) : l);
562
+ const { offset } = quotePrefix(lines[0] ?? "");
563
+ const opener = fenceOpenerOf((lines[0] ?? "").slice(offset).replace(/^ *(?:[-*+]|\d{1,9}[.)])(?= |\t|$) ?/, ""));
564
+ if (!opener) return null;
565
+ const rest = lines.slice(1);
566
+ const closed = rest.length > 0 && new FenceReader(opener, { nesting: false }).feed(rest[rest.length - 1]);
567
+ if (!closed) return { opener, body: rest.join("\n"), closed };
568
+ const last = rest[rest.length - 1];
569
+ const before = trimFenceLine(last).startsWith("```") ? "" : last.slice(0, last.indexOf("```"));
570
+ return { opener, body: [...rest.slice(0, -1), ...before.trim() ? [before] : []].join("\n"), closed };
571
+ }
534
572
  function fenceLineKinds(text) {
535
573
  const s = scan(text);
536
574
  let count = 1;
@@ -2344,6 +2382,6 @@ function mapRange(changes, start, end, unit = "utf16") {
2344
2382
  return { start: newStart, end: newEnd, touched, collapsed: newEnd === newStart && end > start };
2345
2383
  }
2346
2384
 
2347
- export { BacktickRuns, CALLOUT_NAMES, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceReader, NESTING_FENCE_LANGUAGES, SourceSpliceError, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, findCodeRanges, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
2385
+ 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 };
2348
2386
  //# sourceMappingURL=source.js.map
2349
2387
  //# sourceMappingURL=source.js.map