wikiplus-highlight 2.10.0 → 2.12.1
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 +10 -2
- package/dist/main.min.js +1 -1
- package/dist/main.min.js.map +1 -1
- package/fold.js +96 -31
- package/i18n/en.json +3 -2
- package/i18n/zh-hans.json +3 -2
- package/i18n/zh-hant.json +3 -2
- package/jsconfig.json +3 -0
- package/main.js +195 -144
- package/matchtags.js +42 -41
- package/package.json +2 -1
- package/search.js +8 -18
package/matchtags.js
CHANGED
|
@@ -137,7 +137,10 @@
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
/**
|
|
140
|
+
/**
|
|
141
|
+
* @param {string} tag
|
|
142
|
+
* @returns {CodeMirror.matchingTag}
|
|
143
|
+
*/
|
|
141
144
|
findMatchingClose(tag) {
|
|
142
145
|
const /** @type {string[]} */ stack = [];
|
|
143
146
|
for (;;) {
|
|
@@ -175,7 +178,10 @@
|
|
|
175
178
|
}
|
|
176
179
|
}
|
|
177
180
|
|
|
178
|
-
/**
|
|
181
|
+
/**
|
|
182
|
+
* @param {string|undefined} tag
|
|
183
|
+
* @returns {CodeMirror.matchingTag}
|
|
184
|
+
*/
|
|
179
185
|
findMatchingOpen(tag) {
|
|
180
186
|
const /** @type {string[]} */ stack = [];
|
|
181
187
|
for (;;) {
|
|
@@ -214,35 +220,43 @@
|
|
|
214
220
|
}
|
|
215
221
|
}
|
|
216
222
|
|
|
217
|
-
CodeMirror.defineExtension(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
223
|
+
CodeMirror.defineExtension(
|
|
224
|
+
'findMatchingTag',
|
|
225
|
+
/**
|
|
226
|
+
* @param {CodeMirror.Position} pos
|
|
227
|
+
* @returns {CodeMirror.matchingTags}
|
|
228
|
+
*/
|
|
229
|
+
function(pos) {
|
|
230
|
+
let iter = new Iter(this, pos);
|
|
231
|
+
if (!iter.isTag()) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const end = iter.toTagEnd(),
|
|
235
|
+
to = end && Pos(iter.line, iter.ch);
|
|
236
|
+
const start = end && iter.toTagStart();
|
|
237
|
+
if (!start || cmpPos(iter, pos) > 0) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const tag = start[2].toLowerCase(),
|
|
241
|
+
here = {from: Pos(iter.line, iter.ch), to, tag};
|
|
242
|
+
if (end === 'selfClose' || voidTags.includes(tag)) {
|
|
243
|
+
return {open: here, close: null, at: 'self'};
|
|
244
|
+
}
|
|
233
245
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
246
|
+
if (start[1]) { // closing tag
|
|
247
|
+
return {open: iter.findMatchingOpen(tag), close: here, at: 'close'};
|
|
248
|
+
} // opening tag
|
|
249
|
+
iter = new Iter(this, to);
|
|
250
|
+
return {open: here, close: iter.findMatchingClose(tag), at: 'open'};
|
|
251
|
+
},
|
|
252
|
+
);
|
|
240
253
|
|
|
241
254
|
CodeMirror.defineExtension(
|
|
242
255
|
'findEnclosingTag',
|
|
243
256
|
/**
|
|
244
257
|
* @param {CodeMirror.Position} pos
|
|
245
258
|
* @param {string} tag
|
|
259
|
+
* @returns {CodeMirror.matchingTags}
|
|
246
260
|
*/
|
|
247
261
|
function(pos, tag) {
|
|
248
262
|
const iter = new Iter(this, pos);
|
|
@@ -258,12 +272,7 @@
|
|
|
258
272
|
},
|
|
259
273
|
);
|
|
260
274
|
|
|
261
|
-
|
|
262
|
-
* Used by addon/edit/closetag.js
|
|
263
|
-
* @param {CodeMirror.Editor} cm
|
|
264
|
-
* @param {CodeMirror.Position} pos
|
|
265
|
-
* @param {string} name
|
|
266
|
-
*/
|
|
275
|
+
// Used by addon/edit/closetag.js
|
|
267
276
|
CodeMirror.scanForClosingTag = function(cm, pos, name) {
|
|
268
277
|
const iter = new Iter(cm, pos);
|
|
269
278
|
return iter.findMatchingClose(name);
|
|
@@ -280,7 +289,7 @@
|
|
|
280
289
|
}
|
|
281
290
|
});
|
|
282
291
|
|
|
283
|
-
/** @param {CodeMirror.
|
|
292
|
+
/** @param {CodeMirror.EditorWithMatchingTags} cm */
|
|
284
293
|
function clear(cm) {
|
|
285
294
|
if (cm.state.tagHit) {
|
|
286
295
|
cm.state.tagHit.clear();
|
|
@@ -292,22 +301,14 @@
|
|
|
292
301
|
cm.state.tagOther = null;
|
|
293
302
|
}
|
|
294
303
|
|
|
295
|
-
/** @param {CodeMirror.
|
|
304
|
+
/** @param {CodeMirror.EditorWithMatchingTags} cm */
|
|
296
305
|
function doMatchTags(cm) {
|
|
297
306
|
cm.operation(() => {
|
|
298
307
|
clear(cm);
|
|
299
308
|
if (cm.somethingSelected()) {
|
|
300
309
|
return;
|
|
301
310
|
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* @typedef {object} matchingTag
|
|
305
|
-
* @property {string} at
|
|
306
|
-
* @property {CodeMirror.MarkerRange} open
|
|
307
|
-
* @property {CodeMirror.MarkerRange} close
|
|
308
|
-
*/
|
|
309
|
-
|
|
310
|
-
const /** @type {matchingTag}} */ match = cm.findMatchingTag(cm.getCursor());
|
|
311
|
+
const match = cm.findMatchingTag(cm.getCursor());
|
|
311
312
|
if (!match) {
|
|
312
313
|
return;
|
|
313
314
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikiplus-highlight",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.1",
|
|
4
4
|
"description": "A plugin for the MediaWiki front-end add-on \"Wikiplus\"",
|
|
5
5
|
"main": "main.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"homepage": "https://github.com/bhsd-harry/Wikiplus-highlight#readme",
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"eslint": "^8.8.0",
|
|
26
|
+
"types-mediawiki": "^1.2.0",
|
|
26
27
|
"uglify-js": "^3.15.5"
|
|
27
28
|
}
|
|
28
29
|
}
|
package/search.js
CHANGED
|
@@ -6,10 +6,7 @@
|
|
|
6
6
|
(() => {
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* @param {string} key
|
|
11
|
-
* @returns {string}
|
|
12
|
-
*/
|
|
9
|
+
/** @param {string} key */
|
|
13
10
|
const msg = key => mw.msg(`wphl-${key}`);
|
|
14
11
|
|
|
15
12
|
// Prepare elements
|
|
@@ -46,7 +43,7 @@
|
|
|
46
43
|
text: msg('addon-search'),
|
|
47
44
|
});
|
|
48
45
|
|
|
49
|
-
const
|
|
46
|
+
const escapeRegExp = mw.util.escapeRegExp || mw.RegExp.escape;
|
|
50
47
|
const /** @type {{token: (stream: CodeMirror.StringStream) => string}} */ overlay = {token: () => {}};
|
|
51
48
|
|
|
52
49
|
/**
|
|
@@ -74,17 +71,9 @@
|
|
|
74
71
|
$search.css('background-color', '').off('input', onInput);
|
|
75
72
|
};
|
|
76
73
|
|
|
77
|
-
/**
|
|
78
|
-
* @typedef {object} SearchCursor
|
|
79
|
-
* @property {() => boolean} findNext
|
|
80
|
-
* @property {() => boolean} findPrevious
|
|
81
|
-
* @property {() => CodeMirror.Position} from
|
|
82
|
-
* @property {() => CodeMirror.Position} to
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
74
|
// keyboard event handler of $search
|
|
86
75
|
let /** @type {string|RegExp} */ lastPtn,
|
|
87
|
-
/** @type {SearchCursor} */ cursor;
|
|
76
|
+
/** @type {CodeMirror.SearchCursor} */ cursor;
|
|
88
77
|
/**
|
|
89
78
|
* @param {CodeMirror.Editor} cm
|
|
90
79
|
* @param {boolean} dir
|
|
@@ -108,7 +97,7 @@
|
|
|
108
97
|
cursor = cm.getSearchCursor(ptn, cm.getCursor(), {caseFold: true});
|
|
109
98
|
}
|
|
110
99
|
const method = dir ? 'findNext' : 'findPrevious';
|
|
111
|
-
let result = cursor[method]();
|
|
100
|
+
let /** @type {boolean} */ result = cursor[method]();
|
|
112
101
|
if (!result) {
|
|
113
102
|
if (dir) {
|
|
114
103
|
cursor = cm.getSearchCursor(ptn, {line: 0, ch: 0}, {caseFold: true});
|
|
@@ -147,22 +136,23 @@
|
|
|
147
136
|
lastPtn = '';
|
|
148
137
|
};
|
|
149
138
|
|
|
150
|
-
/** @param {CodeMirror.Editor} doc */
|
|
151
139
|
CodeMirror.commands.findForward = doc => {
|
|
152
140
|
findNext(doc, true);
|
|
153
141
|
};
|
|
154
|
-
/** @param {CodeMirror.Editor} doc */
|
|
155
142
|
CodeMirror.commands.findBackward = doc => {
|
|
156
143
|
findNext(doc, false);
|
|
157
144
|
};
|
|
158
145
|
|
|
159
|
-
const
|
|
146
|
+
const {name} = $.client.profile(),
|
|
160
147
|
focus = name === 'safari'
|
|
161
148
|
? /** @param {CodeMirror.Editor} cm */ cm => {
|
|
162
149
|
cm.focus();
|
|
163
150
|
}
|
|
164
151
|
: () => {};
|
|
165
152
|
mw.hook('wiki-codemirror').add(/** @param {CodeMirror.Editor} cm */ cm => {
|
|
153
|
+
if (!cm.getOption('styleSelectedText')) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
166
156
|
const $textarea = $(cm.getWrapperElement()).prev('#Wikiplus-Quickedit');
|
|
167
157
|
if ($textarea.length === 0) {
|
|
168
158
|
return;
|