got*_*nes 68 restructuredtext python-sphinx
如何在reStructuredText中的表示链接中格式化文本?
具体来说,我希望从我的第一个生成以下HTML:
<a href="http://docs.python.org/library/optparse.html"><tt>optparse.OptionParser</tt> documentation documentation</a>
Run Code Online (Sandbox Code Playgroud)
结果应如下所示:
其中"optparse.OptionParser"部分是固定宽度字体.
我试过了
```optparse.OptionParser`` <http://docs.python.org/library/optparse.html>`_
Run Code Online (Sandbox Code Playgroud)
然而,这给了
<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>>`_
Run Code Online (Sandbox Code Playgroud)
看起来像这样
``optparse.OptionParser
documentation <http://docs.python.org/library/optparse.html>\_
mzj*_*zjn 77
这个结构:
Here you have |optparse.OptionParser|_.
.. |optparse.OptionParser| replace:: ``optparse.OptionParser`` documentation
.. _optparse.OptionParser: http://docs.python.org/library/optparse.html
Run Code Online (Sandbox Code Playgroud)
生成此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>
Run Code Online (Sandbox Code Playgroud)
我知道这是不是正是你问什么,但也许这是足够接近.另见http://docutils.sourceforge.net/FAQ.html#is-nested-inline-markup-possible.
你试过intersphinx吗?使用该扩展,以下标记:
:py:class:`optparse.OptionParser`
Run Code Online (Sandbox Code Playgroud)
产生这个 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>
Run Code Online (Sandbox Code Playgroud)
使用 Python 2.6 和 Sphinx 1.0.5 进行测试。
取自 mzjn 引用的同一常见问题解答页面:
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>
Run Code Online (Sandbox Code Playgroud)
理论上应该可以用 RST 来做一些复杂的事情。
| 归档时间: |
|
| 查看次数: |
6550 次 |
| 最近记录: |