@ai-matrx/content-ir 0.19.1 → 0.19.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/CHANGELOG.md +52 -3
- package/dist/index.cjs +109 -1
- 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 +99 -2
- package/dist/index.js.map +1 -1
- package/dist/source.cjs +109 -1
- package/dist/source.cjs.map +1 -1
- package/dist/source.d.cts +43 -1
- package/dist/source.d.ts +43 -1
- package/dist/source.js +99 -2
- package/dist/source.js.map +1 -1
- package/package.json +1 -1
package/dist/source.d.cts
CHANGED
|
@@ -607,4 +607,46 @@ declare function pendingDisplayMathOpener(text: string): number;
|
|
|
607
607
|
/** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
|
|
608
608
|
declare function pairDisplayMath(text: string): Map<number, number>;
|
|
609
609
|
|
|
610
|
-
|
|
610
|
+
/**
|
|
611
|
+
* THE GFM table rule — one splitter, one cell-pipe rule, one "where does a
|
|
612
|
+
* table start and run" — for every surface that reads a markdown table: the
|
|
613
|
+
* chat splitter and live stream, the table renderers and editors, the rich
|
|
614
|
+
* editor's writer, the print package, and (by shared vectors) the Python block
|
|
615
|
+
* detector. verify-RC-B4 R4/R5/R6.
|
|
616
|
+
*
|
|
617
|
+
* - A `|` is a cell boundary unless an ODD run of backslashes precedes it
|
|
618
|
+
* (`\|` is a pipe inside the cell; `\\|` is an escaped backslash and then a
|
|
619
|
+
* boundary). Code spans get no special treatment: GFM splits rows before
|
|
620
|
+
* inline parsing, so an unescaped `|` inside backticks is a boundary too.
|
|
621
|
+
* - A cell's `\|` shows as `|` — inside code spans too (spec example 200).
|
|
622
|
+
* - A table starts at a header holding an unescaped pipe whose NEXT line is a
|
|
623
|
+
* delimiter row (`--- | :-:`, edge pipes optional); a header without a leading
|
|
624
|
+
* pipe must match the delimiter row's width. It runs to a blank line or a
|
|
625
|
+
* line that starts another block (`- x`, `> y`, `# z`, `1.`, a fence, a rule).
|
|
626
|
+
*
|
|
627
|
+
* Pure TS, no dependencies.
|
|
628
|
+
*/
|
|
629
|
+
/** The row's bytes between boundaries (edge segments included). */
|
|
630
|
+
declare function splitRowSegments(line: string): string[];
|
|
631
|
+
/** A row's cell texts as GFM reads them (source bytes, trimmed; edge pipes dropped). */
|
|
632
|
+
declare function rowCells(line: string): string[];
|
|
633
|
+
/** GFM's table-level unescape: a cell's `\|` is a pipe, in code spans too. */
|
|
634
|
+
declare function unescapeCellPipes(cell: string): string;
|
|
635
|
+
/** A GFM delimiter row: every cell `---`, `:--`, `--:` or `:-:`, with at least one pipe. */
|
|
636
|
+
declare function isGfmDelimiterRow(line: string): boolean;
|
|
637
|
+
/** A pipe-led row: `|` first, and another `|` after it. */
|
|
638
|
+
declare function isPipeLedRow(line: string): boolean;
|
|
639
|
+
/** True when `header` + `delimiter` open a table whose header has NO leading pipe. */
|
|
640
|
+
declare function startsPipelessTable(header: string, delimiter: string | undefined): boolean;
|
|
641
|
+
/** A line that continues an open table: a pipe-led row, or a pipe-less line with an unescaped pipe that starts no block. */
|
|
642
|
+
declare function continuesTable(line: string): boolean;
|
|
643
|
+
/** Line `index` opens a table: a pipe-led row, or a pipe-less GFM header over its delimiter row. */
|
|
644
|
+
declare function opensTable(lines: readonly string[], index: number): boolean;
|
|
645
|
+
/** A WHOLE table header at `index`: a table opens here AND its next line is a GFM delimiter row. */
|
|
646
|
+
declare function tableStartsAt(lines: readonly string[], index: number): boolean;
|
|
647
|
+
/** Index of the first line at or after `from` that opens a table; -1 when none. */
|
|
648
|
+
declare function findTableStart(lines: readonly string[], from?: number): number;
|
|
649
|
+
/** Index just past the table whose header is at `start` (header, delimiter, then continuation rows). */
|
|
650
|
+
declare function findTableEnd(lines: readonly string[], start: number): number;
|
|
651
|
+
|
|
652
|
+
export { AFTER_WINDOW, 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, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapPosition, mapRange, opensTable, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsPipelessTable, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes };
|
package/dist/source.d.ts
CHANGED
|
@@ -607,4 +607,46 @@ declare function pendingDisplayMathOpener(text: string): number;
|
|
|
607
607
|
/** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
|
|
608
608
|
declare function pairDisplayMath(text: string): Map<number, number>;
|
|
609
609
|
|
|
610
|
-
|
|
610
|
+
/**
|
|
611
|
+
* THE GFM table rule — one splitter, one cell-pipe rule, one "where does a
|
|
612
|
+
* table start and run" — for every surface that reads a markdown table: the
|
|
613
|
+
* chat splitter and live stream, the table renderers and editors, the rich
|
|
614
|
+
* editor's writer, the print package, and (by shared vectors) the Python block
|
|
615
|
+
* detector. verify-RC-B4 R4/R5/R6.
|
|
616
|
+
*
|
|
617
|
+
* - A `|` is a cell boundary unless an ODD run of backslashes precedes it
|
|
618
|
+
* (`\|` is a pipe inside the cell; `\\|` is an escaped backslash and then a
|
|
619
|
+
* boundary). Code spans get no special treatment: GFM splits rows before
|
|
620
|
+
* inline parsing, so an unescaped `|` inside backticks is a boundary too.
|
|
621
|
+
* - A cell's `\|` shows as `|` — inside code spans too (spec example 200).
|
|
622
|
+
* - A table starts at a header holding an unescaped pipe whose NEXT line is a
|
|
623
|
+
* delimiter row (`--- | :-:`, edge pipes optional); a header without a leading
|
|
624
|
+
* pipe must match the delimiter row's width. It runs to a blank line or a
|
|
625
|
+
* line that starts another block (`- x`, `> y`, `# z`, `1.`, a fence, a rule).
|
|
626
|
+
*
|
|
627
|
+
* Pure TS, no dependencies.
|
|
628
|
+
*/
|
|
629
|
+
/** The row's bytes between boundaries (edge segments included). */
|
|
630
|
+
declare function splitRowSegments(line: string): string[];
|
|
631
|
+
/** A row's cell texts as GFM reads them (source bytes, trimmed; edge pipes dropped). */
|
|
632
|
+
declare function rowCells(line: string): string[];
|
|
633
|
+
/** GFM's table-level unescape: a cell's `\|` is a pipe, in code spans too. */
|
|
634
|
+
declare function unescapeCellPipes(cell: string): string;
|
|
635
|
+
/** A GFM delimiter row: every cell `---`, `:--`, `--:` or `:-:`, with at least one pipe. */
|
|
636
|
+
declare function isGfmDelimiterRow(line: string): boolean;
|
|
637
|
+
/** A pipe-led row: `|` first, and another `|` after it. */
|
|
638
|
+
declare function isPipeLedRow(line: string): boolean;
|
|
639
|
+
/** True when `header` + `delimiter` open a table whose header has NO leading pipe. */
|
|
640
|
+
declare function startsPipelessTable(header: string, delimiter: string | undefined): boolean;
|
|
641
|
+
/** A line that continues an open table: a pipe-led row, or a pipe-less line with an unescaped pipe that starts no block. */
|
|
642
|
+
declare function continuesTable(line: string): boolean;
|
|
643
|
+
/** Line `index` opens a table: a pipe-led row, or a pipe-less GFM header over its delimiter row. */
|
|
644
|
+
declare function opensTable(lines: readonly string[], index: number): boolean;
|
|
645
|
+
/** A WHOLE table header at `index`: a table opens here AND its next line is a GFM delimiter row. */
|
|
646
|
+
declare function tableStartsAt(lines: readonly string[], index: number): boolean;
|
|
647
|
+
/** Index of the first line at or after `from` that opens a table; -1 when none. */
|
|
648
|
+
declare function findTableStart(lines: readonly string[], from?: number): number;
|
|
649
|
+
/** Index just past the table whose header is at `start` (header, delimiter, then continuation rows). */
|
|
650
|
+
declare function findTableEnd(lines: readonly string[], start: number): number;
|
|
651
|
+
|
|
652
|
+
export { AFTER_WINDOW, 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, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapPosition, mapRange, opensTable, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsPipelessTable, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes };
|
package/dist/source.js
CHANGED
|
@@ -745,6 +745,7 @@ var IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
|
745
745
|
var MATH_SUFFIX = /^(?:s|es|th|st|nd|rd)$/i;
|
|
746
746
|
function isVariableChain(content, after) {
|
|
747
747
|
if (/^\{[A-Za-z_][\w.]*\}$/.test(content)) return true;
|
|
748
|
+
if (/^\(\(.*\)\)$/.test(content) || /^_[.[]/.test(content)) return true;
|
|
748
749
|
if (!after) return false;
|
|
749
750
|
if (after[0] === "{") return IDENTIFIER.test(content);
|
|
750
751
|
const run = /^[A-Za-z0-9_]+/.exec(after)?.[0];
|
|
@@ -1316,6 +1317,16 @@ var Tokenizer = class {
|
|
|
1316
1317
|
holdUndecidedTail() {
|
|
1317
1318
|
const last = this.lineStarts.length - 1;
|
|
1318
1319
|
if (last < 0) return;
|
|
1320
|
+
if (this.provisionalFrom < this.n) {
|
|
1321
|
+
for (let b = 0; b < this.blocks.length; b++) {
|
|
1322
|
+
const block = this.blocks[b];
|
|
1323
|
+
if (block.end <= this.provisionalFrom) continue;
|
|
1324
|
+
if (block.kind === "prose") block.inlines = block.inlines.filter((inline) => inline.end <= this.provisionalFrom);
|
|
1325
|
+
else if (block.island?.fromParagraph && block.start < this.provisionalFrom) {
|
|
1326
|
+
this.blocks[b] = { kind: "prose", start: block.start, end: block.end, island: null, inlines: [] };
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1319
1330
|
if (this.isOpenTail(last)) {
|
|
1320
1331
|
let b = this.blocks.length - 1;
|
|
1321
1332
|
while (b >= 0 && this.blocks[b].kind === "gap") b--;
|
|
@@ -1613,6 +1624,9 @@ var Tokenizer = class {
|
|
|
1613
1624
|
}
|
|
1614
1625
|
if (this.isOpenTail(k)) return this.heldFootnote(p, open[1]);
|
|
1615
1626
|
if (FOOTNOTE_DEF.test(line.trimStart())) break;
|
|
1627
|
+
if (this.streaming && TREE_GLYPHS.test(line) && this.connectorRunReachesEnd(k)) {
|
|
1628
|
+
return this.heldFootnote(p, open[1]);
|
|
1629
|
+
}
|
|
1616
1630
|
const block = this.detectBlock(this.lineStarts[k], k, false);
|
|
1617
1631
|
if (block && this.mayDissolve(block)) return this.heldFootnote(p, open[1]);
|
|
1618
1632
|
if (block) break;
|
|
@@ -1620,8 +1634,22 @@ var Tokenizer = class {
|
|
|
1620
1634
|
}
|
|
1621
1635
|
const end = this.contentEnds[last];
|
|
1622
1636
|
if (this.paragraphMayGrow(end)) return this.heldFootnote(p, open[1]);
|
|
1637
|
+
if (this.streaming && end > this.provisionalFrom) return this.heldFootnote(p, open[1]);
|
|
1623
1638
|
return this.island("footnote_def", p, end, true, { id: open[1] });
|
|
1624
1639
|
}
|
|
1640
|
+
/** Every line from `k` to the end is a connector line or blank (a tree may still form there). */
|
|
1641
|
+
connectorRunReachesEnd(k) {
|
|
1642
|
+
if (this.lastNonConnectorLine === void 0) {
|
|
1643
|
+
let j = this.lineCount - 1;
|
|
1644
|
+
for (; j >= 0; j--) {
|
|
1645
|
+
this.tick(1);
|
|
1646
|
+
if (!this.lineIsBlank(j) && !TREE_GLYPHS.test(this.lineText(j))) break;
|
|
1647
|
+
}
|
|
1648
|
+
this.lastNonConnectorLine = j;
|
|
1649
|
+
}
|
|
1650
|
+
return k > this.lastNonConnectorLine;
|
|
1651
|
+
}
|
|
1652
|
+
lastNonConnectorLine = void 0;
|
|
1625
1653
|
/** A footnote whose continuation is still arriving: open to the end of the text. */
|
|
1626
1654
|
heldFootnote(p, id) {
|
|
1627
1655
|
return this.island("footnote_def", p, this.n, false, { id });
|
|
@@ -1886,7 +1914,6 @@ var Tokenizer = class {
|
|
|
1886
1914
|
if (isRecognizedJsonHead(this.text.slice(tp, tp + 512))) {
|
|
1887
1915
|
return this.island("json", p, this.n, false, jsonMeta(this.text.slice(tp)));
|
|
1888
1916
|
}
|
|
1889
|
-
this.provisionalFrom = Math.min(this.provisionalFrom, p);
|
|
1890
1917
|
return null;
|
|
1891
1918
|
}
|
|
1892
1919
|
if (net !== 0) return null;
|
|
@@ -2557,6 +2584,76 @@ function mapRange(changes, start, end, unit = "utf16") {
|
|
|
2557
2584
|
return { start: newStart, end: newEnd, touched, collapsed: newEnd === newStart && end > start };
|
|
2558
2585
|
}
|
|
2559
2586
|
|
|
2560
|
-
|
|
2587
|
+
// source/gfm-table.ts
|
|
2588
|
+
function splitRowSegments(line) {
|
|
2589
|
+
const segments = [];
|
|
2590
|
+
let start = 0;
|
|
2591
|
+
for (let i = 0; i < line.length; i += 1) {
|
|
2592
|
+
const ch = line[i];
|
|
2593
|
+
if (ch === "\\") {
|
|
2594
|
+
i += 1;
|
|
2595
|
+
continue;
|
|
2596
|
+
}
|
|
2597
|
+
if (ch === "|") {
|
|
2598
|
+
segments.push(line.slice(start, i));
|
|
2599
|
+
start = i + 1;
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
segments.push(line.slice(start));
|
|
2603
|
+
return segments;
|
|
2604
|
+
}
|
|
2605
|
+
function rowCells(line) {
|
|
2606
|
+
const cells = splitRowSegments(line).map((cell) => cell.trim());
|
|
2607
|
+
if (cells.length > 1 && cells[0] === "") cells.shift();
|
|
2608
|
+
if (cells.length > 1 && cells[cells.length - 1] === "") cells.pop();
|
|
2609
|
+
else if (cells.length === 1 && cells[0] === "") cells.pop();
|
|
2610
|
+
return cells;
|
|
2611
|
+
}
|
|
2612
|
+
function unescapeCellPipes(cell) {
|
|
2613
|
+
return cell.replace(/\\\|/g, "|");
|
|
2614
|
+
}
|
|
2615
|
+
var BLOCK_START = /^(?:[-+*](?:\s|$)|\d{1,9}[.)](?:\s|$)|>|#{1,6}(?:\s|$)|```|~~~|(?:-\s*){3,}$|(?:\*\s*){3,}$|(?:_\s*){3,}$)/;
|
|
2616
|
+
var DELIMITER_CELL = /^:?-+:?$/;
|
|
2617
|
+
function isGfmDelimiterRow(line) {
|
|
2618
|
+
const trimmed = line.trim();
|
|
2619
|
+
if (!trimmed.includes("|")) return false;
|
|
2620
|
+
const cells = rowCells(trimmed);
|
|
2621
|
+
return cells.length > 0 && cells.every((cell) => DELIMITER_CELL.test(cell));
|
|
2622
|
+
}
|
|
2623
|
+
function isPipeLedRow(line) {
|
|
2624
|
+
const trimmed = line.trim();
|
|
2625
|
+
return trimmed.startsWith("|") && trimmed.includes("|", 1);
|
|
2626
|
+
}
|
|
2627
|
+
function startsPipelessTable(header, delimiter) {
|
|
2628
|
+
const head = header.trim();
|
|
2629
|
+
if (!head || head.startsWith("|") || BLOCK_START.test(head)) return false;
|
|
2630
|
+
if (splitRowSegments(head).length < 2) return false;
|
|
2631
|
+
if (delimiter === void 0 || !isGfmDelimiterRow(delimiter)) return false;
|
|
2632
|
+
return rowCells(head).length === rowCells(delimiter.trim()).length;
|
|
2633
|
+
}
|
|
2634
|
+
function continuesTable(line) {
|
|
2635
|
+
const trimmed = line.trim();
|
|
2636
|
+
if (!trimmed) return false;
|
|
2637
|
+
if (trimmed.startsWith("|")) return trimmed.includes("|", 1);
|
|
2638
|
+
return splitRowSegments(trimmed).length > 1 && !BLOCK_START.test(trimmed);
|
|
2639
|
+
}
|
|
2640
|
+
function opensTable(lines, index) {
|
|
2641
|
+
const line = lines[index] ?? "";
|
|
2642
|
+
return isPipeLedRow(line) || startsPipelessTable(line, lines[index + 1]);
|
|
2643
|
+
}
|
|
2644
|
+
function tableStartsAt(lines, index) {
|
|
2645
|
+
return opensTable(lines, index) && isGfmDelimiterRow(lines[index + 1] ?? "");
|
|
2646
|
+
}
|
|
2647
|
+
function findTableStart(lines, from = 0) {
|
|
2648
|
+
for (let i = Math.max(0, from); i < lines.length; i += 1) if (opensTable(lines, i)) return i;
|
|
2649
|
+
return -1;
|
|
2650
|
+
}
|
|
2651
|
+
function findTableEnd(lines, start) {
|
|
2652
|
+
let end = Math.min(lines.length, start + 2);
|
|
2653
|
+
while (end < lines.length && continuesTable(lines[end] ?? "")) end += 1;
|
|
2654
|
+
return end;
|
|
2655
|
+
}
|
|
2656
|
+
|
|
2657
|
+
export { AFTER_WINDOW, BacktickRuns, CALLOUT_NAMES, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceReader, NESTING_FENCE_LANGUAGES, SourceSpliceError, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapPosition, mapRange, opensTable, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsPipelessTable, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes };
|
|
2561
2658
|
//# sourceMappingURL=source.js.map
|
|
2562
2659
|
//# sourceMappingURL=source.js.map
|