在Sphinx中使用Markdown链接到reStructuredText锚点

3

有没有可能在指向reStructuredText文件中的锚点时插入指向Markdown文件的链接?

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

有什么办法可以实现这个吗?

1个回答

7
Markdown本身不支持跨文档引用到任意位置的交叉引用。 一种解决方法是插入基于HTML的锚点。
[My Label](/root-relative-url.html#anchor-in-page)

另一种选择是使用MyST。在这里,您将不使用markdown作为锚点,而是使用MyST语法或嵌入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>`

1
是的,确实如此。谢谢。我为此创建了一个简单的示例项目: https://github.com/waszil/myst-crosslink-example - waszil

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接