pro*_*eek 28 html restructuredtext rst2html.py
如何在ReStructured Text中使用颜色?例如,**hello**
翻译成<strong>hello</strong>
.我怎样才能使重组(rst2html.py)翻译的东西 成<font color="####">text</font>
?
我想过..raw :: html,但它引入了空白行.我想插入没有空行的HTML标签.
pro*_*eek 40
我发现这种方法有效
首先,你有这个角色.
.. role:: red
An example of using :red:`interpreted text`
Run Code Online (Sandbox Code Playgroud)
它转化为如下.
<p>An example of using <span class="red">interpreted text</span></p>
Run Code Online (Sandbox Code Playgroud)
现在,你有了红色类,你可以使用CSS来改变颜色.
.red {
color:red;
}
Run Code Online (Sandbox Code Playgroud)
Ray*_*Luo 25
好吧,我现在是新用户,因此我无法评论其他人的答案,这要归功于stackoverflow的政策.https://meta.stackexchange.com/questions/51926/new-users-cant-ask-for-clarifications-except-as-answers
Sienkiew的答案很好,但我想纠正它的最后一句话.
有办法在RST文件中指定样式表.线索在Prosseek的原始帖子中,即.. raw ::指令.
我们可以在RST文件的开头添加以下行来指定其样式.
.. raw:: html
<style> .red {color:red} </style>
Run Code Online (Sandbox Code Playgroud)
sie*_*iew 10
这里的另一个答案暗示了我想要做的事情,但它假定了一些关于docutils中样式表的详细知识.这是一本食谱说明:
在您的RST文件中,声明角色一次,然后使用它:
.. role:: red
This text is :red:`colored red` and so is :red:`this`
Run Code Online (Sandbox Code Playgroud)
然后你需要一个样式表文件.首先,使用Python从docutils包中复制默认样式表:
python
import os.path
import shutil
import docutils.writers.html4css1 as h
shutil.copy(os.path.dirname(h.__file__)+"/html4css1.css","my.css")
Run Code Online (Sandbox Code Playgroud)
然后编辑my.css以在最后添加自定义:
.red {
color: red;
}
Run Code Online (Sandbox Code Playgroud)
创建名为"docutils.conf"的docutils配置文件:
[html4css1 writer]
stylesheet-path: my.css
embed-stylesheet: yes
Run Code Online (Sandbox Code Playgroud)
使用rst2html.py转换您的文档:
rst2html.py my_document.rst > my_document.html
Run Code Online (Sandbox Code Playgroud)
如果您不想使用docutils.conf,则可以在每次运行rst2html时指定样式表:
rst2html.py --stylesheet my.css my_document.rst > my_document.html
Run Code Online (Sandbox Code Playgroud)
AFAIK,无法在RST文件中指定样式表.