@ai-matrx/content-ir 0.18.1 → 0.18.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/CHANGELOG.md +10 -0
- package/dist/index.cjs +30 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +28 -1
- package/dist/index.js.map +1 -1
- package/dist/source.cjs +30 -0
- package/dist/source.cjs.map +1 -1
- package/dist/source.d.cts +19 -1
- package/dist/source.d.ts +19 -1
- package/dist/source.js +28 -1
- package/dist/source.js.map +1 -1
- package/package.json +1 -1
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
|
@@ -531,6 +531,33 @@ function findCodeRanges(text) {
|
|
|
531
531
|
for (const [from, to] of s.paragraphs) codeSpans(text, from, to, ranges);
|
|
532
532
|
return ranges.sort((a, b) => a.start - b.start);
|
|
533
533
|
}
|
|
534
|
+
function mapCodeRanges(text, fn) {
|
|
535
|
+
let out = "";
|
|
536
|
+
let at = 0;
|
|
537
|
+
for (const r of findCodeRanges(text)) {
|
|
538
|
+
if (r.start < at) continue;
|
|
539
|
+
out += text.slice(at, r.start) + fn(r, text.slice(r.start, r.end));
|
|
540
|
+
at = r.end;
|
|
541
|
+
}
|
|
542
|
+
return out + text.slice(at);
|
|
543
|
+
}
|
|
544
|
+
function codeSpanText(raw) {
|
|
545
|
+
const ticks = backtickRunLength(raw, 0);
|
|
546
|
+
const inner = raw.slice(ticks, raw.length - ticks);
|
|
547
|
+
return inner.length >= 2 && inner.startsWith(" ") && inner.endsWith(" ") && inner.trim() !== "" ? inner.slice(1, -1) : inner;
|
|
548
|
+
}
|
|
549
|
+
function fenceParts(raw) {
|
|
550
|
+
const lines = raw.split("\n").map((l) => l.endsWith("\r") ? l.slice(0, -1) : l);
|
|
551
|
+
const { offset } = quotePrefix(lines[0] ?? "");
|
|
552
|
+
const opener = fenceOpenerOf((lines[0] ?? "").slice(offset).replace(/^ *(?:[-*+]|\d{1,9}[.)])(?= |\t|$) ?/, ""));
|
|
553
|
+
if (!opener) return null;
|
|
554
|
+
const rest = lines.slice(1);
|
|
555
|
+
const closed = rest.length > 0 && new FenceReader(opener, { nesting: false }).feed(rest[rest.length - 1]);
|
|
556
|
+
if (!closed) return { opener, body: rest.join("\n"), closed };
|
|
557
|
+
const last = rest[rest.length - 1];
|
|
558
|
+
const before = trimFenceLine(last).startsWith("```") ? "" : last.slice(0, last.indexOf("```"));
|
|
559
|
+
return { opener, body: [...rest.slice(0, -1), ...before.trim() ? [before] : []].join("\n"), closed };
|
|
560
|
+
}
|
|
534
561
|
function fenceLineKinds(text) {
|
|
535
562
|
const s = scan(text);
|
|
536
563
|
let count = 1;
|
|
@@ -2344,6 +2371,6 @@ function mapRange(changes, start, end, unit = "utf16") {
|
|
|
2344
2371
|
return { start: newStart, end: newEnd, touched, collapsed: newEnd === newStart && end > start };
|
|
2345
2372
|
}
|
|
2346
2373
|
|
|
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 };
|
|
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 };
|
|
2348
2375
|
//# sourceMappingURL=source.js.map
|
|
2349
2376
|
//# sourceMappingURL=source.js.map
|