##// END OF EJS Templates
Make IPyLexer available in Pygments as 'ipython' and 'ipython3'.
chebee7i -
Show More
@@ -1,27 +1,27 b''
1 """
1 """
2 reST directive for syntax-highlighting ipython interactive sessions.
2 reST directive for syntax-highlighting ipython interactive sessions.
3
3
4 """
4 """
5
5
6 from sphinx import highlighting
6 from sphinx import highlighting
7 from ..nbconvert.utils.lexers import IPyLexer
7 from ..nbconvert.utils.lexers import IPyLexer
8
8
9 def setup(app):
9 def setup(app):
10 """Setup as a sphinx extension."""
10 """Setup as a sphinx extension."""
11
11
12 # This is only a lexer, so adding it below to pygments appears sufficient.
12 # This is only a lexer, so adding it below to pygments appears sufficient.
13 # But if somebody knows what the right API usage should be to do that via
13 # But if somebody knows what the right API usage should be to do that via
14 # sphinx, by all means fix it here. At least having this setup.py
14 # sphinx, by all means fix it here. At least having this setup.py
15 # suppresses the sphinx warning we'd get without it.
15 # suppresses the sphinx warning we'd get without it.
16 pass
16 pass
17
17
18 # Register the extension as a valid pygments lexerself.
18 # Register the extension as a valid pygments lexerself.
19 # Alternatively, we could register the lexer with pygments instead. This would
19 # Alternatively, we could register the lexer with pygments instead. This would
20 # require using setuptools entrypoints: http://pygments.org/docs/plugins
20 # require using setuptools entrypoints: http://pygments.org/docs/plugins
21
21
22 ipy = IPyLexer(python3=False)
22 ipy = IPyLexer(python3=False)
23 ipy3 = IPyLexer(python3=True)
23 ipy3 = IPyLexer(python3=True)
24 ipy3.aliases = ['ipy3']
24 ipy3.aliases = ['ipy3']
25
25
26 highlighting.lexers['ipy'] = ipy
26 highlighting.lexers['ipython'] = ipy
27 highlighting.lexers['ipy3'] = ipy3
27 highlighting.lexers['ipython3'] = ipy3
@@ -1,58 +1,58 b''
1 New IPython Console Lexer
1 New IPython Console Lexer
2 -------------------------
2 -------------------------
3
3
4 The IPython console lexer has been rewritten and now supports tracebacks
4 The IPython console lexer has been rewritten and now supports tracebacks
5 and customized input/output prompts. An entire suite of lexers are now
5 and customized input/output prompts. An entire suite of lexers is now
6 available at :module:`IPython.nbconvert.utils.lexers`. These include:
6 available at :module:`IPython.nbconvert.utils.lexers`. These include:
7
7
8 IPythonLexer
8 IPythonLexer
9 IPython3Lexer
9 IPython3Lexer
10 Lexers for pure IPython (python + magic/shell commands)
10 Lexers for pure IPython (python + magic/shell commands)
11
11
12 IPythonPartialTracebackLexer
12 IPythonPartialTracebackLexer
13 IPythonTracebackLexer
13 IPythonTracebackLexer
14 Supports 2.x and 3.x via the keyword `python3`. The partial traceback
14 Supports 2.x and 3.x via the keyword `python3`. The partial traceback
15 lexer reads everything but the Python code appearing in a traceback.
15 lexer reads everything but the Python code appearing in a traceback.
16 The full lexer combines the partial lexer with an IPython lexer.
16 The full lexer combines the partial lexer with an IPython lexer.
17
17
18 IPythonConsoleLexer
18 IPythonConsoleLexer
19 A lexer for IPython console sessions, with support for tracebacks.
19 A lexer for IPython console sessions, with support for tracebacks.
20 Supports 2.x and 3.x via the keyword `python3`.
20 Supports 2.x and 3.x via the keyword `python3`.
21
21
22 IPyLexer
22 IPyLexer
23 A friendly lexer which examines the first line of text and from it,
23 A friendly lexer which examines the first line of text and from it,
24 decides whether to use an IPython lexer or an IPython console lexer.
24 decides whether to use an IPython lexer or an IPython console lexer.
25 Supports 2.x and 3.x via the keyword `python3`.
25 Supports 2.x and 3.x via the keyword `python3`.
26
26
27 Previously, the :class:`IPythonConsoleLexer` class was available at
27 Previously, the :class:`IPythonConsoleLexer` class was available at
28 :module:`IPython.sphinxext.ipython_console_hightlight`. It was inserted
28 :module:`IPython.sphinxext.ipython_console_hightlight`. It was inserted
29 into Pygments' list of available lexers under the name `ipython`. It should
29 into Pygments' list of available lexers under the name `ipython`. It should
30 be mentioned that this name is inaccurate. An IPython console session
30 be mentioned that this name is inaccurate. An IPython console session
31 is not the same as IPython code (which itself is a superset of the Python
31 is not the same as IPython code (which itself is a superset of the Python
32 language).
32 language).
33
33
34 Now, the Sphinx extension inserts two console lexers into Pygment's list of
34 Now, the Sphinx extension inserts two console lexers into Pygment's list of
35 available lexers. Both are IPyLexer instances under the names: `ipython` and
35 available lexers. Both are IPyLexer instances under the names: `ipython` and
36 `ipython3`. As mentioned above, these names are misleading, but they are kept
36 `ipython3`. As mentioned above, these names are misleading, but they are kept
37 for backwards compatibility and typical usage. If a project needs to make
37 for backwards compatibility and typical usage. If a project needs to make
38 Pygments aware of more than just the IPyLexer class, then one should not
38 Pygments aware of more than just the IPyLexer class, then one should not
39 make the IPyLexer class available under the name `ipython` and use `ipy` or
39 make the IPyLexer class available under the name `ipython` and use `ipy` or
40 some other non-conflicting value.
40 some other non-conflicting value.
41
41
42 Code blocks such as::
42 Code blocks such as::
43
43
44 .. code-block:: ipython
44 .. code-block:: ipython
45
45
46 In [1]: 2**2
46 In [1]: 2**2
47 Out[1]: 4
47 Out[1]: 4
48
48
49 will continue to work as before, but now, they will also properly highlight
49 will continue to work as before, but now, they will also properly highlight
50 tracebacks. For pure IPython code, the same lexer will work::
50 tracebacks. For pure IPython code, the same lexer will work::
51
51
52 .. code-block:: ipython
52 .. code-block:: ipython
53
53
54 x = ''.join(map(str, range(10)))
54 x = ''.join(map(str, range(10)))
55 !echo $x
55 !echo $x
56
56
57 Since the first line of the block did not begin with a standard IPython console
57 Since the first line of the block did not begin with a standard IPython console
58 prompt, the entire block is assumed to be IPython code instead.
58 prompt, the entire block is assumed to be IPython code instead.
General Comments 0
You need to be logged in to leave comments. Login now