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

后端 未结 2 992
终归单人心
终归单人心 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

    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
    

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

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

    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
    

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

提交回复
热议问题