@jupyterlab/codemirror 4.0.0-alpha.10 → 4.0.0-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,167 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ import { defaultHighlightStyle, HighlightStyle, syntaxHighlighting } from '@codemirror/language';
4
+ import { EditorView } from '@codemirror/view';
5
+ import { tags as t } from '@lezer/highlight';
6
+ export const jupyterEditorTheme = EditorView.theme({
7
+ /**
8
+ * CodeMirror themes are handling the background/color in this way. This works
9
+ * fine for CodeMirror editors outside the notebook, but the notebook styles
10
+ * these things differently.
11
+ */
12
+ '&': {
13
+ background: 'var(--jp-layout-color0)',
14
+ color: 'var(--jp-content-font-color1)'
15
+ },
16
+ /* In the notebook, we want this styling to be handled by its container */
17
+ '.jp-CodeConsole &, .jp-Notebook &': {
18
+ background: 'transparent'
19
+ },
20
+ '.cm-content': {
21
+ caretColor: 'var(--jp-editor-cursor-color)'
22
+ },
23
+ '.cm-cursor, .cm-dropCursor': {
24
+ borderLeft: 'var(--jp-code-cursor-width0) solid var(--jp-editor-cursor-color)'
25
+ },
26
+ '.cm-selectionBackground, .cm-content ::selection': {
27
+ backgroundColor: 'var(--jp-editor-selected-background)'
28
+ },
29
+ '&.cm-focused .cm-selectionBackground': {
30
+ backgroundColor: 'var(--jp-editor-selected-focused-background)'
31
+ },
32
+ '.cm-gutters': {
33
+ borderRight: '1px solid var(--jp-border-color2)',
34
+ backgroundColor: 'var(--jp-layout-color2)'
35
+ },
36
+ '.cm-gutter, .cm-activeLine': {
37
+ backgroundColor: 'var(--jp-layout-color2)'
38
+ },
39
+ '.cm-searchMatch': {
40
+ backgroundColor: 'var(--jp-search-unselected-match-background-color)',
41
+ color: 'var(--jp-search-unselected-match-color)'
42
+ },
43
+ '.cm-searchMatch.cm-searchMatch-selected': {
44
+ backgroundColor: 'var(--jp-search-selected-match-background-color) !important',
45
+ color: 'var(--jp-search-selected-match-color) !important'
46
+ }
47
+ });
48
+ // The list of available tags for syntax highlighting is available at
49
+ // https://lezer.codemirror.net/docs/ref/#highlight.tags
50
+ export const jupyterHighlightStyle = HighlightStyle.define([
51
+ // Order matters - a rule will override the previous ones; important for example for in headings styles.
52
+ { tag: t.meta, color: 'var(--jp-mirror-editor-meta-color)' },
53
+ { tag: t.heading, color: 'var(--jp-mirror-editor-header-color)' },
54
+ {
55
+ tag: [t.heading1, t.heading2, t.heading3, t.heading4],
56
+ color: 'var(--jp-mirror-editor-header-color)',
57
+ fontWeight: 'bold'
58
+ },
59
+ {
60
+ tag: t.keyword,
61
+ color: 'var(--jp-mirror-editor-keyword-color)',
62
+ fontWeight: 'bold'
63
+ },
64
+ { tag: t.atom, color: 'var(--jp-mirror-editor-atom-color)' },
65
+ { tag: t.number, color: 'var(--jp-mirror-editor-number-color)' },
66
+ {
67
+ tag: [t.definition(t.name), t.function(t.definition(t.variableName))],
68
+ color: 'var(--jp-mirror-editor-def-color)'
69
+ },
70
+ { tag: t.variableName, color: 'var(--jp-mirror-editor-variable-color)' },
71
+ {
72
+ tag: [t.special(t.variableName), t.self],
73
+ color: 'var(--jp-mirror-editor-variable-2-color)'
74
+ },
75
+ { tag: t.punctuation, color: 'var(--jp-mirror-editor-punctuation-color)' },
76
+ { tag: t.propertyName, color: 'var(--jp-mirror-editor-property-color)' },
77
+ {
78
+ tag: t.operator,
79
+ color: 'var(--jp-mirror-editor-operator-color)',
80
+ fontWeight: 'bold'
81
+ },
82
+ {
83
+ tag: t.comment,
84
+ color: 'var(--jp-mirror-editor-comment-color)',
85
+ fontStyle: 'italic'
86
+ },
87
+ { tag: t.string, color: 'var(--jp-mirror-editor-string-color)' },
88
+ {
89
+ tag: [t.labelName, t.monospace, t.special(t.string)],
90
+ color: 'var(--jp-mirror-editor-string-2-color)'
91
+ },
92
+ { tag: t.bracket, color: 'var(--jp-mirror-editor-bracket-color)' },
93
+ { tag: t.tagName, color: 'var(--jp-mirror-editor-tag-color)' },
94
+ { tag: t.attributeName, color: 'var(--jp-mirror-editor-attribute-color)' },
95
+ { tag: t.quote, color: 'var(--jp-mirror-editor-quote-color)' },
96
+ {
97
+ tag: t.link,
98
+ color: 'var(--jp-mirror-editor-link-color)',
99
+ textDecoration: 'underline'
100
+ },
101
+ { tag: [t.separator, t.derefOperator, t.paren], color: '' },
102
+ { tag: t.strong, fontWeight: 'bold' },
103
+ { tag: t.emphasis, fontStyle: 'italic' },
104
+ { tag: t.strikethrough, textDecoration: 'line-through' }
105
+ ]);
106
+ /**
107
+ * JupyterLab CodeMirror 6 theme
108
+ */
109
+ export const jupyterTheme = [
110
+ jupyterEditorTheme,
111
+ syntaxHighlighting(jupyterHighlightStyle)
112
+ ];
113
+ /**
114
+ * A namespace to handle CodeMirror 6 theme
115
+ *
116
+ * @alpha
117
+ */
118
+ export var Theme;
119
+ (function (Theme) {
120
+ /**
121
+ * CodeMirror 6 themes
122
+ */
123
+ const themeMap = new Map([
124
+ [
125
+ 'codemirror',
126
+ [EditorView.baseTheme({}), syntaxHighlighting(defaultHighlightStyle)]
127
+ ],
128
+ ['jupyter', jupyterTheme]
129
+ ]);
130
+ /**
131
+ * Get the default CodeMirror 6 theme for JupyterLab
132
+ *
133
+ * @alpha
134
+ * @returns Default theme
135
+ */
136
+ function defaultTheme() {
137
+ return themeMap.get('jupyter');
138
+ }
139
+ Theme.defaultTheme = defaultTheme;
140
+ /**
141
+ * Register a new theme.
142
+ *
143
+ * @alpha
144
+ * @param name Theme name
145
+ * @param theme Codemirror 6 theme extension
146
+ */
147
+ function registerTheme(name, theme) {
148
+ themeMap.set(name, theme);
149
+ }
150
+ Theme.registerTheme = registerTheme;
151
+ /**
152
+ * Get a theme.
153
+ *
154
+ * #### Notes
155
+ * It falls back to the default theme
156
+ *
157
+ * @alpha
158
+ * @param name Theme name
159
+ * @returns Theme extension
160
+ */
161
+ function getTheme(name) {
162
+ let ext = themeMap.get(name);
163
+ return ext !== null && ext !== void 0 ? ext : this.defaultTheme();
164
+ }
165
+ Theme.getTheme = getTheme;
166
+ })(Theme || (Theme = {}));
167
+ //# sourceMappingURL=editortheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editortheme.js","sourceRoot":"","sources":["../src/editortheme.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,IAAI,IAAI,CAAC,EAAE,MAAM,kBAAkB,CAAC;AAE7C,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC,KAAK,CAAC;IACjD;;;;OAIG;IACH,GAAG,EAAE;QACH,UAAU,EAAE,yBAAyB;QACrC,KAAK,EAAE,+BAA+B;KACvC;IAED,0EAA0E;IAC1E,mCAAmC,EAAE;QACnC,UAAU,EAAE,aAAa;KAC1B;IAED,aAAa,EAAE;QACb,UAAU,EAAE,+BAA+B;KAC5C;IAED,4BAA4B,EAAE;QAC5B,UAAU,EACR,kEAAkE;KACrE;IAED,kDAAkD,EAAE;QAClD,eAAe,EAAE,sCAAsC;KACxD;IAED,sCAAsC,EAAE;QACtC,eAAe,EAAE,8CAA8C;KAChE;IAED,aAAa,EAAE;QACb,WAAW,EAAE,mCAAmC;QAChD,eAAe,EAAE,yBAAyB;KAC3C;IAED,4BAA4B,EAAE;QAC5B,eAAe,EAAE,yBAAyB;KAC3C;IAED,iBAAiB,EAAE;QACjB,eAAe,EAAE,oDAAoD;QACrE,KAAK,EAAE,yCAAyC;KACjD;IAED,yCAAyC,EAAE;QACzC,eAAe,EACb,6DAA6D;QAC/D,KAAK,EAAE,kDAAkD;KAC1D;CACF,CAAC,CAAC;AAEH,qEAAqE;AACrE,wDAAwD;AACxD,MAAM,CAAC,MAAM,qBAAqB,GAAG,cAAc,CAA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AAqB,CAAC;CAC1C,CAAC;AAEF;;;;GAIG;AACH,MAAM,KAAW,KAAK,CAgDrB;AAhDD,WAAiB,KAAK;IACpB;;OAEG;IACH,MAAM,QAAQ,GAA2B,IAAI,GAAG,CAAC;QAC/C;YACE,YAAY;YACZ,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,kBAAkB,CAAC,qBAAqB,CAAC,CAAC;SACtE;QACD,CAAC,SAAS,EAAE,YAAY,CAAC;KAC1B,CAAC,CAAC;IAEH;;;;;OAKG;IACH,SAAgB,YAAY;QAC1B,OAAO,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAE,CAAC;IAClC,CAAC;IAFe,kBAAY,eAE3B,CAAA;IAED;;;;;;OAMG;IACH,SAAgB,aAAa,CAAC,IAAY,EAAE,KAAgB;QAC1D,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAFe,mBAAa,gBAE5B,CAAA;IAED;;;;;;;;;OASG;IACH,SAAgB,QAAQ,CAAC,IAAY;QACnC,IAAI,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAE7B,OAAO,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,IAAI,CAAC,YAAY,EAAE,CAAC;IACpC,CAAC;IAJe,cAAQ,WAIvB,CAAA;AACH,CAAC,EAhDgB,KAAK,KAAL,KAAK,QAgDrB"}
package/lib/factory.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
+ import { indentLess } from '@codemirror/commands';
4
+ import { searchKeymap } from '@codemirror/search';
3
5
  import { nullTranslator } from '@jupyterlab/translation';
