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,23 +1,26 @@
1
1
  "use strict";
2
- const Parser = require("../index");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fixed = void 0;
4
+ const index_1 = require("../index");
3
5
  /**
4
6
  * 不可增删子节点的类
5
7
  * @param constructor 基类
6
8
  */
9
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
7
10
  const fixed = (constructor) => {
8
11
  /** 不可增删子节点的类 */
9
12
  class FixedToken extends constructor {
10
13
  static fixed = true;
11
14
  /**
12
15
  * @override
13
- * @throws `Error`
16
+ * @throws `Error` 不可用
14
17
  */
15
18
  removeAt() {
16
19
  throw new Error(`${this.constructor.name} 不可删除元素!`);
17
20
  }
18
21
  /** @ignore */
19
22
  insertAt(token, i = this.length) {
20
- if (Parser.running) {
23
+ if (index_1.default.running) {
21
24
  return super.insertAt(token, i);
22
25
  }
23
26
  throw new Error(`${this.constructor.name} 不可插入元素!`);
@@ -25,5 +28,5 @@ const fixed = (constructor) => {
25
28
  }
26
29
  return FixedToken;
27
30
  };
28
- Parser.mixins['fixed'] = __filename;
29
- module.exports = fixed;
31
+ exports.fixed = fixed;
32
+ index_1.default.mixins['fixed'] = __filename;
@@ -1,19 +1,23 @@
1
1
  "use strict";
2
- const Parser = require("../index");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hidden = void 0;
4
+ const index_1 = require("../index");
3
5
  /**
4
6
  * 解析后不可见的类
5
7
  * @param constructor 基类
6
8
  */
9
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
7
10
  const hidden = (constructor) => {
8
11
  /** 解析后不可见的类 */
9
12
  class AnyHiddenToken extends constructor {
10
13
  static hidden = true;
11
14
  /** 没有可见部分 */
15
+ // eslint-disable-next-line class-methods-use-this
12
16
  text() {
13
17
  return '';
14
18
  }
15
19
  }
16
20
  return AnyHiddenToken;
17
21
  };
18
- Parser.mixins['hidden'] = __filename;
19
- module.exports = hidden;
22
+ exports.hidden = hidden;
23
+ index_1.default.mixins['hidden'] = __filename;
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
- const Parser = require("../index");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.singleLine = void 0;
4
+ const index_1 = require("../index");
3
5
  /**
4
6
  * 不可包含换行符的类
5
7
  * @param constructor 基类
6
8
  */
9
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
7
10
  const singleLine = (constructor) => {
8
11
  /** 不可包含换行符的类 */
9
12
  class SingleLineToken extends constructor {
@@ -19,5 +22,5 @@ const singleLine = (constructor) => {
19
22
  Object.defineProperty(SingleLineToken, 'name', { value: `SingleLine${constructor.name}` });
20
23
  return SingleLineToken;
21
24
  };
22
- Parser.mixins['singleLine'] = __filename;
23
- module.exports = singleLine;
25
+ exports.singleLine = singleLine;
26
+ index_1.default.mixins['singleLine'] = __filename;
package/dist/mixin/sol.js CHANGED
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
- const Parser = require("../index");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sol = void 0;
4
+ const index_1 = require("../index");
3
5
  /**
4
6
  * 只能位于行首的类
5
7
  * @param constructor 基类
6
8
  */
9
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
7
10
  const sol = (constructor) => {
8
11
  /** 只能位于行首的类 */
9
12
  class SolToken extends constructor {
@@ -37,5 +40,5 @@ const sol = (constructor) => {
37
40
  }
38
41
  return SolToken;
39
42
  };
40
- Parser.mixins['sol'] = __filename;
41
- module.exports = sol;
43
+ exports.sol = sol;
44
+ index_1.default.mixins['sol'] = __filename;
@@ -1,42 +1,48 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseBraces = void 0;
2
4
  const string_1 = require("../util/string");
3
- const Parser = require("../index");
4
- const HeadingToken = require("../src/heading");
5
- const TranscludeToken = require("../src/transclude");
6
- const ArgToken = require("../src/arg");
5
+ const index_1 = require("../index");
6
+ const heading_1 = require("../src/heading");
7
+ const transclude_1 = require("../src/transclude");
8
+ const arg_1 = require("../src/arg");
7
9
  /**
8
10
  * 解析花括号
11
+ * @param wikitext
12
+ * @param config
13
+ * @param accum
9
14
  * @throws TranscludeToken.constructor()
10
15
  */
11
- const parseBrackets = (wikitext, config = Parser.getConfig(), accum = []) => {
12
- const source = `${config.excludes?.includes('heading') ? '' : '^(\0\\d+c\x7F)*={1,6}|'}\\[\\[|\\{{2,}|-\\{(?!\\{)`, { parserFunction: [, , , subst] } = config, stack = [], closes = { '=': '\n', '{': '\\}{2,}|\\|', '-': '\\}-', '[': '\\]\\]' }, marks = { '!': '!', '!!': '+', '(!': '{', '!)': '}', '!-': '-', '=': '~' };
13
- let text = wikitext, regex = new RegExp(source, 'gmu'), mt = regex.exec(text), moreBraces = text.includes('}}'), lastIndex;
14
- while (mt || Number(lastIndex) <= text.length && stack.at(-1)?.[0]?.startsWith('=')) {
16
+ const parseBraces = (wikitext, config = index_1.default.getConfig(), accum = []) => {
17
+ const source = `${config.excludes?.includes('heading') ? '' : '^(\0\\d+c\x7F)*={1,6}|'}\\[\\[|\\{{2,}|-\\{(?!\\{)`, { parserFunction: [, , , subst] } = config, stack = [], closes = { '=': '\n', '{': '\\}{2,}|\\|', '-': '\\}-', '[': '\\]\\]' }, marks = new Map([['!', '!'], ['!!', '+'], ['(!', '{'], ['!)', '}'], ['!-', '-'], ['=', '~']]);
18
+ let regex = new RegExp(source, 'gmu'), mt = regex.exec(wikitext), moreBraces = wikitext.includes('}}'), lastIndex;
19
+ while (mt || lastIndex !== undefined && lastIndex <= wikitext.length && stack.at(-1)?.[0]?.startsWith('=')) {
15
20
  if (mt?.[1]) {
16
21
  const [, { length }] = mt;
17
22
  mt[0] = mt[0].slice(length);
18
23
  mt.index += length;
19
24
  }
20
- const { 0: syntax, index: curIndex } = mt ?? { 0: '\n', index: text.length }, top = stack.pop() ?? {}, { 0: open, index, parts, findEqual: topFindEqual, pos: topPos } = top, innerEqual = syntax === '=' && topFindEqual;
25
+ const { 0: syntax, index: curIndex } = mt ?? { 0: '\n', index: wikitext.length }, top = stack.pop() ?? {}, { 0: open, index, parts, findEqual: topFindEqual, pos: topPos } = top, innerEqual = syntax === '=' && topFindEqual;
21
26
  if (syntax === ']]' || syntax === '}-') { // 情形1:闭合内链或转换
22
27
  lastIndex = curIndex + 2;
23
28
  }
24
29
  else if (syntax === '\n') { // 情形2:闭合标题或文末
25
30
  lastIndex = curIndex + 1;
26
31
  const { pos, findEqual } = stack.at(-1) ?? {};
27
- if (pos === undefined || findEqual || (0, string_1.removeComment)(text.slice(pos, index)) !== '') {
32
+ if (pos === undefined || findEqual || (0, string_1.removeComment)(wikitext.slice(pos, index)) !== '') {
28
33
  const rmt = /^(={1,6})(.+)\1((?:\s|\0\d+c\x7F)*)$/u
29
- .exec(text.slice(index, curIndex));
34
+ .exec(wikitext.slice(index, curIndex));
30
35
  if (rmt) {
31
- text = `${text.slice(0, index)}\0${accum.length}h\x7F${text.slice(curIndex)}`;
36
+ wikitext = `${wikitext.slice(0, index)}\0${accum.length}h\x7F${wikitext.slice(curIndex)}`;
32
37
  lastIndex = index + 4 + String(accum.length).length;
33
- new HeadingToken(rmt[1].length, rmt.slice(2), config, accum);
38
+ // @ts-expect-error abstract class
39
+ new heading_1.HeadingToken(rmt[1].length, rmt.slice(2), config, accum);
34
40
  }
35
41
  }
36
42
  }
37
43
  else if (syntax === '|' || innerEqual) { // 情形3:模板内部,含行首单个'='
38
44
  lastIndex = curIndex + 1;
39
- parts.at(-1).push(text.slice(topPos, curIndex));
45
+ parts.at(-1).push(wikitext.slice(topPos, curIndex));
40
46
  if (syntax === '|') {
41
47
  parts.push([]);
42
48
  }
@@ -47,21 +53,23 @@ const parseBrackets = (wikitext, config = Parser.getConfig(), accum = []) => {
47
53
  else if (syntax.startsWith('}}')) { // 情形4:闭合模板
48
54
  const close = syntax.slice(0, Math.min(open.length, 3)), rest = open.length - close.length, { length } = accum;
49
55
  lastIndex = curIndex + close.length; // 这不是最终的lastIndex
50
- parts.at(-1).push(text.slice(topPos, curIndex));
56
+ parts.at(-1).push(wikitext.slice(topPos, curIndex));
51
57
  let skip = false, ch = 't';
52
58
  if (close.length === 3) {
53
59
  const argParts = parts.map(part => part.join('=')), str = argParts.length > 1 && (0, string_1.removeComment)(argParts[1]).trim();
54
- new ArgToken(argParts, config, accum);
60
+ // @ts-expect-error abstract class
61
+ new arg_1.ArgToken(argParts, config, accum);
55
62
  if (str && str.endsWith(':') && subst.includes(str.slice(0, -1).toLowerCase())) {
56
63
  ch = 's';
57
64
  }
58
65
  }
59
66
  else {
60
67
  try {
61
- new TranscludeToken(parts[0][0], parts.slice(1), config, accum);
68
+ // @ts-expect-error absstract class
69
+ new transclude_1.TranscludeToken(parts[0][0], parts.slice(1), config, accum);
62
70
  const name = (0, string_1.removeComment)(parts[0][0]).trim();
63
- if (Object.hasOwn(marks, name)) {
64
- ch = marks[name]; // 标记{{!}}等
71
+ if (marks.has(name)) {
72
+ ch = marks.get(name); // 标记{{!}}等
65
73
  }
66
74
  else if (/^(?:filepath|(?:full|canonical)urle?):.|^server$/iu.test(name)) {
67
75
  ch = 'm';
@@ -81,12 +89,12 @@ const parseBrackets = (wikitext, config = Parser.getConfig(), accum = []) => {
81
89
  }
82
90
  }
83
91
  if (!skip) {
84
- text = `${text.slice(0, index + rest)}\0${length}${ch}\x7F${text.slice(lastIndex)}`;
92
+ wikitext = `${wikitext.slice(0, index + rest)}\0${length}${ch}\x7F${wikitext.slice(lastIndex)}`;
85
93
  lastIndex = index + rest + 3 + String(length).length;
86
94
  if (rest > 1) {
87
95
  stack.push({ 0: open.slice(0, rest), index: index, pos: index + rest, parts: [[]] });
88
96
  }
89
- else if (rest === 1 && text[index - 1] === '-') {
97
+ else if (rest === 1 && wikitext[index - 1] === '-') {
90
98
  stack.push({ 0: '-{', index: index - 1, pos: index + 1, parts: [[]] });
91
99
  }
92
100
  }
@@ -99,7 +107,7 @@ const parseBrackets = (wikitext, config = Parser.getConfig(), accum = []) => {
99
107
  }
100
108
  stack.push(...'0' in top ? [top] : [], mt);
101
109
  }
102
- moreBraces &&= text.slice(lastIndex).includes('}}');
110
+ moreBraces &&= wikitext.slice(lastIndex).includes('}}');
103
111
  let curTop = stack.at(-1);
104
112
  if (!moreBraces && curTop?.[0]?.startsWith('{')) {
105
113
  stack.pop();
@@ -109,9 +117,9 @@ const parseBrackets = (wikitext, config = Parser.getConfig(), accum = []) => {
109
117
  ? `|${closes[curTop[0][0]]}${curTop.findEqual ? '|=' : ''}`
110
118
  : ''), 'gmu');
111
119
  regex.lastIndex = lastIndex;
112
- mt = regex.exec(text);
120
+ mt = regex.exec(wikitext);
113
121
  }
114
- return text;
122
+ return wikitext;
115
123
  };
116
- Parser.parsers['parseBrackets'] = __filename;
117
- module.exports = parseBrackets;
124
+ exports.parseBraces = parseBraces;
125
+ index_1.default.parsers['parseBraces'] = __filename;
@@ -1,23 +1,29 @@
1
1
  "use strict";
2
- const Parser = require("../index");
3
- const OnlyincludeToken = require("../src/onlyinclude");
4
- const NoincludeToken = require("../src/nowiki/noinclude");
5
- const IncludeToken = require("../src/tagPair/include");
6
- const ExtToken = require("../src/tagPair/ext");
7
- const CommentToken = require("../src/nowiki/comment");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseCommentAndExt = void 0;
4
+ const index_1 = require("../index");
5
+ const onlyinclude_1 = require("../src/onlyinclude");
6
+ const noinclude_1 = require("../src/nowiki/noinclude");
7
+ const include_1 = require("../src/tagPair/include");
8
+ const ext_1 = require("../src/tagPair/ext");
9
+ const comment_1 = require("../src/nowiki/comment");
8
10
  /**
9
11
  * 解析HTML注释和扩展标签
12
+ * @param wikitext
13
+ * @param config
14
+ * @param accum
10
15
  * @param includeOnly 是否嵌入
11
16
  */
12
- const parseCommentAndExt = (wikitext, config = Parser.getConfig(), accum = [], includeOnly = false) => {
17
+ const parseCommentAndExt = (wikitext, config = index_1.default.getConfig(), accum = [], includeOnly = false) => {
13
18
  const onlyinclude = /<onlyinclude>(.*?)<\/onlyinclude>/gsu;
14
19
  if (includeOnly && wikitext.search(onlyinclude) !== -1) { // `<onlyinclude>`拥有最高优先级
15
20
  return wikitext.replace(onlyinclude, (_, inner) => {
16
21
  const str = `\0${accum.length}e\x7F`;
17
- new OnlyincludeToken(inner, config, accum);
22
+ new onlyinclude_1.OnlyincludeToken(inner, config, accum);
18
23
  return str;
19
24
  }).replace(/(?<=^|\0\d+e\x7F)[^\0]+(?=$|\0\d+e\x7F)/gu, substr => {
20
- new NoincludeToken(substr, config, accum);
25
+ // @ts-expect-error abstract class
26
+ new noinclude_1.NoincludeToken(substr, config, accum);
21
27
  return `\0${accum.length - 1}c\x7F`;
22
28
  });
23
29
  }
@@ -29,20 +35,24 @@ const parseCommentAndExt = (wikitext, config = Parser.getConfig(), accum = [], i
29
35
  return wikitext.replace(regex, (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
30
36
  const str = `\0${accum.length}${name ? 'e' : 'c'}\x7F`;
31
37
  if (name) {
32
- new ExtToken(name, attr, inner, closing, config, accum);
38
+ // @ts-expect-error abstract class
39
+ new ext_1.ExtToken(name, attr, inner, closing, config, accum);
33
40
  }
34
41
  else if (substr.startsWith('<!--')) {
35
42
  const closed = substr.endsWith('-->');
36
- new CommentToken(substr.slice(4, closed ? -3 : undefined), closed, config, accum);
43
+ // @ts-expect-error abstract class
44
+ new comment_1.CommentToken(substr.slice(4, closed ? -3 : undefined), closed, config, accum);
37
45
  }
38
46
  else if (include) {
39
- new IncludeToken(include, includeAttr, includeInner, includeClosing, config, accum);
47
+ // @ts-expect-error abstract class
48
+ new include_1.IncludeToken(include, includeAttr, includeInner, includeClosing, config, accum);
40
49
  }
41
50
  else {
42
- new NoincludeToken(substr, config, accum);
51
+ // @ts-expect-error abstract class
52
+ new noinclude_1.NoincludeToken(substr, config, accum);
43
53
  }
44
54
  return str;
45
55
  });
46
56
  };
47
- Parser.parsers['parseCommentAndExt'] = __filename;
48
- module.exports = parseCommentAndExt;
57
+ exports.parseCommentAndExt = parseCommentAndExt;
58
+ index_1.default.parsers['parseCommentAndExt'] = __filename;
@@ -1,17 +1,24 @@
1
1
  "use strict";
2
- const Parser = require("../index");
3
- const ConverterToken = require("../src/converter");
4
- /** 解析语言变体转换 */
5
- const parseConverter = (wikitext, config = Parser.getConfig(), accum = []) => {
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseConverter = void 0;
4
+ const index_1 = require("../index");
5
+ const converter_1 = require("../src/converter");
6
+ /**
7
+ * 解析语言变体转换
8
+ * @param wikitext
9
+ * @param config
10
+ * @param accum
11
+ */
12
+ const parseConverter = (wikitext, config = index_1.default.getConfig(), accum = []) => {
6
13
  const regex1 = /-\{/gu, regex2 = /-\{|\}-/gu, stack = [];
7
14
  let regex = regex1, text = wikitext, mt = regex.exec(text);
8
15
  while (mt) {
9
16
  const { 0: syntax, index } = mt;
10
17
  if (syntax === '}-') {
11
- const top = stack.pop(), { length } = accum, str = text.slice(top.index + 2, index), i = str.indexOf('|'), [flags, raw] = i === -1 ? [[], str] : [str.slice(0, i).split(';'), str.slice(i + 1)], temp = raw.replace(/(&[#a-z\d]+);/giu, '$1\x01'), // eslint-disable-line regexp/prefer-lookaround
12
- variants = `(?:${config.variants.join('|')})`, rules = temp.split(new RegExp(`;(?=\\s*(?:${variants}|[^;]*?=>\\s*${variants})\\s*:)`, 'u'))
18
+ const top = stack.pop(), { length } = accum, str = text.slice(top.index + 2, index), i = str.indexOf('|'), [flags, raw] = i === -1 ? [[], str] : [str.slice(0, i).split(';'), str.slice(i + 1)], temp = raw.replace(/(&[#a-z\d]+);/giu, '$1\x01'), variants = `(?:${config.variants.join('|')})`, rules = temp.split(new RegExp(`;(?=\\s*(?:${variants}|[^;]*?=>\\s*${variants})\\s*:)`, 'u'))
13
19
  .map(rule => rule.replaceAll('\x01', ';'));
14
- new ConverterToken(flags, rules, config, accum);
20
+ // @ts-expect-error abstract class
21
+ new converter_1.ConverterToken(flags, rules, config, accum);
15
22
  text = `${text.slice(0, top.index)}\0${length}v\x7F${text.slice(index + 2)}`;
16
23
  if (stack.length === 0) {
17
24
  regex = regex1;
@@ -27,5 +34,5 @@ const parseConverter = (wikitext, config = Parser.getConfig(), accum = []) => {
27
34
  }
28
35
  return text;
29
36
  };
30
- Parser.parsers['parseConverter'] = __filename;
31
- module.exports = parseConverter;
37
+ exports.parseConverter = parseConverter;
38
+ index_1.default.parsers['parseConverter'] = __filename;
@@ -1,22 +1,28 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseExternalLinks = void 0;
2
4
  const string_1 = require("../util/string");
3
- const Parser = require("../index");
4
- const ExtLinkToken = require("../src/extLink");
5
- /** 解析外部链接 */
6
- const parseExternalLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
5
+ const index_1 = require("../index");
6
+ const extLink_1 = require("../src/extLink");
7
+ /**
8
+ * 解析外部链接
9
+ * @param wikitext
10
+ * @param config
11
+ * @param accum
12
+ */
13
+ const parseExternalLinks = (wikitext, config = index_1.default.getConfig(), accum = []) => {
7
14
  const regex = new RegExp(`\\[((?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\\d+m\x7F)${string_1.extUrlChar})(\\p{Zs}*)([^\\]\x01-\x08\x0A-\x1F\uFFFD]*)\\]`, 'giu');
8
15
  return wikitext.replace(regex, (_, url, space, text) => {
9
16
  const { length } = accum, mt = /&[lg]t;/u.exec(url);
10
17
  if (mt) {
11
- /* eslint-disable no-param-reassign */
12
18
  url = url.slice(0, mt.index);
13
19
  space = '';
14
20
  text = `${url.slice(mt.index)}${space}${text}`;
15
- /* eslint-enable no-param-reassign */
16
21
  }
17
- new ExtLinkToken(url, space, text, config, accum);
22
+ // @ts-expect-error abstract class
23
+ new extLink_1.ExtLinkToken(url, space, text, config, accum);
18
24
  return `\0${length}w\x7F`;
19
25
  });
20
26
  };
21
- Parser.parsers['parseExternalLinks'] = __filename;
22
- module.exports = parseExternalLinks;
27
+ exports.parseExternalLinks = parseExternalLinks;
28
+ index_1.default.parsers['parseExternalLinks'] = __filename;
@@ -1,33 +1,40 @@
1
1
  "use strict";
2
- const Parser = require("../index");
3
- const HrToken = require("../src/nowiki/hr");
4
- const DoubleUnderscoreToken = require("../src/nowiki/doubleUnderscore");
5
- const HeadingToken = require("../src/heading");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseHrAndDoubleUnderscore = void 0;
4
+ const index_1 = require("../index");
5
+ const hr_1 = require("../src/nowiki/hr");
6
+ const doubleUnderscore_1 = require("../src/nowiki/doubleUnderscore");
7
+ const heading_1 = require("../src/heading");
6
8
  /**
7
9
  * 解析`<hr>`和状态开关
8
10
  * @param {Token} root 根节点
11
+ * @param config
12
+ * @param accum
9
13
  */
10
- const parseHrAndDoubleUnderscore = ({ firstChild, type, name }, config = Parser.getConfig(), accum = []) => {
14
+ const parseHrAndDoubleUnderscore = ({ firstChild, type, name }, config = index_1.default.getConfig(), accum = []) => {
11
15
  const { doubleUnderscore } = config, insensitive = new Set(doubleUnderscore[0]), sensitive = new Set(doubleUnderscore[1]);
12
16
  let { data } = firstChild;
13
17
  if (type !== 'root' && (type !== 'ext-inner' || name !== 'poem')) {
14
18
  data = `\0${data}`;
15
19
  }
16
20
  data = data.replace(/^((?:\0\d+c\x7F)*)(-{4,})/gmu, (_, lead, m) => {
17
- new HrToken(m.length, config, accum);
21
+ // @ts-expect-error abstract class
22
+ new hr_1.HrToken(m.length, config, accum);
18
23
  return `${lead}\0${accum.length - 1}r\x7F`;
19
24
  }).replace(new RegExp(`__(${doubleUnderscore.flat().join('|')})__`, 'giu'), (m, p1) => {
20
25
  if (insensitive.has(p1.toLowerCase()) || sensitive.has(p1)) {
21
- new DoubleUnderscoreToken(p1, config, accum);
26
+ // @ts-expect-error abstract class
27
+ new doubleUnderscore_1.DoubleUnderscoreToken(p1, config, accum);
22
28
  return `\0${accum.length - 1}u\x7F`;
23
29
  }
24
30
  return m;
25
31
  }).replace(/^((?:\0\d+c\x7F)*)(={1,6})(.+)\2((?:[^\S\n]|\0\d+c\x7F)*)$/gmu, (_, lead, equals, heading, trail) => {
26
32
  const text = `${lead}\0${accum.length}h\x7F`;
27
- new HeadingToken(equals.length, [heading, trail], config, accum);
33
+ // @ts-expect-error abstract class
34
+ new heading_1.HeadingToken(equals.length, [heading, trail], config, accum);
28
35
  return text;
29
36
  });
30
37
  return type === 'root' || type === 'ext-inner' && name === 'poem' ? data : data.slice(1);
31
38
  };
32
- Parser.parsers['parseHrAndDoubleUnderscore'] = __filename;
33
- module.exports = parseHrAndDoubleUnderscore;
39
+ exports.parseHrAndDoubleUnderscore = parseHrAndDoubleUnderscore;
40
+ index_1.default.parsers['parseHrAndDoubleUnderscore'] = __filename;
@@ -1,9 +1,16 @@
1
1
  "use strict";
2
- const Parser = require("../index");
3
- const AttributesToken = require("../src/attributes");
4
- const HtmlToken = require("../src/html");
5
- /** 解析HTML标签 */
6
- const parseHtml = (wikitext, config = Parser.getConfig(), accum = []) => {
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseHtml = void 0;
4
+ const index_1 = require("../index");
5
+ const attributes_1 = require("../src/attributes");
6
+ const html_1 = require("../src/html");
7
+ /**
8
+ * 解析HTML标签
9
+ * @param wikitext
10
+ * @param config
11
+ * @param accum
12
+ */
13
+ const parseHtml = (wikitext, config = index_1.default.getConfig(), accum = []) => {
7
14
  const regex = /^(\/?)([a-z][^\s/>]*)((?:\s|\/(?!>))[^>]*?)?(\/?>)([^<]*)$/iu, elements = new Set(config.html.flat()), bits = wikitext.split('<');
8
15
  let text = bits.shift();
9
16
  for (const x of bits) {
@@ -13,7 +20,8 @@ const parseHtml = (wikitext, config = Parser.getConfig(), accum = []) => {
13
20
  continue;
14
21
  }
15
22
  const [, slash, , params = '', brace, rest] = mt,
16
- attr = new AttributesToken(params, 'html-attrs', name, config, accum), itemprop = attr.getAttr('itemprop');
23
+ // @ts-expect-error abstract class
24
+ attr = new attributes_1.AttributesToken(params, 'html-attrs', name, config, accum), itemprop = attr.getAttr('itemprop');
17
25
  if (name === 'meta' && (itemprop === undefined || attr.getAttr('content') === undefined)
18
26
  || name === 'link' && (itemprop === undefined || attr.getAttr('href') === undefined)) {
19
27
  text += `<${x}`;
@@ -21,9 +29,10 @@ const parseHtml = (wikitext, config = Parser.getConfig(), accum = []) => {
21
29
  continue;
22
30
  }
23
31
  text += `\0${accum.length}x\x7F${rest}`;
24
- new HtmlToken(t, attr, slash === '/', brace === '/>', config, accum);
32
+ // @ts-expect-error abstract class
33
+ new html_1.HtmlToken(t, attr, slash === '/', brace === '/>', config, accum);
25
34
  }
26
35
  return text;
27
36
  };
28
- Parser.parsers['parseHtml'] = __filename;
29
- module.exports = parseHtml;
37
+ exports.parseHtml = parseHtml;
38
+ index_1.default.parsers['parseHtml'] = __filename;
@@ -1,11 +1,18 @@
1
1
  "use strict";
2
- const Parser = require("../index");
3
- const LinkToken = require("../src/link");
4
- const FileToken = require("../src/link/file");
5
- const CategoryToken = require("../src/link/category");
6
- /** 解析内部链接 */
7
- const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
8
- const parseQuotes = require('./quotes.js');
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseLinks = void 0;
4
+ const index_1 = require("../index");
5
+ const link_1 = require("../src/link");
6
+ const file_1 = require("../src/link/file");
7
+ const category_1 = require("../src/link/category");
8
+ /**
9
+ * 解析内部链接
10
+ * @param wikitext
11
+ * @param config
12
+ * @param accum
13
+ */
14
+ const parseLinks = (wikitext, config = index_1.default.getConfig(), accum = []) => {
15
+ const { parseQuotes } = require('./quotes.js');
9
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('[[');
10
17
  let s = bits.shift();
11
18
  for (let i = 0; i < bits.length; i++) {
@@ -34,7 +41,7 @@ const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
34
41
  s += `[[${x}`;
35
42
  continue;
36
43
  }
37
- const title = Parser.normalizeTitle(link, 0, false, config, true, true, true), { ns, interwiki, valid } = title;
44
+ const title = index_1.default.normalizeTitle(link, 0, false, config, true, true, true), { ns, interwiki, valid } = title;
38
45
  if (!valid) {
39
46
  s += `[[${x}`;
40
47
  continue;
@@ -61,7 +68,7 @@ const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
61
68
  break;
62
69
  }
63
70
  }
64
- text = parseLinks(text, config, accum);
71
+ text = (0, exports.parseLinks)(text, config, accum);
65
72
  if (!found) {
66
73
  s += `[[${link}${delimiter}${text}`;
67
74
  continue;
@@ -69,18 +76,19 @@ const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
69
76
  }
70
77
  text &&= parseQuotes(text, config, accum);
71
78
  s += `\0${accum.length}l\x7F${after}`;
72
- let SomeLinkToken = LinkToken;
79
+ let SomeLinkToken = link_1.LinkToken;
73
80
  if (!force) {
74
81
  if (!interwiki && ns === 6) {
75
- SomeLinkToken = FileToken;
82
+ SomeLinkToken = file_1.FileToken;
76
83
  }
77
84
  else if (!interwiki && ns === 14) {
78
- SomeLinkToken = CategoryToken;
85
+ SomeLinkToken = category_1.CategoryToken;
79
86
  }
80
87
  }
88
+ // @ts-expect-error abstract class
81
89
  new SomeLinkToken(link, text, config, accum, delimiter);
82
90
  }
83
91
  return s;
84
92
  };
85
- Parser.parsers['parseLinks'] = __filename;
86
- module.exports = parseLinks;
93
+ exports.parseLinks = parseLinks;
94
+ index_1.default.parsers['parseLinks'] = __filename;
@@ -1,16 +1,24 @@
1
1
  "use strict";
2
- const Parser = require("../index");
3
- const ListToken = require("../src/nowiki/list");
4
- const DdToken = require("../src/nowiki/dd");
5
- /** 解析列表 */
6
- const parseList = (wikitext, config = Parser.getConfig(), accum = []) => {
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseList = void 0;
4
+ const index_1 = require("../index");
5
+ const list_1 = require("../src/nowiki/list");
6
+ const dd_1 = require("../src/nowiki/dd");
7
+ /**
8
+ * 解析列表
9
+ * @param wikitext
10
+ * @param config
11
+ * @param accum
12
+ */
13
+ const parseList = (wikitext, config = index_1.default.getConfig(), accum = []) => {
7
14
  const mt = /^((?:\0\d+c\x7F)*)([;:*#]+)/u.exec(wikitext);
8
15
  if (!mt) {
9
16
  return wikitext;
10
17
  }
11
18
  const [total, comment, prefix] = mt;
12
19
  let text = `${comment}\0${accum.length}d\x7F${wikitext.slice(total.length)}`, dt = prefix.split(';').length - 1;
13
- new ListToken(prefix, config, accum);
20
+ // @ts-expect-error abstract class
21
+ new list_1.ListToken(prefix, config, accum);
14
22
  if (!dt) {
15
23
  return text;
16
24
  }
@@ -19,13 +27,15 @@ const parseList = (wikitext, config = Parser.getConfig(), accum = []) => {
19
27
  const { 0: syntax, index } = ex;
20
28
  if (syntax.startsWith(':')) {
21
29
  if (syntax.length >= dt) {
22
- new DdToken(':'.repeat(dt), config, accum);
30
+ // @ts-expect-error abstract class
31
+ new dd_1.DdToken(':'.repeat(dt), config, accum);
23
32
  return `${text.slice(0, index)}\0${accum.length - 1}d\x7F${text.slice(index + dt)}`;
24
33
  }
25
34
  text = `${text.slice(0, index)}\0${accum.length}d\x7F${text.slice(regex.lastIndex)}`;
26
35
  dt -= syntax.length;
27
36
  regex.lastIndex = index + 4 + String(accum.length).length;
28
- new DdToken(syntax, config, accum);
37
+ // @ts-expect-error abstract class
38
+ new dd_1.DdToken(syntax, config, accum);
29
39
  }
30
40
  else if (syntax === '-{') {
31
41
  if (!lc) {
@@ -47,5 +57,5 @@ const parseList = (wikitext, config = Parser.getConfig(), accum = []) => {
47
57
  }
48
58
  return text;
49
59
  };
50
- Parser.parsers['parseList'] = __filename;
51
- module.exports = parseList;
60
+ exports.parseList = parseList;
61
+ index_1.default.parsers['parseList'] = __filename;