wikiparser-node 1.16.3 → 1.16.5

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.
Files changed (154) hide show
  1. package/README.md +1 -1
  2. package/bundle/bundle.es7.js +28 -28
  3. package/bundle/bundle.lsp.js +30 -30
  4. package/bundle/bundle.min.js +29 -29
  5. package/coverage/badge.svg +1 -1
  6. package/data/signatures.json +43 -0
  7. package/dist/addon/table.js +7 -4
  8. package/dist/addon/token.js +119 -113
  9. package/dist/addon/transclude.js +7 -5
  10. package/dist/base.d.mts +99 -30
  11. package/dist/base.d.ts +99 -30
  12. package/dist/index.d.ts +10 -4
  13. package/dist/index.js +59 -14
  14. package/dist/lib/attributes.js +2 -2
  15. package/dist/lib/element.d.ts +128 -29
  16. package/dist/lib/element.js +178 -32
  17. package/dist/lib/lsp.d.ts +62 -27
  18. package/dist/lib/lsp.js +395 -304
  19. package/dist/lib/node.d.ts +123 -54
  20. package/dist/lib/node.js +216 -87
  21. package/dist/lib/range.d.ts +83 -31
  22. package/dist/lib/range.js +83 -31
  23. package/dist/lib/ranges.d.ts +1 -1
  24. package/dist/lib/ranges.js +3 -2
  25. package/dist/lib/text.d.ts +40 -14
  26. package/dist/lib/text.js +47 -19
  27. package/dist/lib/title.d.ts +54 -17
  28. package/dist/lib/title.js +101 -47
  29. package/dist/mixin/attributesParent.d.ts +37 -21
  30. package/dist/mixin/attributesParent.js +18 -20
  31. package/dist/mixin/flagsParent.d.ts +38 -12
  32. package/dist/mixin/hidden.d.ts +0 -2
  33. package/dist/mixin/hidden.js +0 -2
  34. package/dist/mixin/magicLinkParent.d.ts +11 -5
  35. package/dist/mixin/singleLine.d.ts +0 -2
  36. package/dist/mixin/singleLine.js +3 -3
  37. package/dist/mixin/sol.d.ts +0 -2
  38. package/dist/mixin/sol.js +2 -3
  39. package/dist/mixin/syntax.d.ts +0 -2
  40. package/dist/mixin/syntax.js +0 -2
  41. package/dist/parser/braces.js +4 -2
  42. package/dist/parser/links.js +13 -7
  43. package/dist/parser/list.js +3 -1
  44. package/dist/parser/quotes.js +22 -2
  45. package/dist/parser/redirect.js +4 -1
  46. package/dist/parser/selector.js +1 -1
  47. package/dist/src/arg.d.ts +19 -9
  48. package/dist/src/arg.js +34 -15
  49. package/dist/src/atom.d.ts +5 -1
  50. package/dist/src/atom.js +5 -1
  51. package/dist/src/attribute.d.ts +26 -8
  52. package/dist/src/attribute.js +30 -11
  53. package/dist/src/attributes.d.ts +50 -22
  54. package/dist/src/attributes.js +54 -26
  55. package/dist/src/converter.d.ts +4 -2
  56. package/dist/src/converter.js +12 -9
  57. package/dist/src/converterFlags.d.ts +45 -15
  58. package/dist/src/converterFlags.js +45 -15
  59. package/dist/src/converterRule.d.ts +30 -11
  60. package/dist/src/converterRule.js +46 -16
  61. package/dist/src/extLink.d.ts +6 -2
  62. package/dist/src/extLink.js +14 -11
  63. package/dist/src/gallery.d.ts +13 -9
  64. package/dist/src/gallery.js +35 -21
  65. package/dist/src/heading.d.ts +13 -7
  66. package/dist/src/heading.js +28 -18
  67. package/dist/src/hidden.d.ts +5 -1
  68. package/dist/src/hidden.js +7 -3
  69. package/dist/src/html.d.ts +12 -10
  70. package/dist/src/html.js +17 -12
  71. package/dist/src/imageParameter.d.ts +27 -12
  72. package/dist/src/imageParameter.js +27 -12
  73. package/dist/src/imagemap.d.ts +4 -4
  74. package/dist/src/imagemap.js +9 -5
  75. package/dist/src/imagemapLink.d.ts +3 -1
  76. package/dist/src/imagemapLink.js +3 -1
  77. package/dist/src/index.d.ts +65 -64
  78. package/dist/src/index.js +111 -132
  79. package/dist/src/link/base.d.ts +14 -6
  80. package/dist/src/link/base.js +45 -21
  81. package/dist/src/link/category.d.ts +9 -4
  82. package/dist/src/link/category.js +20 -4
  83. package/dist/src/link/file.d.ts +71 -23
  84. package/dist/src/link/file.js +100 -36
  85. package/dist/src/link/galleryImage.d.ts +8 -4
  86. package/dist/src/link/galleryImage.js +15 -8
  87. package/dist/src/link/index.d.ts +14 -6
  88. package/dist/src/link/index.js +15 -5
  89. package/dist/src/link/redirectTarget.d.ts +4 -3
  90. package/dist/src/link/redirectTarget.js +5 -3
  91. package/dist/src/magicLink.d.ts +28 -12
  92. package/dist/src/magicLink.js +56 -34
  93. package/dist/src/nested.d.ts +5 -3
  94. package/dist/src/nested.js +9 -6
  95. package/dist/src/nowiki/base.d.ts +4 -2
  96. package/dist/src/nowiki/base.js +6 -5
  97. package/dist/src/nowiki/comment.d.ts +6 -2
  98. package/dist/src/nowiki/comment.js +8 -3
  99. package/dist/src/nowiki/dd.d.ts +0 -3
  100. package/dist/src/nowiki/dd.js +0 -8
  101. package/dist/src/nowiki/doubleUnderscore.d.ts +5 -1
  102. package/dist/src/nowiki/doubleUnderscore.js +5 -1
  103. package/dist/src/nowiki/index.d.ts +5 -1
  104. package/dist/src/nowiki/index.js +5 -1
  105. package/dist/src/nowiki/list.d.ts +5 -1
  106. package/dist/src/nowiki/list.js +5 -1
  107. package/dist/src/nowiki/listBase.d.ts +15 -5
  108. package/dist/src/nowiki/listBase.js +41 -10
  109. package/dist/src/nowiki/noinclude.d.ts +5 -1
  110. package/dist/src/nowiki/noinclude.js +5 -1
  111. package/dist/src/nowiki/quote.d.ts +15 -8
  112. package/dist/src/nowiki/quote.js +32 -12
  113. package/dist/src/onlyinclude.d.ts +4 -2
  114. package/dist/src/onlyinclude.js +4 -2
  115. package/dist/src/paramTag/index.d.ts +1 -1
  116. package/dist/src/paramTag/index.js +1 -1
  117. package/dist/src/parameter.d.ts +24 -12
  118. package/dist/src/parameter.js +45 -27
  119. package/dist/src/pre.d.ts +1 -1
  120. package/dist/src/pre.js +1 -1
  121. package/dist/src/redirect.d.ts +2 -0
  122. package/dist/src/redirect.js +2 -0
  123. package/dist/src/syntax.d.ts +5 -1
  124. package/dist/src/syntax.js +5 -1
  125. package/dist/src/table/base.d.ts +5 -1
  126. package/dist/src/table/base.js +11 -4
  127. package/dist/src/table/index.d.ts +134 -66
  128. package/dist/src/table/index.js +149 -81
  129. package/dist/src/table/td.d.ts +18 -10
  130. package/dist/src/table/td.js +23 -15
  131. package/dist/src/table/tr.d.ts +13 -3
  132. package/dist/src/table/tr.js +14 -6
  133. package/dist/src/table/trBase.d.ts +28 -12
  134. package/dist/src/table/trBase.js +28 -18
  135. package/dist/src/tagPair/ext.d.ts +3 -1
  136. package/dist/src/tagPair/ext.js +11 -10
  137. package/dist/src/tagPair/include.d.ts +8 -2
  138. package/dist/src/tagPair/include.js +8 -2
  139. package/dist/src/tagPair/index.d.ts +6 -2
  140. package/dist/src/tagPair/index.js +6 -2
  141. package/dist/src/transclude.d.ts +107 -33
  142. package/dist/src/transclude.js +139 -45
  143. package/dist/util/debug.js +2 -7
  144. package/dist/util/html.js +1 -14
  145. package/dist/util/string.js +7 -1
  146. package/extensions/dist/base.js +25 -8
  147. package/extensions/dist/codejar.js +2 -1
  148. package/extensions/dist/lsp.js +5 -10
  149. package/extensions/es7/base.js +25 -8
  150. package/extensions/ui.css +1 -162
  151. package/i18n/zh-hans.json +1 -1
  152. package/i18n/zh-hant.json +1 -1
  153. package/package.json +3 -3
  154. package/extensions/dist/test-page.js +0 -89
