在文档中,您可以引用此样式以获得蓝色单词。
请注意,此位是通用的,如果您在 html 或任何后端样式表中定义蓝色样式,则应生成蓝色文本。
Before blue.
.. role:: bluetext
I like color :bluetext:`blue`.
After blue.
生成的 pdf 包含彩色单词:
If you want to do this without being tied to html, try applying a different style than normal body text to your word.
In this example adapted from the rst2pdf manual, I apply the existing rubric style which is red in the backend that I am using:
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 --print-stylesheet
Continuing the example for a rst2pdf stylesheet, add this to your stylesheet to have a blue text style:
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.
Before blue.
.. role:: bluetext
I like color :bluetext:`blue`.
After blue.
.. role:: raw-html(raw)
:format: html
:raw-html:`<font color="blue">Blue word,</font>` And a word without color
Just a quick note because I landed here looking for something similar for html.
This works on Sphinx v2.0.1 for me. This uses the concept reported by @adam-matan but doesn't cause any formatting issues (i.e. the paragraph problem).
发布评论
评论(5)
在我的 Sphinx 支持的 网站 上,我使用了以下组合:
然后,在每个需要颜色的 rST 文件中,我首先在顶部手动导入
.special.rst
:或者使用
Sphinx 的
配置变量:conf.py
文件中的 rst_epilog然后每个角色都可以在纯 rST 语法中轻松使用:
更多详细信息参见 此页面(法语,抱歉)。
它非常适合 html 输出(和类似 html),但不适用于 PDF。请参阅上面的第一个答案以生成带颜色的 PDF。
On my Sphinx-powered website, I use a combination of:
Then, in every rST file where I need colors, I first import
.special.rst
at the top, either manually:Or with the
rst_epilog
configuration variable in Sphinx'sconf.py
file:And then each role can be used easily in pure rST syntax:
More details are given on this page (in French, sorry).
It works perfectly well for html output (and html-like), but not for PDF. Refer to the first answer above for producing a PDF with colors.
Sphinx 已经通过
支持颜色
s5defs.txt
标准定义文件< /em> 用于 包含(但缺少 CSS 文件):创建/附加此文本到
rst_prolog
sphinx 配置,在您的 docs/conf.py 文件中:
<前><代码> rst_prolog = """
.. 包括::
”“”
按照Sphinx 的说明 添加带有颜色的 css
(例如采用
hack.css
来自@Næreen的回答):将你的css文件放入例如
_static/css中/s4defs-roles.css
;将其路径附加到
shtml_css_files< /code>
sphinx 配置:
然后您可以使用:
Sphinx already supports colors with the
s5defs.txt
standard definition file intended for inclusion (but is missing the CSS file):Create/append this text to the value of
rst_prolog
sphinx configuration, in your
docs/conf.py
file:Follow Sphinx's instructions to add a css with the colors
(e.g. adopt the
hack.css
from @Næreen's answer):Place your css file into e.g.
_static/css/s4defs-roles.css
;append it's path into
shtml_css_files
sphinx configuration:You may then use:
如果您想在不依赖 html 的情况下执行此操作,请尝试对您的单词应用与普通正文文本不同的样式。
在这个改编自 rst2pdf 手册的示例中,我应用了现有的 rubric 样式,该样式在我正在使用的后端中为红色:
单词的实际外观将取决于您选择的样式在生成时使用的样式表中的定义方式你的文件。
如果您想要蓝色文本,请创建蓝色文本样式并从普通文本样式派生它。
样式表是特定于后端的,您可能使用默认值。
要打印 rst2pdf.py 的默认值,请执行以下操作(来自 rst2pdf 手册):
继续 rst2pdf 样式表的示例,将其添加到样式表中以获得蓝色文本样式:
在文档中,您可以引用此样式以获得蓝色单词。
请注意,此位是通用的,如果您在 html 或任何后端样式表中定义蓝色样式,则应生成蓝色文本。
生成的 pdf 包含彩色单词:
If you want to do this without being tied to html, try applying a different style than normal body text to your word.
In this example adapted from the rst2pdf manual, I apply the existing rubric style which is red in the backend that I am using:
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):
Continuing the example for a rst2pdf stylesheet, add this to your stylesheet to have a blue text style:
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.
The generated pdf has the coloured words:
这可行,但会将 HTML 保留在单独的段落中。
如果有人有更好的答案,我会接受。
This works, but leaves the HTML in a separate paragraph.
If anyone has a better answer, I will accept it.
只是简单说明一下,因为我来到这里寻找类似
html
的内容。这对我来说适用于 Sphinx v2.0.1。这使用了@adam-matan 报告的概念,但不会导致任何格式问题(即段落问题)。
参考:reStructuredText 指令
Just a quick note because I landed here looking for something similar for
html
.This works on Sphinx v2.0.1 for me. This uses the concept reported by @adam-matan but doesn't cause any formatting issues (i.e. the paragraph problem).
reference: reStructuredText Directives