你现在正在访问的是萌娘百科用于保存和管理图片、音频等媒体文件的子项目萌娘共享,想要回到萌娘百科,请使用浏览器上的返回按钮、或点击这里
“MediaWiki:Gadget-prism.js”的版本间的差异
AnnAngela-dbot(讨论 | 贡献) (代码变动:7ac8caf - fix: Fix line numbers and add prism-prettyprint-container class to pre el[...] by U:AnnAngela) (1个标签:由机器人或全自动脚本执行的操作) |
AnnAngela-dbot(讨论 | 贡献) (代码变动:7ac8caf2 - fix: Fix line numbers and add prism-prettyprint-container class to pre el[...] by U:AnnAngela) (1个标签:由机器人或全自动脚本执行的操作) |
||
第4行: | 第4行: | ||
* ------------------------------------------------------------------------- | * ------------------------------------------------------------------------- | ||
*/ | */ | ||
− | var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/prism/MediaWiki:Gadget-prism.js|user=[[U:AnnAngela]]|co-authors=|longId=7ac8caf238d1a8cf3c419eae35391df8a5833cb1|shortId= | + | var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/prism/MediaWiki:Gadget-prism.js|user=[[U:AnnAngela]]|co-authors=|longId=7ac8caf238d1a8cf3c419eae35391df8a5833cb1|shortId=7ac8caf2|summary=fix: Fix line numbers and add prism-prettyprint-container class to pre elements in MediaWiki:Gadget-prism.js and MediaWiki:Gadget-prism.css}}'; |
/* <pre> */ | /* <pre> */ |
2024年4月16日 (二) 09:05的版本
/** * ------------------------------------------------------------------------- * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!! * ------------------------------------------------------------------------- */ var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/prism/MediaWiki:Gadget-prism.js|user=[[U:AnnAngela]]|co-authors=|longId=7ac8caf238d1a8cf3c419eae35391df8a5833cb1|shortId=7ac8caf2|summary=fix: Fix line numbers and add prism-prettyprint-container class to pre elements in MediaWiki:Gadget-prism.js and MediaWiki:Gadget-prism.css}}'; /* <pre> */ "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (g && (g = 0, op[0] && (_ = 0)), _) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; $(function () { Prism.manual = true; var acceptsLangs = { css: "css", "sanitized-css": "css", javascript: "javascript", js: "javascript", json: "json", json5: "json", webmanifest: "json", latex: "latex", tex: "latex", context: "latex", lua: "lua", scribunto: "lua", markup: "markup", htm: "markup", html: "markup", mathml: "markup", svg: "markup", xml: "markup", ssml: "markup", atom: "markup", rss: "markup", php: "php", regex: "regex", typescript: "typescript", ts: "typescript", wiki: "wiki", wikitext: "wiki", mediawiki: "wiki", mw: "wiki", yaml: "yaml", yml: "yaml" }; var appendPluginsList = { javascript: "jsdoc", typescript: "jsdoc", php: "phpdoc", markup: "previewers", css: "previewers" }; var acceptsLangNames = Object.values(acceptsLangs); mw.hook("wikipage.content").add(function ($content) { return (function () { return __awaiter(void 0, void 0, void 0, function () { var wgPageContentModel, langSet, pluginsSet, lang, hashWatcher, _a, _b, ele, $ele, classListWithLang, lang, classListWithLang_1, classListWithLang_1_1, cls, workerJS, config, _c, _d, filename, _e, _f, ele, lang, parent_1; var e_1, _g, e_2, _h, e_3, _j; var _k; return __generator(this, function (_l) { switch (_l.label) { case 0: wgPageContentModel = mw.config.get("wgPageContentModel", "").toLowerCase(); langSet = new Set(); pluginsSet = new Set([ "match-braces", ]); if (Reflect.has(acceptsLangs, wgPageContentModel)) { lang = acceptsLangs[wgPageContentModel]; langSet.add(lang); if (Reflect.has(appendPluginsList, lang)) { pluginsSet.add(appendPluginsList[lang]); } $content.find(".mw-code").addClass("linkable-line-numbers").attr({ id: "code" }).wrapInner("<code>").children("code").addClass("prism-prettyprint language-".concat(lang)).attr({ "data-lang": lang }); hashWatcher = function () { if (/^#L[0-9]\d*$/.test(location.hash)) { location.hash = location.hash.replace(/^#L/, "#code."); } }; window.addEventListener("hashchange", hashWatcher); hashWatcher(); } if (wgPageContentModel === "wikitext") { try { for (_a = __values($content.find("pre, code")), _b = _a.next(); !_b.done; _b = _a.next()) { ele = _b.value; $ele = $(ele); classListWithLang = __spreadArray([], __read(ele.classList), false).filter(function (cls) { return /^lang(?:uage)?-[\w-]+$/i.test(cls); }); lang = acceptsLangs[ele.getAttribute("lang")] || acceptsLangs[(_k = classListWithLang[0]) === null || _k === void 0 ? void 0 : _k.replace(/^lang(?:uage)?-/, "")]; if (!lang) { continue; } langSet.add(lang); if (Reflect.has(appendPluginsList, lang)) { pluginsSet.add(appendPluginsList[lang]); } ele.classList.remove("linenums"); ele.removeAttribute("lang"); try { for (classListWithLang_1 = (e_2 = void 0, __values(classListWithLang)), classListWithLang_1_1 = classListWithLang_1.next(); !classListWithLang_1_1.done; classListWithLang_1_1 = classListWithLang_1.next()) { cls = classListWithLang_1_1.value; ele.classList.remove(cls); } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (classListWithLang_1_1 && !classListWithLang_1_1.done && (_h = classListWithLang_1["return"])) _h.call(classListWithLang_1); } finally { if (e_2) throw e_2.error; } } if (ele.tagName === "PRE") { $ele = $ele.wrapInner("<code>").children("code"); } $ele[0].dataset.lang = lang; $ele.addClass("prism-prettyprint language-".concat(lang)); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_b && !_b.done && (_g = _a["return"])) _g.call(_a); } finally { if (e_1) throw e_1.error; } } } return [4, mw.loader.using(__spreadArray(__spreadArray([], __read(__spreadArray([], __read(langSet), false).map(function (lang) { return "ext.gadget.prism-language-".concat(lang); })), false), __read(__spreadArray([], __read(pluginsSet), false).map(function (plugin) { return "ext.gadget.prism-plugin-".concat(plugin); })), false))]; case 1: _l.sent(); if (!(langSet.has("wiki") && !Prism.languages.wiki)) return [3, 4]; workerJS = function (config) { self.importScripts("".concat(location.origin, "/MediaWiki:Gadget-prism-language-wiki.js?action=raw&ctype=text/javascript")); self.Parser.config = JSON.parse(config); var entities = { "&": "&", "<": "<", ">": ">" }, keyword = "keyword", url = "url", bold = "bold", doctype = "doctype", comment = "comment", tag = "tag", punctuation = "punctuation", variable = "variable", builtin = "builtin", template = "function", symbol = "symbol", selector = "selector", string = "string", map = { "redirect-syntax": keyword, "redirect-target": url, "link-target": "".concat(url, " ").concat(bold), noinclude: doctype, include: doctype, comment: comment, ext: tag, "ext-attr-dirty": comment, "ext-attr": punctuation, "attr-key": "attr-name", "attr-value": "attr-value", arg: variable, "arg-name": variable, hidden: comment, "magic-word": builtin, "magic-word-name": builtin, "invoke-function": template, "invoke-module": template, template: template, "template-name": "".concat(template, " ").concat(bold), parameter: punctuation, "parameter-key": variable, heading: symbol, "heading-title": bold, html: tag, "html-attr-dirty": comment, "html-attr": punctuation, table: symbol, tr: symbol, td: symbol, "table-syntax": symbol, "table-attr-dirty": comment, "table-attr": punctuation, "table-inter": "deleted", hr: symbol, "double-underscore": "constant", link: url, category: url, file: url, "gallery-image": url, "imagemap-image": url, "image-parameter": keyword, quote: "".concat(symbol, " ").concat(bold), "ext-link": url, "ext-link-url": url, "free-ext-link": url, list: symbol, dd: symbol, converter: selector, "converter-flags": punctuation, "converter-flag": string, "converter-rule": punctuation, "converter-rule-variant": string }; self.onmessage = function (_a) { var _b, _c; var data = _a.data; var code = JSON.parse(data).code, tree = self.Parser.parse(code).json(); var slice = function (type, parentType, start, end) { var text = code.slice(start, end).replace(/[&<>]/g, function (p) { return entities[p]; }); var t = type || parentType; if (parentType === "image-parameter") { t = "root"; } else if (type === "converter" && text === ";") { t = "converter-rule"; } return Reflect.has(map, t) ? "<span class=\"token ".concat(map[t], "\">").concat(text, "</span>") : text; }; var stack = []; var cur = tree, index = 0, last = 0, out = false, output = ""; while (last < code.length) { var type = cur.type, _d = __read(cur.range, 2), to = _d[1], childNodes = cur.childNodes, parentNode = (_b = stack[0]) === null || _b === void 0 ? void 0 : _b[0]; if (out || !(childNodes === null || childNodes === void 0 ? void 0 : childNodes.length)) { var _e = __read(stack[0], 2), i = _e[1]; if (last < to) { output += slice(type, parentNode.type, last, to); last = to; } index++; if (index === parentNode.childNodes.length) { cur = parentNode; index = i; stack.shift(); out = true; } else { cur = parentNode.childNodes[index]; out = false; var _f = __read(cur.range, 1), from = _f[0]; if (last < from) { output += slice(parentNode.type, (_c = stack[1]) === null || _c === void 0 ? void 0 : _c[0].type, last, from); last = from; } } } else { var child = childNodes[0], _g = __read(child.range, 1), from = _g[0]; if (last < from) { output += slice(type, parentNode === null || parentNode === void 0 ? void 0 : parentNode.type, last, from); last = from; } stack.unshift([cur, index]); cur = child; index = 0; } } postMessage(output); close(); }; }; _d = (_c = JSON).stringify; return [4, fetch("/MediaWiki:Gadget-prism-language-wiki.json?action=raw&ctype=application/json")]; case 2: return [4, (_l.sent()).json()]; case 3: config = _d.apply(_c, [_l.sent()]); filename = URL.createObjectURL(new Blob(["(".concat(String(workerJS), ")(`").concat(config, "`)")], { type: "text/javascript" })); Object.assign(Prism, { filename: filename }); Prism.languages.wiki = {}; _l.label = 4; case 4: try { for (_e = __values($content.find("code.prism-prettyprint")), _f = _e.next(); !_f.done; _f = _e.next()) { ele = _f.value; lang = ele.dataset.lang; if (!acceptsLangNames.includes(lang)) { continue; } parent_1 = ele.parentElement; if (parent_1.tagName === "PRE") { parent_1.classList.add("line-numbers", "prism-prettyprint-container"); } ele.classList.add("match-braces", "rainbow-braces"); Prism.highlightElement(ele, lang === "wiki"); } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (_f && !_f.done && (_j = _e["return"])) _j.call(_e); } finally { if (e_3) throw e_3.error; } } return [2]; } }); }); })(); }); }); /* </pre> */