wikiparser-node 1.9.0 → 1.9.1-b

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 (170) hide show
  1. package/README.en.md +2 -2
  2. package/bundle/bundle.min.js +38 -0
  3. package/config/enwiki.json +1 -814
  4. package/config/llwiki.json +1 -35
  5. package/config/moegirl.json +1 -44
  6. package/config/zhwiki.json +1 -466
  7. package/extensions/dist/base.js +64 -0
  8. package/extensions/dist/editor.js +159 -0
  9. package/extensions/dist/highlight.js +58 -0
  10. package/extensions/dist/lint.js +72 -0
  11. package/extensions/editor.css +64 -0
  12. package/extensions/ui.css +144 -0
  13. package/package.json +38 -28
  14. package/config/.schema.json +0 -181
  15. package/dist/addon/table.js +0 -485
  16. package/dist/addon/token.js +0 -236
  17. package/dist/addon/transclude.js +0 -183
  18. package/dist/base.d.ts +0 -71
  19. package/dist/base.js +0 -39
  20. package/dist/index.d.ts +0 -33
  21. package/dist/index.js +0 -218
  22. package/dist/internal.d.ts +0 -46
  23. package/dist/lib/element.d.ts +0 -129
  24. package/dist/lib/element.js +0 -593
  25. package/dist/lib/node.d.ts +0 -166
  26. package/dist/lib/node.js +0 -480
  27. package/dist/lib/range.d.ts +0 -105
  28. package/dist/lib/range.js +0 -406
  29. package/dist/lib/ranges.d.ts +0 -28
  30. package/dist/lib/ranges.js +0 -126
  31. package/dist/lib/text.d.ts +0 -54
  32. package/dist/lib/text.js +0 -350
  33. package/dist/lib/title.d.ts +0 -40
  34. package/dist/lib/title.js +0 -197
  35. package/dist/mixin/attributesParent.d.ts +0 -49
  36. package/dist/mixin/attributesParent.js +0 -81
  37. package/dist/mixin/fixed.d.ts +0 -5
  38. package/dist/mixin/fixed.js +0 -30
  39. package/dist/mixin/flagsParent.d.ts +0 -41
  40. package/dist/mixin/flagsParent.js +0 -59
  41. package/dist/mixin/hidden.d.ts +0 -4
  42. package/dist/mixin/hidden.js +0 -24
  43. package/dist/mixin/magicLinkParent.d.ts +0 -19
  44. package/dist/mixin/magicLinkParent.js +0 -42
  45. package/dist/mixin/singleLine.d.ts +0 -5
  46. package/dist/mixin/singleLine.js +0 -26
  47. package/dist/mixin/sol.d.ts +0 -5
  48. package/dist/mixin/sol.js +0 -43
  49. package/dist/mixin/syntax.d.ts +0 -8
  50. package/dist/mixin/syntax.js +0 -50
  51. package/dist/parser/braces.js +0 -139
  52. package/dist/parser/commentAndExt.js +0 -89
  53. package/dist/parser/converter.js +0 -40
  54. package/dist/parser/externalLinks.js +0 -44
  55. package/dist/parser/hrAndDoubleUnderscore.js +0 -40
  56. package/dist/parser/html.js +0 -38
  57. package/dist/parser/links.js +0 -99
  58. package/dist/parser/list.js +0 -97
  59. package/dist/parser/magicLinks.js +0 -59
  60. package/dist/parser/quotes.js +0 -67
  61. package/dist/parser/redirect.js +0 -26
  62. package/dist/parser/selector.js +0 -190
  63. package/dist/parser/table.js +0 -123
  64. package/dist/src/arg.d.ts +0 -54
  65. package/dist/src/arg.js +0 -214
  66. package/dist/src/atom.d.ts +0 -12
  67. package/dist/src/atom.js +0 -27
  68. package/dist/src/attribute.d.ts +0 -67
  69. package/dist/src/attribute.js +0 -502
  70. package/dist/src/attributes.d.ts +0 -105
  71. package/dist/src/attributes.js +0 -356
  72. package/dist/src/converter.d.ts +0 -31
  73. package/dist/src/converter.js +0 -134
  74. package/dist/src/converterFlags.d.ts +0 -83
  75. package/dist/src/converterFlags.js +0 -242
  76. package/dist/src/converterRule.d.ts +0 -75
  77. package/dist/src/converterRule.js +0 -209
  78. package/dist/src/extLink.d.ts +0 -39
  79. package/dist/src/extLink.js +0 -191
  80. package/dist/src/gallery.d.ts +0 -50
  81. package/dist/src/gallery.js +0 -139
  82. package/dist/src/heading.d.ts +0 -43
  83. package/dist/src/heading.js +0 -190
  84. package/dist/src/hidden.d.ts +0 -7
  85. package/dist/src/hidden.js +0 -23
  86. package/dist/src/html.d.ts +0 -61
  87. package/dist/src/html.js +0 -358
  88. package/dist/src/imageParameter.d.ts +0 -61
  89. package/dist/src/imageParameter.js +0 -257
  90. package/dist/src/imagemap.d.ts +0 -50
  91. package/dist/src/imagemap.js +0 -144
  92. package/dist/src/imagemapLink.d.ts +0 -31
  93. package/dist/src/imagemapLink.js +0 -93
  94. package/dist/src/index.d.ts +0 -142
  95. package/dist/src/index.js +0 -717
  96. package/dist/src/link/base.d.ts +0 -48
  97. package/dist/src/link/base.js +0 -228
  98. package/dist/src/link/category.d.ts +0 -22
  99. package/dist/src/link/category.js +0 -30
  100. package/dist/src/link/file.d.ts +0 -96
  101. package/dist/src/link/file.js +0 -272
  102. package/dist/src/link/galleryImage.d.ts +0 -30
  103. package/dist/src/link/galleryImage.js +0 -157
  104. package/dist/src/link/index.d.ts +0 -54
  105. package/dist/src/link/index.js +0 -133
  106. package/dist/src/link/redirectTarget.d.ts +0 -49
  107. package/dist/src/link/redirectTarget.js +0 -101
  108. package/dist/src/magicLink.d.ts +0 -59
  109. package/dist/src/magicLink.js +0 -261
  110. package/dist/src/nested.d.ts +0 -41
  111. package/dist/src/nested.js +0 -105
  112. package/dist/src/nowiki/base.d.ts +0 -31
  113. package/dist/src/nowiki/base.js +0 -93
  114. package/dist/src/nowiki/comment.d.ts +0 -21
  115. package/dist/src/nowiki/comment.js +0 -76
  116. package/dist/src/nowiki/dd.d.ts +0 -8
  117. package/dist/src/nowiki/dd.js +0 -24
  118. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -16
  119. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  120. package/dist/src/nowiki/hr.d.ts +0 -5
  121. package/dist/src/nowiki/hr.js +0 -63
  122. package/dist/src/nowiki/index.d.ts +0 -14
  123. package/dist/src/nowiki/index.js +0 -27
  124. package/dist/src/nowiki/list.d.ts +0 -16
  125. package/dist/src/nowiki/list.js +0 -109
  126. package/dist/src/nowiki/listBase.d.ts +0 -5
  127. package/dist/src/nowiki/listBase.js +0 -61
  128. package/dist/src/nowiki/noinclude.d.ts +0 -10
  129. package/dist/src/nowiki/noinclude.js +0 -23
  130. package/dist/src/nowiki/quote.d.ts +0 -17
  131. package/dist/src/nowiki/quote.js +0 -137
  132. package/dist/src/onlyinclude.d.ts +0 -14
  133. package/dist/src/onlyinclude.js +0 -57
  134. package/dist/src/paramTag/index.d.ts +0 -33
  135. package/dist/src/paramTag/index.js +0 -77
  136. package/dist/src/paramTag/inputbox.d.ts +0 -8
  137. package/dist/src/paramTag/inputbox.js +0 -22
  138. package/dist/src/parameter.d.ts +0 -66
  139. package/dist/src/parameter.js +0 -264
  140. package/dist/src/pre.d.ts +0 -29
  141. package/dist/src/pre.js +0 -59
  142. package/dist/src/redirect.d.ts +0 -28
  143. package/dist/src/redirect.js +0 -119
  144. package/dist/src/syntax.d.ts +0 -17
  145. package/dist/src/syntax.js +0 -86
  146. package/dist/src/table/base.d.ts +0 -27
  147. package/dist/src/table/base.js +0 -81
  148. package/dist/src/table/index.d.ts +0 -240
  149. package/dist/src/table/index.js +0 -498
  150. package/dist/src/table/td.d.ts +0 -82
  151. package/dist/src/table/td.js +0 -358
  152. package/dist/src/table/tr.d.ts +0 -32
  153. package/dist/src/table/tr.js +0 -58
  154. package/dist/src/table/trBase.d.ts +0 -51
  155. package/dist/src/table/trBase.js +0 -156
  156. package/dist/src/tagPair/ext.d.ts +0 -30
  157. package/dist/src/tagPair/ext.js +0 -203
  158. package/dist/src/tagPair/include.d.ts +0 -33
  159. package/dist/src/tagPair/include.js +0 -74
  160. package/dist/src/tagPair/index.d.ts +0 -25
  161. package/dist/src/tagPair/index.js +0 -128
  162. package/dist/src/transclude.d.ts +0 -162
  163. package/dist/src/transclude.js +0 -584
  164. package/dist/util/constants.js +0 -27
  165. package/dist/util/debug.js +0 -81
  166. package/dist/util/diff.js +0 -83
  167. package/dist/util/lint.js +0 -31
  168. package/dist/util/string.js +0 -60
  169. package/errors/README +0 -1
  170. package/printed/README +0 -1
