Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@livibetter
Last active April 17, 2023 09:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save livibetter/2858976 to your computer and use it in GitHub Desktop.
Save livibetter/2858976 to your computer and use it in GitHub Desktop.
Rendering this script with all Pygments styles for showing on my wiki
#!/usr/bin/env python3
# Rendering this script with all Pygments styles for showing on my blog at
# http://blog.yjl.im/2015/08/pygments-styles-gallery.html
# Written by Yu-Jie Lin, Public Domain
import sys
import pygments
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import PythonLexer
from pygments.styles import get_all_styles
style_block = '<style>\n%s\n</style>'
with open(sys.argv[0]) as f:
# skip the heading comments
code = f.read().split('\n\n', 1)[1]
print('Pygments version: %s' % pygments.__version__)
print()
indent = lambda s: ' ' + s.replace('\n', '\n ')
for style in sorted(get_all_styles()):
class_tag = 'pygments-%s' % style
print('%s' % style)
print('%s' % ('=' * len(style)))
print()
formatter = HtmlFormatter(linenos=True, cssclass=class_tag, style=style)
print('.. raw:: html\n')
print(indent(style_block % formatter.get_style_defs('.' + class_tag)))
print(indent(highlight(code, PythonLexer(), formatter)))
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment