wikiparser-node 1.0.0-beta.2 → 1.0.0-beta.4

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 (127) hide show
  1. package/config/minimum.json +136 -0
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +4 -4
  4. package/dist/internal.d.ts +1 -1
  5. package/dist/lib/element.d.ts +12 -8
  6. package/dist/lib/element.js +72 -57
  7. package/dist/lib/node.js +4 -5
  8. package/dist/lib/range.js +5 -8
  9. package/dist/lib/ranges.js +2 -2
  10. package/dist/lib/text.d.ts +2 -2
  11. package/dist/lib/text.js +5 -5
  12. package/dist/lib/title.d.ts +3 -2
  13. package/dist/lib/title.js +11 -10
  14. package/dist/mixin/attributesParent.js +2 -2
  15. package/dist/mixin/fixed.js +3 -3
  16. package/dist/mixin/hidden.js +2 -2
  17. package/dist/mixin/singleLine.js +4 -4
  18. package/dist/mixin/sol.js +6 -6
  19. package/dist/parser/braces.js +4 -9
  20. package/dist/parser/commentAndExt.js +24 -18
  21. package/dist/parser/converter.js +8 -7
  22. package/dist/parser/externalLinks.js +3 -4
  23. package/dist/parser/hrAndDoubleUnderscore.js +4 -7
  24. package/dist/parser/html.js +4 -7
  25. package/dist/parser/links.js +4 -5
  26. package/dist/parser/list.js +3 -6
  27. package/dist/parser/magicLinks.js +3 -3
  28. package/dist/parser/quotes.js +4 -5
  29. package/dist/parser/selector.js +4 -7
  30. package/dist/parser/table.js +6 -15
  31. package/dist/src/arg.d.ts +6 -5
  32. package/dist/src/arg.js +31 -27
  33. package/dist/src/atom.d.ts +2 -1
  34. package/dist/src/atom.js +4 -4
  35. package/dist/src/attribute.d.ts +14 -13
  36. package/dist/src/attribute.js +41 -31
  37. package/dist/src/attributes.d.ts +4 -3
  38. package/dist/src/attributes.js +15 -21
  39. package/dist/src/converter.d.ts +4 -3
  40. package/dist/src/converter.js +10 -17
  41. package/dist/src/converterFlags.d.ts +9 -8
  42. package/dist/src/converterFlags.js +14 -15
  43. package/dist/src/converterRule.d.ts +4 -3
  44. package/dist/src/converterRule.js +20 -22
  45. package/dist/src/extLink.d.ts +5 -4
  46. package/dist/src/extLink.js +16 -17
  47. package/dist/src/gallery.d.ts +7 -5
  48. package/dist/src/gallery.js +15 -19
  49. package/dist/src/heading.d.ts +12 -10
  50. package/dist/src/heading.js +17 -18
  51. package/dist/src/hidden.d.ts +4 -3
  52. package/dist/src/hidden.js +4 -4
  53. package/dist/src/html.d.ts +17 -15
  54. package/dist/src/html.js +25 -23
  55. package/dist/src/imageParameter.d.ts +5 -4
  56. package/dist/src/imageParameter.js +22 -23
  57. package/dist/src/imagemap.d.ts +7 -5
  58. package/dist/src/imagemap.js +14 -19
  59. package/dist/src/imagemapLink.d.ts +8 -7
  60. package/dist/src/imagemapLink.js +4 -8
  61. package/dist/src/index.d.ts +2 -1
  62. package/dist/src/index.js +48 -46
  63. package/dist/src/link/base.d.ts +5 -4
  64. package/dist/src/link/base.js +26 -28
  65. package/dist/src/link/category.d.ts +1 -1
  66. package/dist/src/link/category.js +3 -2
  67. package/dist/src/link/file.d.ts +5 -4
  68. package/dist/src/link/file.js +22 -20
  69. package/dist/src/link/galleryImage.d.ts +5 -5
  70. package/dist/src/link/galleryImage.js +11 -10
  71. package/dist/src/link/index.d.ts +1 -1
  72. package/dist/src/link/index.js +8 -6
  73. package/dist/src/magicLink.d.ts +3 -2
  74. package/dist/src/magicLink.js +10 -11
  75. package/dist/src/nested.d.ts +4 -2
  76. package/dist/src/nested.js +5 -9
  77. package/dist/src/nowiki/base.d.ts +6 -5
  78. package/dist/src/nowiki/base.js +4 -4
  79. package/dist/src/nowiki/comment.d.ts +6 -5
  80. package/dist/src/nowiki/comment.js +8 -10
  81. package/dist/src/nowiki/dd.d.ts +1 -1
  82. package/dist/src/nowiki/dd.js +3 -2
  83. package/dist/src/nowiki/doubleUnderscore.d.ts +8 -6
  84. package/dist/src/nowiki/doubleUnderscore.js +13 -13
  85. package/dist/src/nowiki/hr.d.ts +2 -8
  86. package/dist/src/nowiki/hr.js +4 -11
  87. package/dist/src/nowiki/index.d.ts +2 -1
  88. package/dist/src/nowiki/index.js +6 -5
  89. package/dist/src/nowiki/list.d.ts +4 -4
  90. package/dist/src/nowiki/list.js +3 -2
  91. package/dist/src/nowiki/noinclude.d.ts +2 -2
  92. package/dist/src/nowiki/noinclude.js +3 -2
  93. package/dist/src/nowiki/quote.d.ts +1 -8
  94. package/dist/src/nowiki/quote.js +25 -17
  95. package/dist/src/onlyinclude.d.ts +5 -4
  96. package/dist/src/onlyinclude.js +13 -13
  97. package/dist/src/paramTag/index.d.ts +5 -3
  98. package/dist/src/paramTag/index.js +7 -7
  99. package/dist/src/paramTag/inputbox.d.ts +3 -2
  100. package/dist/src/paramTag/inputbox.js +6 -5
  101. package/dist/src/parameter.d.ts +11 -10
  102. package/dist/src/parameter.js +29 -30
  103. package/dist/src/pre.d.ts +4 -2
  104. package/dist/src/pre.js +19 -14
  105. package/dist/src/syntax.d.ts +2 -1
  106. package/dist/src/syntax.js +7 -7
  107. package/dist/src/table/base.d.ts +6 -5
  108. package/dist/src/table/base.js +6 -8
  109. package/dist/src/table/index.d.ts +9 -8
  110. package/dist/src/table/index.js +23 -24
  111. package/dist/src/table/td.d.ts +12 -10
  112. package/dist/src/table/td.js +19 -20
  113. package/dist/src/table/tr.d.ts +3 -2
  114. package/dist/src/table/tr.js +4 -3
  115. package/dist/src/table/trBase.d.ts +3 -3
  116. package/dist/src/table/trBase.js +10 -10
  117. package/dist/src/tagPair/ext.d.ts +7 -6
  118. package/dist/src/tagPair/ext.js +5 -17
  119. package/dist/src/tagPair/include.d.ts +5 -5
  120. package/dist/src/tagPair/include.js +4 -5
  121. package/dist/src/tagPair/index.d.ts +7 -7
  122. package/dist/src/tagPair/index.js +13 -19
  123. package/dist/src/transclude.d.ts +10 -9
  124. package/dist/src/transclude.js +41 -46
  125. package/dist/util/lint.js +14 -4
  126. package/dist/util/string.js +21 -20
  127. package/package.json +11 -9
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseTable = void 0;
4
- const index_1 = require("../index");
4
+ const Parser = require("../index");
5
5
  const src_1 = require("../src");
