Search code examples
python-sphinxrestructuredtext

How do I prevent sphinx from making a url a hyperlink?


In my docs, I occasionally use "garbage" urls as examples and don't want them to be hyperlinks to nowhere. Is there any syntax to make these urls not hyperlinks?


Solution

  • There are three ways to format such URLs so that they are not hyperlinks. The first is to treat sample URLs like other code samples and enclose them in backquotes, like this:

    open ``http://www.example.com`` in a web browser
    

    The second is to use the Sphinx :samp: role, like this:

    open :samp:`http://www.example.com` in a web browser
    

    The :samp: role lets you have variable parts emphasized. So, for example, you could indicate a user-selected port number, like this:

    open :samp:`http://www.example.com:{port}` in a web browser
    

    and the word port would appear emphasized and braces omitted.

    The last option is to prepend the sample URL with a backslash, like this:

    open \http://www.example.com in a web browser
    

    The URL will appear as ordinary text, without being a link or having any special formatting.