@ai-matrx/content-ir 0.19.8 → 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/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();
@@ -2653,14 +2700,42 @@ function startsPipelessTable(header, delimiter) {
2653
2700
  if (delimiter === void 0 || !isGfmDelimiterRow(delimiter)) return false;
2654
2701
  return rowCells(head).length === rowCells(delimiter.trim()).length;
2655
2702
  }
2656
- function continuesTable(line) {
2703
+ function continuesTable(line, containerIndent = 0) {
2657
2704
  const trimmed = line.trim();
2658
2705
  if (!trimmed) return false;
2706
+ if (lineIndent(line) - containerIndent >= 4) return false;
2659
2707
  return trimmed.startsWith("|") || !startsBlock(trimmed);
2660
2708
  }
2661
2709
  function opensTable(lines, index) {
2662
2710
  const line = lines[index] ?? "";
2663
- return isPipeLedRow(line) || startsPipelessTable(line, lines[index + 1]);
2711
+ if (!isPipeLedRow(line) && !startsPipelessTable(line, lines[index + 1])) return false;
2712
+ return !isLazyContinuation(lines, index);
2713
+ }
2714
+ var QUOTE_LINE = /^ {0,3}>/;
2715
+ var THEMATIC_BREAK = /^(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/;
2716
+ var breaksParagraph = (trimmed) => /^#{1,6}(?:\s|$)/.test(trimmed) || THEMATIC_BREAK.test(trimmed) || opensStrictFence(trimmed) || startsHtmlBlock(trimmed);
2717
+ function isLazyContinuation(lines, index) {
2718
+ const header = lines[index] ?? "";
2719
+ let first = -1;
2720
+ for (let k = index - 1; k >= 0; k -= 1) {
2721
+ const line = lines[k] ?? "";
2722
+ const trimmed = line.trim();
2723
+ if (!trimmed) break;
2724
+ if (breaksParagraph(trimmed)) break;
2725
+ const marker = LIST_MARKER.exec(line);
2726
+ if (marker) {
2727
+ const rest = line.slice(marker[0].length).trim();
2728
+ if (!rest || breaksParagraph(rest)) break;
2729
+ first = k;
2730
+ break;
2731
+ }
2732
+ first = k;
2733
+ if (QUOTE_LINE.test(line)) break;
2734
+ }
2735
+ if (first < 0) return false;
2736
+ const start = lines[first] ?? "";
2737
+ if (QUOTE_LINE.test(start)) return !QUOTE_LINE.test(header);
2738
+ return lineIndent(header) < tableContainerIndentOf(lines, first, true);
2664
2739
  }
2665
2740
  function tableStartsAt(lines, index) {
2666
2741
  return opensTable(lines, index) && isGfmDelimiterRow(lines[index + 1] ?? "");
@@ -2670,8 +2745,9 @@ function findTableStart(lines, from = 0) {
2670
2745
  return -1;
2671
2746
  }
2672
2747
  function findTableEnd(lines, start) {
2748
+ const container = tableContainerIndent(lines, start);
2673
2749
  let end = Math.min(lines.length, start + 2);
2674
- while (end < lines.length && continuesTable(lines[end] ?? "")) end += 1;
2750
+ while (end < lines.length && continuesTable(lines[end] ?? "", container)) end += 1;
2675
2751
  return end;
2676
2752
  }
2677
2753
 
@@ -2707,6 +2783,7 @@ exports.isPipeLedRow = isPipeLedRow;
2707
2783
  exports.isSingleDollarMath = isSingleDollarMath;
2708
2784
  exports.islandEdit = islandEdit;
2709
2785
  exports.joinSource = joinSource;
2786
+ exports.lineIndent = lineIndent;
2710
2787
  exports.listIslands = listIslands;
2711
2788
  exports.looksLikeDisplayMath = looksLikeDisplayMath;
2712
2789
  exports.looksLikeOpenInlineMath = looksLikeOpenInlineMath;
@@ -2725,7 +2802,9 @@ exports.singleDollarMathEnd = singleDollarMathEnd;
2725
2802
  exports.spliceSave = spliceSave;
2726
2803
  exports.splitRowSegments = splitRowSegments;
2727
2804
  exports.splitsSurrogatePair = splitsSurrogatePair;
2805
+ exports.startsHtmlBlock = startsHtmlBlock;
2728
2806
  exports.startsPipelessTable = startsPipelessTable;
2807
+ exports.tableContainerIndent = tableContainerIndent;
2729
2808
  exports.tableStartsAt = tableStartsAt;
2730
2809
  exports.toCodePointOffset = toCodePointOffset;
2731
2810
  exports.toUtf16Offset = toUtf16Offset;