Generating an external link in Sphinx

24,612

See the reStructuredText documentation. It can be done either with a named reference:

Test hyperlink: SO_.
    
.. _SO: https://stackoverflow.com/

Or with:

Test hyperlink: `Stack Overflow home <SO>`_.
    
.. _SO: https://stackoverflow.com/

Or with an embedded URI:

Test hyperlink: `Stack Overflow home <https://stackoverflow.com/>`_.
Share:
24,612
Anton Arhipov
Author by

Anton Arhipov

Developer Advocate in Kotlin team at JetBrains. People often ask me about IntelliJ IDEA, TeamCity, Kotlin, and sometimes about Java and bytecode too. Former Product Manager of JRebel and XRebel at ZeroTurnaround.

Updated on April 03, 2022

Comments

  • Anton Arhipov
    Anton Arhipov about 2 years

    I'd like to link to some URL in my Sphinx docs:

    <a href="http://some.url">blah</a>
    

    I have found something similar in the docs: http://sphinx-doc.org/ext/extlinks.html - but it is rather about replacing the custom syntax with the link, by convention. Instead, I just want to generate a link to external web resource.

  • Michael Goerz
    Michael Goerz over 6 years
    How about multiple words in the link text?
  • Anton Arhipov
    Anton Arhipov over 6 years
    @MichaelGoerz in the second example, it contains multiple words in the link text, doesn't it?
  • Michael Goerz
    Michael Goerz over 6 years
    Yes, but for the case of the named reference, it took me quite a while to figure out that the correct syntax is "` Stack Overflow_ `" (without the spaces -- can't properly format this in a comment) and then " .. _Stack Overflow: stackoverflow.com". It's not in the documentation.
  • Ove
    Ove over 6 years
    I think the documentation does say that you can put the text in backquotes (with the underscore outside), i.e. `Stack Overflow`_, but it's shown in the "inline markup" section of the quick reference, not in the hyperlinking section (unless you check the specification itself).
  • Dushyant Joshi
    Dushyant Joshi almost 5 years
    @AntonArhipov, is it possible to append string to href like /docs/Orders.html instead of docs/Orders.html? I m very much new to python
  • drevicko
    drevicko almost 4 years
    Can we decorate the link text (eg: use verbatim) with this trick
  • Kermit
    Kermit over 3 years
    be aware, without the 'http://' or 'https://' it was treating mine as internal links!
  • Asmoox
    Asmoox over 3 years
    How to add many links with the first method? I try different ways with double dots before every URL definition or not, but PyCharm keeps ignoring it.