wikiparser-node 1.19.0 → 1.20.0
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 -0
- package/bundle/bundle-es7.min.js +24 -31
- package/bundle/bundle-lsp.min.js +25 -98
- package/bundle/bundle.min.js +25 -32
- package/config/default.json +49 -3
- package/config/minimum.json +5 -1
- package/data/ext/math.json +660 -0
- package/dist/addon/table.js +24 -5
- package/dist/addon/transclude.js +4 -4
- package/dist/base.d.mts +1 -1
- package/dist/base.d.ts +1 -1
- package/dist/bin/config.js +26 -8
- package/dist/index.js +10 -1
- package/dist/internal.d.ts +2 -0
- package/dist/lib/document.d.ts +1 -0
- package/dist/lib/document.js +10 -1
- package/dist/lib/element.js +15 -21
- package/dist/lib/lsp.js +88 -58
- package/dist/lib/node.js +21 -24
- package/dist/lib/text.js +3 -4
- package/dist/lib/title.js +2 -1
- package/dist/mixin/attributesParent.js +1 -1
- package/dist/mixin/fixed.d.ts +1 -2
- package/dist/mixin/fixed.js +2 -3
- package/dist/mixin/gapped.d.ts +4 -0
- package/dist/mixin/gapped.js +24 -0
- package/dist/mixin/hidden.js +1 -1
- package/dist/mixin/multiLine.d.ts +4 -0
- package/dist/mixin/multiLine.js +33 -0
- package/dist/mixin/noEscape.js +1 -1
- package/dist/mixin/padded.d.ts +5 -0
- package/dist/mixin/padded.js +24 -0
- package/dist/mixin/singleLine.js +1 -1
- package/dist/mixin/sol.js +1 -1
- package/dist/mixin/syntax.js +3 -3
- package/dist/parser/braces.js +8 -12
- package/dist/parser/commentAndExt.js +18 -2
- package/dist/parser/magicLinks.js +2 -2
- package/dist/parser/selector.js +5 -2
- package/dist/src/arg.js +10 -13
- package/dist/src/atom.js +2 -7
- package/dist/src/attribute.js +6 -6
- package/dist/src/attributes.js +8 -12
- package/dist/src/commented.d.ts +26 -0
- package/dist/src/commented.js +52 -0
- package/dist/src/converter.js +3 -6
- package/dist/src/converterFlags.js +266 -223
- package/dist/src/converterRule.d.ts +2 -2
- package/dist/src/converterRule.js +2 -2
- package/dist/src/extLink.d.ts +2 -3
- package/dist/src/extLink.js +222 -175
- package/dist/src/gallery.d.ts +4 -5
- package/dist/src/gallery.js +177 -144
- package/dist/src/heading.js +11 -11
- package/dist/src/hidden.js +2 -7
- package/dist/src/imageParameter.d.ts +2 -2
- package/dist/src/imageParameter.js +6 -5
- package/dist/src/imagemap.d.ts +2 -2
- package/dist/src/imagemap.js +155 -123
- package/dist/src/imagemapLink.d.ts +2 -2
- package/dist/src/index.js +44 -20
- package/dist/src/link/base.d.ts +2 -3
- package/dist/src/link/base.js +13 -15
- package/dist/src/link/file.d.ts +2 -3
- package/dist/src/link/file.js +3 -3
- package/dist/src/link/galleryImage.d.ts +2 -3
- package/dist/src/link/galleryImage.js +7 -13
- package/dist/src/magicLink.js +7 -9
- package/dist/src/nested.d.ts +2 -2
- package/dist/src/nested.js +4 -7
- package/dist/src/nowiki/comment.js +2 -5
- package/dist/src/nowiki/doubleUnderscore.js +2 -5
- package/dist/src/nowiki/index.d.ts +2 -2
- package/dist/src/nowiki/index.js +2 -1
- package/dist/src/onlyinclude.js +6 -13
- package/dist/src/paramTag/index.d.ts +2 -2
- package/dist/src/paramTag/index.js +102 -66
- package/dist/src/parameter.d.ts +4 -5
- package/dist/src/parameter.js +13 -13
- package/dist/src/pre.d.ts +4 -5
- package/dist/src/pre.js +8 -17
- package/dist/src/syntax.d.ts +1 -1
- package/dist/src/syntax.js +2 -7
- package/dist/src/table/base.d.ts +2 -2
- package/dist/src/table/base.js +8 -8
- package/dist/src/table/index.js +1 -1
- package/dist/src/table/td.d.ts +3 -3
- package/dist/src/table/td.js +9 -9
- package/dist/src/table/tr.d.ts +2 -2
- package/dist/src/tagPair/ext.js +35 -30
- package/dist/src/tagPair/index.d.ts +1 -1
- package/dist/src/tagPair/index.js +2 -5
- package/dist/src/tagPair/translate.d.ts +38 -0
- package/dist/src/tagPair/translate.js +129 -0
- package/dist/src/transclude.js +5 -6
- package/dist/util/html.js +16 -1
- package/dist/util/lint.js +17 -30
- package/dist/util/sharable.js +29 -1
- package/dist/util/sharable.mjs +31 -3
- package/dist/util/string.js +14 -1
- package/extensions/dist/base.js +1 -1
- package/extensions/dist/lsp.js +13 -2
- package/package.json +4 -3
- package/extensions/es7/base.js +0 -320
- package/extensions/es7/lint.js +0 -97
package/extensions/es7/base.js
DELETED
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
(() => {
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var _a;
|
|
12
|
-
const version = '1.19.0', src = (_a = document.currentScript) === null || _a === void 0 ? void 0 : _a.src, file = /\/extensions\/dist\/base\.(?:min\.)?js$/u, CDN = src && file.test(src)
|
|
13
|
-
? src.replace(file, '')
|
|
14
|
-
: `https://testingcf.jsdelivr.net/npm/wikiparser-node@${version}`;
|
|
15
|
-
const workerJS = () => {
|
|
16
|
-
importScripts('$CDN/bundle/bundle-es7.min.js');
|
|
17
|
-
const entities = { '&': 'amp', '<': 'lt', '>': 'gt' }, lsps = new Map(), last = { include: true };
|
|
18
|
-
const parse = (wikitext, include = false, stage) => {
|
|
19
|
-
if (stage === undefined && last.wikitext === wikitext && last.include === include) {
|
|
20
|
-
return last.root;
|
|
21
|
-
}
|
|
22
|
-
const root = Parser.parse(wikitext, include, stage);
|
|
23
|
-
if (stage === undefined) {
|
|
24
|
-
last.wikitext = wikitext;
|
|
25
|
-
last.include = include;
|
|
26
|
-
last.root = root;
|
|
27
|
-
}
|
|
28
|
-
return root;
|
|
29
|
-
};
|
|
30
|
-
const getLSP = (qid, include = true) => {
|
|
31
|
-
const id = Math.floor(qid);
|
|
32
|
-
if (lsps.has(id)) {
|
|
33
|
-
return lsps.get(id);
|
|
34
|
-
}
|
|
35
|
-
const lsp = Parser.createLanguageService({});
|
|
36
|
-
lsp.include = include;
|
|
37
|
-
lsps.set(id, lsp);
|
|
38
|
-
return lsp;
|
|
39
|
-
};
|
|
40
|
-
const parseColor = (s) => {
|
|
41
|
-
var _a;
|
|
42
|
-
if (s.startsWith('#')) {
|
|
43
|
-
const short = s.length < 7;
|
|
44
|
-
return [
|
|
45
|
-
parseInt(short ? s.charAt(1).repeat(2) : s.slice(1, 3), 16),
|
|
46
|
-
parseInt(short ? s.charAt(2).repeat(2) : s.slice(3, 5), 16),
|
|
47
|
-
parseInt(short ? s.charAt(3).repeat(2) : s.slice(5, 7), 16),
|
|
48
|
-
parseInt((short ? s.charAt(4).repeat(2) : s.slice(7, 9)) || 'ff', 16)
|
|
49
|
-
/ 255,
|
|
50
|
-
];
|
|
51
|
-
}
|
|
52
|
-
const values = s.slice(s.indexOf('(') + 1, -1).trim()
|
|
53
|
-
.split(/\s+(?:[,/]\s*)?|[,/]\s*/u)
|
|
54
|
-
.map(v => parseFloat(v) / (v.endsWith('%') ? 100 : 1));
|
|
55
|
-
return [
|
|
56
|
-
values[0],
|
|
57
|
-
values[1],
|
|
58
|
-
values[2],
|
|
59
|
-
(_a = values[3]) !== null && _a !== void 0 ? _a : 1,
|
|
60
|
-
];
|
|
61
|
-
};
|
|
62
|
-
self.onmessage = ({ data }) => {
|
|
63
|
-
const [command, qid, wikitext, include, stage, newName] = data;
|
|
64
|
-
switch (command) {
|
|
65
|
-
case 'setI18N':
|
|
66
|
-
Parser.i18n = qid;
|
|
67
|
-
break;
|
|
68
|
-
case 'setConfig':
|
|
69
|
-
Parser.config = qid;
|
|
70
|
-
delete last.wikitext;
|
|
71
|
-
break;
|
|
72
|
-
case 'getConfig':
|
|
73
|
-
postMessage([qid, Parser.getConfig()]);
|
|
74
|
-
break;
|
|
75
|
-
case 'json':
|
|
76
|
-
postMessage([qid, parse(wikitext, include, stage).json()]);
|
|
77
|
-
break;
|
|
78
|
-
case 'lint':
|
|
79
|
-
postMessage([qid, parse(wikitext, include).lint(), wikitext]);
|
|
80
|
-
break;
|
|
81
|
-
case 'print':
|
|
82
|
-
postMessage([
|
|
83
|
-
qid,
|
|
84
|
-
parse(wikitext, include, stage).childNodes.map(child => [
|
|
85
|
-
stage !== null && stage !== void 0 ? stage : Infinity,
|
|
86
|
-
String(child),
|
|
87
|
-
child.type === 'text'
|
|
88
|
-
? String(child).replace(/[&<>]/gu, p => `&${entities[p]};`)
|
|
89
|
-
: child.print(),
|
|
90
|
-
]),
|
|
91
|
-
]);
|
|
92
|
-
break;
|
|
93
|
-
case 'destroy':
|
|
94
|
-
getLSP(qid).destroy();
|
|
95
|
-
lsps.delete(qid);
|
|
96
|
-
break;
|
|
97
|
-
case 'data':
|
|
98
|
-
getLSP(qid, include).data = wikitext;
|
|
99
|
-
break;
|
|
100
|
-
case 'colorPresentations':
|
|
101
|
-
postMessage([qid, getLSP(qid, include).provideColorPresentations(wikitext)]);
|
|
102
|
-
break;
|
|
103
|
-
case 'documentColors':
|
|
104
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
-
postMessage([
|
|
106
|
-
qid,
|
|
107
|
-
yield getLSP(qid, include).provideDocumentColors(parseColor, wikitext, false),
|
|
108
|
-
wikitext,
|
|
109
|
-
]);
|
|
110
|
-
}))();
|
|
111
|
-
break;
|
|
112
|
-
case 'foldingRanges':
|
|
113
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
-
postMessage([qid, yield getLSP(qid, include).provideFoldingRanges(wikitext), wikitext]);
|
|
115
|
-
}))();
|
|
116
|
-
break;
|
|
117
|
-
case 'links':
|
|
118
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
119
|
-
postMessage([qid, yield getLSP(qid, include).provideLinks(wikitext), wikitext]);
|
|
120
|
-
}))();
|
|
121
|
-
break;
|
|
122
|
-
case 'diagnostics':
|
|
123
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
-
postMessage([qid, yield getLSP(qid, include).provideDiagnostics(wikitext, stage), wikitext]);
|
|
125
|
-
}))();
|
|
126
|
-
break;
|
|
127
|
-
case 'completionItems':
|
|
128
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
129
|
-
postMessage([qid, yield getLSP(qid, include).provideCompletionItems(wikitext, stage), wikitext]);
|
|
130
|
-
}))();
|
|
131
|
-
break;
|
|
132
|
-
case 'references':
|
|
133
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
134
|
-
postMessage([qid, yield getLSP(qid, include).provideReferences(wikitext, stage), wikitext]);
|
|
135
|
-
}))();
|
|
136
|
-
break;
|
|
137
|
-
case 'definition':
|
|
138
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
139
|
-
postMessage([qid, yield getLSP(qid, include).provideDefinition(wikitext, stage), wikitext]);
|
|
140
|
-
}))();
|
|
141
|
-
break;
|
|
142
|
-
case 'renameLocation':
|
|
143
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
144
|
-
postMessage([qid, yield getLSP(qid, include).resolveRenameLocation(wikitext, stage), wikitext]);
|
|
145
|
-
}))();
|
|
146
|
-
break;
|
|
147
|
-
case 'renameEdits':
|
|
148
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
149
|
-
postMessage([
|
|
150
|
-
qid,
|
|
151
|
-
yield getLSP(qid, include).provideRenameEdits(wikitext, stage, newName),
|
|
152
|
-
wikitext,
|
|
153
|
-
]);
|
|
154
|
-
}))();
|
|
155
|
-
break;
|
|
156
|
-
case 'hover':
|
|
157
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
158
|
-
postMessage([qid, yield getLSP(qid, include).provideHover(wikitext, stage), wikitext]);
|
|
159
|
-
}))();
|
|
160
|
-
break;
|
|
161
|
-
case 'signatureHelp':
|
|
162
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
163
|
-
postMessage([qid, yield getLSP(qid, include).provideSignatureHelp(wikitext, stage), wikitext]);
|
|
164
|
-
}))();
|
|
165
|
-
break;
|
|
166
|
-
case 'inlayHints':
|
|
167
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
168
|
-
postMessage([qid, yield getLSP(qid, include).provideInlayHints(wikitext), wikitext]);
|
|
169
|
-
}))();
|
|
170
|
-
break;
|
|
171
|
-
case 'findStyleTokens':
|
|
172
|
-
postMessage([qid, getLSP(qid).findStyleTokens().map(token => token.json())]);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
};
|
|
176
|
-
const blob = new Blob([`(${String(workerJS).replace('$CDN', CDN)})()`], { type: 'text/javascript' }), url = URL.createObjectURL(blob), worker = new Worker(url);
|
|
177
|
-
URL.revokeObjectURL(url);
|
|
178
|
-
const getListener = (qid, resolve, raw) => {
|
|
179
|
-
const listener = ({ data: [rid, res, resRaw] }) => {
|
|
180
|
-
if (rid === qid && (raw === undefined || raw === resRaw)) {
|
|
181
|
-
worker.removeEventListener('message', listener);
|
|
182
|
-
resolve(res);
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
return listener;
|
|
186
|
-
};
|
|
187
|
-
const setI18N = (i18n) => {
|
|
188
|
-
worker.postMessage(['setI18N', i18n]);
|
|
189
|
-
};
|
|
190
|
-
const setConfig = (config) => {
|
|
191
|
-
worker.postMessage(['setConfig', config]);
|
|
192
|
-
wikiparse.config = config;
|
|
193
|
-
};
|
|
194
|
-
const getFeedback = (command, qid, strict, raw, ...args) => new Promise(resolve => {
|
|
195
|
-
worker.addEventListener('message', getListener(qid, resolve, strict ? raw : undefined));
|
|
196
|
-
worker.postMessage([command, qid, raw, ...args]);
|
|
197
|
-
});
|
|
198
|
-
const getConfig = () => getFeedback('getConfig', -3);
|
|
199
|
-
const json = (wikitext, include, qid = -4, stage) => getFeedback('json', qid, false, wikitext, include, stage);
|
|
200
|
-
const print = (wikitext, include, stage, qid = -1) => getFeedback('print', qid, false, wikitext, include, stage);
|
|
201
|
-
const lint = (wikitext, include, qid = -2) => getFeedback('lint', qid, true, wikitext, include);
|
|
202
|
-
const provide = (command, qid, wikitext, ...args) => getFeedback(command, qid, typeof wikitext === 'string', wikitext, ...args);
|
|
203
|
-
const append = (parent, text) => {
|
|
204
|
-
if (text) {
|
|
205
|
-
parent.append(text);
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
const splitNewLine = (html) => {
|
|
209
|
-
let cur = html.cloneNode();
|
|
210
|
-
cur.style.padding = '';
|
|
211
|
-
const result = [cur];
|
|
212
|
-
for (const child of html.childNodes) {
|
|
213
|
-
const { textContent } = child;
|
|
214
|
-
if (!(textContent === null || textContent === void 0 ? void 0 : textContent.includes('\n'))) {
|
|
215
|
-
cur.append(child.cloneNode(true));
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
const lines = child.nodeType === Node.TEXT_NODE
|
|
219
|
-
? textContent.split('\n')
|
|
220
|
-
: splitNewLine(child);
|
|
221
|
-
append(cur, lines[0]);
|
|
222
|
-
for (const text of lines.slice(1)) {
|
|
223
|
-
cur = html.cloneNode();
|
|
224
|
-
cur.style.padding = '';
|
|
225
|
-
result.push(cur);
|
|
226
|
-
append(cur, text);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return result;
|
|
230
|
-
};
|
|
231
|
-
const getGutter = (container) => container.querySelector('.wikiparser-line-numbers');
|
|
232
|
-
const size = (html) => {
|
|
233
|
-
const container = html.parentElement, { isContentEditable } = html, { clientHeight } = container, gutter = getGutter(container);
|
|
234
|
-
if (!gutter) {
|
|
235
|
-
intersectionObserver.unobserve(html);
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
html.style.marginLeft = '';
|
|
239
|
-
const start = Number(html.dataset['start'] || 1), lines = splitNewLine(html), width = `${String(lines.length + start - 1).length + 1.5}ch`;
|
|
240
|
-
html.style.marginLeft = width;
|
|
241
|
-
gutter.style.width = width;
|
|
242
|
-
if (isContentEditable) {
|
|
243
|
-
gutter.style.minHeight = `${clientHeight + 1}px`;
|
|
244
|
-
}
|
|
245
|
-
const sizer = document.createElement('span'), { style: { paddingLeft, paddingRight } } = html;
|
|
246
|
-
sizer.className = 'wikiparser-sizer';
|
|
247
|
-
sizer.style.paddingLeft = paddingLeft;
|
|
248
|
-
sizer.style.paddingRight = paddingRight;
|
|
249
|
-
for (const child of lines) {
|
|
250
|
-
sizer.append(child, '\n');
|
|
251
|
-
}
|
|
252
|
-
html.append(sizer);
|
|
253
|
-
let line, lastTop;
|
|
254
|
-
for (let i = 0; i < lines.length; i++) {
|
|
255
|
-
const child = lines[i], { top } = child.getBoundingClientRect();
|
|
256
|
-
if (line) {
|
|
257
|
-
line.style.height = `${top - lastTop}px`;
|
|
258
|
-
}
|
|
259
|
-
line = document.createElement('span');
|
|
260
|
-
line.textContent = String(i + start);
|
|
261
|
-
gutter.append(line);
|
|
262
|
-
lastTop = top;
|
|
263
|
-
}
|
|
264
|
-
if (line) {
|
|
265
|
-
if (isContentEditable) {
|
|
266
|
-
line.style.height = `${clientHeight}px`;
|
|
267
|
-
}
|
|
268
|
-
else if (html.offsetHeight <= clientHeight) {
|
|
269
|
-
line.style.height = `${container.getBoundingClientRect().top + container.scrollHeight - lastTop}px`;
|
|
270
|
-
container.style.overflowY = 'hidden';
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
line.style.height = `${html.getBoundingClientRect().bottom - lastTop}px`;
|
|
274
|
-
container.style.overflowY = '';
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
sizer.remove();
|
|
278
|
-
intersectionObserver.unobserve(html);
|
|
279
|
-
};
|
|
280
|
-
const intersectionObserver = new IntersectionObserver(entries => {
|
|
281
|
-
for (const entry of entries) {
|
|
282
|
-
if (!entry.isIntersecting) {
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
size(entry.target);
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
const lineNumbers = (html, start = 1, paddingTop = '') => {
|
|
289
|
-
const container = html.parentElement, gutter = document.createElement('span');
|
|
290
|
-
html.dataset['start'] = String(start);
|
|
291
|
-
gutter.className = 'wikiparser-line-numbers';
|
|
292
|
-
gutter.style.paddingTop = paddingTop;
|
|
293
|
-
container.classList.add('wikiparse-container');
|
|
294
|
-
container.append(gutter);
|
|
295
|
-
if (getComputedStyle(html).whiteSpace !== 'pre') {
|
|
296
|
-
html.style.whiteSpace = 'pre-wrap';
|
|
297
|
-
}
|
|
298
|
-
if (html.offsetParent) {
|
|
299
|
-
size(html);
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
intersectionObserver.observe(html);
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
const wikiparse = {
|
|
306
|
-
version,
|
|
307
|
-
CDN,
|
|
308
|
-
id: 0,
|
|
309
|
-
config: {},
|
|
310
|
-
setI18N,
|
|
311
|
-
setConfig,
|
|
312
|
-
getConfig,
|
|
313
|
-
print,
|
|
314
|
-
lint,
|
|
315
|
-
json,
|
|
316
|
-
lineNumbers,
|
|
317
|
-
provide,
|
|
318
|
-
};
|
|
319
|
-
Object.assign(window, { wikiparse });
|
|
320
|
-
})();
|
package/extensions/es7/lint.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
(() => {
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
-
};
|
|
17
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
-
};
|
|
22
|
-
var _Linter_instances, _Linter_id, _Linter_wikitext, _Linter_running, _Linter_done, _Linter_config, _Linter_lint;
|
|
23
|
-
class Linter {
|
|
24
|
-
constructor(include) {
|
|
25
|
-
_Linter_instances.add(this);
|
|
26
|
-
_Linter_id.set(this, void 0);
|
|
27
|
-
_Linter_wikitext.set(this, void 0);
|
|
28
|
-
_Linter_running.set(this, void 0);
|
|
29
|
-
_Linter_done.set(this, void 0);
|
|
30
|
-
_Linter_config.set(this, void 0);
|
|
31
|
-
__classPrivateFieldSet(this, _Linter_id, wikiparse.id++, "f");
|
|
32
|
-
this.include = Boolean(include);
|
|
33
|
-
}
|
|
34
|
-
queue(wikitext) {
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
var _a;
|
|
37
|
-
if (__classPrivateFieldGet(this, _Linter_wikitext, "f") === wikitext && __classPrivateFieldGet(this, _Linter_config, "f") === wikiparse.config && !__classPrivateFieldGet(this, _Linter_running, "f")) {
|
|
38
|
-
return __classPrivateFieldGet(this, _Linter_done, "f");
|
|
39
|
-
}
|
|
40
|
-
__classPrivateFieldSet(this, _Linter_wikitext, wikitext, "f");
|
|
41
|
-
__classPrivateFieldSet(this, _Linter_running, (_a = __classPrivateFieldGet(this, _Linter_running, "f")) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _Linter_instances, "m", _Linter_lint).call(this, wikitext), "f");
|
|
42
|
-
return __classPrivateFieldGet(this, _Linter_running, "f");
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
codemirror(wikitext) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
return (yield this.queue(wikitext))
|
|
48
|
-
.map(({ startIndex, endIndex, severity, message, rule, fix, suggestions = [] }) => ({
|
|
49
|
-
source: 'WikiLint',
|
|
50
|
-
from: startIndex,
|
|
51
|
-
to: endIndex,
|
|
52
|
-
severity,
|
|
53
|
-
rule,
|
|
54
|
-
message: `${message} (${rule})`,
|
|
55
|
-
actions: [
|
|
56
|
-
...fix ? [{ name: `Fix: ${fix.desc}`, fix }] : [],
|
|
57
|
-
...suggestions.map(suggestion => ({ name: `Suggestion: ${suggestion.desc}`, fix: suggestion })),
|
|
58
|
-
].map(({ name, fix: { range: [from, to], text } }) => ({
|
|
59
|
-
name,
|
|
60
|
-
apply(view) {
|
|
61
|
-
view.dispatch({ changes: { from, to, insert: text } });
|
|
62
|
-
},
|
|
63
|
-
})),
|
|
64
|
-
}));
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
monaco(wikitext) {
|
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
return (yield this.queue(wikitext))
|
|
70
|
-
.map(({ startLine, startCol, endLine, endCol, severity, message, rule }) => ({
|
|
71
|
-
source: 'WikiLint',
|
|
72
|
-
startLineNumber: startLine + 1,
|
|
73
|
-
startColumn: startCol + 1,
|
|
74
|
-
endLineNumber: endLine + 1,
|
|
75
|
-
endColumn: endCol + 1,
|
|
76
|
-
severity: severity === 'error' ? 8 : 4,
|
|
77
|
-
code: rule,
|
|
78
|
-
message,
|
|
79
|
-
}));
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
_Linter_id = new WeakMap(), _Linter_wikitext = new WeakMap(), _Linter_running = new WeakMap(), _Linter_done = new WeakMap(), _Linter_config = new WeakMap(), _Linter_instances = new WeakSet(), _Linter_lint = function _Linter_lint(wikitext) {
|
|
84
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
__classPrivateFieldSet(this, _Linter_config, wikiparse.config, "f");
|
|
86
|
-
const { include } = this, errors = yield wikiparse.lint(wikitext, include, __classPrivateFieldGet(this, _Linter_id, "f"));
|
|
87
|
-
if (this.include === include && __classPrivateFieldGet(this, _Linter_wikitext, "f") === wikitext && __classPrivateFieldGet(this, _Linter_config, "f") === wikiparse.config) {
|
|
88
|
-
__classPrivateFieldSet(this, _Linter_running, undefined, "f");
|
|
89
|
-
__classPrivateFieldSet(this, _Linter_done, errors, "f");
|
|
90
|
-
return errors;
|
|
91
|
-
}
|
|
92
|
-
__classPrivateFieldSet(this, _Linter_running, __classPrivateFieldGet(this, _Linter_instances, "m", _Linter_lint).call(this, __classPrivateFieldGet(this, _Linter_wikitext, "f")), "f");
|
|
93
|
-
return __classPrivateFieldGet(this, _Linter_running, "f");
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
wikiparse.Linter = Linter;
|
|
97
|
-
})();
|