wikiplus-highlight 3.0.6 → 3.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/main.js +16 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Wikiplus-highlight
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/wikiplus-highlight)
|
|
4
|
-
[](https://github.com/bhsd-harry/Wikiplus-highlight/actions/workflows/codeql.yml)
|
|
5
5
|
|
|
6
6
|
**Wikiplus-highlight** 是由 Bhsd 编写的一款 [Wikiplus](https://github.com/Wikiplus/Wikiplus) 语法高亮插件,它主要基于 MediaWiki 内置的 [JavaScript 模块](https://www.mediawiki.org/wiki/ResourceLoader/Core_modules)和 [CodeMirror](https://codemirror.net/) 编写。
|
|
7
7
|
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
|
|
10
10
|
在*个人 JS 页*添加以下代码:
|
|
11
11
|
|
|
12
|
-
```
|
|
12
|
+
```js
|
|
13
13
|
mw.loader.load('//cdn.jsdelivr.net/npm/wikiplus-highlight');
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
或
|
|
17
17
|
|
|
18
|
-
```
|
|
18
|
+
```js
|
|
19
19
|
mw.loader.load('//unpkg.com/wikiplus-highlight');
|
|
20
20
|
```
|
|
21
21
|
|
package/dist/main.js
CHANGED
|
@@ -5,24 +5,23 @@
|
|
|
5
5
|
* @license GPL-3.0
|
|
6
6
|
*/
|
|
7
7
|
(() => {
|
|
8
|
-
|
|
8
|
+
const { libs } = mw, { wphl } = libs;
|
|
9
|
+
if (wphl === null || wphl === void 0 ? void 0 : wphl.version) {
|
|
9
10
|
return;
|
|
10
11
|
}
|
|
11
|
-
const version = '3.0.
|
|
12
|
-
|
|
12
|
+
const version = '3.0.8';
|
|
13
|
+
libs.wphl = { version, cmVersion: '2.9', ...wphl }; // 开始加载
|
|
13
14
|
// 路径
|
|
14
|
-
const CDN = '//testingcf.jsdelivr.net', MW_CDN =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
script.addEventListener('load', () => {
|
|
20
|
-
resolve();
|
|
21
|
-
});
|
|
22
|
-
script.type = 'module';
|
|
23
|
-
script.src = `${CDN}/${MW_CDN}`;
|
|
24
|
-
document.head.appendChild(script);
|
|
15
|
+
const CDN = '//testingcf.jsdelivr.net', MW_CDN = `npm/@bhsd/codemirror-mediawiki@${libs.wphl.cmVersion || 'latest'}/dist/mw.min.js`, REPO_CDN = 'npm/wikiplus-highlight';
|
|
16
|
+
window.CodeMirror6 || (window.CodeMirror6 = new Promise(resolve => {
|
|
17
|
+
const script = document.createElement('script');
|
|
18
|
+
script.addEventListener('load', () => {
|
|
19
|
+
resolve(CodeMirror6);
|
|
25
20
|
});
|
|
21
|
+
script.type = 'module';
|
|
22
|
+
script.src = `${CDN}/${MW_CDN}`;
|
|
23
|
+
document.head.appendChild(script);
|
|
24
|
+
}));
|
|
26
25
|
const { wgPageName: page, wgNamespaceNumber: ns, wgPageContentModel: contentmodel, } = mw.config.get();
|
|
27
26
|
const CONTENTMODELS = {
|
|
28
27
|
'sanitized-css': 'css',
|
|
@@ -35,8 +34,8 @@
|
|
|
35
34
|
828: 'lua',
|
|
36
35
|
274: 'html',
|
|
37
36
|
};
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-
|
|
39
|
-
const getObject =
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
const getObject = (key) => JSON.parse(String(localStorage.getItem(key)));
|
|
40
39
|
/**
|
|
41
40
|
* 检查页面语言类型
|
|
42
41
|
* @param value 页面内容
|
|
@@ -96,8 +95,7 @@
|
|
|
96
95
|
* @param setting 是否是Wikiplus设置(使用json语法)
|
|
97
96
|
*/
|
|
98
97
|
const renderEditor = async ($target, setting) => {
|
|
99
|
-
await
|
|
100
|
-
const cm = await CodeMirror6.fromTextArea($target[0], ...setting ? ['json'] : await getPageMode($target.val()));
|
|
98
|
+
const cm = await (await CodeMirror6).fromTextArea($target[0], ...setting ? ['json'] : await getPageMode($target.val()));
|
|
101
99
|
cm.view.dom.id = 'Wikiplus-CodeMirror';
|
|
102
100
|
document.querySelector('#Wikiplus-Quickedit-Jump > a').href = '#Wikiplus-CodeMirror';
|
|
103
101
|
if (!setting) { // 普通Wikiplus编辑区
|