From 26105034da4fcce7ac883c899d781f016559310d Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 8 Nov 2018 00:38:48 +0800 Subject: switch to vuepress --- .../plugins/command-line/prism-command-line.css | 33 +++++ .../plugins/command-line/prism-command-line.js | 139 +++++++++++++++++++++ .../plugins/command-line/prism-command-line.min.js | 1 + 3 files changed, 173 insertions(+) create mode 100644 node_modules/prismjs/plugins/command-line/prism-command-line.css create mode 100644 node_modules/prismjs/plugins/command-line/prism-command-line.js create mode 100644 node_modules/prismjs/plugins/command-line/prism-command-line.min.js (limited to 'node_modules/prismjs/plugins/command-line') diff --git a/node_modules/prismjs/plugins/command-line/prism-command-line.css b/node_modules/prismjs/plugins/command-line/prism-command-line.css new file mode 100644 index 00000000..153a8707 --- /dev/null +++ b/node_modules/prismjs/plugins/command-line/prism-command-line.css @@ -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); +} diff --git a/node_modules/prismjs/plugins/command-line/prism-command-line.js b/node_modules/prismjs/plugins/command-line/prism-command-line.js new file mode 100644 index 00000000..b8595d72 --- /dev/null +++ b/node_modules/prismjs/plugins/command-line/prism-command-line.js @@ -0,0 +1,139 @@ +(function() { + +if (typeof self === 'undefined' || !self.Prism || !self.document) { + return; +} + +var clsReg = /\s*\bcommand-line\b\s*/; + +Prism.hooks.add('before-highlight', function (env) { + env.vars = env.vars || {}; + env.vars['command-line'] = env.vars['command-line'] || {}; + + if (env.vars['command-line'].complete || !env.code) { + env.vars['command-line'].complete = true; + return; + } + + // Works only for wrapped inside
 (not inline).
+	var pre = env.element.parentNode;
+	if (!pre || !/pre/i.test(pre.nodeName) || // Abort only if neither the 
 nor the  have the class
+		(!clsReg.test(pre.className) && !clsReg.test(env.element.className))) {
+		env.vars['command-line'].complete = true;
+		return;
+	}
+
+	if (env.element.querySelector('.command-line-prompt')) { // Abort if prompt already exists.
+		env.vars['command-line'].complete = true;
+		return;
+	}
+
+	var codeLines = env.code.split('\n');
+	env.vars['command-line'].numberOfLines = codeLines.length;
+	env.vars['command-line'].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++) {
+					env.vars['command-line'].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
+				env.vars['command-line'].outputLines[i] = codeLines[i].slice(outputFilter.length);
+				codeLines[i] = '';
+			}
+		}
+	}
+
+	env.code = codeLines.join('\n');
+});
+
+Prism.hooks.add('before-insert', function (env) {
+	env.vars = env.vars || {};
+	env.vars['command-line'] = env.vars['command-line'] || {};
+	if (env.vars['command-line'].complete) {
+		return;
+	}
+
+	// Reinsert the output lines into the highlighted code. -- cwells
+	var codeLines = env.highlightedCode.split('\n');
+	for (var i = 0; i < env.vars['command-line'].outputLines.length; i++) {
+		if (env.vars['command-line'].outputLines.hasOwnProperty(i)) {
+			codeLines[i] = env.vars['command-line'].outputLines[i];
+		}
+	}
+	env.highlightedCode = codeLines.join('\n');
+});
+
+Prism.hooks.add('complete', function (env) {
+	env.vars = env.vars || {};
+	env.vars['command-line'] = env.vars['command-line'] || {};
+	if (env.vars['command-line'].complete) {
+		return;
+	}
+
+	var pre = env.element.parentNode;
+	if (clsReg.test(env.element.className)) { // Remove the class "command-line" from the 
+		env.element.className = env.element.className.replace(clsReg, ' ');
+	}
+	if (!clsReg.test(pre.className)) { // Add the class "command-line" to the 
+		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(env.vars['command-line'].numberOfLines + 1);
+	var promptText = getAttribute('data-prompt', '');
+	if (promptText !== '') {
+		promptLines = promptLines.join('');
+	} else {
+		var user = getAttribute('data-user', 'user');
+		var host = getAttribute('data-host', 'localhost');
+		promptLines = promptLines.join('');
+	}
+
+	// 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 < env.vars['command-line'].outputLines.length; i++) {
+		if (env.vars['command-line'].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);
+	env.vars['command-line'].complete = true;
+});
+
+}());
diff --git a/node_modules/prismjs/plugins/command-line/prism-command-line.min.js b/node_modules/prismjs/plugins/command-line/prism-command-line.min.js
new file mode 100644
index 00000000..159f4094
--- /dev/null
+++ b/node_modules/prismjs/plugins/command-line/prism-command-line.min.js
@@ -0,0 +1 @@
+!function(){if("undefined"!=typeof self&&self.Prism&&self.document){var e=/\s*\bcommand-line\b\s*/;Prism.hooks.add("before-highlight",function(a){if(a.vars=a.vars||{},a.vars["command-line"]=a.vars["command-line"]||{},a.vars["command-line"].complete||!a.code)return a.vars["command-line"].complete=!0,void 0;var n=a.element.parentNode;if(!n||!/pre/i.test(n.nodeName)||!e.test(n.className)&&!e.test(a.element.className))return a.vars["command-line"].complete=!0,void 0;if(a.element.querySelector(".command-line-prompt"))return a.vars["command-line"].complete=!0,void 0;var t=a.code.split("\n");a.vars["command-line"].numberOfLines=t.length,a.vars["command-line"].outputLines=[];var r=n.getAttribute("data-output"),s=n.getAttribute("data-filter-output");if(r||""===r){r=r.split(",");for(var o=0;oi&&(i=1),l>t.length&&(l=t.length),i--,l--;for(var d=i;l>=d;d++)a.vars["command-line"].outputLines[d]=t[d],t[d]=""}}}else if(s)for(var o=0;o');else{var o=t("data-user","user"),m=t("data-host","localhost");r=r.join('')}var i=document.createElement("span");i.className="command-line-prompt",i.innerHTML=r;for(var l=0;l