在 Sphinx 中使用图片作为可点击的 link
Use image in Sphinx as clickable link
问题:
我有 table 个图像用作 overview/introduction。我希望最终用户能够单击图像,然后 link 进入 HTML 页面以获取该图像的相应介绍信息1.
问题是我似乎无法让 linking 部分工作。 table 图像显示正常,但单击图像只会将我带到未找到页面屏幕(参见 post 底部的图像)。我在 Google 上花了大约一个小时,但还没有找到解决方案。
1每个图像都有一个对应的 .rst 文件,其中包含我希望最终用户看到的信息
信息:
- 狮身人面像 1.8.5
- Python 3.7.6(迷你康达)
- 从 reStructuredText 文件构建 html 页面
sphinx-build -b html source build
make clean html
make html
- 除了包含 RTD 主题外,我的 conf.py 文件没有做任何特别的事情
- 我想我需要在我的 conf.py 文件中做一些奇特的事情 如果 完全可以做我想做的事情
- 将 .rst 文件添加到
introduction_file.rst
中的 .. toc::
指令没有帮助
这是我目前的 reST 代码:
- 图片指令都在table里面; table 省略
- 我也相信 'image directives inside a table' 不是问题所在
.. filename is "introduction_file.rst"
.. image:: images/my_first_image.png
:scale: 100%
:alt: My First PNG Image
:align: center
:target: introduction_files/my_first_image_intro_file.rst
.. also didn't work:
.. :target: introduction_files/my_first_image_intro_file.html
文件结构:
Home.rst
是 HTML 页面的入口点(即它曾经被称为 index.rst
直到我重命名它并重构 conf.py
因此)
--build
...
-- source
|--Introduction/
|--introduction_file.rst
|--images/
|--my_first_image.png
|--my_second_image.png
...
|--introduction_files/
|--my_first_image_intro_file.rst
|--my_second_image_intro_file.rst
...
|--_static/
...
|--_templates/
...
|--conf.py
|--Home.rst
我不反对在 HTML/CSS 中做我想做的事,但如果有办法在 sphinx 中做,那么我更愿意那样做。无论如何,我最终都会编辑 HTML 代码,但编辑越少越好; Sphinx 本质上是一个快速入门或模板。
这张图片是我在我的 table-of-images 中单击其中一张图片时在浏览器中看到的。 Chrome 中的 URL 栏显示了 .rst 文件的正确路径,所以我有点困惑。
- 我尝试将
:target:
文件扩展名更改为 .html
,但这也不起作用
编辑: 忘记将 introduction_file.rst
的位置添加到文件夹结构
解决方案:
混淆路径。我正在 link 访问源目录中的文件,但需要 link 访问构建目录中的文件。不得不导航回带有几个“../”前缀的根目录,然后导航到构建目录中的 .html 信息文件。换句话说,这就是它最终的样子:
.. filename is "introduction_file.rst"
.. image:: images/my_first_image.png
:scale: 100%
:alt: My First PNG Image
:align: center
:target: ../../../build/html/Introduction/introduction_files/my_first_image_intro_file.html
target
选项的值必须是相对于 introduction_file.rst
的(您没有提供它的位置,所以您必须自己弄清楚),或者是相对于文档根目录的绝对值,即, /Introduction/introduction_files/my_first_image_intro_file.html
.
问题:
我有 table 个图像用作 overview/introduction。我希望最终用户能够单击图像,然后 link 进入 HTML 页面以获取该图像的相应介绍信息1.
问题是我似乎无法让 linking 部分工作。 table 图像显示正常,但单击图像只会将我带到未找到页面屏幕(参见 post 底部的图像)。我在 Google 上花了大约一个小时,但还没有找到解决方案。
1每个图像都有一个对应的 .rst 文件,其中包含我希望最终用户看到的信息
信息:
- 狮身人面像 1.8.5
- Python 3.7.6(迷你康达)
- 从 reStructuredText 文件构建 html 页面
sphinx-build -b html source build
make clean html
make html
- 除了包含 RTD 主题外,我的 conf.py 文件没有做任何特别的事情
- 我想我需要在我的 conf.py 文件中做一些奇特的事情 如果 完全可以做我想做的事情
- 将 .rst 文件添加到
introduction_file.rst
中的.. toc::
指令没有帮助
这是我目前的 reST 代码:
- 图片指令都在table里面; table 省略
- 我也相信 'image directives inside a table' 不是问题所在
.. filename is "introduction_file.rst"
.. image:: images/my_first_image.png
:scale: 100%
:alt: My First PNG Image
:align: center
:target: introduction_files/my_first_image_intro_file.rst
.. also didn't work:
.. :target: introduction_files/my_first_image_intro_file.html
文件结构:
Home.rst
是 HTML 页面的入口点(即它曾经被称为index.rst
直到我重命名它并重构conf.py
因此)
--build
...
-- source
|--Introduction/
|--introduction_file.rst
|--images/
|--my_first_image.png
|--my_second_image.png
...
|--introduction_files/
|--my_first_image_intro_file.rst
|--my_second_image_intro_file.rst
...
|--_static/
...
|--_templates/
...
|--conf.py
|--Home.rst
我不反对在 HTML/CSS 中做我想做的事,但如果有办法在 sphinx 中做,那么我更愿意那样做。无论如何,我最终都会编辑 HTML 代码,但编辑越少越好; Sphinx 本质上是一个快速入门或模板。
这张图片是我在我的 table-of-images 中单击其中一张图片时在浏览器中看到的。 Chrome 中的 URL 栏显示了 .rst 文件的正确路径,所以我有点困惑。
- 我尝试将
:target:
文件扩展名更改为.html
,但这也不起作用
编辑: 忘记将 introduction_file.rst
的位置添加到文件夹结构
解决方案:
混淆路径。我正在 link 访问源目录中的文件,但需要 link 访问构建目录中的文件。不得不导航回带有几个“../”前缀的根目录,然后导航到构建目录中的 .html 信息文件。换句话说,这就是它最终的样子:
.. filename is "introduction_file.rst"
.. image:: images/my_first_image.png
:scale: 100%
:alt: My First PNG Image
:align: center
:target: ../../../build/html/Introduction/introduction_files/my_first_image_intro_file.html
target
选项的值必须是相对于 introduction_file.rst
的(您没有提供它的位置,所以您必须自己弄清楚),或者是相对于文档根目录的绝对值,即, /Introduction/introduction_files/my_first_image_intro_file.html
.