How can I get rst2html.py to include the CSS for syntax highlighting?

后端 未结 2 971
终归单人心
终归单人心 2021-01-12 18:02

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

2条回答
  •  迷失自我
    2021-01-12 18:32

    In docutils 0.9 and 0.10 it doesn't mattter whether you use code, code-block or sourcecode. All directives are considered code role.

    This command will generate css that can embedded into html by rst2html.py.

    pygmentize -S default -f html -a .code > syntax.css
    

    This command will generate the html:

    rst2html.py --stylesheet=syntax.css in.txt > out.html
    

    By default, rst2html.py outputs spans with class names like comment, number, integer, and operator. If you have a docutils.conf either in the same directory as the source, or /etc, or in ~/.docutils with

    [parsers]
    [restructuredtext parser]
    syntax_highlight=short
    

    ... then the class names will be c, m, mi, and o which matches syntax.css generated by pygmentize.

    See syntax-highlight in docutils documentation

提交回复
热议问题