pip install Pygments python from pygments import highlight from pygments.lexers import PythonLexer from pygments.formatters import HtmlFormatter code = ''' def say_hello(): print("Hello, world!") say_hello() ''' lexer = PythonLexer() formatter = HtmlFormatter() highlighted_code = highlight(code, lexer, formatter) print(highlighted_code) python from pygments.lexers import JavascriptLexer python from pygments.formatters import RtfFormatter python with open('highlighted_code.html', 'w') as file: file.write(highlighted_code) python from pygments.styles import get_style_by_name style = get_style_by_name('tango') formatter = HtmlFormatter(style=style)


上一篇:
下一篇:
切换中文