##// END OF EJS Templates
Moved all converter code into nbconvert subdirectory
Moved all converter code into nbconvert subdirectory

File last commit:

r10386:6416b524
r10482:87812de9
Show More
lexers.py
38 lines | 1.5 KiB | text/x-python | PythonLexer
"""A custom pygments lexer for IPython code cells.
Informs The pygments highlighting library of the quirks of IPython's superset
of Python -- magic commands, !shell commands, etc.
"""
#-----------------------------------------------------------------------------
# Copyright (c) 2012, the IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# Third-party imports
from pygments.lexers import PythonLexer, BashLexer
from pygments.lexer import bygroups, using
from pygments.token import Keyword, Operator, Text
#-----------------------------------------------------------------------------
# Class declarations
#-----------------------------------------------------------------------------
class IPythonLexer(PythonLexer):
name = 'IPython'
aliases = ['ip', 'ipython']
filenames = ['*.ipy']
tokens = PythonLexer.tokens.copy()
tokens['root'] = [
(r'(\%+)(\w+)\s+(\.*)(\n)', bygroups(Operator, Keyword,
using(BashLexer), Text)),
(r'(\%+)(\w+)\b', bygroups(Operator, Keyword)),
(r'^(!)(.+)(\n)', bygroups(Operator, using(BashLexer), Text)),
] + tokens['root']