4
6
  import { CodeMirrorEditor } from './editor';
5
7
  /**
@@ -25,26 +27,27 @@ export class CodeMirrorEditorFactory {
25
27
  return new CodeMirrorEditor(Object.assign(Object.assign({}, options), { config: Object.assign(Object.assign({}, this.documentCodeMirrorConfig), (options.config || {})), translator: this.translator }));
26
28
  };
27
29
  this.translator = translator || nullTranslator;
28
- this.inlineCodeMirrorConfig = Object.assign(Object.assign(Object.assign({}, CodeMirrorEditor.defaultConfig), { extraKeys: {
29
- 'Cmd-Right': 'goLineRight',
30
- End: 'goLineRight',
31
- 'Cmd-Left': 'goLineLeft',
32
- Tab: 'indentMoreOrinsertTab',
33
- 'Shift-Tab': 'indentLess',
34
- 'Cmd-/': cm => cm.toggleComment({ indent: true }),
35
- 'Ctrl-/': cm => cm.toggleComment({ indent: true }),
36
- 'Ctrl-G': 'find',
37
- 'Cmd-G': 'find'
38
- } }), defaults);
39
- this.documentCodeMirrorConfig = Object.assign(Object.assign(Object.assign({}, CodeMirrorEditor.defaultConfig), { extraKeys: {
40
- Tab: 'indentMoreOrinsertTab',
41
- 'Shift-Tab': 'indentLess',
42
- 'Cmd-/': cm => cm.toggleComment({ indent: true }),
43
- 'Ctrl-/': cm => cm.toggleComment({ indent: true }),
44
- 'Shift-Enter': () => {
45
- /* no-op */
30
+ this.inlineCodeMirrorConfig = Object.assign(Object.assign(Object.assign({}, CodeMirrorEditor.defaultConfig), { extraKeys: [
31
+ {
32
+ key: 'Tab',
33
+ run: CodeMirrorEditor.indentMoreOrInsertTab,
34
+ shift: indentLess
35
+ },
36
+ ...searchKeymap
37
+ ] }), defaults);
38
+ this.documentCodeMirrorConfig = Object.assign(Object.assign(Object.assign({}, CodeMirrorEditor.defaultConfig), { extraKeys: [
39
+ {
40
+ key: 'Tab',
41
+ run: CodeMirrorEditor.indentMoreOrInsertTab,
42
+ shift: indentLess
43
+ },
44
+ {
45
+ key: 'Shift-Enter',
46
+ run: (target) => {
47
+ return true;
48
+ }
46
49
  }
47
- }, lineNumbers: true, scrollPastEnd: true }), defaults);
50
+ ], lineNumbers: true, scrollPastEnd: true }), defaults);
48
51
  }
