@bhsd/codemirror-mediawiki 3.0.0 → 3.0.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 +11 -8
- package/dist/linter.js +26 -26
- package/dist/main.min.js +14 -13
- package/dist/mw.min.js +30 -29
- package/dist/wiki.min.js +29 -28
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -261,13 +261,15 @@ registerLanguage('python', python);
|
|
|
261
261
|
**param**: `boolean` whether to initialize immediately, default as true
|
|
262
262
|
|
|
263
263
|
```js
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
264
|
+
let cm;
|
|
265
|
+
cm = new CodeMirror6(textarea); // plain text
|
|
266
|
+
cm = new CodeMirror6(textarea, 'mediawiki', mwConfig);
|
|
267
|
+
cm = new CodeMirror6(textarea, 'html', mwConfig);
|
|
268
|
+
cm = new CodeMirror6(textarea, 'css');
|
|
269
|
+
cm = new CodeMirror6(textarea, 'javascript');
|
|
270
|
+
cm = new CodeMirror6(textarea, 'json');
|
|
271
|
+
cm = new CodeMirror6(textarea, 'lua');
|
|
272
|
+
cm = new CodeMirror6(textarea, 'vue');
|
|
271
273
|
```
|
|
272
274
|
|
|
273
275
|
</details>
|
|
@@ -585,11 +587,12 @@ Set the language mode.
|
|
|
585
587
|
|
|
586
588
|
```js
|
|
587
589
|
cm.setLanguage('mediawiki', mwConfig);
|
|
588
|
-
cm.setLanguage('html', mwConfig);
|
|
590
|
+
cm.setLanguage('html', mwConfig);
|
|
589
591
|
cm.setLanguage('css');
|
|
590
592
|
cm.setLanguage('javascript');
|
|
591
593
|
cm.setLanguage('json');
|
|
592
594
|
cm.setLanguage('lua');
|
|
595
|
+
cm.setLanguage('vue');
|
|
593
596
|
```
|
|
594
597
|
|
|
595
598
|
</details>
|
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
|
};
|