From 82d0ca15e85574e14d5714cdf2b989a5a9a36143 Mon Sep 17 00:00:00 2001 From: at055612 <22818309+at055612@users.noreply.github.com> Date: Wed, 2 Feb 2022 12:20:48 +0000 Subject: [PATCH] Command Line: Added span around command and output (#3312) --- plugins/command-line/prism-command-line.js | 9 +++++++-- plugins/command-line/prism-command-line.min.js | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/command-line/prism-command-line.js b/plugins/command-line/prism-command-line.js index 029d15e4dd..c54697768f 100644 --- a/plugins/command-line/prism-command-line.js +++ b/plugins/command-line/prism-command-line.js @@ -130,9 +130,14 @@ // Reinsert the output lines into the highlighted code. -- cwells var codeLines = env.highlightedCode.split('\n'); var outputLines = commandLine.outputLines || []; - for (var i = 0, l = outputLines.length; i < l; i++) { + for (var i = 0, l = codeLines.length; i < l; i++) { + // Add spans to allow distinction of input/output text for styling if (outputLines.hasOwnProperty(i)) { - codeLines[i] = outputLines[i]; + codeLines[i] = '' + + outputLines[i] + ''; + } else { + codeLines[i] = '' + + codeLines[i] + ''; } } env.highlightedCode = codeLines.join('\n'); diff --git a/plugins/command-line/prism-command-line.min.js b/plugins/command-line/prism-command-line.min.js index 867b6a64cd..cfef753cba 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 d=/(?:^|\s)command-line(?:\s|$)/,f="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)&&(d.test(n.className)||d.test(e.element.className))){var a=e.element.querySelector("."+f);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=p('',r);var o=document.createElement("span");o.className=f,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'+a[r]+"":n[r]=''+n[r]+"";e.highlightedCode=n.join("\n")}}),Prism.hooks.add("complete",function(e){if(function(e){return"command-line"in(e.vars=e.vars||{})}(e)){var t=h(e);if(!t.complete){var n,a=e.element.parentElement;p.test(e.element.className)&&(e.element.className=e.element.className.replace(p," ")),p.test(a.className)||(a.className+=" command-line");var r=t.numberOfLines||0,s=u("data-prompt","");if(""!==s)n=f('',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;l