rST:在表中插入代码块

时间:2016-06-21 13:18:31

标签: documentation restructuredtext

我需要使用与DVB规范使用的格式相同的格式在rST中创建表。

语法列类似于代码块,因为它需要有适当的缩进,但它也需要与其他列对齐。

我尝试了各种方法......问题似乎是领先的空白对rST做了一些奇怪的事情。

+-----------------------------+-----------------+------------+
| Syntax                      | Number of bits  | Identifier |
+=============================+=================+============+
|``private_data_byte(){``     |                 |            |
+-----------------------------+-----------------+------------+
|``  magic_bit``              | 8               | uimsbf     |
+-----------------------------+-----------------+------------+
|``  version``                | 8               | uimsbf     |
+-----------------------------+-----------------+------------+
|``  if (a == 0x0F){``        |                 |            |
+-----------------------------+-----------------+------------+
|``    field_a``              | 16              | uimsbf     |
+-----------------------------+-----------------+------------+
|``  }``                      |                 |            |
+-----------------------------+-----------------+------------+
|``}``                        |                 |            |
+-----------------------------+-----------------+------------+

1 个答案:

答案 0 :(得分:2)

解决方法是使用由替换定义的不间断空格:

.. |_| unicode:: 0xA0 

+-----------------------------+-----------------+------------+
| Syntax                      | Number of bits  | Identifier |
+=============================+=================+============+
|``private_data_byte(){``     |                 |            |
+-----------------------------+-----------------+------------+
| |_| ``magic_bit``           | 8               | uimsbf     |
+-----------------------------+-----------------+------------+
| |_| ``version``             | 8               | uimsbf     |
+-----------------------------+-----------------+------------+
| |_| ``if (a == 0x0F){``     |                 |            |
+-----------------------------+-----------------+------------+
| |_| |_| ``field_a``         | 16              | uimsbf     |
+-----------------------------+-----------------+------------+
| |_| ``}``                   |                 |            |
+-----------------------------+-----------------+------------+
|``}``                        |                 |            |
+-----------------------------+-----------------+------------+