forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codemirror-ipythongfm.ts
70 lines (65 loc) · 1.73 KB
/
codemirror-ipythongfm.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import CodeMirror from 'codemirror';
import 'codemirror/mode/stex/stex';
import 'codemirror/mode/gfm/gfm';
import 'codemirror/addon/mode/multiplex';
/**
* Define an IPython GFM (GitHub Flavored Markdown) mode.
*
* Is just a slightly altered GFM Mode with support for LaTeX.
* LaTeX support was supported by Codemirror GFM as of
* https://github.com/codemirror/CodeMirror/pull/567
* But was later removed in
* https://github.com/codemirror/CodeMirror/commit/d9c9f1b1ffe984aee41307f3e927f80d1f23590c
*/
CodeMirror.defineMode(
'ipythongfm',
(config: CodeMirror.EditorConfiguration, modeOptions?: any) => {
let gfmMode = CodeMirror.getMode(config, {
name: 'gfm',
// Override list3 with an under-used token, rather than `keyword`
tokenTypeOverrides: { list3: 'string-2' }
});
let texMode = CodeMirror.getMode(config, {
name: 'stex',
inMathMode: true
});
return CodeMirror.multiplexingMode(
gfmMode,
{
open: '$$',
close: '$$',
mode: texMode,
delimStyle: 'delimit'
},
{
open: '$',
close: '$',
mode: texMode,
delimStyle: 'delimit'
},
{
open: '\\(',
close: '\\)',
mode: texMode,
delimStyle: 'delimit'
},
{
open: '\\[',
close: '\\]',
mode: texMode,
delimStyle: 'delimit'
}
// .. more multiplexed styles can follow here
);
},
'gfm'
);
CodeMirror.defineMIME('text/x-ipythongfm', 'ipythongfm');
CodeMirror.modeInfo.push({
ext: [],
mime: 'text/x-ipythongfm',
mode: 'ipythongfm',
name: 'ipythongfm'
});