diff --git a/components/prism-core.js b/components/prism-core.js index 70afd3b672..f1d001f432 100644 --- a/components/prism-core.js +++ b/components/prism-core.js @@ -531,19 +531,29 @@ var script = document.currentScript || [].slice.call(document.getElementsByTagNa if (script) { _.filename = script.src; + + if (script.hasAttribute('data-manual')) { + _.manual = true; + } +} - if (!_.manual && !script.hasAttribute('data-manual')) { - if(document.readyState !== 'loading') { - if (window.requestAnimationFrame) { - window.requestAnimationFrame(_.highlightAll); - } else { - window.setTimeout(_.highlightAll, 16); - } +if (!_.manual) { + function highlightAutomaticallyCallback() { + if (!_.manual) { + _.highlightAll(); } - else { - document.addEventListener('DOMContentLoaded', _.highlightAll); + } + + if(document.readyState !== 'loading') { + if (window.requestAnimationFrame) { + window.requestAnimationFrame(highlightAutomaticallyCallback); + } else { + window.setTimeout(highlightAutomaticallyCallback, 16); } } + else { + document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback); + } } return _; diff --git a/components/prism-core.min.js b/components/prism-core.min.js index ce0c4a49d6..d7e53f2afc 100644 --- a/components/prism-core.min.js +++ b/components/prism-core.min.js @@ -1 +1 @@ -var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(c){var g=/\blang(?:uage)?-([\w-]+)\b/i,a=0;var _={manual:c.Prism&&c.Prism.manual,disableWorkerMessageHandler:c.Prism&&c.Prism.disableWorkerMessageHandler,util:{encode:function(e){return e instanceof L?new L(e.type,_.util.encode(e.content),e.alias):Array.isArray(e)?e.map(_.util.encode):e.replace(/&/g,"&").replace(/e.length)return;if(!(k instanceof L)){if(f&&y!=a.length-1){if(g.lastIndex=v,!(x=g.exec(e)))break;for(var b=x.index+(h&&x[1]?x[1].length:0),w=x.index+x[0].length,A=y,P=v,O=a.length;A"+n.content+""},!c.document)return c.addEventListener&&(_.disableWorkerMessageHandler||c.addEventListener("message",function(e){var a=JSON.parse(e.data),n=a.language,r=a.code,t=a.immediateClose;c.postMessage(_.highlight(r,_.languages[n],n)),t&&c.close()},!1)),_;var e=document.currentScript||[].slice.call(document.getElementsByTagName("script")).pop();return e&&(_.filename=e.src,_.manual||e.hasAttribute("data-manual")||("loading"!==document.readyState?window.requestAnimationFrame?window.requestAnimationFrame(_.highlightAll):window.setTimeout(_.highlightAll,16):document.addEventListener("DOMContentLoaded",_.highlightAll))),_}(_self);"undefined"!=typeof module&&module.exports&&(module.exports=Prism),"undefined"!=typeof global&&(global.Prism=Prism); \ No newline at end of file +var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(u){var c=/\blang(?:uage)?-([\w-]+)\b/i,a=0;var _={manual:u.Prism&&u.Prism.manual,disableWorkerMessageHandler:u.Prism&&u.Prism.disableWorkerMessageHandler,util:{encode:function(e){return e instanceof L?new L(e.type,_.util.encode(e.content),e.alias):Array.isArray(e)?e.map(_.util.encode):e.replace(/&/g,"&").replace(/e.length)return;if(!(k instanceof L)){if(h&&y!=a.length-1){if(c.lastIndex=v,!(x=c.exec(e)))break;for(var b=x.index+(f&&x[1]?x[1].length:0),w=x.index+x[0].length,A=y,P=v,O=a.length;A"+n.content+""},!u.document)return u.addEventListener&&(_.disableWorkerMessageHandler||u.addEventListener("message",function(e){var a=JSON.parse(e.data),n=a.language,r=a.code,t=a.immediateClose;u.postMessage(_.highlight(r,_.languages[n],n)),t&&u.close()},!1)),_;var e=document.currentScript||[].slice.call(document.getElementsByTagName("script")).pop();if(e&&(_.filename=e.src,e.hasAttribute("data-manual")&&(_.manual=!0)),!_.manual){function n(){_.manual||_.highlightAll()}"loading"!==document.readyState?window.requestAnimationFrame?window.requestAnimationFrame(n):window.setTimeout(n,16):document.addEventListener("DOMContentLoaded",n)}return _}(_self);"undefined"!=typeof module&&module.exports&&(module.exports=Prism),"undefined"!=typeof global&&(global.Prism=Prism); \ No newline at end of file diff --git a/index.html b/index.html index 62797b18d0..27c6327ac9 100644 --- a/index.html +++ b/index.html @@ -149,9 +149,16 @@

Basic usage

<pre><code class="language-css">p { color: red }</code></pre>

If you use that pattern, the <pre> will automatically get the language-xxxx class (if it doesn’t already have it) and will be styled as a code block.

-

If you want to prevent any elements from being automatically highlighted, you can use the attribute data-manual on the <script> element you used for prism and use the API. +

If you want to prevent any elements from being automatically highlighted and instead use the API, you can set Prism.manual to true before the DOMContentLoaded event is fired. By setting the data-manual attribute on the <script> element containing Prism core, this will be done automatically. Example:

<script src="prism.js" data-manual></script>
+

or

+
<script>
+window.Prism = window.Prism || {};
+window.Prism.manual = true;
+</script>
+<script src="prism.js"></script>
+

Usage with CDNs

In combination with CDNs, we recommend using the Autoloader plugin which automatically loads languages when necessary.

diff --git a/prism.js b/prism.js index dc0e9c16ef..6a77215d44 100644 --- a/prism.js +++ b/prism.js @@ -536,19 +536,29 @@ var script = document.currentScript || [].slice.call(document.getElementsByTagNa if (script) { _.filename = script.src; + + if (script.hasAttribute('data-manual')) { + _.manual = true; + } +} - if (!_.manual && !script.hasAttribute('data-manual')) { - if(document.readyState !== 'loading') { - if (window.requestAnimationFrame) { - window.requestAnimationFrame(_.highlightAll); - } else { - window.setTimeout(_.highlightAll, 16); - } +if (!_.manual) { + function highlightAutomaticallyCallback() { + if (!_.manual) { + _.highlightAll(); } - else { - document.addEventListener('DOMContentLoaded', _.highlightAll); + } + + if(document.readyState !== 'loading') { + if (window.requestAnimationFrame) { + window.requestAnimationFrame(highlightAutomaticallyCallback); + } else { + window.setTimeout(highlightAutomaticallyCallback, 16); } } + else { + document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback); + } } return _;