@ai-matrx/content-ir 0.19.13 → 0.19.15

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
@@ -467,6 +467,33 @@ declare function parseFenceOpener(line: string): {
467
467
  } | null;
468
468
  declare function classifyInnerFenceLine(trimmed: string, openTicks: number, nests: boolean, nestedDepth: number): InnerFenceLine;
469
469
 
470
+ /**
471
+ * THE link-reference rule (CommonMark 4.7 / 6.3) for surfaces that read one
472
+ * piece of a document at a time — a table cell, a split chat block, a printed
473
+ * row — and so cannot see the document's `[label]: url "title"` definitions.
474
+ * `collectLinkDefinitions` reads them from the WHOLE text (never inside fenced
475
+ * code); `resolveReferenceLinks` rewrites a fragment's full (`[text][label]`),
476
+ * collapsed (`[label][]`) and shortcut (`[label]`) reference links into inline
477
+ * links (`[text](url "title")`) so any renderer shows what GFM shows. Code spans,
478
+ * images, inline links, footnote references and undefined labels are left as
479
+ * they are. verify-RC-B4 round 9 (R9-4).
480
+ *
481
+ * Pure TS, no dependencies.
482
+ */
483
+ interface LinkDefinition {
484
+ url: string;
485
+ title: string | null;
486
+ }
487
+ /** CommonMark label matching: case-folded, inner whitespace collapsed, trimmed. */
488
+ declare function normalizeLinkLabel(label: string): string;
489
+ /** Every link reference definition in `text` (first one wins, as in CommonMark); fenced code is skipped. */
490
+ declare function collectLinkDefinitions(text: string): Map<string, LinkDefinition>;
491
+ /**
492
+ * `fragment` with every reference link whose label is defined rewritten inline.
493
+ * An image (`![alt][ref]`) resolves too. Nothing else changes.
494
+ */
495
+ declare function resolveReferenceLinks(fragment: string, defs: ReadonlyMap<string, LinkDefinition>): string;
496
+
470
497
  interface CodeRange {
471
498
  /** UTF-16 offset of the first character (the fence line start, or the opening backtick run). */
472
499
  start: number;
@@ -697,4 +724,4 @@ declare function findTableStart(lines: readonly string[], from?: number): number
697
724
  /** Index just past the table whose header is at `start` (header, delimiter, then continuation rows). */
698
725
  declare function findTableEnd(lines: readonly string[], start: number): number;
699
726
 
700
- 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, findInlineCodeSpans, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, opensTable, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes };
727
+ 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 LinkDefinition, 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, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, findInlineCodeSpans, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, normalizeLinkLabel, opensTable, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes };
package/dist/source.d.ts CHANGED
@@ -467,6 +467,33 @@ declare function parseFenceOpener(line: string): {
467
467
  } | null;
468
468
  declare function classifyInnerFenceLine(trimmed: string, openTicks: number, nests: boolean, nestedDepth: number): InnerFenceLine;
469
469
 
470
+ /**
471
+ * THE link-reference rule (CommonMark 4.7 / 6.3) for surfaces that read one
472
+ * piece of a document at a time — a table cell, a split chat block, a printed
473
+ * row — and so cannot see the document's `[label]: url "title"` definitions.
474
+ * `collectLinkDefinitions` reads them from the WHOLE text (never inside fenced
475
+ * code); `resolveReferenceLinks` rewrites a fragment's full (`[text][label]`),
476
+ * collapsed (`[label][]`) and shortcut (`[label]`) reference links into inline
477
+ * links (`[text](url "title")`) so any renderer shows what GFM shows. Code spans,
478
+ * images, inline links, footnote references and undefined labels are left as
479
+ * they are. verify-RC-B4 round 9 (R9-4).
480
+ *
481
+ * Pure TS, no dependencies.
482
+ */
483
+ interface LinkDefinition {
484
+ url: string;
485
+ title: string | null;
486
+ }
487
+ /** CommonMark label matching: case-folded, inner whitespace collapsed, trimmed. */
488
+ declare function normalizeLinkLabel(label: string): string;
489
+ /** Every link reference definition in `text` (first one wins, as in CommonMark); fenced code is skipped. */
490
+ declare function collectLinkDefinitions(text: string): Map<string, LinkDefinition>;
491
+ /**
492
+ * `fragment` with every reference link whose label is defined rewritten inline.
493
+ * An image (`![alt][ref]`) resolves too. Nothing else changes.
494
+ */
495
+ declare function resolveReferenceLinks(fragment: string, defs: ReadonlyMap<string, LinkDefinition>): string;
496
+
470
497
  interface CodeRange {
471
498
  /** UTF-16 offset of the first character (the fence line start, or the opening backtick run). */
472
499
  start: number;
@@ -697,4 +724,4 @@ declare function findTableStart(lines: readonly string[], from?: number): number
697
724
  /** Index just past the table whose header is at `start` (header, delimiter, then continuation rows). */
698
725
  declare function findTableEnd(lines: readonly string[], start: number): number;
699
726
 
700
- 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, findInlineCodeSpans, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, opensTable, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes };
727
+ 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 LinkDefinition, 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, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, findInlineCodeSpans, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, normalizeLinkLabel, opensTable, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes };
package/dist/source.js CHANGED
@@ -2603,6 +2603,51 @@ function mapRange(changes, start, end, unit = "utf16") {
2603
2603
  return { start: newStart, end: newEnd, touched, collapsed: newEnd === newStart && end > start };
2604
2604
  }
