您可以使用名为的角色来执行此操作ref
:
https://www.sphinx-doc.org/en/master/usage/restructedtext/roles.html#role-ref https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-ref
特别阅读第二个要点,它解决了如果参考文献没有放在标题之前会发生什么情况。
例如,在一个名为example.rst
这就是你将如何使用:
.. _arbitrary-anchor:
Some Arbitrary Line
This is actually a definition
标签“任意锚”在整个文档中必须是唯一的。要在文档中的某个位置引用此锚点,您可以执行以下操作:
Lorem ipsum :ref:`here is the anchor link <arbitrary-anchor>` dolor sit amet
不幸的是,当您hover在引用的行上,但您应该能够使用显式链接来访问它http://example.com/example.html#arbitrary-anchor
既然你提到了定义- 还值得注意的是,有一个角色叫做term
它允许您引用术语表中的定义。
有关如何使用它的示例,请参阅:http://sphinx-doc.org/glossary.html#term-role http://sphinx-doc.org/glossary.html#term-role
以及如何在第三段中引用这一点:http://sphinx-doc.org/domains.html#domains http://sphinx-doc.org/domains.html#domains
最后,如果您需要在段落中间插入锚点,一种方法是创建一个显式的锚点<a id=#sample>inline anchor</a>
通过使用raw role
:
http://docutils.sourceforge.net/docs/ref/rst/roles.html#raw http://docutils.sourceforge.net/docs/ref/rst/roles.html#raw
EDIT:
还有一种选择。这将创建锚点和悬停效果。
.. rst:role:: Sample rst role
This is a sample definition which links back to its anchor :rst:role:`Sample rst role`
这是一个看起来很有趣的指令,我已经使用了一段时间了。我在查看这个页面的源码时发现了它:
http://sphinx-doc.org/markup/inline.html#inline-markup http://sphinx-doc.org/markup/inline.html#inline-markup
http://sphinx-doc.org/_sources/markup/inline.txt http://sphinx-doc.org/_sources/markup/inline.txt
The text looks like this when you hover:
The text looks like this after you click on the link:
此选项不太理想,因为它显示:
定义的左侧和右侧。但这很好,因为它创建了一个锚点并将鼠标悬停在不是标题的内容上(因此它也不会出现在目录中,这正是我想要的)