This documentation is for a development version of IPython. There may be significant differences from the latest stable release (1.2.1).
Defines a variety of Pygments lexers for highlighting IPython code.
- IPythonLexer, IPython3Lexer
- Lexers for pure IPython (python + magic/shell commands)
- IPythonPartialTracebackLexer, IPythonTracebackLexer
- Supports 2.x and 3.x via keyword python3. The partial traceback lexer reads everything but the Python code appearing in a traceback. The full lexer combines the partial lexer with an IPython lexer.
- A lexer for IPython console sessions, with support for tracebacks.
- A friendly lexer which examines the first line of text and from it, decides whether to use an IPython lexer or an IPython console lexer. This is probably the only lexer that needs to be explicitly added to Pygments.
Partial lexer for IPython tracebacks.
Handles all the non-python output. This works for both Python 2.x and 3.x.
IPython traceback lexer.
For doctests, the tracebacks can be snipped as much as desired with the exception to the lines that designate a traceback. For non-syntax error tracebacks, this is the line of hyphens. For syntax error tracebacks, this is the line which lists the File and line number.
An IPython console lexer for IPython code-blocks and doctests, such as:
.. code-block:: ipythonconsole In : a = 'foo' In : a Out: 'foo' In : print a foo In : 1 / 0
Support is also provided for IPython exceptions:
.. code-block:: ipythonconsole In : raise Exception --------------------------------------------------------------------------- Exception Traceback (most recent call last) <ipython-input-1-fca2ab0ca76b> in <module>() ----> 1 raise Exception Exception:
Initialize the IPython console lexer.
python3 : bool
in1_regex : RegexObject
in2_regex : RegexObject
out_regex : RegexObject
Generator of unprocessed tokens after doing insertions and before changing to a new state.
Parses the line and returns a 3-tuple: (mode, code, insertion).
mode is the next mode (or state) of the lexer, and is always equal to ‘input’, ‘output’, or ‘tb’.
code is a portion of the line that should be added to the buffer corresponding to the next mode and eventually lexed by another lexer. For example, code could be Python code if mode were ‘input’.
insertion is a 3-tuple (index, token, text) representing an unprocessed “token” that will be inserted into the stream of tokens that are created from the buffer once we change modes. This is usually the input or output prompt.
In general, the next mode depends on current mode and on the contents of line.
The regex to determine when a traceback starts.
Primary lexer for all IPython-like code.
This is a simple helper lexer. If the first line of the text begins with “In [[0-9]+]:”, then the entire text is parsed with an IPython console lexer. If not, then the entire text is parsed with an IPython lexer.
The goal is to reduce the number of lexers that are registered with Pygments.
Builds IPython lexers depending on the value of python3.
The lexer inherits from an appropriate Python lexer and then adds information about IPython specific keywords (i.e. magic commands, shell commands, etc.)
python3 : bool