ipython_console_highlighting.py 895 B

12345678910111213141516171819202122232425262728
  1. """
  2. reST directive for syntax-highlighting ipython interactive sessions.
  3. """
  4. from sphinx import highlighting
  5. from ipython_pygments_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. ipy3 = IPyLexer()
  18. highlighting.lexers["ipython"] = ipy3
  19. highlighting.lexers["ipython3"] = ipy3