当我对我的ReStructured Text源运行rst2html.py时,使用它的代码块指令,它将所有的跨度和类添加到HTML中的代码位,但是实际着色这些跨度的CSS是不存在的.是否可以让RST添加CSS链接或将CSS嵌入HTML文件中?
从Docutils 0.9开始,您可以使用该code指令.从此页面上的示例:
.. code:: python
def my_function():
"just a test"
print 8/2
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用Pygments进行语法突出显示.请参阅ReST文档中的使用Pygments和此 SO答案.
更新如评论中所述,要获取Pygments使用的样式文件,请使用该命令
pygmentize -S default -f html -a .highlight > style.css
Run Code Online (Sandbox Code Playgroud)
这将生成Pygments CSS样式文件style.css.
在docutils 0.9和0.10中,无论您使用代码,代码块还是源代码,它都不会消失.所有指令都被视为代码角色.
此命令将生成可以通过rst2html.py嵌入到html中的css.
pygmentize -S default -f html -a .code > syntax.css
Run Code Online (Sandbox Code Playgroud)
这个命令会生成html:
rst2html.py --stylesheet=syntax.css in.txt > out.html
Run Code Online (Sandbox Code Playgroud)
默认情况下,rst2html.py输出与跨越类的名字,如comment,number,integer,和operator.如果你有一个docutils.conf无论是在相同的目录为源,或者/etc,或~/.docutils与
[parsers]
[restructuredtext parser]
syntax_highlight=short
Run Code Online (Sandbox Code Playgroud)
......那么类的名称将是c,m,mi,和o它匹配syntax.css的产生pygmentize.
请参阅docutils文档中的syntax-highlight
| 归档时间: |
|
| 查看次数: |
3658 次 |
| 最近记录: |