def colorize(text, color, lexer):
if pygments is None or not color:
return text
lexer_obj = pygments.lexers.get_lexer_by_name(lexer, ensurenl=False)
formatter_obj = pygments.formatters.get_formatter_by_name(
"terminal", bg=color)
colorized = pygments.highlight(text, lexer_obj, formatter_obj)
return colorized
评论列表
文章目录