2605
2605
 
2606
+ // source/link-references.ts
2607
+ function normalizeLinkLabel(label) {
2608
+ return label.trim().replace(/\s+/g, " ").toLowerCase();
2609
+ }
2610
+ var DEFINITION = /^ {0,3}\[((?:[^\]\\]|\\.){1,999})\]:[ \t]*(?:<([^<>\n]*)>|(\S+))(?:[ \t]+(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|\(((?:[^()\\]|\\.)*)\)))?[ \t]*$/;
2611
+ function collectLinkDefinitions(text) {
2612
+ const defs = /* @__PURE__ */ new Map();
2613
+ if (!text.includes("]:")) return defs;
2614
+ const lines = text.split("\n");
2615
+ const kinds = fenceLineKinds(text);
2616
+ lines.forEach((line, i) => {
2617
+ if (kinds[i] !== "prose") return;
2618
+ const m = DEFINITION.exec(line);
2619
+ if (!m) return;
2620
+ const label = m[1] ?? "";
2621
+ if (label.startsWith("^")) return;
2622
+ const key = normalizeLinkLabel(label);
2623
+ if (!key || defs.has(key)) return;
2624
+ defs.set(key, { url: m[2] ?? m[3] ?? "", title: m[4] ?? m[5] ?? m[6] ?? null });
2625
+ });
2626
+ return defs;
2627
+ }
2628
+ var REFERENCE = /(!?)\[((?:[^\]\\]|\\.)*)\](?:\[((?:[^\]\\]|\\.)*)\])?(?![(:[])/g;
2629
+ var escapeTitle = (title) => title.replace(/["\\]/g, "\\$&");
2630
+ function resolveReferenceLinks(fragment, defs) {
2631
+ if (defs.size === 0 || !fragment.includes("[")) return fragment;
2632
+ const PLACEHOLDER = "\uE011";
2633
+ const spans = [];
2634
+ const masked = mapInlineCodeSpans(fragment, (_range, raw) => {
2635
+ spans.push(raw);
2636
+ return `${PLACEHOLDER}${spans.length - 1}${PLACEHOLDER}`;
2637
+ });
2638
+ const resolved = masked.replace(REFERENCE, (whole, bang, text, ref, at) => {
2639
+ if (at > 0 && masked[at - 1] === "\\") return whole;
2640
+ if (text.startsWith("^")) return whole;
2641
+ const key = normalizeLinkLabel(ref === void 0 || ref === "" ? text : ref);
2642
+ const def = defs.get(key);
2643
+ if (!def) return whole;
2644
+ const title = def.title === null ? "" : ` "${escapeTitle(def.title)}"`;
2645
+ const url = /[\s()<>]/.test(def.url) ? `<${def.url}>` : def.url;
2646
+ return `${bang}[${text}](${url}${title})`;
2647
+ });
2648
+ return resolved.replace(new RegExp(`${PLACEHOLDER}(\\d+)${PLACEHOLDER}`, "g"), (_m, i) => spans[Number(i)] ?? "");
2649
+ }
2650
+
2606
2651
  // source/gfm-table.ts
2607
2652
  function splitRowSegments(line) {
2608
2653
  const segments = [];
@@ -2631,7 +2676,7 @@ function rowCells(line) {
2631
2676
  function unescapeCellPipes(cell) {
2632
2677
  return cell.replace(/\\\|/g, "|");
2633
2678
  }
2634
- var BLOCK_START = /^(?:[-+*](?:\s|$)|\d{1,9}[.)](?:\s|$)|>|#{1,6}(?:\s|$)|(?:-\s*){3,}$|(?:\*\s*){3,}$|(?:_\s*){3,}$)/;
2679
+ var BLOCK_START = /^(?:[-+*](?:\s|$)|\d{1,9}[.)](?:\s|$)|>|#{1,6}(?:\s|$)|(?:-\s*){3,}$|(?:\*\s*){3,}$|(?:_\s*){3,}$|\[\^[^\]\s]+\]:)/;
2635
2680
  var startsBlock = (trimmed) => BLOCK_START.test(trimmed) || opensStrictFence(trimmed) || startsHtmlBlock(trimmed);
2636
2681
  var HTML_RAW = /^<(?:script|pre|style|textarea)(?:[\s>]|$)/i;
2637
2682
  var HTML_COMMENT_ETC = /^(?:<!--|<\?|<![A-Za-z]|<!\[CDATA\[)/;
@@ -2721,11 +2766,45 @@ function continuesTable(line, containerIndent = 0) {
2721
2766
  function opensTable(lines, index) {
2722
2767
  const line = lines[index] ?? "";
2723
2768
  if (!isPipeLedRow(line) && !startsPipelessTable(line, lines[index + 1])) return false;
2724
- return !isLazyContinuation(lines, index);
2769
+ return !isLazyContinuation(lines, index) && !insideHtmlBlock(lines, index);
2725
2770
  }
2726
2771
  var QUOTE_LINE = /^ {0,3}>/;
2727
2772
  var THEMATIC_BREAK = /^(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/;
2728
2773
  var breaksParagraph = (trimmed) => /^#{1,6}(?:\s|$)/.test(trimmed) || THEMATIC_BREAK.test(trimmed) || opensStrictFence(trimmed) || startsHtmlBlock(trimmed);
2774
+ function htmlBlockEnd(trimmed) {
2775
+ if (HTML_RAW.test(trimmed)) return /<\/(?:script|pre|style|textarea)>/i;
2776
+ if (trimmed.startsWith("<!--")) return /-->/;
2777
+ if (trimmed.startsWith("<?")) return /\?>/;
2778
+ if (trimmed.startsWith("<![CDATA[")) return /\]\]>/;
2779
+ if (/^<![A-Za-z]/.test(trimmed)) return />/;
2780
+ if (HTML_BLOCK_TAG.test(trimmed)) return null;
2781
+ if (HTML_COMPLETE_TAG.test(trimmed)) return null;
2782
+ return void 0;
2783
+ }
2784
+ function insideHtmlBlock(lines, index) {
2785
+ let start = index;
2786
+ while (start > 0 && (lines[start - 1] ?? "").trim()) start -= 1;
2787
+ let open;
2788
+ let paragraph = false;
2789
+ for (let k = start; k < index; k += 1) {
2790
+ const line = lines[k] ?? "";
2791
+ if (open !== void 0) {
2792
+ if (open && open.test(line)) open = void 0;
2793
+ continue;
2794
+ }
2795
+ const trimmed = line.trim();
2796
+ const end = lineIndent(line) < 4 ? htmlBlockEnd(trimmed) : void 0;
2797
+ const type7 = end === null && !HTML_BLOCK_TAG.test(trimmed);
2798
+ const interrupts = end !== void 0 && !(paragraph && type7);
2799
+ if (!interrupts) {
2800
+ paragraph = true;
2801
+ continue;
2802
+ }
2803
+ paragraph = false;
2804
+ open = end && end.test(trimmed.slice(2)) ? void 0 : end;
2805
+ }
2806
+ return open !== void 0;
2807
+ }
2729
2808
  function isLazyContinuation(lines, index) {
2730
2809
  const header = lines[index] ?? "";
2731
2810
  let first = -1;
@@ -2767,6 +2846,6 @@ function findTableEnd(lines, start) {
2767
2846
  return end;
2768
2847
  }
2769
2848
 
2770
- 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, findInlineCodeSpans, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, opensTable, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes };
2849
+ export { AFTER_WINDOW, BacktickRuns, CALLOUT_NAMES, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceReader, NESTING_FENCE_LANGUAGES, SourceSpliceError, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, findInlineCodeSpans, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, normalizeLinkLabel, opensTable, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes };
2771
2850
  //# sourceMappingURL=source.js.map
2772
2851
  //# sourceMappingURL=source.js.map