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

发布于 2024-12-11 03:28:41 字数 884 浏览 2 评论 0原文

我正在尝试将我们的 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...

即当前编码为 id是...)

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

:.. parameter-table:: My Parameter Table
    .. item::
       :param: "id"
       :required: true
       :type: "int"
       :desc: "This is the ID of the record..."

我怎样才能在 reStructuredText 中完成这个?

I'm trying to migrate our API docs and their proprietary documentation generator schema to reStructuredText. The piece that gives the hardest time is, we have a tabular representation of API details, coded directly in HTML, a la:

--------+------------+--------+--------------------------------+
Param   |  Required  |  Type  |  Description
----------------------------------------------------------------
id      |     Yes    | int    | This is the ID of the record...
content |     No     | string | Optional string contents...

(i.e. this is currently coded as <tr><td class='param'>id</td><td class='required'>Yes</td>...)

I want to do this in RST but do it semantically, rather than just using an RST table format. But I can't find any good examples of custom directives to handle this the way I want, which would be something like

:.. parameter-table:: My Parameter Table
    .. item::
       :param: "id"
       :required: true
       :type: "int"
       :desc: "This is the ID of the record..."

How can I accomplish this in reStructuredText?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你怎么敢 2024-12-18 03:28:42

我认为您不需要自定义指令。您是否尝试过使用标准的 restructedText List Table

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

.. 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!

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

I don't think you need a custom directive. Have you tried using a standard restructuredText List Table?

It looks something like this (from the linked page):

.. 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!

The table headers are in the first outer list item (in this example, at least). Even if this isn't exactly what you want I think this will get you at least 90% of the way there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文