wikilint 2.9.2 → 2.10.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.
Files changed (114) hide show
  1. package/config/.schema.json +5 -0
  2. package/config/enwiki.json +2 -1
  3. package/config/llwiki.json +2 -1
  4. package/config/moegirl.json +2 -1
  5. package/config/zhwiki.json +2 -1
  6. package/dist/base.d.ts +11 -4
  7. package/dist/index.js +3 -4
  8. package/dist/lib/element.js +13 -13
  9. package/dist/lib/node.d.ts +9 -1
  10. package/dist/lib/node.js +7 -0
  11. package/dist/lib/text.d.ts +1 -3
  12. package/dist/lib/text.js +8 -6
  13. package/dist/mixin/hidden.d.ts +1 -0
  14. package/dist/mixin/hidden.js +2 -2
  15. package/dist/parser/list.js +8 -6
  16. package/dist/parser/table.js +5 -5
  17. package/dist/src/arg.d.ts +1 -1
  18. package/dist/src/arg.js +5 -3
  19. package/dist/src/atom.d.ts +5 -2
  20. package/dist/src/atom.js +25 -1
  21. package/dist/src/attribute.d.ts +1 -1
  22. package/dist/src/attribute.js +13 -25
  23. package/dist/src/attributes.d.ts +2 -1
  24. package/dist/src/attributes.js +6 -2
  25. package/dist/src/converter.d.ts +2 -2
  26. package/dist/src/converter.js +7 -4
  27. package/dist/src/converterFlags.d.ts +1 -1
  28. package/dist/src/converterFlags.js +5 -3
  29. package/dist/src/converterRule.d.ts +1 -1
  30. package/dist/src/converterRule.js +12 -14
  31. package/dist/src/extLink.d.ts +1 -1
  32. package/dist/src/extLink.js +6 -4
  33. package/dist/src/gallery.d.ts +1 -1
  34. package/dist/src/gallery.js +7 -5
  35. package/dist/src/heading.d.ts +1 -1
  36. package/dist/src/heading.js +7 -4
  37. package/dist/src/hidden.d.ts +1 -1
  38. package/dist/src/hidden.js +4 -2
  39. package/dist/src/html.d.ts +1 -1
  40. package/dist/src/html.js +5 -3
  41. package/dist/src/imageParameter.d.ts +1 -1
  42. package/dist/src/imageParameter.js +5 -3
  43. package/dist/src/imagemap.d.ts +1 -1
  44. package/dist/src/imagemap.js +5 -3
  45. package/dist/src/imagemapLink.d.ts +1 -1
  46. package/dist/src/imagemapLink.js +3 -1
  47. package/dist/src/index.d.ts +2 -1
  48. package/dist/src/index.js +17 -10
  49. package/dist/src/link/base.d.ts +1 -1
  50. package/dist/src/link/base.js +12 -7
  51. package/dist/src/link/category.d.ts +1 -1
  52. package/dist/src/link/category.js +3 -1
  53. package/dist/src/link/file.d.ts +1 -1
  54. package/dist/src/link/file.js +4 -2
  55. package/dist/src/link/galleryImage.d.ts +1 -2
  56. package/dist/src/link/galleryImage.js +7 -13
  57. package/dist/src/link/index.d.ts +1 -1
  58. package/dist/src/link/index.js +3 -1
  59. package/dist/src/link/redirectTarget.d.ts +2 -2
  60. package/dist/src/link/redirectTarget.js +5 -7
  61. package/dist/src/magicLink.d.ts +4 -1
  62. package/dist/src/magicLink.js +42 -54
  63. package/dist/src/nested.d.ts +1 -1
  64. package/dist/src/nested.js +3 -1
  65. package/dist/src/nowiki/base.d.ts +1 -1
  66. package/dist/src/nowiki/comment.d.ts +1 -1
  67. package/dist/src/nowiki/comment.js +6 -4
  68. package/dist/src/nowiki/dd.d.ts +1 -1
  69. package/dist/src/nowiki/dd.js +3 -1
  70. package/dist/src/nowiki/doubleUnderscore.d.ts +1 -1
  71. package/dist/src/nowiki/doubleUnderscore.js +4 -2
  72. package/dist/src/nowiki/hr.d.ts +1 -1
  73. package/dist/src/nowiki/hr.js +3 -1
  74. package/dist/src/nowiki/index.d.ts +1 -1
  75. package/dist/src/nowiki/index.js +3 -1
  76. package/dist/src/nowiki/list.d.ts +1 -1
  77. package/dist/src/nowiki/list.js +3 -1
  78. package/dist/src/nowiki/listBase.d.ts +1 -1
  79. package/dist/src/nowiki/noinclude.d.ts +1 -1
  80. package/dist/src/nowiki/noinclude.js +8 -2
  81. package/dist/src/nowiki/quote.d.ts +1 -1
  82. package/dist/src/nowiki/quote.js +3 -1
  83. package/dist/src/onlyinclude.d.ts +1 -1
  84. package/dist/src/onlyinclude.js +5 -3
  85. package/dist/src/paramTag/index.d.ts +1 -1
  86. package/dist/src/paramTag/index.js +5 -3
  87. package/dist/src/parameter.d.ts +1 -2
  88. package/dist/src/parameter.js +14 -11
  89. package/dist/src/pre.d.ts +1 -1
  90. package/dist/src/pre.js +3 -1
  91. package/dist/src/redirect.d.ts +1 -1
  92. package/dist/src/redirect.js +6 -4
  93. package/dist/src/syntax.d.ts +5 -4
  94. package/dist/src/syntax.js +8 -4
  95. package/dist/src/table/base.d.ts +1 -1
  96. package/dist/src/table/index.d.ts +1 -1
  97. package/dist/src/table/index.js +3 -1
  98. package/dist/src/table/td.d.ts +1 -5
  99. package/dist/src/table/td.js +5 -7
  100. package/dist/src/table/tr.d.ts +1 -1
  101. package/dist/src/table/tr.js +3 -1
  102. package/dist/src/table/trBase.d.ts +1 -1
  103. package/dist/src/table/trBase.js +3 -4
  104. package/dist/src/tagPair/ext.d.ts +1 -1
  105. package/dist/src/tagPair/ext.js +7 -3
  106. package/dist/src/tagPair/include.d.ts +1 -1
  107. package/dist/src/tagPair/include.js +8 -2
  108. package/dist/src/tagPair/index.d.ts +1 -1
  109. package/dist/src/tagPair/index.js +3 -3
  110. package/dist/src/transclude.d.ts +1 -1
  111. package/dist/src/transclude.js +19 -15
  112. package/dist/util/lint.js +1 -1
  113. package/errors/README +2 -0
  114. package/package.json +1 -1
