diff --git a/plugins/command-line/prism-command-line.js b/plugins/command-line/prism-command-line.js index 31a3fc6f4d..029d15e4dd 100644 --- a/plugins/command-line/prism-command-line.js +++ b/plugins/command-line/prism-command-line.js @@ -29,6 +29,16 @@ return s; } + /** + * Returns whether the given hook environment has a command line info object. + * + * @param {any} env + * @returns {boolean} + */ + function hasCommandLineInfo(env) { + var vars = env.vars = env.vars || {}; + return 'command-line' in vars; + } /** * Returns the command line info object from the given hook environment. * @@ -129,6 +139,11 @@ }); Prism.hooks.add('complete', function (env) { + if (!hasCommandLineInfo(env)) { + // the previous hooks never ran + return; + } + var commandLine = getCommandLineInfo(env); if (commandLine.complete) { diff --git a/plugins/command-line/prism-command-line.min.js b/plugins/command-line/prism-command-line.min.js index 17adf7a482..867b6a64cd 100644 --- a/plugins/command-line/prism-command-line.min.js +++ b/plugins/command-line/prism-command-line.min.js @@ -1 +1 @@ -!function(){if("undefined"!=typeof Prism&&"undefined"!=typeof document){var p=/(?:^|\s)command-line(?:\s|$)/,d="command-line-prompt",m="".startsWith?function(e,t){return e.startsWith(t)}:function(e,t){return 0===e.indexOf(t)};Prism.hooks.add("before-highlight",function(e){var t=h(e);if(!t.complete&&e.code){var n=e.element.parentElement;if(n&&/pre/i.test(n.nodeName)&&(p.test(n.className)||p.test(e.element.className))){var a=e.element.querySelector("."+d);a&&a.remove();var s=e.code.split("\n");t.numberOfLines=s.length;var o=t.outputLines=[],r=n.getAttribute("data-output"),i=n.getAttribute("data-filter-output");if(null!==r)r.split(",").forEach(function(e){var t=e.split("-"),n=parseInt(t[0],10),a=2===t.length?parseInt(t[1],10):n;if(!isNaN(n)&&!isNaN(a)){n<1&&(n=1),a>s.length&&(a=s.length),a--;for(var r=--n;r<=a;r++)o[r]=s[r],s[r]=""}});else if(i)for(var l=0;l',r);else n=f('',r);var o=document.createElement("span");o.className=d,o.innerHTML=n;for(var i=t.outputLines||[],l=0,m=i.length;ls.length&&(a=s.length),a--;for(var r=--n;r<=a;r++)o[r]=s[r],s[r]=""}});else if(i)for(var l=0;l',r);else n=p('',r);var o=document.createElement("span");o.className=f,o.innerHTML=n;for(var i=t.outputLines||[],l=0,m=i.length;l