From 35a25f192adeb2d764b49b175e5efe5c13c2855d 2015-01-25 19:04:40 From: Thomas Kluyver Date: 2015-01-25 19:04:40 Subject: [PATCH] Merge pull request #7585 from abalkin/issue-7548-3 Additional fixes for the ipython lexer --- diff --git a/IPython/nbconvert/utils/lexers.py b/IPython/nbconvert/utils/lexers.py index 79f7eb8..427e1b8 100644 --- a/IPython/nbconvert/utils/lexers.py +++ b/IPython/nbconvert/utils/lexers.py @@ -57,7 +57,8 @@ ipython_tokens = [ using(BashLexer), Text)), (r'(%)(\w+)(.*\n)', bygroups(Operator, Keyword, Text)), (r'^(!!)(.+)(\n)', bygroups(Operator, using(BashLexer), Text)), - (r'(!)(.+)(\n)', bygroups(Operator, using(BashLexer), Text)), + (r'(!)(?!=)(.+)(\n)', bygroups(Operator, using(BashLexer), Text)), + (r'^(\s*)(\?\??)(\s*%{0,2}[\w\.\*]*)', bygroups(Text, Operator, Text)), ] def build_ipy_lexer(python3): diff --git a/IPython/nbconvert/utils/tests/test_lexers.py b/IPython/nbconvert/utils/tests/test_lexers.py index a18f892..91a090e 100644 --- a/IPython/nbconvert/utils/tests/test_lexers.py +++ b/IPython/nbconvert/utils/tests/test_lexers.py @@ -109,3 +109,23 @@ class TestLexers(TestsBase): (Token.Text, '\n'), ] self.assertEqual(tokens_2, list(self.lexer.get_tokens(fragment_2))) + + fragment_2 = 'x != y\n' + tokens_2 = [ + (Token.Name, 'x'), + (Token.Text, ' '), + (Token.Operator, '!='), + (Token.Text, ' '), + (Token.Name, 'y'), + (Token.Text, '\n'), + ] + self.assertEqual(tokens_2, list(self.lexer.get_tokens(fragment_2))) + + fragment_2 = ' ?math.sin\n' + tokens_2 = [ + (Token.Text, ' '), + (Token.Operator, '?'), + (Token.Text, 'math.sin'), + (Token.Text, '\n'), + ] + self.assertEqual(tokens_2, list(self.lexer.get_tokens(fragment_2)))