@scrider/formatter 1.8.2 → 1.8.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/dist/index.d.cts CHANGED
@@ -523,6 +523,8 @@ interface TableBlockData {
523
523
  headerRows?: number;
524
524
  /** Column widths (percentages by default) */
525
525
  colWidths?: number[];
526
+ /** Row heights in pixels (optional; auto when absent). */
527
+ rowHeights?: number[];
526
528
  /** Column alignments */
527
529
  colAligns?: (CellAlign | null)[];
528
530
  /** Cells indexed by "row:col" */
package/dist/index.d.ts CHANGED
@@ -523,6 +523,8 @@ interface TableBlockData {
523
523
  headerRows?: number;
524
524
  /** Column widths (percentages by default) */
525
525
  colWidths?: number[];
526
+ /** Row heights in pixels (optional; auto when absent). */
527
+ rowHeights?: number[];
526
528
  /** Column alignments */
527
529
  colAligns?: (CellAlign | null)[];
528
530
  /** Cells indexed by "row:col" */
package/dist/index.js CHANGED
@@ -469,7 +469,9 @@ function promoteAlignFromCellOps(cell) {
469
469
  function renderExtendedRow(data, row, cols, defaultCellTag, context, pretty) {
470
470
  const nl = pretty ? "\n" : "";
471
471
  const ind = (level) => pretty ? " ".repeat(level) : "";
472
- let html = `${ind(2)}<tr>${nl}`;
472
+ const rowHeight = data.rowHeights?.[row];
473
+ const trStyle = rowHeight !== void 0 && rowHeight > 0 ? ` style="height: ${rowHeight}px"` : "";
474
+ let html = `${ind(2)}<tr${trStyle}>${nl}`;
473
475
  for (let c = 0; c < cols; c++) {
474
476
  const key = `${row}:${c}`;
475
477
  const cell = data.cells[key];
@@ -508,6 +510,9 @@ function isGfmCompatible(data) {
508
510
  if (data.colWidths && data.colWidths.some((w) => w > 0)) {
509
511
  return false;
510
512
  }
513
+ if (data.rowHeights && data.rowHeights.some((h) => h > 0)) {
514
+ return false;
515
+ }
511
516
  for (const cell of Object.values(data.cells)) {
512
517
  if (cell !== null && cell.align !== void 0) return false;
513
518
  }
@@ -620,6 +625,39 @@ function extractColWidths(table) {
620
625
  }
621
626
  return void 0;
622
627
  }
628
+ function extractRowHeightPx(row) {
629
+ const style = row.getAttribute("style") || "";
630
+ const heightMatch = style.match(/(?:^|;)\s*height:\s*([\d.]+)px/i);
631
+ if (heightMatch?.[1]) {
632
+ const n = parseFloat(heightMatch[1]);
633
+ if (Number.isFinite(n) && n > 0) return n;
634
+ }
635
+ const minHeightMatch = style.match(/(?:^|;)\s*min-height:\s*([\d.]+)px/i);
636
+ if (minHeightMatch?.[1]) {
637
+ const n = parseFloat(minHeightMatch[1]);
638
+ if (Number.isFinite(n) && n > 0) return n;
639
+ }
640
+ const heightAttr = row.getAttribute("height");
641
+ if (heightAttr) {
642
+ const n = parseFloat(heightAttr);
643
+ if (Number.isFinite(n) && n > 0) return n;
644
+ }
645
+ return null;
646
+ }
647
+ function extractRowHeights(rows) {
648
+ const heights = [];
649
+ let any = false;
650
+ for (const row of rows) {
651
+ const h = extractRowHeightPx(row);
652
+ if (h != null) {
653
+ heights.push(h);
654
+ any = true;
655
+ } else {
656
+ heights.push(0);
657
+ }
658
+ }
659
+ return any ? heights : void 0;
660
+ }
623
661
  function extractCellAlign(cell) {
624
662
  const direct = extractInlineHorizontalAlign(cell);
625
663
  if (direct) return direct;
@@ -745,6 +783,14 @@ function parseTableElement(table, context) {
745
783
  if (colWidths.length > totalCols) colWidths.length = totalCols;
746
784
  result.colWidths = colWidths;
747
785
  }
786
+ const rowHeights = extractRowHeights(rows);
787
+ if (rowHeights) {
788
+ while (rowHeights.length < totalRows) rowHeights.push(0);
789
+ if (rowHeights.length > totalRows) rowHeights.length = totalRows;
790
+ if (rowHeights.some((h) => h > 0)) {
791
+ result.rowHeights = rowHeights;
792
+ }
793
+ }
748
794
  if (colAligns.length > 0 && colAligns.some((a) => a !== null)) {
749
795
  while (colAligns.length < totalCols) colAligns.push(null);
750
796
  if (colAligns.length > totalCols) colAligns.length = totalCols;
@@ -804,6 +850,14 @@ var tableBlockHandler = {
804
850
  if (typeof w !== "number" || w < 0) return false;
805
851
  }
806
852
  }
853
+ if (data.rowHeights !== void 0) {
854
+ if (!Array.isArray(data.rowHeights) || data.rowHeights.length !== rows) {
855
+ return false;
856
+ }
857
+ for (const h of data.rowHeights) {
858
+ if (typeof h !== "number" || h < 0) return false;
859
+ }
860
+ }
807
861
  if (data.colAligns !== void 0) {
808
862
  if (!Array.isArray(data.colAligns) || data.colAligns.length !== cols) {
809
863
  return false;