Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restructured text (rst) http links underscore ('__' vs '_' use)

With restructured text, I've seen both these used:

`Some Link <http://www.some.com>`_
`Some Link <http://www.some.com>`__

Both generate the same output from Sphinx,

Whats the difference between using _ or a double underscore __ for http URL links?

Why would you one over another?

like image 527
ideasman42 Avatar asked Dec 11 '14 10:12

ideasman42


People also ask

What is rst language?

RST, Restructured Text, is a file format created by the Python community to write documentation. It is part of Docutils. RST is a markdown language like HTML but is much more lightweight and easier to read.

How do you use a sphinx code block?

Literal code blocks (ref) are introduced by ending a paragraph with the special marker :: . The literal block must be indented (and, like all paragraphs, separated from the surrounding ones by blank lines): This is a normal text paragraph.


1 Answers

In short, if its a one-off (anonymous) URL which you don't intend to reference, use double underscore.

In practice you could use either in most cases, they generate the same HTML output for example.

However, using single underscores for links means that by default you're creating a reference target - which could conflict with other references of the same name.

So this for example will warn:

.. _Thing:

Title
=====

Text with `Thing <http://link.com>`_.
WARNING: Duplicate target name, cannot be used as a unique reference: "thing".

While this could be overlooked in most cases, it could make for confusing situations especially for anyone inexperienced with reStructuredText. So you may prefer to avoid this entirely only defining targets when that is your intention.


According to: http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#anonymous-hyperlinks

With a single trailing underscore, the reference is named and the same target URI may be referred to again. With two trailing underscores, the reference and target are both anonymous, and the target cannot be referred to again. These are "one-off" hyperlinks.

There are examples on the page links.

like image 65
ideasman42 Avatar answered Oct 15 '22 10:10

ideasman42