作者:我是阿冫轶 | 来源:互联网 | 2023-05-17 09:03
Isthereawaytosetthecolorofsinglewords(orcharacters)insphinx?Imprettysuretheresho
Is there a way to set the color of single words (or characters) in sphinx? I'm pretty sure there should be some markup tag, like HTML's font
tag.
有没有办法在sphinx中设置单个单词(或字符)的颜色?我很确定应该有一些标记标记,比如HTML的字体标记。
3 个解决方案
10
If you want to do this without being tied to html, try applying a different style than normal body text to your word.
如果你想这样做而不依赖于html,尝试将不同于普通正文文本的样式应用到你的单词中。
In this example adapted from the rst2pdf manual, I apply the existing rubric style which is red in the backend that I am using:
在这个改编自rst2pdf手册的例子中,我应用了我正在使用的后端红色的现有量规样式:
Before red.
.. role:: rubric
I like color :rubric:`rubric`.
After red.
The actual look of the word will depend on how the style you choose is defined in the stylesheet that you use when generating your document. If you want blue text, make a blue text style and derive it from the normal text style. The stylsheet is backend-specific and you may be using the default. To print the default for rst2pdf.py, do this (from the rst2pdf manual):
该单词的实际外观取决于您在生成文档时使用的样式表中如何定义所选样式。如果您想要蓝色文本,请创建蓝色文本样式并从普通文本样式派生。样式表是特定于后端的,您可能正在使用默认值。要打印rst2pdf.py的默认值,请执行此操作(从rst2pdf手册):
rst2pdf --print-stylesheet
Continuing the example for a rst2pdf stylesheet, add this to your stylesheet to have a blue text style:
继续使用rst2pdf样式表的示例,将其添加到样式表以使其具有蓝色文本样式:
bluetext:
parent: bodytext
textColor: blue
In the document you can reference this style to get a blue word. Note this bit is generic, and should make blue text if you define a blue style in your html or whatever backend's stylesheet.
在文档中,您可以引用此样式以获得蓝色单词。请注意,这个位是通用的,如果在html或后端的样式表中定义蓝色样式,则应该生成蓝色文本。
Before blue.
.. role:: bluetext
I like color :bluetext:`blue`.
After blue.
The generated pdf has the coloured words:
生成的pdf具有彩色字: