我需要类似的东西,经过多次实验,我找到了解决方法。请注意,这是一个糟糕的解决方案,但它确实有效。
简短的回答:
您需要将链接部分拆分为 |version| 的左侧和右侧并使用原始 html 以及|version|
。你的 .rst 看起来像这样:
Example of a link with version in it |link-pre|\ |version|\ |link-post|
.. |link-pre| raw:: html
<a href="some/location/name_of_file.
.. |link-post| raw:: html
.min.js">name_of_file.min.js</a>
长答案
我们需要克服几个障碍:
问题一:
现在,|version|
本质上是一个替代定义 http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#substitution-definitions。当您使用替代参考 http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#substitution-references在你的文档中,它必须以space
像这样|version|
.
所以即使在一个常规的 rsT 句子中,这不是一个链接,你也不能这样做name_of_file.|version|.min.js
。你需要做name_of_file.\ |version|.min.js
,即逃避space
with a \
问题 2:reST 中不支持嵌套内联标记:http://docutils.sourceforge.net/FAQ.html#is-nested-inline-markup-possible http://docutils.sourceforge.net/FAQ.html#is-nested-inline-markup-possible
所以你无法替代,|version|
, 在链接内\`name_of_file.|version|.min.js`\
。这就是为什么我们必须使用 raw-html 并将其分成几部分,并且我们创建了另外 2 个替换定义|link-pre|
and |link-post|
,它将在生成的输出中替换为其 raw-html。
我尝试使用内联:raw-html:
role http://docutils.sourceforge.net/docs/ref/rst/roles.html#raw但这并没有帮助,所以不幸的是,解决方案结果很冗长。