David Wolever
David Wolever

Reputation: 154484

reST: inline links with arbitrary titles?

If I've defined an internal hyperlink target, how can I link to it using arbitrary text as the link title?

For example:

_`This is a very long internal link target`.

...

A `short reference`_ to the very long link target.

How could I make the “short reference” target the “very long internal target”?

Edit: Another example:

Widgets
=======

...

Use a `widget`_.

How can I make “widget” (singular) link to the “Widgets” (plural) heading?

(of course, I realize that this could be done using `widget`_\s… But that doesn't solve the general problem)

Upvotes: 3

Views: 555

Answers (3)

Eric O. Lebigot
Eric O. Lebigot

Reputation: 94485

A pure-reStructuredText method is to define multiple target names for the same target:

.. _my widget:
.. _above:
My long title about widgets
===========================
…
See how to use  `my widget`_ in the section above_.

(A limitation of this approach is that you may want to use the same text (e.g. "above") for two different locations, and the approach above fails in this case.)

Upvotes: 0

Steve Pike
Steve Pike

Reputation: 1534

Nicely, mzjn's answer also works for classes:

:class:`MyClasses <mymodule.MyClass>` in plural is awesome.

Hurray!

Upvotes: 2

mzjn
mzjn

Reputation: 50947

I haven't found a way to do this using "standard" reST. But with Sphinx, the following works:

.. _`This is a very long internal link target`:

:ref:`Short reference <This is a very long internal link target>` to the very long link target.

Upvotes: 4

Related Questions