问题
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.
回答1:
Solution:
`My cool internal link <foo_>`_
回答2:
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.
回答3:
If John's solution doesn't work for you:
`My cool internal link<foo>`
回答4:
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>`
来源:https://stackoverflow.com/questions/36539740/internal-hyperlink-in-restructuredtext-with-customized-text