wikiparser-node 1.6.1 → 1.6.2-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 (163) hide show
  1. package/bundle/bundle.min.js +39 -0
  2. package/config/enwiki.json +1 -814
  3. package/config/llwiki.json +1 -35
  4. package/config/moegirl.json +1 -44
  5. package/config/zhwiki.json +1 -466
  6. package/extensions/dist/base.js +64 -0
  7. package/extensions/dist/editor.js +159 -0
  8. package/extensions/dist/highlight.js +59 -0
  9. package/extensions/dist/lint.js +60 -0
  10. package/extensions/editor.css +63 -0
  11. package/extensions/ui.css +144 -0
  12. package/package.json +32 -16
  13. package/config/.schema.json +0 -172
  14. package/dist/addon/table.d.ts +0 -1
  15. package/dist/addon/table.js +0 -485
  16. package/dist/base.d.ts +0 -72
  17. package/dist/base.js +0 -38
  18. package/dist/index.d.ts +0 -30
  19. package/dist/index.js +0 -214
  20. package/dist/internal.d.ts +0 -44
  21. package/dist/lib/element.d.ts +0 -151
  22. package/dist/lib/element.js +0 -615
  23. package/dist/lib/node.d.ts +0 -146
  24. package/dist/lib/node.js +0 -426
  25. package/dist/lib/range.d.ts +0 -104
  26. package/dist/lib/range.js +0 -385
  27. package/dist/lib/ranges.d.ts +0 -26
  28. package/dist/lib/ranges.js +0 -121
  29. package/dist/lib/text.d.ts +0 -63
  30. package/dist/lib/text.js +0 -354
  31. package/dist/lib/title.d.ts +0 -38
  32. package/dist/lib/title.js +0 -160
  33. package/dist/mixin/attributesParent.d.ts +0 -50
  34. package/dist/mixin/attributesParent.js +0 -81
  35. package/dist/mixin/fixed.d.ts +0 -6
  36. package/dist/mixin/fixed.js +0 -30
  37. package/dist/mixin/flagsParent.d.ts +0 -72
  38. package/dist/mixin/flagsParent.js +0 -59
  39. package/dist/mixin/hidden.d.ts +0 -5
  40. package/dist/mixin/hidden.js +0 -24
  41. package/dist/mixin/magicLinkParent.d.ts +0 -40
  42. package/dist/mixin/magicLinkParent.js +0 -42
  43. package/dist/mixin/singleLine.d.ts +0 -6
  44. package/dist/mixin/singleLine.js +0 -26
  45. package/dist/mixin/sol.d.ts +0 -6
  46. package/dist/mixin/sol.js +0 -43
  47. package/dist/mixin/syntax.d.ts +0 -9
  48. package/dist/mixin/syntax.js +0 -50
  49. package/dist/parser/braces.js +0 -131
  50. package/dist/parser/commentAndExt.js +0 -90
  51. package/dist/parser/converter.js +0 -41
  52. package/dist/parser/externalLinks.js +0 -32
  53. package/dist/parser/hrAndDoubleUnderscore.js +0 -41
  54. package/dist/parser/html.js +0 -39
  55. package/dist/parser/links.js +0 -95
  56. package/dist/parser/list.js +0 -98
  57. package/dist/parser/magicLinks.js +0 -43
  58. package/dist/parser/quotes.js +0 -68
  59. package/dist/parser/selector.js +0 -162
  60. package/dist/parser/table.js +0 -124
  61. package/dist/src/arg.d.ts +0 -58
  62. package/dist/src/arg.js +0 -214
  63. package/dist/src/atom.d.ts +0 -12
  64. package/dist/src/atom.js +0 -27
  65. package/dist/src/attribute.d.ts +0 -71
  66. package/dist/src/attribute.js +0 -502
  67. package/dist/src/attributes.d.ts +0 -109
  68. package/dist/src/attributes.js +0 -356
  69. package/dist/src/converter.d.ts +0 -33
  70. package/dist/src/converter.js +0 -134
  71. package/dist/src/converterFlags.d.ts +0 -87
  72. package/dist/src/converterFlags.js +0 -242
  73. package/dist/src/converterRule.d.ts +0 -77
  74. package/dist/src/converterRule.js +0 -209
  75. package/dist/src/extLink.d.ts +0 -43
  76. package/dist/src/extLink.js +0 -188
  77. package/dist/src/gallery.d.ts +0 -54
  78. package/dist/src/gallery.js +0 -139
  79. package/dist/src/heading.d.ts +0 -47
  80. package/dist/src/heading.js +0 -190
  81. package/dist/src/hidden.d.ts +0 -7
  82. package/dist/src/hidden.js +0 -23
  83. package/dist/src/html.d.ts +0 -65
  84. package/dist/src/html.js +0 -358
  85. package/dist/src/imageParameter.d.ts +0 -65
  86. package/dist/src/imageParameter.js +0 -257
  87. package/dist/src/imagemap.d.ts +0 -54
  88. package/dist/src/imagemap.js +0 -144
  89. package/dist/src/imagemapLink.d.ts +0 -31
  90. package/dist/src/imagemapLink.js +0 -93
  91. package/dist/src/index.d.ts +0 -143
  92. package/dist/src/index.js +0 -852
  93. package/dist/src/link/base.d.ts +0 -52
  94. package/dist/src/link/base.js +0 -228
  95. package/dist/src/link/category.d.ts +0 -13
  96. package/dist/src/link/category.js +0 -28
  97. package/dist/src/link/file.d.ts +0 -98
  98. package/dist/src/link/file.js +0 -272
  99. package/dist/src/link/galleryImage.d.ts +0 -32
  100. package/dist/src/link/galleryImage.js +0 -157
  101. package/dist/src/link/index.d.ts +0 -56
  102. package/dist/src/link/index.js +0 -133
  103. package/dist/src/magicLink.d.ts +0 -59
  104. package/dist/src/magicLink.js +0 -223
  105. package/dist/src/nested.d.ts +0 -43
  106. package/dist/src/nested.js +0 -105
  107. package/dist/src/nowiki/base.d.ts +0 -31
  108. package/dist/src/nowiki/base.js +0 -93
  109. package/dist/src/nowiki/comment.d.ts +0 -25
  110. package/dist/src/nowiki/comment.js +0 -76
  111. package/dist/src/nowiki/dd.d.ts +0 -8
  112. package/dist/src/nowiki/dd.js +0 -24
  113. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -18
  114. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  115. package/dist/src/nowiki/hr.d.ts +0 -5
  116. package/dist/src/nowiki/hr.js +0 -63
  117. package/dist/src/nowiki/index.d.ts +0 -16
  118. package/dist/src/nowiki/index.js +0 -27
  119. package/dist/src/nowiki/list.d.ts +0 -16
  120. package/dist/src/nowiki/list.js +0 -109
  121. package/dist/src/nowiki/listBase.d.ts +0 -5
  122. package/dist/src/nowiki/listBase.js +0 -61
  123. package/dist/src/nowiki/noinclude.d.ts +0 -10
  124. package/dist/src/nowiki/noinclude.js +0 -23
  125. package/dist/src/nowiki/quote.d.ts +0 -14
  126. package/dist/src/nowiki/quote.js +0 -131
  127. package/dist/src/onlyinclude.d.ts +0 -16
  128. package/dist/src/onlyinclude.js +0 -57
  129. package/dist/src/paramTag/index.d.ts +0 -37
  130. package/dist/src/paramTag/index.js +0 -77
  131. package/dist/src/paramTag/inputbox.d.ts +0 -8
  132. package/dist/src/paramTag/inputbox.js +0 -22
  133. package/dist/src/parameter.d.ts +0 -70
  134. package/dist/src/parameter.js +0 -264
  135. package/dist/src/pre.d.ts +0 -31
  136. package/dist/src/pre.js +0 -59
  137. package/dist/src/syntax.d.ts +0 -20
  138. package/dist/src/syntax.js +0 -86
  139. package/dist/src/table/base.d.ts +0 -27
  140. package/dist/src/table/base.js +0 -81
  141. package/dist/src/table/index.d.ts +0 -242
  142. package/dist/src/table/index.js +0 -495
  143. package/dist/src/table/td.d.ts +0 -86
  144. package/dist/src/table/td.js +0 -354
  145. package/dist/src/table/tr.d.ts +0 -32
  146. package/dist/src/table/tr.js +0 -58
  147. package/dist/src/table/trBase.d.ts +0 -53
  148. package/dist/src/table/trBase.js +0 -156
  149. package/dist/src/tagPair/ext.d.ts +0 -32
  150. package/dist/src/tagPair/ext.js +0 -203
  151. package/dist/src/tagPair/include.d.ts +0 -35
  152. package/dist/src/tagPair/include.js +0 -74
  153. package/dist/src/tagPair/index.d.ts +0 -27
  154. package/dist/src/tagPair/index.js +0 -128
  155. package/dist/src/transclude.d.ts +0 -167
  156. package/dist/src/transclude.js +0 -717
  157. package/dist/util/constants.js +0 -28
  158. package/dist/util/debug.js +0 -88
  159. package/dist/util/diff.js +0 -83
  160. package/dist/util/lint.js +0 -31
  161. package/dist/util/string.js +0 -54
  162. package/errors/README +0 -1
  163. package/printed/README +0 -1
