如何在 reStructuredText 中设置指定链接内的文本格式?
具体来说,我希望从我的第一个代码生成以下 HTML:
<a href="http://docs.python.org/library/optparse.html"><tt>optparse.OptionParser</tt> documentation documentation</a>
结果应如下所示:
其中“optparse.OptionParser”部分采用固定宽度字体。
我试过了
```optparse.OptionParser`` <http://docs.python.org/library/optparse.html>`_
然而,这给了
<tt class="docutils literal">`optparse.OptionParser</tt> documentation <<a class="reference external" href="http://docs.python.org/library/optparse.html">http://docs.python.org/library/optparse.html</a>>`_
看起来像这样
``optparse.OptionParser
documentation <http://docs.python.org/library/optparse.html>\
_
最佳答案
这个结构:
Here you have |optparse.OptionParser|_.
.. |optparse.OptionParser| replace:: ``optparse.OptionParser`` documentation
.. _optparse.OptionParser: http://docs.python.org/library/optparse.html
生成此 HTML(添加了一些换行符):
<p>Here you have
<a class="reference external" href="http://docs.python.org/library/optparse.html">
<tt class="docutils literal"><span class="pre">optparse.OptionParser</span></tt> documentation</a>.
</p>
我意识到这并不完全是您所要求的,但也许已经足够接近了。另请参阅http://docutils.sourceforge.net/FAQ.html#is-nested-inline-markup-possible .
关于python-sphinx - 在 reStructuredText 中格式化链接中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4743845/