如何在reStructuredText中链接重复的目标



我有两个重复的键->我的文档中的.. command:: targetName分为两页。我需要知道如何使用以下语法链接到这两个单独的目标:

Page-1 Click this -> :command:`targetName`  # this will always open the first targetName declared in the doc

目标:

Page-1 Click this -> :command:`targetName <page-1.html#targetName>`  # not working :/
Page-2 Click this -> :command:`targetName <page-2.html#targetName>`  # not working :/
Page-2 Click this -> `targetName <page-2.html#targetName>`_  # this will work but I don't want to use hyperlink instead of " :command: " cuz I want to keep my block style as is.

首先介绍一些术语。您所称的targetName在reStructuredText中称为title。尖括号里的东西是target。请参见交叉引用语法。

reStructuredText不支持嵌套的内联标记,该标记包括样式超链接。然而,有一个替代的变通办法。

由于reStructuredText不支持嵌套的内联标记,创建具有样式文本的引用的唯一方法是使用带有"的替换;替换";指令:

I recommend you try |Python|_.
.. |Python| replace:: Python, *the* best language around
.. _Python: http://www.python.org/

在您的情况下:

Page-1 Click this -> |myTarget|_
.. |myTarget| replace:: ``targetName``
.. _myTarget: page-1.html#targetName

若要进一步自定义外观,请使用自定义样式。请参阅如何为reStructuredText、Sphinx、ReadTheDocs等设置自定义样式。?例如。

最新更新