【问题标题】:How to deal with duplicate target names in reStructuredText?如何处理 reStructuredText 中重复的目标名称?
【发布时间】:2011-06-18 02:26:13
【问题描述】:

例子:

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

由于Download指向不同的url,docutilus给出了这个错误报告:

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

在markdown中,我可以为这两个Download指定不同的id:

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

如何在 reStructuredText 中做类似的事情?

【问题讨论】:

    标签: restructuredtext


    【解决方案1】:

    选项一

    正如@mzjn 指出的,让目标名称更清晰:

    `Download foo`_
    
    .. _Download foo: http://example.com/foo
    
    `Download bar`_
    
    .. _Download bar: http://example.com/bar
    

    选项二

    来自docutils-user maillist

    使用匿名超链接:

    Download__
    
    
    __ http://example.com/foo
    
    
    Download__
    
    __ http://example.com/bar
    

    【讨论】:

      【解决方案2】:

      据我从the documentation 得知,ReST 文档中的引用名称共享一个公共命名空间,因此它们必须是唯一的。我想不出比这更好的了:

      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
      

      【讨论】:

      • 那么这个呢? Our product integrates with `sphinx`_ (omit a lot of paragraphs) Powered by `sphinx`_ ,其中第一个sphinx 链接到sphinx 搜索主页,第二个sphinx 链接到sphinx 文档生成器主页。
      猜你喜欢
      • 2021-02-22
      • 2018-12-21
      • 1970-01-01
      • 1970-01-01
      • 2020-04-28
      • 2020-08-17
      • 2010-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多