4949try :
5050 import pygments .formatters
5151 import pygments .lexers
52+ import pygments .style
5253 import pygments .styles
54+ import pygments .token
5355except ImportError :
5456 # we can work without pygments, but we won't get colors
5557 pygments = None
5658
5759import common
5860
5961
62+ if pygments is not None :
63+ class TutorialStyle (pygments .style .Style ):
64+ background_color = '#111111'
65+ styles = {
66+ pygments .token .Comment : 'italic #336666' ,
67+ pygments .token .Keyword : 'bold #6699cc' ,
68+ pygments .token .Name .Builtin : '#9966ff' ,
69+ pygments .token .String : '#ffff33' ,
70+ pygments .token .Name .Exception : 'bold #ff0000' ,
71+ }
72+
73+
6074HTML_TEMPLATE = """\
6175 <!DOCTYPE html>
6276<html>
@@ -129,9 +143,9 @@ def block_code(self, code, lang=None):
129143 if lang == 'python' and pygments is not None :
130144 # we can highlight it
131145 if code .startswith ('>>> ' ):
132- lexer = pygments .lexers .PythonConsoleLexer ()
146+ lexer = pygments .lexers .PythonConsoleLexer (python3 = True )
133147 else :
134- lexer = pygments .lexers .PythonLexer ()
148+ lexer = pygments .lexers .Python3Lexer ()
135149 formatter = pygments .formatters .HtmlFormatter (
136150 style = self .pygments_style , noclasses = True )
137151 return pygments .highlight (code , lexer , formatter )
@@ -198,10 +212,10 @@ def main():
198212 help = "write the HTML files here, defaults to %(default)r" )
199213 if pygments is not None :
200214 parser .add_argument (
201- '--pygments-style' , metavar = 'STYLE' , default = 'native' ,
215+ '--pygments-style' , metavar = 'STYLE' , default = TutorialStyle ,
202216 choices = list (pygments .styles .get_all_styles ()),
203217 help = ("the Pygments color style (see above), "
204- "%(default)r by default " ))
218+ "defaults to a custom style " ))
205219 args = parser .parse_args ()
206220
207221 if pygments is None :
@@ -215,6 +229,7 @@ def main():
215229 if not common .askyesno ("Continue without pygments?" ):
216230 print ("Interrupt." )
217231 return
232+ args .pygments_style = None
218233
219234 if os .path .exists (args .outdir ):
220235 if not common .askyesno ("%s exists. Do you want to remove it?"
@@ -228,16 +243,16 @@ def main():
228243
229244 print ("Generating HTML files..." )
230245 for markdownfile in common .get_markdown_files ():
231- fixed_markdownfile = fix_filename (markdownfile )
232- htmlfile = posixpath .join (args .outdir , fixed_markdownfile )
246+ fixed_file = fix_filename (markdownfile )
247+ htmlfile = posixpath .join (args .outdir , fixed_file )
233248 print (' %-30.30s --> %-30.30s' % (markdownfile , htmlfile ), end = '\r ' )
234249
235250 with common .slashfix_open (markdownfile , 'r' ) as f :
236251 markdown = f .read ()
237252 renderer = TutorialRenderer (args .pygments_style )
238253 body = mistune .markdown (markdown , renderer = renderer )
239254 stylefile = posixpath .relpath (
240- 'style.css' , posixpath .dirname (fixed_markdownfile ))
255+ 'style.css' , posixpath .dirname (fixed_file ))
241256
242257 html = HTML_TEMPLATE .format (
243258 title = renderer .title ,
0 commit comments