sphinx, rinohtype: 内联代码背景颜色

sphinx, rinohtype: inline code background color

我们如何更改内联代码的背景颜色。

我在重组文本中使用内联代码的一种方式是:

.. role::sql(code)
    :language: sql

You can use the query :sql:`select * from table` to execute...

当使用rst2pdf时,它输出漂亮的语法高亮和与代码块相同的背景颜色。我们如何使用 rinohtype?

实现相同的效果

最好的东西that looks like this in Whosebug

这是我自己试过的

stylesheet:

[code-paragraph: Paragraph(has_class="coder")]
background_color = #fdffd6

and rst:

.. role::sql(code)
    :language: sql
    :class: coder

You can use the query :sql:`select * from table` to execute...

但这没有用,因为 role 可能是文本而不是段落。

此时,rinohtypedoesn't support setting a background color (or a border) for inline elements。在我们等待该功能实现的同时,我将大体讨论内联文本的样式。

这是您的 reStructuredText 片段的 stylelog 的相关部分:

Paragraph('You can use the query select * f...')   inline_code.rst:6 <paragraph>
     > (0,0,0,0,2) body
  MixedStyledText('You can use the query select * f...')
    SingleStyledText('You can use the query ')
    MixedStyledText('select * from table', style='monospaced')   None:None <literal>
         > (0,0,1,0,1) monospaced
      MixedStyledText('select')   None:None <inline>
        SingleStyledText('select')
      ...

您要与选择器匹配的元素是具有 monospaced 样式的 MixedStyledText。因为很难预测您是否需要匹配 SingleStyledTextMixedStyledText 元素,所以您应该 始终使用更通用的 StyledText 选择器.

对于您的示例,样式 sheet 中的 code-paragraph 定义将如下所示:

[inline-code: StyledText('monospaced', has_class='coder')]
base = monospaced
background_color = #fdffd6

关于此的两点说明:

  • 由于选择器中指定的styleclass的权重大,需要在除了 has_class 参数,或者增加选择器的优先级。阅读 Selectors 了解详情。
  • 将样式的base设置为monospaced继承标准monospaced的属性] 风格。否则,您可能还需要设置 typeface 和其他属性。

目前,rinohtype 将中止 TypeError: background_color is not a supported attribute for TextStyle。请参阅 TextStyle 的文档以查看支持哪些样式属性。

如需进一步阅读,请参阅 rinohtype 手册中的 Element Styling