如何获取pygments格式化程序的css?

2024-04-28 17:20:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我用http://pygments.org/docs/quickstart/中的基本方式使用pygments

我的格式化程序是这样创建的:

                formatter = HtmlFormatter(cssclass="codehilite", linenos='table',
                    linenostart = lineno - len(excerpt) + 1,
                    hl_lines = important_lines,
                    style='colorful')           

它工作得很好,但是我没有从输出中得到任何CSS,只得到类。在哪里可以得到CSS?我想把它放在我的HTML文件的<head>中,这样就不需要单独的.css文件了。我从pygments.highlight()得到的就是:

^{pr2}$

Tags: 文件org程序httpdocspygmentsformatter方式
3条回答

Pygments使用样式类来生成CSS。在

http://pygments.org/docs/styles/

除非在格式化程序中使用full=True选项,否则可以获得如下CSS:

the_css = formatter.get_style_defs()

然后你可以把它插入到你的html标题中。在

您可以从GitHub上的pygments-css存储库获取预生成的CSS。 (提示由https://github.com/trentm/python-markdown2/wiki/fenced-code-blocks建议。)

相关问题 更多 >