【问题标题】:Include contents directive without changing headers to links包含内容指令而不将标题更改为链接
【发布时间】:2022-01-12 22:07:17
【问题描述】:

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

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

.. contents:: Table of Contents

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

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

Example with contents and links

Example without contents and no links

【问题讨论】:

    标签: python-sphinx restructuredtext


    【解决方案1】:

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

    .. contents:: Table of Contents
       :backlinks: none
    
    #############
    Heading 1
    #############
    
    *************
    Heading 2
    *************
    

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

    【讨论】:

      猜你喜欢
      • 2011-05-18
      • 2013-02-20
      • 2010-10-09
      • 1970-01-01
      • 2021-04-10
      • 1970-01-01
      • 1970-01-01
      • 2012-06-10
      • 1970-01-01
      相关资源
      最近更新 更多