@@ -162,6 +162,11 @@
162
162
  "minItems": 2,
163
163
  "maxItems": 2
164
164
  }
165
+ },
166
+ "articlePath": {
167
+ "description": "base URL of internal links",
168
+ "type": "string",
169
+ "pattern": "\\$1"
165
170
  }
166
171
  },
167
172
  "required": [
@@ -409,5 +409,6 @@
409
409
  "redirection": [
410
410
  "#redirect"
411
411
  ],
412
- "variants": []
412
+ "variants": [],
413
+ "articlePath": "/wiki/$1"
413
414
  }
@@ -597,5 +597,6 @@
597
597
  "zh-sg",
598
598
  "zh-my",
599
599
  "zh-mo"
600
- ]
600
+ ],
601
+ "articlePath": "/zh/$1"
601
602
  }
@@ -687,5 +687,6 @@
687
687
  "zh-cn",
688
688
  "zh-tw",
689
689
  "zh-hk"
690
- ]
690
+ ],
691
+ "articlePath": "/$1"
691
692
  }
@@ -805,5 +805,6 @@
805
805
  "zh-sg",
806
806
  "zh-my",
807
807
  "zh-mo"
808
- ]
808
+ ],
809
+ "articlePath": "/wiki/$1"
809
810
  }
package/dist/base.d.ts CHANGED
@@ -38,13 +38,20 @@ export interface LintError {
38
38
  }
39
39
  /** 类似Node */
40
40
  export interface AstNode {
41
- type: string;
42
41
  readonly childNodes: readonly AstNode[];
42
+ /** 节点类型 */
43
+ type: string;
43
44
  /** Linter */
44
45
  lint(): LintError[];
45
46
  }
