forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmode.ts
More file actions
31 lines (27 loc) · 960 Bytes
/
mode.ts
File metadata and controls
31 lines (27 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const requireAMDModule = paths =>
new Promise(resolve => (window as any).require(paths, () => resolve()));
export default async (title: string, monaco) => {
if (title == null) return 'javascript';
const kind = title.match(/\.([^.]*)$/);
if (kind) {
if (kind[1] === 'css') return 'css';
if (kind[1] === 'scss') return 'scss';
if (kind[1] === 'json') return 'json';
if (kind[1] === 'html') return 'html';
if (kind[1] === 'svelte') return 'html';
if (kind[1] === 'vue') {
if (
monaco.languages.getLanguages &&
!monaco.languages.getLanguages().find(l => l.id === 'vue')
) {
await requireAMDModule(['vs/language/vue/monaco.contribution']);
}
return 'vue';
}
if (kind[1] === 'less') return 'less';
if (kind[1] === 'md') return 'markdown';
if (/jsx?$/.test(kind[1])) return 'javascript';
if (/tsx?$/.test(kind[1])) return 'typescript';
}
return undefined;
};