wikilint 2.0.0-beta.1 → 2.0.0-beta.2

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 (117) hide show
  1. package/README.md +3 -2
  2. package/bin/cli.js +3 -0
  3. package/dist/bin/cli.js +0 -0
  4. package/dist/index.d.ts +0 -4
  5. package/dist/index.js +2 -2
  6. package/dist/internal.d.ts +5 -5
  7. package/dist/lib/element.d.ts +2 -24
  8. package/dist/lib/element.js +4 -24
  9. package/dist/lib/node.d.ts +9 -40
  10. package/dist/lib/node.js +10 -47
  11. package/dist/lib/text.d.ts +2 -17
  12. package/dist/lib/text.js +3 -17
  13. package/dist/lib/title.d.ts +0 -5
  14. package/dist/lib/title.js +1 -6
  15. package/dist/mixin/hidden.js +0 -1
  16. package/dist/parser/hrAndDoubleUnderscore.js +4 -4
  17. package/dist/parser/links.js +3 -3
  18. package/dist/parser/table.js +7 -6
  19. package/dist/src/arg.d.ts +5 -23
  20. package/dist/src/arg.js +13 -25
  21. package/dist/src/atom.d.ts +2 -2
  22. package/dist/src/atom.js +3 -3
  23. package/dist/src/attribute.d.ts +7 -31
  24. package/dist/src/attribute.js +12 -37
  25. package/dist/src/attributes.d.ts +4 -11
  26. package/dist/src/attributes.js +3 -10
  27. package/dist/src/converter.d.ts +2 -12
  28. package/dist/src/converter.js +4 -12
  29. package/dist/src/converterFlags.d.ts +6 -27
  30. package/dist/src/converterFlags.js +8 -28
  31. package/dist/src/converterRule.d.ts +2 -12
  32. package/dist/src/converterRule.js +4 -12
  33. package/dist/src/extLink.d.ts +2 -12
  34. package/dist/src/extLink.js +7 -15
  35. package/dist/src/gallery.d.ts +4 -19
  36. package/dist/src/gallery.js +6 -19
  37. package/dist/src/heading.d.ts +4 -20
  38. package/dist/src/heading.js +11 -28
  39. package/dist/src/hidden.d.ts +1 -4
  40. package/dist/src/hidden.js +2 -3
  41. package/dist/src/html.d.ts +4 -21
  42. package/dist/src/html.js +6 -24
  43. package/dist/src/imageParameter.d.ts +7 -24
  44. package/dist/src/imageParameter.js +12 -28
  45. package/dist/src/imagemap.d.ts +7 -26
  46. package/dist/src/imagemap.js +7 -24
  47. package/dist/src/imagemapLink.d.ts +2 -4
  48. package/dist/src/imagemapLink.js +4 -6
  49. package/dist/src/index.d.ts +1 -11
  50. package/dist/src/index.js +29 -75
  51. package/dist/src/link/base.d.ts +3 -15
  52. package/dist/src/link/base.js +12 -21
  53. package/dist/src/link/category.d.ts +1 -2
  54. package/dist/src/link/category.js +2 -3
  55. package/dist/src/link/file.d.ts +5 -23
  56. package/dist/src/link/file.js +5 -26
  57. package/dist/src/link/galleryImage.d.ts +2 -6
  58. package/dist/src/link/galleryImage.js +5 -9
  59. package/dist/src/link/index.d.ts +0 -1
  60. package/dist/src/link/index.js +0 -1
  61. package/dist/src/magicLink.d.ts +6 -6
  62. package/dist/src/magicLink.js +3 -7
  63. package/dist/src/nested.d.ts +2 -7
  64. package/dist/src/nested.js +4 -11
  65. package/dist/src/nowiki/base.d.ts +4 -1
  66. package/dist/src/nowiki/base.js +7 -2
  67. package/dist/src/nowiki/comment.d.ts +3 -17
  68. package/dist/src/nowiki/comment.js +3 -13
  69. package/dist/src/nowiki/dd.d.ts +3 -4
  70. package/dist/src/nowiki/dd.js +2 -3
  71. package/dist/src/nowiki/doubleUnderscore.d.ts +5 -6
  72. package/dist/src/nowiki/doubleUnderscore.js +9 -5
  73. package/dist/src/nowiki/hr.d.ts +0 -1
  74. package/dist/src/nowiki/hr.js +0 -1
  75. package/dist/src/nowiki/index.d.ts +1 -5
  76. package/dist/src/nowiki/index.js +1 -5
  77. package/dist/src/nowiki/list.d.ts +2 -3
  78. package/dist/src/nowiki/list.js +2 -3
  79. package/dist/src/nowiki/listBase.d.ts +5 -0
  80. package/dist/src/nowiki/listBase.js +9 -0
  81. package/dist/src/nowiki/noinclude.d.ts +0 -3
  82. package/dist/src/nowiki/noinclude.js +0 -1
  83. package/dist/src/nowiki/quote.d.ts +1 -5
  84. package/dist/src/nowiki/quote.js +1 -5
  85. package/dist/src/onlyinclude.d.ts +1 -17
  86. package/dist/src/onlyinclude.js +5 -15
  87. package/dist/src/paramTag/index.d.ts +4 -16
  88. package/dist/src/paramTag/index.js +6 -16
  89. package/dist/src/paramTag/inputbox.d.ts +3 -3
  90. package/dist/src/paramTag/inputbox.js +3 -3
  91. package/dist/src/parameter.d.ts +4 -20
  92. package/dist/src/parameter.js +9 -22
  93. package/dist/src/pre.d.ts +2 -3
  94. package/dist/src/pre.js +3 -4
  95. package/dist/src/syntax.d.ts +2 -6
  96. package/dist/src/syntax.js +4 -10
  97. package/dist/src/table/base.d.ts +2 -3
  98. package/dist/src/table/base.js +3 -4
  99. package/dist/src/table/index.d.ts +3 -12
  100. package/dist/src/table/index.js +2 -11
  101. package/dist/src/table/td.d.ts +4 -20
  102. package/dist/src/table/td.js +8 -22
  103. package/dist/src/table/tr.d.ts +0 -2
  104. package/dist/src/table/tr.js +0 -2
  105. package/dist/src/table/trBase.d.ts +2 -8
  106. package/dist/src/table/trBase.js +2 -8
  107. package/dist/src/tagPair/ext.d.ts +3 -7
  108. package/dist/src/tagPair/ext.js +9 -12
  109. package/dist/src/tagPair/include.d.ts +1 -8
  110. package/dist/src/tagPair/include.js +2 -4
  111. package/dist/src/tagPair/index.d.ts +3 -15
  112. package/dist/src/tagPair/index.js +5 -18
  113. package/dist/src/transclude.d.ts +7 -35
  114. package/dist/src/transclude.js +12 -41
  115. package/dist/util/diff.js +4 -3
  116. package/dist/util/string.js +0 -5
  117. package/package.json +10 -9
