1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-18 09:35:20 +02:00
joplin/packages/editor/CodeMirror/markdown/syntaxHighlightingLanguages.ts

36 lines
1004 B
TypeScript
Raw Normal View History

//
// Exports a list of languages that can be used in fenced code blocks.
//
import { LanguageDescription } from '@codemirror/language';
import { languages } from '@codemirror/language-data';
const additionalAliases: Record<string, string[]> = {
'python': ['py'],
'rust': ['rs'],
'markdown': ['md'],
};
// Convert supportedLanguages to a CodeMirror-readable list
// of LanguageDescriptions
const syntaxHighlightingLanguages: LanguageDescription[] = [];
for (const language of languages) {
const languageId = language.name.toLowerCase();
if (additionalAliases.hasOwnProperty(languageId)) {
syntaxHighlightingLanguages.push(LanguageDescription.of({
name: language.name,
alias: [...language.alias, ...additionalAliases[languageId]],
extensions: language.extensions,
filename: language.filename,
support: language.support,
load: () => language.load.call(language),
}));
} else {
syntaxHighlightingLanguages.push(language);
}
}
export default syntaxHighlightingLanguages;