MediaWiki:Gadget-prism-language-wiki.js

来自萌娘共享
AnnAngela-dbot讨论 | 贡献2024年4月22日 (一) 17:11的版本 (代码变动:baeaa605 - fix: Fix prism (#462) by U:Bhsd
跳转至: 导航搜索

注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件
/**
 * -------------------------------------------------------------------------
 * !!! 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=baeaa60578d7f6f126b066af3261d851e88bc814|shortId=baeaa605|summary=fix: Fix prism (#462)}}'; 

/* <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 __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 () { return __awaiter(void 0, void 0, void 0, function () {
    var wiki, _a, keyword, url, bold, doctype, comment, tag, punctuation, variable, builtin, template, symbol, selector, string, map, getSliceFunc, tokenize;
    return __generator(this, function (_b) {
        switch (_b.label) {
            case 0:
                wiki = {};
                Prism.languages.wiki = wiki;
                _a = Parser;
                return [4, fetch("/MediaWiki:Gadget-prism-language-wiki.json?action=raw&ctype=application/json")];
            case 1: return [4, (_b.sent()).json()];
            case 2:
                _a.config = _b.sent();
                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
                };
                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);
                    };
                };
                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);
                };
                return [2];
        }
    });
}); })(); 

/* </pre> */