I am using Sphinx with reStructuredText, and I’d like to include a hyperlink inside an inline literal. However, predictably, if I write
The result has type ``Foo_ -> Bar_``.
.. _Foo:
Information about ``Foo``.
.. _Bar:
Information about ``Bar``.
then Foo_ and Bar_ are not turned into hyperlinks. If I change my document to use a parsed-literal block, instead
The result has type:
.. parsed-literal::
    Foo_ -> Bar_
then I get the hyperlinks I want. However, I don’t want a separate block—I want the code to be inline. Is there any way to do that?
You can get pretty close with substitutions.
.. |Foo| replace:: ``Foo``
.. |Bar| replace:: ``Bar`` 
The result has type |Foo|_ ``->`` |Bar|_.
.. _Foo:
Information about ``Foo``.
.. _Bar:
Information about ``Bar``.
This was inspired by the workaround for nested inline markup described here: http://docutils.sourceforge.net/FAQ.html#is-nested-inline-markup-possible.
See also Format text in a link in reStructuredText.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With