Internal hyperlink in restructuredtext with custom

2020-07-02 10:43发布

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.

4条回答
够拽才男人
2楼-- · 2020-07-02 10:52

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楼-- · 2020-07-02 10:59

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

`My cool internal link<foo>`
查看更多
爷的心禁止访问
4楼-- · 2020-07-02 11:01

Solution:

`My cool internal link <foo_>`_
查看更多
Viruses.
5楼-- · 2020-07-02 11:11

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>`
查看更多
登录 后发表回答