Link reStructuredText 中的不同目标的相同文本

Link the same text to different targets in reStructuredText

如何在 reStructuredText 中使两个链接具有相同的文本但目标不同?以下脚本不起作用,但可以帮助您理解要点:

This Python_ is not the same as that Python_.

.. _Python2: https://docs.python.org/2/
.. _Python3: https://docs.python.org/3/

这项工作可以在 Markdown 中完成:

This [Python][Python2] is not the same as that [Python][Python3].

[Python2]: https://docs.python.org/2/
[Python3]: https://docs.python.org/3/

结果:

这个Python is not the same as that Python.

更好的解决方案:

This `Python <Python2_>`_ is not the same as that `Python <Python3_>`_.

.. _Python2: https://docs.python.org/2/
.. _Python3: https://docs.python.org/3/

找到了带有指令和替换的解决方案。不确定这是不是最好的。

This |Python2|_ is not the same as that |Python3|_.

.. |Python2| replace:: Python
.. |Python3| replace:: Python
.. _Python2: https://docs.python.org/2/
.. _Python3: https://docs.python.org/3/