10000 Table: support cells with newlines after a cell with colspan >= 2 · symfony/symfony@4776950 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4776950

Browse files
author
Jelle Raaijmakers
committed
Table: support cells with newlines after a cell with colspan >= 2
When rendering a table with a cell containing newlines after a cell with colspan set to at least 2, every line in the cell with newlines except the first one fails to render. This case is fixed by calling `->fillCells()` on the unmerged rows and implementing support for rows that start with a non-zero index for the columns.
1 parent 909158b commit 4776950

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ private function buildTableRows(array $rows): TableRows
586586

587587
if (isset($unmergedRows[$rowKey])) {
588588
foreach ($unmergedRows[$rowKey] as $row) {
589-
yield $row;
589+
yield $this->fillCells($row);
590590
}
591591
}
592592
}
@@ -670,12 +670,17 @@ private function fillNextRows(array $rows, int $line): array
670670
private function fillCells($row)
671671
{
672672
$newRow = [];
673+
674+
$newColumn = null;
673675
foreach ($row as $column => $cell) {
674-
$newRow[] = $cell;
676+
if (null === $newColumn) {
677+
$newColumn = $column;
678+
}
679+
$newRow[$newColumn++] = $cell;
675680
if ($cell instanceof TableCell && $cell->getColspan() > 1) {
676681
foreach (range($column + 1, $column + $cell->getColspan() - 1) as $position) {
677682
// insert empty value at column position
678-
$newRow[] = '';
683+
$newRow[$newColumn++] = '';
679684
}
680685
}
681686
}

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,25 @@ public function renderProvider()
333333
| Cupiditate dicta atque porro, tempora exercitationem modi animi nulla nemo vel nihil! |
334334
+-------------------------------+-------------------------------+-----------------------------+
335335

336+
TABLE
337+
],
338+
'Cell after colspan contains new line break' => [
339+
['Foo', 'Bar', 'Baz'],
340+
[
341+
[
342+
new TableCell("foo\nbar", ['colspan' => 2]),
343+
"baz\nqux",
344+
],
345+
],
346+
'default',
347+
<<<'TABLE'
348+
+-----+-----+-----+
349+
| Foo | Bar | Baz |
350+
+-----+-----+-----+
351+
| foo | baz |
352+
| bar | qux |
353+
+-----+-----+-----+
354+
336355
TABLE
337356
],
338357
'Cell with rowspan' => [

0 commit comments

Comments
 (0)
0