@@ -1,236 +0,0 @@
1
- "use strict";
2
- /* eslint @stylistic/operator-linebreak: [2, "before", {overrides: {"=": "after"}}] */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const constants_1 = require("../util/constants");
5
- const debug_1 = require("../util/debug");
6
- const index_1 = require("../src/index");
7
- const comment_1 = require("../src/nowiki/comment");
8
- const include_1 = require("../src/tagPair/include");
9
- const ext_1 = require("../src/tagPair/ext");
10
- const html_1 = require("../src/html");
11
- const attributes_1 = require("../src/attributes");
12
- index_1.Token.prototype.createComment =
13
- /** @implements */
14
- function (data = '') {
15
- const config = this.getAttribute('config');
16
- // @ts-expect-error abstract class
17
- return debug_1.Shadow.run(() => new comment_1.CommentToken(data.replace(/-->/gu, '-->'), true, config));
18
- };
19
- index_1.Token.prototype.createElement =
20
- /** @implements */
21
- function (tagName, { selfClosing, closing } = {}) {
22
- const config = this.getAttribute('config'), include = this.getAttribute('include');
23
- if (tagName === (include ? 'noinclude' : 'includeonly')) {
24
- return debug_1.Shadow.run(
25
- // @ts-expect-error abstract class
26
- () => new include_1.IncludeToken(tagName, '', undefined, selfClosing ? undefined : tagName, config));
27
- }
28
- else if (config.ext.includes(tagName)) {
29
- // @ts-expect-error abstract class
30
- return debug_1.Shadow.run(() => new ext_1.ExtToken(tagName, '', undefined, selfClosing ? undefined : '', config));
31
- }
32
- else if (config.html.flat().includes(tagName)) {
33
- return debug_1.Shadow.run(() => {
34
- // @ts-expect-error abstract class
35
- const attr = new attributes_1.AttributesToken(undefined, 'html-attrs', tagName, config);
36
- // @ts-expect-error abstract class
37
- return new html_1.HtmlToken(tagName, attr, Boolean(closing), Boolean(selfClosing), config);
38
- });
39
- }
40
- throw new RangeError(`非法的标签名:${tagName}`);
41
- };
42
- index_1.Token.prototype.caretPositionFromIndex =
43
- /** @implements */
44
- function (index) {
45
- if (index === undefined) {
46
- return undefined;
47
- }
48
- const { length } = this.toString();
49
- if (index >= length || index < -length) {
50
- return undefined;
51
- }
52
- index += index < 0 ? length : 0;
53
- let self = this, acc = 0, start = 0;
54
- while (self.type !== 'text') {
55
- const { childNodes } = self;
56
- acc += self.getAttribute('padding');
57
- for (let i = 0; acc <= index && i < childNodes.length; i++) {
58
- const cur = childNodes[i], l = cur.toString().length;
59
- acc += l;
60
- if (acc > index) {
61
- self = cur;
62
- acc -= l;
63
- start = acc;
64
- break;
65
- }
66
- acc += self.getGaps(i);
67
- }
68
- if (self.childNodes === childNodes) {
69
- return { offsetNode: self, offset: index - start };
70
- }
71
- }
72
- return { offsetNode: self, offset: index - start };
73
- };
74
- index_1.Token.prototype.sections =
75
- /** @implements */
76
- function () {
77
- if (this.type !== 'root') {
78
- return undefined;
79
- }
80
- const { childNodes, length } = this, headings = [...childNodes.entries()]
81
- .filter((entry) => entry[1].type === 'heading')
82
- .map(([i, { level }]) => [i, level]), lastHeading = [-1, -1, -1, -1, -1, -1], sections = headings.map(([i]) => {
83
- const range = this.createRange();
84
- range.setStart(this, i);
85
- return range;
86
- });
87
- for (let i = 0; i < headings.length; i++) {
88
- const [index, level] = headings[i];
89
- for (let j = level; j < 6; j++) {
90
- const last = lastHeading[j];
91
- if (last >= 0) {
92
- sections[last].setEnd(this, index);
93
- }
94
- lastHeading[j] = j === level ? i : -1;
95
- }
96
- }
97
- for (const last of lastHeading) {
98
- if (last >= 0) {
99
- sections[last].setEnd(this, length);
100
- }
101
- }
102
- const range = this.createRange();
103
- range.setStart(this, 0);
104
- range.setEnd(this, headings[0]?.[0] ?? length);
105
- sections.unshift(range);
106
- return sections;
107
- };
108
- index_1.Token.prototype.findEnclosingHtml =
109
- /** @implements */
110
- function (tag) {
111
- tag = tag?.toLowerCase();
112
- const { html } = this.getAttribute('config'), normalTags = new Set(html[0]), voidTags = new Set(html[2]);
113
- if (tag !== undefined && !html.slice(0, 2).flat().includes(tag)) {
114
- throw new RangeError(`非法的标签或空标签:${tag}`);
115
- }
116
- const { parentNode } = this;
117
- if (!parentNode) {
118
- return undefined;
119
- }
120
- const isHtml = (0, debug_1.isToken)('html'),
121
- /**
122
- * 检查是否为指定的 HTML 标签
123
- * @param node 节点
124
- * @param name 标签名
125
- * @param closing 是否为闭合标签
126
- */
127
- checkHtml = (node, name, closing) => isHtml(node)
128
- && (!name && !voidTags.has(node.name) || node.name === name)
129
- && (normalTags.has(node.name) || !node.selfClosing)
130
- && node.closing === closing;
131
- const { childNodes, length } = parentNode, index = childNodes.indexOf(this);
132
- let i = index - 1, j = length;
133
- for (; i >= 0; i--) {
134
- const open = childNodes[i];
135
- if (checkHtml(open, tag, false)) {
136
- for (j = index + 1; j < length; j++) {
137
- const close = childNodes[j];
138
- if (checkHtml(close, open.name, true)) {
139
- break;
140
- }
141
- }
142
- if (j < length) {
143
- break;
144
- }
145
- }
146
- }
147
- if (i === -1) {
148
- return parentNode.findEnclosingHtml(tag);
149
- }
150
- const range = this.createRange();
151
- range.setStart(parentNode, i);
152
- range.setEnd(parentNode, j + 1);
153
- return range;
154
- };
155
- index_1.Token.prototype.redoQuotes =
156
- /** @implements */
157
- function () {
158
- const acceptable = this.getAttribute('acceptable');
159
- if (acceptable && !('QuoteToken' in acceptable)) {
160
- return;
161
- }
162
- const accum = [];
163
- for (const child of this.childNodes) {
164
- if (child.type !== 'quote' && child.type !== 'text') {
165
- child.replaceWith(`\0${accum.length}e\x7F`);
166
- accum.push(child);
167
- }
168
- }
169
- const token = debug_1.Shadow.run(() => {
170
- const node = new index_1.Token(this.toString(), this.getAttribute('config'), accum);
171
- node.setAttribute('stage', 6);
172
- return node.parse(7);
173
- });
174
- this.replaceChildren(...token.childNodes);
175
- };
176
- index_1.Token.prototype.solveConst =
177
- /** @implements */
178
- function () {
179
- const targets = this.querySelectorAll('magic-word, arg'), magicWords = new Set(['if', 'ifeq', 'switch']);
180
- for (let i = targets.length - 1; i >= 0; i--) {
181
- const target = targets[i], { type, name, childNodes, length } = target, [, var1, var2 = ''] = childNodes;
182
- if (type === 'arg' || type === 'magic-word' && magicWords.has(name)) {
183
- let replace = '';
184
- if (type === 'arg') {
185
- replace = target.default === false ? target.toString() : target.default;
186
- }
187
- else if (name === 'if' && !var1?.getElementByTypes('magic-word, template')) {
188
- replace = String(childNodes[String(var1 ?? '').trim() ? 2 : 3] ?? '').trim();
189
- }
190
- else if (name === 'ifeq'
191
- && !childNodes.slice(1, 3).some(child => child.getElementByTypes('magic-word, template'))) {
192
- replace = String(childNodes[String(var1 ?? '').trim() === String(var2).trim() ? 3 : 4] ?? '').trim();
193
- }
194
- else if (name === 'switch' && !var1?.getElementByTypes('magic-word, template')) {
195
- const key = String(var1 ?? '').trim();
196
- let defaultVal = '', found = false, transclusion = false;
197
- for (let j = 2; j < length; j++) {
198
- const { anon, name: option, value, firstChild } = childNodes[j];
199
- transclusion = Boolean(firstChild.getElementByTypes('magic-word, template'));
200
- if (anon) {
201
- if (j === length - 1) {
202
- defaultVal = value;
203
- }
204
- else if (transclusion) {
205
- break;
206
- }
207
- else {
208
- found ||= key === value;
209
- }
210
- }
211
- else if (transclusion) {
212
- break;
213
- }
214
- else if (found || option === key) {
215
- replace = value;
216
- break;
217
- }
218
- else if (option.toLowerCase() === '#default') {
219
- defaultVal = value;
220
- }
221
- if (j === length - 1) {
222
- replace = defaultVal;
223
- }
224
- }
225
- if (transclusion) {
226
- continue;
227
- }
228
- }
229
- else {
230
- continue;
231
- }
232
- target.replaceWith(replace);
233
- }
234
- }
235
- };
236
- constants_1.classes['ExtendedTableToken'] = __filename;
@@ -1,183 +0,0 @@
1
- "use strict";
2
- /* eslint @stylistic/operator-linebreak: [2, "before", {overrides: {"=": "after"}}] */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const constants_1 = require("../util/constants");
5
- const debug_1 = require("../util/debug");
6
- const string_1 = require("../util/string");
7
- const index_1 = require("../index");
8
- const index_2 = require("../src/index");
9
- const transclude_1 = require("../src/transclude");
10
- const parameter_1 = require("../src/parameter");
11
- const atom_1 = require("../src/atom");
12
- transclude_1.TranscludeToken.prototype.newAnonArg =
13
- /** @implements */
14
- function (val) {
15
- const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(val, this.getAttribute('include'), undefined, config),
16
- // @ts-expect-error abstract class
17
- token = debug_1.Shadow.run(() => new parameter_1.ParameterToken(undefined, undefined, config));
18
- token.lastChild.append(...childNodes);
19
- token.afterBuild();
20
- return this.insertAt(token);
21
- };
22
- transclude_1.TranscludeToken.prototype.setValue =
23
- /** @implements */
24
- function (key, value) {
25
- if (!this.isTemplate()) {
26
- throw new Error('setValue 方法仅供模板使用!');
27
- }
28
- const arg = this.getArg(key);
29
- if (arg) {
30
- arg.setValue(value);
31
- return;
32
- }
33
- const include = this.getAttribute('include'), config = this.getAttribute('config'), k = index_1.default.parse(key, include, undefined, config), v = index_1.default.parse(value, include, undefined, config),
34
- // @ts-expect-error abstract class
35
- token = debug_1.Shadow.run(() => new parameter_1.ParameterToken(undefined, undefined, config));
36
- token.firstChild.append(...k.childNodes);
37
- token.lastChild.append(...v.childNodes);
38
- token.afterBuild();
39
- this.insertAt(token);
40
- };
41
- transclude_1.TranscludeToken.prototype.replaceTemplate =
42
- /** @implements */
43
- function (title) {
44
- if (this.type === 'magic-word') {
45
- throw new Error('replaceTemplate 方法仅用于更换模板!');
46
- }
47
- const { childNodes } = index_1.default.parse(title, this.getAttribute('include'), 2, this.getAttribute('config'));
48
- this.firstChild.replaceChildren(...childNodes);
49
- };
50
- transclude_1.TranscludeToken.prototype.replaceModule =
51
- /** @implements */
52
- function (title) {
53
- if (this.type !== 'magic-word' || this.name !== 'invoke') {
54
- throw new Error('replaceModule 方法仅用于更换模块!');
55
- }
56
- const config = this.getAttribute('config');
57
- if (this.length === 1) {
58
- index_2.Token.prototype.insertAt.call(this, new atom_1.AtomToken(undefined, 'invoke-module', config, [], {
59
- 'Stage-1': ':', '!ExtToken': '',
60
- }));
61
- return;
62
- }
63
- const { childNodes } = index_1.default.parse(title, this.getAttribute('include'), 2, config);
64
- this.childNodes[1].replaceChildren(...childNodes);
65
- };
66
- transclude_1.TranscludeToken.prototype.replaceFunction =
67
- /** @implements */
68
- function (func) {
69
- if (this.type !== 'magic-word' || this.name !== 'invoke') {
70
- throw new Error('replaceModule 方法仅用于更换模块!');
71
- }
72
- else if (this.length < 2) {
73
- throw new Error('尚未指定模块名称!');
74
- }
75
- const config = this.getAttribute('config');
76
- if (this.length === 2) {
77
- index_2.Token.prototype.insertAt.call(this, new atom_1.AtomToken(undefined, 'invoke-function', config, [], {
78
- 'Stage-1': ':', '!ExtToken': '',
79
- }));
80
- return;
81
- }
82
- const { childNodes } = index_1.default.parse(func, this.getAttribute('include'), 2, config);
83
- this.childNodes[2].replaceChildren(...childNodes);
84
- };
85
- transclude_1.TranscludeToken.prototype.fixDuplication =
86
- /** @implements */
87
- function (aggressive) {
88
- if (!this.hasDuplicatedArgs()) {
89
- return [];
90
- }
91
- const duplicatedKeys = [];
92
- let anonCount = this.getAnonArgs().length;
93
- for (const [key, args] of this.getDuplicatedArgs()) {
94
- if (args.length <= 1) {
95
- continue;
96
- }
97
- const values = new Map();
98
- for (const arg of args) {
99
- const val = arg.getValue().trim();
100
- if (values.has(val)) {
101
- values.get(val).push(arg);
102
- }
103
- else {
104
- values.set(val, [arg]);
105
- }
106
- }
107
- let noMoreAnon = anonCount === 0 || !key.trim() || isNaN(key);
108
- const emptyArgs = values.get('') ?? [], duplicatedArgs = [...values].filter(([val, { length }]) => val && length > 1).flatMap(([, curArgs]) => {
109
- const anonIndex = noMoreAnon ? -1 : curArgs.findIndex(({ anon }) => anon);
110
- if (anonIndex !== -1) {
111
- noMoreAnon = true;
112
- }
113
- curArgs.splice(anonIndex, 1);
114
- return curArgs;
115
- }), badArgs = [...emptyArgs, ...duplicatedArgs], index = noMoreAnon ? -1 : emptyArgs.findIndex(({ anon }) => anon);
116
- if (badArgs.length === args.length) {
117
- badArgs.splice(index, 1);
118
- }
119
- else if (index !== -1) {
120
- this.anonToNamed();
121
- anonCount = 0;
122
- }
123
- for (const arg of badArgs) {
124
- arg.remove();
125
- }
126
- let remaining = args.length - badArgs.length;
127
- if (remaining === 1) {
128
- continue;
129
- }
130
- else if (aggressive && (anonCount ? /\D\d+$/u : /(?:^|\D)\d+$/u).test(key)) {
131
- let last;
132
- // eslint-disable-next-line es-x/no-regexp-lookbehind-assertions
133
- const str = key.slice(0, -/(?<!\d)\d+$/u.exec(key)[0].length), regex = new RegExp(`^${(0, string_1.escapeRegExp)(str)}\\d+$`, 'u'), series = this.getAllArgs().filter(({ name }) => regex.test(name)), ordered = series.every(({ name }, i) => {
134
- const j = Number(name.slice(str.length)), cmp = j <= i + 1 && (i === 0 || j >= last || name === key);
135
- last = j;
136
- return cmp;
137
- });
138
- if (ordered) {
139
- for (let i = 0; i < series.length; i++) {
140
- const name = `${str}${i + 1}`, arg = series[i];
141
- if (arg.name !== name) {
142
- if (arg.name === key) {
143
- remaining--;
144
- }
145
- arg.rename(name, true);
146
- }
147
- }
148
- }
149
- }
150
- if (remaining > 1) {
151
- index_1.default.error(`${this.type === 'template'
152
- ? this.name
153
- : this.normalizeTitle(this.childNodes[1].text(), 828)
154
- .title} 还留有 ${remaining} 个重复的 ${key} 参数:${[...this.getArgs(key)].map(arg => {
155
- const { top, left } = arg.getBoundingClientRect();
156
- return `第 ${String(top)} 行第 ${String(left)} 列`;
157
- }).join('、')}`);
158
- duplicatedKeys.push(key);
159
- continue;
160
- }
161
- }
162
- return duplicatedKeys;
163
- };
164
- transclude_1.TranscludeToken.prototype.escapeTables =
165
- /** @implements */
166
- function () {
167
- if (!/\n[^\S\n]*(?::+[^\S\n]*)?\{\|/u.test(this.text())) {
168
- return this;
169
- }
170
- const stripped = this.toString().slice(2, -2), include = this.getAttribute('include'), config = this.getAttribute('config'), parsed = index_1.default.parse(stripped, include, 4, config), isTable = (0, debug_1.isToken)('table');
171
- for (const table of parsed.childNodes) {
172
- if (isTable(table)) {
173
- table.escape();
174
- }
175
- }
176
- const { firstChild, length } = index_1.default.parse(`{{${parsed.toString()}}}`, include, undefined, config);
177
- if (length !== 1 || !(firstChild instanceof transclude_1.TranscludeToken)) {
178
- throw new Error('转义表格失败!');
179
- }
180
- this.safeReplaceWith(firstChild);
181
- return firstChild;
182
- };
183
- constants_1.classes['ExtendedTranscludeToken'] = __filename;
package/dist/base.d.ts DELETED
@@ -1,71 +0,0 @@
1
- export interface Config {
2
- ext: string[];
3
- readonly html: [string[], string[], string[]];
4
- readonly namespaces: Record<string, string>;
5
- readonly nsid: Record<string, number>;
6
- readonly parserFunction: [Record<string, string>, string[], string[], string[]];
7
- readonly doubleUnderscore: [string[], string[]];
8
- readonly protocol: string;
9
- readonly img: Record<string, string>;
10
- readonly redirection: string[];
11
- readonly variants: string[];
12
- readonly excludes?: string[];
13
- readonly interwiki: string[];
14
- readonly conversionTable?: [string, string][];
15
- readonly redirects?: [string, string][];
16
- }
17
- export type TokenTypes = 'root' | 'plain' | 'redirect' | 'redirect-syntax' | 'redirect-target' | 'onlyinclude' | 'noinclude' | 'include' | 'comment' | 'ext' | 'ext-attrs' | 'ext-attr-dirty' | 'ext-attr' | 'attr-key' | 'attr-value' | 'ext-inner' | 'arg' | 'arg-name' | 'arg-default' | 'hidden' | 'magic-word' | 'magic-word-name' | 'invoke-function' | 'invoke-module' | 'template' | 'template-name' | 'parameter' | 'parameter-key' | 'parameter-value' | 'heading' | 'heading-title' | 'heading-trail' | 'html' | 'html-attrs' | 'html-attr-dirty' | 'html-attr' | 'table' | 'tr' | 'td' | 'table-syntax' | 'table-attrs' | 'table-attr-dirty' | 'table-attr' | 'table-inter' | 'td-inner' | 'hr' | 'double-underscore' | 'link' | 'link-target' | 'link-text' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'image-parameter' | 'quote' | 'ext-link' | 'ext-link-text' | 'ext-link-url' | 'free-ext-link' | 'magic-link' | 'list' | 'dd' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'imagemap-link';
18
- export declare const rules: readonly ["bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "lonely-apos", "lonely-bracket", "lonely-http", "nested-link", "no-arg", "no-duplicate", "no-ignored", "obsolete-attr", "obsolete-tag", "parsing-order", "pipe-like", "table-layout", "tag-like", "unbalanced-header", "unclosed-comment", "unclosed-quote", "unclosed-table", "unescaped", "unknown-page", "unmatched-tag", "unterminated-url", "url-encoding", "var-anchor", "void-ext"];
19
- export declare namespace LintError {
20
- type Severity = 'error' | 'warning';
21
- type Rule = typeof rules[number];
22
- interface Fix {
23
- readonly range: [number, number];
24
- text: string;
25
- }
26
- }
27
- export interface LintError {
28
- rule: LintError.Rule;
29
- message: string;
30
- severity: LintError.Severity;
31
- startIndex: number;
32
- endIndex: number;
33
- startLine: number;
34
- startCol: number;
35
- endLine: number;
36
- endCol: number;
37
- fix?: LintError.Fix;
38
- suggestions?: (LintError.Fix & {
39
- desc: string;
40
- })[];
41
- }
42
- export type AST = Record<string, string | number | boolean> & {
43
- range: [number, number];
44
- type?: TokenTypes;
45
- childNodes?: AST[];
46
- };
47
- /** 类似Node */
48
- export interface AstNode {
49
- type: string;
50
- readonly childNodes: readonly AstNode[];
51
- /** Linter */
52
- lint(): LintError[];
53
- /** 以HTML格式打印 */
54
- print(): string;
55
- }
56
- /** 类似HTMLElement */
57
- interface AstElement extends AstNode {
58
- /** 保存为JSON */
59
- json(): AST;
60
- }
61
- export interface Parser {
62
- config: Config | string;
63
- i18n: Record<string, string> | string | undefined;
64
- /**
65
- * 解析wikitext
66
- * @param include 是否嵌入
67
- * @param maxStage 最大解析层级
68
- */
69
- parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): AstElement;
70
- }
71
- export {};
package/dist/base.js DELETED
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rules = void 0;
4
- exports.rules = [
5
- 'bold-header',
6
- 'format-leakage',
7
- 'fostered-content',
8
- 'h1',
9
- 'illegal-attr',
10
- 'insecure-style',
11
- 'invalid-gallery',
12
- 'invalid-imagemap',
13
- 'invalid-invoke',
14
- 'invalid-isbn',
15
- 'lonely-apos',
16
- 'lonely-bracket',
17
- 'lonely-http',
18
- 'nested-link',
19
- 'no-arg',
20
- 'no-duplicate',
21
- 'no-ignored',
22
- 'obsolete-attr',
23
- 'obsolete-tag',
24
- 'parsing-order',
25
- 'pipe-like',
26
- 'table-layout',
27
- 'tag-like',
28
- 'unbalanced-header',
29
- 'unclosed-comment',
30
- 'unclosed-quote',
31
- 'unclosed-table',
32
- 'unescaped',
33
- 'unknown-page',
34
- 'unmatched-tag',
35
- 'unterminated-url',
36
- 'url-encoding',
37
- 'var-anchor',
38
- 'void-ext',
39
- ];
package/dist/index.d.ts DELETED
@@ -1,33 +0,0 @@
1
- import type { Config, LintError, Parser as ParserBase } from './base';
2
- import type { Title } from './lib/title';
3
- import type { Token } from './internal';
4
- declare interface Parser extends ParserBase {
5
- rules: readonly LintError.Rule[];
6
- viewOnly: boolean;
7
- conversionTable: Map<string, string>;
8
- redirects: Map<string, string>;
9
- warning: boolean;
10
- debugging: boolean;
11
- /**
12
- * 规范化页面标题
13
- * @param title 标题(含或不含命名空间前缀)
14
- * @param defaultNs 命名空间
15
- * @param include 是否嵌入
16
- * @param halfParsed 是否是半解析状态
17
- * @param decode 是否需要解码
18
- * @param selfLink 是否允许selfLink
19
- */
20
- normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): Title;
21
- parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): Token;
22
- /**
23
- * 是否是跨维基链接
24
- * @param title 链接标题
25
- */
26
- isInterwiki(title: string, config?: Config): RegExpExecArray | null;
27
- }
28
- declare const Parser: Parser;
29
- // @ts-expect-error mixed export styles
30
- export = Parser;
31
- export type { Config, LintError };
32
- export type * from './internal';
33
- declare global { type Acceptable = unknown; }