mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-28 21:49:40 +02:00
feat(editor): integrate Monaco Editor for local file editing and enhance language inference
This commit is contained in:
parent
864f6f798a
commit
bbc1c76c0d
5 changed files with 166 additions and 0 deletions
34
surfsense_web/lib/editor-language.ts
Normal file
34
surfsense_web/lib/editor-language.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
const EXTENSION_TO_MONACO_LANGUAGE: Record<string, string> = {
|
||||
css: "css",
|
||||
csv: "plaintext",
|
||||
cjs: "javascript",
|
||||
html: "html",
|
||||
htm: "html",
|
||||
ini: "ini",
|
||||
js: "javascript",
|
||||
json: "json",
|
||||
markdown: "markdown",
|
||||
md: "markdown",
|
||||
mjs: "javascript",
|
||||
py: "python",
|
||||
sql: "sql",
|
||||
toml: "plaintext",
|
||||
ts: "typescript",
|
||||
tsx: "typescript",
|
||||
xml: "xml",
|
||||
yaml: "yaml",
|
||||
yml: "yaml",
|
||||
};
|
||||
|
||||
export function inferMonacoLanguageFromPath(filePath: string | null | undefined): string {
|
||||
if (!filePath) return "plaintext";
|
||||
|
||||
const fileName = filePath.split("/").pop() ?? filePath;
|
||||
const extensionIndex = fileName.lastIndexOf(".");
|
||||
if (extensionIndex <= 0 || extensionIndex === fileName.length - 1) {
|
||||
return "plaintext";
|
||||
}
|
||||
|
||||
const extension = fileName.slice(extensionIndex + 1).toLowerCase();
|
||||
return EXTENSION_TO_MONACO_LANGUAGE[extension] ?? "plaintext";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue