如何解决如何在 Sphinx 文档中的某些特定功能之后插入图像?
我是 Sphinx 的新手。我使用 autodoc 生成了 .rst
文件。以下是其中一个模块的 .rst
文件:
Building things
=====================
Actions
----------------------------------
.. automodule:: acat.build.actions
:members: func1,func2,func3
:undoc-members:
:show-inheritance:
Patterns
----------------------------------
.. automodule:: acat.build.patterns
:members: func4,func5
:undoc-members:
:show-inheritance:
Orderings
----------------------------------
.. automodule:: acat.build.orderings
:members: func6
:undoc-members:
:show-inheritance:
现在我想在func1
、func3
和func5
之后插入图片,我知道图片可以嵌入
.. image:: func1_example.png
但是我应该把这些线放在哪里才能使图像出现在相应的功能下?
解决方法
假设您有 1 个包含 2 个函数和 3 个文档字符串的模块,例如:
acat.build.actions.py
"""
The module docstring.
"""
def func1():
"""
Docstring of func1.
"""
def func2():
"""
Docstring of func2.
"""
为了将图像准确插入到您想要的位置,您必须在 .rst
文件中的确切位置声明图像。所以你可以这样写 acat.build.actions.rst
:
Building things
=====================
Actions
----------------------------------
.. automodule:: acat.build.actions
:members:
:exclude-members: func1
:undoc-members:
:show-inheritance:
.. autofunction:: func1
You can write some text here.
.. image:: func1_example.png
您使用 func1
选项从模块中明确排除 :exclude-members: func1
因为您想在其下方包含图像。这允许您以自定义方式编写 func1
的文档,.. autofunction::
directive 将从 func1
文件中提取 .py
的文档字符串,但您可以编写 reStructuredText你想要里面。如果您想为更多功能执行此操作,请应用相同的技术。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。