08-27-周三_17-09-29
This commit is contained in:
33
node_modules/prismjs/plugins/command-line/prism-command-line.css
generated
vendored
Normal file
33
node_modules/prismjs/plugins/command-line/prism-command-line.css
generated
vendored
Normal 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);
|
||||
}
|
139
node_modules/prismjs/plugins/command-line/prism-command-line.js
generated
vendored
Normal file
139
node_modules/prismjs/plugins/command-line/prism-command-line.js
generated
vendored
Normal 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, l = (commandLine.outputLines || []).length; i < l; 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, '"');
|
||||
};
|
||||
|
||||
// Create the "rows" that will become the command-line prompts. -- cwells
|
||||
var promptLines = new Array((commandLine.numberOfLines || 0) + 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, l = (commandLine.outputLines || []).length; i < l; 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;
|
||||
});
|
||||
|
||||
}());
|
1
node_modules/prismjs/plugins/command-line/prism-command-line.min.js
generated
vendored
Normal file
1
node_modules/prismjs/plugins/command-line/prism-command-line.min.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(){if("undefined"!=typeof self&&self.Prism&&self.document){var u=/(?:^|\s)command-line(?:\s|$)/;Prism.hooks.add("before-highlight",function(e){var t=e.vars=e.vars||{},a=t["command-line"]=t["command-line"]||{};if(!a.complete&&e.code){var n=e.element.parentNode;if(n&&/pre/i.test(n.nodeName)&&(u.test(n.className)||u.test(e.element.className)))if(e.element.querySelector(".command-line-prompt"))a.complete=!0;else{var r=e.code.split("\n");a.numberOfLines=r.length;var s=a.outputLines=[],o=n.getAttribute("data-output"),i=n.getAttribute("data-filter-output");if(o||""===o){o=o.split(",");for(var l=0;l<o.length;l++){var m=o[l].split("-"),p=parseInt(m[0],10),d=2===m.length?parseInt(m[1],10):p;if(!isNaN(p)&&!isNaN(d)){p<1&&(p=1),d>r.length&&(d=r.length),d--;for(var c=--p;c<=d;c++)s[c]=r[c],r[c]=""}}}else if(i)for(l=0;l<r.length;l++)0===r[l].indexOf(i)&&(s[l]=r[l].slice(i.length),r[l]="");e.code=r.join("\n")}else a.complete=!0}else a.complete=!0}),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,s=(a.outputLines||[]).length;r<s;r++)a.outputLines.hasOwnProperty(r)&&(n[r]=a.outputLines[r]);e.highlightedCode=n.join("\n")}}),Prism.hooks.add("complete",function(e){var t=e.vars=e.vars||{},a=t["command-line"]=t["command-line"]||{};if(!a.complete){var n=e.element.parentNode;u.test(e.element.className)&&(e.element.className=e.element.className.replace(u," ")),u.test(n.className)||(n.className+=" command-line");var r=function(e,t){return(n.getAttribute(e)||t).replace(/"/g,""")},s=new Array((a.numberOfLines||0)+1),o=r("data-prompt","");if(""!==o)s=s.join('<span data-prompt="'+o+'"></span>');else{var i=r("data-user","user"),l=r("data-host","localhost");s=s.join('<span data-user="'+i+'" data-host="'+l+'"></span>')}var m=document.createElement("span");m.className="command-line-prompt",m.innerHTML=s;for(var p=0,d=(a.outputLines||[]).length;p<d;p++)if(a.outputLines.hasOwnProperty(p)){var c=m.children[p];c.removeAttribute("data-user"),c.removeAttribute("data-host"),c.removeAttribute("data-prompt")}e.element.insertBefore(m,e.element.firstChild),a.complete=!0}})}}();
|
Reference in New Issue
Block a user