python-sphinx - 在 reStructuredText 中格式化链接中的文本

标签 python-sphinx restructuredtext

如何在 reStructuredText 中设置指定链接内的文本格式?

具体来说,我希望从我的第一个代码生成以下 HTML:

<a href="http://docs.python.org/library/optparse.html"><tt>optparse.OptionParser</tt> documentation documentation</a>

结果应如下所示:

optparse.OptionParser documentation

其中“optparse.OptionParser”部分采用固定宽度字体。

我试过了

```optparse.OptionParser`` <http://docs.python.org/library/optparse.html>`_

然而,这给了

<tt class="docutils literal">`optparse.OptionParser</tt> documentation &lt;<a class="reference external" href="http://docs.python.org/library/optparse.html">http://docs.python.org/library/optparse.html</a>&gt;`_

看起来像这样

``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/

相关文章:

internationalization - 在单独的目录中构建已翻译的 Sphinx 文档

python - 使 Sphinx 在 PDF 输出中生成未分类的代码块

python-sphinx - 重组文本链接到其他第一个文件菜单 anchor

python-sphinx - 如何在 Sphinx reStructuredText 中向等宽文本添加前导/尾随空格

python-sphinx - 如何更改通过下载角色引用的文件的文件路径以不使用散列文件夹?

python-sphinx - Sphinx/reStructuredText 中表格的编辑器?

html - 为什么图像缩放在生成 html 文件时在 reStructuredText 中不起作用?

python - 如何查找所有支持的 python、reStructuredText 字段名称?

python - 在windows上安装python/sphinx环境?