@ai-matrx/content-ir 0.19.7 → 0.19.9

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.19.9
4
+ ### Unreleased
5
+
6
+ - `/source` **A table ends where GFM ends it (verify-RC-B4 round 9):** `continuesTable` / `findTableEnd` end a table at an HTML block start (all seven CommonMark 4.6 conditions — `<script`/`<pre`/`<style`/`<textarea`, `<!--`, `<?`, `<!X`, `<![CDATA[`, a block tag name, or any other complete tag alone on its line such as `</artifact>`) and at indented code: a line 4+ columns past the table's container. New `startsHtmlBlock`, `lineIndent`, `tableContainerIndent` (the content column of the list item a table sits in); `continuesTable(line, containerIndent = 0)`. A lone `|` is a row (one empty cell) — `rowCells("|")` is `[""]`, no longer `[]`. Since 0.19.4 an HTML line or an indented line after a table was read as a table row. Shared vectors gain `tableEnds` (30 cases, each judged against remark-gfm in matrx-frontend); the Python twin moved with them.
7
+ - `/source` **A table never opens on a lazy continuation line (verify-RC-B4 round 9):** `opensTable` / `tableStartsAt` / `findTableStart` refuse a header that lazily continues a list item's or a block quote's paragraph (no blank line above, not indented to the item's content column, or missing the quote's `>`) — GFM reads it as paragraph text (`- item` then `| a | b |` is no table). Vectors gain `tableStarts` (15 cases, judged against remark-gfm).
8
+
9
+ ## 0.19.8
10
+
11
+ Automatic changed-only republish (docs/metadata drift since the last tag — see
12
+ `git diff npm/content-ir-core/v0.19.7..npm/content-ir-core/v0.19.8 -- apps/shared/content-ir-core`).
13
+ No source changes intended and no consumer action required.
14
+
3
15
  ## 0.19.7
4
16
  ### Unreleased
5
17
 
package/dist/index.cjs CHANGED
@@ -7687,14 +7687,61 @@ function rowCells(line) {
7687
7687
  const cells = splitRowSegments(line).map((cell) => cell.trim());
7688
7688
  if (cells.length > 1 && cells[0] === "") cells.shift();
7689
7689
  if (cells.length > 1 && cells[cells.length - 1] === "") cells.pop();
7690
- else if (cells.length === 1 && cells[0] === "") cells.pop();
7690
+ else if (cells.length === 1 && cells[0] === "" && !line.includes("|")) cells.pop();
7691
7691
  return cells;
7692
7692
  }
7693
7693
  function unescapeCellPipes(cell) {
7694
7694
  return cell.replace(/\\\|/g, "|");
7695
7695
  }
7696
7696
  var BLOCK_START = /^(?:[-+*](?:\s|$)|\d{1,9}[.)](?:\s|$)|>|#{1,6}(?:\s|$)|(?:-\s*){3,}$|(?:\*\s*){3,}$|(?:_\s*){3,}$)/;
