wikiparser-node 1.0.0-beta.4 → 1.0.0-beta.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 (125) hide show
  1. package/README.md +10 -9
  2. package/dist/bin/toc.js +18 -0
  3. package/dist/index.d.ts +0 -4
  4. package/dist/index.js +17 -9
  5. package/dist/internal.d.ts +5 -5
  6. package/dist/lib/element.d.ts +2 -25
  7. package/dist/lib/element.js +16 -31
  8. package/dist/lib/node.d.ts +9 -40
  9. package/dist/lib/node.js +19 -48
  10. package/dist/lib/range.d.ts +9 -2
  11. package/dist/lib/range.js +41 -13
  12. package/dist/lib/ranges.js +2 -4
  13. package/dist/lib/text.d.ts +2 -17
  14. package/dist/lib/text.js +6 -17
  15. package/dist/lib/title.d.ts +0 -14
  16. package/dist/lib/title.js +8 -11
  17. package/dist/mixin/attributesParent.js +0 -1
  18. package/dist/mixin/fixed.js +0 -1
  19. package/dist/mixin/hidden.js +0 -1
  20. package/dist/mixin/singleLine.js +1 -2
  21. package/dist/mixin/sol.js +2 -3
  22. package/dist/mixin/syntax.js +55 -0
  23. package/dist/parser/hrAndDoubleUnderscore.js +4 -4
  24. package/dist/parser/links.js +3 -3
  25. package/dist/parser/selector.js +1 -2
  26. package/dist/parser/table.js +7 -6
  27. package/dist/src/arg.d.ts +7 -27
  28. package/dist/src/arg.js +13 -30
  29. package/dist/src/atom.d.ts +2 -2
  30. package/dist/src/atom.js +5 -4
  31. package/dist/src/attribute.d.ts +15 -36
  32. package/dist/src/attribute.js +21 -50
  33. package/dist/src/attributes.d.ts +7 -19
  34. package/dist/src/attributes.js +12 -18
  35. package/dist/src/converter.d.ts +3 -16
  36. package/dist/src/converter.js +9 -17
  37. package/dist/src/converterFlags.d.ts +7 -31
  38. package/dist/src/converterFlags.js +12 -39
  39. package/dist/src/converterRule.d.ts +3 -16
  40. package/dist/src/converterRule.js +13 -22
  41. package/dist/src/extLink.d.ts +3 -16
  42. package/dist/src/extLink.js +12 -20
  43. package/dist/src/gallery.d.ts +5 -23
  44. package/dist/src/gallery.js +14 -28
  45. package/dist/src/heading.d.ts +16 -27
  46. package/dist/src/heading.js +17 -36
  47. package/dist/src/hidden.d.ts +5 -4
  48. package/dist/src/hidden.js +3 -7
  49. package/dist/src/html.d.ts +16 -31
  50. package/dist/src/html.js +14 -32
  51. package/dist/src/imageParameter.d.ts +9 -29
  52. package/dist/src/imageParameter.js +28 -37
  53. package/dist/src/imagemap.d.ts +10 -32
  54. package/dist/src/imagemap.js +13 -33
  55. package/dist/src/imagemapLink.d.ts +12 -4
  56. package/dist/src/imagemapLink.js +7 -7
  57. package/dist/src/index.d.ts +6 -15
  58. package/dist/src/index.js +52 -87
  59. package/dist/src/link/base.d.ts +4 -19
  60. package/dist/src/link/base.js +20 -28
  61. package/dist/src/link/category.d.ts +1 -2
  62. package/dist/src/link/category.js +3 -3
  63. package/dist/src/link/file.d.ts +5 -23
  64. package/dist/src/link/file.js +9 -29
  65. package/dist/src/link/galleryImage.d.ts +16 -6
  66. package/dist/src/link/galleryImage.js +22 -9
  67. package/dist/src/link/index.d.ts +0 -1
  68. package/dist/src/link/index.js +1 -1
  69. package/dist/src/magicLink.d.ts +23 -8
  70. package/dist/src/magicLink.js +14 -14
  71. package/dist/src/nested.d.ts +2 -7
  72. package/dist/src/nested.js +6 -9
  73. package/dist/src/nowiki/base.d.ts +7 -2
  74. package/dist/src/nowiki/base.js +12 -7
  75. package/dist/src/nowiki/comment.d.ts +12 -21
  76. package/dist/src/nowiki/comment.js +10 -20
  77. package/dist/src/nowiki/dd.d.ts +3 -20
  78. package/dist/src/nowiki/dd.js +7 -36
  79. package/dist/src/nowiki/doubleUnderscore.d.ts +27 -17
  80. package/dist/src/nowiki/doubleUnderscore.js +21 -20
  81. package/dist/src/nowiki/hr.d.ts +17 -9
  82. package/dist/src/nowiki/hr.js +2 -17
  83. package/dist/src/nowiki/index.d.ts +1 -5
  84. package/dist/src/nowiki/index.js +1 -5
  85. package/dist/src/nowiki/list.d.ts +10 -2
  86. package/dist/src/nowiki/list.js +20 -3
  87. package/dist/src/nowiki/listBase.d.ts +29 -0
  88. package/dist/src/nowiki/listBase.js +34 -0
  89. package/dist/src/nowiki/noinclude.d.ts +6 -1
  90. package/dist/src/nowiki/noinclude.js +1 -1
  91. package/dist/src/nowiki/quote.d.ts +16 -14
  92. package/dist/src/nowiki/quote.js +3 -21
  93. package/dist/src/onlyinclude.d.ts +2 -27
  94. package/dist/src/onlyinclude.js +9 -26
  95. package/dist/src/paramTag/index.d.ts +6 -21
  96. package/dist/src/paramTag/index.js +12 -24
  97. package/dist/src/paramTag/inputbox.d.ts +3 -3
  98. package/dist/src/paramTag/inputbox.js +3 -3
  99. package/dist/src/parameter.d.ts +11 -25
  100. package/dist/src/parameter.js +18 -31
  101. package/dist/src/pre.d.ts +2 -3
  102. package/dist/src/pre.js +5 -5
  103. package/dist/src/syntax.d.ts +15 -14
  104. package/dist/src/syntax.js +9 -48
  105. package/dist/src/table/base.d.ts +7 -9
  106. package/dist/src/table/base.js +7 -5
  107. package/dist/src/table/index.d.ts +4 -13
  108. package/dist/src/table/index.js +11 -17
  109. package/dist/src/table/td.d.ts +19 -34
  110. package/dist/src/table/td.js +36 -47
  111. package/dist/src/table/tr.d.ts +0 -2
  112. package/dist/src/table/tr.js +1 -2
  113. package/dist/src/table/trBase.d.ts +2 -10
  114. package/dist/src/table/trBase.js +6 -12
  115. package/dist/src/tagPair/ext.d.ts +8 -7
  116. package/dist/src/tagPair/ext.js +12 -12
  117. package/dist/src/tagPair/include.d.ts +7 -4
  118. package/dist/src/tagPair/include.js +3 -4
  119. package/dist/src/tagPair/index.d.ts +9 -19
  120. package/dist/src/tagPair/index.js +10 -23
  121. package/dist/src/transclude.d.ts +9 -39
  122. package/dist/src/transclude.js +24 -54
  123. package/dist/util/diff.js +4 -3
  124. package/dist/util/string.js +1 -6
  125. package/package.json +11 -10
