@bhsd/codemirror-mediawiki 3.0.1 → 3.0.3
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/dist/codemirror.js +2 -7
- package/dist/linter.js +26 -26
- package/dist/main.min.js +18 -17
- package/dist/mw.min.js +20 -19
- package/dist/wiki.min.js +17 -16
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +7 -8
- package/dist/lsp.d.ts +0 -3
- package/dist/lsp.js +0 -34
package/dist/codemirror.js
CHANGED
|
@@ -27,7 +27,6 @@ import toolKeymap from './keymap';
|
|
|
27
27
|
import statusBar from './statusBar';
|
|
28
28
|
import { detectIndent } from './indent';
|
|
29
29
|
import bracketMatching from './matchBrackets';
|
|
30
|
-
import wikitextLSP from './lsp';
|
|
31
30
|
import javascript from './javascript';
|
|
32
31
|
import css from './css';
|
|
33
32
|
import lua from './lua';
|
|
@@ -323,15 +322,11 @@ export class CodeMirror6 {
|
|
|
323
322
|
* @param lang language
|
|
324
323
|
* @param config language configuration
|
|
325
324
|
*/
|
|
325
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
326
326
|
async setLanguage(lang = 'plain', config) {
|
|
327
327
|
this.#lang = lang;
|
|
328
328
|
if (this.#view) {
|
|
329
|
-
|
|
330
|
-
ws: { // eslint-disable-line no-unused-labels
|
|
331
|
-
if (lang === 'mediawiki') {
|
|
332
|
-
ext = [ext, await wikitextLSP()];
|
|
333
|
-
}
|
|
334
|
-
}
|
|
329
|
+
const ext = (languages[lang] ?? plain)(config);
|
|
335
330
|
this.#effects([
|
|
336
331
|
this.#language.reconfigure(ext),
|
|
337
332
|
this.#linter.reconfigure(linters[lang] ?? []),
|
package/dist/linter.js
CHANGED
|
@@ -6,16 +6,16 @@ import { styleLint } from '@bhsd/stylelint-util';
|
|
|
6
6
|
* 计算位置
|
|
7
7
|
* @param range 范围
|
|
8
8
|
* @param lineOrOffset 行号或相对位置
|
|
9
|
-
* @param
|
|
9
|
+
* @param column 列号
|
|
10
10
|
*/
|
|
11
|
-
const offsetAt = (range, lineOrOffset,
|
|
12
|
-
if (
|
|
13
|
-
return Math.min(range[1], range[0] + Math.max(0, lineOrOffset
|
|
11
|
+
const offsetAt = (range, lineOrOffset, column) => {
|
|
12
|
+
if (column === undefined) {
|
|
13
|
+
return Math.min(range[1], range[0] + Math.max(0, lineOrOffset));
|
|
14
14
|
}
|
|
15
15
|
else if (lineOrOffset === -2) {
|
|
16
16
|
return range[0];
|
|
17
17
|
}
|
|
18
|
-
return lineOrOffset === 0 ? range[1] : range[0] +
|
|
18
|
+
return lineOrOffset === 0 ? range[1] : range[0] + column;
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
21
|
* 获取伪CSS代码块的前缀
|
|
@@ -41,41 +41,41 @@ const indexToPos = (code, index) => {
|
|
|
41
41
|
*/
|
|
42
42
|
export const getWikiLinter = async (opt, obj) => {
|
|
43
43
|
await getWikiparse(opt?.['getConfig'], opt?.['i18n']);
|
|
44
|
-
const lsp = getLSP(obj, opt?.['include']);
|
|
44
|
+
const lsp = getLSP(obj, opt?.['include']), cssLint = await getCssLinter();
|
|
45
45
|
return async (text, config) => {
|
|
46
46
|
const defaultSeverity = config?.['defaultSeverity'] ?? 2, diagnostics = (await lsp.provideDiagnostics(text)).filter(({ code, severity }) => Number(config?.[code] ?? defaultSeverity) > Number(severity === 2)), tokens = 'findStyleTokens' in lsp && config?.['invalid-css'] !== '0' ? await lsp.findStyleTokens() : [];
|
|
47
47
|
if (tokens.length === 0) {
|
|
48
48
|
return diagnostics;
|
|
49
49
|
}
|
|
50
|
-
const
|
|
50
|
+
const lines = tokens.map((token, i) => `${getPrefix(token, i)}${sanitizeInlineStyle(token.childNodes[1].childNodes[0].data)
|
|
51
|
+
.replace(/\n/gu, ' ')}\n}`);
|
|
51
52
|
return [
|
|
52
53
|
...diagnostics,
|
|
53
|
-
...(await cssLint(
|
|
54
|
-
.
|
|
55
|
-
const i = Math.ceil(line / 3),
|
|
56
|
-
return {
|
|
54
|
+
...(await cssLint(lines.join('\n'), config?.['css']))
|
|
55
|
+
.map(({ line, column, endLine, endColumn, rule, severity, text: message, fix }) => {
|
|
56
|
+
const i = Math.ceil(line / 3), { length } = getPrefix(tokens[i - 1], i), { range } = tokens[i - 1].childNodes[1].childNodes[0], from = offsetAt(range, line - 3 * i, column - 1), diagnostic = {
|
|
57
57
|
from,
|
|
58
58
|
to: endLine === undefined ? from : offsetAt(range, endLine - 3 * i, endColumn - 1),
|
|
59
59
|
severity: severity === 'error' ? 1 : 2,
|
|
60
60
|
source: 'Stylelint',
|
|
61
61
|
code: rule,
|
|
62
62
|
message,
|
|
63
|
-
...fix
|
|
64
|
-
? {
|
|
65
|
-
data: [
|
|
66
|
-
{
|
|
67
|
-
range: {
|
|
68
|
-
start: indexToPos(text, offsetAt(range, fix.range[0], prefix)),
|
|
69
|
-
end: indexToPos(text, offsetAt(range, fix.range[1], prefix)),
|
|
70
|
-
},
|
|
71
|
-
newText: fix.text,
|
|
72
|
-
title: 'Fix: Stylelint',
|
|
73
|
-
fix: true,
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
}
|
|
77
|
-
: {},
|
|
78
63
|
};
|
|
64
|
+
if (fix) {
|
|
65
|
+
const before = lines.slice(0, i - 1).join('\n').length + 1 + length;
|
|
66
|
+
diagnostic.data = [
|
|
67
|
+
{
|
|
68
|
+
range: {
|
|
69
|
+
start: indexToPos(text, offsetAt(range, fix.range[0] - before)),
|
|
70
|
+
end: indexToPos(text, offsetAt(range, fix.range[1] - before)),
|
|
71
|
+
},
|
|
72
|
+
newText: fix.text,
|
|
73
|
+
title: 'Fix: Stylelint',
|
|
74
|
+
fix: true,
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
return diagnostic;
|
|
79
79
|
}),
|
|
80
80
|
];
|
|
81
81
|
};
|