格式化 reStructuredText 中链接中的文本 [英] Format text in a link in reStructuredText

查看:47
本文介绍了格式化 reStructuredText 中链接中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do you format text within a denoted link in reStructuredText?

具体来说,我希望从我的 rst 生成以下 HTML:

Specifically, I wish to generate the following HTML from my rst:

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

结果应该是这样的:

optparse.OptionParser文档

其中optparse.OptionParser"部分是等宽字体.

where the "optparse.OptionParser" portion is in fixed-width font.

我试过了

```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文件<http://docs.python.org/library/optparse.html>\_

``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(添加了一些换行符):

produces this HTML (some linebreaks added):

<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.

I realize that this is not exactly what you asked for, but maybe it's close enough. See also http://docutils.sourceforge.net/FAQ.html#is-nested-inline-markup-possible.

这篇关于格式化 reStructuredText 中链接中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