Skip to content

Instantly share code, notes, and snippets.

@data-goblin
Created May 3, 2022 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save data-goblin/6b944a251fe982c0aac3a803ed0734b5 to your computer and use it in GitHub Desktop.
Save data-goblin/6b944a251fe982c0aac3a803ed0734b5 to your computer and use it in GitHub Desktop.
Example of using pygments to format Python code with default configuration
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter
code = """
print('hello world')
"""
result = highlight(code, PythonLexer(), HtmlFormatter())
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment