@bhsd/codemirror-mediawiki 2.13.1 → 2.14.1

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/static.d.ts CHANGED
@@ -1,17 +1,23 @@
1
1
  import type { Config } from 'wikiparser-node';
2
- import type { MwConfig } from './mediawiki';
2
+ import type { MwConfig } from './token';
3
3
  export declare const tagModes: {
4
- tab: string;
5
- tabs: string;
4
+ onlyinclude: string;
5
+ includeonly: string;
6
+ noinclude: string;
7
+ pre: string;
8
+ nowiki: string;
6
9
  indicator: string;
7
10
  poem: string;
8
11
  ref: string;
9
12
  references: string;
10
- option: string;
13
+ gallery: string;
14
+ poll: string;
15
+ tabs: string;
16
+ tab: string;
11
17
  choose: string;
12
- combooption: string;
18
+ option: string;
13
19
  combobox: string;
14
- poll: string;
15
- gallery: string;
20
+ combooption: string;
21
+ inputbox: string;
16
22
  };
17
23
  export declare const getStaticMwConfig: (config: Config) => MwConfig;
@@ -0,0 +1,244 @@
1
+ /**
2
+ * @author pastakhov, MusikAnimal and others
3
+ * @license GPL-2.0-or-later
4
+ * @see https://gerrit.wikimedia.org/g/mediawiki/extensions/CodeMirror
5
+ */
6
+ import { Tag } from '@lezer/highlight';
7
+ import type { StreamParser, StringStream } from '@codemirror/language';
8
+ declare const tokens: {
9
+ apostrophes: string;
10
+ comment: string;
11
+ convertBracket: string;
12
+ convertDelimiter: string;
13
+ convertFlag: string;
14
+ convertLang: string;
15
+ doubleUnderscore: string;
16
+ em: string;
17
+ error: string;
18
+ extLink: string;
19
+ extLinkBracket: string;
20
+ extLinkProtocol: string;
21
+ extLinkText: string;
22
+ extTag: string;
23
+ extTagAttribute: string;
24
+ extTagAttributeValue: string;
25
+ extTagBracket: string;
26
+ extTagName: string;
27
+ fileText: string;
28
+ freeExtLink: string; /** 已解析的节点 */
29
+ freeExtLinkProtocol: string;
30
+ hr: string;
31
+ htmlEntity: string;
32
+ htmlTagAttribute: string;
33
+ htmlTagAttributeValue: string;
34
+ htmlTagBracket: string;
35
+ htmlTagName: string;
36
+ imageParameter: string;
37
+ linkBracket: string;
38
+ linkDelimiter: string;
39
+ linkPageName: string;
40
+ linkText: string;
41
+ linkToSection: string;
42
+ list: string;
43
+ magicLink: string;
44
+ pageName: string;
45
+ parserFunction: string;
46
+ parserFunctionBracket: string;
47
+ parserFunctionDelimiter: string;
48
+ parserFunctionName: string;
49
+ redirect: string;
50
+ section: string;
51
+ sectionHeader: string;
52
+ signature: string;
53
+ skipFormatting: string;
54
+ strong: string;
55
+ tableBracket: string;
56
+ tableCaption: string;
57
+ tableDefinition: string;
58
+ tableDefinitionValue: string;
59
+ tableDelimiter: string;
60
+ tableDelimiter2: string;
61
+ tableTd: string;
62
+ tableTh: string;
63
+ template: string;
64
+ templateArgumentName: string;
65
+ templateBracket: string;
66
+ templateDelimiter: string;
67
+ templateName: string;
68
+ templateVariable: string;
69
+ templateVariableBracket: string;
70
+ templateVariableDelimiter: string;
71
+ templateVariableName: string;
72
+ };
73
+ declare type Style = string | [string];
74
+ declare type Tokenizer<T = Style> = ((stream: StringStream, state: State) => T) & {
75
+ args?: unknown[];
76
+ };
77
+ declare type TagName = keyof typeof tokens;
78
+ declare type NestCount = 'nTemplate' | 'nExt' | 'nVar' | 'nLink' | 'nExtLink';
79
+ declare interface Nesting extends Record<NestCount, number> {
80
+ extName: string | false;
81
+ extState: object | false;
82
+ }
83
+ declare interface State extends Nesting {
84
+ tokenize: Tokenizer;
85
+ readonly stack: Tokenizer[];
86
+ readonly inHtmlTag: string[];
87
+ extMode: StreamParser<object> | false;
88
+ lbrack: boolean | undefined;
89
+ bold: boolean;
90
+ italic: boolean;
91
+ dt: Partial<Nesting> & {
92
+ n: number;
93
+ };
94
+ redirect: boolean;
95
+ data: MediaWikiData;
96
+ }
97
+ declare type ExtState = Omit<State, 'dt'> & Partial<Pick<State, 'dt'>>;
98
+ declare interface Token {
99
+ pos: number;
100
+ readonly string: string;
101
+ style: Style;
102
+ readonly state: State;
103
+ }
104
+ export type ApiSuggestions = [string, string?][];
105
+ /**
106
+ * 获取维基链接建议
107
+ * @param search 搜索字符串,开头不包含` `
108
+ * @param namespace 命名空间
109
+ * @param subpage 是否为子页面
110
+ */
111
+ export type ApiSuggest = (search: string, namespace?: number, subpage?: boolean) => ApiSuggestions | Promise<ApiSuggestions>;
112
+ export interface MwConfig {
113
+ readonly tags: Record<string, true>;
114
+ readonly tagModes: Record<string, string>;
115
+ urlProtocols: string;
116
+ functionSynonyms: [Record<string, string>, Record<string, unknown>];
117
+ doubleUnderscore: [Record<string, unknown>, Record<string, unknown>];
118
+ nsid: Record<string, number>;
119
+ variants?: string[];
120
+ img?: Record<string, string>;
121
+ redirection?: string[];
122
+ permittedHtmlTags?: string[];
123
+ implicitlyClosedHtmlTags?: string[];
124
+ linkSuggest?: ApiSuggest;
125
+ paramSuggest?: ApiSuggest;
126
+ }
127
+ declare class MediaWikiData {
128
+ /** 已解析的节点 */
129
+ readonly readyTokens: Token[];
130
+ /** 当前起始位置 */
131
+ oldToken: Token | null;
132
+ /** 可能需要回滚的`'''` */
133
+ mark: number | null;
134
+ firstSingleLetterWord: number | null;
135
+ firstMultiLetterWord: number | null;
136
+ firstSpace: number | null;
137
+ readonly tags: string[];
138
+ constructor(tags: string[]);
139
+ }
140
+ /** Adapted from the original CodeMirror 5 stream parser by Pavel Astakhov */
141
+ export declare class MediaWiki {
142
+ readonly config: MwConfig;
143
+ readonly tokenTable: {
144
+ [x: string]: Tag;
145
+ };
146
+ readonly hiddenTable: Record<string, Tag>;
147
+ readonly permittedHtmlTags: Set<string>;
148
+ readonly implicitlyClosedHtmlTags: Set<string>;
149
+ readonly urlProtocols: RegExp;
150
+ readonly linkRegex: RegExp;
151
+ readonly inLinkRegex: RegExp;
152
+ readonly fileRegex: RegExp;
153
+ readonly redirectRegex: RegExp;
154
+ readonly img: string[];
155
+ readonly imgRegex: RegExp;
156
+ readonly headerRegex: RegExp;
157
+ readonly extAttrRegex: RegExp;
158
+ readonly templateRegex: RegExp;
159
+ readonly argumentRegex: RegExp;
160
+ readonly convertSemicolon: RegExp;
161
+ readonly convertLang: RegExp;
162
+ readonly convertRegex: RegExp;
163
+ readonly inputboxRegex: RegExp;
164
+ readonly wikiRegex: RegExp;
165
+ readonly tags: string[];
166
+ constructor(config: MwConfig);
167
+ /**
168
+ * Dynamically register a token in CodeMirror.
169
+ * This is solely for use by this.addTag() and CodeMirrorModeMediaWiki.makeLocalStyle().
170
+ *
171
+ * @param token
172
+ * @param hidden Whether the token is not highlighted
173
+ * @param parent
174
+ */
175
+ addToken(token: string, hidden?: boolean, parent?: Tag): void;
176
+ /**
177
+ * Register the ground tokens. These aren't referenced directly in the StreamParser, nor do
178
+ * they have a parent Tag, so we don't need them as constants like we do for other tokens.
179
+ * See this.makeLocalStyle() for how these tokens are used.
180
+ */
181
+ registerGroundTokens(): void;
182
+ makeFullStyle(style: Style, state: ExtState): string;
183
+ makeTagStyle(tag: TagName, state: State, endGround?: NestCount): [string];
184
+ makeStyle(style: string, state: ExtState, endGround?: NestCount): [string];
185
+ makeLocalTagStyle(tag: TagName, state: State, endGround?: NestCount): string;
186
+ makeLocalStyle(style: string, state: ExtState, endGround?: NestCount): string;
187
+ inStr(str: string, tag: TagName | false, errorTag?: TagName): Tokenizer;
188
+ eatWikiText(style: string): Tokenizer;
189
+ eatApostrophes(obj: Pick<State, 'bold' | 'italic'>): Tokenizer<string | false>;
190
+ eatExternalLinkProtocol(chars: string, free?: boolean): Tokenizer;
191
+ inExternalLink(text?: boolean): Tokenizer;
192
+ get eatFreeExternalLink(): Tokenizer;
193
+ inLink(file: boolean, section?: boolean): Tokenizer;
194
+ inLinkText(file: boolean, gallery?: boolean): Tokenizer;
195
+ toEatImageParameter(stream: StringStream, state: State): void;
196
+ eatList(stream: StringStream, state: State): string;
197
+ eatDoubleUnderscore(style: string, stream: StringStream, state: State): Style;
198
+ get eatStartTable(): Tokenizer;
199
+ inTableDefinition(tr?: boolean, quote?: string): Tokenizer;
200
+ get inTable(): Tokenizer;
201
+ inTableCell(style: string, needAttr?: boolean, firstLine?: boolean): Tokenizer;
202
+ inSectionHeader(str: string): Tokenizer;
203
+ get inComment(): Tokenizer;
204
+ eatTagName(name: string, isCloseTag?: boolean, isHtmlTag?: boolean): Tokenizer;
205
+ inHtmlTagAttribute(name: string, quote?: string): Tokenizer;
206
+ inExtTagAttribute(name: string, quote?: string): Tokenizer;
207
+ eatExtTagArea(name: string): Tokenizer;
208
+ inExtTokens(origString: string): Tokenizer;
209
+ inVariable(pos?: number): Tokenizer;
210
+ eatTransclusion(stream: StringStream, state: State): string;
211
+ inParserFunctionName(invoke?: boolean): Tokenizer;
212
+ inTemplatePageName(haveEaten?: boolean, anchor?: boolean): Tokenizer;
213
+ inParserFunctionArgument(module?: boolean): Tokenizer;
214
+ inTemplateArgument(expectName?: boolean): Tokenizer;
215
+ inConvert(style: string, needFlag?: boolean, needLang?: boolean): Tokenizer;
216
+ eatEntity(stream: StringStream, style: string): string;
217
+ /**
218
+ * Remembers position and status for rollbacking.
219
+ * It is needed for changing from bold to italic with apostrophes before it, if required.
220
+ *
221
+ * @see https://phabricator.wikimedia.org/T108455
222
+ * @param stream
223
+ * @param state
224
+ */
225
+ prepareItalicForCorrection(stream: StringStream, state: State): void;
226
+ /**
227
+ * main entry
228
+ *
229
+ * @see https://codemirror.net/docs/ref/#language.StreamParser
230
+ *
231
+ * @param tags
232
+ */
233
+ mediawiki(tags?: string[]): StreamParser<State>;
234
+ 'text/nowiki'(): StreamParser<Record<string, never>>;
235
+ inReferences(tag: string, comment?: boolean): Tokenizer<string>;
236
+ 'text/references'(tags: string[]): StreamParser<State>;
237
+ 'text/choose'(tags: string[]): StreamParser<State>;
238
+ 'text/combobox'(tags: string[]): StreamParser<State>;
239
+ get inInputbox(): Tokenizer<string>;
240
+ 'text/inputbox'(tags: string[]): StreamParser<State>;
241
+ inGallery(section?: boolean): Tokenizer;
242
+ 'text/gallery'(tags: string[]): StreamParser<State>;
243
+ }
244
+ export {};
package/i18n/en.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.13.1",
2
+ "version": "2.14.1",
3
3
  "lang": "en",
