Repository: pypa/readme_renderer (language: python)

Issue:
RST tables multirow cells rendering
As I understand this is the lib that powers PyPI REDME rendering so I post this question here.

## The problem

PyPI renders multirow cells in a way that it essentially ignores them which messes up the following rows. I have first encounterd this problem when trying to publish package to PyPI: https://pypi.org/project/ssh-utilities/ .

## Minimal reproducible example

```rst
+---------------+---------------+
| title1        | title2        |
+===============+===============+
| col1          | col2          |
+---------------+---------------+
| mutirow       | cell1         |
|               +---------------+
|               | cell2         |
+---------------+---------------+
| singlerow     | cell3         |
+---------------+---------------+
```

Render this rst code with `readme-renderer`

```bash
python -m readme_renderer README.rst -o README.html
```

You will get this:
![example](https://user-images.githubusercontent.com/26881798/104957140-e03a0a80-59cd-11eb-81c8-ce76db2f99d3.jpg)

In the picture you can see the **cell2** is incorrectly possitioned in the first column.

As far as I know RST is not supposed to render like this. So is this a know bug? Does any workaround exist? or is this on purpose?




Discussion / hints:
Reviewing older issues, this one wasn't responded to.

This does appear to be a missing part of the functionality, as [docutils supports this kind of table layout](https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#tables).

It's likely due to us stripping out the necessary directives to support this view during the `clean()` phase.
I'll add some tests and figure out the necessary directives to support this.

Fix patch:
diff --git a/readme_renderer/clean.py b/readme_renderer/clean.py
index 332dd5b..be430cd 100644
--- a/readme_renderer/clean.py
+++ b/readme_renderer/clean.py
@@ -46,7 +46,7 @@
     "img": ["src", "width", "height", "alt", "align", "class"],
     "span": ["class"],
     "th": ["align"],
-    "td": ["align"],
+    "td": ["align", "colspan", "rowspan"],
     "div": ["align", "class"],
     "h1": ["align"],
     "h2": ["align"],


Test patch:
diff --git a/tests/fixtures/test_rst_tables.html b/tests/fixtures/test_rst_tables.html
new file mode 100644
index 0000000..2e2a984
--- /dev/null
+++ b/tests/fixtures/test_rst_tables.html
@@ -0,0 +1,62 @@
+<table>
+<colgroup>
+<col>
+<col>
+<col>
+<col>
+</colgroup>
+<thead>
+<tr><th>Header row, column 1
+(header rows optional)</th>
+<th>Header 2</th>
+<th>Header 3</th>
+<th>Header 4</th>
+</tr>
+</thead>
+<tbody>
+<tr><td>body row 1, column 1</td>
+<td>column 2</td>
+<td>column 3</td>
+<td>column 4</td>
+</tr>
+<tr><td>body row 2</td>
+<td colspan="3">Cells may span columns.</td>
+</tr>
+<tr><td>body row 3</td>
+<td rowspan="2">Cells may
+span rows.</td>
+<td colspan="2" rowspan="2"><ul>
+<li>Table cells</li>
+<li>contain</li>
+<li>body elements.</li>
+</ul>
+</td>
+</tr>
+<tr><td>body row 4</td>
+</tr>
+</tbody>
+</table>
+<table>
+<colgroup>
+<col>
+<col>
+</colgroup>
+<thead>
+<tr><th>title1</th>
+<th>title2</th>
+</tr>
+</thead>
+<tbody>
+<tr><td>col1</td>
+<td>col2</td>
+</tr>
+<tr><td rowspan="2">mutirow</td>
+<td>cell1</td>
+</tr>
+<tr><td>cell2</td>
+</tr>
+<tr><td>singlerow</td>
+<td>cell3</td>
+</tr>
+</tbody>
+</table>
diff --git a/tests/fixtures/test_rst_tables.rst b/tests/fixtures/test_rst_tables.rst
new file mode 100644
index 0000000..52ceaa2
--- /dev/null
+++ b/tests/fixtures/test_rst_tables.rst
@@ -0,0 +1,28 @@
+.. Example from https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#tables
+
++------------------------+------------+----------+----------+
+| Header row, column 1   | Header 2   | Header 3 | Header 4 |
+| (header rows optional) |            |          |          |
++========================+============+==========+==========+
+| body row 1, column 1   | column 2   | column 3 | column 4 |
++------------------------+------------+----------+----------+
+| body row 2             | Cells may span columns.          |
++------------------------+------------+---------------------+
+| body row 3             | Cells may  | - Table cells       |
++------------------------+ span rows. | - contain           |
+| body row 4             |            | - body elements.    |
++------------------------+------------+---------------------+
+
+.. Example from #182
+
++---------------+---------------+
+| title1        | title2        |
++===============+===============+
+| col1          | col2          |
++---------------+---------------+
+| mutirow       | cell1         |
+|               +---------------+
+|               | cell2         |
++---------------+---------------+
+| singlerow     | cell3         |
++---------------+---------------+