1+ """reST directive for syntax-highlighting ipython interactive sessions.
2+ """
3+
4+ #-----------------------------------------------------------------------------
5+ # Needed modules
6+
7+ # Standard library
8+ import re
9+
10+ # Third party
111from pygments .lexer import Lexer , do_insertions
2- from pygments .lexers .agile import PythonConsoleLexer , PythonLexer , \
3- PythonTracebackLexer
12+ from pygments .lexers .agile import ( PythonConsoleLexer , PythonLexer ,
13+ PythonTracebackLexer )
414from pygments .token import Comment , Generic
15+
516from sphinx import highlighting
6- import re
717
18+
19+ #-----------------------------------------------------------------------------
20+ # Global constants
821line_re = re .compile ('.*?\n ' )
922
23+ #-----------------------------------------------------------------------------
24+ # Code begins - classes and functions
25+
1026class IPythonConsoleLexer (Lexer ):
1127 """
1228 For IPython console output or doctests, such as:
1329
14- Tracebacks are not currently supported.
15-
1630 .. sourcecode:: ipython
1731
1832 In [1]: a = 'foo'
@@ -24,7 +38,14 @@ class IPythonConsoleLexer(Lexer):
2438 foo
2539
2640 In [4]: 1 / 0
41+
42+ Notes:
43+
44+ - Tracebacks are not currently supported.
45+
46+ - It assumes the default IPython prompts, not customized ones.
2747 """
48+
2849 name = 'IPython console session'
2950 aliases = ['ipython' ]
3051 mimetypes = ['text/x-ipython-console' ]
@@ -72,4 +93,6 @@ def get_tokens_unprocessed(self, text):
7293 pylexer .get_tokens_unprocessed (curcode )):
7394 yield item
7495
96+ #-----------------------------------------------------------------------------
97+ # Register the extension as a valid pygments lexer
7598highlighting .lexers ['ipython' ] = IPythonConsoleLexer ()
0 commit comments