feat(FN-4411): complete Step 2 — add CodeMirror language resolver
Fusion-Task-Id: FN-4411 Fusion-Task-Lineage: d90785f2-b828-4fa0-b330-ede7f3c14349
This commit is contained in:
35
packages/dashboard/app/utils/codemirror-language.ts
Normal file
35
packages/dashboard/app/utils/codemirror-language.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { type Extension } from "@codemirror/state";
|
||||
import { css } from "@codemirror/lang-css";
|
||||
import { javascript } from "@codemirror/lang-javascript";
|
||||
import { json } from "@codemirror/lang-json";
|
||||
import { markdown } from "@codemirror/lang-markdown";
|
||||
|
||||
export function resolveCodeMirrorLanguage(filePath: string | undefined): Extension | null {
|
||||
if (!filePath) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const lowerPath = filePath.toLowerCase();
|
||||
|
||||
if (lowerPath.endsWith(".js") || lowerPath.endsWith(".mjs") || lowerPath.endsWith(".cjs") || lowerPath.endsWith(".jsx")) {
|
||||
return javascript({ jsx: true });
|
||||
}
|
||||
|
||||
if (lowerPath.endsWith(".ts") || lowerPath.endsWith(".tsx")) {
|
||||
return javascript({ jsx: true, typescript: true });
|
||||
}
|
||||
|
||||
if (lowerPath.endsWith(".css")) {
|
||||
return css();
|
||||
}
|
||||
|
||||
if (lowerPath.endsWith(".json")) {
|
||||
return json();
|
||||
}
|
||||
|
||||
if (lowerPath.endsWith(".md") || lowerPath.endsWith(".markdown") || lowerPath.endsWith(".mdx")) {
|
||||
return markdown();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user