File tree Expand file tree Collapse file tree 2 files changed +51
-4
lines changed
Expand file tree Collapse file tree 2 files changed +51
-4
lines changed Original file line number Diff line number Diff line change @@ -574,6 +574,9 @@ private function buildTableRows(array $rows): TableRows
574574 if (0 === $ lineKey ) {
575575 $ rows [$ rowKey ][$ column ] = $ line ;
576576 } else {
577+ if (!\array_key_exists ($ rowKey , $ unmergedRows ) || !\array_key_exists ($ lineKey , $ unmergedRows [$ rowKey ])) {
578+ $ unmergedRows [$ rowKey ][$ lineKey ] = $ this ->copyRow ($ rows , $ rowKey );
579+ }
577580 $ unmergedRows [$ rowKey ][$ lineKey ][$ column ] = $ line ;
578581 }
579582 }
@@ -585,8 +588,8 @@ private function buildTableRows(array $rows): TableRows
585588 yield $ this ->fillCells ($ row );
586589
587590 if (isset ($ unmergedRows [$ rowKey ])) {
588- foreach ($ unmergedRows [$ rowKey ] as $ row ) {
589- yield $ row ;
591+ foreach ($ unmergedRows [$ rowKey ] as $ unmergedRow ) {
592+ yield $ this -> fillCells ( $ unmergedRow ) ;
590593 }
591594 }
592595 }
@@ -670,12 +673,17 @@ private function fillNextRows(array $rows, int $line): array
670673 private function fillCells ($ row )
671674 {
672675 $ newRow = [];
676+
677+ $ newColumn = null ;
673678 foreach ($ row as $ column => $ cell ) {
674- $ newRow [] = $ cell ;
679+ if (null === $ newColumn ) {
680+ $ newColumn = $ column ;
681+ }
682+ $ newRow [$ newColumn ++] = $ cell ;
675683 if ($ cell instanceof TableCell && $ cell ->getColspan () > 1 ) {
676684 foreach (range ($ column + 1 , $ column + $ cell ->getColspan () - 1 ) as $ position ) {
677685 // insert empty value at column position
678- $ newRow [] = '' ;
686+ $ newRow [$ newColumn ++ ] = '' ;
679687 }
680688 }
681689 }
Original file line number Diff line number Diff line change @@ -333,6 +333,45 @@ 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+
355+ TABLE
356+ ],
357+ 'Cell after colspan contains multiple new lines ' => [
358+ ['Foo ' , 'Bar ' , 'Baz ' ],
359+ [
360+ [
361+ new TableCell ("foo \nbar " , ['colspan ' => 2 ]),
362+ "baz \nqux \nquux " ,
363+ ],
364+ ],
365+ 'default ' ,
366+ <<<'TABLE'
367+ +-----+-----+------+
368+ | Foo | Bar | Baz |
369+ +-----+-----+------+
370+ | foo | baz |
371+ | bar | qux |
372+ | | quux |
373+ +-----+-----+------+
374+
336375TABLE
337376 ],
338377 'Cell with rowspan ' => [
You can’t perform that action at this time.
0 commit comments