ipython_console_highlighting.py
27 lines
| 886 B
| text/x-python
|
PythonLexer
Fernando Perez
|
r1850 | """ | ||
chebee7i
|
r13631 | reST directive for syntax-highlighting ipython interactive sessions. | ||
Fernando Perez
|
r1850 | |||
chebee7i
|
r13631 | """ | ||
Fernando Perez
|
r1850 | |||
Fernando Perez
|
r1694 | from sphinx import highlighting | ||
Thomas Kluyver
|
r20625 | from IPython.lib.lexers import IPyLexer | ||
Brian Granger
|
r2275 | |||
def setup(app): | ||||
"""Setup as a sphinx extension.""" | ||||
# This is only a lexer, so adding it below to pygments appears sufficient. | ||||
chebee7i
|
r13631 | # But if somebody knows what the right API usage should be to do that via | ||
Brian Granger
|
r2275 | # sphinx, by all means fix it here. At least having this setup.py | ||
# suppresses the sphinx warning we'd get without it. | ||||
pass | ||||
chebee7i
|
r13652 | # Register the extension as a valid pygments lexer. | ||
chebee7i
|
r13631 | # Alternatively, we could register the lexer with pygments instead. This would | ||
# require using setuptools entrypoints: http://pygments.org/docs/plugins | ||||
chebee7i
|
r13864 | ipy2 = IPyLexer(python3=False) | ||
chebee7i
|
r13631 | ipy3 = IPyLexer(python3=True) | ||
chebee7i
|
r13864 | highlighting.lexers['ipython'] = ipy2 | ||
highlighting.lexers['ipython2'] = ipy2 | ||||
chebee7i
|
r13633 | highlighting.lexers['ipython3'] = ipy3 | ||