如何自定义pygments的输出?

Geo*_*Geo 1 html css python pygments

如果我通过pygments运行python源文件,它会输出html代码,其元素类属于某些CSS文件pygments正在使用.样式属性是否可以包含在输出的html中,这样我就不必提供CSS文件了?

Geo*_*Geo 5

通过将noclasses属性设置为True,将仅生成内联样式.这是一个完成工作的片段:


formatter = HtmlFormatter(style=MyStyle)
formatter.noclasses = True
print highlight(content,PythonLexer(),formatter)
Run Code Online (Sandbox Code Playgroud)