6
6
  const table_1 = require("../src/table");
7
7
  const tr_1 = require("../src/table/tr");
@@ -13,7 +13,7 @@ const dd_1 = require("../src/nowiki/dd");
13
13
  * @param config
14
14
  * @param accum
15
15
  */
16
- const parseTable = ({ firstChild: { data }, type, name }, config = index_1.default.getConfig(), accum = []) => {
16
+ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getConfig(), accum = []) => {
17
17
  const stack = [], lines = data.split('\n');
18
18
  let out = type === 'root' || type === 'parameter-value' || type === 'ext-inner' && name === 'poem'
19
19
  ? ''
@@ -48,13 +48,10 @@ const parseTable = ({ firstChild: { data }, type, name }, config = index_1.defau
48
48
  }
49
49
  const [, indent, moreSpaces, tableSyntax, attr] = matchesStart;
50
50
  if (indent) {
51
- // @ts-expect-error abstract class
52
51
  new dd_1.DdToken(indent, config, accum);
53
52
  }
54
53
  push(`\n${spaces}${indent && `\0${accum.length - 1}d\x7F`}${moreSpaces}\0${accum.length}b\x7F`, top);
55
- // @ts-expect-error abstract class
56
- const table = new table_1.TableToken(tableSyntax, attr, config, accum);
57
- stack.push(...top ? [top] : [], table);
54
+ stack.push(...top ? [top] : [], new table_1.TableToken(tableSyntax, attr, config, accum));
58
55
  continue;
59
56
  }
