wikiplus-highlight 3.0.4 → 3.0.6
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 -22
- package/dist/main.js +38 -23
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -7,22 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
## 使用方法
|
|
9
9
|
|
|
10
|
-
### 最新版本
|
|
11
|
-
|
|
12
|
-
在*个人 JS 页*添加以下代码:
|
|
13
|
-
|
|
14
|
-
```javascript
|
|
15
|
-
mw.loader.load('//cdn.jsdelivr.net/npm/wikiplus-highlight@3.0.4');
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
或
|
|
19
|
-
|
|
20
|
-
```javascript
|
|
21
|
-
mw.loader.load('//unpkg.com/wikiplus-highlight@3.0.4');
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
### 稳定版本
|
|
25
|
-
|
|
26
10
|
在*个人 JS 页*添加以下代码:
|
|
27
11
|
|
|
28
12
|
```javascript
|
|
@@ -35,8 +19,6 @@ mw.loader.load('//cdn.jsdelivr.net/npm/wikiplus-highlight');
|
|
|
35
19
|
mw.loader.load('//unpkg.com/wikiplus-highlight');
|
|
36
20
|
```
|
|
37
21
|
|
|
38
|
-
由于 CDN 的缓存机制,稳定版本的更新大约会滞后一周。
|
|
39
|
-
|
|
40
22
|
## 更多插件
|
|
41
23
|
|
|
42
24
|
使用 *[Vector](https://www.mediawiki.org/wiki/Skin:Vector)* 皮肤或 MediaWiki 1.35 及以上的 *[Minerva Neue](https://www.mediawiki.org/wiki/Skin:Minerva_Neue)* 皮肤时,在右上角的【更多】菜单将添加一个【CodeMirror插件】选项,点击后可以选择想要加载的 CodeMirror 插件。其他桌面版皮肤(包括 *[Timeless](https://www.mediawiki.org/wiki/Skin:Timeless)*、*[MonoBook](https://www.mediawiki.org/wiki/Skin:MonoBook)* 和 *[Citizen](https://www.mediawiki.org/wiki/Skin:Citizen)*)会在类似性质的菜单中插入这一选项。修改插件设置后将立刻生效。
|
|
@@ -75,6 +57,7 @@ MediaWiki 模式下自动闭合生效的字符包括 `(`、`[`、`{` 和 `"`,
|
|
|
75
57
|
|
|
76
58
|
- `Ctrl` + `Shift` + `[`/`Cmd` + `Alt` + `[`: 折叠选中的文字(如果可行)
|
|
77
59
|
- `Ctrl` + `Shift` + `]`/`Cmd` + `Alt` + `]`: 展开选中的文字
|
|
60
|
+
- `Ctrl` + `Alt` + `[`: 折叠所有模板的参数
|
|
78
61
|
- `Ctrl` + `Alt` + `]`: 展开所有折叠的代码
|
|
79
62
|
|
|
80
63
|
### HTML/URL编码快捷键
|
|
@@ -84,9 +67,9 @@ MediaWiki 模式下自动闭合生效的字符包括 `(`、`[`、`{` 和 `"`,
|
|
|
84
67
|
- `Ctrl`/`Cmd` + `[`: 将选中的文字转换为HTML实体
|
|
85
68
|
- `Ctrl`/`Cmd` + `]`: 将选中的文字解码或转换为URL编码
|
|
86
69
|
|
|
87
|
-
###
|
|
70
|
+
### 快速打开链接
|
|
88
71
|
|
|
89
|
-
按住 `Ctrl`/`Cmd`
|
|
72
|
+
按住 `Ctrl`/`Cmd` 并点击被高亮标记为内部链接、模板标题或外部链接的文字时,会在新标签页打开对应页面。
|
|
90
73
|
|
|
91
74
|
### 维基语法检查
|
|
92
75
|
|
|
@@ -94,8 +77,6 @@ MediaWiki 模式下自动闭合生效的字符包括 `(`、`[`、`{` 和 `"`,
|
|
|
94
77
|
|
|
95
78
|
### 添加 WikiEditor 工具栏
|
|
96
79
|
|
|
97
|
-
*加入的版本:3.0.2*
|
|
98
|
-
|
|
99
80
|
工具栏遵从当前网站安装的 [WikiEditor](https://www.mediawiki.org/wiki/Extension:WikiEditor) 扩展的版本。
|
|
100
81
|
|
|
101
82
|
### 自动填充
|
package/dist/main.js
CHANGED
|
@@ -8,10 +8,21 @@
|
|
|
8
8
|
if ('wphl' in mw.libs) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
const version = '3.0.
|
|
11
|
+
const version = '3.0.6';
|
|
12
12
|
mw.libs['wphl'] = { version }; // 开始加载
|
|
13
13
|
// 路径
|
|
14
14
|
const CDN = '//testingcf.jsdelivr.net', MW_CDN = 'npm/@bhsd/codemirror-mediawiki/dist/mw.min.js', REPO_CDN = 'npm/wikiplus-highlight';
|
|
15
|
+
const /** 加载CodeMirror 6 */ init = 'CodeMirror6' in window
|
|
16
|
+
? Promise.resolve()
|
|
17
|
+
: new Promise(resolve => {
|
|
18
|
+
const script = document.createElement('script');
|
|
19
|
+
script.addEventListener('load', () => {
|
|
20
|
+
resolve();
|
|
21
|
+
});
|
|
22
|
+
script.type = 'module';
|
|
23
|
+
script.src = `${CDN}/${MW_CDN}`;
|
|
24
|
+
document.head.appendChild(script);
|
|
25
|
+
});
|
|
15
26
|
const { wgPageName: page, wgNamespaceNumber: ns, wgPageContentModel: contentmodel, } = mw.config.get();
|
|
16
27
|
const CONTENTMODELS = {
|
|
17
28
|
'sanitized-css': 'css',
|
|
@@ -26,18 +37,6 @@
|
|
|
26
37
|
};
|
|
27
38
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/unbound-method
|
|
28
39
|
const getObject = mw.storage.getObject || ((key) => JSON.parse(String(localStorage.getItem(key))));
|
|
29
|
-
/** 根据需要加载CodeMirror6 */
|
|
30
|
-
const init = () => 'CodeMirror6' in window
|
|
31
|
-
? Promise.resolve()
|
|
32
|
-
: new Promise(resolve => {
|
|
33
|
-
const script = document.createElement('script');
|
|
34
|
-
script.addEventListener('load', () => {
|
|
35
|
-
resolve();
|
|
36
|
-
});
|
|
37
|
-
script.type = 'module';
|
|
38
|
-
script.src = `${CDN}/${MW_CDN}`;
|
|
39
|
-
document.head.appendChild(script);
|
|
40
|
-
});
|
|
41
40
|
/**
|
|
42
41
|
* 检查页面语言类型
|
|
43
42
|
* @param value 页面内容
|
|
@@ -52,28 +51,44 @@
|
|
|
52
51
|
const modes = new Set(pages.map(({ title }) => {
|
|
53
52
|
var _a;
|
|
54
53
|
if (title.endsWith('/doc')) {
|
|
55
|
-
return '
|
|
54
|
+
return 'template';
|
|
56
55
|
}
|
|
57
56
|
const t = new mw.Title(title), namespace = t.getNamespaceId();
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
if (namespace % 2) {
|
|
58
|
+
return 'mediawiki';
|
|
59
|
+
}
|
|
60
|
+
const mode = EXTS[((_a = t.getExtension()) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || ''] || NAMESPACES[namespace];
|
|
61
|
+
if (mode) {
|
|
62
|
+
return mode === 'javascript' && (namespace === 8 || namespace === 2300) ? 'gadget' : mode;
|
|
63
|
+
}
|
|
64
|
+
return namespace === 10 || namespace === 2 ? 'template' : 'mediawiki';
|
|
61
65
|
}));
|
|
62
66
|
if (modes.size === 1) {
|
|
63
67
|
const [mode] = modes;
|
|
64
|
-
|
|
68
|
+
if (mode === 'gadget') {
|
|
69
|
+
return ['javascript', 8];
|
|
70
|
+
}
|
|
71
|
+
return mode === 'template' ? ['mediawiki', 10] : [mode];
|
|
72
|
+
}
|
|
73
|
+
else if (modes.size === 2) {
|
|
74
|
+
if (modes.has('javascript') && modes.has('gadget')) {
|
|
75
|
+
return ['javascript'];
|
|
76
|
+
}
|
|
77
|
+
else if (modes.has('mediawiki') && modes.has('template')) {
|
|
78
|
+
return ['mediawiki'];
|
|
79
|
+
}
|
|
65
80
|
}
|
|
66
81
|
}
|
|
67
82
|
if (ns !== 274 && contentmodel !== 'Scribunto' || page.endsWith('/doc')) {
|
|
68
|
-
return CONTENTMODELS[contentmodel] || contentmodel;
|
|
83
|
+
return [CONTENTMODELS[contentmodel] || contentmodel, contentmodel === 'javascript' ? ns : undefined];
|
|
69
84
|
}
|
|
70
85
|
await mw.loader.using('oojs-ui-windows');
|
|
71
86
|
if (await OO.ui.confirm(mw.msg('cm-mw-contentmodel'), {
|
|
72
87
|
actions: [{ label: ns === 274 ? 'Widget' : 'Lua' }, { label: 'Wikitext', action: 'accept' }],
|
|
73
88
|
})) {
|
|
74
|
-
return 'mediawiki';
|
|
89
|
+
return ['mediawiki'];
|
|
75
90
|
}
|
|
76
|
-
return ns === 274 ? 'html' : 'lua';
|
|
91
|
+
return [ns === 274 ? 'html' : 'lua'];
|
|
77
92
|
};
|
|
78
93
|
/**
|
|
79
94
|
* 渲染编辑器
|
|
@@ -81,8 +96,8 @@
|
|
|
81
96
|
* @param setting 是否是Wikiplus设置(使用json语法)
|
|
82
97
|
*/
|
|
83
98
|
const renderEditor = async ($target, setting) => {
|
|
84
|
-
await init
|
|
85
|
-
const cm = await CodeMirror6.fromTextArea($target[0], setting ? 'json' : await getPageMode($target.val()));
|
|
99
|
+
await init;
|
|
100
|
+
const cm = await CodeMirror6.fromTextArea($target[0], ...setting ? ['json'] : await getPageMode($target.val()));
|
|
86
101
|
cm.view.dom.id = 'Wikiplus-CodeMirror';
|
|
87
102
|
document.querySelector('#Wikiplus-Quickedit-Jump > a').href = '#Wikiplus-CodeMirror';
|
|
88
103
|
if (!setting) { // 普通Wikiplus编辑区
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikiplus-highlight",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "A plugin for the MediaWiki front-end add-on \"Wikiplus\"",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mediawiki",
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"build": "tsc"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@bhsd/codemirror-mediawiki": "^2.
|
|
32
|
+
"@bhsd/codemirror-mediawiki": "^2.6.8",
|
|
33
33
|
"@stylistic/eslint-plugin": "^1.5.4",
|
|
34
34
|
"@stylistic/stylelint-plugin": "^2.0.0",
|
|
35
35
|
"@types/jquery": "^3.5.29",
|
|
36
36
|
"@types/oojs-ui": "^0.47.6",
|
|
37
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
38
|
-
"@typescript-eslint/parser": "^
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^7.1.0",
|
|
38
|
+
"@typescript-eslint/parser": "^7.1.0",
|
|
39
39
|
"eslint": "^8.56.0",
|
|
40
40
|
"eslint-plugin-es-x": "^7.5.0",
|
|
41
41
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"eslint-plugin-json-es": "^1.5.7",
|
|
44
44
|
"eslint-plugin-promise": "^6.1.1",
|
|
45
45
|
"eslint-plugin-regexp": "^2.2.0",
|
|
46
|
-
"eslint-plugin-unicorn": "^
|
|
46
|
+
"eslint-plugin-unicorn": "^51.0.1",
|
|
47
47
|
"stylelint": "^16.1.0",
|
|
48
48
|
"stylelint-config-recommended": "^14.0.0",
|
|
49
49
|
"types-mediawiki": "^1.4.0",
|