Added silent option to `loadLanguages` (#2147) This adds an option to `loadLanguages` which prevents all warning messages.
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 32 33 34 35 36 37 38
diff --git a/components/index.js b/components/index.js
index 450810a..b2edcc2 100644
--- a/components/index.js
+++ b/components/index.js
@@ -30,7 +30,9 @@ function loadLanguages(languages) {
getLoader(components, languages, loaded).load(lang => {
if (!(lang in components.languages)) {
- console.warn('Language does not exist: ' + lang);
+ if (!loadLanguages.silent) {
+ console.warn('Language does not exist: ' + lang);
+ }
return;
}
@@ -46,4 +48,9 @@ function loadLanguages(languages) {
});
}
+/**
+ * Set this to `true` to prevent all warning messages `loadLanguages` logs.
+ */
+loadLanguages.silent = false;
+
module.exports = loadLanguages;
diff --git a/index.html b/index.html
index f845186..ab2bfd0 100644
--- a/index.html
+++ b/index.html
@@ -226,6 +226,8 @@ const html = Prism.highlight(code, Prism.languages.haml, 'haml');</code></pre>
<p><strong>Note</strong>: Do <em>not</em> use <code class="language-javascript">loadLanguages()</code> with Webpack or another bundler, as this will cause Webpack to include all languages and plugins. Use the babel plugin described above.</p>
+ <p><strong>Note</strong>: <code class="language-javascript">loadLanguages()</code> will ignore unknown languages and log warning messages to the console. You can prevent the warnings by setting <code class="language-javascript">loadLanguages.silent = true</code>.</p>
+
</section>
<section class="language-markup">