2022-07-28 18:01:34 +02:00
|
|
|
//
|
|
|
|
// Exports a list of languages that can be used in fenced code blocks.
|
|
|
|
//
|
|
|
|
|
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
|
|
|
|
const syntaxHighlightingLanguages: LanguageDescription[] = [];
|
|
|
|
|
2023-12-20 21:10:20 +02:00
|
|
|
for (const language of languages) {
|
|
|
|
const languageId = language.name.toLowerCase();
|
|
|
|
|
|
|
|
if (additionalAliases.hasOwnProperty(languageId)) {
|
|
|
|
syntaxHighlightingLanguages.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 {
|
|
|
|
syntaxHighlightingLanguages.push(language);
|
|
|
|
}
|
2022-07-28 18:01:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default syntaxHighlightingLanguages;
|