python-3.x - 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不支持为内联元素设置背景颜色(或边框)。在我们等待该功能实现的同时,我将讨论一般的内联文本样式。
这是您的 reStructuredText 片段的样式日志的相关部分:
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')
...
您要与选择器匹配的元素是具有等宽样式的MixedStyledText 。因为很难预测您是否需要匹配SingleStyledText或MixedStyledText元素,所以您应该始终使用更通用的StyledText作为选择器。
对于您的示例,样式表中的代码段定义将如下所示:
[inline-code: StyledText('monospaced', has_class='coder')]
base = monospaced
background_color = #fdffd6
对此有两点评论:
- 由于选择器中指定的样式比class的权重更大,因此您需要在has_class参数之外指定它,或者增加选择器的优先级。阅读选择器了解详情。
- 将样式的基础设置为等宽以继承标准等宽样式的属性。否则,您可能还需要设置字体和其他属性。
目前,rinohtype 将中止TypeError: background_color is not a supported attribute for TextStyle
. 请参阅TextStyle的文档以查看支持哪些样式属性。
如需进一步阅读,请参阅rinohtype 手册中的元素样式。
推荐阅读
- c# - 为什么降级我的框架版本然后再次升级允许此 .dll 正确加载?
- javascript - 如何过滤 S3 listObject 到一个确定的点?(与标记参数相反)
- azure-machine-learning-studio - 如何管理多个数据集 - Azure 机器学习
- c - 不了解 C 中静态 int 的功能
- c - dup2 没有切换到文件?
- cordova - 如何将 cordova 包裹在现有的 nuxt.js 项目中?
- javascript - 如何在幻灯片更改时更改 img 的 href
- facebook - 使用 Facebook API 获取用户组列表
- jquery - 无法在 Reactjs 中使用 Reel 旋转图像
- python - Python Elasticsearch 错误排序关键字字段