From 2c086844d7407ba60479d37ce721201fb8c5895c Mon Sep 17 00:00:00 2001 From: bhsd <2545473905@qq.com> Date: Sun, 14 Jan 2024 13:25:45 +0800 Subject: [PATCH] fix(wikieditor-highlight-cm6): fix wikilint 1. assuming templates to be transcluded 2. loading full parser config --- .../MediaWiki:Gadget-wikieditor-highlight-cm6.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/gadgets/wikieditor-highlight-cm6/MediaWiki:Gadget-wikieditor-highlight-cm6.js b/src/gadgets/wikieditor-highlight-cm6/MediaWiki:Gadget-wikieditor-highlight-cm6.js index 6d814c04..d53abef9 100644 --- a/src/gadgets/wikieditor-highlight-cm6/MediaWiki:Gadget-wikieditor-highlight-cm6.js +++ b/src/gadgets/wikieditor-highlight-cm6/MediaWiki:Gadget-wikieditor-highlight-cm6.js @@ -10,12 +10,12 @@ let cm, state = localObjectStorage.getItem("wikieditor-codemirror", false); const $textarea = $("#wpTextbox1"); const isAdvanced = ["loading", "loaded", "executing", "ready"].includes(mw.loader.getState("ext.wikiEditor")); - const lang = mw.config.get("wgNamespaceNumber") === 274 ? "html" : "mediawiki"; + const ns = mw.config.get("wgNamespaceNumber"); + const lang = ns === 274 ? "html" : "mediawiki"; const init = () => new Promise((resolve) => { const script = document.createElement("script"); script.addEventListener("load", async () => { cm = await CodeMirror.fromTextArea($textarea[0], lang); - cm.defaultLint(true); cm.prefer([ "highlightSpecialChars", "highlightActiveLine", @@ -23,10 +23,19 @@ "bracketMatching", "closeBrackets", ]); + const [config] = await Promise.all([ + libCachedCode.getCachedCode("https://testingcf.jsdelivr.net/npm/wikiparser-node/config/moegirl.json"), + cm.defaultLint(true, {include: ns === 10}), + ]); + try { + window.wikiparse.setConfig(JSON.parse(config)); + } catch (e) { + console.error(e); + } resolve(); }); script.type = "module"; - script.src = "https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.2/mw/dist/base.min.js"; + script.src = "https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.4/mw/dist/base.min.js"; document.head.appendChild(script); }); if (!isAdvanced) {