Format: text/x-python
⬇ Download File (970 B)
   1  """
   2  reST directive for syntax-highlighting ipython interactive sessions.
   3  
   4  """
   5  
   6  from sphinx import highlighting
   7  from IPython.lib.lexers import IPyLexer
   8  
   9  def setup(app):
  10      """Setup as a sphinx extension."""
  11  
  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
  14      # sphinx, by all means fix it here.  At least having this setup.py
  15      # suppresses the sphinx warning we'd get without it.
  16      metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
  17      return metadata
  18  
  19  # Register the extension as a valid pygments lexer.
  20  # Alternatively, we could register the lexer with pygments instead. This would
  21  # require using setuptools entrypoints: http://pygments.org/docs/plugins
  22  
  23  ipy2 = IPyLexer(python3=False)
  24  ipy3 = IPyLexer(python3=True)
  25  
  26  highlighting.lexers['ipython'] = ipy2
  27  highlighting.lexers['ipython2'] = ipy2
  28  highlighting.lexers['ipython3'] = ipy3
  29