use prism-tomorrow.css

This commit is contained in:
CyC2018
2018-12-19 14:09:39 +08:00
parent 0f00bcacaf
commit e9e604e6a7
1747 changed files with 100462 additions and 0 deletions

View File

@ -0,0 +1,111 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="favicon.png" />
<title>Command Line ▲ Prism plugins</title>
<base href="../.." />
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="themes/prism.css" data-noprefix />
<link rel="stylesheet" href="plugins/command-line/prism-command-line.css" data-noprefix />
<script src="prefixfree.min.js"></script>
<script>var _gaq = [['_setAccount', 'UA-33746269-1'], ['_trackPageview']];</script>
<script src="https://www.google-analytics.com/ga.js" async></script>
</head>
<body>
<header>
<div class="intro" data-src="templates/header-plugins.html" data-type="text/html"></div>
<h2>Command Line</h2>
<p>Display a command line with a prompt and, optionally, the output/response from the commands.</p>
</header>
<section class="language-markup">
<h1>How to use</h1>
<p>This is intended for code blocks (<code class="language-markup">&lt;pre>&lt;code></code>) and not for inline code.</p>
<p>Add class <strong>command-line</strong> to your <code class="language-markup">&lt;pre></code>. For a server command line, specify the user and host names using the <code class="language-markup">data-user</code> and <code class="language-markup">data-host</code> attributes. The resulting prompt displays a <strong>#</strong> for the root user and <strong>$</strong> for all other users. For any other command line, such as a Windows prompt, you may specify the entire prompt using the <code class="language-markup">data-prompt</code> attribute.</p>
<p>Optional: You may specify the lines to be presented as output (no prompt and no highlighting) through the <code class="language-markup">data-output</code> attribute on the <code class="language-markup">&lt;pre></code> element in the following simple format:</p>
<ul>
<li>A single number refers to the line with that number</li>
<li>Ranges are denoted by two numbers, separated with a hyphen (-)</li>
<li>Multiple line numbers or ranges are separated by commas.</li>
<li>Whitespace is allowed anywhere and will be stripped off.</li>
</ul>
<p>Examples:</p>
<dl>
<dt>5</dt>
<dd>The 5th line</dd>
<dt>1-5</dt>
<dd>Lines 1 through 5</dd>
<dt>1,4</dt>
<dd>Line 1 and line 4</dd>
<dt>1-2, 5, 9-20</dt>
<dd>Lines 1 through 2, line 5, lines 9 through 20</dd>
</dl>
<p>Optional: To automatically present some lines as output, you can prefix those lines with any string and specify the prefix using the <code class="language-markup">data-filter-output</code> attribute on the <code class="language-markup">&lt;pre></code> element. For example, <code class="language-markup">data-filter-output="(out)"</code> will treat lines beginning with <code class="language-markup">(out)</code> as output and remove the prefix.</p>
</section>
<section>
<h1>Examples</h1>
<h2>Root User Without Output</h2>
<pre class="command-line" data-user="root" data-host="localhost"><code class="language-bash">cd /usr/local/etc
cp php.ini php.ini.bak
vi php.ini</code></pre>
<h2>Non-Root User With Output</h2>
<pre class="command-line" data-user="chris" data-host="remotehost" data-output="2, 4-8"><code class="language-bash">pwd
/usr/home/chris/bin
ls -la
total 2
drwxr-xr-x 2 chris chris 11 Jan 10 16:48 .
drwxr--r-x 45 chris chris 92 Feb 14 11:10 ..
-rwxr-xr-x 1 chris chris 444 Aug 25 2013 backup
-rwxr-xr-x 1 chris chris 642 Jan 17 14:42 deploy</code></pre>
<h2>Windows PowerShell With Output</h2>
<pre class="command-line" data-prompt="PS C:\Users\Chris>" data-output="2-19"><code class="language-powershell">dir
Directory: C:\Users\Chris
Mode LastWriteTime Length Name
---- ------------- ------ ----
d-r-- 10/14/2015 5:06 PM Contacts
d-r-- 12/12/2015 1:47 PM Desktop
d-r-- 11/4/2015 7:59 PM Documents
d-r-- 10/14/2015 5:06 PM Downloads
d-r-- 10/14/2015 5:06 PM Favorites
d-r-- 10/14/2015 5:06 PM Links
d-r-- 10/14/2015 5:06 PM Music
d-r-- 10/14/2015 5:06 PM Pictures
d-r-- 10/14/2015 5:06 PM Saved Games
d-r-- 10/14/2015 5:06 PM Searches
d-r-- 10/14/2015 5:06 PM Videos</code></pre>
</section>
<footer data-src="templates/footer.html" data-type="text/html"></footer>
<script src="prism.js"></script>
<script src="plugins/command-line/prism-command-line.js"></script>
<script src="utopia.js"></script>
<script src="components.js"></script>
<script src="code.js"></script>
<script src="components/prism-bash.js"></script>
<script src="components/prism-powershell.js"></script>
</body>
</html>

