Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/codemirror/extensions/get-edit-mode.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import * as CodeMirror from "codemirror";67CodeMirror.defineExtension("get_edit_mode", function (cur?: {8line: number;9ch: number;10}): string | undefined {11// @ts-ignore12const editor = this;13switch (editor.getModeAt(cur ?? editor.getCursor()).name) {14case "markdown":15case "yaml-frontmatter":16return "md";17case "xml":18return "html";19case "mediawiki":20return "mediawiki";21case "stex":22return "tex";23case "python": // FUTURE how to tell it to return sage when in a sagews file?24return "python";25case "r":26return "r";27case "julia":28return "julia";29case "sagews": // WARNING: this doesn't work30return "sage";31default:32const { name } = editor.getOption("mode");33if (name.slice(0, 3) === "gfm" || name == "yaml-frontmatter") {34return "md";35} else if (name.slice(0, 9) === "htmlmixed") {36return "html";37} else if (name.indexOf("mediawiki") !== -1) {38return "mediawiki";39} else if (name.indexOf("rst") !== -1) {40return "rst";41} else if (name.indexOf("stex") !== -1) {42return "tex";43}44if (45["md", "html", "tex", "rst", "mediawiki", "sagews", "r"].indexOf(46name47) == -148) {49return "html";50}51}52});535455