【问题标题】:How can I include a hyperlink reference inside an inline literal in reStructuredText?如何在 reStructuredText 的内联文字中包含超链接引用?
【发布时间】:2019-11-19 05:15:48
【问题描述】:

我正在使用带有 reStructuredText 的 Sphinx,并且我想在内联文字中包含一个超链接。但是,可以预见的是,如果我写

The result has type ``Foo_ -> Bar_``.

.. _Foo:

Information about ``Foo``.

.. _Bar:

Information about ``Bar``.

然后Foo_Bar_ 不会变成超链接。如果我将文档更改为使用 parsed-literal 块,则改为

The result has type:

.. parsed-literal::

    Foo_ -> Bar_

然后我得到我想要的超链接。但是,我不想要一个单独的块——我希望代码是内联的。有什么办法吗?

【问题讨论】:

标签: python-sphinx restructuredtext


【解决方案1】:

你可以通过替换非常接近。

.. |Foo| replace:: ``Foo``
.. |Bar| replace:: ``Bar`` 

The result has type |Foo|_ ``->`` |Bar|_.

.. _Foo:

Information about ``Foo``.

.. _Bar:

Information about ``Bar``.

这是受到此处描述的嵌套内联标记的解决方法的启发:http://docutils.sourceforge.net/FAQ.html#is-nested-inline-markup-possible

另见Format text in a link in reStructuredText

【讨论】:

    猜你喜欢
    • 2016-04-03
    • 2018-06-12
    • 1970-01-01
    • 2021-08-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-23
    • 2016-08-01
    • 1970-01-01
    相关资源
    最近更新 更多