package/README.md CHANGED
@@ -1,15 +1,16 @@
1
1
  [![npm version](https://badge.fury.io/js/wikiparser-node.svg)](https://www.npmjs.com/package/wikiparser-node)
2
- [![CodeQL](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/github-code-scanning/codeql)
2
+ [![CodeQL](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/codeql.yml/badge.svg)](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/codeql.yml)
3
+ [![CI](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/node.js.yml/badge.svg)](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/node.js.yml)
3
4
 
4
5
  # 简介
5
6
 
6
- wikiparser-node 是一款由 Bhsd 开发的基于 [Node.js](https://nodejs.org/en/) 环境的离线[维基文本](https://www.mediawiki.org/wiki/Wikitext)语法解析器,可以解析绝大部分的维基语法并生成[语法树](https://en.wikipedia.org/wiki/Abstract_syntax_tree),还可以很方便地对语法树进行查询和修改,最后返回修改后的维基文本。
7
+ wikiparser-node 是一款由 Bhsd 开发的基于 [Node.js](https://nodejs.org/) 环境的离线[维基文本](https://www.mediawiki.org/wiki/Wikitext)语法解析器,可以解析几乎全部的维基语法并生成[语法树](https://en.wikipedia.org/wiki/Abstract_syntax_tree),还可以很方便地对语法树进行查询和修改,最后返回修改后的维基文本。
7
8
 
8
9
  # 其他版本
9
10
 
10
- ## Mini
11
+ ## Mini (又名 [wikilint](https://www.npmjs.com/package/wikilint))
11
12
 
12
- 仅保留了解析功能和[语法错误分析](https://github.com/bhsd-harry/wikiparser-node/wiki/AstElement#lint)功能的轻量版本,解析生成的语法树不能修改。这个版本被应用于 [eslint-plugin-wikitext](/bhsd-harry/eslint-plugin-wikitext) 插件。
13
+ 提供了 [CLI](https://en.wikipedia.org/wiki/Command-line_interface),但仅保留了解析功能和语法错误分析功能,解析生成的语法树不能修改。这个版本被应用于 [eslint-plugin-wikitext](https://www.npmjs.com/package/eslint-plugin-wikitext) 插件。
13
14
 
14
15
  ## Browser
15
16
 
@@ -19,16 +20,16 @@ wikiparser-node 是一款由 Bhsd 开发的基于 [Node.js](https://nodejs.org/e
19
20
 
20
21
  ## Node.js
21
22
 
22
- 请根据需要需要安装对应的版本(`latest` 或 `mini`),如:
23
+ 请根据需要需要安装对应的版本(`wikiparser-node` 或 `wikilint`),如:
23
24
 
24
25
  ```sh
25
- npm i wikiparser-node # 默认为latest
26
+ npm i wikiparser-node
26
27
  ```
27
28
 
28
29
 
29
30
 
30
31
  ```sh
31
- npm i wikiparser-node@mini
32
+ npm i wikilint
32
33
  ```
33
34
 
34
35
  ## 浏览器
@@ -45,8 +46,8 @@ npm i wikiparser-node@mini
45
46
  <script src="//unpkg.com/wikiparser-node@browser/bundle/bundle.min.js"></script>
46
47
  ```
47
48
 
48
- 更多浏览器端可用的插件请查阅对应[文档](https://github.com/bhsd-harry/wikiparser-node/wiki/Browser)。
49
+ 更多浏览器端可用的插件请查阅对应文档。
49
50
 
50
51
  # 使用方法
51
52
 
52
- 请查阅 [Wiki](https://github.com/bhsd-harry/wikiparser-node/wiki/Parser)。
53
+ 请查阅 [Wiki](https://github.com/bhsd-harry/wikiparser-node/wiki)。
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { argv: [, , filename] } = process;
6
+ if (!filename) {
7
+ throw new RangeError('请指定文档文件!');
8
+ }
9
+ const fullpath = path.join(__dirname, '..', '..', 'wiki', `${filename}.md`);
10
+ if (!fs.existsSync(fullpath)) {
11
+ throw new RangeError(`文档 ${filename}.md 不存在!`);
12
+ }
13
+ const content = fs.readFileSync(fullpath, 'utf8');
14
+ if (/^- \[[^\]]+\]\(#[^)]+\)$/mu.test(content)) {
15
+ throw new Error(`文档 ${filename}.md 中已包含目录!`);
16
+ }
17
+ const toc = content.split('\n').filter(line => line.startsWith('#')).map(line => line.replace(/^(#+)\s+(\S.*)$/u, (_, { length }, title) => `${'\t'.repeat(length - 1)}- [${title}](#${title.toLowerCase().replaceAll(' ', '-').replaceAll('.', '')})`)).join('\n');
18
+ fs.writeFileSync(fullpath, `<details>\n\t<summary>目录</summary>\n\n${toc}\n</details>\n\n${content}`);
package/dist/index.d.ts CHANGED
@@ -27,15 +27,12 @@ export interface LintError {
27
27
  excerpt: string;
28
28
  }
29
29
  declare interface Parser {
30
- /** @browser */
31
30
  config: string | Config;
32
- /** @browser */
33
31
  i18n?: string | Record<string, string>;
34
32
  conversionTable: Map<string, string>;
35
33
  redirects: Map<string, string>;
36
34
  /**
37
35
  * 规范化页面标题
38
- * @browser
39
36
  * @param title 标题(含或不含命名空间前缀)
40
37
  * @param defaultNs 命名空间
41
38
  * @param include 是否嵌入
@@ -46,7 +43,6 @@ declare interface Parser {
46
43
  normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): Title;
47
44
  /**
48
45
  * 解析wikitext
49
- * @browser
50
46
  * @param include 是否嵌入
51
47
  * @param maxStage 最大解析层级
52
48
  */
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  /* eslint n/exports-style: 0 */
3
3
  const fs = require("fs");
4
4
  const path = require("path");
5
+ const diff_1 = require("./util/diff");
5
6
  /**
6
7
  * 从根路径require
7
8
  * @param file 文件名
@@ -12,6 +13,7 @@ const rootRequire = (file, dir) => require(file.startsWith('/') ? file : `../${f
12
13
  const Parser = {
13
14
  config: 'default',
14
15
  MAX_STAGE: 11,
16
+ /* NOT FOR BROWSER */
15
17
  conversionTable: new Map(),
16
18
  redirects: new Map(),
17
19
  warning: true,
@@ -120,6 +122,7 @@ const Parser = {
120
122
  'imagemap-link': ['image-map-link'],
121
123
  },
122
124
  promises: [Promise.resolve()],
125
+ /* NOT FOR BROWSER END */
123
126
  /** @implements */
124
127
  getConfig() {
125
128
  if (typeof this.config === 'string') {
@@ -149,8 +152,8 @@ const Parser = {
149
152
  if (halfParsed) {
150
153
  return new Title(title, defaultNs, config, decode, selfLink);
151
154
  }
152
- const { Token } = require('./src');
153
- const token = this.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token.firstChild), defaultNs, config, decode, selfLink);
155
+ const { Token } = require('./src/index');
156
+ const token = this.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token), defaultNs, config, decode, selfLink);
154
157
  this.run(() => {
155
158
  for (const key of ['main', 'fragment']) {
156
159
  if (titleObj[key]?.includes('\0')) {
@@ -164,10 +167,10 @@ const Parser = {
164
167
  },
165
168
  /** @implements */
166
169
  parse(wikitext, include, maxStage = Parser.MAX_STAGE, config = Parser.getConfig()) {
167
- const { Token } = require('./src');
170
+ const { Token } = require('./src/index');
168
171
  let token;
169
172
  this.run(() => {
170
- token = new Token(wikitext, config);
173
+ token = new Token(wikitext.replace(/[\0\x7F]/gu, ''), config);
171
174
  try {
172
175
  token.parse(maxStage, include);
173
176
  }
@@ -216,6 +219,7 @@ const Parser = {
216
219
  throw e;
217
220
  }
218
221
  },
222
+ /* NOT FOR BROWSER */
219
223
  /** @implements */
220
224
  warn(msg, ...args) {
221
225
  if (this.warning) {
@@ -243,8 +247,8 @@ const Parser = {
243
247
  }
244
248
  },
245
249
  /** @implements */
246
- clearCache() {
247
- const entries = [
250
+ async clearCache() {
251
+ const promise = (0, diff_1.cmd)('npm', ['run', 'build']), entries = [
248
252
  ...Object.entries(this.classes),
249
253
  ...Object.entries(this.mixins),
250
254
  ...Object.entries(this.parsers),
@@ -255,12 +259,15 @@ const Parser = {
255
259
  }
256
260
  catch { }
257
261
  }
262
+ await promise;
258
263
  for (const [name, filePath] of entries) {
259
264
  if (name in global) {
260
265
  // @ts-expect-error noImplicitAny
261
- global[name] = require(filePath);
266
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
267
+ global[name] = require(filePath)[name];
262
268
  }
263
269
  }
270
+ this.info('已重新加载Parser');
264
271
  },
265
272
  /** @implements */
266
273
  isInterwiki(title, { interwiki } = Parser.getConfig()) {
@@ -278,9 +285,10 @@ const Parser = {
278
285
  const { stage, include, config } = require(`${file}.json`), { Token } = require('./src');
279
286
  this.config = config;
280
287
  return this.run(() => {
281
- const halfParsed = stage < this.MAX_STAGE, token = new Token(wikitext, this.getConfig(), halfParsed);
288
+ const halfParsed = stage < this.MAX_STAGE, token = new Token(halfParsed ? wikitext : wikitext.replace(/[\0\x7F]/gu, ''), this.getConfig());
282
289
  if (halfParsed) {
283
- token.setAttribute('stage', stage).parseOnce(stage, include);
290
+ token.setAttribute('stage', stage);
291
+ token.parseOnce(stage, include);
284
292
  }
285
293
  else {
286
294
  token.parse(undefined, include);
@@ -1,6 +1,6 @@
1
1
  export type { AstNodes, } from './lib/node';
2
2
  export type * from './lib/text';
3
- export type * from './src';
3
+ export type * from './src/index';
4
4
  export type * from './src/onlyinclude';
5
5
  export type * from './src/nowiki/noinclude';
6
6
  export type * from './src/tagPair/include';
@@ -18,10 +18,10 @@ export type * from './src/heading';
18
18
  export type * from './src/html';
19
19
  export type { TdToken } from './src/table/td';
20
20
  export type * from './src/table/tr';
21
- export type * from './src/table';
21
+ export type * from './src/table/index';
22
22
  export type * from './src/nowiki/hr';
23
23
  export type * from './src/nowiki/doubleUnderscore';
24
- export type * from './src/link';
24
+ export type * from './src/link/index';
25
25
  export type * from './src/link/category';
26
26
  export type * from './src/imageParameter';
27
27
  export type * from './src/link/file';
@@ -34,9 +34,9 @@ export type * from './src/nowiki/list';
34
34
  export type * from './src/converterFlags';
35
35
  export type * from './src/converterRule';
36
36
  export type * from './src/converter';
37
- export type * from './src/nowiki';
37
+ export type * from './src/nowiki/index';
38
38
  export type * from './src/pre';
39
- export type * from './src/paramTag';
39
+ export type * from './src/paramTag/index';
40
40
  export type * from './src/paramTag/inputbox';
41
41
  export type * from './src/nested';
42
42
  export type * from './src/gallery';
@@ -4,12 +4,8 @@ import type { AstNodes, AstText, Token } from '../internal';
4
4
  /** 类似HTMLElement */
5
5
  export declare abstract class AstElement extends AstNode {
6
6
  #private;
7
- /** @browser */
8
7
  name?: string;
9
- /**
10
- * 子节点总数
11
- * @browser
12
- */
8
+ /** 子节点总数 */
13
9
  get length(): number;
14
10
  /** 全部非文本子节点 */
15
11
  get children(): Token[];
@@ -36,24 +32,18 @@ export declare abstract class AstElement extends AstNode {
36
32
  constructor();
37
33
  /**
38
34
  * 可见部分
39
- * @browser
40
35
  * @param separator 子节点间的连接符
41
36
  */
42
37
  text(separator?: string): string;
43
- /**
44
- * 合并相邻的文本子节点
45
- * @browser
46
- */
38
+ /** 合并相邻的文本子节点 */
47
39
  normalize(): void;
48
40
  /**
49
41
  * 移除子节点
50
- * @browser
51
42
  * @param i 移除位置
52
43
  */
53
44
  removeAt(i: number): AstNodes;
54
45
  /**
55
46
  * 插入子节点
56
- * @browser
57
47
  * @param node 待插入的子节点
58
48
  * @param i 插入位置
59
49
  * @throws `RangeError` 不能插入祖先节点
@@ -61,46 +51,33 @@ export declare abstract class AstElement extends AstNode {
61
51
  insertAt<T extends AstNodes>(node: T, i?: number): T;
62
52
  /**
63
53
  * 最近的祖先节点
64
- * @browser
65
54
  * @param selector 选择器
66
55
  */
67
56
  closest(selector: string): Token | undefined;
68
57
  /**
69
58
  * 在末尾批量插入子节点
70
- * @browser
71
59
  * @param elements 插入节点
72
60
  */
73
61
  append(...elements: (AstNodes | string)[]): void;
74
62
  /**
75
63
  * 批量替换子节点
76
- * @browser
77
64
  * @param elements 新的子节点
78
65
  */
79
66
  replaceChildren(...elements: (AstNodes | string)[]): void;
80
67
  /**
81
68
  * 修改文本子节点
82
- * @browser
83
69
  * @param str 新文本
84
70
  * @param i 子节点位置
85
71
  * @throws `RangeError` 对应位置的子节点不是文本节点
86
72
  */
87
73
  setText(str: string, i?: number): string;
88
- /**
89
- * 还原为wikitext
90
- * @browser
91
- * @param omit 忽略的节点类型
92
- * @param separator 子节点间的连接符
93
- */
94
- toString(omit?: Set<string>, separator?: string): string;
95
74
  /**
96
75
  * Linter
97
- * @browser
98
76
  * @param start
99
77
  */
100
78
  lint(start?: number): LintError[];
101
79
  /**
102
80
  * 以HTML格式打印
103
- * @browser
104
81
  * @param opt 选项
105
82
  */
106
83
  print(opt?: PrintOpt): string;
@@ -26,6 +26,7 @@ const lintIgnoredExt = new Set([
26
26
  'templatedata',
27
27
  'timeline',
28
28
  ]);
29
+ /* NOT FOR BROWSER */
29
30
  /**
30
31
  * 检查某个下标是否符合表达式
31
32
  * @param str 表达式
@@ -42,17 +43,15 @@ const matchesLang = ({ attributes }, regex) => {
42
43
  const lang = attributes?.['lang'];
43
44
  return typeof lang === 'string' && regex.test(lang);
44
45
  };
46
+ /* NOT FOR BROWSER END */
45
47
  /** 类似HTMLElement */
46
48
  class AstElement extends node_1.AstNode {
47
- /** @browser */
48
49
  name;
49
- /**
50
- * 子节点总数
51
- * @browser
52
- */
50
+ /** 子节点总数 */
53
51
  get length() {
54
52
  return this.childNodes.length;
55
53
  }
54
+ /* NOT FOR BROWSER */
56
55
  /** 全部非文本子节点 */
57
56
  get children() {
58
57
  return this.childNodes.filter(({ type }) => type !== 'text');
@@ -111,18 +110,15 @@ class AstElement extends node_1.AstNode {
111
110
  super();
112
111
  this.seal('name');
113
112
  }
113
+ /* NOT FOR BROWSER END */
114
114
  /**
115
115
  * 可见部分
116
- * @browser
117
116
  * @param separator 子节点间的连接符
118
117
  */
119
118
  text(separator) {
120
119
  return (0, string_1.text)(this.childNodes, separator);
121
120
  }
122
- /**
123
- * 合并相邻的文本子节点
124
- * @browser
125
- */
121
+ /** 合并相邻的文本子节点 */
126
122
  normalize() {
127
123
  const childNodes = [...this.childNodes];
128
124
  for (let i = childNodes.length - 1; i >= 0; i--) {
@@ -142,7 +138,6 @@ class AstElement extends node_1.AstNode {
142
138
  }
143
139
  /**
144
140
  * 移除子节点
145
- * @browser
146
141
  * @param i 移除位置
147
142
  */
148
143
  removeAt(i) {
@@ -155,7 +150,6 @@ class AstElement extends node_1.AstNode {
155
150
  }
156
151
  /**
157
152
  * 插入子节点
158
- * @browser
159
153
  * @param node 待插入的子节点
160
154
  * @param i 插入位置
161
155
  * @throws `RangeError` 不能插入祖先节点
@@ -181,7 +175,6 @@ class AstElement extends node_1.AstNode {
181
175
  }
182
176
  /**
183
177
  * 最近的祖先节点
184
- * @browser
185
178
  * @param selector 选择器
186
179
  */
187
180
  closest(selector) {
@@ -204,7 +197,6 @@ class AstElement extends node_1.AstNode {
204
197
  }
205
198
  /**
206
199
  * 在末尾批量插入子节点
207
- * @browser
208
200
  * @param elements 插入节点
209
201
  */
210
202
  append(...elements) {
@@ -214,7 +206,6 @@ class AstElement extends node_1.AstNode {
214
206
  }
215
207
  /**
216
208
  * 批量替换子节点
217
- * @browser
218
209
  * @param elements 新的子节点
219
210
  */
220
211
  replaceChildren(...elements) {
@@ -225,7 +216,6 @@ class AstElement extends node_1.AstNode {
225
216
  }
226
217
  /**
227
218
  * 修改文本子节点
228
- * @browser
229
219
  * @param str 新文本
230
220
  * @param i 子节点位置
231
221
  * @throws `RangeError` 对应位置的子节点不是文本节点
@@ -240,12 +230,7 @@ class AstElement extends node_1.AstNode {
240
230
  }
241
231
  throw new RangeError(`第 ${i} 个子节点是 ${name}!`);
242
232
  }
243
- /**
244
- * 还原为wikitext
245
- * @browser
246
- * @param omit 忽略的节点类型
247
- * @param separator 子节点间的连接符
248
- */
233
+ /** @private */
249
234
  toString(omit, separator = '') {
250
235
  return omit && this.matchesTypes(omit)
251
236
  ? ''
@@ -253,7 +238,6 @@ class AstElement extends node_1.AstNode {
253
238
  }
254
239
  /**
255
240
  * Linter
256
- * @browser
257
241
  * @param start
258
242
  */
259
243
  lint(start = this.getAbsoluteIndex()) {
@@ -270,18 +254,18 @@ class AstElement extends node_1.AstNode {
270
254
  }
271
255
  return errors;
272
256
  }
273
- /** @private */
274
- matchesTypes(types) {
275
- return types.has(this.type);
276
- }
277
257
  /**
278
258
  * 以HTML格式打印
279
- * @browser
280
259
  * @param opt 选项
281
260
  */
282
261
  print(opt = {}) {
283
262
  return String(this) ? `<span class="wpb-${opt.class ?? this.type}">${(0, string_1.print)(this.childNodes, opt)}</span>` : '';
284
263
  }
264
+ /* NOT FOR BROWSER */
265
+ /** @private */
266
+ matchesTypes(types) {
267
+ return types.has(this.type);
268
+ }
285
269
  /**
286
270
  * 保存为JSON
287
271
  * @param file 文件名
@@ -476,8 +460,9 @@ class AstElement extends node_1.AstNode {
476
460
  if (!parentNode) {
477
461
  return false;
478
462
  }
479
- const { children } = parentNode, i = children.indexOf(this);
480
- return children.slice(0, i).some(child => child.#matchesArray(condition));
463
+ const { children } = parentNode;
464
+ return children.slice(0, children.indexOf(this))
465
+ .some(child => child.#matchesArray(condition));
481
466
  }
482
467
  default: // ' '
483
468
  return this.getAncestors().some(ancestor => ancestor.#matchesArray(condition));
@@ -650,7 +635,7 @@ class AstElement extends node_1.AstNode {
650
635
  for (let j = 0; j < length; j++) {
651
636
  const child = childNodes[j], childStr = String(child), gap = j === length - 1 ? 0 : this.getGaps(j);
652
637
  if (!childStr) {
653
- // pass
638
+ //
654
639
  }
655
640
  else if (child.type === 'text') {
656
641
  console.log(`${indent} ${(0, string_1.noWrap)(child.data)}`);
@@ -16,44 +16,21 @@ export interface CaretPosition {
16
16
  /** 类似Node */
17
17
  export declare abstract class AstNode {
18
18
  #private;
19
- /** @browser */
20
19
  type: TokenTypes | 'text';
21
- /** @browser */
22
20
  readonly childNodes: AstNodes[];
23
- /**
24
- * 首位子节点
25
- * @browser
26
- */
21
+ /** 首位子节点 */
27
22
  get firstChild(): AstNodes | undefined;
28
- /**
29
- * 末位子节点
30
- * @browser
31
- */
23
+ /** 末位子节点 */
32
24
  get lastChild(): AstNodes | undefined;
33
- /**
34
- * 父节点
35
- * @browser
36
- */
25
+ /** 父节点 */
37
26
  get parentNode(): Token | undefined;
38
- /**
39
- * 后一个兄弟节点
40
- * @browser
41
- */
27
+ /** 后一个兄弟节点 */
42
28
  get nextSibling(): AstNodes | undefined;
43
- /**
44
- * 前一个兄弟节点
45
- * @browser
46
- */
29
+ /** 前一个兄弟节点 */
47
30
  get previousSibling(): AstNodes | undefined;
48
- /**
49
- * 行数
50
- * @browser
51
- */
31
+ /** 行数 */
52
32
  get offsetHeight(): number;
53
- /**
54
- * 最后一行的列数
55
- * @browser
56
- */
33
+ /** 最后一行的列数 */
57
34
  get offsetWidth(): number;
58
35
  /** 后一个非文本兄弟节点 */
59
36
  get nextElementSibling(): Token | undefined;
@@ -74,27 +51,19 @@ export declare abstract class AstNode {
74
51
  padding: number;
75
52
  };
76
53
  constructor();
77
- /**
78
- * 获取根节点
79
- * @browser
80
- */
54
+ /** 获取根节点 */
81
55
  getRootNode(): Token | this;
82
56
  /**
83
57
  * 将字符位置转换为行列号
84
- * @browser
85
58
  * @param index 字符位置
86
59
  */
87
60
  posFromIndex(index: number): Position | undefined;
88
61
  /**
89
62
  * 获取当前节点的相对字符位置,或其第`j`个子节点的相对字符位置
90
- * @browser
91
63
  * @param j 子节点序号
92
64
  */
93
65
  getRelativeIndex(j?: number): number;
94
- /**
95
- * 获取当前节点的绝对位置
96
- * @browser
97
- */
66
+ /** 获取当前节点的绝对位置 */
98
67
  getAbsoluteIndex(): number;
99
68
  /**
100
69
  * 是否是全同节点