Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internal hyperlink in restructuredtext with customized text

I know how to create an external hyperlink with customized text.

`My cool link <http://www.asdf.com>`_

But I want to link to an internal reference.

.. _foo:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.

So I'd like to do something like

`My cool internal link <foo>`_

But this doesn't work.

like image 485
John Avatar asked Apr 11 '16 04:04

John


4 Answers

Solution:

`My cool internal link <foo_>`_
like image 150
John Avatar answered Oct 04 '22 04:10

John


Use 2 underscores on text and 1 undescore on link target, example:

`My cool internal link <foo_>`__

... somewhere lower ...

.. _foo:

This staff is referenced by "My cool internal link"

When I use one underscore instead of 2, rst2pdf throws an error.

like image 28
user2626972 Avatar answered Oct 04 '22 03:10

user2626972


If John's solution doesn't work for you:

`My cool internal link<foo>`
like image 30
tuxayo Avatar answered Oct 04 '22 05:10

tuxayo


You just needed to remove the space after your custom title, and before the angle brackets, and use the :ref: directive:

This works:

:ref:`My cool internal link with no space before bracket<foo>`

This doesn't:

:ref:`My cool internal link with space <foo>`
like image 23
user2662404 Avatar answered Oct 04 '22 05:10

user2662404