mirror of
https://github.com/oneclickvirt/oneclickvirt.github.io.git
synced 2026-05-29 22:29:41 +08:00
Update
This commit is contained in:
198
node_modules/prismjs/plugins/normalize-whitespace/prism-normalize-whitespace.js
generated
vendored
Normal file
198
node_modules/prismjs/plugins/normalize-whitespace/prism-normalize-whitespace.js
generated
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
(function () {
|
||||
|
||||
if (typeof Prism === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
var assign = Object.assign || function (obj1, obj2) {
|
||||
for (var name in obj2) {
|
||||
if (obj2.hasOwnProperty(name)) {
|
||||
obj1[name] = obj2[name];
|
||||
}
|
||||
}
|
||||
return obj1;
|
||||
};
|
||||
|
||||
function NormalizeWhitespace(defaults) {
|
||||
this.defaults = assign({}, defaults);
|
||||
}
|
||||
|
||||
function toCamelCase(value) {
|
||||
return value.replace(/-(\w)/g, function (match, firstChar) {
|
||||
return firstChar.toUpperCase();
|
||||
});
|
||||
}
|
||||
|
||||
function tabLen(str) {
|
||||
var res = 0;
|
||||
for (var i = 0; i < str.length; ++i) {
|
||||
if (str.charCodeAt(i) == '\t'.charCodeAt(0)) {
|
||||
res += 3;
|
||||
}
|
||||
}
|
||||
return str.length + res;
|
||||
}
|
||||
|
||||
NormalizeWhitespace.prototype = {
|
||||
setDefaults: function (defaults) {
|
||||
this.defaults = assign(this.defaults, defaults);
|
||||
},
|
||||
normalize: function (input, settings) {
|
||||
settings = assign(this.defaults, settings);
|
||||
|
||||
for (var name in settings) {
|
||||
var methodName = toCamelCase(name);
|
||||
if (name !== 'normalize' && methodName !== 'setDefaults' &&
|
||||
settings[name] && this[methodName]) {
|
||||
input = this[methodName].call(this, input, settings[name]);
|
||||
}
|
||||
}
|
||||
|
||||
return input;
|
||||
},
|
||||
|
||||
/*
|
||||
* Normalization methods
|
||||
*/
|
||||
leftTrim: function (input) {
|
||||
return input.replace(/^\s+/, '');
|
||||
},
|
||||
rightTrim: function (input) {
|
||||
return input.replace(/\s+$/, '');
|
||||
},
|
||||
tabsToSpaces: function (input, spaces) {
|
||||
spaces = spaces|0 || 4;
|
||||
return input.replace(/\t/g, new Array(++spaces).join(' '));
|
||||
},
|
||||
spacesToTabs: function (input, spaces) {
|
||||
spaces = spaces|0 || 4;
|
||||
return input.replace(RegExp(' {' + spaces + '}', 'g'), '\t');
|
||||
},
|
||||
removeTrailing: function (input) {
|
||||
return input.replace(/\s*?$/gm, '');
|
||||
},
|
||||
// Support for deprecated plugin remove-initial-line-feed
|
||||
removeInitialLineFeed: function (input) {
|
||||
return input.replace(/^(?:\r?\n|\r)/, '');
|
||||
},
|
||||
removeIndent: function (input) {
|
||||
var indents = input.match(/^[^\S\n\r]*(?=\S)/gm);
|
||||
|
||||
if (!indents || !indents[0].length) {
|
||||
return input;
|
||||
}
|
||||
|
||||
indents.sort(function (a, b) { return a.length - b.length; });
|
||||
|
||||
if (!indents[0].length) {
|
||||
return input;
|
||||
}
|
||||
|
||||
return input.replace(RegExp('^' + indents[0], 'gm'), '');
|
||||
},
|
||||
indent: function (input, tabs) {
|
||||
return input.replace(/^[^\S\n\r]*(?=\S)/gm, new Array(++tabs).join('\t') + '$&');
|
||||
},
|
||||
breakLines: function (input, characters) {
|
||||
characters = (characters === true) ? 80 : characters|0 || 80;
|
||||
|
||||
var lines = input.split('\n');
|
||||
for (var i = 0; i < lines.length; ++i) {
|
||||
if (tabLen(lines[i]) <= characters) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var line = lines[i].split(/(\s+)/g);
|
||||
var len = 0;
|
||||
|
||||
for (var j = 0; j < line.length; ++j) {
|
||||
var tl = tabLen(line[j]);
|
||||
len += tl;
|
||||
if (len > characters) {
|
||||
line[j] = '\n' + line[j];
|
||||
len = tl;
|
||||
}
|
||||
}
|
||||
lines[i] = line.join('');
|
||||
}
|
||||
return lines.join('\n');
|
||||
}
|
||||
};
|
||||
|
||||
// Support node modules
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = NormalizeWhitespace;
|
||||
}
|
||||
|
||||
Prism.plugins.NormalizeWhitespace = new NormalizeWhitespace({
|
||||
'remove-trailing': true,
|
||||
'remove-indent': true,
|
||||
'left-trim': true,
|
||||
'right-trim': true,
|
||||
/*'break-lines': 80,
|
||||
'indent': 2,
|
||||
'remove-initial-line-feed': false,
|
||||
'tabs-to-spaces': 4,
|
||||
'spaces-to-tabs': 4*/
|
||||
});
|
||||
|
||||
Prism.hooks.add('before-sanity-check', function (env) {
|
||||
var Normalizer = Prism.plugins.NormalizeWhitespace;
|
||||
|
||||
// Check settings
|
||||
if (env.settings && env.settings['whitespace-normalization'] === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check classes
|
||||
if (!Prism.util.isActive(env.element, 'whitespace-normalization', true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Simple mode if there is no env.element
|
||||
if ((!env.element || !env.element.parentNode) && env.code) {
|
||||
env.code = Normalizer.normalize(env.code, env.settings);
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal mode
|
||||
var pre = env.element.parentNode;
|
||||
if (!env.code || !pre || pre.nodeName.toLowerCase() !== 'pre') {
|
||||
return;
|
||||
}
|
||||
|
||||
var children = pre.childNodes;
|
||||
var before = '';
|
||||
var after = '';
|
||||
var codeFound = false;
|
||||
|
||||
// Move surrounding whitespace from the <pre> tag into the <code> tag
|
||||
for (var i = 0; i < children.length; ++i) {
|
||||
var node = children[i];
|
||||
|
||||
if (node == env.element) {
|
||||
codeFound = true;
|
||||
} else if (node.nodeName === '#text') {
|
||||
if (codeFound) {
|
||||
after += node.nodeValue;
|
||||
} else {
|
||||
before += node.nodeValue;
|
||||
}
|
||||
|
||||
pre.removeChild(node);
|
||||
--i;
|
||||
}
|
||||
}
|
||||
|
||||
if (!env.element.children.length || !Prism.plugins.KeepMarkup) {
|
||||
env.code = before + env.code + after;
|
||||
env.code = Normalizer.normalize(env.code, env.settings);
|
||||
} else {
|
||||
// Preserve markup for keep-markup plugin
|
||||
var html = before + env.element.innerHTML + after;
|
||||
env.element.innerHTML = Normalizer.normalize(html, env.settings);
|
||||
env.code = env.element.textContent;
|
||||
}
|
||||
});
|
||||
|
||||
}());
|
||||
1
node_modules/prismjs/plugins/normalize-whitespace/prism-normalize-whitespace.min.js
generated
vendored
Normal file
1
node_modules/prismjs/plugins/normalize-whitespace/prism-normalize-whitespace.min.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(){if("undefined"!=typeof Prism){var e=Object.assign||function(e,n){for(var t in n)n.hasOwnProperty(t)&&(e[t]=n[t]);return e};n.prototype={setDefaults:function(n){this.defaults=e(this.defaults,n)},normalize:function(n,t){for(var r in t=e(this.defaults,t)){var i=r.replace(/-(\w)/g,(function(e,n){return n.toUpperCase()}));"normalize"!==r&&"setDefaults"!==i&&t[r]&&this[i]&&(n=this[i].call(this,n,t[r]))}return n},leftTrim:function(e){return e.replace(/^\s+/,"")},rightTrim:function(e){return e.replace(/\s+$/,"")},tabsToSpaces:function(e,n){return n=0|n||4,e.replace(/\t/g,new Array(++n).join(" "))},spacesToTabs:function(e,n){return n=0|n||4,e.replace(RegExp(" {"+n+"}","g"),"\t")},removeTrailing:function(e){return e.replace(/\s*?$/gm,"")},removeInitialLineFeed:function(e){return e.replace(/^(?:\r?\n|\r)/,"")},removeIndent:function(e){var n=e.match(/^[^\S\n\r]*(?=\S)/gm);return n&&n[0].length?(n.sort((function(e,n){return e.length-n.length})),n[0].length?e.replace(RegExp("^"+n[0],"gm"),""):e):e},indent:function(e,n){return e.replace(/^[^\S\n\r]*(?=\S)/gm,new Array(++n).join("\t")+"$&")},breakLines:function(e,n){n=!0===n?80:0|n||80;for(var r=e.split("\n"),i=0;i<r.length;++i)if(!(t(r[i])<=n)){for(var o=r[i].split(/(\s+)/g),a=0,l=0;l<o.length;++l){var s=t(o[l]);(a+=s)>n&&(o[l]="\n"+o[l],a=s)}r[i]=o.join("")}return r.join("\n")}},"undefined"!=typeof module&&module.exports&&(module.exports=n),Prism.plugins.NormalizeWhitespace=new n({"remove-trailing":!0,"remove-indent":!0,"left-trim":!0,"right-trim":!0}),Prism.hooks.add("before-sanity-check",(function(e){var n=Prism.plugins.NormalizeWhitespace;if((!e.settings||!1!==e.settings["whitespace-normalization"])&&Prism.util.isActive(e.element,"whitespace-normalization",!0))if(e.element&&e.element.parentNode||!e.code){var t=e.element.parentNode;if(e.code&&t&&"pre"===t.nodeName.toLowerCase()){for(var r=t.childNodes,i="",o="",a=!1,l=0;l<r.length;++l){var s=r[l];s==e.element?a=!0:"#text"===s.nodeName&&(a?o+=s.nodeValue:i+=s.nodeValue,t.removeChild(s),--l)}if(e.element.children.length&&Prism.plugins.KeepMarkup){var c=i+e.element.innerHTML+o;e.element.innerHTML=n.normalize(c,e.settings),e.code=e.element.textContent}else e.code=i+e.code+o,e.code=n.normalize(e.code,e.settings)}}else e.code=n.normalize(e.code,e.settings)}))}function n(n){this.defaults=e({},n)}function t(e){for(var n=0,t=0;t<e.length;++t)e.charCodeAt(t)=="\t".charCodeAt(0)&&(n+=3);return e.length+n}}();
|
||||
Reference in New Issue
Block a user