@bhsd/codemirror-mediawiki 2.13.1 → 2.14.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/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,241 @@
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
+ extTagBracket: string;
25
+ extTagName: string;
26
+ fileText: string;
27
+ freeExtLink: string;
28
+ freeExtLinkProtocol: string;
29
+ /** 已解析的节点 */
30
+ hr: string;
31
+ htmlEntity: string;
32
+ htmlTagAttribute: string;
33
+ htmlTagBracket: string;
34
+ htmlTagName: string;
35
+ imageParameter: string;
36
+ linkBracket: string;
37
+ linkDelimiter: string;
38
+ linkPageName: string;
39
+ linkText: string;
40
+ linkToSection: string;
41
+ list: string;
42
+ magicLink: string;
43
+ pageName: string;
44
+ parserFunction: string;
45
+ parserFunctionBracket: string;
46
+ parserFunctionDelimiter: string;
47
+ parserFunctionName: string;
48
+ redirect: string;
49
+ section: string;
50
+ sectionHeader: string;
51
+ signature: string;
52
+ skipFormatting: string;
53
+ strong: string;
54
+ tableBracket: string;
55
+ tableCaption: string;
56
+ tableDefinition: string;
57
+ tableDelimiter: string;
58
+ tableDelimiter2: string;
59
+ tableTd: string;
60
+ tableTh: string;
61
+ template: string;
62
+ templateArgumentName: string;
63
+ templateBracket: string;
64
+ templateDelimiter: string;
65
+ templateName: string;
66
+ templateVariable: string;
67
+ templateVariableBracket: string;
68
+ templateVariableDelimiter: string;
69
+ templateVariableName: string;
70
+ };
71
+ declare type Style = string | [string];
72
+ declare type Tokenizer<T = Style> = ((stream: StringStream, state: State) => T) & {
73
+ args?: unknown[];
74
+ };
75
+ declare type TagName = keyof typeof tokens;
76
+ declare type NestCount = 'nTemplate' | 'nExt' | 'nVar' | 'nLink' | 'nExtLink';
77
+ declare interface Nesting extends Record<NestCount, number> {
78
+ extName: string | false;
79
+ extState: object | false;
80
+ }
81
+ declare interface State extends Nesting {
82
+ tokenize: Tokenizer;
83
+ readonly stack: Tokenizer[];
84
+ readonly inHtmlTag: string[];
85
+ extMode: StreamParser<object> | false;
86
+ lbrack: boolean | undefined;
87
+ bold: boolean;
88
+ italic: boolean;
89
+ dt: Partial<Nesting> & {
90
+ n: number;
91
+ };
92
+ redirect: boolean;
93
+ data: MediaWikiData;
94
+ }
95
+ declare type ExtState = Omit<State, 'dt'> & Partial<Pick<State, 'dt'>>;
96
+ declare interface Token {
97
+ pos: number;
98
+ readonly string: string;
99
+ style: Style;
100
+ readonly state: State;
101
+ }
102
+ export type ApiSuggestions = [string, string?][];
103
+ /**
104
+ * 获取维基链接建议
105
+ * @param search 搜索字符串,开头不包含` `
106
+ * @param namespace 命名空间
107
+ * @param subpage 是否为子页面
108
+ */
109
+ export type ApiSuggest = (search: string, namespace?: number, subpage?: boolean) => ApiSuggestions | Promise<ApiSuggestions>;
110
+ export interface MwConfig {
111
+ readonly tags: Record<string, true>;
112
+ readonly tagModes: Record<string, string>;
113
+ urlProtocols: string;
114
+ functionSynonyms: [Record<string, string>, Record<string, unknown>];
115
+ doubleUnderscore: [Record<string, unknown>, Record<string, unknown>];
116
+ nsid: Record<string, number>;
117
+ variants?: string[];
118
+ img?: Record<string, string>;
119
+ redirection?: string[];
120
+ permittedHtmlTags?: string[];
121
+ implicitlyClosedHtmlTags?: string[];
122
+ linkSuggest?: ApiSuggest;
123
+ paramSuggest?: ApiSuggest;
124
+ }
125
+ declare class MediaWikiData {
126
+ /** 已解析的节点 */
127
+ readonly readyTokens: Token[];
128
+ /** 当前起始位置 */
129
+ oldToken: Token | null;
130
+ /** 可能需要回滚的`'''` */
131
+ mark: number | null;
132
+ firstSingleLetterWord: number | null;
133
+ firstMultiLetterWord: number | null;
134
+ firstSpace: number | null;
135
+ readonly tags: string[];
136
+ constructor(tags: string[]);
137
+ }
138
+ /** Adapted from the original CodeMirror 5 stream parser by Pavel Astakhov */
139
+ export declare class MediaWiki {
140
+ readonly config: MwConfig;
141
+ readonly tokenTable: {
142
+ [x: string]: Tag;
143
+ };
144
+ readonly hiddenTable: Record<string, Tag>;
145
+ readonly permittedHtmlTags: Set<string>;
146
+ readonly implicitlyClosedHtmlTags: Set<string>;
147
+ readonly urlProtocols: RegExp;
148
+ readonly linkRegex: RegExp;
149
+ readonly inLinkRegex: RegExp;
150
+ readonly fileRegex: RegExp;
151
+ readonly redirectRegex: RegExp;
152
+ readonly img: string[];
153
+ readonly imgRegex: RegExp;
154
+ readonly headerRegex: RegExp;
155
+ readonly extAttrRegex: RegExp;
156
+ readonly templateRegex: RegExp;
157
+ readonly argumentRegex: RegExp;
158
+ readonly convertSemicolon: RegExp;
159
+ readonly convertLang: RegExp;
160
+ readonly convertRegex: RegExp;
161
+ readonly inputboxRegex: RegExp;
162
+ readonly tags: string[];
163
+ constructor(config: MwConfig);
164
+ /**
165
+ * Dynamically register a token in CodeMirror.
166
+ * This is solely for use by this.addTag() and CodeMirrorModeMediaWiki.makeLocalStyle().
167
+ *
168
+ * @param token
169
+ * @param hidden Whether the token is not highlighted
170
+ * @param parent
171
+ */
172
+ addToken(token: string, hidden?: boolean, parent?: Tag): void;
173
+ /**
174
+ * Register the ground tokens. These aren't referenced directly in the StreamParser, nor do
175
+ * they have a parent Tag, so we don't need them as constants like we do for other tokens.
176
+ * See this.makeLocalStyle() for how these tokens are used.
177
+ */
178
+ registerGroundTokens(): void;
179
+ makeFullStyle(style: Style, state: ExtState): string;
180
+ makeTagStyle(tag: TagName, state: State, endGround?: NestCount): [string];
181
+ makeStyle(style: string, state: ExtState, endGround?: NestCount): [string];
182
+ makeLocalTagStyle(tag: TagName, state: State, endGround?: NestCount): string;
183
+ makeLocalStyle(style: string, state: ExtState, endGround?: NestCount): string;
184
+ inStr(str: string, tag: TagName | false, errorTag?: TagName): Tokenizer;
185
+ eatWikiText(style: string): Tokenizer;
186
+ eatApostrophes(obj: Pick<State, 'bold' | 'italic'>): Tokenizer<string | false>;
187
+ eatExternalLinkProtocol(chars: string, free?: boolean): Tokenizer;
188
+ inExternalLink(text?: boolean): Tokenizer;
189
+ get eatFreeExternalLink(): Tokenizer;
190
+ inLink(file: boolean, section?: boolean): Tokenizer;
191
+ inLinkText(file: boolean, gallery?: boolean): Tokenizer;
192
+ toEatImageParameter(stream: StringStream, state: State): void;
193
+ eatList(stream: StringStream, state: State): string;
194
+ eatDoubleUnderscore(style: string, stream: StringStream, state: State): Style;
195
+ get eatStartTable(): Tokenizer;
196
+ inTableDefinition(tr?: boolean): Tokenizer;
197
+ get inTable(): Tokenizer;
198
+ inTableCell(style: string, needAttr?: boolean, firstLine?: boolean): Tokenizer;
199
+ inSectionHeader(str: string): Tokenizer;
200
+ get inComment(): Tokenizer;
201
+ eatTagName(name: string, isCloseTag?: boolean, isHtmlTag?: boolean): Tokenizer;
202
+ inHtmlTagAttribute(name: string): Tokenizer;
203
+ inExtTagAttribute(name: string): Tokenizer;
204
+ eatExtTagArea(name: string): Tokenizer;
205
+ inExtTokens(origString: string): Tokenizer;
206
+ inVariable(pos?: number): Tokenizer;
207
+ eatTransclusion(stream: StringStream, state: State): string;
208
+ inParserFunctionName(invoke?: boolean): Tokenizer;
209
+ inTemplatePageName(haveEaten?: boolean, anchor?: boolean): Tokenizer;
210
+ inParserFunctionArgument(module?: boolean): Tokenizer;
211
+ inTemplateArgument(expectName?: boolean): Tokenizer;
212
+ inConvert(style: string, needFlag?: boolean, needLang?: boolean): Tokenizer;
213
+ eatEntity(stream: StringStream, style: string): string;
214
+ /**
215
+ * Remembers position and status for rollbacking.
216
+ * It is needed for changing from bold to italic with apostrophes before it, if required.
217
+ *
218
+ * @see https://phabricator.wikimedia.org/T108455
219
+ * @param stream
220
+ * @param state
221
+ */
222
+ prepareItalicForCorrection(stream: StringStream, state: State): void;
223
+ /**
224
+ * main entry
225
+ *
226
+ * @see https://codemirror.net/docs/ref/#language.StreamParser
227
+ *
228
+ * @param tags
229
+ */
230
+ mediawiki(tags?: string[]): StreamParser<State>;
231
+ 'text/nowiki'(): StreamParser<Record<string, never>>;
232
+ inReferences(tag: string, comment?: boolean): Tokenizer<string>;
233
+ 'text/references'(tags: string[]): StreamParser<State>;
234
+ 'text/choose'(tags: string[]): StreamParser<State>;
235
+ 'text/combobox'(tags: string[]): StreamParser<State>;
236
+ get inInputbox(): Tokenizer<string>;
237
+ 'text/inputbox'(tags: string[]): StreamParser<State>;
238
+ inGallery(section?: boolean): Tokenizer;
239
+ 'text/gallery'(tags: string[]): StreamParser<State>;
240
+ }
241
+ export {};
package/i18n/en.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.13.1",
2
+ "version": "2.14.0",
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.0",
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.0",
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
  }
@@ -193,10 +195,22 @@
193
195
  color: #d08;
194
196
  font-weight: normal;
195
197
  }
198
+ .cm-mw-table-th,
196
199
  .cm-mw-table-caption {
197
200
  font-weight: bold;
198
201
  }
199
202
 
203
+ /* convert */
204
+ .cm-mw-convert-bracket,
205
+ .cm-mw-convert-delimiter {
206
+ color: #b68;
207
+ font-weight: bold;
208
+ }
209
+ .cm-mw-convert-flag,
210
+ .cm-mw-convert-lang {
211
+ color: #b68;
212
+ }
213
+
200
214
  /* HTML entity */
201
215
  .cm-mw-entity {
202
216
  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.0",
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
  }