| const components = require('../components.js'); | |
| const getLoader = require('../dependencies'); | |
| /** | |
| * The set of all languages which have been loaded using the below function. | |
| * | |
| * @type {Set<string>} | |
| */ | |
| const loadedLanguages = new Set(); | |
| /** | |
| * Loads the given languages and adds them to the current Prism instance. | |
| * | |
| * If no languages are provided, __all__ Prism languages will be loaded. | |
| * | |
| * @param {string|string[]} [languages] | |
| * @returns {void} | |
| */ | |
| function loadLanguages(languages) { | |
| if (languages === undefined) { | |
| languages = Object.keys(components.languages).filter(l => l != 'meta'); | |
| } else if (!Array.isArray(languages)) { | |
| languages = [languages]; | |
| } | |
| // the user might have loaded languages via some other way or used `prism.js` which already includes some | |
| // we don't need to validate the ids because `getLoader` will ignore invalid ones | |
| const loaded = [...loadedLanguages, ...Object.keys(Prism.languages)]; | |
| getLoader(components, languages, loaded).load(lang => { | |
| if (!(lang in components.languages)) { | |
| if (!loadLanguages.silent) { | |
| console.warn('Language does not exist: ' + lang); | |
| } | |
| return; | |
| } | |
| const pathToLanguage = './prism-' + lang; | |
| // remove from require cache and from Prism | |
| delete require.cache[require.resolve(pathToLanguage)]; | |
| delete Prism.languages[lang]; | |
| require(pathToLanguage); | |
| loadedLanguages.add(lang); | |
| }); | |
| } | |
| /** | |
| * Set this to `true` to prevent all warning messages `loadLanguages` logs. | |
| */ | |
| loadLanguages.silent = false; | |
| module.exports = loadLanguages; | |
Xet Storage Details
- Size:
- 1.54 kB
- Xet hash:
- 779ef11547bb3098565f89daf1ee52f1af94f858a176e32c979bd22a4ccfb131
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.