如何在不使用RST表格式的情况下在reStructuredText中生成表格输出?

mri*_*her 5 documentation restructuredtext documentation-generation docutils python-sphinx

我正在尝试将我们的API文档及其专有文档生成器架构迁移到reStructuredText.给出最难的时间的是,我们有一个API细节的表格表示,直接用HTML编码,a:

--------+------------+--------+--------------------------------+
Param   |  Required  |  Type  |  Description
----------------------------------------------------------------
id      |     Yes    | int    | This is the ID of the record...
content |     No     | string | Optional string contents...
Run Code Online (Sandbox Code Playgroud)

(即目前编码为<tr><td class='param'>id</td><td class='required'>Yes</td>...)

我想在RST中执行此操作,但是在语义上执行此操作,而不是仅使用RST表格式.但我找不到任何自定义指令的好例子来处理我想要的方式,这就像是

:.. parameter-table:: My Parameter Table
    .. item::
       :param: "id"
       :required: true
       :type: "int"
       :desc: "This is the ID of the record..."
Run Code Online (Sandbox Code Playgroud)

如何在reStructuredText中完成此操作?

Kev*_*orn 5

我认为您不需要自定义指令。您是否尝试过使用标准的重构文本列表

它看起来像这样(来自链接页面):

.. list-table:: Frozen Delights!
   :widths: 15 10 30
   :header-rows: 1

   * - Treat
     - Quantity
     - Description
   * - Albatross
     - 2.99
     - On a stick!
   * - Crunchy Frog
     - 1.49
     - If we took the bones out, it wouldn't be
       crunchy, now would it?
   * - Gannet Ripple
     - 1.99
     - On a stick!
Run Code Online (Sandbox Code Playgroud)

表标题位于第一个外部列表项中(至少在本例中)。即使这并不完全是您想要的,我认为这至少可以帮助您完成 90% 的目标。