This post is made for people who need to quickly pick a style of Pygments Styles . I wrote a script just to generate the list of code blocks each with different style, using itself as example code to highlight.
Note
This was first created on YJL --wiki with Pygments 1.5 at 2012/06/02 09:20:24-09:43:08.
Set
page background color to .
Pygments version: 2.0.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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 ()
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.