49
52
  }
50
53
  //# sourceMappingURL=factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources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or';
6
6
  export * from './editor';
7
7
  export * from './factory';
8
+ export * from './searchprovider';
8
9
  export * from './mimetype';
9
10
  export * from './mode';
10
- export * from './searchprovider';
11
11
  export * from './syntaxstatus';
12
- export * from './tokens';
12
+ export * from './editortheme';
13
13
  /**
14
14
  * The default editor services.
15
15
  */
package/lib/index.js CHANGED
@@ -8,11 +8,11 @@ import { CodeMirrorEditorFactory } from './factory';
8
8
  import { CodeMirrorMimeTypeService } from './mimetype';
9
9
  export * from './editor';
10
10
  export * from './factory';
11
+ export * from './searchprovider';
11
12
  export * from './mimetype';
12
13
  export * from './mode';
13
- export * from './searchprovider';
14
14
  export * from './syntaxstatus';
15
- export * from './tokens';
15
+ export * from './editortheme';
16
16
  /**
17
17
  * The default editor services.
18
18
  */
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAC3D;;;GAGG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AAEzB;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC7C,cAAc,EAAE,IAAI,uBAAuB,EAAE;IAC7C,eAAe,EAAE,IAAI,yBAAyB,EAAE;CACjD,CAAC;AAEF;;;;;;;;;;GAUG"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAC3D;;;GAGG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAE9B;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC7C,cAAc,EAAE,IAAI,uBAAuB,EAAE;IAC7C,eAAe,EAAE,IAAI,yBAAyB,EAAE;CACjD,CAAC;AAEF;;;;;;;;;;GAUG"}
package/lib/mimetype.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
+ import { IEditorMimeTypeService } from '@jupyterlab/codeeditor';
3
4
  import { PathExt } from '@jupyterlab/coreutils';
