Skip to main content
 首页 » 编程设计

python-sphinx之如何在不创建任意标签的情况下在sphinx restructuredtext中建立到标题的内部链接

2025年02月15日46JeffreyZhao

我有一个包含许多标题和子标题的文档。在文本中,我想链接回到标题之一。没有:ref:标签的冗余怎么办?内容似乎可以选择标题。我希望有这样的东西:`#polled-data-retrieval`_

请您参考如下方法:

reStructuredText支持implicit hyperlink targets。从reStructuredText quick reference:

Section titles, footnotes, and citations automatically generate hyperlink targets (the title text or footnote/citation label is used as the hyperlink name).



因此,以下文本(从reStructuredText快速引用,拼写错误和所有内容中删除):
Titles are targets, too 
======================= 
Implict references, like `Titles are targets, too`_. 

产生类似于以下内容的HTML:
<strong><a name="title">Titles are targets, too</a></strong> 
 
<p>Implict references, like <a href="#title">Titles are targets, too</a>.</p>