wikiplus-highlight 3.2.0 → 3.2.2
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 +49 -13
- package/dist/main.js +13 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,6 +5,30 @@
|
|
|
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
|
|
|
8
|
+
<details>
|
|
9
|
+
<summary>展开</summary>
|
|
10
|
+
|
|
11
|
+
- [使用方法](#使用方法)
|
|
12
|
+
- [更多插件](#更多插件)
|
|
13
|
+
- [高亮当前行](#高亮当前行)
|
|
14
|
+
- [显示不可见字符](#显示不可见字符)
|
|
15
|
+
- [显示空白字符](#显示空白字符)
|
|
16
|
+
- [显示尾随空格](#显示尾随空格)
|
|
17
|
+
- [匹配括号](#匹配括号)
|
|
18
|
+
- [自动闭合括号和引号](#自动闭合括号和引号)
|
|
19
|
+
- [代码折叠](#代码折叠)
|
|
20
|
+
- [自动填充](#自动填充)
|
|
21
|
+
- [匹配标签](#匹配标签)
|
|
22
|
+
- [HTML/URL编码快捷键](#htmlurl编码快捷键)
|
|
23
|
+
- [快速打开链接](#快速打开链接)
|
|
24
|
+
- [语法检查](#语法检查)
|
|
25
|
+
- [添加 WikiEditor 工具栏](#添加-wikieditor-工具栏)
|
|
26
|
+
- [使用 Monaco Editor](#使用-monaco-editor)
|
|
27
|
+
- [调整缩进](#调整缩进)
|
|
28
|
+
- [Supported languages](#supported-languages)
|
|
29
|
+
|
|
30
|
+
</details>
|
|
31
|
+
|
|
8
32
|
## 使用方法
|
|
9
33
|
|
|
10
34
|
在*个人 JS 页*添加以下代码:
|
|
@@ -45,43 +69,55 @@ mw.loader.load('//unpkg.com/wikiplus-highlight');
|
|
|
45
69
|
|
|
46
70
|
### 自动闭合括号和引号
|
|
47
71
|
|
|
48
|
-
MediaWiki 模式下自动闭合生效的字符包括 `(`、`[`、`{` 和 `"
|
|
49
|
-
|
|
50
|
-
### 匹配标签
|
|
51
|
-
|
|
52
|
-
匹配的标签对或自封闭标签会添加青色背景,未匹配的标签会添加暗红色背景。注意被高亮标记为错误的标签不会进行匹配。
|
|
72
|
+
MediaWiki 模式下自动闭合生效的字符包括 `(`、`[`、`{` 和 `"`,其他模式还额外包括 `'`。如果在选中部分文字的情况下键入这些字符,选中的文字会被成对的括号或引号包裹。
|
|
53
73
|
|
|
54
74
|
### 代码折叠
|
|
55
75
|
|
|
56
|
-
|
|
76
|
+
MediaWiki 模式下,光标移动至模板、解析器函数或扩展标签内部时会在光标上方出现一个 `-` 标记,点击即可折叠模板和解析器函数的参数或扩展标签内部的文本。折叠后使用一个带有虚线边框的 `⋯` 标记占位,点击该标记将重新展开折叠的代码部分。其他模式下,可折叠的代码行行号左侧会出现箭头 `⌄` 作为折叠按钮。同时添加以下快捷键:
|
|
57
77
|
|
|
58
78
|
- `Ctrl` + `Shift` + `[`/`Cmd` + `Alt` + `[`: 折叠选中的文字(如果可行)
|
|
59
79
|
- `Ctrl` + `Shift` + `]`/`Cmd` + `Alt` + `]`: 展开选中的文字
|
|
60
|
-
- `Ctrl` + `Alt` + `[`:
|
|
80
|
+
- `Ctrl` + `Alt` + `[`: 折叠所有可折叠的代码
|
|
61
81
|
- `Ctrl` + `Alt` + `]`: 展开所有折叠的代码
|
|
62
82
|
|
|
83
|
+
### 自动填充
|
|
84
|
+
|
|
85
|
+
MediaWiki 模式下可自动填充魔术字(包括状态开关和解析器函数)、标签名、标签属性名、URL 协议和图片参数。此外按下 `Ctrl` + `Space` 还可触发页面名称和模板参数(需要 [TemplateData](https://www.mediawiki.org/wiki/Extension:TemplateData) 扩展)的自动填充。JavaScript 和 CSS 模式下可自动填充关键字和常数。
|
|
86
|
+
|
|
87
|
+
### 匹配标签
|
|
88
|
+
|
|
89
|
+
仅用于 MediaWiki 模式,匹配的标签对或自封闭标签会添加青色背景,未匹配的标签会添加暗红色背景。注意被高亮标记为错误的标签不会进行匹配。
|
|
90
|
+
|
|
63
91
|
### HTML/URL编码快捷键
|
|
64
92
|
|
|
65
|
-
|
|
93
|
+
仅用于 MediaWiki 模式,添加以下快捷键:
|
|
66
94
|
|
|
67
95
|
- `Ctrl`/`Cmd` + `[`: 将选中的文字转换为HTML实体
|
|
68
96
|
- `Ctrl`/`Cmd` + `]`: 将选中的文字解码或转换为URL编码
|
|
69
97
|
|
|
70
98
|
### 快速打开链接
|
|
71
99
|
|
|
72
|
-
|
|
100
|
+
仅用于 MediaWiki 模式,按住 `Ctrl`/`Cmd` 并点击被高亮标记为内部链接、模板标题或外部链接的文字时,会在新标签页打开对应页面。
|
|
101
|
+
|
|
102
|
+
### 语法检查
|
|
73
103
|
|
|
74
|
-
|
|
104
|
+
开启后将在编辑框内提示可能存在的语法错误。
|
|
75
105
|
|
|
76
|
-
|
|
106
|
+
|模式|语法检查库|
|
|
107
|
+
|:-:|:-:|
|
|
108
|
+
|MediaWiki|[WikiParser-Node](https://github.com/bhsd-harry/wikiparser-node)|
|
|
109
|
+
|JavaScript|[ESLint](https://eslint.org/)|
|
|
110
|
+
|CSS|[Stylelint](https://stylelint.io/)|
|
|
111
|
+
|JSON|[JSON.parse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)|
|
|
112
|
+
|Lua|[luaparse](https://npmjs.com/package/luaparse)|
|
|
77
113
|
|
|
78
114
|
### 添加 WikiEditor 工具栏
|
|
79
115
|
|
|
80
116
|
工具栏遵从当前网站安装的 [WikiEditor](https://www.mediawiki.org/wiki/Extension:WikiEditor) 扩展的版本。
|
|
81
117
|
|
|
82
|
-
###
|
|
118
|
+
### 使用 Monaco Editor
|
|
83
119
|
|
|
84
|
-
|
|
120
|
+
不使用默认的 [CodeMirror 6](https://codemirror.net/) 编辑器,而是使用 [Monaco Editor](https://microsoft.github.io/monaco-editor/)。
|
|
85
121
|
|
|
86
122
|
### 调整缩进
|
|
87
123
|
|
package/dist/main.js
CHANGED
|
@@ -9,14 +9,19 @@
|
|
|
9
9
|
if (wphl === null || wphl === void 0 ? void 0 : wphl.version) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
const version = '3.2.
|
|
12
|
+
const version = '3.2.2';
|
|
13
13
|
libs.wphl = { version, ...wphl }; // 开始加载
|
|
14
14
|
// 路径
|
|
15
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 =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
window.CodeMirror6 || (window.CodeMirror6 = new Promise(resolve => {
|
|
17
|
+
const script = document.createElement('script');
|
|
18
|
+
script.addEventListener('load', () => {
|
|
19
|
+
resolve(CodeMirror6);
|
|
20
|
+
});
|
|
21
|
+
script.type = 'module';
|
|
22
|
+
script.src = `${CDN}/${MW_CDN}`;
|
|
23
|
+
document.head.append(script);
|
|
24
|
+
}));
|
|
20
25
|
const { wgPageName: page, wgNamespaceNumber: ns, wgPageContentModel: contentmodel, } = mw.config.get();
|
|
21
26
|
const CONTENTMODELS = {
|
|
22
27
|
'sanitized-css': 'css',
|
|
@@ -106,8 +111,8 @@
|
|
|
106
111
|
(((_a = cm.view) === null || _a === void 0 ? void 0 : _a.dom) || cm.editor.getDomNode()).id = 'Wikiplus-CodeMirror';
|
|
107
112
|
if (!setting) { // 普通Wikiplus编辑区
|
|
108
113
|
if (cm.editor) {
|
|
109
|
-
cm.editor.
|
|
110
|
-
if (e.keyCode ===
|
|
114
|
+
cm.editor.onKeyDown(e => {
|
|
115
|
+
if (e.keyCode === monaco.KeyCode.KeyS && (e.ctrlKey || e.metaKey)) {
|
|
111
116
|
e.preventDefault();
|
|
112
117
|
if (e.shiftKey) {
|
|
113
118
|
submitMinor();
|
|
@@ -116,7 +121,7 @@
|
|
|
116
121
|
submit();
|
|
117
122
|
}
|
|
118
123
|
}
|
|
119
|
-
else if (e.keyCode ===
|
|
124
|
+
else if (e.keyCode === monaco.KeyCode.Escape && esc) {
|
|
120
125
|
e.preventDefault();
|
|
121
126
|
escapeEdit();
|
|
122
127
|
}
|