wikiparser-node 1.0.0-beta.0 → 1.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 (133) hide show
  1. package/config/.schema.json +26 -0
  2. package/dist/index.d.ts +11 -9
  3. package/dist/index.js +22 -24
  4. package/dist/internal.d.ts +44 -0
  5. package/dist/lib/element.d.ts +42 -32
  6. package/dist/lib/element.js +59 -56
  7. package/dist/lib/node.d.ts +29 -36
  8. package/dist/lib/node.js +33 -48
  9. package/dist/lib/range.d.ts +132 -0
  10. package/dist/lib/range.js +387 -0
  11. package/dist/lib/ranges.d.ts +2 -12
  12. package/dist/lib/ranges.js +6 -11
  13. package/dist/lib/text.d.ts +11 -5
  14. package/dist/lib/text.js +25 -13
  15. package/dist/lib/title.d.ts +4 -5
  16. package/dist/lib/title.js +17 -7
  17. package/dist/mixin/attributesParent.js +6 -3
  18. package/dist/mixin/fixed.js +8 -5
  19. package/dist/mixin/hidden.js +7 -3
  20. package/dist/mixin/singleLine.js +6 -3
  21. package/dist/mixin/sol.js +6 -3
  22. package/dist/parser/{brackets.js → braces.js} +34 -26
  23. package/dist/parser/commentAndExt.js +25 -15
  24. package/dist/parser/converter.js +16 -9
  25. package/dist/parser/externalLinks.js +15 -9
  26. package/dist/parser/hrAndDoubleUnderscore.js +17 -10
  27. package/dist/parser/html.js +18 -9
  28. package/dist/parser/links.js +22 -14
  29. package/dist/parser/list.js +20 -10
  30. package/dist/parser/magicLinks.js +14 -7
  31. package/dist/parser/quotes.js +21 -11
  32. package/dist/parser/selector.js +19 -12
  33. package/dist/parser/table.js +25 -16
  34. package/dist/src/arg.d.ts +7 -8
  35. package/dist/src/arg.js +27 -24
  36. package/dist/src/atom.d.ts +4 -5
  37. package/dist/src/atom.js +9 -7
  38. package/dist/src/attribute.d.ts +13 -13
  39. package/dist/src/attribute.js +28 -25
  40. package/dist/src/attributes.d.ts +11 -10
  41. package/dist/src/attributes.js +40 -45
  42. package/dist/src/converter.d.ts +5 -7
  43. package/dist/src/converter.js +22 -16
  44. package/dist/src/converterFlags.d.ts +11 -12
  45. package/dist/src/converterFlags.js +17 -14
  46. package/dist/src/converterRule.d.ts +9 -10
  47. package/dist/src/converterRule.js +27 -27
  48. package/dist/src/extLink.d.ts +4 -6
  49. package/dist/src/extLink.js +25 -22
  50. package/dist/src/gallery.d.ts +9 -13
  51. package/dist/src/gallery.js +28 -23
  52. package/dist/src/heading.d.ts +11 -11
  53. package/dist/src/heading.js +19 -19
  54. package/dist/src/hidden.d.ts +4 -5
  55. package/dist/src/hidden.js +10 -8
  56. package/dist/src/html.d.ts +15 -12
  57. package/dist/src/html.js +18 -15
  58. package/dist/src/imageParameter.d.ts +11 -13
  59. package/dist/src/imageParameter.js +21 -16
  60. package/dist/src/imagemap.d.ts +11 -15
  61. package/dist/src/imagemap.js +26 -21
  62. package/dist/src/imagemapLink.d.ts +12 -17
  63. package/dist/src/imagemapLink.js +19 -14
  64. package/dist/src/index.d.ts +24 -20
  65. package/dist/src/index.js +65 -75
  66. package/dist/src/link/base.d.ts +8 -10
  67. package/dist/src/link/base.js +28 -22
  68. package/dist/src/link/category.d.ts +2 -3
  69. package/dist/src/link/category.js +7 -5
  70. package/dist/src/link/file.d.ts +9 -11
  71. package/dist/src/link/file.js +53 -26
  72. package/dist/src/link/galleryImage.d.ts +8 -8
  73. package/dist/src/link/galleryImage.js +18 -16
  74. package/dist/src/link/index.d.ts +6 -6
  75. package/dist/src/link/index.js +14 -16
  76. package/dist/src/magicLink.d.ts +9 -6
  77. package/dist/src/magicLink.js +23 -18
  78. package/dist/src/nested.d.ts +10 -10
  79. package/dist/src/nested.js +25 -17
  80. package/dist/src/nowiki/base.d.ts +7 -8
  81. package/dist/src/nowiki/base.js +10 -8
  82. package/dist/src/nowiki/comment.d.ts +7 -7
  83. package/dist/src/nowiki/comment.js +12 -9
  84. package/dist/src/nowiki/dd.d.ts +2 -3
  85. package/dist/src/nowiki/dd.js +7 -11
  86. package/dist/src/nowiki/doubleUnderscore.d.ts +5 -7
  87. package/dist/src/nowiki/doubleUnderscore.js +11 -8
  88. package/dist/src/nowiki/hr.d.ts +6 -7
  89. package/dist/src/nowiki/hr.js +11 -8
  90. package/dist/src/nowiki/index.d.ts +5 -7
  91. package/dist/src/nowiki/index.js +8 -6
  92. package/dist/src/nowiki/list.d.ts +4 -4
  93. package/dist/src/nowiki/list.js +8 -6
  94. package/dist/src/nowiki/noinclude.d.ts +3 -3
  95. package/dist/src/nowiki/noinclude.js +8 -6
  96. package/dist/src/nowiki/quote.d.ts +6 -7
  97. package/dist/src/nowiki/quote.js +11 -8
  98. package/dist/src/onlyinclude.d.ts +3 -5
  99. package/dist/src/onlyinclude.js +9 -7
  100. package/dist/src/paramTag/index.d.ts +8 -10
  101. package/dist/src/paramTag/index.js +15 -13
  102. package/dist/src/paramTag/inputbox.d.ts +4 -6
  103. package/dist/src/paramTag/inputbox.js +10 -8
  104. package/dist/src/parameter.d.ts +11 -12
  105. package/dist/src/parameter.js +25 -22
  106. package/dist/src/pre.d.ts +5 -10
  107. package/dist/src/pre.js +16 -11
  108. package/dist/src/syntax.d.ts +6 -7
  109. package/dist/src/syntax.js +12 -10
  110. package/dist/src/table/base.d.ts +14 -9
  111. package/dist/src/table/base.js +18 -15
  112. package/dist/src/table/index.d.ts +24 -17
  113. package/dist/src/table/index.js +39 -67
  114. package/dist/src/table/td.d.ts +17 -21
  115. package/dist/src/table/td.js +20 -28
  116. package/dist/src/table/tr.d.ts +6 -11
  117. package/dist/src/table/tr.js +8 -6
  118. package/dist/src/table/trBase.d.ts +12 -22
  119. package/dist/src/table/trBase.js +23 -19
  120. package/dist/src/tagPair/ext.d.ts +10 -10
  121. package/dist/src/tagPair/ext.js +47 -24
  122. package/dist/src/tagPair/include.d.ts +6 -7
  123. package/dist/src/tagPair/include.js +11 -8
  124. package/dist/src/tagPair/index.d.ts +12 -11
  125. package/dist/src/tagPair/index.js +13 -11
  126. package/dist/src/transclude.d.ts +8 -10
  127. package/dist/src/transclude.js +70 -77
  128. package/dist/util/debug.js +2 -12
  129. package/dist/util/diff.js +4 -2
  130. package/dist/util/lint.js +5 -5
  131. package/dist/util/string.js +2 -31
  132. package/package.json +13 -13
  133. package/dist/util/base.js +0 -26
