【问题标题】:Bold italic in ReStructuredTextReStructuredText 中的粗斜体
【发布时间】:2012-08-16 09:51:17
【问题描述】:

我正在使用 ReStructuredText (ReST) 格式编写一些文档,以便稍后使用 Sphinx 生成网页,但我找不到编写一些“粗斜体”文本的方法。

有所谓的“强调”(斜体)和“强调”(粗体)文本的标记。它们分别是*italic text***bold text**。我还在一些关于这种格式的文档中读到,这些格式标记不能简单地“嵌套”。 IE。 ***text***(或** *text* **)不会产生粗斜体文本。

仍然可能应该有某种方法来生成用粗体和斜体标记强调的文本,因为以这种方式标记文本片段是一种普遍的做法。

【问题讨论】:

    标签: python-sphinx restructuredtext


    【解决方案1】:

    虽然 Markdown 支持嵌套粗体和斜体,但 reStructuredText 不支持(这是 Markdown 更强大的罕见情况之一,因为无法在 reStructuredText 中表示粗斜体)。

    https://gist.github.com/1855764

    【讨论】:

    • 罕见的案例之一,但很重要!
    • 不,这是不正确的(“无法在 reStructuredText 中表示粗斜体”)。实际上有几种不同的方法(正如其他受访者所指出的那样)。我同意 - 不过 - 不幸的是,这不是通过字符串两侧的三重 * 来支持“开箱即用”的......
    【解决方案2】:

    HTML 输出配方。

    my.rst:

    .. role:: red
      :class: red
    
    .. role:: bolditalic
      :class: bolditalic
    
    :red:`WARNING` :bolditalic:`Don't be stupid!`
    

    my.css:

    .red { color: red; }
    .bolditalic {
      font-weight: bold;
      font-style: italic;
    }
    

    构建者:

    rst2html --strip-comments --halt warning --stylesheet=my.css my.rst my.html
    

    【讨论】:

      【解决方案3】:

      在 sphinx 中,这可以通过自定义角色实现:您在 css 中创建一个样式,并创建一个指向该样式的角色。这是带下划线文本的完整工作示例:sphinx-dev thread

      编辑

      这是一个很好的例子:ReST strikethrough

      编辑 2

      那个 sphinx-dev 链接不再可用,所以这里是要点,它与上面的删除线链接非常相​​似:

      CSS:

      span.underlined {
        text-decoration: underline;
      }
      

      在 RST 中注册角色:

      .. role:: underlined
         :class: underlined
      

      以后用它

      :underlined:`test`
      

      所有这些都可以在一个 RST 文档中:

      .. raw:: html
      
         <style type="text/css">
           span.underlined {
             text-decoration: underline;
           }
         </style>
      
      .. role:: underlined
         :class: underlined
      
      :underlined:`test`
      

      用:: 测试它

      rst2html5.py test01.rst test01.html
      

      【讨论】:

      • 不幸的是 sphinx-dev 线程链接重定向回the group
      猜你喜欢
      • 2012-09-28
      • 1970-01-01
      • 1970-01-01
      • 2021-02-19
      • 1970-01-01
      • 2011-07-18
      • 2012-03-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多