如何让 rst2html.py 包含用于语法高亮显示的 CSS? [英] How can I get rst2html.py to include the CSS for syntax highlighting?

查看:57
本文介绍了如何让 rst2html.py 包含用于语法高亮显示的 CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我针对我的 ReStructured Text 源运行 rst2html.py 时,使用它的代码块指令,它将所有的跨度和类添加到 HTML 中的代码位,但不存在实际为这些跨度着色的 CSS.是否可以让 RST 添加 CSS 链接或将 CSS 嵌入 HTML 文件中?

When I run rst2html.py against my ReStructured Text source, with its code-block directive, it adds all the spans and classes to the bits of code in the HTML, but the CSS to actually colorize those spans is absent. Is it possible to get RST to add a CSS link or embed the CSS in the HTML file?

推荐答案

从 Docutils 0.9 开始,您可以使用 code 指令.来自此页面上的示例:

As of Docutils 0.9 you could use the code directive. From the example on this page:

.. code:: python

 def my_function():
     "just a test"
     print 8/2

或者,您可以使用 Pygments 进行语法高亮显示.请参阅在 ReST 文档中使用 Pygments这个 所以答案.

Alternatively, you can use Pygments for syntax highlighting. See Using Pygments in ReST documents and this SO answer.

最后,您还可以使用this这篇 博文.

Finally, you could also use the code in this or this blogpost.

更新 正如评论中所讨论的,要获取 Pygments 使用的样式文件,请使用命令

Update As discussed in the comments, to get the style file used by Pygments use the command

pygmentize -S default -f html -a .highlight > style.css

这将生成 Pygments CSS 样式文件 style.css.

which will generate the Pygments CSS style file style.css.

这篇关于如何让 rst2html.py 包含用于语法高亮显示的 CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