有没有办法在单元格内生成没有段落的 html 表格(使用 docutils rst2html)?

Is there a way to generate html tables without paragraphs inside the cells (using docutils rst2html)?

如果我有这样的第一个:

+--------------------------------+
| Table H1                       |
+-------------+------------------+
| Table H2a   | Table H2b        |
+=============+==================+
| a1          | b1               |
+-------------+------------------+
| a2          | b2               |
+-------------+------------------+
| a3          | b3               |
+-------------+------------------+

并将其转换为 html,如下所示:

python -u %PYTHONPATH3%\Scripts\rst2html5.py input.rst output.html

生成的 html table 如下所示:

<body>
    <div class="document"><blockquote><table>
        <colgroup>
            <col style="width: 42%" />
            <col style="width: 58%" />
        </colgroup>
        <thead>
            <tr><th class="head" colspan="2"><p>Table H1</p></th>
            </tr>
            <tr><th class="head"><p>Table H2a</p></th>
            <th class="head"><p>Table H2b</p></th>
            </tr>
        </thead>
        <tbody>
            <tr><td><p>a1</p></td>
            <td><p>b1</p></td>
            </tr>
            <tr><td><p>a2</p></td>
            <td><p>b2</p></td>
            </tr>
            <tr><td><p>a3</p></td>
            <td><p>b3</p></td>
            </tr>
        </tbody>
    </table></blockquote></div>
</body>

如您所见,单元格内容放置在段落标记内(在 <p></p> 内),因此被格式化为段落而不像我的 table 配置在 css 文件(例如,如果我在 css 中的文本段落添加首行缩进,单元格内容也会收到该缩进)

有没有办法在单元格内生成没有段落的 html tables(使用 docutils rst2html)?

备注:

您可以使用自定义 CSS 覆盖 <p> 标签的视觉间距。像这样。

td > p, li > p {
    margin: 0;
}

不过,我认为您的输出在表中生成 <p> 标记很奇怪,因为这不是 docutils 所做的,假设这是 rst2html5 的基础。我建议您联系该库的作者。

编辑:这是我使用 Sphinx 和您的 reST 示例的 HTML 输出:

<table border="1" class="docutils">
<colgroup>
<col width="42%">
<col width="58%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head" colspan="2">Table H1</th>
</tr>
<tr class="row-even"><th class="head">Table H2a</th>
<th class="head">Table H2b</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-odd"><td>a1</td>
<td>b1</td>
</tr>
<tr class="row-even"><td>a2</td>
<td>b2</td>
</tr>
<tr class="row-odd"><td>a3</td>
<td>b3</td>
</tr>
</tbody>
</table>