在reStructuredText中的链接中设置文本的格式
你如何格式化reStructuredText中指定的链接文本?
具体来说,我希望从我的第一个生成以下的HTML:
<a href="http://docs.python.org/library/optparse.html"><tt>optparse.OptionParser</tt> documentation documentation</a> 结果应该是这样的:
optparse.OptionParser文档
其中“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 。
你有没有试过intersphinx ? 使用该扩展名,以下标记:
 :py:class:`optparse.OptionParser` 
产生这个HTML:
 <a class="reference external" href="http://docs.python.org/2.6/library/optparse.html#optparse.OptionParser" title="(in Python v2.6)"><tt class="xref py py-class docutils literal"><span class="pre">optparse.OptionParser</span></tt></a> 
经过Python 2.6和Sphinx 1.0.5的testing。
从mzjn引用的同一个FAQ页面:
 The "raw" directive can be used to insert raw HTML into HTML output: Here is some |stuff|. .. |stuff| raw:: html <em>emphasized text containing a <a href="http://example.org">hyperlink</a> and <tt>inline literals</tt></em> 
理论上可以用RST做不了的复杂事情。
如果你想本质上做HTML / CSS的等价物
 <span class="red">This is red text</span> 
在使用Sphinx的reStructuredText中,你可以通过创build一个angular色来做到这一点:
 .. role:: red 
然后你这样使用它:
 :red:`This is red text` 
在上面一行的末尾应该只有一个刻度线。 你当然必须拥有
 .red { color: red } 
在你的CSS文件中。