2023-12-20 21:10:20 +02:00
|
|
|
import { LanguageDescription } from '@codemirror/language';
|
|
|
|
import { languages } from '@codemirror/language-data';
|
2022-07-28 18:01:34 +02:00
|
|
|
|
2023-12-20 21:10:20 +02:00
|
|
|
const additionalAliases: Record<string, string[]> = {
|
|
|
|
'python': ['py'],
|
|
|
|
'rust': ['rs'],
|
|
|
|
'markdown': ['md'],
|
|
|
|
};
|
2022-07-28 18:01:34 +02:00
|
|
|
|
|
|
|
// Convert supportedLanguages to a CodeMirror-readable list
|
|
|
|
// of LanguageDescriptions
|
2024-02-22 17:35:54 +02:00
|
|
|
export const allLanguages: LanguageDescription[] = [];
|
2022-07-28 18:01:34 +02:00
|
|
|
|
2023-12-20 21:10:20 +02:00
|
|
|
for (const language of languages) {
|
|
|
|
const languageId = language.name.toLowerCase();
|
|
|
|
|
|
|
|
if (additionalAliases.hasOwnProperty(languageId)) {
|
2024-02-22 17:35:54 +02:00
|
|
|
allLanguages.push(LanguageDescription.of({
|
2022-07-28 18:01:34 +02:00
|
|
|
name: language.name,
|
2023-12-20 21:10:20 +02:00
|
|
|
alias: [...language.alias, ...additionalAliases[languageId]],
|
|
|
|
extensions: language.extensions,
|
|
|
|
filename: language.filename,
|
|
|
|
support: language.support,
|
|
|
|
load: () => language.load.call(language),
|
|
|
|
}));
|
|
|
|
} else {
|
2024-02-22 17:35:54 +02:00
|
|
|
allLanguages.push(language);
|
2023-12-20 21:10:20 +02:00
|
|
|
}
|
2022-07-28 18:01:34 +02:00
|
|
|
}
|
|
|
|
|
2024-02-22 17:35:54 +02:00
|
|
|
export default allLanguages;
|