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

标签 python html css restructuredtext

如果我有这样的第一个:

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

然后像这样把它转换成html:

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

生成的 html 表格如下所示:

<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> 内),因此被格式化为段落,而不像我的表是在 css 文件中配置的(例如,如果我添加第一个 - css 中文本段落的行缩进,单元格内容也接收该缩进)

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

注意事项:

  • 我实际上是在转换一个非常长的第一个文件,因此应该首选使其正常工作而不是破解/替换 html。
  • 我的列表项也发生了同样的事情,它们是在 <p> 中创建的标签(例如 <li><p>Something</p></li> )。

最佳答案

您可以使用自定义 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>

关于python - 有没有办法在单元格内生成没有段落的 html 表格(使用 docutils rst2html)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48081783/

相关文章:

python - 如何在 python 中正确解析 xml 注释

Python CSV 分隔符 : Separate Cells

Python - 如何查找多维数组中是否存在某个项目?

javascript - Google map - 使用 API 获取放置方向并查找该特定路线上的流量

css - 如何使点击标志在 css/html 中没有 href 出现?

python - 为什么使用 '==' 或 'is' 比较字符串有时会产生不同的结果?

javascript - 如何在键入另一个字符时插入一个字符

javascript - 无法让 CSS3 转换在 IE 10/11 中工作

html - 无法很好地定位到中心

html - 电子邮件模板 HTML 从 ul 中删除元素符号点