@bhsd/codemirror-mediawiki 2.28.2 → 2.29.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 +15 -2
- package/dist/bidi.js +84 -0
- package/dist/codemirror.js +608 -0
- package/dist/color.js +52 -0
- package/dist/config.js +119 -0
- package/dist/css.js +30 -0
- package/dist/escape.js +35 -0
- package/dist/fold.js +445 -0
- package/dist/hover.js +52 -0
- package/dist/indent.js +50 -0
- package/dist/inlay.js +68 -0
- package/dist/javascript.js +5 -0
- package/dist/keybindings.js +35 -0
- package/dist/keymap.js +36 -0
- package/dist/linter.d.ts +1 -0
- package/dist/linter.js +134 -0
- package/dist/lua.js +428 -0
- package/dist/main.min.js +25 -29
- package/dist/matchBrackets.d.ts +7 -0
- package/dist/matchBrackets.js +58 -0
- package/dist/matchTag.js +139 -0
- package/dist/mediawiki.js +443 -0
- package/dist/mw.min.js +31 -35
- package/dist/openLinks.js +97 -0
- package/dist/ref.js +85 -0
- package/dist/signature.js +69 -0
- package/dist/static.js +46 -0
- package/dist/statusBar.js +138 -0
- package/dist/token.js +1888 -0
- package/dist/wiki.min.js +33 -37
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +19 -18
- package/dist/keybindings.d.mts +0 -15
- package/dist/keybindings.mjs +0 -34
- package/dist/linter.d.mts +0 -43
- package/dist/linter.mjs +0 -132
- /package/dist/{mwConfig.d.mts → mwConfig.d.ts} +0 -0
- /package/dist/{mwConfig.mjs → mwConfig.js} +0 -0
package/i18n/en.json
CHANGED
package/i18n/zh-hans.json
CHANGED
package/i18n/zh-hant.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhsd/codemirror-mediawiki",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.29.0",
|
|
4
4
|
"description": "Modified CodeMirror mode based on wikimedia/mediawiki-extensions-CodeMirror",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mediawiki",
|
|
@@ -16,13 +16,12 @@
|
|
|
16
16
|
"/i18n/",
|
|
17
17
|
"/dist/*.js",
|
|
18
18
|
"/dist/*.d.ts",
|
|
19
|
-
"/dist/*.mjs",
|
|
20
|
-
"/dist/*.d.mts",
|
|
21
19
|
"/mediawiki.css"
|
|
22
20
|
],
|
|
23
21
|
"browser": "dist/main.min.js",
|
|
24
|
-
"main": "./dist/
|
|
22
|
+
"main": "./dist/codemirror.js",
|
|
25
23
|
"types": "./dist/codemirror.d.ts",
|
|
24
|
+
"type": "module",
|
|
26
25
|
"sideEffects": false,
|
|
27
26
|
"repository": {
|
|
28
27
|
"type": "git",
|
|
@@ -30,13 +29,15 @@
|
|
|
30
29
|
},
|
|
31
30
|
"scripts": {
|
|
32
31
|
"prepublishOnly": "npm run build",
|
|
32
|
+
"bundle:core": "esbuild ./src/codemirror.ts --charset=utf8 --bundle --format=esm --outfile=build/main.js",
|
|
33
|
+
"bundle:wiki": "esbuild ./mw/index.ts --charset=utf8 --bundle --format=esm --outfile=build/wiki.js",
|
|
33
34
|
"build:css": "esbuild ./css/index.css --bundle --minify --outfile=mediawiki.css",
|
|
34
|
-
"build:core": "esbuild ./
|
|
35
|
-
"build:mw": "esbuild ./
|
|
36
|
-
"build:wiki": "esbuild ./
|
|
35
|
+
"build:core": "npm run bundle:core && esbuild ./build/main.js --charset=utf8 --minify --target=es2019 --format=esm --sourcemap --outfile=dist/main.min.js && tsc && rm dist/*-page.{js,d.ts}",
|
|
36
|
+
"build:mw": "esbuild ./build/wiki.js --charset=utf8 --minify --target=es2019 --format=esm --outfile=dist/mw.min.js && esbuild ./mw/config.ts --charset=utf8 --bundle --target=es2019 --format=esm --outfile=dist/mwConfig.js",
|
|
37
|
+
"build:wiki": "npm run bundle:wiki && esbuild ./build/wiki.js --charset=utf8 --minify --target=es2019 --format=iife --sourcemap --outfile=dist/wiki.min.js",
|
|
37
38
|
"build:gh-page": "bash build.sh",
|
|
38
39
|
"build:test": "tsc --project test/tsconfig.json && npm test",
|
|
39
|
-
"build": "npm run build:css && rm -rf dist/ && npm run build:core && npm run build:
|
|
40
|
+
"build": "npm run build:css && rm -rf dist/ && npm run build:core && npm run build:wiki && npm run build:mw && eslint --no-eslintrc -c .eslintrc.dist.cjs dist/*.min.js",
|
|
40
41
|
"lint:ts": "tsc --noEmit && tsc --project mw/tsconfig.json --noEmit && tsc --project test/tsconfig.json --noEmit && eslint --cache .",
|
|
41
42
|
"lint:css": "stylelint **/*.css",
|
|
42
43
|
"lint": "npm run lint:ts && npm run lint:css",
|
|
@@ -47,24 +48,24 @@
|
|
|
47
48
|
"test:real": "node test/dist/test/real.js"
|
|
48
49
|
},
|
|
49
50
|
"dependencies": {
|
|
50
|
-
"@bhsd/common": "^0.13.0",
|
|
51
|
-
"@codemirror/lint": "^6.8.5",
|
|
52
|
-
"@codemirror/state": "^6.5.2",
|
|
53
|
-
"@codemirror/view": "^6.36.8",
|
|
54
|
-
"@lezer/common": "^1.2.3",
|
|
55
|
-
"wikiparser-node": "^1.21.2"
|
|
56
|
-
},
|
|
57
|
-
"devDependencies": {
|
|
58
51
|
"@bhsd/codemirror-css-color-picker": "^6.3.0",
|
|
52
|
+
"@bhsd/common": "^0.13.1",
|
|
59
53
|
"@codemirror/autocomplete": "^6.18.6",
|
|
60
54
|
"@codemirror/commands": "^6.8.1",
|
|
55
|
+
"@codemirror/language": "^6.11.0",
|
|
61
56
|
"@codemirror/lang-css": "^6.3.1",
|
|
62
57
|
"@codemirror/lang-javascript": "^6.2.2",
|
|
63
58
|
"@codemirror/lang-json": "^6.0.1",
|
|
64
|
-
"@codemirror/language": "^6.11.0",
|
|
65
59
|
"@codemirror/legacy-modes": "^6.4.2",
|
|
60
|
+
"@codemirror/lint": "^6.8.5",
|
|
66
61
|
"@codemirror/search": "^6.5.11",
|
|
62
|
+
"@codemirror/state": "^6.5.2",
|
|
63
|
+
"@codemirror/view": "^6.36.8",
|
|
64
|
+
"@lezer/common": "^1.2.3",
|
|
67
65
|
"@lezer/highlight": "^1.2.1",
|
|
66
|
+
"wikiparser-node": "^1.21.2"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
68
69
|
"@stylistic/eslint-plugin": "^3.1.0",
|
|
69
70
|
"@stylistic/stylelint-plugin": "^3.1.2",
|
|
70
71
|
"@types/eslint": "^8.56.10",
|
|
@@ -85,7 +86,7 @@
|
|
|
85
86
|
"eslint-plugin-regexp": "^2.7.0",
|
|
86
87
|
"eslint-plugin-unicorn": "^56.0.1",
|
|
87
88
|
"http-server": "^14.1.1",
|
|
88
|
-
"luacheck-browserify": "^0.
|
|
89
|
+
"luacheck-browserify": "^0.7.0",
|
|
89
90
|
"mocha": "^11.1.0",
|
|
90
91
|
"monaco-editor": "^0.52.2",
|
|
91
92
|
"stylelint": "^16.20.0",
|
package/dist/keybindings.d.mts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface KeymapConfig {
|
|
2
|
-
key: string;
|
|
3
|
-
desc: string;
|
|
4
|
-
pre?: string;
|
|
5
|
-
post?: string;
|
|
6
|
-
splitlines?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export declare const keybindings: KeymapConfig[];
|
|
9
|
-
/**
|
|
10
|
-
* 将文本各行包裹在指定的前后缀中
|
|
11
|
-
* @param text 跨行文本
|
|
12
|
-
* @param pre 前缀
|
|
13
|
-
* @param post 后缀
|
|
14
|
-
*/
|
|
15
|
-
export declare const encapsulateLines: (text: string, pre: string, post: string) => string;
|
package/dist/keybindings.mjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
const keybindings = [
|
|
2
|
-
{ key: "Ctrl-8", pre: "<blockquote>", post: "</blockquote>", desc: "blockquote" },
|
|
3
|
-
{ key: "Mod-.", pre: "<sup>", post: "</sup>", desc: "sup" },
|
|
4
|
-
{ key: "Mod-,", pre: "<sub>", post: "</sub>", desc: "sub" },
|
|
5
|
-
{ key: "Mod-Shift-6", pre: "<code>", post: "</code>", desc: "code" },
|
|
6
|
-
{ key: "Ctrl-Shift-5", pre: "<s>", post: "</s>", desc: "s" },
|
|
7
|
-
{ key: "Mod-u", pre: "<u>", post: "</u>", desc: "u" },
|
|
8
|
-
{ key: "Mod-k", pre: "[[", post: "]]", desc: "link" },
|
|
9
|
-
{ key: "Mod-i", pre: "''", post: "''", desc: "italic" },
|
|
10
|
-
{ key: "Mod-b", pre: "'''", post: "'''", desc: "bold" },
|
|
11
|
-
{ key: "Mod-Shift-k", pre: "<ref>", post: "</ref>", desc: "ref" },
|
|
12
|
-
{ key: "Mod-/", pre: "<!-- ", post: " -->", desc: "comment" },
|
|
13
|
-
{ key: "Ctrl-0", splitlines: true, desc: "heading 0" },
|
|
14
|
-
...new Array(6).fill(0).map((_, i) => ({
|
|
15
|
-
key: `Ctrl-${i + 1}`,
|
|
16
|
-
pre: `${"=".repeat(i + 1)} `,
|
|
17
|
-
post: ` ${"=".repeat(i + 1)}`,
|
|
18
|
-
splitlines: true,
|
|
19
|
-
desc: `heading ${i + 1}`
|
|
20
|
-
})),
|
|
21
|
-
{ key: "Ctrl-7", pre: " ", splitlines: true, desc: "pre" }
|
|
22
|
-
];
|
|
23
|
-
const encapsulateLines = (text, pre, post) => {
|
|
24
|
-
const lines = text.split("\n");
|
|
25
|
-
return lines.map((line) => {
|
|
26
|
-
var _a, _b;
|
|
27
|
-
const str = ((_b = (_a = /^(={1,6})(.+)\1\s*$/u.exec(line)) == null ? void 0 : _a[2]) != null ? _b : line).trim();
|
|
28
|
-
return pre === " " || lines.length === 1 || line.trim() ? pre + str + post : str;
|
|
29
|
-
}).join("\n");
|
|
30
|
-
};
|
|
31
|
-
export {
|
|
32
|
-
encapsulateLines,
|
|
33
|
-
keybindings
|
|
34
|
-
};
|
package/dist/linter.d.mts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { Diagnostic as DiagnosticBase, Range } from 'vscode-languageserver-types';
|
|
2
|
-
import type { Linter } from 'eslint';
|
|
3
|
-
import type { Warning } from 'stylelint';
|
|
4
|
-
import type { Diagnostic } from 'luacheck-browserify';
|
|
5
|
-
export type Option = Record<string, unknown> | null | undefined;
|
|
6
|
-
export type LiveOption = (runtime?: boolean) => Option;
|
|
7
|
-
declare type getLinter<T> = () => (text: string) => T;
|
|
8
|
-
declare type asyncLinter<T, S = Record<string, unknown>> = ((text: string, config?: Option) => T) & {
|
|
9
|
-
config?: S;
|
|
10
|
-
fixer?: (code: string, rule?: string) => string | Promise<string>;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* @param opt 初始化选项
|
|
14
|
-
* @param obj 仅用于wikiparse.LanguageService
|
|
15
|
-
*/
|
|
16
|
-
declare type getAsyncLinter<T, S = never, R = never> = (opt?: S, obj?: R) => Promise<asyncLinter<T>>;
|
|
17
|
-
declare interface MixedDiagnostic extends Omit<DiagnosticBase, 'range'> {
|
|
18
|
-
range?: Range;
|
|
19
|
-
from?: number;
|
|
20
|
-
to?: number;
|
|
21
|
-
}
|
|
22
|
-
declare interface JsonError {
|
|
23
|
-
message: string;
|
|
24
|
-
severity: 'error';
|
|
25
|
-
line: string | undefined;
|
|
26
|
-
column: string | undefined;
|
|
27
|
-
position: string | undefined;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* 获取 Wikitext LSP
|
|
31
|
-
* @param opt 选项
|
|
32
|
-
* @param obj 对象
|
|
33
|
-
*/
|
|
34
|
-
export declare const getWikiLinter: getAsyncLinter<Promise<MixedDiagnostic[]>, Option, object>;
|
|
35
|
-
/** 获取 ESLint */
|
|
36
|
-
export declare const getJsLinter: getAsyncLinter<Linter.LintMessage[]>;
|
|
37
|
-
/** 获取 Stylelint */
|
|
38
|
-
export declare const getCssLinter: getAsyncLinter<Promise<Warning[]>>;
|
|
39
|
-
/** 获取 Luacheck */
|
|
40
|
-
export declare const getLuaLinter: getAsyncLinter<Promise<Diagnostic[]>>;
|
|
41
|
-
/** JSON.parse */
|
|
42
|
-
export declare const getJsonLinter: getLinter<JsonError[]>;
|
|
43
|
-
export {};
|
package/dist/linter.mjs
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { loadScript, getWikiparse, getLSP, sanitizeInlineStyle } from "@bhsd/common";
|
|
2
|
-
import { styleLint } from "@bhsd/common/dist/stylelint";
|
|
3
|
-
const offsetAt = (range, line, column) => {
|
|
4
|
-
if (line === -2) {
|
|
5
|
-
return range[0];
|
|
6
|
-
}
|
|
7
|
-
return line === 0 ? range[1] : range[0] + column;
|
|
8
|
-
};
|
|
9
|
-
const getWikiLinter = async (opt, obj) => {
|
|
10
|
-
await getWikiparse(
|
|
11
|
-
opt == null ? void 0 : opt["getConfig"],
|
|
12
|
-
opt == null ? void 0 : opt["i18n"]
|
|
13
|
-
);
|
|
14
|
-
const lsp = getLSP(obj, opt == null ? void 0 : opt["include"]);
|
|
15
|
-
return async (text, config) => {
|
|
16
|
-
const diagnostics = (await lsp.provideDiagnostics(text)).filter(
|
|
17
|
-
({ code, severity }) => {
|
|
18
|
-
var _a;
|
|
19
|
-
return Number((_a = config == null ? void 0 : config[code]) != null ? _a : 2) > Number(severity === 2);
|
|
20
|
-
}
|
|
21
|
-
), tokens = "findStyleTokens" in lsp && (config == null ? void 0 : config["invalid-css"]) !== "0" ? await lsp.findStyleTokens() : [];
|
|
22
|
-
if (tokens.length === 0) {
|
|
23
|
-
return diagnostics;
|
|
24
|
-
}
|
|
25
|
-
const cssLint = await getCssLinter();
|
|
26
|
-
return [
|
|
27
|
-
...diagnostics,
|
|
28
|
-
...(await cssLint(
|
|
29
|
-
tokens.map(({ childNodes, type, tag }, i) => `${type === "ext-attr" ? "div" : tag}#${i}{
|
|
30
|
-
${sanitizeInlineStyle(childNodes[1].childNodes[0].data).replace(/\n/gu, " ")}
|
|
31
|
-
}`).join("\n")
|
|
32
|
-
)).map(({ line, column, endLine, endColumn, rule, severity, text: message }) => {
|
|
33
|
-
const i = Math.ceil(line / 3), { range } = tokens[i - 1].childNodes[1].childNodes[0], from = offsetAt(range, line - 3 * i, column - 1);
|
|
34
|
-
return {
|
|
35
|
-
from,
|
|
36
|
-
to: endLine === void 0 ? from : offsetAt(range, endLine - 3 * i, endColumn - 1),
|
|
37
|
-
severity: severity === "error" ? 1 : 2,
|
|
38
|
-
source: "Stylelint",
|
|
39
|
-
code: rule,
|
|
40
|
-
message
|
|
41
|
-
};
|
|
42
|
-
})
|
|
43
|
-
];
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
const getJsLinter = async () => {
|
|
47
|
-
var _a;
|
|
48
|
-
await loadScript("npm/@bhsd/eslint-browserify", "eslint");
|
|
49
|
-
const esLinter = new eslint.Linter(), conf = {
|
|
50
|
-
env: { browser: true, es2024: true },
|
|
51
|
-
parserOptions: { ecmaVersion: 15, sourceType: "module" }
|
|
52
|
-
}, recommended = {};
|
|
53
|
-
for (const [name, { meta }] of esLinter.getRules()) {
|
|
54
|
-
if ((_a = meta == null ? void 0 : meta.docs) == null ? void 0 : _a.recommended) {
|
|
55
|
-
recommended[name] = 2;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const linter = (text, opt) => {
|
|
59
|
-
const config = { ...conf, ...opt };
|
|
60
|
-
if (!("rules" in config) || config.extends === "eslint:recommended" || Array.isArray(config.extends) && config.extends.includes("eslint:recommended")) {
|
|
61
|
-
config.rules = { ...recommended, ...config.rules };
|
|
62
|
-
}
|
|
63
|
-
delete config.extends;
|
|
64
|
-
linter.config = config;
|
|
65
|
-
return esLinter.verify(text, config);
|
|
66
|
-
};
|
|
67
|
-
linter.fixer = (code, rule) => {
|
|
68
|
-
var _a2, _b;
|
|
69
|
-
return esLinter.verifyAndFix(
|
|
70
|
-
code,
|
|
71
|
-
rule ? { ...linter.config, rules: { [rule]: (_b = (_a2 = linter.config.rules) == null ? void 0 : _a2[rule]) != null ? _b : 2 } } : linter.config
|
|
72
|
-
).output;
|
|
73
|
-
};
|
|
74
|
-
return linter;
|
|
75
|
-
};
|
|
76
|
-
const getCssLinter = async () => {
|
|
77
|
-
await loadScript("npm/@bhsd/stylelint-browserify", "stylelint");
|
|
78
|
-
const linter = async (code, opt) => {
|
|
79
|
-
const warnings = await styleLint(stylelint, code, opt);
|
|
80
|
-
if (opt && "rules" in opt) {
|
|
81
|
-
linter.config = opt;
|
|
82
|
-
}
|
|
83
|
-
return warnings;
|
|
84
|
-
};
|
|
85
|
-
linter.fixer = (code, rule) => {
|
|
86
|
-
var _a, _b;
|
|
87
|
-
if (!linter.config) {
|
|
88
|
-
throw new Error("Fixer unavailable!");
|
|
89
|
-
}
|
|
90
|
-
return styleLint(
|
|
91
|
-
stylelint,
|
|
92
|
-
code,
|
|
93
|
-
rule ? { extends: [], rules: { [rule]: (_b = (_a = linter.config.rules) == null ? void 0 : _a[rule]) != null ? _b : true } } : linter.config,
|
|
94
|
-
true
|
|
95
|
-
);
|
|
96
|
-
};
|
|
97
|
-
return linter;
|
|
98
|
-
};
|
|
99
|
-
const getLuaLinter = async () => {
|
|
100
|
-
await loadScript("npm/luacheck-browserify", "luacheck");
|
|
101
|
-
const luachecker = await luacheck(void 0);
|
|
102
|
-
return async (text) => (await luachecker.queue(text)).filter(({ severity }) => severity);
|
|
103
|
-
};
|
|
104
|
-
const getJsonLinter = () => (str) => {
|
|
105
|
-
var _a, _b, _c;
|
|
106
|
-
try {
|
|
107
|
-
if (str.trim()) {
|
|
108
|
-
JSON.parse(str);
|
|
109
|
-
}
|
|
110
|
-
} catch (e) {
|
|
111
|
-
if (e instanceof SyntaxError) {
|
|
112
|
-
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];
|
|
113
|
-
return [
|
|
114
|
-
{
|
|
115
|
-
message,
|
|
116
|
-
severity: "error",
|
|
117
|
-
line,
|
|
118
|
-
column,
|
|
119
|
-
position
|
|
120
|
-
}
|
|
121
|
-
];
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return [];
|
|
125
|
-
};
|
|
126
|
-
export {
|
|
127
|
-
getCssLinter,
|
|
128
|
-
getJsLinter,
|
|
129
|
-
getJsonLinter,
|
|
130
|
-
getLuaLinter,
|
|
131
|
-
getWikiLinter
|
|
132
|
-
};
|
|
File without changes
|
|
File without changes
|