package/dist/base.d.ts CHANGED
@@ -74,28 +74,54 @@ export type AST = Record<string, string | number | boolean> & {
74
74
  childNodes?: AST[];
75
75
  data?: string;
76
76
  };
77
- /** 类似Node */
77
+ /**
78
+ * Node-like
79
+ *
80
+ * 类似Node
81
+ */
78
82
  export interface AstNode {
79
83
  readonly childNodes: readonly AstNode[];
80
- /** 节点类型 */
84
+ /**
85
+ * node type
86
+ *
87
+ * 节点类型
88
+ */
81
89
  type: string;
82
90
  toString(...args: unknown[]): string;
83
91
  /** Linter */
84
92
  lint(): LintError[];
85
- /** 以HTML格式打印 */
93
+ /**
94
+ * print in HTML
95
+ *
96
+ * 以HTML格式打印
97
+ */
86
98
  print(): string;
87
99
  }
88
- /** 所有节点的基类 */
100
+ /**
101
+ * base class for all tokens
102
+ *
103
+ * 所有节点的基类
104
+ */
89
105
  interface Token extends AstNode {
90
106
  readonly name?: string;
91
107
  /**
108
+ * Get all descendants that match the selector
109
+ *
92
110
  * 符合选择器的所有后代节点
93
111
  * @param selector 选择器
94
112
  */
95
113
  querySelectorAll<T = Token>(selector: string): T[];
96
- /** 保存为JSON */
114
+ /**
115
+ * Save in JSON format
116
+ *
117
+ * 保存为JSON
118
+ */
97
119
  json(): AST;
98
- /** 生成HTML */
120
+ /**
121
+ * Generate HTML
122
+ *
123
+ * 生成HTML
124
+ */
99
125
  toHtml(): string;
100
126
  }