4
4
  "i18n-failed": "Failed to fetch the translation file in $1.",
5
5
  "title": "CodeMirror Addons",
package/i18n/zh-hans.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.13.1",
2
+ "version": "2.14.1",
3
3
  "lang": "zh-hans",
4
4
  "i18n-failed": "获取 $1 的语言文件失败。",
5
5
  "title": "CodeMirror插件",
package/i18n/zh-hant.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.13.1",
2
+ "version": "2.14.1",
3
3
  "lang": "zh-hant",
4
4
  "i18n-failed": "取得 $1 的語言檔案失敗。",
5
5
  "title": "CodeMirror外掛程式",
package/mediawiki.css CHANGED
@@ -74,7 +74,8 @@
74
74
  .cm-mw-extlink-protocol,
75
75
  .cm-mw-extlink,
76
76
  .cm-mw-free-extlink-protocol,
77
- .cm-mw-free-extlink {
77
+ .cm-mw-free-extlink,
78
+ .cm-mw-magic-link {
78
79
  text-decoration: underline;
79
80
  }
80
81
 
@@ -145,7 +146,8 @@
145
146
  .cm-mw-link-bracket,
146
147
  .cm-mw-link-delimiter,
147
148
  .cm-mw-extlink,
148
- .cm-mw-free-extlink {
149
+ .cm-mw-free-extlink,
150
+ .cm-mw-magic-link {
149
151
  color: #000aaa;
150
152
  font-weight: normal;
151
153
  }
@@ -181,6 +183,11 @@
181
183
  color: #14866d;
182
184
  font-weight: normal;
183
185
  }
186
+ .cm-mw-exttag-attribute-value,
187
+ .cm-mw-htmltag-attribute-value {
188
+ color: #179b1c;
189
+ font-weight: normal;
190
+ }
184
191
 
185
192
  /* table */
186
193
  .cm-mw-table-bracket,
@@ -193,10 +200,26 @@
193
200
  color: #d08;
194
201
  font-weight: normal;
195
202
  }
