@ai-matrx/content-ir 0.19.8 → 0.19.10

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.cjs CHANGED
@@ -2627,14 +2627,61 @@ function rowCells(line) {
2627
2627
  const cells = splitRowSegments(line).map((cell) => cell.trim());
2628
2628
  if (cells.length > 1 && cells[0] === "") cells.shift();
2629
2629
  if (cells.length > 1 && cells[cells.length - 1] === "") cells.pop();
2630
- else if (cells.length === 1 && cells[0] === "") cells.pop();
2630
+ else if (cells.length === 1 && cells[0] === "" && !line.includes("|")) cells.pop();
2631
2631
  return cells;
2632
2632
  }
2633
2633
  function unescapeCellPipes(cell) {
2634
2634
  return cell.replace(/\\\|/g, "|");
2635
2635
  }
2636
2636
  var BLOCK_START = /^(?:[-+*](?:\s|$)|\d{1,9}[.)](?:\s|$)|>|#{1,6}(?:\s|$)|(?:-\s*){3,}$|(?:\*\s*){3,}$|(?:_\s*){3,}$)/;
2637
- var startsBlock = (trimmed) => BLOCK_START.test(trimmed) || opensStrictFence(trimmed);
2637
+ var startsBlock = (trimmed) => BLOCK_START.test(trimmed) || opensStrictFence(trimmed) || startsHtmlBlock(trimmed);
2638
+ var HTML_RAW = /^<(?:script|pre|style|textarea)(?:[\s>]|$)/i;
2639
+ var HTML_COMMENT_ETC = /^(?:<!--|<\?|<![A-Za-z]|<!\[CDATA\[)/;
2640
+ 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";
2641
+ var HTML_BLOCK_TAG = new RegExp(`^</?(?:${HTML_BLOCK_NAMES})(?:[\\s>]|/>|$)`, "i");
2642
+ var ATTRIBUTE = `\\s+[A-Za-z_:][A-Za-z0-9_.:-]*(?:\\s*=\\s*(?:[^\\s"'=<>\`]+|'[^']*'|"[^"]*"))?`;
2643
+ var HTML_COMPLETE_TAG = new RegExp(`^(?:<[A-Za-z][A-Za-z0-9-]*(?:${ATTRIBUTE})*\\s*/?>|</[A-Za-z][A-Za-z0-9-]*\\s*>)\\s*$`);
2644
+ function startsHtmlBlock(trimmed) {
2645
+ if (!trimmed.startsWith("<")) return false;
2646
+ return HTML_RAW.test(trimmed) || HTML_COMMENT_ETC.test(trimmed) || HTML_BLOCK_TAG.test(trimmed) || HTML_COMPLETE_TAG.test(trimmed);
2647
+ }
2648
+ function lineIndent(line) {
2649
+ let column = 0;
2650
+ for (const ch of line) {
2651
+ if (ch === " ") column += 1;
2652
+ else if (ch === " ") column += 4 - column % 4;
2653
+ else break;
2654
+ }
2655
+ return column;
2656
+ }
2657
+ var LIST_MARKER = /^([ \t]*)([-+*]|\d{1,9}[.)])([ \t]+|$)/;
2658
+ function markerContentColumn(marker) {
2659
+ const markerEnd = lineIndent(marker[1] ?? "") + (marker[2] ?? "").length;
2660
+ const gap = marker[3] ? lineIndent(" ".repeat(markerEnd) + marker[3]) - markerEnd : 1;
2661
+ return markerEnd + (gap >= 1 && gap <= 4 ? gap : 1);
2662
+ }
2663
+ function tableContainerIndent(lines, start) {
2664
+ return tableContainerIndentOf(lines, start, false);
2665
+ }
2666
+ function tableContainerIndentOf(lines, start, ownItem) {
2667
+ const own = ownItem ? LIST_MARKER.exec(lines[start] ?? "") : null;
2668
+ if (own) return markerContentColumn(own);
2669
+ const header = lineIndent(lines[start] ?? "");
2670
+ if (header === 0) return 0;
2671
+ for (let k = start - 1; k >= 0; k -= 1) {
2672
+ const line = lines[k] ?? "";
2673
+ if (!line.trim()) continue;
2674
+ const indent = lineIndent(line);
2675
+ const marker = LIST_MARKER.exec(line);
2676
+ if (marker && indent < header) {
2677
+ const content = markerContentColumn(marker);
2678
+ if (content <= header) return content;
2679
+ continue;
2680
+ }
2681
+ if (indent === 0) return 0;
2682
+ }
2683
+ return 0;
2684
+ }
2638
2685
  var DELIMITER_CELL = /^:?-+:?$/;
2639
2686
  function isGfmDelimiterRow(line) {
2640
2687
  const trimmed = line.trim();
@@ -2646,32 +2693,68 @@ function isPipeLedRow(line) {
2646
2693
  const trimmed = line.trim();
2647
2694
  return trimmed.startsWith("|") && trimmed.includes("|", 1);
2648
2695
  }
2696
+ function isTableDelimiter(line) {
2697
+ if (line === void 0 || !isGfmDelimiterRow(line)) return false;
2698
+ return !BLOCK_START.test(line.trim());
2699
+ }
2649
2700
  function startsPipelessTable(header, delimiter) {
2650
2701
  const head = header.trim();
2651
- if (!head || head.startsWith("|") || startsBlock(head)) return false;
2652
- if (splitRowSegments(head).length < 2) return false;
2653
- if (delimiter === void 0 || !isGfmDelimiterRow(delimiter)) return false;
2702
+ if (!head || isPipeLedRow(head) || !head.startsWith("|") && startsBlock(head)) return false;
2703
+ if (!isTableDelimiter(delimiter)) return false;
2654
2704
  return rowCells(head).length === rowCells(delimiter.trim()).length;
2655
2705
  }
2656
- function continuesTable(line) {
2706
+ function continuesTable(line, containerIndent = 0) {
2657
2707
  const trimmed = line.trim();
2658
2708
  if (!trimmed) return false;
2709
+ if (lineIndent(line) - containerIndent >= 4) return false;
2659
2710
  return trimmed.startsWith("|") || !startsBlock(trimmed);
2660
2711
  }
2661
2712
  function opensTable(lines, index) {
2662
2713
  const line = lines[index] ?? "";
2663
- return isPipeLedRow(line) || startsPipelessTable(line, lines[index + 1]);
2714
+ if (!isPipeLedRow(line) && !startsPipelessTable(line, lines[index + 1])) return false;
2715
+ return !isLazyContinuation(lines, index);
2716
+ }
2717
+ var QUOTE_LINE = /^ {0,3}>/;
2718
+ var THEMATIC_BREAK = /^(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/;
2719
+ var breaksParagraph = (trimmed) => /^#{1,6}(?:\s|$)/.test(trimmed) || THEMATIC_BREAK.test(trimmed) || opensStrictFence(trimmed) || startsHtmlBlock(trimmed);
2720
+ function isLazyContinuation(lines, index) {
2721
+ const header = lines[index] ?? "";
2722
+ let first = -1;
2723
+ for (let k = index - 1; k >= 0; k -= 1) {
2724
+ const line = lines[k] ?? "";
2725
+ const trimmed = line.trim();
2726
+ if (!trimmed) break;
2727
+ if (breaksParagraph(trimmed)) break;
2728
+ const marker = LIST_MARKER.exec(line);
2729
+ if (marker) {
2730
+ const rest = line.slice(marker[0].length).trim();
2731
+ if (!rest || breaksParagraph(rest)) break;
2732
+ first = k;
2733
+ break;
2734
+ }
2735
+ first = k;
2736
+ if (QUOTE_LINE.test(line)) break;
2737
+ }
2738
+ if (first < 0) return false;
2739
+ const start = lines[first] ?? "";
2740
+ if (QUOTE_LINE.test(start)) return !QUOTE_LINE.test(header);
2741
+ return lineIndent(header) < tableContainerIndentOf(lines, first, true);
2664
2742
  }
2665
2743
  function tableStartsAt(lines, index) {
2666
- return opensTable(lines, index) && isGfmDelimiterRow(lines[index + 1] ?? "");
2744
+ const header = lines[index] ?? "";
2745
+ const delimiter = lines[index + 1];
2746
+ if (!opensTable(lines, index) || !isTableDelimiter(delimiter)) return false;
2747
+ if (rowCells(header).length !== rowCells(delimiter).length) return false;
2748
+ return lineIndent(header) - tableContainerIndent(lines, index) < 4;
2667
2749
  }
2668
2750
  function findTableStart(lines, from = 0) {
2669
2751
  for (let i = Math.max(0, from); i < lines.length; i += 1) if (opensTable(lines, i)) return i;
2670
2752
  return -1;
2671
2753
  }
2672
2754
  function findTableEnd(lines, start) {
2755
+ const container = tableContainerIndent(lines, start);
2673
2756
  let end = Math.min(lines.length, start + 2);
2674
- while (end < lines.length && continuesTable(lines[end] ?? "")) end += 1;
2757
+ while (end < lines.length && continuesTable(lines[end] ?? "", container)) end += 1;
2675
2758
  return end;
2676
2759
  }
2677
2760
 
@@ -2707,6 +2790,7 @@ exports.isPipeLedRow = isPipeLedRow;
2707
2790
  exports.isSingleDollarMath = isSingleDollarMath;
2708
2791
  exports.islandEdit = islandEdit;
2709
2792
  exports.joinSource = joinSource;
2793
+ exports.lineIndent = lineIndent;
2710
2794
  exports.listIslands = listIslands;
2711
2795
  exports.looksLikeDisplayMath = looksLikeDisplayMath;
2712
2796
  exports.looksLikeOpenInlineMath = looksLikeOpenInlineMath;
@@ -2725,7 +2809,9 @@ exports.singleDollarMathEnd = singleDollarMathEnd;
2725
2809
  exports.spliceSave = spliceSave;
2726
2810
  exports.splitRowSegments = splitRowSegments;
2727
2811
  exports.splitsSurrogatePair = splitsSurrogatePair;
2812
+ exports.startsHtmlBlock = startsHtmlBlock;
2728
2813
  exports.startsPipelessTable = startsPipelessTable;
2814
+ exports.tableContainerIndent = tableContainerIndent;
2729
2815
  exports.tableStartsAt = tableStartsAt;
2730
2816
  exports.toCodePointOffset = toCodePointOffset;
2731
2817
  exports.toUtf16Offset = toUtf16Offset;