How to deal with duplicate target names in reStructuredText?

亡梦爱人 提交于 2019-12-05 02:52:05

问题


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


来源:https://stackoverflow.com/questions/4843052/how-to-deal-with-duplicate-target-names-in-restructuredtext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!