微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决sphinx, rinohtype: 内联代码背景颜色

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

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

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

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

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

理想情况下 that looks like this in stackoverflow

这是我自己尝试过的

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 可能是文本而不是段落。

解决方法

此时,rinohtype doesn'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,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,1,1) monospaced
      MixedStyledText('select')   None:None <inline>
        SingleStyledText('select')
      ...

要与选择器匹配的元素是 MixedStyledTextmonospaced 样式。因为很难预测您是否需要匹配 SingleStyledTextMixedStyledText 元素,所以您应该总是使用更通用的 StyledText 用于选择器

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

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

关于此的两点说明:

  • 由于选择器中指定的 style 的权重大于 class,因此除了 has_class 参数之外,您还需要指定它,或增加选择器的优先级。阅读Selectors了解详情。
  • 将样式的 base 设置为 monospaced 以继承标准 monospaced 样式的属性。否则,您可能还需要设置 字体 和其他属性。

现在,rinohtype 将使用 TypeError: background_color is not a supported attribute for TextStyle 中止。请参阅 TextStyle 的文档以了解支持哪些样式属性。

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。