jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.38k stars 4.73k forks source link

CodeMirror doesn't recognize `==, >=, <=, !=, +=, *=` as operators. #2682

Open ruoyu0088 opened 6 years ago

ruoyu0088 commented 6 years ago

For example, in the following image, all = after >, <, = are black, and operators +=, -=, *=, /= are not recognized.

image

There is something wrong in the CodeMirror mode, here is the doubleOperators define in python.js:

var doubleOperators = parserConf.doubleOperators || /^([!<>]==|<>|<<|>>|\/\/|\*\*)/;

There is a bug in it for !=, <=, >=, == operators, it should be:

var doubleOperators = parserConf.doubleOperators || /^([!<>=]=|<>|<<|>>|\/\/|\*\*)/;

and I thinks operators in doubleDelimiters should be appended to doubleOperators.

Here is the code I added to codemirror-ipython.js:

pythonConf.doubleOperators = /^([!<>=]=|<>|<<|>>|\/\/|\*\*|\+=|\-=|\*=|%=|\/=|&=|\|=|\^=)/;
pythonConf.doubleDelimiters = /^(@@)/; // I don't know how to remove all items in doubleDelimiters

Here is the result (I am using programming ligatures):

image

takluyver commented 6 years ago

It looks like we currently inherit the doubleOperators from CodeMirror, without overriding it. So I think it would be best to fix this in CodeMirror, if you have the time to file an issue there.