文档:使用 include 指令时缺少图像(第一个,sphinx)
docs: missing images when using include directives (rst, sphinx)
我正在使用 rst/sphinx 生成文档,但引用文件中的图像有问题。
include
指令可以很好地引入 rst 文件,但我没有得到本身从包含的文件中引用的图像。
我的结构是这样的:
/documentation
/master_doc
/source
pointer_file.rst
and this file calls file.rst:
include:: ../../doc_a/source/file.rst
/documents
/doc_a
/source
/images
picture.jpg
file.rst
includes a figure ref:
.. figure:: images/picture.jpg
当我从 doc_a
目录构建时,我得到文本 + 图像。都好。
但是当我从 master_doc
目录构建时,在 include
指令出现的地方,我只得到文本,构建中缺少图像。
我该如何解决这个问题?我不想在两个目录中复制我的所有图像,这是目前唯一可行的方法。
***编辑:在上面的项目结构中添加了详细信息,因为下面建议的修复还不起作用。
针对第一条评论中的建议,我尝试了以下所有方法,none 有效:
.. figure:: /documentation/documents/doc_a/source/images/picture.jpg
和
.. figure:: /documents/doc_a/source/images/picture.jpg
和
.. figure:: /doc_a/source/images/picture.jpg
还有其他想法吗?
尝试将图像文件路径从相对路径更改为绝对路径。
.. figure:: /doc_a/source/images/picture.jpg
来自reStructuredText Primer, Images:
When used within Sphinx, the file name given (here gnu.png
) must either be relative to the source file, or absolute which means that they are relative to the top source directory. For example, the file sketch/spam.rst
could refer to the image images/spam.png
as ../images/spam.png
or /images/spam.png
.
我解决了这个问题。感谢 Steve Piercy 提出的有用问题。我必须做两件事:
将所有图像移动到 shared_images
文件夹,与所有文档项目的相对距离相同,并且
重新组织我的项目文件夹,使它们成为兄弟姐妹。
现在我的图片引用都是:../../../shared_images/
。
有效!
我正在使用 rst/sphinx 生成文档,但引用文件中的图像有问题。
include
指令可以很好地引入 rst 文件,但我没有得到本身从包含的文件中引用的图像。
我的结构是这样的:
/documentation
/master_doc
/source
pointer_file.rst
and this file calls file.rst:
include:: ../../doc_a/source/file.rst
/documents
/doc_a
/source
/images
picture.jpg
file.rst
includes a figure ref:
.. figure:: images/picture.jpg
当我从 doc_a
目录构建时,我得到文本 + 图像。都好。
但是当我从 master_doc
目录构建时,在 include
指令出现的地方,我只得到文本,构建中缺少图像。
我该如何解决这个问题?我不想在两个目录中复制我的所有图像,这是目前唯一可行的方法。
***编辑:在上面的项目结构中添加了详细信息,因为下面建议的修复还不起作用。
针对第一条评论中的建议,我尝试了以下所有方法,none 有效:
.. figure:: /documentation/documents/doc_a/source/images/picture.jpg
和
.. figure:: /documents/doc_a/source/images/picture.jpg
和
.. figure:: /doc_a/source/images/picture.jpg
还有其他想法吗?
尝试将图像文件路径从相对路径更改为绝对路径。
.. figure:: /doc_a/source/images/picture.jpg
来自reStructuredText Primer, Images:
When used within Sphinx, the file name given (here
gnu.png
) must either be relative to the source file, or absolute which means that they are relative to the top source directory. For example, the filesketch/spam.rst
could refer to the imageimages/spam.png
as../images/spam.png
or/images/spam.png
.
我解决了这个问题。感谢 Steve Piercy 提出的有用问题。我必须做两件事:
将所有图像移动到
shared_images
文件夹,与所有文档项目的相对距离相同,并且重新组织我的项目文件夹,使它们成为兄弟姐妹。
现在我的图片引用都是:../../../shared_images/
。
有效!