Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I include a hyperlink reference inside an inline literal in reStructuredText?

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?

like image 734
Alexis King Avatar asked Oct 31 '25 05:10

Alexis King


1 Answers

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.

like image 88
mzjn Avatar answered Nov 02 '25 23:11

mzjn