Skip to content

Commit 209bcae

Browse files
authored
fix: enable colspan and rowspan attributes (#245)
Previously exlcuded directives made for incorrect rendering of rst table cells spanning more than a single column or row. Fixes #182 Signed-off-by: Mike Fiedler <miketheman@gmail.com>
1 parent d821b44 commit 209bcae

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

readme_renderer/clean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"img": ["src", "width", "height", "alt", "align", "class"],
4747
"span": ["class"],
4848
"th": ["align"],
49-
"td": ["align"],
49+
"td": ["align", "colspan", "rowspan"],
5050
"div": ["align", "class"],
5151
"h1": ["align"],
5252
"h2": ["align"],
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<table>
2+
<colgroup>
3+
<col>
4+
<col>
5+
<col>
6+
<col>
7+
</colgroup>
8+
<thead>
9+
<tr><th>Header row, column 1
10+
(header rows optional)</th>
11+
<th>Header 2</th>
12+
<th>Header 3</th>
13+
<th>Header 4</th>
14+
</tr>
15+
</thead>
16+
<tbody>
17+
<tr><td>body row 1, column 1</td>
18+
<td>column 2</td>
19+
<td>column 3</td>
20+
<td>column 4</td>
21+
</tr>
22+
<tr><td>body row 2</td>
23+
<td colspan="3">Cells may span columns.</td>
24+
</tr>
25+
<tr><td>body row 3</td>
26+
<td rowspan="2">Cells may
27+
span rows.</td>
28+
<td colspan="2" rowspan="2"><ul>
29+
<li>Table cells</li>
30+
<li>contain</li>
31+
<li>body elements.</li>
32+
</ul>
33+
</td>
34+
</tr>
35+
<tr><td>body row 4</td>
36+
</tr>
37+
</tbody>
38+
</table>
39+
<table>
40+
<colgroup>
41+
<col>
42+
<col>
43+
</colgroup>
44+
<thead>
45+
<tr><th>title1</th>
46+
<th>title2</th>
47+
</tr>
48+
</thead>
49+
<tbody>
50+
<tr><td>col1</td>
51+
<td>col2</td>
52+
</tr>
53+
<tr><td rowspan="2">mutirow</td>
54+
<td>cell1</td>
55+
</tr>
56+
<tr><td>cell2</td>
57+
</tr>
58+
<tr><td>singlerow</td>
59+
<td>cell3</td>
60+
</tr>
61+
</tbody>
62+
</table>

tests/fixtures/test_rst_tables.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.. Example from https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#tables
2+
3+
+------------------------+------------+----------+----------+
4+
| Header row, column 1 | Header 2 | Header 3 | Header 4 |
5+
| (header rows optional) | | | |
6+
+========================+============+==========+==========+
7+
| body row 1, column 1 | column 2 | column 3 | column 4 |
8+
+------------------------+------------+----------+----------+
9+
| body row 2 | Cells may span columns. |
10+
+------------------------+------------+---------------------+
11+
| body row 3 | Cells may | - Table cells |
12+
+------------------------+ span rows. | - contain |
13+
| body row 4 | | - body elements. |
14+
+------------------------+------------+---------------------+
15+
16+
.. Example from #182
17+
18+
+---------------+---------------+
19+
| title1 | title2 |
20+
+===============+===============+
21+
| col1 | col2 |
22+
+---------------+---------------+
23+
| mutirow | cell1 |
24+
| +---------------+
25+
| | cell2 |
26+
+---------------+---------------+
27+
| singlerow | cell3 |
28+
+---------------+---------------+

0 commit comments

Comments
 (0)