如何为重构文本(ReST)

时间:2018-06-14 12:23:22

标签: alias python-sphinx restructuredtext documentation-generation

我正在尝试将一些图像放入重构文本(ReST)文档中,以便通过Sphinx为python项目构建文档。这些图像应出现在表格内。

可以将图像放在像

这样的表格中
+------------+-----------------------------+ 
| cell1 text | .. image:: path/to/file.png |
+------------+-----------------------------+ 

不幸的是,在我的情况下,文件路径很长。实际上,表格仍然符合PEP8限制(在我的情况下)为80个字符。

 .. image:: ../quite/unfortunate/loooooooooooooooooooong/path/to/file.png

为了保持表格仍然可读,我正在考虑使用所描述的别名here

 .. |longtext| replace:: ../quite/unfortunate/loooooooooooooooooooong/path/to/

+------------+-------------------------------+ 
| cell1 text | .. image:: |longtext|file.png |
+------------+-------------------------------+ 

但这失败了。在doc构建中,错误是

image file not readable |longtext|file.png

表示不会应用别名。

我知道我可以为完整的图像指令创建一个别名,比如

.. |longtext01| image:: ../quite/unfortunate/loooooooooooooooooooong/path/to/file01.png

但这会导致不幸的情况,我需要在表格中为每个图像创建一个别名;在我的情况下,我有~50张图片。

有没有什么好方法可以为部分文件名生成别名? 正如this question所说,几年前没有,但也许情况发生了变化?

我想的另一种方法是以编程方式创建50个别名,但似乎我不能在ReST中使用for-loops?

0 个答案:

没有答案