ipython_console_highlighting.py 970 B

12345678910111213141516171819202122232425262728
  1. """
  2. reST directive for syntax-highlighting ipython interactive sessions.
  3. """
  4. from sphinx import highlighting
  5. from IPython.lib.lexers import IPyLexer
  6. def setup(app):
  7. """Setup as a sphinx extension."""
  8. # This is only a lexer, so adding it below to pygments appears sufficient.
  9. # But if somebody knows what the right API usage should be to do that via
  10. # sphinx, by all means fix it here. At least having this setup.py
  11. # suppresses the sphinx warning we'd get without it.
  12. metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
  13. return metadata
  14. # Register the extension as a valid pygments lexer.
  15. # Alternatively, we could register the lexer with pygments instead. This would
  16. # require using setuptools entrypoints: http://pygments.org/docs/plugins
  17. ipy2 = IPyLexer(python3=False)
  18. ipy3 = IPyLexer(python3=True)
  19. highlighting.lexers['ipython'] = ipy2
  20. highlighting.lexers['ipython2'] = ipy2
  21. highlighting.lexers['ipython3'] = ipy3