@bhsd/codemirror-mediawiki 2.19.4 → 2.19.6
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 +5 -4
- package/dist/bidi.d.ts +2 -1
- package/dist/codemirror.d.ts +4 -27
- package/dist/config.d.ts +0 -1
- package/dist/fold.d.ts +8 -1
- package/dist/linter.mjs +116 -0
- package/dist/main.min.js +14 -14
- package/dist/matchTag.d.ts +4 -3
- package/dist/mw.min.js +19 -19
- package/dist/mwConfig.mjs +161 -0
- package/dist/openExtLinks.d.ts +1 -1
- package/dist/openLinks.d.ts +4 -0
- package/dist/ref.d.ts +0 -5
- package/dist/static.d.ts +1 -1
- package/dist/token.d.ts +17 -6
- package/dist/wiki.min.js +19 -19
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/mediawiki.css +0 -11
- package/mw/config.ts +180 -0
- package/package.json +10 -4
- package/src/linter.ts +149 -0
- package/src/static.ts +66 -0
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
[](https://www.npmjs.com/package/@bhsd/codemirror-mediawiki)
|
|
2
2
|
[](https://github.com/bhsd-harry/codemirror-mediawiki/actions/workflows/codeql.yml)
|
|
3
|
+
[](https://www.npmjs.com/package/@bhsd/codemirror-mediawiki)
|
|
3
4
|
|
|
4
5
|
<details>
|
|
5
6
|
<summary>Expand</summary>
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
- [escape](#escape)
|
|
46
47
|
- [tagMatching](#tagmatching)
|
|
47
48
|
- [refHover](#refhover)
|
|
48
|
-
- [
|
|
49
|
+
- [openLinks](#openlinks)
|
|
49
50
|
|
|
50
51
|
</details>
|
|
51
52
|
|
|
@@ -550,8 +551,8 @@ Matched or unmatched tags are highlighted in cyan or dark red when the cursor is
|
|
|
550
551
|
|
|
551
552
|
Show the content of the `<ref>` tag defined elsewhere when hovering.
|
|
552
553
|
|
|
553
|
-
##
|
|
554
|
+
## openLinks
|
|
554
555
|
|
|
555
|
-
*version added: 2.19.
|
|
556
|
+
*version added: 2.19.6*
|
|
556
557
|
|
|
557
|
-
CTRL/CMD-click opens
|
|
558
|
+
CTRL/CMD-click opens a link in a new tab.
|
package/dist/bidi.d.ts
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { Direction, ViewPlugin } from '@codemirror/view';
|
|
7
7
|
import type { ViewUpdate, DecorationSet } from '@codemirror/view';
|
|
8
|
-
|
|
8
|
+
declare const _default: ViewPlugin<{
|
|
9
9
|
isolates: DecorationSet;
|
|
10
10
|
tree: import("@lezer/common").Tree;
|
|
11
11
|
dir: Direction;
|
|
12
12
|
update({ docChanged, viewportChanged, state, view }: ViewUpdate): void;
|
|
13
13
|
}>;
|
|
14
|
+
export default _default;
|
package/dist/codemirror.d.ts
CHANGED
|
@@ -3,14 +3,16 @@ import type { KeyBinding } from '@codemirror/view';
|
|
|
3
3
|
import type { Extension, Text } from '@codemirror/state';
|
|
4
4
|
import type { SyntaxNode } from '@lezer/common';
|
|
5
5
|
import type { Diagnostic } from '@codemirror/lint';
|
|
6
|
+
import type { Config } from 'wikiparser-node';
|
|
6
7
|
import type { MwConfig } from './token';
|
|
7
8
|
import type { DocRange } from './fold';
|
|
8
9
|
export type { MwConfig };
|
|
9
10
|
export type LintSource = (doc: Text) => Diagnostic[] | Promise<Diagnostic[]>;
|
|
10
|
-
export type Addon<T> = [(config?: T) => Extension, Record<string, T>];
|
|
11
|
+
export type Addon<T> = [(config?: T, cm?: CodeMirror6) => Extension, Record<string, T>];
|
|
11
12
|
/** CodeMirror 6 编辑器 */
|
|
12
13
|
export declare class CodeMirror6 {
|
|
13
14
|
#private;
|
|
15
|
+
langConfig: MwConfig | undefined;
|
|
14
16
|
get textarea(): HTMLTextAreaElement;
|
|
15
17
|
get view(): EditorView | undefined;
|
|
16
18
|
get lang(): string;
|
|
@@ -88,31 +90,6 @@ export declare class CodeMirror6 {
|
|
|
88
90
|
anchor: number;
|
|
89
91
|
head: number;
|
|
90
92
|
}): void;
|
|
91
|
-
/** 支持的MediaWiki扩展标签 */
|
|
92
|
-
static mwTagModes: {
|
|
93
|
-
onlyinclude: string;
|
|
94
|
-
includeonly: string;
|
|
95
|
-
noinclude: string;
|
|
96
|
-
pre: string;
|
|
97
|
-
nowiki: string;
|
|
98
|
-
indicator: string;
|
|
99
|
-
poem: string;
|
|
100
|
-
ref: string;
|
|
101
|
-
references: string;
|
|
102
|
-
gallery: string;
|
|
103
|
-
poll: string;
|
|
104
|
-
tabs: string;
|
|
105
|
-
tab: string;
|
|
106
|
-
choose: string;
|
|
107
|
-
option: string;
|
|
108
|
-
combobox: string;
|
|
109
|
-
combooption: string;
|
|
110
|
-
inputbox: string;
|
|
111
|
-
templatedata: string;
|
|
112
|
-
mapframe: string;
|
|
113
|
-
maplink: string;
|
|
114
|
-
graph: string;
|
|
115
|
-
};
|
|
116
93
|
/**
|
|
117
94
|
* 替换选中内容
|
|
118
95
|
* @param view
|
|
@@ -123,5 +100,5 @@ export declare class CodeMirror6 {
|
|
|
123
100
|
* 将wikiparser-node设置转换为codemirror-mediawiki设置
|
|
124
101
|
* @param config
|
|
125
102
|
*/
|
|
126
|
-
static getMwConfig
|
|
103
|
+
static getMwConfig(config: Config): MwConfig;
|
|
127
104
|
}
|
package/dist/config.d.ts
CHANGED
|
@@ -92,7 +92,6 @@ tokens: {
|
|
|
92
92
|
/**
|
|
93
93
|
* These are custom tokens (a.k.a. tags) that aren't mapped to any of the standardized tags.
|
|
94
94
|
*
|
|
95
|
-
* @todo pass parent Tags in Tag.define() where appropriate for better theming.
|
|
96
95
|
* @see https://codemirror.net/docs/ref/#language.StreamParser.tokenTable
|
|
97
96
|
* @see https://lezer.codemirror.net/docs/ref/#highlight.Tag%5Edefine
|
|
98
97
|
*/
|
package/dist/fold.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { EditorView } from '@codemirror/view';
|
|
2
|
-
import type { Extension } from '@codemirror/state';
|
|
2
|
+
import type { EditorState, Extension } from '@codemirror/state';
|
|
3
|
+
import type { SyntaxNode } from '@lezer/common';
|
|
3
4
|
import type { Addon } from './codemirror';
|
|
4
5
|
export interface DocRange {
|
|
5
6
|
from: number;
|
|
6
7
|
to: number;
|
|
7
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Update the stack of opening (+) or closing (-) brackets
|
|
11
|
+
* @param state
|
|
12
|
+
* @param node 语法树节点
|
|
13
|
+
*/
|
|
14
|
+
export declare const braceStackUpdate: (state: EditorState, node: SyntaxNode) => [number, number];
|
|
8
15
|
declare const _default: Addon<Extension>;
|
|
9
16
|
export default _default;
|
|
10
17
|
/**
|
package/dist/linter.mjs
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { CDN, loadScript } from "@bhsd/common";
|
|
2
|
+
const getWikiLinter = async (opt) => {
|
|
3
|
+
const REPO = "npm/wikiparser-node@browser", DIR = `${REPO}/extensions/dist`, lang = opt == null ? void 0 : opt["i18n"];
|
|
4
|
+
await loadScript(`${DIR}/base.min.js`, "wikiparse");
|
|
5
|
+
await loadScript(`${DIR}/lint.min.js`, "wikiparse.Linter");
|
|
6
|
+
if (typeof lang === "string") {
|
|
7
|
+
try {
|
|
8
|
+
const i18n = await (await fetch(`${CDN}/${REPO}/i18n/${lang.toLowerCase()}.json`)).json();
|
|
9
|
+
wikiparse.setI18N(i18n);
|
|
10
|
+
} catch {
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return new wikiparse.Linter(opt == null ? void 0 : opt["include"]);
|
|
14
|
+
};
|
|
15
|
+
const getJsLinter = async (opt) => {
|
|
16
|
+
var _a, _b, _c;
|
|
17
|
+
await loadScript("npm/eslint-linter-browserify@8.57.0/linter.min.js", "eslint", true);
|
|
18
|
+
const esLinter = new eslint.Linter(), conf = {
|
|
19
|
+
env: { browser: true, es2024: true },
|
|
20
|
+
parserOptions: { ecmaVersion: 15, sourceType: "module" },
|
|
21
|
+
rules: {},
|
|
22
|
+
...opt
|
|
23
|
+
};
|
|
24
|
+
for (const [name, { meta }] of esLinter.getRules()) {
|
|
25
|
+
if ((_a = meta == null ? void 0 : meta.docs) == null ? void 0 : _a.recommended) {
|
|
26
|
+
(_c = (_b = conf.rules)[name]) != null ? _c : _b[name] = 2;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return (text) => esLinter.verify(text, conf);
|
|
30
|
+
};
|
|
31
|
+
const getCssLinter = async (opt) => {
|
|
32
|
+
await loadScript("npm/stylelint-bundle", "stylelint");
|
|
33
|
+
const config = {
|
|
34
|
+
rules: {
|
|
35
|
+
"annotation-no-unknown": true,
|
|
36
|
+
"at-rule-no-unknown": true,
|
|
37
|
+
"block-no-empty": true,
|
|
38
|
+
"color-no-invalid-hex": true,
|
|
39
|
+
"comment-no-empty": true,
|
|
40
|
+
"custom-property-no-missing-var-function": true,
|
|
41
|
+
"declaration-block-no-duplicate-custom-properties": true,
|
|
42
|
+
"declaration-block-no-duplicate-properties": [
|
|
43
|
+
true,
|
|
44
|
+
{
|
|
45
|
+
ignore: ["consecutive-duplicates-with-different-syntaxes"]
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
"declaration-block-no-shorthand-property-overrides": true,
|
|
49
|
+
"font-family-no-duplicate-names": true,
|
|
50
|
+
"font-family-no-missing-generic-family-keyword": true,
|
|
51
|
+
"function-calc-no-unspaced-operator": true,
|
|
52
|
+
"function-linear-gradient-no-nonstandard-direction": true,
|
|
53
|
+
"function-no-unknown": true,
|
|
54
|
+
"keyframe-block-no-duplicate-selectors": true,
|
|
55
|
+
"keyframe-declaration-no-important": true,
|
|
56
|
+
"media-feature-name-no-unknown": true,
|
|
57
|
+
"media-query-no-invalid": true,
|
|
58
|
+
"named-grid-areas-no-invalid": true,
|
|
59
|
+
"no-descending-specificity": true,
|
|
60
|
+
"no-duplicate-at-import-rules": true,
|
|
61
|
+
"no-duplicate-selectors": true,
|
|
62
|
+
"no-empty-source": true,
|
|
63
|
+
"no-invalid-double-slash-comments": true,
|
|
64
|
+
"no-invalid-position-at-import-rule": true,
|
|
65
|
+
"no-irregular-whitespace": true,
|
|
66
|
+
"property-no-unknown": true,
|
|
67
|
+
"selector-anb-no-unmatchable": true,
|
|
68
|
+
"selector-pseudo-class-no-unknown": true,
|
|
69
|
+
"selector-pseudo-element-no-unknown": true,
|
|
70
|
+
"selector-type-no-unknown": [
|
|
71
|
+
true,
|
|
72
|
+
{
|
|
73
|
+
ignore: ["custom-elements"]
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"string-no-newline": true,
|
|
77
|
+
"unit-no-unknown": true,
|
|
78
|
+
...opt == null ? void 0 : opt["rules"]
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
return async (code) => (await stylelint.lint({ code, config })).results.flatMap(({ warnings }) => warnings);
|
|
82
|
+
};
|
|
83
|
+
const getLuaLinter = async () => {
|
|
84
|
+
await loadScript("npm/luacheck-browserify/dist/index.min.js", "luacheck");
|
|
85
|
+
const luachecker = await luacheck(void 0);
|
|
86
|
+
return async (text) => (await luachecker.queue(text)).filter(({ severity }) => severity);
|
|
87
|
+
};
|
|
88
|
+
const getJsonLinter = () => (str) => {
|
|
89
|
+
var _a, _b, _c;
|
|
90
|
+
try {
|
|
91
|
+
if (str.trim()) {
|
|
92
|
+
JSON.parse(str);
|
|
93
|
+
}
|
|
94
|
+
} catch (e) {
|
|
95
|
+
if (e instanceof SyntaxError) {
|
|
96
|
+
const { message } = e, line = (_a = /\bline (\d+)/u.exec(message)) == null ? void 0 : _a[1], column = (_b = /\bcolumn (\d+)/u.exec(message)) == null ? void 0 : _b[1], position = (_c = /\bposition (\d+)/u.exec(message)) == null ? void 0 : _c[1];
|
|
97
|
+
return [
|
|
98
|
+
{
|
|
99
|
+
message,
|
|
100
|
+
severity: "error",
|
|
101
|
+
line,
|
|
102
|
+
column,
|
|
103
|
+
position
|
|
104
|
+
}
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return [];
|
|
109
|
+
};
|
|
110
|
+
export {
|
|
111
|
+
getCssLinter,
|
|
112
|
+
getJsLinter,
|
|
113
|
+
getJsonLinter,
|
|
114
|
+
getLuaLinter,
|
|
115
|
+
getWikiLinter
|
|
116
|
+
};
|