@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.
@@ -4,144 +4,13 @@
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';
7
+ import { MediaWiki } from './token';
8
+ import type { StreamParser, TagStyle } from '@codemirror/language';
9
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
- fileText: string;
25
- freeExtLink: string;
26
- freeExtLinkProtocol: string;
27
- hr: string;
28
- htmlEntity: string;
29
- htmlTagAttribute: string;
30
- htmlTagBracket: string;
31
- htmlTagName: string;
32
- imageParameter: string;
33
- linkBracket: string;
34
- linkDelimiter: string;
35
- linkPageName: string;
36
- linkText: string;
37
- linkToSection: string;
38
- list: string;
39
- pageName: string;
40
- parserFunction: string;
41
- parserFunctionBracket: string;
42
- parserFunctionDelimiter: string;
43
- parserFunctionName: string;
44
- redirect: string;
45
- section: string;
46
- sectionHeader: string;
47
- signature: string;
48
- skipFormatting: string;
49
- strong: string;
50
- tableBracket: string;
51
- tableCaption: string;
52
- tableDefinition: string;
53
- tableDelimiter: string;
54
- tableDelimiter2: string;
55
- template: string;
56
- templateArgumentName: string;
57
- templateBracket: string;
58
- templateDelimiter: string;
59
- templateName: string;
60
- templateVariable: string;
61
- templateVariableBracket: string;
62
- templateVariableDelimiter: string;
63
- templateVariableName: string;
64
- };
65
- declare type Style = string | [string];
66
- declare type Tokenizer<T = Style> = (stream: StringStream, state: State) => T;
67
- declare type TagName = keyof typeof tokens;
68
- declare type NestCount = 'nTemplate' | 'nExt' | 'nVar' | 'nLink' | 'nExtLink';
69
- declare interface Nesting extends Record<NestCount, number> {
70
- extName: string | false;
71
- extState: object | false;
72
- }
73
- declare interface State extends Nesting {
74
- tokenize: Tokenizer;
75
- readonly stack: Tokenizer[];
76
- readonly inHtmlTag: string[];
77
- extMode: StreamParser<object> | false;
78
- lbrack: boolean | undefined;
79
- bold: boolean;
80
- italic: boolean;
81
- dt: Partial<Nesting> & {
82
- n: number;
83
- };
84
- redirect: boolean;
85
- }
86
- declare type ExtState = Omit<State, 'dt'> & Partial<Pick<State, 'dt'>>;
87
- declare interface Token {
88
- pos: number;
89
- readonly string: string;
90
- style: Style;
91
- readonly state: State;
92
- }
93
- export type ApiSuggestions = [string, string?][];
94
- /**
95
- * 获取维基链接建议
96
- * @param search 搜索字符串,开头不包含` `
97
- * @param namespace 命名空间
98
- * @param subpage 是否为子页面
99
- */
100
- export type ApiSuggest = (search: string, namespace?: number, subpage?: boolean) => ApiSuggestions | Promise<ApiSuggestions>;
101
- export interface MwConfig {
102
- readonly tags: Record<string, true>;
103
- readonly tagModes: Record<string, string>;
104
- urlProtocols: string;
105
- functionSynonyms: [Record<string, string>, Record<string, unknown>];
106
- doubleUnderscore: [Record<string, unknown>, Record<string, unknown>];
107
- nsid: Record<string, number>;
108
- variants?: string[];
109
- img?: Record<string, string>;
110
- redirection?: string[];
111
- permittedHtmlTags?: string[];
112
- implicitlyClosedHtmlTags?: string[];
113
- linkSuggest?: ApiSuggest;
114
- paramSuggest?: ApiSuggest;
115
- }
116
- declare const enum TableCell {
117
- Td = 0,
118
- Th = 1,
119
- Caption = 2
120
- }
121
- /** Adapted from the original CodeMirror 5 stream parser by Pavel Astakhov */
122
- export declare class MediaWiki {
10
+ import type { MwConfig } from './token';
11
+ export declare class FullMediaWiki extends MediaWiki {
123
12
  #private;
124
- /** 已解析的节点 */
125
- readonly readyTokens: Token[];
126
- /** 当前起始位置 */
127
- oldToken: Token | null;
128
- /** 可能需要回滚的`'''` */
129
- mark: number | null;
130
- readonly config: MwConfig;
131
- firstSingleLetterWord: number | null;
132
- firstMultiLetterWord: number | null;
133
- firstSpace: number | null;
134
- readonly tokenTable: {
135
- [x: string]: Tag;
136
- };
137
- readonly hiddenTable: Record<string, Tag>;
138
- readonly permittedHtmlTags: Set<string>;
139
- readonly implicitlyClosedHtmlTags: Set<string>;
140
- readonly urlProtocols: RegExp;
141
- readonly fileRegex: RegExp;
142
13
  readonly nsRegex: RegExp;
143
- readonly redirectRegex: RegExp;
144
- readonly imgRegex: RegExp;
145
14
  readonly functionSynonyms: Completion[];
146
15
  readonly doubleUnderscore: Completion[];
147
16
  readonly extTags: Completion[];
@@ -152,80 +21,13 @@ export declare class MediaWiki {
152
21
  readonly elementAttrs: Map<string | undefined, Completion[]>;
153
22
  readonly extAttrs: Map<string, Completion[]>;
154
23
  constructor(config: MwConfig);
155
- /**
156
- * Dynamically register a token in CodeMirror.
157
- * This is solely for use by this.addTag() and CodeMirrorModeMediaWiki.makeLocalStyle().
158
- *
159
- * @param token
160
- * @param hidden Whether the token is not highlighted
161
- * @param parent
162
- */
163
- addToken(token: string, hidden?: boolean, parent?: Tag): void;
164
- /**
165
- * Register the ground tokens. These aren't referenced directly in the StreamParser, nor do
166
- * they have a parent Tag, so we don't need them as constants like we do for other tokens.
167
- * See this.makeLocalStyle() for how these tokens are used.
168
- */
169
- registerGroundTokens(): void;
170
24
  /**
171
25
  * This defines the actual CSS class assigned to each tag/token.
172
26
  *
173
27
  * @see https://codemirror.net/docs/ref/#language.TagStyle
174
28
  */
175
29
  getTagStyles(): TagStyle[];
176
- makeFullStyle(style: Style, state: ExtState): string;
177
- makeTagStyle(tag: TagName, state: State, endGround?: NestCount): [string];
178
- makeStyle(style: string, state: ExtState, endGround?: NestCount): [string];
179
- makeLocalTagStyle(tag: TagName, state: State, endGround?: NestCount): string;
180
- makeLocalStyle(style: string, state: ExtState, endGround?: NestCount): string;
181
- inStr(str: string, tag: TagName | false, errorTag?: TagName): Tokenizer;
182
- /**
183
- * @todo 添加stage参数
184
- * @ignore
185
- */
186
- eatWikiText(style: string): Tokenizer;
187
- eatApostrophes(obj: Pick<State, 'bold' | 'italic'>): Tokenizer<string | false>;
188
- eatExternalLinkProtocol(chars: string, free?: boolean): Tokenizer;
189
- inExternalLink(text?: boolean): Tokenizer;
190
- get eatFreeExternalLink(): Tokenizer;
191
- inLink(file: boolean, section?: boolean): Tokenizer;
192
- inLinkText(file: boolean): Tokenizer;
193
- toEatImageParameter(stream: StringStream, state: State): void;
194
- eatList(stream: StringStream, state: State): string;
195
- eatDoubleUnderscore(style: string): Tokenizer;
196
- get eatStartTable(): Tokenizer;
197
- inTableDefinition(tr?: boolean): Tokenizer;
198
- get inTable(): Tokenizer;
199
- inTableCell(needAttr: boolean, type: TableCell, firstLine?: boolean): Tokenizer;
200
- inSectionHeader(str: string): Tokenizer;
201
- get inComment(): Tokenizer;
202
- eatTagName(name: string, isCloseTag?: boolean, isHtmlTag?: boolean): Tokenizer;
203
- inHtmlTagAttribute(name: string): Tokenizer;
204
- inExtTagAttribute(name: string): Tokenizer;
205
- eatExtTagArea(name: string): Tokenizer;
206
- inExtTokens(origString: string): Tokenizer;
207
- inVariable(pos: number): Tokenizer;
208
- inParserFunctionName(invoke?: boolean): Tokenizer;
209
- inTemplatePageName(haveEaten?: boolean, anchor?: boolean): Tokenizer;
210
- inParserFunctionArgument(module?: boolean): Tokenizer;
211
- inTemplateArgument(expectName?: boolean): Tokenizer;
212
- eatEntity(stream: StringStream, style: string): string;
213
- get eatNowiki(): Tokenizer<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
- */
221
- prepareItalicForCorrection(stream: StringStream): void;
222
- /**
223
- * main entry
224
- *
225
- * @see https://codemirror.net/docs/ref/#language.StreamParser
226
- */
227
- get mediawiki(): StreamParser<State>;
228
- get 'text/mediawiki'(): StreamParser<State>;
30
+ mediawiki(tags?: string[]): StreamParser<any>;
229
31
  /** 自动补全魔术字和标签名 */
230
32
  get completionSource(): CompletionSource;
231
33
  }
@@ -239,4 +41,3 @@ export declare const mediawiki: (config: MwConfig) => LanguageSupport;
239
41
  * @param config Configuration for the MediaWiki mode
240
42
  */
241
43
  export declare const html: (config: MwConfig) => LanguageSupport;
242
- export {};