203
+ .cm-mw-table-definition-value {
204
+ color: #f500d4;
205
+ font-weight: normal;
206
+ }
207
+ .cm-mw-table-th,
196
208
  .cm-mw-table-caption {
197
209
  font-weight: bold;
198
210
  }
199
211
 
212
+ /* convert */
213
+ .cm-mw-convert-bracket,
214
+ .cm-mw-convert-delimiter {
215
+ color: #b68;
216
+ font-weight: bold;
217
+ }
218
+ .cm-mw-convert-flag,
219
+ .cm-mw-convert-lang {
220
+ color: #b68;
221
+ }
222
+
200
223
  /* HTML entity */
201
224
  .cm-mw-entity {
202
225
  color: #00a1a1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhsd/codemirror-mediawiki",
3
- "version": "2.13.1",
3
+ "version": "2.14.1",
4
4
  "description": "Modified CodeMirror mode based on wikimedia/mediawiki-extensions-CodeMirror",
5
5
  "keywords": [
6
6
  "mediawiki",
@@ -16,7 +16,7 @@
16
16
  "/dist/*.js",
17
17
  "/dist/*.d.ts",
18
18
  "!/dist/*-page.d.ts",
19
- "!/dist/parserTests.js",
19
+ "!/dist/parser.*",
20
20
  "/mediawiki.css"
21
21
  ],
22
22
  "browser": "dist/main.min.js",
@@ -30,16 +30,18 @@
30
30
  "build:core": "esbuild ./src/codemirror.ts --bundle --minify --target=es2018 --format=esm --sourcemap --outfile=dist/main.min.js && tsc --emitDeclarationOnly",
31
31
  "build:mw": "esbuild ./mw/base.ts --bundle --minify --target=es2018 --format=esm --sourcemap --outfile=dist/mw.min.js",
32
32
  "build:gh-page": "bash build.sh",
33
- "build:test": "esbuild ./test/parserTests.ts --bundle --minify --platform=node --outfile=dist/parserTests.js && node dist/parserTests.js",
34
- "build": "npm run build:core && npm run build:mw && npm run build:test",
33
+ "build:test": "tsc --project test/tsconfig.json && node test/dist/test/test.js",
34
+ "build": "npm run build:core && npm run build:mw",
35
35
  "diff": "git diff --ignore-all-space --color-moved",
36
36
  "diff:stat": "f() { git diff --stat --ignore-all-space --color=always $1 $2 -- . ':!dist/' ':!.github/'; }; f",
37
37
  "lint:ts": "tsc --noEmit && tsc --project mw/tsconfig.json --noEmit && tsc --project test/tsconfig.json --noEmit && eslint --cache .",
38
38
  "lint:css": "stylelint *.css",
39
39
  "lint": "npm run lint:ts && npm run lint:css",
40
+ "prof": "node --prof test/dist/test/prof.js && node --prof-process isolate-0x*-v8.log > test/prof.txt && gsed -i '0,/Bottom up/d' test/prof.txt && rm isolate-0x*-v8.log",
40
41
  "server": "npm run test:end; http-server .. -c-1 --cors &",
41
42
  "test": "npm run build:core && npm run build:gh-page && npm run server",
42
- "test:end": "pkill -x http-server"
43
+ "test:end": "pkill -x http-server",
44
+ "test:real": "node test/dist/test/real.js"
43
45
  },
