Internal hyperlink in restructuredtext with customized text

只谈情不闲聊 提交于 2020-01-01 08:04:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!