2023年政策修订增补工作正在进行中,欢迎参与!
MediaWiki:Gadget-DotsSyntaxHighlighter.js
跳转到导航
跳转到搜索
注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox/Safari:按住“Shift”的同时单击“刷新”,或按“Ctrl-F5”或“Ctrl-R”(Mac为“⌘-R”)
- Google Chrome:按“Ctrl-Shift-R”(Mac为“⌘-Shift-R”)
- Internet Explorer:按住“Ctrl”的同时单击“刷新”,或按“Ctrl-F5”
- Opera:在“工具→首选项”中清除缓存
- 如果您已登录但该页面出现未登录状态,请尝试在地址栏的地址最后添加代码
?_=1
来访问最新页面。 - 添加代码后的本页地址如下:
-{R|https://moegirl.icu/MediaWiki:Gadget-DotsSyntaxHighlighter.js?_=1}-
萌娘百科界面管理员团队提醒您
本页面由萌娘百科界面管理员团队在其 GitHub 库内进行维护,通过机器人自动生成可被 MediaWiki Gadget 扩展接受的版本并保存到此处。
如果您有任何意见或建议,建议您到技术实现版提出。
- 本页面的内容为自动生成,手动修改可能会被覆盖,源码可在此处查看;
- 最新修订由 U:AnnAngela 与 U:Bhsd、GH:github-actions[bot] 共同做出,相关 commit 为:bf83eaea - ci: use eslint flat config (#400) [展开/折叠]
Co-authored-by: Bhsd <55071315+bhsd-harry📧users.noreply.github.com>↩Co-authored-by: github-actions[bot] <41898282+github-actions[bot]📧users.noreply.github.com>
/**
* -------------------------------------------------------------------------
* !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
* -------------------------------------------------------------------------
*/
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/DotsSyntaxHighlighter/MediaWiki:Gadget-DotsSyntaxHighlighter.js|user=[[U:AnnAngela]]|co-authors=[[U:Bhsd]]、GH:github-actions[bot]|longId=bf83eaea8eb4d94405bdf6885ec072fec997dd56|shortId=bf83eaea|summary=ci: use eslint flat config (#400)|body=<nowiki>Co-authored-by: Bhsd <55071315+bhsd-harry📧users.noreply.github.com>↩Co-authored-by: github-actions[bot] <41898282+github-actions[bot]📧users.noreply.github.com></nowiki>}}';
/* <pre> */
"use strict";
(function () {
var wpTextbox0;
var wpTextbox1;
var syntaxStyleTextNode;
var lastText;
var maxSpanNumber = -1;
var highlightSyntaxIfNeededIntervalID;
var attributeObserver;
var parentObserver;
var syntaxHighlighterSiteConfig = window.syntaxHighlighterSiteConfig || (window.syntaxHighlighterSiteConfig = {});
var syntaxHighlighterConfig = window.syntaxHighlighterConfig || (window.syntaxHighlighterConfig = {});
var wgUrlProtocols = mw.config.get("wgUrlProtocols");
var entityRegexBase = "&(?:(?:n(?:bsp|dash)|m(?:dash|inus)|lt|e[mn]sp|thinsp|amp|quot|gt|shy|zwn?j|lrm|rlm|Alpha|Beta|Epsilon|Zeta|Eta|Iota|Kappa|[Mm]u|micro|Nu|[Oo]micron|[Rr]ho|Tau|Upsilon|Chi)|#x[0-9a-fA-F]+);\n*";
var breakerRegexBase = "\\[(?:\\[|(?:".concat(wgUrlProtocols, "))|\\{(?:\\{\\{?|\\|)|<(?:[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:\\w\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD-\\.\u00B7\u0300-\u036F\u203F-\u203F-\u2040]*(?=/?>| |\n)|!--[^]*?-->\n*)|(?:").concat(wgUrlProtocols.replace("|\\/\\/", ""), ")[^\\s\"<>[\\]{-}]*[^\\s\",\\.:;<>[\\]{-}]\n*|^(?:=|[*#:;]+\n*|-{4,}\n*)|\\\\'\\\\'(?:\\\\')?|~{3,5}\n*|").concat(entityRegexBase);
var breakerRegexWithPrefix = function (prefix) { return new RegExp("(".concat(prefix, ")\n*|").concat(breakerRegexBase), "gm"); };
var nowikiTagBreakerRegex = function (tagName) { return new RegExp("(</".concat(tagName, ">)\n*|").concat(entityRegexBase), "gm"); };
var defaultBreakerRegex = new RegExp(breakerRegexBase, "gm");
var wikilinkBreakerRegex = breakerRegexWithPrefix("]][a-zA-Z]*");
var namedExternalLinkBreakerRegex = breakerRegexWithPrefix("]");
var parameterBreakerRegex = breakerRegexWithPrefix("}}}");
var templateBreakerRegex = breakerRegexWithPrefix("}}");
var tableBreakerRegex = breakerRegexWithPrefix("\\|}");
var headingBreakerRegex = breakerRegexWithPrefix("\n");
var tagBreakerRegexCache = {};
var nowikiTagBreakerRegexCache = {};
var syncScrollX = function () {
wpTextbox0.scrollLeft = wpTextbox1.scrollLeft;
};
var syncScrollY = function () {
wpTextbox0.scrollTop = wpTextbox1.scrollTop;
};
var highlightSyntax = function () {
lastText = wpTextbox1.value;
var text = "".concat(lastText.replace(/['\\]/g, "\\BODY"), "\n");
var i = 0;
var css = "";
var spanNumber = 0;
var lastColor;
var writeText = function (text, color) {
if (color !== lastColor) {
css += "'}";
if (color) {
css += "#s".concat(spanNumber, "{background-color:").concat(color, "}");
}
css += "#s".concat(spanNumber, "::after{content:'");
lastColor = color;
spanNumber++;
}
css += text;
};
var highlightBlock = function (color, breakerRegex, _assumedBold, _assumedItalic) {
var match;
var assumedBold = _assumedBold;
var assumedItalic = _assumedItalic;
breakerRegex.lastIndex = i;
while (Number.MAX_SAFE_INTEGER > Number.MIN_SAFE_INTEGER) {
match = breakerRegex.exec(text);
if (match[1]) {
writeText(text.substring(i, breakerRegex.lastIndex), color);
i = breakerRegex.lastIndex;
return;
}
var endIndexOfLastColor = breakerRegex.lastIndex - match[0].length;
if (i < endIndexOfLastColor) {
writeText(text.substring(i, endIndexOfLastColor), color);
}
i = breakerRegex.lastIndex;
switch (match[0].charAt(0)) {
case "[":
if (match[0].charAt(1) === "[") {
writeText("[[", syntaxHighlighterConfig.wikilinkColor || color);
highlightBlock(syntaxHighlighterConfig.wikilinkColor || color, wikilinkBreakerRegex);
}
else {
writeText(match[0], syntaxHighlighterConfig.externalLinkColor || color);
highlightBlock(syntaxHighlighterConfig.externalLinkColor || color, namedExternalLinkBreakerRegex);
}
break;
case "{":
if (match[0].charAt(1) === "{") {
if (match[0].length === 3) {
writeText("{{{", syntaxHighlighterConfig.parameterColor || color);
highlightBlock(syntaxHighlighterConfig.parameterColor || color, parameterBreakerRegex);
}
else {
writeText("{{", syntaxHighlighterConfig.templateColor || color);
highlightBlock(syntaxHighlighterConfig.templateColor || color, templateBreakerRegex);
}
}
else {
writeText("{|", syntaxHighlighterConfig.tableColor || color);
highlightBlock(syntaxHighlighterConfig.tableColor || color, tableBreakerRegex);
}
break;
case "<":
if (match[0].charAt(1) === "!") {
writeText(match[0], syntaxHighlighterConfig.commentColor || color);
break;
}
else {
var tagEnd = text.indexOf(">", i) + 1;
if (tagEnd === 0) {
writeText("<", color);
i = i - match[0].length + 1;
break;
}
if (text.charAt(tagEnd - 2) === "/" || syntaxHighlighterConfig.voidTags.includes(match[0].substring(1))) {
writeText(text.substring(i - match[0].length, tagEnd), syntaxHighlighterConfig.tagColor || color);
i = tagEnd;
}
else {
var tagName = match[0].substring(1);
if (syntaxHighlighterConfig.sourceTags.includes(tagName)) {
var stopAfter = "</".concat(tagName, ">");
var endIndex = text.indexOf(stopAfter, i);
if (endIndex === -1) {
endIndex = text.length;
}
else {
endIndex += stopAfter.length;
}
writeText(text.substring(i - match[0].length, endIndex), syntaxHighlighterConfig.tagColor || color);
i = endIndex;
}
else if (syntaxHighlighterConfig.nowikiTags.includes(tagName)) {
writeText(text.substring(i - match[0].length, tagEnd), syntaxHighlighterConfig.tagColor || color);
i = tagEnd;
highlightBlock(syntaxHighlighterConfig.tagColor || color, nowikiTagBreakerRegexCache[tagName]);
}
else {
writeText(text.substring(i - match[0].length, tagEnd), syntaxHighlighterConfig.tagColor || color);
i = tagEnd;
if (!tagBreakerRegexCache[tagName]) {
tagBreakerRegexCache[tagName] = breakerRegexWithPrefix("</".concat(tagName, ">"));
}
highlightBlock(syntaxHighlighterConfig.tagColor || color, tagBreakerRegexCache[tagName]);
}
}
}
break;
case "=":
if (/[^=]=+$/.test(text.substring(i, text.indexOf("\n", i)))) {
writeText("=", syntaxHighlighterConfig.headingColor || color);
highlightBlock(syntaxHighlighterConfig.headingColor || color, headingBreakerRegex);
}
else {
writeText("=", color);
}
break;
case "*":
case "#":
case ":":
writeText(match[0], syntaxHighlighterConfig.listOrIndentColor || color);
break;
case ";":
writeText(";", syntaxHighlighterConfig.headingColor || color);
highlightBlock(syntaxHighlighterConfig.headingColor || color, headingBreakerRegex);
break;
case "-":
writeText(match[0], syntaxHighlighterConfig.hrColor || color);
break;
case "\\":
writeText(match[0], syntaxHighlighterConfig.boldOrItalicColor || color);
if (match[0].length === 6) {
if (assumedBold) {
if (assumedItalic) {
assumedBold = false;
}
else {
return;
}
}
else {
if (assumedItalic) {
assumedBold = true;
}
else {
highlightBlock(syntaxHighlighterConfig.boldOrItalicColor || color, defaultBreakerRegex, true, false);
}
}
}
else {
if (assumedItalic) {
if (assumedBold) {
assumedItalic = false;
}
else {
return;
}
}
else {
if (assumedBold) {
assumedItalic = true;
}
else {
highlightBlock(syntaxHighlighterConfig.boldOrItalicColor || color, defaultBreakerRegex, false, true);
}
}
}
break;
case "&":
writeText(match[0], syntaxHighlighterConfig.entityColor || color);
break;
case "~":
writeText(match[0], syntaxHighlighterConfig.signatureColor || color);
break;
default:
writeText(match[0], syntaxHighlighterConfig.externalLinkColor || color);
}
breakerRegex.lastIndex = i;
}
};
var startTime = Date.now();
highlightBlock("", defaultBreakerRegex);
if (i < text.length) {
writeText(text.substring(i), "");
}
var endTime = Date.now();
if (endTime - startTime > syntaxHighlighterConfig.timeout) {
clearInterval(highlightSyntaxIfNeededIntervalID);
wpTextbox1.removeEventListener("input", highlightSyntax);
wpTextbox1.removeEventListener("scroll", syncScrollX);
wpTextbox1.removeEventListener("scroll", syncScrollY);
attributeObserver.disconnect();
parentObserver.disconnect();
syntaxStyleTextNode.nodeValue = "";
var errorMessage = {
zh: "由于渲染耗时过长, Syntax highlighting 已在本页禁用。在设定中渲染时间被限制在$1毫秒以内,但这次我们耗去了$2毫秒。您可以尝试关闭一些标签页和程序,并点击“显示预览”或“显示更改”。如果这不起作用,请尝试更换一个不同的浏览器。如果这还不起作用,请尝试更换一个更快的电脑=w=。",
en: "Syntax highlighting on this page was disabled because it took too long. The maximum allowed highlighting time is $1ms, and your computer took $2ms. Try closing some tabs and programs and clicking \"Show preview\" or \"Show changes\". If that doesn't work, try a different web browser, and if that doesn't work, try a faster computer."
};
var wgUserLanguage = mw.config.get("wgUserLanguage");
errorMessage = errorMessage[wgUserLanguage] || errorMessage[wgUserLanguage.substring(0, wgUserLanguage.indexOf("-"))] || errorMessage.en;
wpTextbox1.style.backgroundColor = "";
wpTextbox1.style.marginTop = "0";
wpTextbox0.removeAttribute("dir");
wpTextbox0.removeAttribute("lang");
wpTextbox0.setAttribute("style", "color:red; font-size:small");
wpTextbox0.textContent = errorMessage.replace("$1", syntaxHighlighterConfig.timeout).replace("$2", endTime - startTime);
return;
}
if (maxSpanNumber < spanNumber) {
var fragment = document.createDocumentFragment();
do {
fragment.appendChild(document.createElement("span")).id = "s".concat(++maxSpanNumber);
} while (maxSpanNumber < spanNumber);
wpTextbox0.appendChild(fragment);
}
syntaxStyleTextNode.nodeValue = "".concat(css.substring(2).replace(/\n/g, "\\A "), "'}#wpTextbox0>span::after{visibility:hidden}");
};
var syncTextDirection = function () {
wpTextbox0.dir = wpTextbox1.dir;
};
var syncParent = function () {
if (wpTextbox1.previousSibling !== wpTextbox0) {
wpTextbox1.parentNode.insertBefore(wpTextbox0, wpTextbox1);
parentObserver.disconnect();
parentObserver.observe(wpTextbox1.parentNode, { childList: true });
}
};
var highlightSyntaxIfNeeded = function () {
if (wpTextbox1.value !== lastText) {
highlightSyntax();
}
if (wpTextbox1.scrollLeft !== wpTextbox0.scrollLeft) {
syncScrollX();
}
if (wpTextbox1.scrollTop !== wpTextbox0.scrollTop) {
syncScrollY();
}
if (wpTextbox1.offsetHeight !== wpTextbox0.offsetHeight) {
var height = "".concat(wpTextbox1.offsetHeight, "px");
wpTextbox0.style.height = height;
wpTextbox1.style.marginTop = "-".concat(height);
}
};
var setup = function () {
wpTextbox1 = document.getElementById("wpTextbox1");
if (!wpTextbox1) {
return;
}
if (document.getElementById("wpTextbox0")) {
return;
}
var configureColor = function (parameterName, hardcodedFallback, defaultOk) {
if (typeof syntaxHighlighterConfig[parameterName] === "undefined") {
syntaxHighlighterConfig[parameterName] = syntaxHighlighterSiteConfig[parameterName];
}
if (syntaxHighlighterConfig[parameterName] === "normal") {
syntaxHighlighterConfig[parameterName] = hardcodedFallback;
}
else if (typeof syntaxHighlighterConfig[parameterName] !== "undefined") {
return;
}
else if (typeof syntaxHighlighterConfig.defaultColor !== "undefined" && defaultOk) {
syntaxHighlighterConfig[parameterName] = syntaxHighlighterConfig.defaultColor;
}
else {
syntaxHighlighterConfig[parameterName] = hardcodedFallback;
}
};
configureColor("backgroundColor", "#FFF", false);
configureColor("foregroundColor", "#000", false);
configureColor("boldOrItalicColor", "#EEE", true);
configureColor("commentColor", "#EFE", true);
configureColor("entityColor", "#DFD", true);
configureColor("externalLinkColor", "#EFF", true);
configureColor("headingColor", "#EEE", true);
configureColor("hrColor", "#EEE", true);
configureColor("listOrIndentColor", "#EFE", true);
configureColor("parameterColor", "#FC6", true);
configureColor("signatureColor", "#FC6", true);
configureColor("tagColor", "#FEF", true);
configureColor("tableColor", "#FFC", true);
configureColor("templateColor", "#FFC", true);
configureColor("wikilinkColor", "#EEF", true);
syntaxHighlighterConfig.nowikiTags || (syntaxHighlighterConfig.nowikiTags = syntaxHighlighterSiteConfig.nowikiTags || ["nowiki", "pre"]);
syntaxHighlighterConfig.sourceTags || (syntaxHighlighterConfig.sourceTags = syntaxHighlighterSiteConfig.sourceTags || ["math", "syntaxhighlight", "source", "timeline", "hiero", "score"]);
syntaxHighlighterConfig.voidTags || (syntaxHighlighterConfig.voidTags = syntaxHighlighterSiteConfig.voidTags || ["br", "hr"]);
syntaxHighlighterConfig.timeout || (syntaxHighlighterConfig.timeout = syntaxHighlighterSiteConfig.timeout || 20);
syntaxHighlighterConfig.nowikiTags.forEach(function (tagName) {
nowikiTagBreakerRegexCache[tagName] = nowikiTagBreakerRegex(tagName);
});
wpTextbox0 = document.createElement("div");
wpTextbox1 = document.getElementById("wpTextbox1");
var syntaxStyleElement = document.createElement("style");
syntaxStyleTextNode = syntaxStyleElement.appendChild(document.createTextNode(""));
var wpTextbox1Style = window.getComputedStyle(wpTextbox1);
var resize = wpTextbox1Style.resize === "vertical" || wpTextbox1Style.resize === "both" ? "vertical" : "none";
wpTextbox0.dir = wpTextbox1.dir;
wpTextbox0.id = "wpTextbox0";
wpTextbox0.lang = wpTextbox1.lang;
wpTextbox0.style.backgroundColor = syntaxHighlighterConfig.backgroundColor;
wpTextbox0.style.borderBottomLeftRadius = wpTextbox1Style.borderBottomLeftRadius;
wpTextbox0.style.borderBottomRightRadius = wpTextbox1Style.borderBottomRightRadius;
wpTextbox0.style.borderBottomStyle = wpTextbox1Style.borderBottomStyle;
wpTextbox0.style.borderBottomWidth = wpTextbox1Style.borderBottomWidth;
wpTextbox0.style.borderColor = "transparent";
wpTextbox0.style.borderLeftStyle = wpTextbox1Style.borderLeftStyle;
wpTextbox0.style.borderLeftWidth = wpTextbox1Style.borderLeftWidth;
wpTextbox0.style.borderRightStyle = wpTextbox1Style.borderRightStyle;
wpTextbox0.style.borderRightWidth = wpTextbox1Style.borderRightWidth;
wpTextbox0.style.borderTopLeftRadius = wpTextbox1Style.borderTopLeftRadius;
wpTextbox0.style.borderTopRightRadius = wpTextbox1Style.borderTopRightRadius;
wpTextbox0.style.borderTopStyle = wpTextbox1Style.borderTopStyle;
wpTextbox0.style.borderTopWidth = wpTextbox1Style.borderTopWidth;
wpTextbox0.style.boxSizing = "border-box";
wpTextbox0.style.clear = wpTextbox1Style.clear;
wpTextbox0.style.fontFamily = wpTextbox1Style.fontFamily;
wpTextbox0.style.fontSize = wpTextbox1Style.fontSize;
wpTextbox0.style.lineHeight = "normal";
wpTextbox0.style.marginBottom = "0";
wpTextbox0.style.marginLeft = "0";
wpTextbox0.style.marginRight = "0";
wpTextbox0.style.marginTop = "0";
wpTextbox0.style.overflowX = "auto";
wpTextbox0.style.overflowY = "scroll";
wpTextbox0.style.resize = resize;
wpTextbox0.style.tabSize = wpTextbox1Style.tabSize;
wpTextbox0.style.whiteSpace = "pre-wrap";
wpTextbox0.style.width = "100%";
wpTextbox0.style.wordWrap = "normal";
wpTextbox1.style.backgroundColor = "transparent";
wpTextbox1.style.borderBottomLeftRadius = wpTextbox1Style.borderBottomLeftRadius;
wpTextbox1.style.borderBottomRightRadius = wpTextbox1Style.borderBottomRightRadius;
wpTextbox1.style.borderBottomStyle = wpTextbox1Style.borderBottomStyle;
wpTextbox1.style.borderBottomWidth = wpTextbox1Style.borderBottomWidth;
wpTextbox1.style.borderLeftStyle = wpTextbox1Style.borderLeftStyle;
wpTextbox1.style.borderLeftWidth = wpTextbox1Style.borderLeftWidth;
wpTextbox1.style.borderRightStyle = wpTextbox1Style.borderRightStyle;
wpTextbox1.style.borderRightWidth = wpTextbox1Style.borderRightWidth;
wpTextbox1.style.borderTopLeftRadius = wpTextbox1Style.borderTopLeftRadius;
wpTextbox1.style.borderTopRightRadius = wpTextbox1Style.borderTopRightRadius;
wpTextbox1.style.borderTopStyle = wpTextbox1Style.borderTopStyle;
wpTextbox1.style.borderTopWidth = wpTextbox1Style.borderTopWidth;
wpTextbox1.style.boxSizing = "border-box";
wpTextbox1.style.clear = wpTextbox1Style.clear;
wpTextbox1.style.color = syntaxHighlighterConfig.foregroundColor;
wpTextbox1.style.fontFamily = wpTextbox1Style.fontFamily;
wpTextbox1.style.fontSize = wpTextbox1Style.fontSize;
wpTextbox1.style.lineHeight = "normal";
wpTextbox1.style.marginBottom = wpTextbox1Style.marginBottom;
wpTextbox1.style.marginLeft = "0";
wpTextbox1.style.marginRight = "0";
wpTextbox1.style.overflowX = "auto";
wpTextbox1.style.overflowY = "scroll";
wpTextbox1.style.padding = "0";
wpTextbox1.style.resize = resize;
wpTextbox1.style.tabSize = wpTextbox1Style.tabSize;
wpTextbox1.style.whiteSpace = "pre-wrap";
wpTextbox1.style.width = "100%";
wpTextbox1.style.wordWrap = "normal";
wpTextbox1.style.height = wpTextbox0.style.height = "".concat(wpTextbox1.offsetHeight, "px");
wpTextbox1.style.marginTop = "".concat(-wpTextbox1.offsetHeight, "px");
wpTextbox1.parentNode.insertBefore(wpTextbox0, wpTextbox1);
document.head.appendChild(syntaxStyleElement);
wpTextbox1.addEventListener("input", highlightSyntax);
wpTextbox1.addEventListener("scroll", syncScrollX);
wpTextbox1.addEventListener("scroll", syncScrollY);
attributeObserver = new MutationObserver(syncTextDirection);
attributeObserver.observe(wpTextbox1, { attributes: true });
parentObserver = new MutationObserver(syncParent);
parentObserver.observe(wpTextbox1.parentNode, { childList: true });
highlightSyntaxIfNeededIntervalID = setInterval(highlightSyntaxIfNeeded, 500);
highlightSyntax();
};
var wgAction = mw.config.get("wgAction");
var layoutEngine = $.client.profile().layout;
if ((wgAction === "edit" || wgAction === "submit") && mw.config.get("wgPageContentModel") === "wikitext" && layoutEngine !== "trident" && layoutEngine !== "edge") {
if (document.readyState === "complete") {
setup();
}
else {
window.addEventListener("load", setup);
}
}
})();
/* </pre> */