你现在正在访问的是萌娘百科用于保存和管理图片、音频等媒体文件的子项目萌娘共享,想要回到萌娘百科,请使用浏览器上的返回按钮、或点击这里
“MediaWiki:Gadget-prism-language-wiki.js”的版本间的差异
AnnAngela-dbot(讨论 | 贡献) (1个标签:由机器人或全自动脚本执行的操作) |
AnnAngela-dbot(讨论 | 贡献) (1个标签:由机器人或全自动脚本执行的操作) |
||
第4行: | 第4行: | ||
* ------------------------------------------------------------------------- | * ------------------------------------------------------------------------- | ||
*/ | */ | ||
− | var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/prism-language-wiki/MediaWiki:Gadget-prism-language-wiki.js|user=[[U:Bhsd]]|co-authors=|longId= | + | var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/prism-language-wiki/MediaWiki:Gadget-prism-language-wiki.js|user=[[U:Bhsd]]|co-authors=|longId=f291caf4b68aac3897ffe03632c8d1391e433ce4|shortId=f291caf4|summary=fix(gadget-prism-wiki): 更改异步加载的位置 (#466)}}'; |
/* <pre> */ | /* <pre> */ | ||
"use strict"; | "use strict"; | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
var __read = (this && this.__read) || function (o, n) { | var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
第61行: | 第25行: | ||
return ar; | return ar; | ||
}; | }; | ||
− | ( | + | (function () { |
− | var | + | var wiki = {}; |
− | + | Prism.languages.wiki = wiki; | |
− | + | var 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 | |
− | + | }; | |
− | + | var getSliceFunc = function (stream, code) { | |
− | + | return function (type, parentType, start, end) { | |
− | + | var text = code.slice(start, end); | |
− | + | var t = type || parentType; | |
− | + | if (parentType === "image-parameter") { | |
− | + | t = "root"; | |
− | + | } | |
− | + | else if (type === "converter" && text === ";") { | |
− | + | t = "converter-rule"; | |
− | + | } | |
− | + | stream.push(Reflect.has(map, t) ? new Prism.Token(map[t], [text]) : text); | |
− | + | }; | |
− | + | }; | |
− | + | var tokenize = Prism.tokenize; | |
− | + | Prism.tokenize = function (code, grammar) { | |
− | + | var _a, _b; | |
− | + | if (grammar === wiki) { | |
− | + | var tree = Parser.parse(code).json(), stack = [], output = []; | |
+ | var slice = getSliceFunc(output, code); | ||
+ | var cur = tree, index = 0, last = 0, out = false; | ||
+ | while (last < code.length) { | ||
+ | var type = cur.type, _c = __read(cur.range, 2), to = _c[1], childNodes = cur.childNodes, parentNode = (_a = stack[0]) === null || _a === void 0 ? void 0 : _a[0]; | ||
+ | if (out || !(childNodes === null || childNodes === void 0 ? void 0 : childNodes.length)) { | ||
+ | var _d = __read(stack[0], 2), i = _d[1]; | ||
+ | if (last < to) { | ||
+ | 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 _e = __read(cur.range, 1), from = _e[0]; | ||
+ | if (last < from) { | ||
+ | slice(parentNode.type, (_b = stack[1]) === null || _b === void 0 ? void 0 : _b[0].type, last, from); | ||
+ | last = from; | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
− | + | } | |
− | + | else { | |
− | return | + | var child = childNodes[0], _f = __read(child.range, 1), from = _f[0]; |
+ | if (last < from) { | ||
+ | slice(type, parentNode === null || parentNode === void 0 ? void 0 : parentNode.type, last, from); | ||
+ | last = from; | ||
+ | } | ||
+ | stack.unshift([cur, index]); | ||
+ | cur = child; | ||
+ | index = 0; | ||
+ | } | ||
+ | } | ||
+ | return output; | ||
} | } | ||
− | + | return tokenize(code, grammar); | |
− | } | + | }; |
+ | })(); | ||
/* </pre> */ | /* </pre> */ |
2024年4月23日 (二) 10:37的最新版本
/** * ------------------------------------------------------------------------- * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!! * ------------------------------------------------------------------------- */ var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/prism-language-wiki/MediaWiki:Gadget-prism-language-wiki.js|user=[[U:Bhsd]]|co-authors=|longId=f291caf4b68aac3897ffe03632c8d1391e433ce4|shortId=f291caf4|summary=fix(gadget-prism-wiki): 更改异步加载的位置 (#466)}}'; /* <pre> */ "use strict"; 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; }; (function () { var wiki = {}; Prism.languages.wiki = wiki; var 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 }; var getSliceFunc = function (stream, code) { return function (type, parentType, start, end) { var text = code.slice(start, end); var t = type || parentType; if (parentType === "image-parameter") { t = "root"; } else if (type === "converter" && text === ";") { t = "converter-rule"; } stream.push(Reflect.has(map, t) ? new Prism.Token(map[t], [text]) : text); }; }; var tokenize = Prism.tokenize; Prism.tokenize = function (code, grammar) { var _a, _b; if (grammar === wiki) { var tree = Parser.parse(code).json(), stack = [], output = []; var slice = getSliceFunc(output, code); var cur = tree, index = 0, last = 0, out = false; while (last < code.length) { var type = cur.type, _c = __read(cur.range, 2), to = _c[1], childNodes = cur.childNodes, parentNode = (_a = stack[0]) === null || _a === void 0 ? void 0 : _a[0]; if (out || !(childNodes === null || childNodes === void 0 ? void 0 : childNodes.length)) { var _d = __read(stack[0], 2), i = _d[1]; if (last < to) { 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 _e = __read(cur.range, 1), from = _e[0]; if (last < from) { slice(parentNode.type, (_b = stack[1]) === null || _b === void 0 ? void 0 : _b[0].type, last, from); last = from; } } } else { var child = childNodes[0], _f = __read(child.range, 1), from = _f[0]; if (last < from) { slice(type, parentNode === null || parentNode === void 0 ? void 0 : parentNode.type, last, from); last = from; } stack.unshift([cur, index]); cur = child; index = 0; } } return output; } return tokenize(code, grammar); }; })(); /* </pre> */