--- Sphinx-1.1.3/sphinx/highlighting.py.bak 2012-03-10 21:31:27.313713248 -0500 +++ Sphinx-1.1.3/sphinx/highlighting.py 2012-03-10 21:34:42.117398616 -0500 @@ -159,11 +159,17 @@ if not pygments: return self.unhighlighted(source) + sage = False + # find out which lexer to use if lang in ('py', 'python'): if source.startswith('>>>'): # interactive session lexer = lexers['pycon'] + elif source.startswith('sage:'): + lexer = lexers['pycon'] + source = source.replace('sage:', '>>>') + sage = True elif not force: # maybe Python -- try parsing it if self.try_parse(source): @@ -203,13 +209,25 @@ formatter = self.get_formatter(**kwargs) hlsource = highlight(source, lexer, formatter) if self.dest == 'html': + if sage: + hlsource = hlsource.replace(r'>>>', + 'sage:') + hlsource = hlsource.replace(r'>>>', 'sage:') return hlsource else: + if sage: + hlsource = hlsource.replace(r'>>>', 'sage:') return hlsource.translate(tex_hl_escape_map_new) except ErrorToken: # this is most probably not the selected language, # so let it pass unhighlighted - return self.unhighlighted(source) + uhlsource = self.unhighlighted(source) + if sage: + uhlsource = uhlsource.replace('@textgreater[]@textgreater[]@textgreater[]', + '@PYGaO[sage: ]') + uhlsource = uhlsource.replace(r'>>>', 'sage:') + uhlsource = uhlsource.replace(r'>>>', 'sage:') + return uhlsource def get_stylesheet(self): if not pygments: