Markdown link 到 Sphinx 中的 reStructuredText 锚点

Markdown link to reStructuredText anchor in Sphinx

是否可以通过任何方式将 link 插入指向 reStructuredText 文件中锚点的 Markdown 文件?

我有一个包含 .rst 和 .md 文件的项目文档,我正在使用 m2rr Sphinx 扩展,但它似乎只支持文件内第一个锚点 links.

有什么办法可以实现吗?

Markdown 本身不支持 cross-referencing 到文档中的任意位置。

一种解决方法是插入一个基于 HTML 的锚点。

[My Label](/root-relative-url.html#anchor-in-page)

另一种选择是使用 MyST. Here you would instead of using markdown for the anchor, you would use either MyST syntax 或嵌入 reST 语法。

Target headers are defined with this syntax:

(header_target)=

They can then be referred to with the ref inline role:

{ref}`header_target`

By default, the reference will use the text of the target (such as the section title), but also you can directly specify the text:

{ref}`my text <header_target>`