How to deal with duplicate target names in reStruc

2020-06-23 07:28发布

问题:

Example:

foo is a tool used to do foo.

Download_

.. _Download: http://example.com/foo

blah blah blah (omit a lot of paragraphs)

bar is another tool to do bar.

Download_

.. _Download: http://example.com/bar

Since Download points to different urls, docutilus gives this error report:

Duplicate target name, cannot be used as a
unique reference: "Download".

While in markdown, I can specify different id for this two Download:

[Download][download-foo]
[download-foo]: http://example.com/foo
[Download][download-bar]
[download-bar]: http://example.com/bar

How can I do similar things in reStructuredText?

回答1:

Option one

As @mzjn pointed out, make target name more clear:

`Download foo`_

.. _Download foo: http://example.com/foo

`Download bar`_

.. _Download bar: http://example.com/bar

Option two

From docutils-user maillist:

Use Anonymous hyperlink:

Download__


__ http://example.com/foo


Download__

__ http://example.com/bar


回答2:

As far as I can tell from the documentation, reference names in ReST documents share a common namespace, so they must be unique. I can't think of anything better than this:

foo is a tool used to do foo.

`Download foo`_

.. _Download foo: http://example.com/foo

blah blah blah (omit a lot of paragraphs)

bar is another tool to do bar.

`Download bar`_

.. _Download bar: http://example.com/bar