CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/codemirror/extensions/get-edit-mode.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import * as CodeMirror from "codemirror";
7
8
CodeMirror.defineExtension("get_edit_mode", function (cur?: {
9
line: number;
10
ch: number;
11
}): string | undefined {
12
// @ts-ignore
13
const editor = this;
14
switch (editor.getModeAt(cur ?? editor.getCursor()).name) {
15
case "markdown":
16
case "yaml-frontmatter":
17
return "md";
18
case "xml":
19
return "html";
20
case "mediawiki":
21
return "mediawiki";
22
case "stex":
23
return "tex";
24
case "python": // FUTURE how to tell it to return sage when in a sagews file?
25
return "python";
26
case "r":
27
return "r";
28
case "julia":
29
return "julia";
30
case "sagews": // WARNING: this doesn't work
31
return "sage";
32
default:
33
const { name } = editor.getOption("mode");
34
if (name.slice(0, 3) === "gfm" || name == "yaml-frontmatter") {
35
return "md";
36
} else if (name.slice(0, 9) === "htmlmixed") {
37
return "html";
38
} else if (name.indexOf("mediawiki") !== -1) {
39
return "mediawiki";
40
} else if (name.indexOf("rst") !== -1) {
41
return "rst";
42
} else if (name.indexOf("stex") !== -1) {
43
return "tex";
44
}
45
if (
46
["md", "html", "tex", "rst", "mediawiki", "sagews", "r"].indexOf(
47
name
48
) == -1
49
) {
50
return "html";
51
}
52
}
53
});
54
55