@@ -1,264 +0,0 @@
1
- "use strict";
2
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
- var _, done = false;
8
- for (var i = decorators.length - 1; i >= 0; i--) {
9
- var context = {};
10
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
- if (kind === "accessor") {
15
- if (result === void 0) continue;
16
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
- if (_ = accept(result.get)) descriptor.get = _;
18
- if (_ = accept(result.set)) descriptor.set = _;
19
- if (_ = accept(result.init)) initializers.unshift(_);
20
- }
21
- else if (_ = accept(result)) {
22
- if (kind === "field") initializers.unshift(_);
23
- else descriptor[key] = _;
24
- }
25
- }
26
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
- done = true;
28
- };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.ParameterToken = void 0;
38
- const string_1 = require("../util/string");
39
- const lint_1 = require("../util/lint");
40
- const debug_1 = require("../util/debug");
41
- const constants_1 = require("../util/constants");
42
- const fixed_1 = require("../mixin/fixed");
43
- const index_1 = require("../index");
44
- const index_2 = require("./index");
45
- /**
46
- * 准确获取参数名
47
- * @param name 预定的参数名
48
- */
49
- const getName = (name) => name.text().replace(/^[ \t\n\0\v]+|([^ \t\n\0\v])[ \t\n\0\v]+$/gu, '$1');
50
- /**
51
- * 模板或魔术字参数
52
- * @classdesc `{childNodes: [Token, Token]}`
53
- */
54
- let ParameterToken = (() => {
55
- let _classDecorators = [fixed_1.fixedToken];
56
- let _classDescriptor;
57
- let _classExtraInitializers = [];
58
- let _classThis;
59
- let _classSuper = index_2.Token;
60
- var ParameterToken = class extends _classSuper {
61
- static { _classThis = this; }
62
- static {
63
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
64
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
65
- ParameterToken = _classThis = _classDescriptor.value;
66
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
67
- __runInitializers(_classThis, _classExtraInitializers);
68
- }
69
- type = 'parameter';
70
- /* NOT FOR BROWSER END */
71
- /** 是否是匿名参数 */
72
- get anon() {
73
- return this.firstChild.length === 0;
74
- }
75
- /* NOT FOR BROWSER */
76
- set anon(value) {
77
- if (value) {
78
- throw new Error('无法将命名参数转换为匿名参数!');
79
- }
80
- this.parentNode?.anonToNamed();
81
- }
82
- /** getValue()的getter */
83
- get value() {
84
- return this.getValue();
85
- }
86
- set value(value) {
87
- this.setValue(value);
88
- }
89
- /** 是否是重复参数 */
90
- get duplicated() {
91
- try {
92
- return Boolean(this.parentNode?.getDuplicatedArgs().some(([key]) => key === this.name));
93
- }
94
- catch {
95
- return false;
96
- }
97
- }
98
- set duplicated(value) {
99
- if (this.duplicated && !value) {
100
- this.parentNode.fixDuplication();
101
- }
102
- }
103
- /* NOT FOR BROWSER END */
104
- /**
105
- * @param key 参数名
106
- * @param value 参数值
107
- */
108
- constructor(key, value, config = index_1.default.getConfig(), accum = []) {
109
- super(undefined, config, accum);
110
- const keyToken = new index_2.Token(typeof key === 'number' ? undefined : key, config, accum, {
111
- 'Stage-11': ':', '!HeadingToken': '',
112
- }), token = new index_2.Token(value, config, accum);
113
- keyToken.type = 'parameter-key';
114
- token.type = 'parameter-value';
115
- token.setAttribute('stage', 2);
116
- this.append(keyToken, token);
117
- }
118
- /** @private */
119
- afterBuild() {
120
- if (!this.anon) {
121
- const { parentNode, firstChild } = this, name = getName(firstChild);
122
- this.setAttribute('name', name);
123
- if (parentNode) {
124
- parentNode.getArgs(name, false, false).add(this);
125
- /* NOT FOR BROWSER */
126
- parentNode.getAttribute('keys').add(name);
127
- }
128
- }
129
- /* NOT FOR BROWSER */
130
- const /** @implements */ parameterListener = ({ prevTarget }, data) => {
131
- if (!this.anon) { // 匿名参数不管怎么变动还是匿名
132
- const { firstChild, name } = this;
133
- if (prevTarget === firstChild) {
134
- const newKey = getName(firstChild);
135
- data.oldKey = name;
136
- data.newKey = newKey;
137
- this.setAttribute('name', newKey);
138
- }
139
- }
140
- };
141
- this.addEventListener(['remove', 'insert', 'replace', 'text'], parameterListener);
142
- }
143
- /** @private */
144
- toString() {
145
- return this.anon ? String(this.lastChild) : super.toString('=');
146
- }
147
- /** @override */
148
- text() {
149
- return this.anon ? this.lastChild.text() : super.text('=');
150
- }
151
- /** @private */
152
- getGaps() {
153
- return this.anon ? 0 : 1;
154
- }
155
- /** @override */
156
- lint(start = this.getAbsoluteIndex(), re) {
157
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
158
- /https?:\/\/(?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])(?:[^[\]<>"\0\t\n\p{Zs}]|\0\d+c\x7F)*$/iu;
159
- const errors = super.lint(start, re), { firstChild } = this, link = new RegExp(`https?://${string_1.extUrlCharFirst}${string_1.extUrlChar}$`, 'iu').exec(firstChild.text())?.[0];
160
- if (link && new URL(link).search) {
161
- const e = (0, lint_1.generateForChild)(firstChild, { start }, 'unescaped', 'unescaped query string in an anonymous parameter');
162
- e.startIndex = e.endIndex;
163
- e.startLine = e.endLine;
164
- e.startCol = e.endCol;
165
- e.endIndex++;
166
- e.endCol++;
167
- e.fix = {
168
- range: [e.startIndex, e.endIndex],
169
- text: '{{=}}',
170
- };
171
- errors.push(e);
172
- }
173
- return errors;
174
- }
175
- /** @override */
176
- print() {
177
- return super.print({ sep: this.anon ? '' : '=' });
178
- }
179
- /** @override */
180
- json() {
181
- const json = super.json();
182
- json['anon'] = this.anon;
183
- return json;
184
- }
185
- /* NOT FOR BROWSER */
186
- /** @override */
187
- cloneNode() {
188
- const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
189
- return debug_1.Shadow.run(() => {
190
- // @ts-expect-error abstract class
191
- const token = new ParameterToken(this.anon ? Number(this.name) : undefined, undefined, config);
192
- token.firstChild.safeReplaceWith(key);
193
- token.lastChild.safeReplaceWith(value);
194
- token.afterBuild();
195
- if (this.anon) {
196
- token.setAttribute('name', this.name);
197
- }
198
- return token;
199
- });
200
- }
201
- /**
202
- * @override
203
- * @param token 待替换的节点
204
- */
205
- safeReplaceWith(token) {
206
- index_1.default.warn(`${this.constructor.name}.safeReplaceWith 方法退化到 replaceWith。`);
207
- this.replaceWith(token);
208
- }
209
- /** 获取参数值 */
210
- getValue() {
211
- const value = this.lastChild.text();
212
- return this.anon && this.parentNode?.isTemplate() !== false ? value : value.trim();
213
- }
214
- /**
215
- * 设置参数值
216
- * @param value 参数值
217
- */
218
- setValue(value) {
219
- const { childNodes } = index_1.default.parse(value, this.getAttribute('include'), undefined, this.getAttribute('config'));
220
- this.lastChild.replaceChildren(...childNodes);
221
- }
222
- /**
223
- * 修改参数名
224
- * @param key 新参数名
225
- * @param force 是否无视冲突命名
226
- * @throws `Error` 仅用于模板参数
227
- * @throws `RangeError` 更名造成重复参数
228
- */
229
- rename(key, force = false) {
230
- const { parentNode, anon } = this;
231
- // 必须检测是否是TranscludeToken
232
- if (parentNode?.isTemplate() === false) {
233
- throw new Error('rename 方法仅用于模板参数!');
234
- }
235
- else if (anon) {
236
- parentNode?.anonToNamed();
237
- }
238
- const root = index_1.default.parse(key, this.getAttribute('include'), undefined, this.getAttribute('config')), name = getName(root);
239
- if (this.name === name) {
240
- index_1.default.warn('未改变实际参数名', name);
241
- }
242
- else if (parentNode?.hasArg(name)) {
243
- if (force) {
244
- index_1.default.warn('参数更名造成重复参数', name);
245
- }
246
- else {
247
- throw new RangeError(`参数更名造成重复参数:${name}`);
248
- }
249
- }
250
- this.firstChild.replaceChildren(...root.childNodes);
251
- }
252
- /** 转义 `=` */
253
- escape() {
254
- for (const child of this.lastChild.childNodes) {
255
- if (child.type === 'text') {
256
- child.escape();
257
- }
258
- }
259
- }
260
- };
261
- return ParameterToken = _classThis;
262
- })();
263
- exports.ParameterToken = ParameterToken;
264
- constants_1.classes['ParameterToken'] = __filename;
package/dist/src/pre.d.ts DELETED
@@ -1,31 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import { NoincludeToken } from './nowiki/noinclude';
4
- import type { LintError } from '../base';
5
- import type { AstText, AttributesToken, ExtToken, ConverterToken } from '../internal';
6
- /**
7
- * `<pre>`
8
- * @classdesc `{childNodes: [...AstText|NoincludeToken|ConverterToken]}`
9
- */
10
- export declare abstract class PreToken extends Token {
11
- readonly type = "ext-inner";
12
- readonly name: 'pre';
13
- readonly childNodes: readonly (AstText | NoincludeToken | ConverterToken)[];
14
- abstract get firstChild(): AstText | NoincludeToken | ConverterToken | undefined;
15
- abstract get lastChild(): AstText | NoincludeToken | ConverterToken | undefined;
16
- abstract get nextSibling(): undefined;
17
- abstract get previousSibling(): AttributesToken;
18
- abstract get parentNode(): ExtToken | undefined;
19
- abstract get children(): (NoincludeToken | ConverterToken)[];
20
- abstract get firstElementChild(): NoincludeToken | ConverterToken | undefined;
21
- abstract get lastElementChild(): NoincludeToken | ConverterToken | undefined;
22
- abstract get previousElementSibling(): AttributesToken;
23
- abstract get nextElementSibling(): undefined;
24
- abstract get parentElement(): ExtToken | undefined;
25
- /** @class */
26
- constructor(wikitext?: string, config?: Parser.Config, accum?: Token[]);
27
- /** @override */
28
- lint(start?: number): LintError[];
29
- /** @override */
30
- cloneNode(): this;
31
- }
package/dist/src/pre.js DELETED
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PreToken = void 0;
4
- const constants_1 = require("../util/constants");
5
- const debug_1 = require("../util/debug");
6
- const index_1 = require("../index");
7
- const index_2 = require("./index");
8
- const noinclude_1 = require("./nowiki/noinclude");
9
- /**
10
- * `<pre>`
11
- * @classdesc `{childNodes: [...AstText|NoincludeToken|ConverterToken]}`
12
- */
13
- class PreToken extends index_2.Token {
14
- type = 'ext-inner';
15
- /* NOT FOR BROWSER END */
16
- /** @class */
17
- constructor(wikitext, config = index_1.default.getConfig(), accum = []) {
18
- if (wikitext) {
19
- const opening = '<nowiki>', closing = '</nowiki>', { length } = opening;
20
- let i = wikitext.indexOf(opening), j = wikitext.indexOf(closing, i + length), str = '';
21
- while (i !== -1 && j !== -1) {
22
- // @ts-expect-error abstract class
23
- new noinclude_1.NoincludeToken(opening, config, accum);
24
- // @ts-expect-error abstract class
25
- new noinclude_1.NoincludeToken(closing, config, accum);
26
- str += `${wikitext.slice(0, i)}\0${accum.length - 1}c\x7F${wikitext.slice(i + length, j)}\0${accum.length}c\x7F`;
27
- wikitext = wikitext.slice(j + length + 1);
28
- i = wikitext.indexOf(opening);
29
- j = wikitext.indexOf(closing, i + length);
30
- }
31
- wikitext = `${str}${wikitext}`;
32
- }
33
- super(wikitext, config, accum, {
34
- AstText: ':', NoincludeToken: ':', ConverterToken: ':',
35
- });
36
- this.setAttribute('stage', constants_1.MAX_STAGE - 1);
37
- }
38
- /** @private */
39
- getAttribute(key) {
40
- return (key === 'plain') || super.getAttribute(key);
41
- }
42
- /** @override */
43
- lint(start = this.getAbsoluteIndex()) {
44
- return super.lint(start, /<\s*\/\s*(pre)\b/giu);
45
- }
46
- /* NOT FOR BROWSER */
47
- /** @override */
48
- cloneNode() {
49
- const cloned = this.cloneChildNodes();
50
- return debug_1.Shadow.run(() => {
51
- // @ts-expect-error abstract class
52
- const token = new PreToken(undefined, this.getAttribute('config'));
53
- token.append(...cloned);
54
- return token;
55
- });
56
- }
57
- }
58
- exports.PreToken = PreToken;
59
- constants_1.classes['PreToken'] = __filename;
@@ -1,20 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import type { LintError } from '../base';
4
- import type { SyntaxBase } from '../mixin/syntax';
5
- declare type SyntaxTypes = 'plain' | 'heading-trail' | 'magic-word-name' | 'table-syntax';
6
- /** NOT FOR BROWSER */
7
- export interface SyntaxToken extends SyntaxBase {
8
- }
9
- /** NOT FOR BROWSER END */
10
- /** 满足特定语法格式的plain Token */
11
- export declare class SyntaxToken extends Token {
12
- type: SyntaxTypes;
13
- /** @param pattern 语法正则 */
14
- constructor(wikitext: string | undefined, pattern: RegExp, type?: SyntaxTypes, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
15
- /** @override */
16
- lint(): LintError[];
17
- /** @override */
18
- cloneNode(): this;
19
- }
20
- export {};
@@ -1,86 +0,0 @@
1
- "use strict";
2
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
- var _, done = false;
8
- for (var i = decorators.length - 1; i >= 0; i--) {
9
- var context = {};
10
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
- if (kind === "accessor") {
15
- if (result === void 0) continue;
16
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
- if (_ = accept(result.get)) descriptor.get = _;
18
- if (_ = accept(result.set)) descriptor.set = _;
19
- if (_ = accept(result.init)) initializers.unshift(_);
20
- }
21
- else if (_ = accept(result)) {
22
- if (kind === "field") initializers.unshift(_);
23
- else descriptor[key] = _;
24
- }
25
- }
26
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
- done = true;
28
- };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.SyntaxToken = void 0;
38
- const debug_1 = require("../util/debug");
39
- const constants_1 = require("../util/constants");
40
- const syntax_1 = require("../mixin/syntax");
41
- const index_1 = require("../index");
42
- const index_2 = require("./index");
43
- /** NOT FOR BROWSER END */
44
- /** 满足特定语法格式的plain Token */
45
- let SyntaxToken = (() => {
46
- let _classDecorators = [(0, syntax_1.syntax)()];
47
- let _classDescriptor;
48
- let _classExtraInitializers = [];
49
- let _classThis;
50
- let _classSuper = index_2.Token;
51
- var SyntaxToken = class extends _classSuper {
52
- static { _classThis = this; }
53
- static {
54
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
55
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
56
- SyntaxToken = _classThis = _classDescriptor.value;
57
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
58
- __runInitializers(_classThis, _classExtraInitializers);
59
- }
60
- /** @param pattern 语法正则 */
61
- constructor(wikitext, pattern, type = 'plain', config = index_1.default.getConfig(), accum = [], acceptable) {
62
- super(wikitext, config, accum, acceptable);
63
- this.type = type;
64
- /* NOT FOR BROWSER */
65
- this.setAttribute('pattern', pattern);
66
- }
67
- /** @override */
68
- lint() {
69
- return [];
70
- }
71
- /* NOT FOR BROWSER */
72
- /** @override */
73
- cloneNode() {
74
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAttribute('acceptable');
75
- return debug_1.Shadow.run(() => {
76
- const token = new SyntaxToken(undefined, this.pattern, this.type, config, [], acceptable);
77
- token.append(...cloned);
78
- token.afterBuild();
79
- return token;
80
- });
81
- }
82
- };
83
- return SyntaxToken = _classThis;
84
- })();
85
- exports.SyntaxToken = SyntaxToken;
86
- constants_1.classes['SyntaxToken'] = __filename;
@@ -1,27 +0,0 @@
1
- import Parser from '../../index';
2
- import { Token } from '../index';
3
- import { SyntaxToken } from '../syntax';
4
- import { AttributesToken } from '../attributes';
5
- import type { AttributesParentBase } from '../../mixin/attributesParent';
6
- export interface TableBaseToken extends AttributesParentBase {
7
- }
8
- export declare abstract class TableBaseToken extends Token {
9
- type: 'table' | 'tr' | 'td';
10
- readonly childNodes: readonly [SyntaxToken, AttributesToken, ...Token[]];
11
- abstract get firstChild(): SyntaxToken;
12
- abstract get lastChild(): Token;
13
- abstract get children(): [SyntaxToken, AttributesToken, ...Token[]];
14
- abstract get firstElementChild(): SyntaxToken;
15
- abstract get lastElementChild(): Token;
16
- /**
17
- * @param pattern 表格语法正则
18
- * @param syntax 表格语法
19
- * @param attr 表格属性
20
- */
21
- constructor(pattern: RegExp, syntax?: string, attr?: string, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
22
- /** @override */
23
- cloneNode(): this;
24
- /** 转义表格语法 */
25
- escape(): void;
26
- }
27
- export {};
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TableBaseToken = void 0;
4
- const debug_1 = require("../../util/debug");
5
- const constants_1 = require("../../util/constants");
6
- const attributesParent_1 = require("../../mixin/attributesParent");
7
- const index_1 = require("../../index");
8
- const index_2 = require("../index");
9
- const syntax_1 = require("../syntax");
10
- const attributes_1 = require("../attributes");
11
- /* NOT FOR BROWSER */
12
- /**
13
- * 转义表格语法
14
- * @param syntax 表格语法节点
15
- */
16
- const escapeTable = (syntax) => {
17
- const wikitext = syntax.childNodes.map(child => child.type === 'text'
18
- ? child.data.replace(/\|/gu, '{{!}}')
19
- : String(child)).join(''), { childNodes } = index_1.default.parse(wikitext, syntax.getAttribute('include'), 2, syntax.getAttribute('config'));
20
- syntax.replaceChildren(...childNodes);
21
- };
22
- /**
23
- * 表格行,含开头的换行,不含结尾的换行
24
- * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ...Token]}`
25
- */
26
- class TableBaseToken extends (0, attributesParent_1.attributesParent)(1)(index_2.Token) {
27
- /* NOT FOR BROWSER END */
28
- /**
29
- * @param pattern 表格语法正则
30
- * @param syntax 表格语法
31
- * @param attr 表格属性
32
- */
33
- constructor(pattern, syntax, attr, config = index_1.default.getConfig(), accum = [], acceptable = {}) {
34
- super(undefined, config, accum, acceptable);
35
- this.append(new syntax_1.SyntaxToken(syntax, pattern, 'table-syntax', config, accum, {
36
- 'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':',
37
- }),
38
- // @ts-expect-error abstract class
39
- new attributes_1.AttributesToken(attr, 'table-attrs', this.type, config, accum));
40
- /* NOT FOR BROWSER */
41
- this.protectChildren(0, 1);
42
- }
43
- /* NOT FOR BROWSER */
44
- /** @override */
45
- cloneNode() {
46
- const [syntax, attr, ...cloned] = this.cloneChildNodes();
47
- return debug_1.Shadow.run(() => {
48
- const { constructor } = this, token = new constructor(undefined, undefined, this.getAttribute('config'));
49
- token.firstChild.safeReplaceWith(syntax);
50
- token.childNodes[1].safeReplaceWith(attr);
51
- if (token.type === 'td') { // TdToken
52
- token.childNodes[2].safeReplaceWith(cloned[0]);
53
- }
54
- else {
55
- token.append(...cloned);
56
- }
57
- return token;
58
- });
59
- }
60
- /** 转义表格语法 */
61
- escape() {
62
- for (const child of this.childNodes) {
63
- if (child instanceof syntax_1.SyntaxToken) {
64
- escapeTable(child);
65
- }
66
- else if (child instanceof TableBaseToken) {
67
- child.escape();
68
- }
69
- }
70
- }
71
- /** @private */
72
- setSyntax(syntax, esc = false) {
73
- const { firstChild } = this;
74
- firstChild.replaceChildren(syntax);
75
- if (esc) {
76
- escapeTable(firstChild);
77
- }
78
- }
79
- }
80
- exports.TableBaseToken = TableBaseToken;
81
- constants_1.classes['TableBaseToken'] = __filename;