Note
This documentation is for a development version of IPython. There may be significant differences from the latest stable release (1.2.1).
New in version 2.0.0.
The IPython console lexer has been rewritten and now supports tracebacks and customized input/output prompts. An entire suite of lexers is now available at IPython.nbconvert.utils.lexers. These include:
Previously, the IPythonConsoleLexer class was available at IPython.sphinxext.ipython_console_hightlight. It was inserted into Pygments’ list of available lexers under the name ipython. It should be mentioned that this name is inaccurate, since an IPython console session is not the same as IPython code (which itself is a superset of the Python language).
Now, the Sphinx extension inserts two console lexers into Pygments’ list of available lexers. Both are IPyLexer instances under the names: ipython and ipython3. Although the names can be confusing (as mentioned above), their continued use is, in part, to maintain backwards compatibility and to aid typical usage. If a project needs to make Pygments aware of more than just the IPyLexer class, then one should not make the IPyLexer class available under the name ipython and use ipy or some other non-conflicting value.
Code blocks such as:
.. code-block:: ipython
In [1]: 2**2
Out[1]: 4
will continue to work as before, but now, they will also properly highlight tracebacks. For pure IPython code, the same lexer will also work:
.. code-block:: ipython
x = ''.join(map(str, range(10)))
!echo $x
Since the first line of the block did not begin with a standard IPython console prompt, the entire block is assumed to consist of IPython code instead.