Link 带锚点的文档之间

Link between documents with anchor

我有两个第一个文件,比如:

doc1.rst
doc2.rst

doc1.rst

Doc 1 content
*************

Foo bar
=======

baz !

doc2.rst

Doc 2 content
*************

You can see "foo bar" `here <doc1.html#foo-bar>`.

要在 doc2 到 doc1#foo-bar 中有一个 link,我可以对其进行硬编码。但是如果没有硬编码怎么办呢?我可以用 sphinx 代码做到这一点吗?

为 doc1.rst 中您想要 link 的部分定义一个标签。然后使用 :ref: 角色创建对该部分的交叉引用。

doc1.rst:

Doc 1 content
*************

.. _foobar:

Foo bar
=======

baz !

doc2.rst:

Doc 2 content
*************

You can see "foo bar" :ref:`here <foobar>`.