60
57
  else if (!top) {
@@ -84,7 +81,6 @@ const parseTable = ({ firstChild: { data }, type, name }, config = index_1.defau
84
81
  if (top.type === 'tr') {
85
82
  top = stack.pop();
86
83
  }
87
- // @ts-expect-error abstract class
88
84
  const tr = new tr_1.TrToken(`\n${spaces}${row}`, attr, config, accum);
89
85
  stack.push(top, tr);
90
86
  top.insertAt(tr);
@@ -93,19 +89,14 @@ const parseTable = ({ firstChild: { data }, type, name }, config = index_1.defau
93
89
  if (top.type === 'td') {
94
90
  top = stack.pop();
95
91
  }
96
- const regex = cell === '!'
97
- ? /!!|(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu
98
- : /(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu;
92
+ const regex = cell === '!' ? /!!|(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu : /(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu;
99
93
  let mt = regex.exec(attr), lastIndex = 0, lastSyntax = `\n${spaces}${cell}`;
100
94
  while (mt) {
101
- // @ts-expect-error abstract class
102
- const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex, mt.index), config, accum);
103
- top.insertAt(td);
95
+ top.insertAt(new td_1.TdToken(lastSyntax, attr.slice(lastIndex, mt.index), config, accum));
104
96
  ({ lastIndex } = regex);
105
97
  [lastSyntax] = mt;
106
98
  mt = regex.exec(attr);
107
99
  }
108
- // @ts-expect-error abstract class
109
100
  const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex), config, accum);
110
101
  stack.push(top, td);
111
102
  top.insertAt(td);
@@ -114,4 +105,4 @@ const parseTable = ({ firstChild: { data }, type, name }, config = index_1.defau
114
105
  return out.slice(1);
115
106
  };
116
107
  exports.parseTable = parseTable;
117
- index_1.default.parsers['parseTable'] = __filename;
108
+ Parser.parsers['parseTable'] = __filename;
package/dist/src/arg.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as Parser from '../index';
1
2
  import { Token } from '.';
2
3
  import { AtomToken } from './atom';
3
4
  import { HiddenToken } from './hidden';
@@ -6,7 +7,7 @@ import type { LintError } from '../index';
6
7
  * `{{{}}}`包裹的参数
7
8
  * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
8
9
  */
9
- export declare abstract class ArgToken extends Token {
10
+ export declare class ArgToken extends Token {
10
11
  /** @browser */
11
12
  readonly type = "arg";
12
13
  name: string;
@@ -24,12 +25,12 @@ export declare abstract class ArgToken extends Token {
24
25
  * @browser
25
26
  * @param parts 以'|'分隔的各部分
26
27
  */
27
- constructor(parts: string[], config?: import("../index").Config, accum?: Token[]);
28
+ constructor(parts: string[], config?: Parser.Config, accum?: Token[]);
28
29
  /**
29
30
  * @override
30
31
  * @browser
31
32
  */
32
- toString(selector?: string): string;
33
+ toString(omit?: Set<string>): string;
33
34
  /**
34
35
  * @override
35
36
  * @browser
@@ -39,12 +40,12 @@ export declare abstract class ArgToken extends Token {
39
40
  * @override
40
41
  * @browser
41
42
  */
42
- print(): string;
43
+ lint(start?: number): LintError[];
43
44
  /**
44
45
  * @override
45
46
  * @browser
46
47
  */
47
- lint(start?: number): LintError[];
48
+ print(): string;
48
49
  /** @override */
49
50
  cloneNode(): this;
50
51
  /** 移除无效部分 */
package/dist/src/arg.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ArgToken = void 0;
4
4
  const string_1 = require("../util/string");
5
5
  const lint_1 = require("../util/lint");
6
- const index_1 = require("../index");
6
+ const Parser = require("../index");
7
7
  const _1 = require(".");
8
8
  const atom_1 = require("./atom");
9
9
  const hidden_1 = require("./hidden");
@@ -25,7 +25,7 @@ class ArgToken extends _1.Token {
25
25
  * @browser
26
26
  * @param parts 以'|'分隔的各部分
27
27
  */
28
- constructor(parts, config = index_1.default.getConfig(), accum = []) {
28
+ constructor(parts, config = Parser.getConfig(), accum = []) {
29
29
  super(undefined, config, true, accum, {
30
30
  AtomToken: 0, Token: 1, HiddenToken: '2:',
31
31
  });
@@ -54,8 +54,8 @@ class ArgToken extends _1.Token {
54
54
  * @override
55
55
  * @browser
56
56
  */
57
- toString(selector) {
58
- return selector && this.matches(selector) ? '' : `{{{${super.toString(selector, '|')}}}}`;
57
+ toString(omit) {
58
+ return omit && this.matchesTypes(omit) ? '' : `{{{${super.toString(omit, '|')}}}}`;
59
59
  }
60
60
  /**
61
61
  * @override
@@ -72,13 +72,6 @@ class ArgToken extends _1.Token {
72
72
  getGaps(i) {
73
73
  return i < this.length - 1 ? 1 : 0;
74
74
  }
75
- /**
76
- * @override
77
- * @browser
78
- */
79
- print() {
80
- return super.print({ pre: '{{{', post: '}}}', sep: '|' });
81
- }
82
75
  /**
83
76
  * @override
84
77
  * @browser
@@ -94,17 +87,28 @@ class ArgToken extends _1.Token {
94
87
  if (rest.length > 0) {
95
88
  const rect = { start, ...this.getRootNode().posFromIndex(start) };
96
89
  errors.push(...rest.map(child => {
97
- const error = (0, lint_1.generateForChild)(child, rect, 'invisible content inside triple braces'), { startIndex, startCol, excerpt } = error;
98
- return { ...error, startIndex: startIndex - 1, startCol: startCol - 1, excerpt: `|${excerpt}` };
90
+ const error = (0, lint_1.generateForChild)(child, rect, 'invisible content inside triple braces'), { startIndex, startCol, excerpt, } = error;
91
+ return {
92
+ ...error,
93
+ startIndex: startIndex - 1,
94
+ startCol: startCol - 1,
95
+ excerpt: `|${excerpt}`,
96
+ };
99
97
  }));
100
98
  }
101
99
  return errors;
102
100
  }
101
+ /**
102
+ * @override
103
+ * @browser
104
+ */
105
+ print() {
106
+ return super.print({ pre: '{{{', post: '}}}', sep: '|' });
107
+ }
103
108
  /** @override */
104
109
  cloneNode() {
105
110
  const [name, ...cloned] = this.cloneChildNodes();
106
- return index_1.default.run(() => {
107
- // @ts-expect-error abstract class
111
+ return Parser.run(() => {
108
112
  const token = new ArgToken([''], this.getAttribute('config'));
109
113
  token.firstChild.safeReplaceWith(name);
110
114
  token.append(...cloned);
@@ -124,7 +128,7 @@ class ArgToken extends _1.Token {
124
128
  }
125
129
  /** 移除无效部分 */
126
130
  removeRedundant() {
127
- index_1.default.run(() => {
131
+ Parser.run(() => {
128
132
  for (let i = this.length - 1; i > 1; i--) {
129
133
  super.removeAt(i);
130
134
  }
@@ -148,15 +152,15 @@ class ArgToken extends _1.Token {
148
152
  * @throws `TypeError` 不可插入文本节点
149
153
  */
150
154
  insertAt(token, i = this.length) {
151
- const j = i < 0 ? i + this.length : i;
152
- if (j > 1) {
155
+ i += i < 0 ? this.length : 0;
156
+ if (i > 1) {
153
157
  throw new RangeError(`${this.constructor.name}不可插入多余的子节点!`);
154
158
  }
155
159
  else if (typeof token === 'string') {
156
160
  throw new TypeError(`${this.constructor.name}不可插入文本节点!`);
157
161
  }
158
162
  super.insertAt(token, i);
159
- if (j === 1) {
163
+ if (i === 1) {
160
164
  token.type = 'arg-default';
161
165
  }
162
166
  return token;
@@ -167,13 +171,13 @@ class ArgToken extends _1.Token {
167
171
  * @throws `SyntaxError` 非法的参数名
168
172
  */
169
173
  setName(name) {
170
- const root = index_1.default.parse(`{{{${name}}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: arg } = root;
171
- if (length === 1 && arg instanceof ArgToken && arg.length === 1) {
172
- const { firstChild } = arg;
173
- arg.destroy();
174
- this.firstChild.safeReplaceWith(firstChild);
174
+ const root = Parser.parse(`{{{${name}}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: arg } = root;
175
+ if (length !== 1 || !(arg instanceof ArgToken) || arg.length !== 1) {
176
+ throw new SyntaxError(`非法的参数名称:${(0, string_1.noWrap)(name)}`);
175
177
  }
176
- throw new SyntaxError(`非法的参数名称:${(0, string_1.noWrap)(name)}`);
178
+ const { firstChild } = arg;
179
+ arg.destroy();
180
+ this.firstChild.safeReplaceWith(firstChild);
177
181
  }
178
182
  /**
179
183
  * 设置预设值
@@ -181,7 +185,7 @@ class ArgToken extends _1.Token {
181
185
  * @throws `SyntaxError` 非法的参数预设值
182
186
  */
183
187
  setDefault(value) {
184
- const root = index_1.default.parse(`{{{|${value}}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: arg } = root;
188
+ const root = Parser.parse(`{{{|${value}}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: arg } = root;
185
189
  if (length !== 1 || !(arg instanceof ArgToken) || arg.length !== 2) {
186
190
  throw new SyntaxError(`非法的参数预设值:${(0, string_1.noWrap)(value)}`);
187
191
  }
@@ -196,4 +200,4 @@ class ArgToken extends _1.Token {
196
200
  }
197
201
  }
198
202
  exports.ArgToken = ArgToken;
199
- index_1.default.classes['ArgToken'] = __filename;
203
+ Parser.classes['ArgToken'] = __filename;
@@ -1,10 +1,11 @@
1
+ import * as Parser from '../index';
1
2
  import { Token } from '.';
2
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' | 'converter-rule-noconvert' | 'invoke-function' | 'invoke-module' | 'template-name' | 'link-target' | 'param-line';
3
4
  /** 不会被继续解析的plain Token */
4
5
  export declare class AtomToken extends Token {
5
6
  type: AtomTypes;
6
7
  /** @browser */
7
- constructor(wikitext: string | undefined, type: AtomTypes, config?: import("../index").Config, accum?: Token[], acceptable?: Acceptable);
8
+ constructor(wikitext: string | undefined, type: AtomTypes, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
8
9
  /** @override */
9
10
  cloneNode(): this;
10
11
  }
package/dist/src/atom.js CHANGED
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AtomToken = void 0;
4
- const index_1 = require("../index");
4
+ const Parser = require("../index");
5
5
  const _1 = require(".");
6
6
  /** 不会被继续解析的plain Token */
7
7
  class AtomToken extends _1.Token {
8
8
  /** @browser */
9
- constructor(wikitext, type, config = index_1.default.getConfig(), accum = [], acceptable) {
9
+ constructor(wikitext, type, config = Parser.getConfig(), accum = [], acceptable) {
10
10
  super(wikitext, config, true, accum, acceptable);
11
11
  this.type = type;
12
12
  }
13
13
  /** @override */
14
14
  cloneNode() {
15
15
  const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAttribute('acceptable');
16
- return index_1.default.run(() => {
16
+ return Parser.run(() => {
17
17
  const token = new AtomToken(undefined, this.type, config, [], acceptable);
18
18
  token.append(...cloned);
19
19
  return token;
@@ -21,4 +21,4 @@ class AtomToken extends _1.Token {
21
21
  }
22
22
  }
23
23
  exports.AtomToken = AtomToken;
24
- index_1.default.classes['AtomToken'] = __filename;
24
+ Parser.classes['AtomToken'] = __filename;
@@ -1,23 +1,24 @@
1
+ import * as Parser from '../index';
1
2
  import { Token } from '.';
2
3
  import { AtomToken } from './atom';
3
4
  import type { LintError } from '../index';
4
5
  import type { AttributesToken } from '../internal';
5
- declare type AttributeTypes = 'ext-attr' | 'html-attr' | 'table-attr';
6
+ export type AttributeTypes = 'ext-attr' | 'html-attr' | 'table-attr';
6
7
  declare const AttributeToken_base: ((abstract new (...args: any[]) => {
7
8
  removeAt(): never;
8
- insertAt(token: string, i?: number | undefined): import("../index").AstText;
9
- insertAt<T extends import("../index").AstNodes>(token: T, i?: number | undefined): T;
9
+ insertAt(token: string, i?: number | undefined): Parser.AstText;
10
+ insertAt<T extends Parser.AstNodes>(token: T, i?: number | undefined): T;
10
11
  length: number;
11
- toString(selector?: string | undefined, separator?: string | undefined): string;
12
+ toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
12
13
  text(separator?: string | undefined): string;
13
14
  }) & {
14
15
  readonly fixed: true;
15
- }) & typeof Token;
16
+ }) & typeof Parser.Token;
16
17
  /**
17
18
  * 扩展和HTML标签属性
18
19
  * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
19
20
  */
20
- export declare abstract class AttributeToken extends AttributeToken_base {
21
+ export declare class AttributeToken extends AttributeToken_base {
21
22
  #private;
22
23
  type: AttributeTypes;
23
24
  name: string;
@@ -57,22 +58,17 @@ export declare abstract class AttributeToken extends AttributeToken_base {
57
58
  * @param value 属性值
58
59
  * @param quotes 引号
59
60
  */
60
- constructor(type: AttributeTypes, tag: string, key: string, equal?: string, value?: string, quotes?: [string?, string?], config?: import("../index").Config, accum?: Token[]);
61
+ constructor(type: AttributeTypes, tag: string, key: string, equal?: string, value?: string, quotes?: [string?, string?], config?: Parser.Config, accum?: Token[]);
61
62
  /**
62
63
  * @override
63
64
  * @browser
64
65
  */
65
- toString(selector?: string): string;
66
+ toString(omit?: Set<string>): string;
66
67
  /**
67
68
  * @override
68
69
  * @browser
69
70
  */
70
71
  text(): string;
71
- /**
72
- * @override
73
- * @browser
74
- */
75
- print(): string;
76
72
  /**
77
73
  * @override
78
74
  * @browser
@@ -83,6 +79,11 @@ export declare abstract class AttributeToken extends AttributeToken_base {
83
79
  * @browser
84
80
  */
85
81
  getValue(): string | true;
82
+ /**
83
+ * @override
84
+ * @browser
85
+ */
86
+ print(): string;
86
87
  /** @override */
87
88
  cloneNode(): this;
88
89
  /** 转义等号 */
@@ -4,7 +4,7 @@ exports.AttributeToken = void 0;
4
4
  const lint_1 = require("../util/lint");
5
5
  const string_1 = require("../util/string");
6
6
  const fixed_1 = require("../mixin/fixed");
7
- const index_1 = require("../index");
7
+ const Parser = require("../index");
8
8
  const _1 = require(".");
9
9
  const atom_1 = require("./atom");
10
10
  const stages = { 'ext-attr': 0, 'html-attr': 2, 'table-attr': 3 }, pre = { 'ext-attr': '<pre ', 'html-attr': '<p ', 'table-attr': '{|' }, post = { 'ext-attr': '/>', 'html-attr': '>', 'table-attr': '' }, commonHtmlAttrs = new Set([
@@ -188,20 +188,23 @@ class AttributeToken extends (0, fixed_1.fixed)(_1.Token) {
188
188
  * @param value 属性值
189
189
  * @param quotes 引号
190
190
  */
191
- constructor(type, tag, key, equal = '', value = '', quotes = [], config = index_1.default.getConfig(), accum = []) {
191
+ constructor(type, tag, key, equal = '', value, quotes = [], config = Parser.getConfig(), accum = []) {
192
192
  const keyToken = new atom_1.AtomToken(key, 'attr-key', config, accum, {
193
193
  [type === 'ext-attr' ? 'AstText' : 'Stage-1']: ':', ArgToken: ':', TranscludeToken: ':',
194
194
  });
195
195
  let valueToken;
196
- if (key === 'title') {
196
+ if (key === 'title' || tag === 'img' && key === 'alt') {
197
197
  valueToken = new _1.Token(value, config, true, accum, {
198
198
  [`Stage-${stages[type]}`]: ':', ConverterToken: ':',
199
199
  });
200
200
  valueToken.type = 'attr-value';
201
- valueToken.setAttribute('stage', index_1.default.MAX_STAGE - 1);
201
+ valueToken.setAttribute('stage', Parser.MAX_STAGE - 1);
202
202
  }
203
203
  else if (tag === 'gallery' && key === 'caption') {
204
- const newConfig = { ...config, excludes: [...config.excludes, 'quote', 'extLink', 'magicLink', 'list'] };
204
+ const newConfig = {
205
+ ...config,
206
+ excludes: [...config.excludes, 'quote', 'extLink', 'magicLink', 'list'],
207
+ };
205
208
  valueToken = new _1.Token(value, newConfig, true, accum, {
206
209
  AstText: ':', LinkToken: ':', FileToken: ':', CategoryToken: ':', ConverterToken: ':',
207
210
  });
@@ -209,7 +212,10 @@ class AttributeToken extends (0, fixed_1.fixed)(_1.Token) {
209
212
  valueToken.setAttribute('stage', 5);
210
213
  }
211
214
  else if (tag === 'choose' && (key === 'before' || key === 'after')) {
212
- const newConfig = { ...config, excludes: [...config.excludes, 'heading', 'html', 'table', 'hr', 'list'] };
215
+ const newConfig = {
216
+ ...config,
217
+ excludes: [...config.excludes, 'heading', 'html', 'table', 'hr', 'list'],
218
+ };
213
219
  valueToken = new _1.Token(value, newConfig, true, accum, {
214
220
  ArgToken: ':',
215
221
  TranscludeToken: ':',
@@ -251,14 +257,14 @@ class AttributeToken extends (0, fixed_1.fixed)(_1.Token) {
251
257
  * @override
252
258
  * @browser
253
259
  */
254
- toString(selector) {
255
- if (selector && this.matches(selector)) {
260
+ toString(omit) {
261
+ if (omit && this.matchesTypes(omit)) {
256
262
  return '';
257
263
  }
258
264
  const [quoteStart = '', quoteEnd = ''] = this.#quotes;
259
265
  return this.#equal
260
- ? `${super.toString(selector, `${this.#equal}${quoteStart}`)}${quoteEnd}`
261
- : this.firstChild.toString(selector);
266
+ ? `${super.toString(omit, `${this.#equal}${quoteStart}`)}${quoteEnd}`
267
+ : this.firstChild.toString(omit);
262
268
  }
263
269
  /**
264
270
  * @override
@@ -271,14 +277,6 @@ class AttributeToken extends (0, fixed_1.fixed)(_1.Token) {
271
277
  getGaps(i) {
272
278
  return this.#equal && i === 0 ? this.#equal.length + (this.#quotes[0]?.length ?? 0) : 0;
273
279
  }
274
- /**
275
- * @override
276
- * @browser
277
- */
278
- print() {
279
- const [quoteStart = '', quoteEnd = ''] = this.#quotes;
280
- return this.#equal ? super.print({ sep: `${this.#equal}${quoteStart}`, post: quoteEnd }) : super.print();
281
- }
282
280
  /**
283
281
  * @override
284
282
  * @browser
@@ -289,8 +287,13 @@ class AttributeToken extends (0, fixed_1.fixed)(_1.Token) {
289
287
  if (!balanced) {
290
288
  const root = this.getRootNode();
291
289
  rect = { start, ...root.posFromIndex(start) };
292
- const e = (0, lint_1.generateForChild)(lastChild, rect, 'unclosed quotes', 'warning'), startIndex = e.startIndex - 1, startCol = e.startCol - 1;
293
- errors.push({ ...e, startIndex, startCol, excerpt: String(root).slice(startIndex, startIndex + 50) });
290
+ const e = (0, lint_1.generateForChild)(lastChild, rect, 'unclosed quotes', 'warning'), startIndex = e.startIndex - 1;
291
+ errors.push({
292
+ ...e,
293
+ startIndex,
294
+ startCol: e.startCol - 1,
295
+ excerpt: String(root).slice(startIndex, startIndex + 50),
296
+ });
294
297
  }
295
298
  if (extAttrs[tag] && !extAttrs[tag].has(name)
296
299
  || (type !== 'ext-attr' && !/\{\{[^{]+\}\}/u.test(name) || tag in htmlAttrs)
@@ -323,6 +326,14 @@ class AttributeToken extends (0, fixed_1.fixed)(_1.Token) {
323
326
  }
324
327
  return this.type === 'ext-attr' || '';
325
328
  }
329
+ /**
330
+ * @override
331
+ * @browser
332
+ */
333
+ print() {
334
+ const [quoteStart = '', quoteEnd = ''] = this.#quotes;
335
+ return this.#equal ? super.print({ sep: `${this.#equal}${quoteStart}`, post: quoteEnd }) : super.print();
336
+ }
326
337
  /** @private */
327
338
  getAttribute(key) {
328
339
  if (key === 'equal') {
@@ -337,8 +348,7 @@ class AttributeToken extends (0, fixed_1.fixed)(_1.Token) {
337
348
  /** @override */
338
349
  cloneNode() {
339
350
  const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
340
- return index_1.default.run(() => {
341
- // @ts-expect-error abstract class
351
+ return Parser.run(() => {
342
352
  const token = new AttributeToken(this.type, this.#tag, '', this.#equal, '', this.#quotes, config);
343
353
  token.firstChild.safeReplaceWith(key);
344
354
  token.lastChild.safeReplaceWith(value);
@@ -371,7 +381,7 @@ class AttributeToken extends (0, fixed_1.fixed)(_1.Token) {
371
381
  this.#equal = '';
372
382
  return;
373
383
  }
374
- const { type } = this, key = this.name === 'title' ? 'title' : 'data', wikitext = `${pre[type]}${key}="${value}"${post[type]}`, root = index_1.default.parse(wikitext, this.getAttribute('include'), stages[type] + 1, this.getAttribute('config')), { length, firstChild: tag } = root;
384
+ const { type, name } = this, key = name === 'title' ? 'title' : 'data', wikitext = `${pre[type]}${key}="${value}"${post[type]}`, root = Parser.parse(wikitext, this.getAttribute('include'), stages[type] + 1, this.getAttribute('config')), { length, firstChild: tag } = root;
375
385
  let attrs;
376
386
  if (length !== 1 || tag.type !== type.slice(0, -5)) {
377
387
  throw new SyntaxError(`非法的标签属性:${(0, string_1.noWrap)(value)}`);
@@ -386,7 +396,7 @@ class AttributeToken extends (0, fixed_1.fixed)(_1.Token) {
386
396
  attrs = tag.firstChild;
387
397
  }
388
398
  const { firstChild } = attrs;
389
- if (attrs.length !== 1 || firstChild.type !== this.type || firstChild.name !== key) {
399
+ if (attrs.length !== 1 || firstChild.type !== type || firstChild.name !== key) {
390
400
  throw new SyntaxError(`非法的标签属性:${(0, string_1.noWrap)(value)}`);
391
401
  }
392
402
  const { lastChild } = firstChild;
@@ -409,7 +419,7 @@ class AttributeToken extends (0, fixed_1.fixed)(_1.Token) {
409
419
  if (this.name === 'title') {
410
420
  throw new Error('title 属性不能更名!');
411
421
  }
412
- const { type } = this, wikitext = `${pre[type]}${key}${post[type]}`, root = index_1.default.parse(wikitext, this.getAttribute('include'), stages[type] + 1, this.getAttribute('config')), { length, firstChild: tag } = root;
422
+ const { type } = this, wikitext = `${pre[type]}${key}${post[type]}`, root = Parser.parse(wikitext, this.getAttribute('include'), stages[type] + 1, this.getAttribute('config')), { length, firstChild: tag } = root;
413
423
  let attrs;
414
424
  if (length !== 1 || tag.type !== type.slice(0, -5)) {
415
425
  throw new SyntaxError(`非法的标签属性名:${(0, string_1.noWrap)(key)}`);
@@ -424,13 +434,13 @@ class AttributeToken extends (0, fixed_1.fixed)(_1.Token) {
424
434
  attrs = tag.firstChild;
425
435
  }
426
436
  const { firstChild: attr } = attrs;
427
- if (attrs.length === 1 && attr.type === this.type && attr.value === true) {
428
- const { firstChild } = attr;
429
- attr.destroy();
430
- this.firstChild.safeReplaceWith(firstChild);
437
+ if (attrs.length !== 1 || attr.type !== type || attr.value !== true) {
438
+ throw new SyntaxError(`非法的标签属性名:${(0, string_1.noWrap)(key)}`);
431
439
  }
432
- throw new SyntaxError(`非法的标签属性名:${(0, string_1.noWrap)(key)}`);
440
+ const { firstChild } = attr;
441
+ attr.destroy();
442
+ this.firstChild.safeReplaceWith(firstChild);
433
443
  }
434
444
  }
435
445
  exports.AttributeToken = AttributeToken;
436
- index_1.default.classes['AttributeToken'] = __filename;
446
+ Parser.classes['AttributeToken'] = __filename;
@@ -1,3 +1,4 @@
1
+ import * as Parser from '../index';
1
2
  import { Token } from '.';
2
3
  import { AtomToken } from './atom';
3
4
  import { AttributeToken } from './attribute';
@@ -8,7 +9,7 @@ declare type AttributesTypes = 'ext-attrs' | 'html-attrs' | 'table-attrs';
8
9
  * 扩展和HTML标签属性
9
10
  * @classdesc `{childNodes: ...AtomToken|AttributeToken}`
10
11
  */
11
- export declare abstract class AttributesToken extends Token {
12
+ export declare class AttributesToken extends Token {
12
13
  #private;
13
14
  type: AttributesTypes;
14
15
  name: string;
@@ -38,7 +39,7 @@ export declare abstract class AttributesToken extends Token {
38
39
  * @param type 标签类型
39
40
  * @param name 标签名
40
41
  */
41
- constructor(attr: string | undefined, type: AttributesTypes, name: string, config?: import("../index").Config, accum?: Token[]);
42
+ constructor(attr: string | undefined, type: AttributesTypes, name: string, config?: Parser.Config, accum?: Token[]);
42
43
  /**
43
44
  * 所有指定属性名的AttributeToken
44
45
  * @browser
@@ -112,7 +113,7 @@ export declare abstract class AttributesToken extends Token {
112
113
  */
113
114
  toggleAttr(key: string, force?: boolean): void;
114
115
  /** @override */
115
- toString(selector?: string): string;
116
+ toString(omit?: Set<string>): string;
116
117
  /** @override */
117
118
  text(): string;
118
119
  }