【问题标题】:How to underline text in reStructuredText?如何在 reStructuredText 中为文本加下划线?
【发布时间】:2012-01-31 17:34:24
【问题描述】:

当然,在网络上,下划线表示超链接,但是如果我需要不是超链接的下划线怎么办?

【问题讨论】:

    标签: restructuredtext


    【解决方案1】:

    我问了一个类似的问题here。试试这样:

    .. role:: underline
        :class: underline
    

    在文档中,可以这样应用:

    :underline:`This text is underlined`
    

    在您的css 文件中,您可以:

    .underline {
      text-decoration: underline;
    }
    

    这应该适用于 HTML 输出。但是,下划线故意不是 ReST 规范的一部分。见this link

    【讨论】:

      【解决方案2】:

      例如,您在 index.rst 文件中添加以下指令:

      .. role:: underline
          :class: underline
      

      在文档中,您将以下文字标为下划线:

      :underline:`This text is underlined`
      

      要为下划线类指定 css,如果您使用的是 sphinx_rtd_theme,则将一些 css 添加到文件夹 _themes/sphinx_rtd_theme/sphinx_rtd_theme/ 内的 layout.html 文件中,否则为您的默认主题目录:

      <style>
          .underline {
          text-decoration: underline;
        }
      </style>
      

      这将相应地设置您的 html 样式。

      下划线是 StructureText 的一部分,但不是 Sphinx 的 reStructuredText 规范的一部分,根据 David Ascher 在他的 2000-01-21 Doc-SIG 邮件列表帖子“Docstring 语法:一个非常修订的提案”中的引用:

      带有 _ 的下划线文本的标记是次优的。下划线 不应该从排版的角度使用(下划线是 设计用于在手稿中与排字员交流 文本应该是斜体——从来没有排版好的书使用过 下划线),并与双下划线 Python 变量冲突 名称(init 等),会被截断并 当不需要该效果时,加下划线。请注意,虽然完成 我认为标记会阻止截断('init') 文档字符串标记很像我想到的类型注释——它们应该 是可选的,最重要的是没有伤害。在这种情况下,下划线 标记确实有害。

      【讨论】:

        猜你喜欢
        • 2018-11-09
        • 2012-04-18
        • 2011-04-13
        • 1970-01-01
        • 1970-01-01
        • 2012-09-07
        • 2013-02-21
        • 2015-05-29
        • 2015-10-21
        相关资源
        最近更新 更多