44
46
  "engines": {
45
47
  "node": "20.9.0"
@@ -49,8 +51,8 @@
49
51
  "@codemirror/lint": "^6.5.0",
50
52
  "@codemirror/state": "^6.4.1",
51
53
  "@codemirror/view": "^6.24.1",
52
- "@lezer/common": "^1.1.2",
53
- "wikiparser-node": "^1.7.1"
54
+ "@lezer/common": "^1.2.1",
55
+ "wikiparser-node": "^1.9.0"
54
56
  },
55
57
  "devDependencies": {
56
58
  "@codemirror/autocomplete": "^6.12.0",
@@ -65,22 +67,22 @@
65
67
  "@stylistic/stylelint-plugin": "^2.0.0",
66
68
  "@types/jquery": "^3.5.29",
67
69
  "@types/oojs-ui": "^0.49.0",
68
- "@typescript-eslint/eslint-plugin": "^7.1.0",
69
- "@typescript-eslint/parser": "^7.1.0",
70
- "esbuild": "^0.19.12",
70
+ "@typescript-eslint/eslint-plugin": "^7.10.0",
71
+ "@typescript-eslint/parser": "^7.10.0",
72
+ "esbuild": "^0.21.4",
71
73
  "eslint": "^8.56.0",
72
74
  "eslint-plugin-es-x": "^7.5.0",
73
75
  "eslint-plugin-eslint-comments": "^3.2.0",
74
76
  "eslint-plugin-jsdoc": "^48.0.2",
75
- "eslint-plugin-json-es": "^1.5.7",
77
+ "eslint-plugin-json-es": "^1.6.0",
76
78
  "eslint-plugin-promise": "^6.1.1",
77
79
  "eslint-plugin-regexp": "^2.2.0",
78
80
  "eslint-plugin-unicorn": "^52.0.0",
79
81
  "http-server": "^14.1.0",
80
- "monaco-editor": "^0.48.0",
82
+ "monaco-editor": "^0.49.0",
81
83
  "stylelint": "^16.1.0",
82
84
  "stylelint-config-recommended": "^14.0.0",
83
85
  "types-mediawiki": "^1.6.0",
84
- "typescript": "^5.3.3"
86
+ "typescript": "^5.4.5"
85
87
  }
86
88
  }