@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.cjs CHANGED
@@ -599,7 +599,9 @@ function promoteAlignFromCellOps(cell) {
599
599
  function renderExtendedRow(data, row, cols, defaultCellTag, context, pretty) {
600
600
  const nl = pretty ? "\n" : "";
601
601
  const ind = (level) => pretty ? " ".repeat(level) : "";
602
- let html = `${ind(2)}<tr>${nl}`;
602
+ const rowHeight = data.rowHeights?.[row];
603
+ const trStyle = rowHeight !== void 0 && rowHeight > 0 ? ` style="height: ${rowHeight}px"` : "";
604
+ let html = `${ind(2)}<tr${trStyle}>${nl}`;
603
605
  for (let c = 0; c < cols; c++) {
604
606
  const key = `${row}:${c}`;
605
607
  const cell = data.cells[key];
@@ -638,6 +640,9 @@ function isGfmCompatible(data) {
638
640
  if (data.colWidths && data.colWidths.some((w) => w > 0)) {
639
641
  return false;
640
642
  }
643
+ if (data.rowHeights && data.rowHeights.some((h) => h > 0)) {
644
+ return false;
645
+ }
641
646
  for (const cell of Object.values(data.cells)) {
642
647
  if (cell !== null && cell.align !== void 0) return false;
643
648
  }
@@ -750,6 +755,39 @@ function extractColWidths(table) {
750
755
  }
751
756
  return void 0;
752
757
  }
758
+ function extractRowHeightPx(row) {
759
+ const style = row.getAttribute("style") || "";
760
+ const heightMatch = style.match(/(?:^|;)\s*height:\s*([\d.]+)px/i);
761
+ if (heightMatch?.[1]) {
762
+ const n = parseFloat(heightMatch[1]);
763
+ if (Number.isFinite(n) && n > 0) return n;
764
+ }
765
+ const minHeightMatch = style.match(/(?:^|;)\s*min-height:\s*([\d.]+)px/i);
766
+ if (minHeightMatch?.[1]) {
767
+ const n = parseFloat(minHeightMatch[1]);
768
+ if (Number.isFinite(n) && n > 0) return n;
769
+ }
770
+ const heightAttr = row.getAttribute("height");
771
+ if (heightAttr) {
772
+ const n = parseFloat(heightAttr);
773
+ if (Number.isFinite(n) && n > 0) return n;
774
+ }
775
+ return null;
776
+ }
777
+ function extractRowHeights(rows) {
778
+ const heights = [];
779
+ let any = false;
780
+ for (const row of rows) {
781
+ const h = extractRowHeightPx(row);
782
+ if (h != null) {
783
+ heights.push(h);
784
+ any = true;
785
+ } else {
786
+ heights.push(0);
787
+ }
788
+ }
789
+ return any ? heights : void 0;
790
+ }
753
791
  function extractCellAlign(cell) {
754
792
  const direct = extractInlineHorizontalAlign(cell);
755
793
  if (direct) return direct;
@@ -875,6 +913,14 @@ function parseTableElement(table, context) {
875
913
  if (colWidths.length > totalCols) colWidths.length = totalCols;
876
914
  result.colWidths = colWidths;
877
915
  }
916
+ const rowHeights = extractRowHeights(rows);
917
+ if (rowHeights) {
918
+ while (rowHeights.length < totalRows) rowHeights.push(0);
919
+ if (rowHeights.length > totalRows) rowHeights.length = totalRows;
920
+ if (rowHeights.some((h) => h > 0)) {
921
+ result.rowHeights = rowHeights;
922
+ }
923
+ }
878
924
  if (colAligns.length > 0 && colAligns.some((a) => a !== null)) {
879
925
  while (colAligns.length < totalCols) colAligns.push(null);
880
926
  if (colAligns.length > totalCols) colAligns.length = totalCols;
@@ -934,6 +980,14 @@ var tableBlockHandler = {
934
980
  if (typeof w !== "number" || w < 0) return false;
935
981
  }
936
982
  }
983
+ if (data.rowHeights !== void 0) {
984
+ if (!Array.isArray(data.rowHeights) || data.rowHeights.length !== rows) {
985
+ return false;
986
+ }
987
+ for (const h of data.rowHeights) {
988
+ if (typeof h !== "number" || h < 0) return false;
989
+ }
990
+ }
937
991
  if (data.colAligns !== void 0) {
938
992
  if (!Array.isArray(data.colAligns) || data.colAligns.length !== cols) {
939
993
  return false;