96

Here is what I would like to do:

1. `link <http://www.google.com>`__
2. `link <http://www.yahoo.com>`__

To obtain:

<ol>
<li><a href="http://www.google.com">link</a></li>
<li><a href="http://www.yahoo.com">link</a></li>
</ol>

The context is a list of publications, where I want them all to have a link marked "DOI" at the end.

However, this seems to fails with:

<string>:3: (WARNING/2) Duplicate explicit target name: "doi".

The exact error seems to depend on the version of docutils that I use, but they've all failed.

Is there a way to generate multiple links with the same text in restructured text?

luispedro
  • 6,934
  • 4
  • 35
  • 45
  • Possible duplicate of [How to deal with duplicate target names in reStructuredText?](https://stackoverflow.com/questions/4843052/how-to-deal-with-duplicate-target-names-in-restructuredtext) – drammock Feb 06 '19 at 20:49

3 Answers3

163

The warning

(WARNING/2) Duplicate explicit target name:foo

occurs when you use the same text for two different links in "Named hyperlink references":

`Foo <http://example.org>`_
`Foo <http://example.com>`_

To circumvent it, use anonymous hyperlink references with double underscores:

`Foo <http://example.org>`__
`Foo <http://example.com>`__

This works without a warning on docutils 0.8.1.

cweiske
  • 30,033
  • 14
  • 133
  • 194
  • I think this is true only on more recent versions. I can confirm that I now got this result (which is, arguably, the better result). I am accepting this new answer. – luispedro Dec 28 '12 at 10:30
16

I think you'll want to use anonymous hyperlinks:

1. `link`__
2. `link`__

__ http://www.google.com
__ http://www.yahoo.com

Keep in mind that the order they're referred to in the document is important. More information can be found here.

Jesse
  • 4,814
  • 1
  • 18
  • 9
4

Seems like you need a newline and two underscores.

This is what I do:

What is that Process object good for? `(html)
<process.html>`__
`(html) 
<other.process.rst>`__

to obtain:

What is that Process object good for? 
<a class="reference external" href="process.html">(html)</a>
<a class="reference external" href="process.rst">(html)</a>
User
  • 14,131
  • 2
  • 40
  • 59