如何使两个链接中的同一文本与重组后的文本相同?

2024-05-16 06:53:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我想做的是:

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

获得:

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

上下文是一个出版物列表,我希望它们在最后都有一个标记为“DOI”的链接。

然而,这似乎失败了:

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

确切的错误似乎取决于我使用的docutils的版本,但它们都失败了。

有没有一种方法可以在重组后的文本中生成具有相同文本的多个链接?


Tags: 标记文本comhttp列表链接wwwgoogle
3条回答

好像你需要一个换行符和两个下划线。

我就是这么做的:

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

获得:

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>

我想您需要使用匿名超链接:

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

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

请记住,文档中引用它们的顺序很重要。可以找到更多信息here

警告

(WARNING/2) Duplicate explicit target name:foo

对“命名超链接引用”中的两个不同链接使用同一文本时发生:

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

要绕过它,请使用带双下划线的匿名hyperlink references

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

在docutils 0.8.1上,此操作不会发出警告。

相关问题 更多 >