101
127
  interface SignatureParameter {
@@ -116,91 +142,126 @@ export type CompletionItem = Omit<CompletionItemBase, 'kind'> & {
116
142
  kind: keyof typeof CompletionItemKind;
117
143
  };
118
144
  export interface LanguageService {
119
- /** 销毁实例 */
145
+ /**
146
+ * Destroy the instance
147
+ *
148
+ * 销毁实例
149
+ */
120
150
  destroy(): void;
121
151
  /**
152
+ * Provide color decorators
153
+ *
122
154
  * 提供颜色指示
123
- * @param rgba 颜色解析函数
124
- * @param text 源代码
125
- * @param hsl 是否允许HSL颜色
155
+ * @param rgba color parser / 颜色解析函数
156
+ * @param text source Wikitext / 源代码
157
+ * @param hsl whether HSL colors are treated / 是否允许HSL颜色
126
158
  */
127
159
  provideDocumentColors(rgba: (s: string) => [number, number, number, number] | [], text: string, hsl?: boolean): Promise<ColorInformation[]>;
128
160
  /**
161
+ * Provide color pickers
162
+ *
129
163
  * 颜色选择器
130
- * @param color 颜色信息
164
+ * @param color color information / 颜色信息
131
165
  */
132
166
  provideColorPresentations(color: ColorInformation): ColorPresentation[];
133
167
  /**
168
+ * Provide auto-completion
169
+ *
134
170
  * 提供自动补全
135
- * @param text 源代码
171
+ * @param text source Wikitext / 源代码
136
172
  * @param position 位置
137
173
  */
138
174
  provideCompletionItems(text: string, position: Position): Promise<CompletionItem[] | undefined>;
139
175
  /**
176
+ * Provide grammar check
177
+ *
140
178
  * 提供语法检查
141
- * @param wikitext 源代码
179
+ * @param text source Wikitext / 源代码
180
+ * @param warning whether to include warnings / 是否包含警告
142
181
  */
143
- provideDiagnostics(wikitext: string, warning?: boolean): Promise<Diagnostic[]>;
182
+ provideDiagnostics(text: string, warning?: boolean): Promise<Diagnostic[]>;
144
183
  /**
184
+ * Provide folding ranges
185
+ *
145
186
  * 提供折叠范围
146
- * @param text 源代码
187
+ * @param text source Wikitext / 源代码
147
188
  */
148
189
  provideFoldingRanges(text: string): Promise<FoldingRange[]>;
149
190
  /**
191
+ * Provide links
192
+ *
150
193
  * 提供链接
151
- * @param text 源代码
194
+ * @param text source Wikitext / 源代码
152
195
  */
153
196
  provideLinks(text: string): Promise<DocumentLink[]>;
154
197
  /**
198
+ * Provide references
199
+ *
155
200
  * 提供引用
156
- * @param text 源代码
201
+ * @param text source Wikitext / 源代码
157
202
  * @param position 位置
158
203
  */
159
204
  provideReferences(text: string, position: Position): Promise<Omit<Location, 'uri'>[] | undefined>;
160
205
  /**
206
+ * Provide definitions
207
+ *
161
208
  * 提供定义
162
- * @param text 源代码
209
+ * @param text source Wikitext / 源代码
163
210
  * @param position 位置
164
211
  */
165
212
  provideDefinition(text: string, position: Position): Promise<Omit<Location, 'uri'>[] | undefined>;
166
213
  /**
214
+ * Provide locations for renaming
215
+ *
167
216
  * 提供变量更名准备
168
- * @param text 源代码
217
+ * @param text source Wikitext / 源代码
169
218
  * @param position 位置
170
219
  */
171
220
  resolveRenameLocation(text: string, position: Position): Promise<Range | undefined>;
172
221
  /**
222
+ * Provide rename edits
223
+ *
173
224
  * 变量更名
174
- * @param text 源代码
225
+ * @param text source Wikitext / 源代码
175
226
  * @param position 位置
176
- * @param newName 新名称
227
+ * @param newName new name / 新名称
177
228
  */
178
229
  provideRenameEdits(text: string, position: Position, newName: string): Promise<WorkspaceEdit | undefined>;
179
230
  /**
231
+ * Provide hover information
232
+ *
180
233
  * 提供悬停信息
181
- * @param text 源代码
234
+ * @param text source Wikitext / 源代码
182
235
  * @param position 位置
183
236
  */
184
237
  provideHover(text: string, position: Position): Promise<Hover | undefined>;
185
238
  /**
239
+ * Provide signature help for magic words
240
+ *
186
241
  * 提供魔术字帮助
187
- * @param text 源代码
242
+ * @param text source Wikitext / 源代码
188
243
  * @param position 位置
189
244
  */
190
245
  provideSignatureHelp(text: string, position: Position): Promise<SignatureHelp | undefined>;
191
246
  /**
247
+ * Provide CodeLens
248
+ *
192
249
  * 提供 CodeLens
193
- * @param text 源代码
250
+ * @param text source Wikitext / 源代码
194
251
  */
195
252
  provideInlayHints(text: string): Promise<InlayHint[]>;
196
253
  /**
254
+ * Provide quick fixes
255
+ *
197
256
  * 提供快速修复建议
198
- * @param diagnostics 语法诊断信息
257
+ * @param diagnostics grammar diagnostics / 语法诊断信息
199
258
  */
200
259
  provideCodeAction(diagnostics: Diagnostic[]): CodeAction[];
201
260
  /**
261
+ * Provide document sections
262
+ *
202
263
  * 提供章节
203
- * @param text 源代码
264
+ * @param text source Wikitext / 源代码
204
265
  */
205
266
  provideDocumentSymbols(text: string): Promise<DocumentSymbol[]>;
206
267
  }
@@ -208,17 +269,25 @@ export interface Parser {
208
269
  config: Config | string;
209
270
  i18n: Record<string, string> | string | undefined;
210
271
  viewOnly: boolean;
211
- /** 获取当前的解析设置 */
272
+ /**
273
+ * Get the current parser configuration
274
+ *
275
+ * 获取当前的解析设置
276
+ */
212
277
  getConfig(): Config;
213
278
  /**
279
+ * Parse wikitext
280
+ *
214
281
  * 解析wikitext
215
- * @param include 是否嵌入
216
- * @param maxStage 最大解析层级
282
+ * @param include whether to be transcluded / 是否嵌入
283
+ * @param maxStage max stage for parsing / 最大解析层级
217
284
  */
218
285
  parse(wikitext: string, include?: boolean, maxStage?: number | Stage | Stage[], config?: Config): Token;
219
286
  /**
287
+ * Create a language server
288
+ *
220
289
  * 创建语言服务
221
- * @param uri 文档标识
290
+ * @param uri document URI / 文档标识
222
291
  */
223
292
  createLanguageService(uri: object): LanguageService;
224
293
  }
package/dist/index.d.ts CHANGED
@@ -11,19 +11,25 @@ declare interface Parser extends ParserBase {
11
11
  warning: boolean;
12
12
  debugging: boolean;
13
13
  /**
14
+ * Normalize page title
15
+ *
14
16
  * 规范化页面标题
15
- * @param title 标题(含或不含命名空间前缀)
16
- * @param defaultNs 命名空间
17
- * @param include 是否嵌入
17
+ * @param title title (with or without the namespace prefix) / 标题(含或不含命名空间前缀)
18
+ * @param defaultNs default namespace number / 命名空间
19
+ * @param include whether to be transcluded / 是否嵌入
18
20
  */
19
21
  normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config): Title;
20
22
  parse(wikitext: string, include?: boolean, maxStage?: number | Stage | Stage[], config?: Config): Token;
21
23
  /**
24
+ * Create a language server
25
+ *
22
26
  * 创建语言服务
23
- * @param uri 文档标识
27
+ * @param uri document URI / 文档标识
24
28
  */
25
29
  createLanguageService(uri: object): LanguageService;
26
30
  /**
31
+ * Check if the title is an interwiki link
32
+ *
27
33
  * 是否是跨维基链接
28
34
  * @param title 链接标题
29
35
  */
package/dist/index.js CHANGED
@@ -1,26 +1,32 @@
1
1
  "use strict";
2
2
  /* eslint n/exports-style: 0 */
3
- const fs = require("fs");
4
- const path = require("path");
5
3
  const base_1 = require("./base");
6
4
  const debug_1 = require("./util/debug");
7
5
  const constants_1 = require("./util/constants");
8
6
  const string_1 = require("./util/string");
9
- const diff_1 = require("./util/diff");
10
7
  /* NOT FOR BROWSER */
11
8
  const chalk = require("chalk");
9
+ /* NOT FOR BROWSER END */
10
+ /* NOT FOR BROWSER ONLY */
11
+ const fs = require("fs");
12
+ const path = require("path");
13
+ const diff_1 = require("./util/diff");
14
+ /* NOT FOR BROWSER ONLY */
12
15
  /**
13
16
  * 从根路径require
14
17
  * @param file 文件名
15
18
  * @param dir 子路径
16
19
  */
17
- const rootRequire = (file, dir) => require(path.isAbsolute(file) ? /* istanbul ignore next */ file : path.join('..', file.includes('/') ? '' : dir, file));
20
+ const rootRequire = (file, dir) => require(path.isAbsolute(file)
21
+ ? /* istanbul ignore next */ file
22
+ : path.join('..', file.includes('/') ? '' : dir, file));
23
+ /* NOT FOR BROWSER ONLY END */
18
24
  /* NOT FOR BROWSER */
19
25
  /**
20
26
  * 快速规范化页面标题
21
27
  * @param title 标题
22
28
  */
23
- const normalizeTitle = (title) => String(Parser.normalizeTitle(title));
29
+ const normalizeTitle = (title) => String(Parser.normalizeTitle(title, 0, false, undefined, true));
24
30
  /** 重定向列表 */
25
31
  class RedirectMap extends Map {
26
32
  /** @ignore */
@@ -68,6 +74,7 @@ const Parser = {
68
74
  /* NOT FOR BROWSER END */
69
75
  /** @implements */
70
76
  getConfig() {
77
+ /* NOT FOR BROWSER ONLY */
71
78
  if (typeof this.config === 'string') {
72
79
  this.config = rootRequire(this.config, 'config');
73
80
  /* istanbul ignore if */
@@ -87,6 +94,7 @@ const Parser = {
87
94
  /* NOT FOR BROWSER END */
88
95
  return this.getConfig();
89
96
  }
97
+ /* NOT FOR BROWSER ONLY END */
90
98
  const { doubleUnderscore } = this.config;
91
99
  for (let i = 0; i < 2; i++) {
92
100
  if (doubleUnderscore.length > i + 2 && doubleUnderscore[i].length === 0) {
@@ -100,18 +108,20 @@ const Parser = {
100
108
  },
101
109
  /** @implements */
102
110
  msg(msg, arg = '') {
111
+ /* NOT FOR BROWSER ONLY */
103
112
  if (typeof this.i18n === 'string') {
104
113
  this.i18n = rootRequire(this.i18n, 'i18n');
105
114
  return this.msg(msg, arg);
106
115
  }
116
+ /* NOT FOR BROWSER ONLY END */
107
117
  return msg && (this.i18n?.[msg] ?? msg).replace('$1', this.msg(arg));
108
118
  },
109
119
  /** @implements */
110
- normalizeTitle(title, defaultNs = 0, include, config = Parser.getConfig(), halfParsed, decode = false, selfLink = false) {
120
+ normalizeTitle(title, defaultNs = 0, include, config = Parser.getConfig(), temporary = false, halfParsed, decode = false, selfLink = false) {
111
121
  const { Title } = require('./lib/title');
112
122
  let titleObj;
113
123
  if (halfParsed) {
114
- titleObj = new Title(title, defaultNs, config, decode, selfLink);
124
+ titleObj = new Title(title, defaultNs, config, temporary, decode, selfLink);
115
125
  }
116
126
  else {
117
127
  const { Token } = require('./src/index');
@@ -119,7 +129,7 @@ const Parser = {
119
129
  const root = new Token(title, config);
120
130
  root.type = 'root';
121
131
  root.parseOnce(0, include).parseOnce();
122
- const t = new Title(root.toString(), defaultNs, config, decode, selfLink);
132
+ const t = new Title(root.toString(), defaultNs, config, temporary, decode, selfLink);
123
133
  for (const key of ['main', 'fragment']) {
124
134
  const str = t[key];
125
135
  if (str?.includes('\0')) {
@@ -154,6 +164,7 @@ const Parser = {
154
164
  token.type = 'root';
155
165
  try {
156
166
  return token.parse(maxStage, include);
167
+ /* NOT FOR BROWSER ONLY */
157
168
  }
158
169
  catch (e) /* istanbul ignore next */ {
159
170
  if (e instanceof Error) {
@@ -169,6 +180,7 @@ const Parser = {
169
180
  }
170
181
  throw e;
171
182
  }
183
+ /* NOT FOR BROWSER ONLY END */
172
184
  });
173
185
  /* NOT FOR BROWSER */
174
186
  /* istanbul ignore if */
@@ -192,13 +204,46 @@ const Parser = {
192
204
  return root;
193
205
  },
194
206
  /** @implements */
207
+ async partialParse(wikitext, watch, include, config = Parser.getConfig()) {
208
+ const { Token } = require('./src/index');
209
+ const set = typeof setImmediate === 'function' ? setImmediate : /* istanbul ignore next */ setTimeout, { running } = debug_1.Shadow;
210
+ debug_1.Shadow.running = true;
211
+ const token = new Token((0, string_1.tidy)(wikitext), config);
212
+ token.type = 'root';
213
+ let i = 0;
214
+ await new Promise(resolve => {
215
+ const /** @ignore */ check = () => {
216
+ if (watch() === wikitext) {
217
+ i++;
218
+ set(parseOnce, 0);
219
+ }
220
+ else {
221
+ resolve();
222
+ }
223
+ },
224
+ /** @ignore */ parseOnce = () => {
225
+ if (i === constants_1.MAX_STAGE + 1) {
226
+ token.afterBuild();
227
+ resolve();
228
+ }
229
+ else {
230
+ token[i === constants_1.MAX_STAGE ? 'build' : 'parseOnce'](i, include);
231
+ check();
232
+ }
233
+ };
234
+ set(parseOnce, 0);
235
+ });
236
+ debug_1.Shadow.running = running;
237
+ return token;
238
+ },
239
+ /** @implements */
195
240
  createLanguageService(uri) {
196
- let mod;
197
- // eslint-disable-next-line no-unused-labels
198
- LSP: mod = require('./lib/lsp');
199
- const { LanguageService, tasks } = mod;
200
- Parser.viewOnly = true;
201
- return tasks.get(uri) ?? new LanguageService(uri);
241
+ LSP: { // eslint-disable-line no-unused-labels
242
+ const mod = require('./lib/lsp');
243
+ const { LanguageService, tasks } = mod;
244
+ Parser.viewOnly = true;
245
+ return tasks.get(uri) ?? new LanguageService(uri);
246
+ }
202
247
  },
203
248
  /* NOT FOR BROWSER */
204
249
  /** @implements */
@@ -26,8 +26,8 @@ class Attributes {
26
26
  return this.#link;
27
27
  }
28
28
  get invalid() {
29
- this.#invalid ??= this.type === 'table-inter'
30
- || this.type === 'image-parameter' && this.token.name === 'invalid';
29
+ const { type, token: { name } } = this;
30
+ this.#invalid ??= type === 'table-inter' || type === 'image-parameter' && name === 'invalid';
31
31
  return this.#invalid;
32
32
  }
33
33
  get siblings() {
@@ -1,125 +1,224 @@
1
1
  import { AstNode } from './node';
2
2
  import type { LintError, AST } from '../base';
3
- import type { AstNodes, AstText, Token } from '../internal';
4
- /** 类似HTMLElement */
3
+ import type { AstNodes, AstText, Token, FileToken, LinkToken, RedirectTargetToken, ExtLinkToken, MagicLinkToken, ImageParameterToken, TranscludeToken } from '../internal';
4
+ declare type LinkTokens = LinkToken | RedirectTargetToken | ExtLinkToken | MagicLinkToken | ImageParameterToken;
5
+ export interface CaretPosition {
6
+ readonly offsetNode: AstNodes;
7
+ readonly offset: number;
8
+ }
9
+ /**
10
+ * HTMLElement-like
11
+ *
12
+ * 类似HTMLElement
13
+ */
5
14
  export declare abstract class AstElement extends AstNode {
6
15
  #private;
7
16
  readonly name?: string;
8
17
  readonly data: undefined;
9
- /** 子节点总数 */
18
+ /** number of child nodes / 子节点总数 */
10
19
  get length(): number;
11
20
  set length(n: number);
12
- /** 全部非文本子节点 */
21
+ /** all child elements / 全部非文本子节点 */
13
22
  get children(): Token[];
14
- /** 首位非文本子节点 */
23
+ /** first child element / 首位非文本子节点 */
15
24
  get firstElementChild(): Token | undefined;
16
- /** 末位非文本子节点 */
25
+ /** last child element / 末位非文本子节点 */
17
26
  get lastElementChild(): Token | undefined;
18
- /** 非文本子节点总数 */
27
+ /** number of child elements / 非文本子节点总数 */
19
28
  get childElementCount(): number;
20
- /** 父节点 */
29
+ /** parent node / 父节点 */
21
30
  get parentElement(): Token | undefined;
22
- /** AstElement.prototype.text()的getter写法 */
31
+ /** visible text / 可见部分 */
23
32
  get outerText(): string;
24
- /** 不可见 */
33
+ /** invisible / 不可见 */
25
34
  get hidden(): boolean;
26
- /** 内部高度 */
35
+ /** height of the inner / 内部高度 */
27
36
  get clientHeight(): number | undefined;
28
- /** 内部宽度 */
37
+ /** width of the inner / 内部宽度 */
29
38
  get clientWidth(): number | undefined;
39
+ /** all images, including gallery images / 所有图片,包括图库 */
40
+ get images(): FileToken[];
41
+ /** all internal, external and free external links / 所有内链、外链和自由外链 */
42
+ get links(): LinkTokens[];
43
+ /** all templates and modules / 所有模板和模块 */
44
+ get embeds(): TranscludeToken[];
30
45
  constructor();
31
- /** 合并相邻的文本子节点 */
46
+ /**
47
+ * Merge adjacent text child nodes
48
+ *
49
+ * 合并相邻的文本子节点
50
+ */
32
51
  normalize(): void;
33
52
  /**
53
+ * Remove a child node
54
+ *
34
55
  * 移除子节点
35
- * @param i 移除位置
56
+ * @param i position of the child node / 移除位置
36
57
  */
37
58
  removeAt(i: number): AstNodes;
38
59
  /**
60
+ * Insert a child node
61
+ *
39
62
  * 插入子节点
40
- * @param node 待插入的子节点
41
- * @param i 插入位置
63
+ * @param node node to be inserted / 待插入的子节点
64
+ * @param i position to be inserted at / 插入位置
42
65
  * @throws `RangeError` 不能插入祖先或子节点
43
66
  */
44
67
  insertAt<T extends AstNodes>(node: T, i?: number): T;
45
68
  /**
46
- * 最近的祖先节点
69
+ * Get the closest ancestor node that matches the selector
70
+ *
71
+ * 最近的符合选择器的祖先节点
47
72
  * @param selector 选择器
48
73
  */
49
74
  closest<T = Token>(selector: string): T | undefined;
50
75
  /**
76
+ * Get the first descendant that matches the selector
77
+ *
51
78
  * 符合选择器的第一个后代节点
52
79
  * @param selector 选择器
53
80
  */
54
81
  querySelector<T = Token>(selector: string): T | undefined;
55
82
  /**
83
+ * Get all descendants that match the selector
84
+ *
56
85
  * 符合选择器的所有后代节点
57
86
  * @param selector 选择器
58
87
  */
59
88
  querySelectorAll<T = Token>(selector: string): T[];
60
89
  /**
90
+ * Insert a batch of child nodes at the end
91
+ *
61
92
  * 在末尾批量插入子节点
62
- * @param elements 插入节点
93
+ * @param elements nodes to be inserted / 插入节点
63
94
  */
64
95
  append(...elements: (AstNodes | string)[]): void;
65
96
  /**
97
+ * Replace all child nodes
98
+ *
66
99
  * 批量替换子节点
67
- * @param elements 新的子节点
100
+ * @param elements nodes to be inserted / 新的子节点
68
101
  */
69
102
  replaceChildren(...elements: (AstNodes | string)[]): void;
70
103
  /**
104
+ * Modify the text child node
105
+ *
71
106
  * 修改文本子节点
72
- * @param str 新文本
73
- * @param i 子节点位置
107
+ * @param str new text / 新文本
108
+ * @param i position of the text child node / 子节点位置
74
109
  * @throws `RangeError` 对应位置的子节点不是文本节点
75
110
  */
76
111
  setText(str: string, i?: number): string;
77
112
  /**
113
+ * Get the caret position from the character index
114
+ *
115
+ * 找到给定位置
116
+ * @param index character index / 位置
117
+ */
118
+ caretPositionFromIndex(index?: number): CaretPosition | undefined;
119
+ /**
120
+ * Get the closest ancestor element from the character index
121
+ *
122
+ * 找到给定位置所在的最内层非文本节点
123
+ * @param index character index / 位置
124
+ */
125
+ elementFromIndex(index?: number): Token | undefined;
126
+ /**
127
+ * Get the closest ancestor element from the position
128
+ *
129
+ * 找到给定位置所在的最内层非文本节点
130
+ * @param x column number / 列数
131
+ * @param y line number / 行数
132
+ */
133
+ elementFromPoint(x: number, y: number): Token | undefined;
134
+ /**
135
+ * Save in JSON format
136
+ *
78
137
  * 保存为JSON
79
- * @param file 文件名
138
+ * @param file file name / 文件名
80
139
  * @param start
81
140
  */
82
141
  json(file?: string, start?: number): AST;
83
142
  /**
143
+ * Check if the current element matches the selector
144
+ *
84
145
  * 检查是否符合选择器
85
146
  * @param selector 选择器
86
147
  */
87
148
  matches<T>(selector?: string): this is T;
88
149
  /**
150
+ * Get all descendants of the types
151
+ *
89
152
  * 类型选择器
90
- * @param types
153
+ * @param types token types / 节点类型
91
154
  */
92
155
  getElementByTypes<T = Token>(types: string): T | undefined;
93
156
  /**
157
+ * Get the first descendant with the id
158
+ *
94
159
  * id选择器
95
160
  * @param id id名
96
161
  */
97
162
  getElementById<T = Token>(id: string): T | undefined;
98
163
  /**
164
+ * Get all descendants with the class
165
+ *
99
166
  * 类选择器
100
- * @param className 类名之一
167
+ * @param className class name / 类名之一
101
168
  */
102
169
  getElementsByClassName<T = Token>(className: string): T[];
103
170
  /**
171
+ * Get all descendants with the tag name
172
+ *
104
173
  * 标签名选择器
105
- * @param tag 标签名
174
+ * @param tag tag name / 标签名
106
175
  */
107
176
  getElementsByTagName<T = Token>(tag: string): T[];
108
177
  /**
178
+ * Insert a batch of child nodes at the start
179
+ *
109
180
  * 在开头批量插入子节点
110
- * @param elements 插入节点
181
+ * @param elements nodes to be inserted / 插入节点
111
182
  */
112
183
  prepend(...elements: (AstNodes | string)[]): void;
113
184
  /**
185
+ * Remove a child node
186
+ *
114
187
  * 移除子节点
115
- * @param node 子节点
188
+ * @param node child node to be removed / 子节点
116
189
  */
117
190
  removeChild<T extends AstNodes>(node: T): T;
118
191
  /**
192
+ * Insert a child node before the reference node
193
+ *
119
194
  * 在指定位置前插入子节点
120
- * @param child 插入节点
121
- * @param reference 指定位置处的子节点
195
+ * @param child node to be inserted / 插入节点
196
+ * @param reference reference child node / 指定位置处的子节点
122
197
  */
123
198
  insertBefore(child: string, reference?: AstNodes): AstText;
124
199
  insertBefore<T extends AstNodes>(child: T, reference?: AstNodes): T;
200
+ /**
201
+ * Get the caret position from the point
202
+ *
203
+ * 找到给定位置
204
+ * @param x column number / 列数
205
+ * @param y line number / 行数
206
+ */
207
+ caretPositionFromPoint(x: number, y: number): CaretPosition | undefined;
208
+ /**
209
+ * Get all ancestor elements from the character index
210
+ *
211
+ * 找到给定位置所在的所有节点
212
+ * @param index character index / 位置
213
+ */
214
+ elementsFromIndex(index?: number): Token[];
215
+ /**
216
+ * Get all ancestor elements from the position
217
+ *
218
+ * 找到给定位置所在的所有节点
219
+ * @param x column number / 列数
220
+ * @param y line number / 行数
221
+ */
222
+ elementsFromPoint(x: number, y: number): Token[];
125
223
  }
224
+ export {};