开发者

reST: inline links with arbitrary titles?

开发者 https://www.devze.com 2023-02-28 05:32 出处:网络
If I\'ve defined an internal hyperlink target, how can I link to it using arbitrary text as the link title?

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)


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.


Nicely, mzjn's answer also works for classes:

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

Hurray!


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消