forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codemirror-ipython.ts
35 lines (30 loc) · 1 KB
/
codemirror-ipython.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import * as CodeMirror
from 'codemirror';
import 'codemirror/mode/meta';
import 'codemirror/mode/python/python';
/**
* Define an IPython codemirror mode.
*
* It is a slightly altered Python Mode with a `?` operator.
*/
CodeMirror.defineMode('ipython', (config: CodeMirror.EditorConfiguration, modeOptions?: any) => {
let pythonConf: any = {};
for (let prop in modeOptions) {
if (modeOptions.hasOwnProperty(prop)) {
pythonConf[prop] = modeOptions[prop];
}
}
pythonConf.name = 'python';
pythonConf.singleOperators = new RegExp('^[\\+\\-\\*/%&|@\\^~<>!\\?]');
pythonConf.identifiers = new RegExp('^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*');
return CodeMirror.getMode(config, pythonConf);
}, 'python');
CodeMirror.defineMIME('text/x-ipython', 'ipython');
CodeMirror.modeInfo.push({
ext: [],
mime: 'text/x-ipython',
mode: 'ipython',
name: 'ipython'
});