当我对带有代码块指令的ReStructured文本源运行rst2html.py时,它会将所有的跨度和类添加到ReStructured中的代码片段中,但是缺少对这些跨度进行着色的CSS。是否可以让RST在HTML文件中添加CSS链接或嵌入CSS?
发布于 2012-03-22 01:17:23
从Docutils0.9开始,你可以使用code directive。从本页的示例中可以看出:
.. code:: python
def my_function():
"just a test"
print 8/2或者,您可以使用Pygments进行语法突出显示。参见Using Pygments in ReST documents和this SO answer。
最后,您还可以在this或this blogpost中使用这些代码。
按照注释中的讨论更新,要获取Pygments使用的样式文件,请使用以下命令
pygmentize -S default -f html -a .highlight > style.css它将生成Pygments CSS样式文件style.css。
发布于 2013-06-13 05:00:26
在docutils 0.9和0.10中,使用code、code-block或sourcecode code都无关紧要。所有指令都被认为是code role。
此命令将生成可通过rst2html.py嵌入到html中的css。
pygmentize -S default -f html -a .code > syntax.css此命令将生成html:
rst2html.py --stylesheet=syntax.css in.txt > out.html默认情况下,rst2html.py使用comment、number、integer和operator等类名输出跨度。如果您在与源或/etc相同的目录中有docutils.conf,或者在~/.docutils中有
[parsers]
[restructuredtext parser]
syntax_highlight=short..。然后类名将是c、m、mi和o,它们与pygmentize生成的syntax.css相匹配。
See syntax-highlight in docutils documentation
https://stackoverflow.com/questions/9807604
复制相似问题