diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..8f2857aa2c6562ff70acc9034f2d6170cdcc2f0c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +out +.vscode +__pycache__ diff --git a/gridTable.py b/gridTable.py index 91ab0c71ee1837d9030166c392a310f5b0029969..c859bef90f429af7d826474494e6fb399e30dfa2 100644 --- a/gridTable.py +++ b/gridTable.py @@ -94,7 +94,7 @@ def formatGridTable(lines: list[str]) -> list[str]: return lines # Get column widths from first separator line - colWidths = [len(col.strip()) for col in lines[0].split('+')[1:-1]] + colWidths = [0] * (lines[0].count('+') - 1) result = [] # Adjust column widths if any cell is longer @@ -105,7 +105,10 @@ def formatGridTable(lines: list[str]) -> list[str]: for i, cell in enumerate(rowCells): if i >= len(colWidths): continue - cellWidth = len(cell.strip()) + # Calculate maximum width of each line in the cell. Lines could be multilines, so we need to split them. + cellLines = cell.strip().split('\\\n') + cellWidth = max(len(line.strip()) if line != colspanMarker else 0 + for line in cellLines) if cellWidth > colWidths[i]: colWidths[i] = cellWidth