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 24
24
use phpDocumentor \Guides \RestructuredText \Parser \Productions \RuleContainer ;
25
25
use Psr \Log \LoggerInterface ;
26
26
27
+ use function array_map ;
27
28
use function array_reverse ;
28
29
use function count ;
29
30
use function mb_strlen ;
@@ -45,6 +46,7 @@ protected function compile(ParserContext $context): TableNode
45
46
{
46
47
$ rows = $ this ->extractTableRows ($ context );
47
48
$ rows = $ this ->concatenateTableRows ($ rows , $ context );
49
+ $ rows = $ this ->trimTableCellContents ($ rows );
48
50
$ headers = $ this ->extractHeaderRows ($ rows , $ context );
49
51
50
52
return new TableNode ($ rows , $ headers );
@@ -407,4 +409,27 @@ private function hasRowSpan(string $line): bool
407
409
{
408
410
return preg_match ('/\+[-]+\+/ ' , $ line ) === 1 ;
409
411
}
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
+ }
410
435
}
Original file line number Diff line number Diff line change @@ -205,7 +205,7 @@ public static function gridTableWithRowSpanProvider(): Generator
205
205
+===================================+===============+
206
206
| description | string |
207
207
+-----------------------------------+ |
208
- | author | |
208
+ | author | test |
209
209
+-----------------------------------+---------------+
210
210
| keywords | string |
211
211
+-----------------------------------+---------------+
@@ -217,7 +217,7 @@ public static function gridTableWithRowSpanProvider(): Generator
217
217
218
218
$ row1 = new TableRow ();
219
219
$ row1 ->addColumn (self ::createColumnNode ('description ' ));
220
- $ rowSpan = self ::createColumnNode (' string ' );
220
+ $ rowSpan = self ::createColumnNode (" string \n\n test " );
221
221
$ rowSpan ->incrementRowSpan ();
222
222
$ row1 ->addColumn ($ rowSpan );
223
223
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ public function getRowSpan(): int
54
54
55
55
public function addContent (string $ content ): void
56
56
{
57
- $ this ->content = trim ( $ this -> content . $ content ) ;
57
+ $ this ->content .= $ content ;
58
58
}
59
59
60
60
public function incrementRowSpan (): void
Original file line number Diff line number Diff line change 23
23
24
24
final class TableRow
25
25
{
26
- /** @var TableColumn[] */
27
- private array $ columns = [];
26
+ /** @param TableColumn[] $columns */
27
+ public function __construct (private array $ columns = [])
28
+ {
29
+ }
28
30
29
31
public function addColumn (TableColumn $ tableColumn ): void
30
32
{
Original file line number Diff line number Diff line change @@ -6,19 +6,23 @@ <h1>table</h1>
6
6
< tbody >
7
7
< tr >
8
8
< 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 >
11
13
</ tr >
12
14
< tr >
13
15
< td > < strong > Lists</ strong > </ td >
14
- < td > < p > See the list</ p >
16
+ < td >
17
+ < p > See the list</ p >
15
18
< ul >
16
19
< li > Item 1</ li >
17
20
< li > Item 2</ li >
18
21
</ ul >
19
- < p > A paragraph</ p > </ td >
22
+ < p > A paragraph</ p >
23
+ </ td >
20
24
</ tr >
21
25
</ tbody >
22
26
</ table >
23
27
</ div >
24
- <!-- content end -->
28
+ <!-- content end -->
You can’t perform that action at this time.
0 commit comments