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/next/components/share/codemirror.tsx
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
/* Static codemirror-based renderer. */
7
8
import {
9
CodeMirrorStatic,
10
Options,
11
} from "@cocalc/frontend/jupyter/codemirror-static";
12
import { getExtension } from "lib/share/util";
13
import { codemirrorMode } from "@cocalc/frontend/file-extensions";
14
15
interface Props {
16
content: string;
17
filename: string;
18
options?: Options;
19
fontSize?: number;
20
lineNumbers?: boolean; // default true
21
}
22
23
export default function CodeMirror({
24
content,
25
filename,
26
options,
27
fontSize,
28
lineNumbers = true,
29
}: Props) {
30
const ext = getExtension(filename);
31
const mode = codemirrorMode(ext);
32
return (
33
<CodeMirrorStatic
34
value={content}
35
font_size={fontSize}
36
options={{ lineNumbers, mode, ...options }}
37
/>
38
);
39
}
40
41