4
5
  import { Mode } from './mode';
5
6
  /**
@@ -14,11 +15,14 @@ export class CodeMirrorMimeTypeService {
14
15
  */
15
16
  getMimeTypeByLanguage(info) {
16
17
  const ext = info.file_extension || '';
17
- return Mode.findBest(info.codemirror_mode || {
18
+ const mode = Mode.findBest(info.codemirror_mode || {
18
19
  mimetype: info.mimetype,
19
20
  name: info.name,
20
21
  ext: [ext.split('.').slice(-1)[0]]
21
- }).mime;
22
+ });
23
+ return mode
24
+ ? mode.mime
25
+ : IEditorMimeTypeService.defaultMimeType;
22
26
  }
23
27
  /**
24
28
  * Returns a mime type for the given file path.
@@ -35,7 +39,9 @@ export class CodeMirrorMimeTypeService {
35
39
  return 'text/x-ipythongfm';
36
40
  }
37
41
  const mode = Mode.findByFileName(path) || Mode.findBest('');
38
- return mode.mime;
42
+ return mode
43
+ ? mode.mime
44
+ : IEditorMimeTypeService.defaultMimeType;
39
45
  }
40
46
  }
41
47
  //# sourceMappingURL=mimetype.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mimetype.js","sourceRoot":"","sources":["../src/mimetype.ts"],"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AM,QAAQ,CAAC;AAE9B;;GAEG;AACH,MAAM,OAAO,yBAAyB;IACpC;;;;;OAKG;IACH,qBAAqB,CAAC,IAAoC;QACxD,MAAM,GAAG,GAAG,IAAI,CAAC,cAAc,IAAI,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CACvB,IAAI,CAAC,eAAuB,IAAI;YAC/B,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACnC,CACF,CAAC;QACF,OAAO,IAAI;YACT,CAAC,CAAE,IAAI,CAAC,IAAe;YACvB,CAAC,CAAC,sBAAsB,CAAC,eAAe,CAAC;IAC7C,CAAC;IAED;;;;;OAKG;IACH,qBAAqB,CAAC,IAAY;QAChC,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,GAAG,KAAK,MAAM,EAAE;YAClB,OAAO,eAAe,CAAC;SACxB;aAAM,IAAI,GAAG,KAAK,KAAK,EAAE;YACxB,OAAO,mBAAmB,CAAC;SAC5B;QACD,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC5D,OAAO,IAAI;YACT,CAAC,CAAE,IAAI,CAAC,IAAe;YACvB,CAAC,CAAC,sBAAsB,CAAC,eAAe,CAAC;IAC7C,CAAC;CACF"}
package/lib/mode.d.ts CHANGED
@@ -1,82 +1,88 @@
1
- import { JSONValue } from '@lumino/coreutils';
2
- import 'codemirror/addon/runmode/runmode';
3
- import 'codemirror/mode/clike/clike';
4
- import 'codemirror/mode/css/css';
5
- import 'codemirror/mode/javascript/javascript';
6
- import 'codemirror/mode/jsx/jsx';
7
- import 'codemirror/mode/julia/julia';
8
- import 'codemirror/mode/markdown/markdown';
9
- import 'codemirror/mode/meta';
10
- import 'codemirror/mode/r/r';
11
- import 'codemirror/mode/shell/shell';
12
- import 'codemirror/mode/sql/sql';
13
- import './codemirror-ipython';
14
- import './codemirror-ipythongfm';
15
- /**
16
- * The namespace for CodeMirror Mode functionality.
17
- */
1
+ import { LanguageSupport, StreamParser } from '@codemirror/language';
18
2
  export declare namespace Mode {
19
3
  /**
20
- * The interface of a codemirror modeInfo spec.
4
+ * The interface of a codemirror language spec.
21
5
  */
22
6
  interface ISpec {
23
- ext?: string[];
24
- name?: string;
25
- mode: string;
26
- mime: string;
27
- }
28
- /**
29
- * The interface of a codemirror mode spec.
30
- */
31
- interface IMode {
32
7
  name: string;
33
- [key: string]: JSONValue;
34
- }
35
- /**
36
- * The interface for a codemirror spec resolver.
37
- */
38
- interface ISpecLoader {
39
- /**
40
- * A function which returns whether it was successfully loaded
41
- */
42
- (spec: ISpec): Promise<boolean>;
8
+ alias?: readonly string[];
9
+ mime: string | readonly string[];
10
+ load?: () => Promise<LanguageSupport>;
11
+ extensions?: readonly string[];
12
+ filename?: RegExp;
13
+ support?: LanguageSupport;
43
14
  }
15
+ function legacy(parser: StreamParser<unknown>): LanguageSupport;
44
16
  /**
45
17
  * Get the raw list of available modes specs.
18
+ *
19
+ * @alpha
20
+ * @returns The available modes
46
21
  */
47
22
  function getModeInfo(): ISpec[];
48
23
  /**
49
- * Running a CodeMirror mode outside of an editor.
24
+ * Find a codemirror mode by MIME.
25
+ *
26
+ * @alpha
27
+ * @param mime Mime type to look for
28
+ * @returns The mode or null
50
29
  */
51
- function run(code: string, mode: string | ISpec, el: HTMLElement): void;
30
+ function findByMIME(mime: string | readonly string[]): ISpec | null;
52
31
  /**
53
- * Ensure a codemirror mode is available by name or Codemirror spec.
32
+ * Find a codemirror mode by name.
54
33
  *
55
- * @param mode - The mode to ensure. If it is a string, uses [findBest]
56
- * to get the appropriate spec.
34
+ * @alpha
35
+ * @param name The mode name
36
+ * @returns The mode or null
37
+ */
38
+ function findByName(name: string): ISpec | null;
39
+ /**
40
+ * Find a codemirror mode by extension.
57
41
  *
58
- * @returns A promise that resolves when the mode is available.
42
+ * @alpha
43
+ * @param ext The extension name
44
+ * @returns The mode or null
59
45
  */
60
- function ensure(mode: string | ISpec): Promise<ISpec | null>;
61
- function addSpecLoader(loader: ISpecLoader, rank: number): void;
46
+ function findByExtension(ext: string | readonly string[]): ISpec | null;
62
47
  /**
63
- * Find a codemirror mode by name or CodeMirror spec.
48
+ * Find a codemirror mode by filename.
49
+ *
50
+ * @param name File name
51
+ * @returns The mode or null
64
52
  */
65
- function findBest(mode: string | ISpec): ISpec;
53
+ function findByFileName(name: string): ISpec | null;
66
54
  /**
67
- * Find a codemirror mode by MIME.
55
+ * Find a codemirror mode by name or CodeMirror spec.
56
+ *
57
+ * @alpha
58
+ * @param mode The CodeMirror mode
59
+ * @param fallback Whether to fallback to default mimetype spec or not
60
+ * @returns The mode or null
68
61
  */
69
- function findByMIME(mime: string): ISpec;
62
+ function findBest(mode: string | ISpec, fallback?: boolean): ISpec | null;
70
63
  /**
71
- * Find a codemirror mode by name.
64
+ * Ensure a codemirror mode is available by name or Codemirror spec.
65
+ *
66
+ * @param mode - The mode to ensure. If it is a string, uses [findBest]
67
+ * to get the appropriate spec.
68
+ *
69
+ * @returns A promise that resolves when the mode is available.
72
70
  */
73
- function findByName(name: string): ISpec;
71
+ function ensure(mode: string | ISpec): Promise<ISpec | null>;
74
72
  /**
75
- * Find a codemirror mode by filename.
73
+ * Register a new mode for CodeMirror
74
+ *
75
+ * @alpha
76
+ * @param mode Mode to register
76
77
  */
77
- function findByFileName(name: string): ISpec;
78
+ function registerModeInfo(mode: ISpec): void;
78
79
  /**
79
- * Find a codemirror mode by extension.
80
+ * Parse and style a string.
81
+ *
82
+ * @alpha
83
+ * @param code Code to highlight
84
+ * @param mode Code mode
85
+ * @param el HTML element into which the highlighted code will be inserted
80
86
  */
81
- function findByExtension(ext: string | string[]): ISpec | null;
87
+ function run(code: string, mode: ISpec, el: HTMLElement): void;
82
88
  }