在 Sphinx 中使用图片作为可点击的 link

Use image in Sphinx as clickable link

问题:

我有 table 个图像用作 overview/introduction。我希望最终用户能够单击图像,然后 link 进入 HTML 页面以获取该图像的相应介绍信息1.

问题是我似乎无法让 linking 部分工作。 table 图像显示正常,但单击图像只会将我带到未找到页面屏幕(参见 post 底部的图像)。我在 Google 上花了大约一个小时,但还没有找到解决方案。




1每个图像都有一个对应的 .rst 文件,其中包含我希望最终用户看到的信息


信息:


这是我目前的 reST 代码:

    .. 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 

文件结构:

--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 文件的正确路径,所以我有点困惑。


编辑: 忘记将 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.