-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(wikieditor-highlight-cm6): avoid reusing global CodeMirror
- 对Widget模式进行了一些更新 - 忽略一些false positive的语法错误
- Loading branch information
1 parent
5fbcee9
commit 5d4ee96
Showing
1 changed file
with
28 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,32 +12,34 @@ | |
const isAdvanced = ["loading", "loaded", "executing", "ready"].includes(mw.loader.getState("ext.wikiEditor")); | ||
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.prefer([ | ||
"highlightSpecialChars", | ||
"highlightActiveLine", | ||
"highlightWhitespace", | ||
"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/[email protected]/mw/dist/base.min.js"; | ||
document.head.append(script); | ||
}); | ||
const init = async () => { | ||
if (!window.CodeMirror6) { | ||
await new Promise((resolve) => { | ||
const script = document.createElement("script"); | ||
script.addEventListener("load", resolve); | ||
script.type = "module"; | ||
script.src = "https://testingcf.jsdelivr.net/npm/@bhsd/[email protected]/mw/dist/base.min.js"; | ||
document.head.append(script); | ||
}); | ||
} | ||
cm = await window.CodeMirror6.fromTextArea($textarea[0], lang); | ||
cm.prefer([ | ||
"highlightSpecialChars", | ||
"highlightActiveLine", | ||
"highlightWhitespace", | ||
"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); | ||
} | ||
}; | ||
if (!isAdvanced) { | ||
init(); | ||
return; | ||
|