python-sphinx - 包含内容指令而不更改链接标题

标签 python-sphinx restructuredtext

如果我在文档中包含 ..contents:: 指令,则页面上的所有标题都会变成指向页面 anchor #id1#id2 的链接...

如果没有..contents::,页面上的标题不是链接(但会在悬停时显示 anchor 链接)。是否可以在不将页面标题更改为链接的情况下包含内容?

.. contents:: Table of Contents

#############
Heading 1
#############

*************
Heading 2
*************

Example with contents and links

Example without contents and no links

最佳答案

contents directive接受几个选项,其中之一是反向链接。它的默认值为 entry,它将每个标题的链接添加回目录中相应的条目。这是您观察到的行为。使用top,它将链接回整个目录。如果您将该值设置为none,反向链接将被删除。

.. contents:: Table of Contents
   :backlinks: none

#############
Heading 1
#############

*************
Heading 2
*************

这是live rendering由 rst.ninjs.org 提供,与您链接到的网站相同。请注意,它使用 Docutils 呈现 reStructuredText 输入。悬停时显示的部分链接由 Sphinx 添加。至少默认情况下是这样。您也可以通过在 Sphinx 的配置文件 conf.py 中设置 html_permalinks = False 来抑制它们。

关于python-sphinx - 包含内容指令而不更改链接标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70689017/

相关文章:

python - 通过 Sphinx 从脚本中获取文档字符串

python - 坏狮身人面像 :linenos: alignment

python - 狮身人面像 : Autodocs for classes inheriting from base classes implemented in C

python - 如何在python中解析重组文本?

html - 如何使用 ReStructured Text (rst2html.py) 在文本中使用颜色或如何插入没有空行的 HTML 标签?

python - 如何确保 README.rst 有效?

python - 如何配置 Sphinx auto flask 来记录 flask-restful API?

python - 如何在 Sphinx 中创建自定义指令

github - 在 "github pages"站点内查看 .rst

restructuredtext - reStructuredText 中的链接图像