@@ -1,9 +1,16 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseMagicLinks = void 0;
2
4
  const string_1 = require("../util/string");
3
- const Parser = require("../index");
4
- const MagicLinkToken = require("../src/magicLink");
5
- /** 解析自由外链 */
6
- const parseMagicLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
5
+ const index_1 = require("../index");
6
+ const magicLink_1 = require("../src/magicLink");
7
+ /**
8
+ * 解析自由外链
9
+ * @param wikitext
10
+ * @param config
11
+ * @param accum
12
+ */
13
+ const parseMagicLinks = (wikitext, config = index_1.default.getConfig(), accum = []) => {
7
14
  const regex = new RegExp(`(?<![\\p{L}\\d_])(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})`, 'giu');
8
15
  return wikitext.replace(regex, (m, p1) => {
9
16
  let trail = '', url = m;
@@ -24,9 +31,9 @@ const parseMagicLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
24
31
  if (trail.length >= p1.length) {
25
32
  return m;
26
33
  }
27
- new MagicLinkToken(url, false, config, accum);
34
+ new magicLink_1.MagicLinkToken(url, false, config, accum);
28
35
  return `\0${accum.length - 1}w\x7F${trail}`;
29
36
  });
30
37
  };
31
- Parser.parsers['parseMagicLinks'] = __filename;
32
- module.exports = parseMagicLinks;
38
+ exports.parseMagicLinks = parseMagicLinks;
39
+ index_1.default.parsers['parseMagicLinks'] = __filename;
@@ -1,8 +1,15 @@
1
1
  "use strict";