package/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  [![npm version](https://badge.fury.io/js/wikilint.svg)](https://www.npmjs.com/package/wikilint)
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
  # wikilint
5
6
  This is a minimal version of [wikiparser-node](https://www.npmjs.com/package/wikiparser-node) customized for [eslint-plugin-wikitext](https://www.npmjs.com/package/eslint-plugin-wikitext).
@@ -7,7 +8,7 @@ This is a minimal version of [wikiparser-node](https://www.npmjs.com/package/wik
7
8
  You can also directly lint Wikitext articles in the command line using this package:
8
9
 
9
10
  ```sh
10
- npx wikilint --config zhwiki --include *.wiki
11
+ npx wikilint --config zhwiki --include --lang zh-hans *.wiki
11
12
  ```
12
13
 
13
14
  ## CLI Options
package/bin/cli.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ require('../dist/bin/cli.js');
package/dist/bin/cli.js CHANGED
File without changes
package/dist/index.d.ts CHANGED
@@ -23,13 +23,10 @@ export interface LintError {
23
23
  endCol: number;
24
24
  }
25
25
  declare interface Parser {
26
- /** @browser */
27
26
  config: string | Config;
28
- /** @browser */
29
27
  i18n?: string | Record<string, string>;
30
28
  /**
31
29
  * 规范化页面标题
32
- * @browser
33
30
  * @param title 标题(含或不含命名空间前缀)
34
31
  * @param defaultNs 命名空间
35
32
  * @param include 是否嵌入
@@ -40,7 +37,6 @@ declare interface Parser {
40
37
  normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): Title;
41
38
  /**
42
39
  * 解析wikitext
43
- * @browser
44
40
  * @param include 是否嵌入
45
41
  * @param maxStage 最大解析层级
46
42
  */
package/dist/index.js CHANGED
@@ -34,13 +34,13 @@ const Parser = {
34
34
  if (halfParsed) {
35
35
  return new Title(title, defaultNs, config, decode, selfLink);
36
36
  }
37
- const { Token } = require('./src');
37
+ const { Token } = require('./src/index');
38
38
  const token = this.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token), defaultNs, config, decode, selfLink);
39
39
  return titleObj;
40
40
  },
41
41
  /** @implements */
42
42
  parse(wikitext, include, maxStage = Parser.MAX_STAGE, config = Parser.getConfig()) {
43
- const { Token } = require('./src');
43
+ const { Token } = require('./src/index');
44
44
  let token;
45
45
  this.run(() => {
46
46
  token = new Token(wikitext.replace(/[\0\x7F]/gu, ''), config);
@@ -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';
@@ -3,33 +3,23 @@ import type { LintError } from '../index';
3
3
  import type { AstNodes, Token } from '../internal';
4
4
  /** 类似HTMLElement */
5
5
  export declare abstract class AstElement extends AstNode {
6
- /** @browser */
7
6
  name?: string;
8
- /**
9
- * 子节点总数
10
- * @browser
11
- */
7
+ /** 子节点总数 */
12
8
  get length(): number;
13
9
  /**
14
10
  * 可见部分
15
- * @browser
16
11
  * @param separator 子节点间的连接符
17
12
  */
18
13
  text(separator?: string): string;
19
- /**
20
- * 合并相邻的文本子节点
21
- * @browser
22
- */
14
+ /** 合并相邻的文本子节点 */
23
15
  normalize(): void;
24
16
  /**
25
17
  * 移除子节点
26
- * @browser
27
18
  * @param i 移除位置
28
19
  */
29
20
  removeAt(i: number): AstNodes;
30
21
  /**
31
22
  * 插入子节点
32
- * @browser
33
23
  * @param node 待插入的子节点
34
24
  * @param i 插入位置
35
25
  * @throws `RangeError` 不能插入祖先节点
@@ -37,40 +27,28 @@ export declare abstract class AstElement extends AstNode {
37
27
  insertAt<T extends AstNodes>(node: T, i?: number): T;
38
28
  /**
39
29
  * 最近的祖先节点
40
- * @browser
41
30
  * @param selector 选择器
42
31
  */
43
32
  closest(selector: string): Token | undefined;
44
33
  /**
45
34
  * 在末尾批量插入子节点
46
- * @browser
47
35
  * @param elements 插入节点
48
36
  */
49
37
  append(...elements: (AstNodes | string)[]): void;
50
38
  /**
51
39
  * 批量替换子节点
52
- * @browser
53
40
  * @param elements 新的子节点
54
41
  */
55
42
  replaceChildren(...elements: (AstNodes | string)[]): void;
56
43
  /**
57
44
  * 修改文本子节点
58
- * @browser
59
45
  * @param str 新文本
60
46
  * @param i 子节点位置
61
47
  * @throws `RangeError` 对应位置的子节点不是文本节点
62
48
  */
63
49
  setText(str: string, i?: number): string;
64
- /**
65
- * 还原为wikitext
66
- * @browser
67
- * @param omit 忽略的节点类型
68
- * @param separator 子节点间的连接符
69
- */
70
- toString(omit?: Set<string>, separator?: string): string;
71
50
  /**
72
51
  * Linter
73
- * @browser
74
52
  * @param start
75
53
  */
76
54
  lint(start?: number): LintError[];
@@ -22,27 +22,19 @@ const lintIgnoredExt = new Set([
22
22
  ]);
23
23
  /** 类似HTMLElement */
24
24
  class AstElement extends node_1.AstNode {
25
- /** @browser */
26
25
  name;
27
- /**
28
- * 子节点总数
29
- * @browser
30
- */
26
+ /** 子节点总数 */
31
27
  get length() {
32
28
  return this.childNodes.length;
33
29
  }
34
30
  /**
35
31
  * 可见部分
36
- * @browser
37
32
  * @param separator 子节点间的连接符
38
33
  */
39
34
  text(separator) {
40
35
  return (0, string_1.text)(this.childNodes, separator);
41
36
  }
42
- /**
43
- * 合并相邻的文本子节点
44
- * @browser
45
- */
37
+ /** 合并相邻的文本子节点 */
46
38
  normalize() {
47
39
  const { childNodes } = this;
48
40
  for (let i = childNodes.length - 1; i >= 0; i--) {
@@ -61,7 +53,6 @@ class AstElement extends node_1.AstNode {
61
53
  }
62
54
  /**
63
55
  * 移除子节点
64
- * @browser
65
56
  * @param i 移除位置
66
57
  */
67
58
  removeAt(i) {
@@ -70,7 +61,6 @@ class AstElement extends node_1.AstNode {
70
61
  }
71
62
  /**
72
63
  * 插入子节点
73
- * @browser
74
64
  * @param node 待插入的子节点
75
65
  * @param i 插入位置
76
66
  * @throws `RangeError` 不能插入祖先节点
@@ -83,7 +73,6 @@ class AstElement extends node_1.AstNode {
83
73
  }
84
74
  /**
85
75
  * 最近的祖先节点
86
- * @browser
87
76
  * @param selector 选择器
88
77
  */
89
78
  closest(selector) {
@@ -101,7 +90,6 @@ class AstElement extends node_1.AstNode {
101
90
  }
102
91
  /**
103
92
  * 在末尾批量插入子节点
104
- * @browser
105
93
  * @param elements 插入节点
106
94
  */
107
95
  append(...elements) {
@@ -111,7 +99,6 @@ class AstElement extends node_1.AstNode {
111
99
  }
112
100
  /**
113
101
  * 批量替换子节点
114
- * @browser
115
102
  * @param elements 新的子节点
116
103
  */
117
104
  replaceChildren(...elements) {
@@ -120,28 +107,21 @@ class AstElement extends node_1.AstNode {
120
107
  }
121
108
  /**
122
109
  * 修改文本子节点
123
- * @browser
124
110
  * @param str 新文本
125
111
  * @param i 子节点位置
126
112
  * @throws `RangeError` 对应位置的子节点不是文本节点
127
113
  */
128
114
  setText(str, i = 0) {
129
- const oldText = this.childNodes[i], { data } = oldText;
115
+ const oldText = this.childNodes.at(i), { data } = oldText;
130
116
  oldText.replaceData(str);
131
117
  return data;
132
118
  }
133
- /**
134
- * 还原为wikitext
135
- * @browser
136
- * @param omit 忽略的节点类型
137
- * @param separator 子节点间的连接符
138
- */
119
+ /** @private */
139
120
  toString(omit, separator = '') {
140
121
  return this.childNodes.map(child => child.toString()).join(separator);
141
122
  }
142
123
  /**
143
124
  * Linter
144
- * @browser
145
125
  * @param start
146
126
  */
147
127
  lint(start = this.getAbsoluteIndex()) {
@@ -16,65 +16,34 @@ 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
- /**
59
- * 获取根节点
60
- * @browser
61
- */
35
+ /** 获取根节点 */
62
36
  getRootNode(): Token | this;
63
37
  /**
64
38
  * 将字符位置转换为行列号
65
- * @browser
66
39
  * @param index 字符位置
67
40
  */
68
41
  posFromIndex(index: number): Position | undefined;
69
42
  /**
70
43
  * 获取当前节点的相对字符位置,或其第`j`个子节点的相对字符位置
71
- * @browser
72
44
  * @param j 子节点序号
73
45
  */
74
46
  getRelativeIndex(j?: number): number;
75
- /**
76
- * 获取当前节点的绝对位置
77
- * @browser
78
- */
47
+ /** 获取当前节点的绝对位置 */
79
48
  getAbsoluteIndex(): number;
80
49
  }
package/dist/lib/node.js CHANGED
@@ -3,60 +3,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AstNode = void 0;
4
4
  /** 类似Node */
5
5
  class AstNode {
6
- /** @browser */
7
6
  type;
8
- /** @browser */
9
7
  childNodes = [];
10
- /** @browser */
11
8
  #parentNode;
12
- /**
13
- * 首位子节点
14
- * @browser
15
- */
9
+ /** 首位子节点 */
16
10
  get firstChild() {
17
11
  return this.childNodes[0];
18
12
  }
19
- /**
20
- * 末位子节点
21
- * @browser
22
- */
13
+ /** 末位子节点 */
23
14
  get lastChild() {
24
15
  return this.childNodes.at(-1);
25
16
  }
26
- /**
27
- * 父节点
28
- * @browser
29
- */
17
+ /** 父节点 */
30
18
  get parentNode() {
31
19
  return this.#parentNode;
32
20
  }
33
- /**
34
- * 后一个兄弟节点
35
- * @browser
36
- */
21
+ /** 后一个兄弟节点 */
37
22
  get nextSibling() {
38
23
  const childNodes = this.#parentNode?.childNodes;
39
24
  return childNodes && childNodes[childNodes.indexOf(this) + 1];
40
25
  }
41
- /**
42
- * 前一个兄弟节点
43
- * @browser
44
- */
26
+ /** 前一个兄弟节点 */
45
27
  get previousSibling() {
46
28
  const childNodes = this.#parentNode?.childNodes;
47
29
  return childNodes && childNodes[childNodes.indexOf(this) - 1];
48
30
  }
49
- /**
50
- * 行数
51
- * @browser
52
- */
31
+ /** 行数 */
53
32
  get offsetHeight() {
54
33
  return this.#getDimension().height;
55
34
  }
56
- /**
57
- * 最后一行的列数
58
- * @browser
59
- */
35
+ /** 最后一行的列数 */
60
36
  get offsetWidth() {
61
37
  return this.#getDimension().width;
62
38
  }
@@ -80,12 +56,8 @@ class AstNode {
80
56
  // @ts-expect-error noImplicitAny
81
57
  this[key] = value;
82
58
  }
83
- return this;
84
59
  }
85
- /**
86
- * 获取根节点
87
- * @browser
88
- */
60
+ /** 获取根节点 */
89
61
  getRootNode() {
90
62
  let { parentNode } = this;
91
63
  while (parentNode?.parentNode) {
@@ -95,7 +67,6 @@ class AstNode {
95
67
  }
96
68
  /**
97
69
  * 将字符位置转换为行列号
98
- * @browser
99
70
  * @param index 字符位置
100
71
  */
101
72
  posFromIndex(index) {
@@ -106,10 +77,7 @@ class AstNode {
106
77
  }
107
78
  return undefined;
108
79
  }
109
- /**
110
- * 获取行数和最后一行的列数
111
- * @browser
112
- */
80
+ /** 获取行数和最后一行的列数 */
113
81
  #getDimension() {
114
82
  const lines = String(this).split('\n');
115
83
  return { height: lines.length, width: lines.at(-1).length };
@@ -119,13 +87,11 @@ class AstNode {
119
87
  return 0;
120
88
  }
121
89
  /** @private */
122
- // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
123
90
  getGaps(i) {
124
91
  return 0;
125
92
  }
126
93
  /**
127
94
  * 获取当前节点的相对字符位置,或其第`j`个子节点的相对字符位置
128
- * @browser
129
95
  * @param j 子节点序号
130
96
  */
131
97
  getRelativeIndex(j) {
@@ -148,10 +114,7 @@ class AstNode {
148
114
  ({ childNodes } = this);
149
115
  return getIndex(j, this);
150
116
  }
151
- /**
152
- * 获取当前节点的绝对位置
153
- * @browser
154
- */
117
+ /** 获取当前节点的绝对位置 */
155
118
  getAbsoluteIndex() {
156
119
  const { parentNode } = this;
157
120
  return parentNode ? parentNode.getAbsoluteIndex() + this.getRelativeIndex() : 0;
@@ -3,35 +3,20 @@ import type { LintError } from '../index';
3
3
  /** 文本节点 */
4
4
  export declare class AstText extends AstNode {
5
5
  #private;
6
- /** @browser */
7
6
  readonly type = "text";
8
7
  name: undefined;
9
- /** @browser */
10
8
  data: string;
11
- /**
12
- * @browser
13
- * @param text 包含文本
14
- */
9
+ /** @param text 包含文本 */
15
10
  constructor(text: string);
16
- /**
17
- * 输出字符串
18
- * @browser
19
- */
20
- toString(): string;
21
- /**
22
- * 可见部分
23
- * @browser
24
- */
11
+ /** 可见部分 */
25
12
  text(): string;
26
13
  /**
27
14
  * Linter
28
- * @browser
29
15
  * @param start
30
16
  */
31
17
  lint(start?: number): LintError[];
32
18
  /**
33
19
  * 替换字符串
34
- * @browser
35
20
  * @param text 替换的字符串
36
21
  */
37
22
  replaceData(text: string): void;
package/dist/lib/text.js CHANGED
@@ -32,35 +32,23 @@ const errorSyntax = /https?:\/\/|\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\
32
32
  ];
33
33
  /** 文本节点 */
34
34
  class AstText extends node_1.AstNode {
35
- /** @browser */
36
35
  type = 'text';
37
- /** @browser */
38
36
  data;
39
- /**
40
- * @browser
41
- * @param text 包含文本
42
- */
37
+ /** @param text 包含文本 */
43
38
  constructor(text) {
44
39
  super();
45
40
  this.data = text;
46
41
  }
47
- /**
48
- * 输出字符串
49
- * @browser
50
- */
42
+ /** @private */
51
43
  toString() {
52
44
  return this.data;
53
45
  }
54
- /**
55
- * 可见部分
56
- * @browser
57
- */
46
+ /** 可见部分 */
58
47
  text() {
59
48
  return this.data;
60
49
  }
61
50
  /**
62
51
  * Linter
63
- * @browser
64
52
  * @param start
65
53
  */
66
54
  lint(start = this.getAbsoluteIndex()) {
@@ -100,7 +88,6 @@ class AstText extends node_1.AstNode {
100
88
  }
101
89
  /**
102
90
  * 修改内容
103
- * @browser
104
91
  * @param text 新内容
105
92
  */
106
93
  #setData(text) {
@@ -108,7 +95,6 @@ class AstText extends node_1.AstNode {
108
95
  }
109
96
  /**
110
97
  * 替换字符串
111
- * @browser
112
98
  * @param text 替换的字符串
113
99
  */
114
100
  replaceData(text) {
@@ -1,16 +1,11 @@
1
1
  import * as Parser from '../index';
2
2
  /** MediaWiki页面标题对象 */
3
3
  export declare class Title {
4
- /** @browser */
5
4
  valid: boolean;
6
- /** @browser */
7
5
  ns: number;
8
- /** @browser */
9
6
  fragment: string | undefined;
10
- /** @browser */
11
7
  encoded: boolean;
12
8
  /**
13
- * @browser
14
9
  * @param title 标题(含或不含命名空间前缀)
15
10
  * @param defaultNs 命名空间
16
11
  * @param decode 是否需要解码
package/dist/lib/title.js CHANGED
@@ -5,16 +5,11 @@ const string_1 = require("../util/string");
5
5
  const Parser = require("../index");
6
6
  /** MediaWiki页面标题对象 */
7
7
  class Title {
8
- /** @browser */
9
8
  valid;
10
- /** @browser */
11
9
  ns;
12
- /** @browser */
13
10
  fragment;
14
- /** @browser */
15
11
  encoded = false;
16
12
  /**
17
- * @browser
18
13
  * @param title 标题(含或不含命名空间前缀)
19
14
  * @param defaultNs 命名空间
20
15
  * @param decode 是否需要解码
@@ -22,7 +17,7 @@ class Title {
22
17
  */
23
18
  constructor(title, defaultNs = 0, config = Parser.getConfig(), decode = false, selfLink = false) {
24
19
  const { namespaces, nsid } = config;
25
- let namespace = namespaces[defaultNs];
20
+ let namespace = namespaces[defaultNs] ?? '';
26
21
  title = (0, string_1.decodeHtml)(title);
27
22
  if (decode && title.includes('%')) {
28
23
  try {
@@ -5,7 +5,6 @@ exports.hidden = void 0;
5
5
  * 解析后不可见的类
6
6
  * @param constructor 基类
7
7
  */
8
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
9
8
  const hidden = (constructor) => {
10
9
  /** 解析后不可见的类 */
11
10
  class AnyHiddenToken extends constructor {
@@ -11,9 +11,8 @@ const heading_1 = require("../src/heading");
11
11
  * @param config
12
12
  * @param accum
13
13
  */
14
- const parseHrAndDoubleUnderscore = ({ firstChild, type, name }, config = Parser.getConfig(), accum = []) => {
14
+ const parseHrAndDoubleUnderscore = ({ firstChild: { data }, type, name }, config = Parser.getConfig(), accum = []) => {
15
15
  const { doubleUnderscore } = config, insensitive = new Set(doubleUnderscore[0]), sensitive = new Set(doubleUnderscore[1]);
16
- let { data } = firstChild;
17
16
  if (type !== 'root' && (type !== 'ext-inner' || name !== 'poem')) {
18
17
  data = `\0${data}`;
19
18
  }
@@ -21,8 +20,9 @@ const parseHrAndDoubleUnderscore = ({ firstChild, type, name }, config = Parser.
21
20
  new hr_1.HrToken(m, config, accum);
22
21
  return `${lead}\0${accum.length - 1}r\x7F`;
23
22
  }).replace(new RegExp(`__(${doubleUnderscore.flat().join('|')})__`, 'giu'), (m, p1) => {
24
- if (insensitive.has(p1.toLowerCase()) || sensitive.has(p1)) {
25
- new doubleUnderscore_1.DoubleUnderscoreToken(p1, config, accum);
23
+ const fixed = sensitive.has(p1);
24
+ if (fixed || insensitive.has(p1.toLowerCase())) {
25
+ new doubleUnderscore_1.DoubleUnderscoreToken(p1, fixed, config, accum);
26
26
  return `\0${accum.length - 1}u\x7F`;
27
27
  }
28
28
  return m;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseLinks = void 0;
4
4
  const Parser = require("../index");
5
- const link_1 = require("../src/link");
5
+ const index_1 = require("../src/link/index");
6
6
  const file_1 = require("../src/link/file");
7
7
  const category_1 = require("../src/link/category");
8
8
  /**
@@ -12,7 +12,7 @@ const category_1 = require("../src/link/category");
12
12
  * @param accum
13
13
  */
14
14
  const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
15
- const { parseQuotes } = require('./quotes.js');
15
+ const { parseQuotes } = require('./quotes');
16
16
  const regex = /^((?:(?!\0\d+!\x7F)[^\n<>[\]{}|])+)(?:(\||\0\d+!\x7F)(.*?[^\]]))?\]\](.*)$/su, regexImg = /^((?:(?!\0\d+!\x7F)[^\n<>[\]{}|])+)(\||\0\d+!\x7F)(.*)$/su, regexExt = new RegExp(`^\\s*(?:${config.protocol})`, 'iu'), bits = wikitext.split('[[');
17
17
  let s = bits.shift();
18
18
  for (let i = 0; i < bits.length; i++) {
@@ -76,7 +76,7 @@ const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
76
76
  }
77
77
  text &&= parseQuotes(text, config, accum);
78
78
  s += `\0${accum.length}l\x7F${after}`;
79
- let SomeLinkToken = link_1.LinkToken;
79
+ let SomeLinkToken = index_1.LinkToken;
80
80
  if (!force) {
81
81
  if (ns === 6) {
82
82
  SomeLinkToken = file_1.FileToken;