7697
- var startsBlock = (trimmed) => BLOCK_START.test(trimmed) || opensStrictFence(trimmed);
7697
+ var startsBlock = (trimmed) => BLOCK_START.test(trimmed) || opensStrictFence(trimmed) || startsHtmlBlock(trimmed);
7698
+ var HTML_RAW = /^<(?:script|pre|style|textarea)(?:[\s>]|$)/i;
7699
+ var HTML_COMMENT_ETC = /^(?:<!--|<\?|<![A-Za-z]|<!\[CDATA\[)/;
7700
+ var HTML_BLOCK_NAMES = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul";
7701
+ var HTML_BLOCK_TAG = new RegExp(`^</?(?:${HTML_BLOCK_NAMES})(?:[\\s>]|/>|$)`, "i");
7702
+ var ATTRIBUTE = `\\s+[A-Za-z_:][A-Za-z0-9_.:-]*(?:\\s*=\\s*(?:[^\\s"'=<>\`]+|'[^']*'|"[^"]*"))?`;
7703
+ var HTML_COMPLETE_TAG = new RegExp(`^(?:<[A-Za-z][A-Za-z0-9-]*(?:${ATTRIBUTE})*\\s*/?>|</[A-Za-z][A-Za-z0-9-]*\\s*>)\\s*$`);
7704
+ function startsHtmlBlock(trimmed) {
7705
+ if (!trimmed.startsWith("<")) return false;
7706
+ return HTML_RAW.test(trimmed) || HTML_COMMENT_ETC.test(trimmed) || HTML_BLOCK_TAG.test(trimmed) || HTML_COMPLETE_TAG.test(trimmed);
7707
+ }
7708
+ function lineIndent(line) {
7709
+ let column = 0;
7710
+ for (const ch of line) {
7711
+ if (ch === " ") column += 1;
7712
+ else if (ch === " ") column += 4 - column % 4;
7713
+ else break;
7714
+ }
7715
+ return column;
7716
+ }
7717
+ var LIST_MARKER = /^([ \t]*)([-+*]|\d{1,9}[.)])([ \t]+|$)/;
7718
+ function markerContentColumn(marker) {
7719
+ const markerEnd = lineIndent(marker[1] ?? "") + (marker[2] ?? "").length;
7720
+ const gap = marker[3] ? lineIndent(" ".repeat(markerEnd) + marker[3]) - markerEnd : 1;
7721
+ return markerEnd + (gap >= 1 && gap <= 4 ? gap : 1);
7722
+ }
7723
+ function tableContainerIndent(lines, start) {
7724
+ return tableContainerIndentOf(lines, start, false);
7725
+ }
7726
+ function tableContainerIndentOf(lines, start, ownItem) {
7727
+ const own = ownItem ? LIST_MARKER.exec(lines[start] ?? "") : null;
7728
+ if (own) return markerContentColumn(own);
7729
+ const header = lineIndent(lines[start] ?? "");
7730
+ if (header === 0) return 0;
7731
+ for (let k = start - 1; k >= 0; k -= 1) {
7732
+ const line = lines[k] ?? "";
7733
+ if (!line.trim()) continue;
7734
+ const indent = lineIndent(line);
7735
+ const marker = LIST_MARKER.exec(line);
7736
+ if (marker && indent < header) {
7737
+ const content = markerContentColumn(marker);
7738
+ if (content <= header) return content;
7739
+ continue;
7740
+ }
7741
+ if (indent === 0) return 0;
7742
+ }
7743
+ return 0;
7744
+ }
7698
7745
  var DELIMITER_CELL = /^:?-+:?$/;
7699
7746
  function isGfmDelimiterRow(line) {
7700
7747
  const trimmed = line.trim();
@@ -7713,14 +7760,42 @@ function startsPipelessTable(header, delimiter) {
7713
7760
  if (delimiter === void 0 || !isGfmDelimiterRow(delimiter)) return false;
7714
7761
  return rowCells(head).length === rowCells(delimiter.trim()).length;
7715
7762
  }
7716
- function continuesTable(line) {
7763
+ function continuesTable(line, containerIndent = 0) {
7717
7764
  const trimmed = line.trim();
7718
7765
  if (!trimmed) return false;
7766
+ if (lineIndent(line) - containerIndent >= 4) return false;
7719
7767
  return trimmed.startsWith("|") || !startsBlock(trimmed);
7720
7768
  }
7721
7769
  function opensTable(lines, index) {
7722
7770
  const line = lines[index] ?? "";
7723
- return isPipeLedRow(line) || startsPipelessTable(line, lines[index + 1]);
7771
+ if (!isPipeLedRow(line) && !startsPipelessTable(line, lines[index + 1])) return false;
7772
+ return !isLazyContinuation(lines, index);
7773
+ }
7774
+ var QUOTE_LINE = /^ {0,3}>/;
7775
+ var THEMATIC_BREAK = /^(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/;
7776
+ var breaksParagraph = (trimmed) => /^#{1,6}(?:\s|$)/.test(trimmed) || THEMATIC_BREAK.test(trimmed) || opensStrictFence(trimmed) || startsHtmlBlock(trimmed);
7777
+ function isLazyContinuation(lines, index) {
7778
+ const header = lines[index] ?? "";
7779
+ let first = -1;
7780
+ for (let k = index - 1; k >= 0; k -= 1) {
7781
+ const line = lines[k] ?? "";
7782
+ const trimmed = line.trim();
7783
+ if (!trimmed) break;
7784
+ if (breaksParagraph(trimmed)) break;
7785
+ const marker = LIST_MARKER.exec(line);
7786
+ if (marker) {
7787
+ const rest = line.slice(marker[0].length).trim();
7788
+ if (!rest || breaksParagraph(rest)) break;
7789
+ first = k;
7790
+ break;
7791
+ }
7792
+ first = k;
7793
+ if (QUOTE_LINE.test(line)) break;
7794
+ }
7795
+ if (first < 0) return false;
7796
+ const start = lines[first] ?? "";
7797
+ if (QUOTE_LINE.test(start)) return !QUOTE_LINE.test(header);
7798
+ return lineIndent(header) < tableContainerIndentOf(lines, first, true);
7724
7799
  }
7725
7800
  function tableStartsAt(lines, index) {
7726
7801
  return opensTable(lines, index) && isGfmDelimiterRow(lines[index + 1] ?? "");
@@ -7730,8 +7805,9 @@ function findTableStart(lines, from = 0) {
7730
7805
  return -1;
7731
7806
  }
7732
7807
  function findTableEnd(lines, start) {
7808
+ const container = tableContainerIndent(lines, start);
7733
7809
  let end = Math.min(lines.length, start + 2);
7734
- while (end < lines.length && continuesTable(lines[end] ?? "")) end += 1;
7810
+ while (end < lines.length && continuesTable(lines[end] ?? "", container)) end += 1;
7735
7811
  return end;
7736
7812
  }
7737
7813
 
@@ -7847,6 +7923,7 @@ exports.kindSchemaToJsonSchema = kindSchemaToJsonSchema;
7847
7923
  exports.kindSchemaToStorage = kindSchemaToStorage;
7848
7924
  exports.kindVerdictOf = kindVerdictOf;
7849
7925
  exports.legacyShellUses = legacyShellUses;
7926
+ exports.lineIndent = lineIndent;
7850
7927
  exports.listIslands = listIslands;
7851
7928
  exports.looksLikeDirectiveHead = looksLikeDirectiveHead;
7852
7929
  exports.looksLikeDisplayMath = looksLikeDisplayMath;
@@ -7895,9 +7972,11 @@ exports.singleDollarMathEnd = singleDollarMathEnd;
7895
7972
  exports.spliceSave = spliceSave;
7896
7973
  exports.splitRowSegments = splitRowSegments;
7897
7974
  exports.splitsSurrogatePair = splitsSurrogatePair;
7975
+ exports.startsHtmlBlock = startsHtmlBlock;
7898
7976
  exports.startsPipelessTable = startsPipelessTable;
7899
7977
  exports.storageToKindSchema = storageToKindSchema;
7900
7978
  exports.stripKindDeep = stripKindDeep;
7979
+ exports.tableContainerIndent = tableContainerIndent;
7901
7980
  exports.tableStartsAt = tableStartsAt;
7902
7981
  exports.titleCaseToken = titleCaseToken;
7903
7982
  exports.toCodePointOffset = toCodePointOffset;