2
- const Parser = require("../index");
3
- const QuoteToken = require("../src/nowiki/quote");
4
- /** 解析单引号 */
5
- const parseQuotes = (wikitext, config = Parser.getConfig(), accum = []) => {
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseQuotes = void 0;
4
+ const index_1 = require("../index");
5
+ const quote_1 = require("../src/nowiki/quote");
6
+ /**
7
+ * 解析单引号
8
+ * @param wikitext
9
+ * @param config
10
+ * @param accum
11
+ */
12
+ const parseQuotes = (wikitext, config = index_1.default.getConfig(), accum = []) => {
6
13
  const arr = wikitext.split(/('{2,})/u), { length } = arr;
7
14
  if (length === 1) {
8
15
  return wikitext;
@@ -20,11 +27,11 @@ const parseQuotes = (wikitext, config = Parser.getConfig(), accum = []) => {
20
27
  // fall through
21
28
  case 3:
22
29
  nBold++;
23
- if (firstSingle) {
30
+ if (firstSingle !== undefined) {
24
31
  break;
25
32
  }
26
33
  else if (arr[i - 1].endsWith(' ')) {
27
- if (!firstMulti && !firstSpace) {
34
+ if (firstMulti === undefined && firstSpace === undefined) {
28
35
  firstSpace = i;
29
36
  }
30
37
  }
@@ -44,14 +51,17 @@ const parseQuotes = (wikitext, config = Parser.getConfig(), accum = []) => {
44
51
  }
45
52
  if (nItalic % 2 === 1 && nBold % 2 === 1) {
46
53
  const i = firstSingle ?? firstMulti ?? firstSpace;
47
- arr[i] = `''`;
48
- arr[i - 1] += `'`;
54
+ if (i !== undefined) {
55
+ arr[i] = `''`;
56
+ arr[i - 1] += `'`;
57
+ }
49
58
  }
50
59
  for (let i = 1; i < length; i += 2) {
51
- new QuoteToken(arr[i].length, config, accum);
60
+ // @ts-expect-error abstract class
61
+ new quote_1.QuoteToken(arr[i].length, config, accum);
52
62
  arr[i] = `\0${accum.length - 1}q\x7F`;
53
63
  }
54
64
  return arr.join('');
55
65
  };
56
- Parser.parsers['parseQuotes'] = __filename;
57
- module.exports = parseQuotes;
66
+ exports.parseQuotes = parseQuotes;
67
+ index_1.default.parsers['parseQuotes'] = __filename;
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
- const Parser = require("../index");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseSelector = void 0;
4
+ const index_1 = require("../index");
3
5
  const simplePseudos = new Set([
4
6
  'root',
5
7
  'first-child',
@@ -45,21 +47,25 @@ const specialChars = [
45
47
  ['&', '&amp;'],
46
48
  ];
47
49
  const pseudoRegex = new RegExp(`:(${complexPseudos.join('|')})$`, 'u'), regularRegex = /[[(,>+~]|\s+/u, attributeRegex = /^\s*(\w+)\s*(?:([~|^$*!]?=)\s*("[^"]*"|'[^']*'|[^\s[\]]+)(?:\s+(i))?\s*)?\]/u, functionRegex = /^(\s*"[^"]*"\s*|\s*'[^']*'\s*|[^()]*)\)/u, grouping = new Set([',', '>', '+', '~']), combinator = new Set(['>', '+', '~', '']);
48
- /** 清理转义符号 */
50
+ /**
51
+ * 清理转义符号
52
+ * @param selector
53
+ */
49
54
  const sanitize = (selector) => {
50
- let s = selector;
51
55
  for (const [c, escaped] of specialChars) {
52
- s = s.replaceAll(`\\${c}`, escaped);
56
+ selector = selector.replaceAll(`\\${c}`, escaped);
53
57
  }
54
- return s;
58
+ return selector;
55
59
  };
56
- /** 还原转义符号 */
60
+ /**
61
+ * 还原转义符号
62
+ * @param selector
63
+ */
57
64
  const desanitize = (selector) => {
58
- let str = selector;
59
65
  for (const [c, escaped] of specialChars) {
60
- str = str.replaceAll(escaped, c);
66
+ selector = selector.replaceAll(escaped, c);
61
67
  }
62
- return str.trim();
68
+ return selector.trim();
63
69
  };
64
70
  /**
65
71
  * 去除首尾的引号
@@ -86,6 +92,7 @@ const pushSimple = (step, str) => {
86
92
  };
87
93
  /**
88
94
  * 解析选择器
95
+ * @param selector
89
96
  * @throws `SyntaxError` 非法的选择器
90
97
  */
91
98
  const parseSelector = (selector) => {
@@ -148,11 +155,11 @@ const parseSelector = (selector) => {
148
155
  pushSimple(step, sanitized);
149
156
  const pseudos = new Set(stack.flat(2).filter(e => typeof e === 'string' && e.startsWith(':')));
150
157
  if (pseudos.size > 0) {
151
- Parser.warn('检测到伪选择器,请确认是否需要将":"转义成"\\:"。', pseudos);
158
+ index_1.default.warn('检测到伪选择器,请确认是否需要将":"转义成"\\:"。', pseudos);
152
159
  }
153
160
  return stack;
154
161
  }
155
162
  throw new SyntaxError(`非法的选择器!\n${s}\n检测到未闭合的'${regex === attributeRegex ? '[' : '('}'`);
156
163
  };
157
- Parser.parsers['parseSelector'] = __filename;
158
- module.exports = parseSelector;
164
+ exports.parseSelector = parseSelector;
165
+ index_1.default.parsers['parseSelector'] = __filename;
@@ -1,15 +1,19 @@
1
1
  "use strict";
2
- const Parser = require("../index");
3
- const Token = require("../src");
4
- const TableToken = require("../src/table");
5
- const TrToken = require("../src/table/tr");
6
- const TdToken = require("../src/table/td");
7
- const DdToken = require("../src/nowiki/dd");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseTable = void 0;
4
+ const index_1 = require("../index");
5
+ const src_1 = require("../src");
6
+ const table_1 = require("../src/table");
7
+ const tr_1 = require("../src/table/tr");
8
+ const td_1 = require("../src/table/td");
9
+ const dd_1 = require("../src/nowiki/dd");
8
10
  /**
9
11
  * 解析表格,注意`tr`和`td`包含开头的换行
10
12
  * @param {Token & {firstChild: AstText}} root 根节点
13
+ * @param config
14
+ * @param accum
11
15
  */
12
- const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getConfig(), accum = []) => {
16
+ const parseTable = ({ firstChild: { data }, type, name }, config = index_1.default.getConfig(), accum = []) => {
13
17
  const stack = [], lines = data.split('\n');
14
18
  let out = type === 'root' || type === 'parameter-value' || type === 'ext-inner' && name === 'poem'
15
19
  ? ''
@@ -25,11 +29,11 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
25
29
  return;
26
30
  }
27
31
  const { lastChild } = top;
28
- if (lastChild.constructor === Token) {
32
+ if (lastChild.constructor === src_1.Token) {
29
33
  lastChild.setText(String(lastChild) + str);
30
34
  }
31
35
  else {
32
- const token = new Token(str, config, true, accum);
36
+ const token = new src_1.Token(str, config, true, accum);
33
37
  token.type = 'table-inter';
34
38
  top.insertAt(token.setAttribute('stage', 3));
35
39
  }
@@ -44,10 +48,12 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
44
48
  }
45
49
  const [, indent, moreSpaces, tableSyntax, attr] = matchesStart;
46
50
  if (indent) {
47
- new DdToken(indent, config, accum);
51
+ // @ts-expect-error abstract class
52
+ new dd_1.DdToken(indent, config, accum);
48
53
  }
49
54
  push(`\n${spaces}${indent && `\0${accum.length - 1}d\x7F`}${moreSpaces}\0${accum.length}b\x7F`, top);
50
- const table = new TableToken(tableSyntax, attr, config, accum);
55
+ // @ts-expect-error abstract class
56
+ const table = new table_1.TableToken(tableSyntax, attr, config, accum);
51
57
  stack.push(...top ? [top] : [], table);
52
58
  continue;
53
59
  }
@@ -78,7 +84,8 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
78
84
  if (top.type === 'tr') {
79
85
  top = stack.pop();
80
86
  }
81
- const tr = new TrToken(`\n${spaces}${row}`, attr, config, accum);
87
+ // @ts-expect-error abstract class
88
+ const tr = new tr_1.TrToken(`\n${spaces}${row}`, attr, config, accum);
82
89
  stack.push(top, tr);
83
90
  top.insertAt(tr);
84
91
  }
@@ -91,18 +98,20 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
91
98
  : /(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu;
92
99
  let mt = regex.exec(attr), lastIndex = 0, lastSyntax = `\n${spaces}${cell}`;
93
100
  while (mt) {
94
- const td = new TdToken(lastSyntax, attr.slice(lastIndex, mt.index), config, accum);
101
+ // @ts-expect-error abstract class
102
+ const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex, mt.index), config, accum);
95
103
  top.insertAt(td);
96
104
  ({ lastIndex } = regex);
97
105
  [lastSyntax] = mt;
98
106
  mt = regex.exec(attr);
99
107
  }
100
- const td = new TdToken(lastSyntax, attr.slice(lastIndex), config, accum);
108
+ // @ts-expect-error abstract class
109
+ const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex), config, accum);
101
110
  stack.push(top, td);
102
111
  top.insertAt(td);
103
112
  }
104
113
  }
105
114
  return out.slice(1);
106
115
  };
107
- Parser.parsers['parseTable'] = __filename;
108
- module.exports = parseTable;
116
+ exports.parseTable = parseTable;
117
+ index_1.default.parsers['parseTable'] = __filename;
package/dist/src/arg.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import * as Parser from '../index';
2
- import Token = require('.');
3
- import AtomToken = require('./atom');
4
- import HiddenToken = require('./hidden');
1
+ import { Token } from '.';
2
+ import { AtomToken } from './atom';
3
+ import { HiddenToken } from './hidden';
4
+ import type { LintError } from '../index';
5
5
  /**
6
6
  * `{{{}}}`包裹的参数
7
7
  * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
8
8
  */
9
- declare abstract class ArgToken extends Token {
9
+ export declare abstract class ArgToken extends Token {
10
10
  /** @browser */
11
11
  readonly type = "arg";
12
12
  name: string;
@@ -24,7 +24,7 @@ declare abstract class ArgToken extends Token {
24
24
  * @browser
25
25
  * @param parts 以'|'分隔的各部分
26
26
  */
27
- constructor(parts: string[], config?: Parser.Config, accum?: Token[]);
27
+ constructor(parts: string[], config?: import("../index").Config, accum?: Token[]);
28
28
  /**
29
29
  * @override
30
30
  * @browser
@@ -44,7 +44,7 @@ declare abstract class ArgToken extends Token {
44
44
  * @override
45
45
  * @browser
46
46
  */
47
- lint(start?: number): Parser.LintError[];
47
+ lint(start?: number): LintError[];
48
48
  /** @override */
49
49
  cloneNode(): this;
50
50
  /** 移除无效部分 */
@@ -75,4 +75,3 @@ declare abstract class ArgToken extends Token {
75
75
  */
76
76
  setDefault(value: string): void;
77
77
  }
78
- export = ArgToken;
package/dist/src/arg.js CHANGED
@@ -1,15 +1,17 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArgToken = void 0;
2
4
  const string_1 = require("../util/string");
3
5
  const lint_1 = require("../util/lint");
4
- const Parser = require("../index");
5
- const Token = require(".");
6
- const AtomToken = require("./atom");
7
- const HiddenToken = require("./hidden");
6
+ const index_1 = require("../index");
7
+ const _1 = require(".");
8
+ const atom_1 = require("./atom");
9
+ const hidden_1 = require("./hidden");
8
10
  /**
9
11
  * `{{{}}}`包裹的参数
10
12
  * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
11
13
  */
12
- class ArgToken extends Token {
14
+ class ArgToken extends _1.Token {
13
15
  /** @browser */
14
16
  type = 'arg';
15
17
  /**
@@ -23,25 +25,25 @@ class ArgToken extends Token {
23
25
  * @browser
24
26
  * @param parts 以'|'分隔的各部分
25
27
  */
26
- constructor(parts, config = Parser.getConfig(), accum = []) {
28
+ constructor(parts, config = index_1.default.getConfig(), accum = []) {
27
29
  super(undefined, config, true, accum, {
28
30
  AtomToken: 0, Token: 1, HiddenToken: '2:',
29
31
  });
30
32
  for (let i = 0; i < parts.length; i++) {
31
33
  if (i === 0) {
32
- const token = new AtomToken(parts[i], 'arg-name', config, accum, {
34
+ const token = new atom_1.AtomToken(parts[i], 'arg-name', config, accum, {
33
35
  'Stage-2': ':', '!HeadingToken': '',
34
36
  });
35
37
  super.insertAt(token);
36
38
  }
37
39
  else if (i > 1) {
38
- const token = new HiddenToken(parts[i], config, accum, {
40
+ const token = new hidden_1.HiddenToken(parts[i], config, accum, {
39
41
  'Stage-2': ':', '!HeadingToken': '',
40
42
  });
41
43
  super.insertAt(token);
42
44
  }
43
45
  else {
44
- const token = new Token(parts[i], config, true, accum);
46
+ const token = new _1.Token(parts[i], config, true, accum);
45
47
  token.type = 'arg-default';
46
48
  super.insertAt(token.setAttribute('stage', 2));
47
49
  }
@@ -67,8 +69,8 @@ class ArgToken extends Token {
67
69
  return 3;
68
70
  }
69
71
  /** @private */
70
- getGaps() {
71
- return 1;
72
+ getGaps(i) {
73
+ return i < this.length - 1 ? 1 : 0;
72
74
  }
73
75
  /**
74
76
  * @override
@@ -92,7 +94,7 @@ class ArgToken extends Token {
92
94
  if (rest.length > 0) {
93
95
  const rect = { start, ...this.getRootNode().posFromIndex(start) };
94
96
  errors.push(...rest.map(child => {
95
- const error = (0, lint_1.generateForChild)(child, rect, 'invisible content inside triple brackets'), { startIndex, startCol, excerpt } = error;
97
+ const error = (0, lint_1.generateForChild)(child, rect, 'invisible content inside triple braces'), { startIndex, startCol, excerpt } = error;
96
98
  return { ...error, startIndex: startIndex - 1, startCol: startCol - 1, excerpt: `|${excerpt}` };
97
99
  }));
98
100
  }
@@ -101,7 +103,8 @@ class ArgToken extends Token {
101
103
  /** @override */
102
104
  cloneNode() {
103
105
  const [name, ...cloned] = this.cloneChildNodes();
104
- return Parser.run(() => {
106
+ return index_1.default.run(() => {
107
+ // @ts-expect-error abstract class
105
108
  const token = new ArgToken([''], this.getAttribute('config'));
106
109
  token.firstChild.safeReplaceWith(name);
107
110
  token.append(...cloned);
@@ -121,7 +124,7 @@ class ArgToken extends Token {
121
124
  }
122
125
  /** 移除无效部分 */
123
126
  removeRedundant() {
124
- Parser.run(() => {
127
+ index_1.default.run(() => {
125
128
  for (let i = this.length - 1; i > 1; i--) {
126
129
  super.removeAt(i);
127
130
  }
@@ -164,13 +167,13 @@ class ArgToken extends Token {
164
167
  * @throws `SyntaxError` 非法的参数名
165
168
  */
166
169
  setName(name) {
167
- const root = Parser.parse(`{{{${name}}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: arg } = root;
168
- if (length !== 1 || arg.type !== 'arg' || arg.length !== 1) {
169
- throw new SyntaxError(`非法的参数名称:${(0, string_1.noWrap)(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);
170
175
  }
171
- const { firstChild } = arg;
172
- arg.destroy();
173
- this.firstChild.safeReplaceWith(firstChild);
176
+ throw new SyntaxError(`非法的参数名称:${(0, string_1.noWrap)(name)}`);
174
177
  }
175
178
  /**
176
179
  * 设置预设值
@@ -178,8 +181,8 @@ class ArgToken extends Token {
178
181
  * @throws `SyntaxError` 非法的参数预设值
179
182
  */
180
183
  setDefault(value) {
181
- const root = Parser.parse(`{{{|${value}}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: arg } = root;
182
- if (length !== 1 || arg.type !== 'arg' || arg.length !== 2) {
184
+ const root = index_1.default.parse(`{{{|${value}}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: arg } = root;
185
+ if (length !== 1 || !(arg instanceof ArgToken) || arg.length !== 2) {
183
186
  throw new SyntaxError(`非法的参数预设值:${(0, string_1.noWrap)(value)}`);
184
187
  }
185
188
  const { childNodes: [, oldDefault] } = this, { lastChild } = arg;
@@ -192,5 +195,5 @@ class ArgToken extends Token {
192
195
  }
193
196
  }
194
197
  }
195
- Parser.classes['ArgToken'] = __filename;
196
- module.exports = ArgToken;
198
+ exports.ArgToken = ArgToken;
199
+ index_1.default.classes['ArgToken'] = __filename;
@@ -1,12 +1,11 @@
1
- import * as Parser from '../index';
2
- import Token = require('.');
1
+ import { Token } from '.';
3
2
  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';
4
3
  /** 不会被继续解析的plain Token */
5
- declare class AtomToken extends Token {
4
+ export declare class AtomToken extends Token {
6
5
  type: AtomTypes;
7
6
  /** @browser */
8
- constructor(wikitext: string | undefined, type: AtomTypes, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
7
+ constructor(wikitext: string | undefined, type: AtomTypes, config?: import("../index").Config, accum?: Token[], acceptable?: Acceptable);
9
8
  /** @override */
10
9
  cloneNode(): this;
11
10
  }
12
- export = AtomToken;
11
+ export {};
package/dist/src/atom.js CHANGED
@@ -1,22 +1,24 @@
1
1
  "use strict";
2
- const Parser = require("../index");
3
- const Token = require(".");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AtomToken = void 0;
4
+ const index_1 = require("../index");
5
+ const _1 = require(".");
4
6
  /** 不会被继续解析的plain Token */
5
- class AtomToken extends Token {
7
+ class AtomToken extends _1.Token {
6
8
  /** @browser */
7
- constructor(wikitext, type, config = Parser.getConfig(), accum = [], acceptable) {
9
+ constructor(wikitext, type, config = index_1.default.getConfig(), accum = [], acceptable) {
8
10
  super(wikitext, config, true, accum, acceptable);
9
11
  this.type = type;
10
12
  }
11
13
  /** @override */
12
14
  cloneNode() {
13
15
  const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAttribute('acceptable');
14
- return Parser.run(() => {
16
+ return index_1.default.run(() => {
15
17
  const token = new AtomToken(undefined, this.type, config, [], acceptable);
16
18
  token.append(...cloned);
17
19
  return token;
18
20
  });
19
21
  }
20
22
  }
21
- Parser.classes['AtomToken'] = __filename;
22
- module.exports = AtomToken;
23
+ exports.AtomToken = AtomToken;
24
+ index_1.default.classes['AtomToken'] = __filename;
@@ -1,12 +1,12 @@
1
- import * as Parser from '../index';
2
- import Token = require('.');
3
- import AtomToken = require('./atom');
4
- import type { TokenAttributeGetter } from '../lib/node';
1
+ import { Token } from '.';
2
+ import { AtomToken } from './atom';
3
+ import type { LintError } from '../index';
4
+ import type { AttributesToken } from '../internal';
5
5
  declare type AttributeTypes = 'ext-attr' | 'html-attr' | 'table-attr';
6
6
  declare const AttributeToken_base: ((abstract new (...args: any[]) => {
7
7
  removeAt(): never;
8
- insertAt(token: string, i?: number | undefined): import("../lib/text");
9
- insertAt<T extends import("../lib/node").AstNodeTypes>(token: T, i?: number | undefined): T;
8
+ insertAt(token: string, i?: number | undefined): import("../index").AstText;
9
+ insertAt<T extends import("../index").AstNodes>(token: T, i?: number | undefined): T;
10
10
  length: number;
11
11
  toString(selector?: string | undefined, separator?: string | undefined): string;
12
12
  text(separator?: string | undefined): string;
@@ -17,7 +17,7 @@ declare const AttributeToken_base: ((abstract new (...args: any[]) => {
17
17
  * 扩展和HTML标签属性
18
18
  * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
19
19
  */
20
- declare abstract class AttributeToken extends AttributeToken_base {
20
+ export declare abstract class AttributeToken extends AttributeToken_base {
21
21
  #private;
22
22
  type: AttributeTypes;
23
23
  name: string;
@@ -26,8 +26,8 @@ declare abstract class AttributeToken extends AttributeToken_base {
26
26
  abstract get firstElementChild(): AtomToken;
27
27
  abstract get lastChild(): Token;
28
28
  abstract get lastElementChild(): Token;
29
- abstract get parentNode(): import('./attributes') | undefined;
30
- abstract get parentElement(): import('./attributes') | undefined;
29
+ abstract get parentNode(): AttributesToken | undefined;
30
+ abstract get parentElement(): AttributesToken | undefined;
31
31
  abstract get nextSibling(): AtomToken | this | undefined;
32
32
  abstract get nextElementSibling(): AtomToken | this | undefined;
33
33
  abstract get previousSibling(): AtomToken | this | undefined;
@@ -57,7 +57,7 @@ declare abstract class AttributeToken extends AttributeToken_base {
57
57
  * @param value 属性值
58
58
  * @param quotes 引号
59
59
  */
60
- constructor(type: AttributeTypes, tag: string, key: string, equal?: string, value?: string, quotes?: [string?, string?], config?: Parser.Config, accum?: Token[]);
60
+ constructor(type: AttributeTypes, tag: string, key: string, equal?: string, value?: string, quotes?: [string?, string?], config?: import("../index").Config, accum?: Token[]);
61
61
  /**
62
62
  * @override
63
63
  * @browser
@@ -77,7 +77,7 @@ declare abstract class AttributeToken extends AttributeToken_base {
77
77
  * @override
78
78
  * @browser
79
79
  */
80
- lint(start?: number): Parser.LintError[];
80
+ lint(start?: number): LintError[];
81
81
  /**
82
82
  * 获取属性值
83
83
  * @browser
@@ -99,8 +99,8 @@ declare abstract class AttributeToken extends AttributeToken_base {
99
99
  * 修改属性名
100
100
  * @param key 新属性名
101
101
  * @throws `Error` title属性不能更名
102
- * @throws `SyntaxError` 非法的模板参数名
102
+ * @throws `SyntaxError` 非法的标签属性名
103
103
  */
104
104
  rename(key: string): void;
105
105
  }
106
- export = AttributeToken;
106
+ export {};