View File

@ -0,0 +1,33 @@
.command-line-prompt {
border-right: 1px solid #999;
display: block;
float: left;
font-size: 100%;
letter-spacing: -1px;
margin-right: 1em;
pointer-events: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.command-line-prompt > span:before {
color: #999;
content: ' ';
display: block;
padding-right: 0.8em;
}
.command-line-prompt > span[data-user]:before {
content: "[" attr(data-user) "@" attr(data-host) "] $";
}
.command-line-prompt > span[data-user="root"]:before {
content: "[" attr(data-user) "@" attr(data-host) "] #";
}
.command-line-prompt > span[data-prompt]:before {
content: attr(data-prompt);
}

View File

@ -0,0 +1,139 @@
(function() {
if (typeof self === 'undefined' || !self.Prism || !self.document) {
return;
}
var clsReg = /(?:^|\s)command-line(?:\s|$)/;
Prism.hooks.add('before-highlight', function (env) {
var vars = env.vars = env.vars || {};
var commandLine = vars['command-line'] = vars['command-line'] || {};
if (commandLine.complete || !env.code) {
commandLine.complete = true;
return;
}
// Works only for <code> wrapped inside <pre> (not inline).
var pre = env.element.parentNode;
if (!pre || !/pre/i.test(pre.nodeName) || // Abort only if neither the <pre> nor the <code> have the class
(!clsReg.test(pre.className) && !clsReg.test(env.element.className))) {
commandLine.complete = true;
return;
}
if (env.element.querySelector('.command-line-prompt')) { // Abort if prompt already exists.
commandLine.complete = true;
return;
}
var codeLines = env.code.split('\n');
commandLine.numberOfLines = codeLines.length;
var outputLines = commandLine.outputLines = [];
var outputSections = pre.getAttribute('data-output');
var outputFilter = pre.getAttribute('data-filter-output');
if (outputSections || outputSections === '') { // The user specified the output lines. -- cwells
outputSections = outputSections.split(',');
for (var i = 0; i < outputSections.length; i++) { // Parse the output sections into start/end ranges. -- cwells
var range = outputSections[i].split('-');
var outputStart = parseInt(range[0], 10);
var outputEnd = (range.length === 2 ? parseInt(range[1], 10) : outputStart);
if (!isNaN(outputStart) && !isNaN(outputEnd)) {
if (outputStart < 1) {
outputStart = 1;
}
if (outputEnd > codeLines.length) {
outputEnd = codeLines.length;
}
// Convert start and end to 0-based to simplify the arrays. -- cwells
outputStart--;
outputEnd--;
// Save the output line in an array and clear it in the code so it's not highlighted. -- cwells
for (var j = outputStart; j <= outputEnd; j++) {
outputLines[j] = codeLines[j];
codeLines[j] = '';
}
}
}
} else if (outputFilter) { // Treat lines beginning with this string as output. -- cwells
for (var i = 0; i < codeLines.length; i++) {
if (codeLines[i].indexOf(outputFilter) === 0) { // This line is output. -- cwells
outputLines[i] = codeLines[i].slice(outputFilter.length);
codeLines[i] = '';
}
}
}
env.code = codeLines.join('\n');
});
Prism.hooks.add('before-insert', function (env) {
var vars = env.vars = env.vars || {};
var commandLine = vars['command-line'] = vars['command-line'] || {};
if (commandLine.complete) {
return;
}
// Reinsert the output lines into the highlighted code. -- cwells
var codeLines = env.highlightedCode.split('\n');
for (var i = 0; i < commandLine.outputLines.length; i++) {
if (commandLine.outputLines.hasOwnProperty(i)) {
codeLines[i] = commandLine.outputLines[i];
}
}
env.highlightedCode = codeLines.join('\n');
});
Prism.hooks.add('complete', function (env) {
var vars = env.vars = env.vars || {};
var commandLine = vars['command-line'] = vars['command-line'] || {};
if (commandLine.complete) {
return;
}
var pre = env.element.parentNode;
if (clsReg.test(env.element.className)) { // Remove the class "command-line" from the <code>
env.element.className = env.element.className.replace(clsReg, ' ');
}
if (!clsReg.test(pre.className)) { // Add the class "command-line" to the <pre>
pre.className += ' command-line';
}
var getAttribute = function(key, defaultValue) {
return (pre.getAttribute(key) || defaultValue).replace(/"/g, '&quot');
};
// Create the "rows" that will become the command-line prompts. -- cwells
var promptLines = new Array(commandLine.numberOfLines + 1);
var promptText = getAttribute('data-prompt', '');
if (promptText !== '') {
promptLines = promptLines.join('<span data-prompt="' + promptText + '"></span>');
} else {
var user = getAttribute('data-user', 'user');
var host = getAttribute('data-host', 'localhost');
promptLines = promptLines.join('<span data-user="' + user + '" data-host="' + host + '"></span>');
}
// Create the wrapper element. -- cwells
var prompt = document.createElement('span');
prompt.className = 'command-line-prompt';
prompt.innerHTML = promptLines;
// Remove the prompt from the output lines. -- cwells
for (var i = 0; i < commandLine.outputLines.length; i++) {
if (commandLine.outputLines.hasOwnProperty(i)) {
var node = prompt.children[i];
node.removeAttribute('data-user');
node.removeAttribute('data-host');
node.removeAttribute('data-prompt');
}
}
env.element.insertBefore(prompt, env.element.firstChild);
commandLine.complete = true;
});
}());

View File

@ -0,0 +1 @@
!function(){if("undefined"!=typeof self&&self.Prism&&self.document){var e=/(?:^|\s)command-line(?:\s|$)/;Prism.hooks.add("before-highlight",function(t){var a=t.vars=t.vars||{},n=a["command-line"]=a["command-line"]||{};if(n.complete||!t.code)return n.complete=!0,void 0;var r=t.element.parentNode;if(!r||!/pre/i.test(r.nodeName)||!e.test(r.className)&&!e.test(t.element.className))return n.complete=!0,void 0;if(t.element.querySelector(".command-line-prompt"))return n.complete=!0,void 0;var o=t.code.split("\n");n.numberOfLines=o.length;var s=n.outputLines=[],i=r.getAttribute("data-output"),l=r.getAttribute("data-filter-output");if(i||""===i){i=i.split(",");for(var m=0;m<i.length;m++){var d=i[m].split("-"),p=parseInt(d[0],10),c=2===d.length?parseInt(d[1],10):p;if(!isNaN(p)&&!isNaN(c)){1>p&&(p=1),c>o.length&&(c=o.length),p--,c--;for(var u=p;c>=u;u++)s[u]=o[u],o[u]=""}}}else if(l)for(var m=0;m<o.length;m++)0===o[m].indexOf(l)&&(s[m]=o[m].slice(l.length),o[m]="");t.code=o.join("\n")}),Prism.hooks.add("before-insert",function(e){var t=e.vars=e.vars||{},a=t["command-line"]=t["command-line"]||{};if(!a.complete){for(var n=e.highlightedCode.split("\n"),r=0;r<a.outputLines.length;r++)a.outputLines.hasOwnProperty(r)&&(n[r]=a.outputLines[r]);e.highlightedCode=n.join("\n")}}),Prism.hooks.add("complete",function(t){var a=t.vars=t.vars||{},n=a["command-line"]=a["command-line"]||{};if(!n.complete){var r=t.element.parentNode;e.test(t.element.className)&&(t.element.className=t.element.className.replace(e," ")),e.test(r.className)||(r.className+=" command-line");var o=function(e,t){return(r.getAttribute(e)||t).replace(/"/g,"&quot")},s=new Array(n.numberOfLines+1),i=o("data-prompt","");if(""!==i)s=s.join('<span data-prompt="'+i+'"></span>');else{var l=o("data-user","user"),m=o("data-host","localhost");s=s.join('<span data-user="'+l+'" data-host="'+m+'"></span>')}var d=document.createElement("span");d.className="command-line-prompt",d.innerHTML=s;for(var p=0;p<n.outputLines.length;p++)if(n.outputLines.hasOwnProperty(p)){var c=d.children[p];c.removeAttribute("data-user"),c.removeAttribute("data-host"),c.removeAttribute("data-prompt")}t.element.insertBefore(d,t.element.firstChild),n.complete=!0}})}}();