@bhsd/codemirror-mediawiki 2.12.6 → 2.13.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.
@@ -9,10 +9,10 @@ declare interface TagMatchResult extends MatchResult {
9
9
  end?: Tag;
10
10
  }
11
11
  declare class Tag {
12
- type: TagType;
13
- name: string;
14
- first: SyntaxNode;
15
- last: SyntaxNode;
12
+ readonly type: TagType;
13
+ readonly name: string;
14
+ readonly first: SyntaxNode;
15
+ readonly last: SyntaxNode;
16
16
  get closing(): boolean;
17
17
  get selfClosing(): boolean;
18
18
  get from(): number;
@@ -4,6 +4,91 @@
4
4
  * @see https://gerrit.wikimedia.org/g/mediawiki/extensions/CodeMirror
5
5
  */
6
6
  import { LanguageSupport } from '@codemirror/language';
7
+ import { Tag } from '@lezer/highlight';
8
+ import type { StreamParser, StringStream, TagStyle } from '@codemirror/language';
9
+ import type { CompletionSource, Completion } from '@codemirror/autocomplete';
10
+ declare const tokens: {
11
+ apostrophes: string;
12
+ comment: string;
13
+ doubleUnderscore: string;
14
+ em: string;
15
+ error: string;
16
+ extLink: string;
17
+ extLinkBracket: string;
18
+ extLinkProtocol: string;
19
+ extLinkText: string;
20
+ extTag: string;
21
+ extTagAttribute: string;
22
+ extTagBracket: string;
23
+ extTagName: string;
24
+ freeExtLink: string;
25
+ freeExtLinkProtocol: string;
26
+ hr: string;
27
+ htmlEntity: string;
28
+ htmlTagAttribute: string;
29
+ htmlTagBracket: string;
30
+ htmlTagName: string;
31
+ imageParameter: string;
32
+ linkBracket: string;
33
+ linkDelimiter: string;
34
+ linkPageName: string;
35
+ linkText: string;
36
+ linkToSection: string;
37
+ list: string;
38
+ pageName: string;
39
+ parserFunction: string;
40
+ parserFunctionBracket: string;
41
+ parserFunctionDelimiter: string;
42
+ parserFunctionName: string;
43
+ redirect: string;
44
+ section: string;
45
+ sectionHeader: string;
46
+ signature: string;
47
+ skipFormatting: string;
48
+ strong: string;
49
+ tableBracket: string;
50
+ tableCaption: string;
51
+ tableDefinition: string;
52
+ tableDelimiter: string;
53
+ tableDelimiter2: string;
54
+ template: string;
55
+ templateArgumentName: string;
56
+ templateBracket: string;
57
+ templateDelimiter: string;
58
+ templateName: string;
59
+ templateVariable: string;
60
+ templateVariableBracket: string;
61
+ templateVariableDelimiter: string;
62
+ templateVariableName: string;
63
+ };
64
+ declare type Style = string | [string];
65
+ declare type Tokenizer<T = Style> = (stream: StringStream, state: State) => T;
66
+ declare type TagName = keyof typeof tokens;
67
+ declare type NestCount = 'nTemplate' | 'nExt' | 'nVar' | 'nLink' | 'nExtLink';
68
+ declare interface Nesting extends Record<NestCount, number> {
69
+ extName: string | false;
70
+ extState: object | false;
71
+ }
72
+ declare interface State extends Nesting {
73
+ tokenize: Tokenizer;
74
+ readonly stack: Tokenizer[];
75
+ readonly inHtmlTag: string[];
76
+ extMode: StreamParser<object> | false;
77
+ lbrack: boolean | undefined;
78
+ bold: boolean;
79
+ italic: boolean;
80
+ dt: Partial<Nesting> & {
81
+ n: number;
82
+ };
83
+ redirect: boolean;
84
+ }
85
+ declare type ExtState = Omit<State, 'dt'> & Partial<Pick<State, 'dt'>>;
86
+ declare interface Token {
87
+ pos: number;
88
+ readonly string: string;
89
+ style: Style;
90
+ readonly state: State;
91
+ }
7
92
  export type ApiSuggestions = [string, string?][];
8
93
  /**
9
94
  * 获取维基链接建议
@@ -27,6 +112,124 @@ export interface MwConfig {
27
112
  linkSuggest?: ApiSuggest;
28
113
  paramSuggest?: ApiSuggest;
29
114
  }
115
+ declare const enum TableCell {
116
+ Td = 0,
117
+ Th = 1,
118
+ Caption = 2
119
+ }
120
+ /** Adapted from the original CodeMirror 5 stream parser by Pavel Astakhov */
121
+ export declare class MediaWiki {
122
+ #private;
123
+ /** 已解析的节点 */
124
+ readonly readyTokens: Token[];
125
+ /** 当前起始位置 */
126
+ oldToken: Token | null;
127
+ /** 可能需要回滚的`'''` */
128
+ mark: number | null;
129
+ readonly config: MwConfig;
130
+ firstSingleLetterWord: number | null;
131
+ firstMultiLetterWord: number | null;
132
+ firstSpace: number | null;
133
+ readonly tokenTable: {
134
+ [x: string]: Tag;
135
+ };
136
+ readonly hiddenTable: Record<string, Tag>;
137
+ readonly permittedHtmlTags: Set<string>;
138
+ readonly implicitlyClosedHtmlTags: Set<string>;
139
+ readonly urlProtocols: RegExp;
140
+ readonly fileRegex: RegExp;
141
+ readonly nsRegex: RegExp;
142
+ readonly redirectRegex: RegExp;
143
+ readonly imgRegex: RegExp;
144
+ readonly functionSynonyms: Completion[];
145
+ readonly doubleUnderscore: Completion[];
146
+ readonly extTags: Completion[];
147
+ readonly htmlTags: Completion[];
148
+ readonly protocols: Completion[];
149
+ readonly imgKeys: Completion[];
150
+ readonly htmlAttrs: Completion[];
151
+ readonly elementAttrs: Map<string | undefined, Completion[]>;
152
+ readonly extAttrs: Map<string, Completion[]>;
153
+ constructor(config: MwConfig);
154
+ /**
155
+ * Dynamically register a token in CodeMirror.
156
+ * This is solely for use by this.addTag() and CodeMirrorModeMediaWiki.makeLocalStyle().
157
+ *
158
+ * @param token
159
+ * @param hidden Whether the token is not highlighted
160
+ * @param parent
161
+ */
162
+ addToken(token: string, hidden?: boolean, parent?: Tag): void;
163
+ /**
164
+ * Register the ground tokens. These aren't referenced directly in the StreamParser, nor do
165
+ * they have a parent Tag, so we don't need them as constants like we do for other tokens.
166
+ * See this.makeLocalStyle() for how these tokens are used.
167
+ */
168
+ registerGroundTokens(): void;
169
+ /**
170
+ * This defines the actual CSS class assigned to each tag/token.
171
+ *
172
+ * @see https://codemirror.net/docs/ref/#language.TagStyle
173
+ */
174
+ getTagStyles(): TagStyle[];
175
+ makeFullStyle(style: Style, state: ExtState): string;
176
+ makeTagStyle(tag: TagName, state: State, endGround?: NestCount): [string];
177
+ makeStyle(style: string, state: ExtState, endGround?: NestCount): [string];
178
+ makeLocalTagStyle(tag: TagName, state: State, endGround?: NestCount): string;
179
+ makeLocalStyle(style: string, state: ExtState, endGround?: NestCount): string;
180
+ inStr(str: string, tag: TagName | false, errorTag?: TagName): Tokenizer;
181
+ /**
182
+ * @todo 添加stage参数
183
+ * @ignore
184
+ */
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): Tokenizer;
192
+ toEatImageParameter(stream: StringStream, state: State): void;
193
+ inSectionHeader(count: number): Tokenizer;
194
+ get eatSectionHeader(): Tokenizer;
195
+ eatList(stream: StringStream, state: State): string;
196
+ get eatStartTable(): Tokenizer;
197
+ inTableDefinition(tr?: boolean): Tokenizer;
198
+ get inTable(): Tokenizer;
199
+ inTableCell(needAttr: boolean, type: TableCell, firstLine?: boolean): Tokenizer;
200
+ eatEntity(stream: StringStream, style: string): string;
201
+ get inVariable(): Tokenizer;
202
+ inVariableDefault(isFirst?: boolean): Tokenizer;
203
+ get inComment(): Tokenizer;
204
+ inParserFunctionName(sameLine?: boolean, invoke?: boolean): Tokenizer;
205
+ inParserFunctionArguments(module?: boolean): Tokenizer;
206
+ inTemplatePageName(haveEaten?: boolean, anchor?: boolean): Tokenizer;
207
+ inTemplateArgument(expectName?: boolean): Tokenizer;
208
+ eatTagName(chars: string, isCloseTag?: boolean, isHtmlTag?: boolean): Tokenizer;
209
+ inHtmlTagAttribute(name: string): Tokenizer;
210
+ get eatNowiki(): Tokenizer<string>;
211
+ inExtTagAttribute(name: string): Tokenizer;
212
+ eatExtTagArea(name: string): Tokenizer;
213
+ eatExtCloseTag(name: string): Tokenizer;
214
+ inExtTokens(origString: string | false): Tokenizer;
215
+ /**
216
+ * Remembers position and status for rollbacking.
217
+ * It is needed for changing from bold to italic with apostrophes before it, if required.
218
+ *
219
+ * @see https://phabricator.wikimedia.org/T108455
220
+ * @param stream
221
+ */
222
+ prepareItalicForCorrection(stream: StringStream): void;
223
+ /**
224
+ * main entry
225
+ *
226
+ * @see https://codemirror.net/docs/ref/#language.StreamParser
227
+ */
228
+ get mediawiki(): StreamParser<State>;
229
+ get 'text/mediawiki'(): StreamParser<State>;
230
+ /** 自动补全魔术字和标签名 */
231
+ get completionSource(): CompletionSource;
232
+ }
30
233
  /**
31
234
  * Gets a LanguageSupport instance for the MediaWiki mode.
32
235
  * @param config Configuration for the MediaWiki mode
@@ -37,3 +240,4 @@ export declare const mediawiki: (config: MwConfig) => LanguageSupport;
37
240
  * @param config Configuration for the MediaWiki mode
38
241
  */
39
242
  export declare const html: (config: MwConfig) => LanguageSupport;
243
+ export {};