File tree Expand file tree Collapse file tree 6 files changed +41
-10
lines changed
src/RestructuredText/Parser/Productions/Table
tests/unit/Parser/Productions
tests/Integration/tests/tables/grid-table-with-list Expand file tree Collapse file tree 6 files changed +41
-10
lines changed Original file line number Diff line number Diff line change 2424use phpDocumentor \Guides \RestructuredText \Parser \Productions \RuleContainer ;
2525use Psr \Log \LoggerInterface ;
2626
27+ use function array_map ;
2728use function array_reverse ;
2829use function count ;
2930use function mb_strlen ;
@@ -45,6 +46,7 @@ protected function compile(ParserContext $context): TableNode
4546 {
4647 $ rows = $ this ->extractTableRows ($ context );
4748 $ rows = $ this ->concatenateTableRows ($ rows , $ context );
49+ $ rows = $ this ->trimTableCellContents ($ rows );
4850 $ headers = $ this ->extractHeaderRows ($ rows , $ context );
4951
5052 return new TableNode ($ rows , $ headers );
@@ -407,4 +409,27 @@ private function hasRowSpan(string $line): bool
407409 {
408410 return preg_match ('/\+[-]+\+/ ' , $ line ) === 1 ;
409411 }
412+
413+ /**
414+ * @param array<int, TableRow> $rows
415+ *
416+ * @return array<int, TableRow>
417+ */
418+ private function trimTableCellContents (array $ rows ): array
419+ {
420+ return array_map (
421+ static fn (TableRow $ row ) => new TableRow (
422+ array_map (
423+ static fn (TableColumn $ column ) => new TableColumn (
424+ trim ($ column ->getContent ()),
425+ $ column ->getColSpan (),
426+ [],
427+ $ column ->getRowSpan (),
428+ ),
429+ $ row ->getColumns (),
430+ ),
431+ ),
432+ $ rows ,
433+ );
434+ }
410435}
Original file line number Diff line number Diff line change @@ -205,7 +205,7 @@ public static function gridTableWithRowSpanProvider(): Generator
205205+===================================+===============+
206206| description | string |
207207+-----------------------------------+ |
208- | author | |
208+ | author | test |
209209+-----------------------------------+---------------+
210210| keywords | string |
211211+-----------------------------------+---------------+
@@ -217,7 +217,7 @@ public static function gridTableWithRowSpanProvider(): Generator
217217
218218 $ row1 = new TableRow ();
219219 $ row1 ->addColumn (self ::createColumnNode ('description ' ));
220- $ rowSpan = self ::createColumnNode (' string ' );
220+ $ rowSpan = self ::createColumnNode (" string \n\n test " );
221221 $ rowSpan ->incrementRowSpan ();
222222 $ row1 ->addColumn ($ rowSpan );
223223
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ public function getRowSpan(): int
5454
5555 public function addContent (string $ content ): void
5656 {
57- $ this ->content = trim ( $ this -> content . $ content ) ;
57+ $ this ->content .= $ content ;
5858 }
5959
6060 public function incrementRowSpan (): void
Original file line number Diff line number Diff line change 2323
2424final class TableRow
2525{
26- /** @var TableColumn[] */
27- private array $ columns = [];
26+ /** @param TableColumn[] $columns */
27+ public function __construct (private array $ columns = [])
28+ {
29+ }
2830
2931 public function addColumn (TableColumn $ tableColumn ): void
3032 {
Original file line number Diff line number Diff line change @@ -6,19 +6,23 @@ <h1>table</h1>
66 < tbody >
77 < tr >
88 < td > < strong > Paragraphs</ strong > </ td >
9- < td > < p > Paragraph 1</ p >
10- < p > Paragraph 2</ p > </ td >
9+ < td >
10+ < p > Paragraph 1</ p >
11+ < p > Paragraph 2</ p >
12+ </ td >
1113 </ tr >
1214 < tr >
1315 < td > < strong > Lists</ strong > </ td >
14- < td > < p > See the list</ p >
16+ < td >
17+ < p > See the list</ p >
1518 < ul >
1619 < li > Item 1</ li >
1720 < li > Item 2</ li >
1821 </ ul >
19- < p > A paragraph</ p > </ td >
22+ < p > A paragraph</ p >
23+ </ td >
2024 </ tr >
2125</ tbody >
2226</ table >
2327 </ div >
24- <!-- content end -->
28+ <!-- content end -->
You can’t perform that action at this time.
0 commit comments