Commit 191b4116a9b9b264aa306cb5a46603fb1bd68ef8

Michael Schmidt 2020-01-06T13:28:17

Added silent option to `loadLanguages` (#2147) This adds an option to `loadLanguages` which prevents all warning messages.

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">