46
- /** 类似HTMLElement */
47
- interface AstElement extends AstNode {
47
+ /** 所有节点的基类 */
48
+ interface Token extends AstNode {
49
+ readonly name?: string;
50
+ /**
51
+ * 符合选择器的所有后代节点
52
+ * @param selector 选择器
53
+ */
54
+ querySelectorAll<T = Token>(selector: string): T[];
48
55
  }
49
56
  export interface Parser {
50
57
  config: Config | string;
@@ -56,6 +63,6 @@ export interface Parser {
56
63
  * @param include 是否嵌入
57
64
  * @param maxStage 最大解析层级
58
65
  */
59
- parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): AstElement;
66
+ parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): Token;
60
67
  }
61
68
  export {};
package/dist/index.js CHANGED
@@ -11,8 +11,7 @@ const string_1 = require("./util/string");
11
11
  * @param file 文件名
12
12
  * @param dir 子路径
13
13
  */
14
- const rootRequire = (file, dir) => require(file.startsWith('/') ? file : `../${file.includes('/') ? '' : dir}${file}`);
15
- // eslint-disable-next-line @typescript-eslint/no-redeclare
14
+ const rootRequire = (file, dir) => require(path.isAbsolute(file) ? file : path.join('..', file.includes('/') ? '' : dir, file));
16
15
  const Parser = {
17
16
  config: 'default',
18
17
  i18n: undefined,
@@ -20,7 +19,7 @@ const Parser = {
20
19
  /** @implements */
21
20
  getConfig() {
22
21
  if (typeof this.config === 'string') {
23
- this.config = rootRequire(this.config, 'config/');
22
+ this.config = rootRequire(this.config, 'config');
24
23
  return this.getConfig();
25
24
  }
26
25
  return {
@@ -31,7 +30,7 @@ const Parser = {
31
30
  /** @implements */
32
31
  msg(msg, arg = '') {
33
32
  if (typeof this.i18n === 'string') {
34
- this.i18n = rootRequire(this.i18n, 'i18n/');
33
+ this.i18n = rootRequire(this.i18n, 'i18n');
35
34
  return this.msg(msg, arg);
36
35
  }
37
36
  return msg && (this.i18n?.[msg] ?? msg).replace('$1', this.msg(arg));
@@ -4,6 +4,14 @@ exports.AstElement = void 0;
4
4
  const string_1 = require("../util/string");
5
5
  const debug_1 = require("../util/debug");
6
6
  const node_1 = require("./node");
7
+ /**
8
+ * 将选择器转化为类型谓词
9
+ * @param selector 选择器
10
+ */
11
+ const getCondition = (selector) => {
12
+ const types = new Set(selector.split(',').map(str => str.trim()));
13
+ return (({ type }) => types.has(type));
14
+ };
7
15
  /** 类似HTMLElement */
8
16
  class AstElement extends node_1.AstNode {
9
17
  /** 子节点总数 */
@@ -51,20 +59,12 @@ class AstElement extends node_1.AstNode {
51
59
  (0, debug_1.setChildNodes)(this, i, 0, [node]);
52
60
  return node;
53
61
  }
54
- /**
55
- * 将选择器转化为类型谓词
56
- * @param selector 选择器
57
- */
58
- #getCondition(selector) {
59
- const types = new Set(selector.split(',').map(str => str.trim()));
60
- return (({ type }) => types.has(type));
61
- }
62
62
  /**
63
63
  * 最近的祖先节点
64
64
  * @param selector 选择器
65
65
  */
66
66
  closest(selector) {
67
- const condition = this.#getCondition(selector);
67
+ const condition = getCondition(selector);
68
68
  let { parentNode } = this;
69
69
  while (parentNode) {
70
70
  if (condition(parentNode)) {
@@ -98,7 +98,7 @@ class AstElement extends node_1.AstNode {
98
98
  * @param selector 选择器
99
99
  */
100
100
  querySelector(selector) {
101
- const condition = this.#getCondition(selector);
101
+ const condition = getCondition(selector);
102
102
  return this.#getElementBy(condition);
103
103
  }
104
104
  /**
@@ -123,7 +123,7 @@ class AstElement extends node_1.AstNode {
123
123
  * @param selector 选择器
124
124
  */
125
125
  querySelectorAll(selector) {
126
- const condition = this.#getCondition(selector);
126
+ const condition = getCondition(selector);
127
127
  return this.#getElementsBy(condition);
128
128
  }
129
129
  /**
@@ -158,8 +158,8 @@ class AstElement extends node_1.AstNode {
158
158
  return data;
159
159
  }
160
160
  /** @private */
161
- toString(separator = '') {
162
- return this.childNodes.map(String).join(separator);
161
+ toString(skip, separator = '') {
162
+ return this.childNodes.map(child => child.toString(skip)).join(separator);
163
163
  }
164
164
  /** @private */
165
165
  lint(start = this.getAbsoluteIndex(), re) {
@@ -16,9 +16,12 @@ export interface CaretPosition {
16
16
  /** 类似Node */
17
17
  export declare abstract class AstNode implements AstNodeBase {
18
18
  #private;
19
- type: TokenTypes | 'text';
20
19
  data?: string | undefined;
21
20
  readonly childNodes: readonly AstNodes[];
21
+ abstract get type(): TokenTypes | 'text';
22
+ abstract set type(value: TokenTypes | 'text');
23
+ /** 可见部分 */
24
+ text(): string;
22
25
  lint(): LintError[];
23
26
  /** 首位子节点 */
24
27
  get firstChild(): AstNodes | undefined;
@@ -48,4 +51,9 @@ export declare abstract class AstNode implements AstNodeBase {
48
51
  getRelativeIndex(j?: number): number;
49
52
  /** 获取当前节点的绝对位置 */
50
53
  getAbsoluteIndex(): number;
54
+ /**
55
+ * 是否是某种类型的节点
56
+ * @param type 节点类型
57
+ */
58
+ is<T extends Token>(type: string): this is T;
51
59
  }
package/dist/lib/node.js CHANGED
@@ -114,5 +114,12 @@ class AstNode {
114
114
  configurable: true,
115
115
  });
116
116
  }
117
+ /**
118
+ * 是否是某种类型的节点
119
+ * @param type 节点类型
120
+ */
121
+ is(type) {
122
+ return this.type === type;
123
+ }
117
124
  }
118
125
  exports.AstNode = AstNode;
@@ -3,13 +3,11 @@ import type { LintError } from '../base';
3
3
  /** 文本节点 */
4
4
  export declare class AstText extends AstNode {
5
5
  #private;
6
- readonly type = "text";
7
6
  readonly name: undefined;
8
7
  readonly data: string;
8
+ get type(): 'text';
9
9
  /** @param text 包含文本 */
10
10
  constructor(text: string);
11
- /** 可见部分 */
12
- text(): string;
13
11
  /**
14
12
  * 替换字符串
15
13
  * @param text 替换的字符串
package/dist/lib/text.js CHANGED
@@ -45,14 +45,15 @@ const source = String.raw `<\s*(?:/\s*)?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])
45
45
  ];
46
46
  /** 文本节点 */
47
47
  class AstText extends node_1.AstNode {
48
- type = 'text';
49
48
  data = '';
49
+ get type() {
50
+ return 'text';
51
+ }
50
52
  /** @param text 包含文本 */
51
53
  constructor(text) {
52
54
  super();
53
55
  Object.defineProperties(this, {
54
56
  childNodes: { enumerable: false, configurable: false },
55
- type: { enumerable: false, writable: false },
56
57
  data: {
57
58
  value: text,
58
59
  },
@@ -62,12 +63,15 @@ class AstText extends node_1.AstNode {
62
63
  toString() {
63
64
  return this.data;
64
65
  }
65
- /** 可见部分 */
66
+ /** @private */
66
67
  text() {
67
68
  return this.data;
68
69
  }
69
70
  /** @private */
70
71
  lint(start = this.getAbsoluteIndex(), errorRegex) {
72
+ if (errorRegex === false) {
73
+ return [];
74
+ }
71
75
  const { data, parentNode, nextSibling, previousSibling } = this;
72
76
  if (!parentNode) {
73
77
  throw new Error('An isolated text node cannot be linted!');
@@ -107,9 +111,7 @@ class AstText extends node_1.AstNode {
107
111
  || char === '['
108
112
  && type === 'ext-link-text'
109
113
  && (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
110
- || nextType === 'ext'
111
- && nextName === 'nowiki'
112
- && nextSibling.innerText?.includes(']'))) {
114
+ || nextSibling?.is('ext') && nextName === 'nowiki' && nextSibling.innerText?.includes(']'))) {
113
115
  continue;
114
116
  }
115
117
  else if (char === ']' && (index || length > 1)) {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * 解析后不可见的类
3
3
  * @param linter 是否覆写 lint 方法
4
+ * @param html 是否覆写 toHtml 方法
4
5
  * @param constructor 基类
5
6
  * @param _ context
6
7
  */
@@ -5,17 +5,17 @@ const debug_1 = require("../util/debug");
5
5
  /**
6
6
  * 解析后不可见的类
7
7
  * @param linter 是否覆写 lint 方法
8
+ * @param html 是否覆写 toHtml 方法
8
9
  * @param constructor 基类
9
10
  * @param _ context
10
11
  */
11
- const hiddenToken = (linter) => (constructor, _) => {
12
+ const hiddenToken = (linter = true, html = true) => (constructor, _) => {
12
13
  /** 解析后不可见的类 */
13
14
  class AnyHiddenToken extends constructor {
14
15
  /** 没有可见部分 */
15
16
  text() {
16
17
  return '';
17
18
  }
18
- /** @private */
19
19
  lint(start) {
20
20
  // @ts-expect-error private argument
21
21
  return linter ? [] : super.lint(start);
@@ -10,18 +10,20 @@ const dd_1 = require("../src/nowiki/dd");
10
10
  * @param accum
11
11
  */
12
12
  const parseList = (wikitext, config, accum) => {
13
- const mt = /^((?:\0\d+c\x7F)*)([;:*#]+)/u.exec(wikitext);
13
+ const mt = /^((?:\0\d+c\x7F)*)([;:*#]+\s*)/u.exec(wikitext);
14
14
  if (!mt) {
15
15
  return wikitext;
16
16
  }
17
- const [total, comment, prefix] = mt;
18
- let text = `${comment}\0${accum.length}d\x7F${wikitext.slice(total.length)}`, dt = prefix.split(';').length - 1;
19
- // @ts-expect-error abstract class
20
- new list_1.ListToken(prefix, config, accum);
17
+ const [total, comment, prefix] = mt, parts = prefix.split(/(?=;)/u);
18
+ let text = comment + parts.map((_, i) => `\0${accum.length + i}d\x7F`).join('') + wikitext.slice(total.length), dt = parts.length - (parts[0].startsWith(';') ? 0 : 1);
19
+ for (const part of parts) {
20
+ // @ts-expect-error abstract class
21
+ new list_1.ListToken(part, config, accum);
22
+ }
21
23
  if (!dt) {
22
24
  return text;
23
25
  }
24
- const { html: [normalTags] } = config, fullRegex = /:+|-\{|\0\d+[xq]\x7F/gu;
26
+ const { html: [normalTags] } = config, fullRegex = /:+\s*|-\{|\0\d+[xq]\x7F/gu;
25
27
  let regex = fullRegex, ex = regex.exec(text), lt = 0, lb = false, li = false, lc = 0;
26
28
  /**
27
29
  * 创建`DdToken`
@@ -67,8 +67,8 @@ const parseTable = ({ firstChild: { data }, type, name }, config, accum) => {
67
67
  out += `\n${outLine}`;
68
68
  continue;
69
69
  }
70
- // eslint-disable-next-line @stylistic/operator-linebreak
71
- const matches = /^(?:(\|\}|\0\d+!\x7F\}|\0\d+\}\x7F)|(\|-+|\0\d+!\x7F-+|\0\d+-\x7F-*)(?!-)|(!|(?:\||\0\d+!\x7F)\+?))(.*)$/u
70
+ const matches = // eslint-disable-line @stylistic/operator-linebreak
71
+ /^(?:(\|\}|\0\d+!\x7F\}|\0\d+\}\x7F)|(\|-+|\0\d+!\x7F-+|\0\d+-\x7F-*)(?!-)|(!|(?:\||\0\d+!\x7F)\+?))(.*)$/u
72
72
  .exec(line);
73
73
  if (!matches) {
74
74
  push(`\n${outLine}`, top);
@@ -101,19 +101,19 @@ const parseTable = ({ firstChild: { data }, type, name }, config, accum) => {
101
101
  * 创建表格单元格
102
102
  * @param tr 当前表格行
103
103
  */
104
- const createTd = (tr) => {
104
+ const newTd = (tr) => {
105
105
  // @ts-expect-error abstract class
106
106
  const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex, mt?.index), config, accum);
107
107
  tr.insertAt(td);
108
108
  return td;
109
109
  };
110
110
  while (mt) {
111
- createTd(top);
111
+ newTd(top);
112
112
  ({ lastIndex } = regex);
113
113
  [lastSyntax] = mt;
114
114
  mt = regex.exec(attr);
115
115
  }
116
- stack.push(top, createTd(top));
116
+ stack.push(top, newTd(top));
117
117
  }
118
118
  }
119
119
  return out.slice(1);
package/dist/src/arg.d.ts CHANGED
@@ -8,10 +8,10 @@ import type { LintError } from '../base';
8
8
  * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
9
9
  */
10
10
  export declare abstract class ArgToken extends Token {
11
- readonly type = "arg";
12
11
  readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token, ...HiddenToken[]];
13
12
  abstract get firstChild(): AtomToken;
14
13
  abstract get lastChild(): Token;
14
+ get type(): 'arg';
15
15
  /** 预设值 */
16
16
  get default(): string | false;
17
17
  /** @param parts 以'|'分隔的各部分 */
package/dist/src/arg.js CHANGED
@@ -13,7 +13,9 @@ const hidden_1 = require("./hidden");
13
13
  * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
14
14
  */
15
15
  class ArgToken extends index_2.Token {
16
- type = 'arg';
16
+ get type() {
17
+ return 'arg';
18
+ }
17
19
  /** 预设值 */
18
20
  get default() {
19
21
  return this.childNodes[1]?.text() ?? false;
@@ -39,8 +41,8 @@ class ArgToken extends index_2.Token {
39
41
  }
40
42
  }
41
43
  /** @private */
42
- toString() {
43
- return `{{{${super.toString('|')}}}}`;
44
+ toString(skip) {
45
+ return `{{{${super.toString(skip, '|')}}}}`;
44
46
  }
45
47
  /** @private */
46
48
  text() {
@@ -1,9 +1,12 @@
1
1
  import { Token } from './index';
2
2
  import type { Config } from '../base';
3
- declare type AtomTypes = 'arg-name' | 'attr-key' | 'attr-value' | 'ext-attr-dirty' | 'html-attr-dirty' | 'table-attr-dirty' | 'converter-flag' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'invoke-function' | 'invoke-module' | 'template-name' | 'link-target' | 'param-line';
3
+ declare const atomTypes: readonly ["arg-name", "attr-key", "attr-value", "ext-attr-dirty", "html-attr-dirty", "table-attr-dirty", "converter-flag", "converter-rule-variant", "converter-rule-to", "converter-rule-from", "invoke-function", "invoke-module", "template-name", "link-target", "param-line"];
4
+ declare type AtomTypes = typeof atomTypes[number];
4
5
  /** 不会被继续解析的plain Token */
5
6
  export declare class AtomToken extends Token {
6
- type: AtomTypes;
7
+ #private;
8
+ get type(): AtomTypes;
9
+ set type(value: AtomTypes);
7
10
  /** @class */
8
11
  constructor(wikitext: string | undefined, type: AtomTypes, config?: Config, accum?: Token[], acceptable?: Acceptable);
9
12
  }
package/dist/src/atom.js CHANGED
@@ -2,12 +2,36 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AtomToken = void 0;
4
4
  const index_1 = require("./index");
5
+ const atomTypes = [
6
+ 'arg-name',
7
+ 'attr-key',
8
+ 'attr-value',
9
+ 'ext-attr-dirty',
10
+ 'html-attr-dirty',
11
+ 'table-attr-dirty',
12
+ 'converter-flag',
13
+ 'converter-rule-variant',
14
+ 'converter-rule-to',
15
+ 'converter-rule-from',
16
+ 'invoke-function',
17
+ 'invoke-module',
18
+ 'template-name',
19
+ 'link-target',
20
+ 'param-line',
21
+ ];
5
22
  /** 不会被继续解析的plain Token */
6
23
  class AtomToken extends index_1.Token {
24
+ #type;
25
+ get type() {
26
+ return this.#type;
27
+ }
28
+ set type(value) {
29
+ this.#type = value;
30
+ }
7
31
  /** @class */
8
32
  constructor(wikitext, type, config, accum, acceptable) {
9
33
  super(wikitext, config, accum, acceptable);
10
- this.type = type;
34
+ this.#type = type;
11
35
  }
12
36
  }
13
37
  exports.AtomToken = AtomToken;
@@ -10,7 +10,6 @@ export type AttributeTypes = 'ext-attr' | 'html-attr' | 'table-attr';
10
10
  */
11
11
  export declare abstract class AttributeToken extends Token {
12
12
  #private;
13
- type: AttributeTypes;
14
13
  readonly name: string;
15
14
  readonly childNodes: readonly [AtomToken, Token];
16
15
  abstract get firstChild(): AtomToken;
@@ -18,6 +17,7 @@ export declare abstract class AttributeToken extends Token {
18
17
  abstract get parentNode(): AttributesToken | undefined;
19
18
  abstract get nextSibling(): AtomToken | this | undefined;
20
19
  abstract get previousSibling(): AtomToken | this | undefined;
20
+ get type(): AttributeTypes;
21
21
  /** 标签名 */
22
22
  get tag(): string;
23
23
  /** 引号是否匹配 */
@@ -60,7 +60,6 @@ const commonHtmlAttrs = new Set([
60
60
  img: new Set(['alt', 'src', 'width', 'height', 'srcset']),
61
61
  font: new Set(['size', 'color', 'face']),
62
62
  hr: widthAttrs,
63
- rt: new Set(['rbspan']),
64
63
  data: new Set(['value']),
65
64
  time: new Set(['datetime']),
66
65
  meta: new Set(['itemprop', 'content']),
@@ -170,9 +169,13 @@ const commonHtmlAttrs = new Set([
170
169
  * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
171
170
  */
172
171
  class AttributeToken extends index_2.Token {
172
+ #type;
173
173
  #tag;
174
174
  #equal;
175
175
  #quotes;
176
+ get type() {
177
+ return this.#type;
178
+ }
176
179
  /** 标签名 */
177
180
  get tag() {
178
181
  return this.#tag;
@@ -190,23 +193,15 @@ class AttributeToken extends index_2.Token {
190
193
  * @param quotes 引号
191
194
  */
192
195
  constructor(type, tag, key, equal = '', value, quotes = [], config = index_1.default.getConfig(), accum = []) {
193
- const keyToken = new atom_1.AtomToken(key, 'attr-key', config, accum, {});
196
+ const keyToken = new atom_1.AtomToken(key, 'attr-key', config, accum);
194
197
  let valueToken;
195
198
  if (key === 'title' || tag === 'img' && key === 'alt') {
196
199
  valueToken = new index_2.Token(value, config, accum, {});
197
200
  valueToken.type = 'attr-value';
198
201
  valueToken.setAttribute('stage', constants_1.MAX_STAGE - 1);
199
202
  }
200
- else if (tag === 'gallery' && key === 'caption') {
201
- const newConfig = {
202
- ...config,
203
- excludes: [...config.excludes, 'quote', 'extLink', 'magicLink', 'list'],
204
- };
205
- valueToken = new index_2.Token(value, newConfig, accum, {});
206
- valueToken.type = 'attr-value';
207
- valueToken.setAttribute('stage', 5);
208
- }
209
- else if (tag === 'choose' && (key === 'before' || key === 'after')) {
203
+ else if (tag === 'gallery' && key === 'caption'
204
+ || tag === 'choose' && (key === 'before' || key === 'after')) {
210
205
  const newConfig = {
211
206
  ...config,
212
207
  excludes: [...config.excludes, 'heading', 'html', 'table', 'hr', 'list'],
@@ -219,7 +214,7 @@ class AttributeToken extends index_2.Token {
219
214
  valueToken = new atom_1.AtomToken(value, 'attr-value', config, accum, {});
220
215
  }
221
216
  super(undefined, config, accum);
222
- this.type = type;
217
+ this.#type = type;
223
218
  this.append(keyToken, valueToken);
224
219
  this.#equal = equal;
225
220
  this.#quotes = [...quotes];
@@ -234,13 +229,13 @@ class AttributeToken extends index_2.Token {
234
229
  if (this.parentNode) {
235
230
  this.#tag = this.parentNode.name;
236
231
  }
237
- this.setAttribute('name', this.firstChild.text().trim().toLowerCase());
232
+ this.setAttribute('name', this.firstChild.toString(true).trim().toLowerCase());
238
233
  super.afterBuild();
239
234
  }
240
235
  /** @private */
241
- toString() {
236
+ toString(skip) {
242
237
  const [quoteStart = '', quoteEnd = ''] = this.#quotes;
243
- return this.#equal ? super.toString(this.#equal + quoteStart) + quoteEnd : this.firstChild.toString();
238
+ return this.#equal ? super.toString(skip, this.#equal + quoteStart) + quoteEnd : this.firstChild.toString(skip);
244
239
  }
245
240
  /** @private */
246
241
  text() {
@@ -288,7 +283,7 @@ class AttributeToken extends index_2.Token {
288
283
  else if (name === 'style' && typeof value === 'string' && insecureStyle.test(value)) {
289
284
  errors.push((0, lint_1.generateForChild)(lastChild, rect, 'insecure-style', 'insecure style'));
290
285
  }
291
- else if (name === 'tabindex' && typeof value === 'string' && value.trim() !== '0') {
286
+ else if (name === 'tabindex' && typeof value === 'string' && value !== '0') {
292
287
  const e = (0, lint_1.generateForChild)(lastChild, rect, 'illegal-attr', 'nonzero tabindex');
293
288
  e.suggestions = [
294
289
  {
@@ -308,14 +303,7 @@ class AttributeToken extends index_2.Token {
308
303
  }
309
304
  /** 获取属性值 */
310
305
  getValue() {
311
- if (this.#equal) {
312
- const value = this.lastChild.text();
313
- if (this.#quotes[1]) {
314
- return value;
315
- }
316
- return value[this.#quotes[0] ? 'trimEnd' : 'trim']();
317
- }
318
- return this.type === 'ext-attr' || '';
306
+ return this.#equal ? this.lastChild.text().trim() : this.type === 'ext-attr' || '';
319
307
  }
320
308
  }
321
309
  exports.AttributeToken = AttributeToken;
@@ -11,12 +11,13 @@ declare type AttributesTypes = `${AttributeTypes}s`;
11
11
  * @classdesc `{childNodes: ...AtomToken|AttributeToken}`
12
12
  */
13
13
  export declare abstract class AttributesToken extends Token {
14
- type: AttributesTypes;
14
+ #private;
15
15
  readonly name: string;
16
16
  readonly childNodes: readonly (AtomToken | AttributeToken)[];
17
17
  abstract get firstChild(): AtomToken | AttributeToken | undefined;
18
18
  abstract get lastChild(): AtomToken | AttributeToken | undefined;
19
19
  abstract get parentNode(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
20
+ get type(): AttributesTypes;
20
21
  /**
21
22
  * @param attr 标签属性
22
23
  * @param type 标签类型
@@ -24,6 +24,10 @@ const toDirty = (type) => `${toAttributeType(type)}-dirty`;
24
24
  * @classdesc `{childNodes: ...AtomToken|AttributeToken}`
25
25
  */
26
26
  class AttributesToken extends index_2.Token {
27
+ #type;
28
+ get type() {
29
+ return this.#type;
30
+ }
27
31
  /**
28
32
  * @param attr 标签属性
29
33
  * @param type 标签类型
@@ -31,7 +35,7 @@ class AttributesToken extends index_2.Token {
31
35
  */
32
36
  constructor(attr, type, name, config = index_1.default.getConfig(), accum = []) {
33
37
  super(undefined, config, accum, {});
34
- this.type = type;
38
+ this.#type = type;
35
39
  this.setAttribute('name', name);
36
40
  if (attr) {
37
41
  regex.lastIndex = 0;
@@ -119,7 +123,7 @@ class AttributesToken extends index_2.Token {
119
123
  duplicated.add(name);
120
124
  attrs.get(name).push(attr);
121
125
  }
122
- else if (name !== 'class') {
126
+ else {
123
127
  attrs.set(name, [attr]);
124
128
  }
125
129
  }
@@ -7,10 +7,10 @@ import { ConverterRuleToken } from './converterRule';
7
7
  * @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken]}`
8
8
  */
9
9
  export declare abstract class ConverterToken extends Token {
10
- readonly type = "converter";
11
- readonly childNodes: readonly [ConverterFlagsToken, ...ConverterRuleToken[]];
10
+ readonly childNodes: readonly [ConverterFlagsToken, ConverterRuleToken, ...ConverterRuleToken[]];
12
11
  abstract get firstChild(): ConverterFlagsToken;
13
12
  abstract get lastChild(): ConverterFlagsToken | ConverterRuleToken;
13
+ get type(): 'converter';
14
14
  /**
15
15
  * @param flags 转换类型标记
16
16
  * @param rules 转换规则