11

I can do this:

For more info, see Target_.

.. _Target: http://google.com

This correctly generates documentation that links Target to "http://google.com".

I want to replace Target with text that has spaces:

For more info, see Text With Space_.

.. _Text With Space: http://google.com

The above example generates documentation that incorrectly links "Space" to an unknown location. I want it to link "Text With Space" to "http://google.com".

How can I achieve this?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
mpenkov
  • 21,621
  • 10
  • 84
  • 126
  • In the Sphinx ReST context these are called [target](https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#hyperlink-targets) and [hyperlink](https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#hyperlinks), the term [anchor](https://www.w3.org/TR/html401/struct/links.html#h-12.1.3) is best applied strictly in the HTML context. – bad_coder Oct 04 '20 at 13:09

2 Answers2

15

From the Sphinx documentation for Hyperlinks, External links.

Use Link text <http://example.com/>_ for inline web links.

`Link text <http://example.com/>`_

You can also separate the link and the target definition (ref), like this:

This is a paragraph that contains `a link`_.

.. _a link: http://example.com/
Steve Piercy
  • 13,693
  • 1
  • 44
  • 57
6

You can do this:

.. |Target| replace:: Text With Space
.. _Target: http://google.com

For more info, see |Target|_
bad_coder
  • 11,289
  • 20
  • 44
  • 72
asrjarratt
  • 314
  • 6
  • 17