wikiparser-node 1.6.2 → 1.7.0-beta.0

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 (167) hide show
  1. package/bundle/bundle.min.js +38 -0
  2. package/config/default.json +5 -0
  3. package/config/enwiki.json +4 -814
  4. package/config/llwiki.json +5 -35
  5. package/config/minimum.json +3 -0
  6. package/config/moegirl.json +5 -44
  7. package/config/zhwiki.json +6 -466
  8. package/extensions/dist/base.js +64 -0
  9. package/extensions/dist/editor.js +159 -0
  10. package/extensions/dist/highlight.js +58 -0
  11. package/extensions/dist/lint.js +60 -0
  12. package/extensions/editor.css +64 -0
  13. package/extensions/ui.css +144 -0
  14. package/i18n/zh-hans.json +2 -1
  15. package/i18n/zh-hant.json +2 -1
  16. package/package.json +31 -16
  17. package/config/.schema.json +0 -172
  18. package/dist/addon/table.d.ts +0 -1
  19. package/dist/addon/table.js +0 -485
  20. package/dist/base.d.ts +0 -69
  21. package/dist/base.js +0 -38
  22. package/dist/index.d.ts +0 -31
  23. package/dist/index.js +0 -212
  24. package/dist/internal.d.ts +0 -44
  25. package/dist/lib/element.d.ts +0 -151
  26. package/dist/lib/element.js +0 -618
  27. package/dist/lib/node.d.ts +0 -146
  28. package/dist/lib/node.js +0 -426
  29. package/dist/lib/range.d.ts +0 -104
  30. package/dist/lib/range.js +0 -385
  31. package/dist/lib/ranges.d.ts +0 -28
  32. package/dist/lib/ranges.js +0 -126
  33. package/dist/lib/text.d.ts +0 -63
  34. package/dist/lib/text.js +0 -354
  35. package/dist/lib/title.d.ts +0 -40
  36. package/dist/lib/title.js +0 -179
  37. package/dist/mixin/attributesParent.d.ts +0 -50
  38. package/dist/mixin/attributesParent.js +0 -81
  39. package/dist/mixin/fixed.d.ts +0 -6
  40. package/dist/mixin/fixed.js +0 -30
  41. package/dist/mixin/flagsParent.d.ts +0 -72
  42. package/dist/mixin/flagsParent.js +0 -59
  43. package/dist/mixin/hidden.d.ts +0 -5
  44. package/dist/mixin/hidden.js +0 -24
  45. package/dist/mixin/magicLinkParent.d.ts +0 -40
  46. package/dist/mixin/magicLinkParent.js +0 -42
  47. package/dist/mixin/singleLine.d.ts +0 -6
  48. package/dist/mixin/singleLine.js +0 -26
  49. package/dist/mixin/sol.d.ts +0 -6
  50. package/dist/mixin/sol.js +0 -43
  51. package/dist/mixin/syntax.d.ts +0 -9
  52. package/dist/mixin/syntax.js +0 -50
  53. package/dist/parser/braces.js +0 -130
  54. package/dist/parser/commentAndExt.js +0 -89
  55. package/dist/parser/converter.js +0 -40
  56. package/dist/parser/externalLinks.js +0 -45
  57. package/dist/parser/hrAndDoubleUnderscore.js +0 -40
  58. package/dist/parser/html.js +0 -38
  59. package/dist/parser/links.js +0 -97
  60. package/dist/parser/list.js +0 -97
  61. package/dist/parser/magicLinks.js +0 -42
  62. package/dist/parser/quotes.js +0 -67
  63. package/dist/parser/selector.js +0 -190
  64. package/dist/parser/table.js +0 -123
  65. package/dist/src/arg.d.ts +0 -58
  66. package/dist/src/arg.js +0 -214
  67. package/dist/src/atom.d.ts +0 -12
  68. package/dist/src/atom.js +0 -27
  69. package/dist/src/attribute.d.ts +0 -71
  70. package/dist/src/attribute.js +0 -502
  71. package/dist/src/attributes.d.ts +0 -109
  72. package/dist/src/attributes.js +0 -356
  73. package/dist/src/converter.d.ts +0 -33
  74. package/dist/src/converter.js +0 -134
  75. package/dist/src/converterFlags.d.ts +0 -87
  76. package/dist/src/converterFlags.js +0 -242
  77. package/dist/src/converterRule.d.ts +0 -77
  78. package/dist/src/converterRule.js +0 -209
  79. package/dist/src/extLink.d.ts +0 -43
  80. package/dist/src/extLink.js +0 -191
  81. package/dist/src/gallery.d.ts +0 -54
  82. package/dist/src/gallery.js +0 -139
  83. package/dist/src/heading.d.ts +0 -47
  84. package/dist/src/heading.js +0 -190
  85. package/dist/src/hidden.d.ts +0 -7
  86. package/dist/src/hidden.js +0 -23
  87. package/dist/src/html.d.ts +0 -65
  88. package/dist/src/html.js +0 -358
  89. package/dist/src/imageParameter.d.ts +0 -65
  90. package/dist/src/imageParameter.js +0 -257
  91. package/dist/src/imagemap.d.ts +0 -54
  92. package/dist/src/imagemap.js +0 -144
  93. package/dist/src/imagemapLink.d.ts +0 -31
  94. package/dist/src/imagemapLink.js +0 -93
  95. package/dist/src/index.d.ts +0 -143
  96. package/dist/src/index.js +0 -851
  97. package/dist/src/link/base.d.ts +0 -52
  98. package/dist/src/link/base.js +0 -228
  99. package/dist/src/link/category.d.ts +0 -13
  100. package/dist/src/link/category.js +0 -28
  101. package/dist/src/link/file.d.ts +0 -98
  102. package/dist/src/link/file.js +0 -272
  103. package/dist/src/link/galleryImage.d.ts +0 -32
  104. package/dist/src/link/galleryImage.js +0 -158
  105. package/dist/src/link/index.d.ts +0 -56
  106. package/dist/src/link/index.js +0 -133
  107. package/dist/src/magicLink.d.ts +0 -59
  108. package/dist/src/magicLink.js +0 -223
  109. package/dist/src/nested.d.ts +0 -43
  110. package/dist/src/nested.js +0 -105
  111. package/dist/src/nowiki/base.d.ts +0 -31
  112. package/dist/src/nowiki/base.js +0 -93
  113. package/dist/src/nowiki/comment.d.ts +0 -25
  114. package/dist/src/nowiki/comment.js +0 -76
  115. package/dist/src/nowiki/dd.d.ts +0 -8
  116. package/dist/src/nowiki/dd.js +0 -24
  117. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -18
  118. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  119. package/dist/src/nowiki/hr.d.ts +0 -5
  120. package/dist/src/nowiki/hr.js +0 -63
  121. package/dist/src/nowiki/index.d.ts +0 -16
  122. package/dist/src/nowiki/index.js +0 -27
  123. package/dist/src/nowiki/list.d.ts +0 -16
  124. package/dist/src/nowiki/list.js +0 -109
  125. package/dist/src/nowiki/listBase.d.ts +0 -5
  126. package/dist/src/nowiki/listBase.js +0 -61
  127. package/dist/src/nowiki/noinclude.d.ts +0 -10
  128. package/dist/src/nowiki/noinclude.js +0 -23
  129. package/dist/src/nowiki/quote.d.ts +0 -14
  130. package/dist/src/nowiki/quote.js +0 -131
  131. package/dist/src/onlyinclude.d.ts +0 -16
  132. package/dist/src/onlyinclude.js +0 -57
  133. package/dist/src/paramTag/index.d.ts +0 -37
  134. package/dist/src/paramTag/index.js +0 -77
  135. package/dist/src/paramTag/inputbox.d.ts +0 -8
  136. package/dist/src/paramTag/inputbox.js +0 -22
  137. package/dist/src/parameter.d.ts +0 -70
  138. package/dist/src/parameter.js +0 -264
  139. package/dist/src/pre.d.ts +0 -31
  140. package/dist/src/pre.js +0 -59
  141. package/dist/src/syntax.d.ts +0 -20
  142. package/dist/src/syntax.js +0 -86
  143. package/dist/src/table/base.d.ts +0 -27
  144. package/dist/src/table/base.js +0 -81
  145. package/dist/src/table/index.d.ts +0 -242
  146. package/dist/src/table/index.js +0 -497
  147. package/dist/src/table/td.d.ts +0 -86
  148. package/dist/src/table/td.js +0 -355
  149. package/dist/src/table/tr.d.ts +0 -32
  150. package/dist/src/table/tr.js +0 -58
  151. package/dist/src/table/trBase.d.ts +0 -53
  152. package/dist/src/table/trBase.js +0 -156
  153. package/dist/src/tagPair/ext.d.ts +0 -32
  154. package/dist/src/tagPair/ext.js +0 -203
  155. package/dist/src/tagPair/include.d.ts +0 -35
  156. package/dist/src/tagPair/include.js +0 -74
  157. package/dist/src/tagPair/index.d.ts +0 -27
  158. package/dist/src/tagPair/index.js +0 -128
  159. package/dist/src/transclude.d.ts +0 -167
  160. package/dist/src/transclude.js +0 -717
  161. package/dist/util/constants.js +0 -27
  162. package/dist/util/debug.js +0 -81
  163. package/dist/util/diff.js +0 -83
  164. package/dist/util/lint.js +0 -31
  165. package/dist/util/string.js +0 -60
  166. package/errors/README +0 -1
  167. package/printed/README +0 -1
@@ -1,203 +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.ExtToken = void 0;
38
- const lint_1 = require("../../util/lint");
39
- const debug_1 = require("../../util/debug");
40
- const constants_1 = require("../../util/constants");
41
- const attributesParent_1 = require("../../mixin/attributesParent");
42
- const index_1 = require("../../index");
43
- const index_2 = require("../index");
44
- const index_3 = require("./index");
45
- const attributes_1 = require("../attributes");
46
- /**
47
- * 从数组中删除指定元素
48
- * @param arr 数组
49
- * @param ele 元素
50
- */
51
- const del = (arr, ele) => {
52
- const set = new Set(arr);
53
- set.delete(ele);
54
- return [...set];
55
- };
56
- /* NOT FOR BROWSER END */
57
- /**
58
- * 扩展标签
59
- * @classdesc `{childNodes: [AttributesToken, Token]}`
60
- */
61
- let ExtToken = (() => {
62
- let _classDecorators = [(0, attributesParent_1.attributesParent)()];
63
- let _classDescriptor;
64
- let _classExtraInitializers = [];
65
- let _classThis;
66
- let _classSuper = index_3.TagPairToken;
67
- var ExtToken = class extends _classSuper {
68
- static { _classThis = this; }
69
- static {
70
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
71
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
72
- ExtToken = _classThis = _classDescriptor.value;
73
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
74
- __runInitializers(_classThis, _classExtraInitializers);
75
- }
76
- type = 'ext';
77
- /* NOT FOR BROWSER END */
78
- /**
79
- * @param name 标签名
80
- * @param attr 标签属性
81
- * @param inner 内部wikitext
82
- * @param closed 是否封闭
83
- */
84
- constructor(name, attr, inner, closed, config = index_1.default.getConfig(), accum = []) {
85
- const lcName = name.toLowerCase(),
86
- // @ts-expect-error abstract class
87
- attrToken = new attributes_1.AttributesToken(!attr || attr.trimStart() !== attr ? attr : ` ${attr}`, 'ext-attrs', lcName, config, accum), newConfig = { ...config, ext: del(config.ext, lcName), excludes: [...config.excludes ?? []] };
88
- let innerToken;
89
- switch (lcName) {
90
- case 'tab':
91
- newConfig.ext = del(newConfig.ext, 'tabs');
92
- // fall through
93
- case 'indicator':
94
- case 'poem':
95
- case 'ref':
96
- case 'option':
97
- case 'combooption':
98
- case 'tabs':
99
- case 'poll':
100
- case 'seo':
101
- if (lcName === 'poem') {
102
- newConfig.excludes.push('heading');
103
- }
104
- innerToken = new index_2.Token(inner, newConfig, accum);
105
- break;
106
- case 'pre': {
107
- const { PreToken } = require('../pre');
108
- // @ts-expect-error abstract class
109
- innerToken = new PreToken(inner, newConfig, accum);
110
- break;
111
- }
112
- case 'dynamicpagelist': {
113
- const { ParamTagToken } = require('../paramTag/index');
114
- // @ts-expect-error abstract class
115
- innerToken = new ParamTagToken(inner, newConfig, accum);
116
- break;
117
- }
118
- case 'inputbox': {
119
- newConfig.excludes.push('heading');
120
- const { InputboxToken } = require('../paramTag/inputbox');
121
- // @ts-expect-error abstract class
122
- innerToken = new InputboxToken(inner, newConfig, accum);
123
- break;
124
- }
125
- case 'references': {
126
- const { NestedToken } = require('../nested');
127
- // @ts-expect-error abstract class
128
- innerToken = new NestedToken(inner, /<!--.*?(?:-->|$)|<(ref)(\s[^>]*)?>(.*?)<\/(ref\s*)>/gisu, ['ref'], newConfig, accum);
129
- break;
130
- }
131
- case 'choose': {
132
- const { NestedToken } = require('../nested');
133
- // @ts-expect-error abstract class
134
- innerToken = new NestedToken(inner, /<(option|choicetemplate)(\s[^>]*)?>(.*?)<\/(\1)>/gsu, ['option', 'choicetemplate'], newConfig, accum);
135
- break;
136
- }
137
- case 'combobox': {
138
- const { NestedToken } = require('../nested');
139
- // @ts-expect-error abstract class
140
- innerToken = new NestedToken(inner, /<(combooption)(\s[^>]*)?>(.*?)<\/(combooption\s*)>/gisu, ['combooption'], newConfig, accum);
141
- break;
142
- }
143
- case 'gallery': {
144
- const { GalleryToken } = require('../gallery');
145
- // @ts-expect-error abstract class
146
- innerToken = new GalleryToken(inner, newConfig, accum);
147
- break;
148
- }
149
- case 'imagemap': {
150
- const { ImagemapToken } = require('../imagemap');
151
- // @ts-expect-error abstract class
152
- innerToken = new ImagemapToken(inner, newConfig, accum);
153
- break;
154
- }
155
- // 更多定制扩展的代码示例:
156
- // ```
157
- // case 'extensionName': {
158
- // const {ExtensionToken}: typeof import('../extension') = require('../extension');
159
- // innerToken = new ExtensionToken(inner, newConfig, accum);
160
- // break;
161
- // }
162
- // ```
163
- default: {
164
- const { NowikiToken } = require('../nowiki/index');
165
- // @ts-expect-error abstract class
166
- innerToken = new NowikiToken(inner, newConfig);
167
- }
168
- }
169
- innerToken.setAttribute('name', lcName);
170
- innerToken.type = 'ext-inner';
171
- super(name, attrToken, innerToken, closed, config, accum);
172
- this.seal('closed', true);
173
- }
174
- /** @override */
175
- lint(start = this.getAbsoluteIndex(), re) {
176
- const errors = super.lint(start, re);
177
- let rect;
178
- if (this.name !== 'nowiki' && this.closest('html-attrs, table-attrs')) {
179
- rect = { start, ...this.getRootNode().posFromIndex(start) };
180
- errors.push((0, lint_1.generateForSelf)(this, rect, 'parsing-order', 'extension tag in HTML tag attributes'));
181
- }
182
- if (this.name === 'ref' && this.closest('heading-title')) {
183
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
184
- errors.push((0, lint_1.generateForSelf)(this, rect, 'var-anchor', 'variable anchor in a section header'));
185
- }
186
- return errors;
187
- }
188
- /* NOT FOR BROWSER */
189
- /** @override */
190
- cloneNode() {
191
- const inner = this.lastChild.cloneNode(), tags = this.getAttribute('tags'), config = this.getAttribute('config'), attr = String(this.firstChild);
192
- return debug_1.Shadow.run(() => {
193
- // @ts-expect-error abstract class
194
- const token = new ExtToken(tags[0], attr, '', this.selfClosing ? undefined : tags[1], config);
195
- token.lastChild.safeReplaceWith(inner);
196
- return token;
197
- });
198
- }
199
- };
200
- return ExtToken = _classThis;
201
- })();
202
- exports.ExtToken = ExtToken;
203
- constants_1.classes['ExtToken'] = __filename;
@@ -1,35 +0,0 @@
1
- import Parser from '../../index';
2
- import { TagPairToken } from './index';
3
- import type { LintError } from '../../base';
4
- import type { AstText, Token } from '../../internal';
5
- export declare abstract class IncludeToken extends TagPairToken {
6
- readonly type = "include";
7
- readonly childNodes: readonly [AstText, AstText];
8
- abstract get firstChild(): AstText;
9
- abstract get lastChild(): AstText;
10
- abstract get children(): [];
11
- abstract get firstElementChild(): undefined;
12
- abstract get lastElementChild(): undefined;
13
- /** @override */
14
- get innerText(): string | undefined;
15
- set innerText(text: string | undefined);
16
- /**
17
- * @param name 标签名
18
- * @param attr 标签属性
19
- * @param inner 内部wikitext
20
- * @param closed 是否封闭
21
- */
22
- constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Parser.Config, accum?: Token[]);
23
- /** @override */
24
- lint(start?: number): LintError[];
25
- /** @override */
26
- cloneNode(): this;
27
- /**
28
- * @override
29
- * @param str 新文本
30
- */
31
- setText(str: string): string;
32
- /** 清除标签属性 */
33
- removeAttr(): void;
34
- }
35
- export {};
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IncludeToken = void 0;
4
- const lint_1 = require("../../util/lint");
5
- const debug_1 = require("../../util/debug");
6
- const constants_1 = require("../../util/constants");
7
- const hidden_1 = require("../../mixin/hidden");
8
- const index_1 = require("../../index");
9
- const index_2 = require("./index");
10
- /**
11
- * `<includeonly>`或`<noinclude>`或`<onlyinclude>`
12
- * @classdesc `{childNodes: [AstText, AstText]}`
13
- */
14
- class IncludeToken extends (0, hidden_1.hiddenToken)(index_2.TagPairToken) {
15
- type = 'include';
16
- /** @override */
17
- get innerText() {
18
- return this.selfClosing ? undefined : this.lastChild.data;
19
- }
20
- set innerText(text) {
21
- if (text === undefined) {
22
- this.selfClosing = true;
23
- }
24
- else {
25
- this.selfClosing = false;
26
- this.setText(text);
27
- }
28
- }
29
- /* NOT FOR BROWSER END */
30
- /**
31
- * @param name 标签名
32
- * @param attr 标签属性
33
- * @param inner 内部wikitext
34
- * @param closed 是否封闭
35
- */
36
- constructor(name, attr = '', inner, closed, config = index_1.default.getConfig(), accum = []) {
37
- super(name, attr, inner ?? '', inner === undefined ? closed : closed ?? '', config, accum);
38
- }
39
- /** @override */
40
- lint(start = this.getAbsoluteIndex()) {
41
- if (this.closed) {
42
- return [];
43
- }
44
- const e = (0, lint_1.generateForSelf)(this, { start }, 'unclosed-comment', index_1.default.msg('unclosed $1', `<${this.name}>`));
45
- e.suggestions = [
46
- {
47
- desc: 'close',
48
- range: [e.endIndex, e.endIndex],
49
- text: `</${this.name}>`,
50
- },
51
- ];
52
- return [e];
53
- }
54
- /* NOT FOR BROWSER */
55
- /** @override */
56
- cloneNode() {
57
- const tags = this.getAttribute('tags'), config = this.getAttribute('config'), { innerText } = this, closing = this.selfClosing || !this.closed ? undefined : tags[1];
58
- // @ts-expect-error abstract class
59
- return debug_1.Shadow.run(() => new IncludeToken(tags[0], this.firstChild.data, innerText, closing, config));
60
- }
61
- /**
62
- * @override
63
- * @param str 新文本
64
- */
65
- setText(str) {
66
- return super.setText(str, 1);
67
- }
68
- /** 清除标签属性 */
69
- removeAttr() {
70
- super.setText('');
71
- }
72
- }
73
- exports.IncludeToken = IncludeToken;
74
- constants_1.classes['IncludeToken'] = __filename;
@@ -1,27 +0,0 @@
1
- import Parser from '../../index';
2
- import { Token } from '../index';
3
- import type { AstNodes } from '../../lib/node';
4
- /** 成对标签 */
5
- export declare abstract class TagPairToken extends Token {
6
- #private;
7
- type: 'ext' | 'include';
8
- readonly name: string;
9
- closed: boolean;
10
- selfClosing: boolean;
11
- readonly childNodes: readonly [AstNodes, AstNodes];
12
- abstract get firstChild(): AstNodes;
13
- abstract get lastChild(): AstNodes;
14
- /** 内部wikitext */
15
- get innerText(): string | undefined;
16
- /**
17
- * @param name 标签名
18
- * @param attr 标签属性
19
- * @param inner 内部wikitext
20
- * @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
21
- */
22
- constructor(name: string, attr: string | Token, inner: string | Token, closed?: string, config?: Parser.Config, accum?: Token[]);
23
- /** @override */
24
- text(): string;
25
- /** @override */
26
- print(): string;
27
- }
@@ -1,128 +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.TagPairToken = void 0;
38
- const constants_1 = require("../../util/constants");
39
- const fixed_1 = require("../../mixin/fixed");
40
- const index_1 = require("../../index");
41
- const index_2 = require("../index");
42
- /** 成对标签 */
43
- let TagPairToken = (() => {
44
- let _classDecorators = [fixed_1.fixedToken];
45
- let _classDescriptor;
46
- let _classExtraInitializers = [];
47
- let _classThis;
48
- let _classSuper = index_2.Token;
49
- var TagPairToken = class extends _classSuper {
50
- static { _classThis = this; }
51
- static {
52
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
53
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
54
- TagPairToken = _classThis = _classDescriptor.value;
55
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
56
- __runInitializers(_classThis, _classExtraInitializers);
57
- }
58
- #tags;
59
- closed;
60
- selfClosing;
61
- /* NOT FOR BROWSER END */
62
- /** 内部wikitext */
63
- get innerText() {
64
- return this.selfClosing ? undefined : this.lastChild.text();
65
- }
66
- /**
67
- * @param name 标签名
68
- * @param attr 标签属性
69
- * @param inner 内部wikitext
70
- * @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
71
- */
72
- constructor(name, attr, inner, closed, config = index_1.default.getConfig(), accum = []) {
73
- super(undefined, config);
74
- this.setAttribute('name', name.toLowerCase());
75
- this.#tags = [name, closed || name];
76
- this.closed = closed !== '';
77
- this.selfClosing = closed === undefined;
78
- this.append(attr, inner);
79
- const index = typeof attr === 'string' ? -1 : accum.indexOf(attr);
80
- accum.splice(index === -1 ? Infinity : index, 0, this);
81
- }
82
- /** @private */
83
- toString() {
84
- const { selfClosing, firstChild, lastChild,
85
- /* NOT FOR BROWSER */
86
- nextSibling, name, closed, } = this, [opening, closing] = this.#tags;
87
- /* NOT FOR BROWSER */
88
- if (!closed && nextSibling) {
89
- index_1.default.error(`自动闭合 <${name}>`, lastChild);
90
- this.closed = true;
91
- }
92
- /* NOT FOR BROWSER END */
93
- return selfClosing
94
- ? `<${opening}${String(firstChild)}/>`
95
- : `<${opening}${String(firstChild)}>${String(lastChild)}${this.closed ? `</${closing}>` : ''}`;
96
- }
97
- /** @override */
98
- text() {
99
- const [opening, closing] = this.#tags;
100
- return this.selfClosing
101
- ? `<${opening}${this.firstChild.text()}/>`
102
- : `<${opening}${super.text('>')}${this.closed ? `</${closing}>` : ''}`;
103
- }
104
- /** @private */
105
- getAttribute(key) {
106
- /* NOT FOR BROWSER */
107
- if (key === 'tags') {
108
- return [...this.#tags];
109
- }
110
- /* NOT FOR BROWSER END */
111
- return key === 'padding' ? this.#tags[0].length + 1 : super.getAttribute(key);
112
- }
113
- /** @private */
114
- getGaps() {
115
- return 1;
116
- }
117
- /** @override */
118
- print() {
119
- const [opening, closing] = this.#tags;
120
- return super.print(this.selfClosing
121
- ? { pre: `&lt;${opening}`, post: '/&gt;' }
122
- : { pre: `&lt;${opening}`, sep: '&gt;', post: this.closed ? `&lt;/${closing}&gt;` : '' });
123
- }
124
- };
125
- return TagPairToken = _classThis;
126
- })();
127
- exports.TagPairToken = TagPairToken;
128
- constants_1.classes['TagPairToken'] = __filename;
@@ -1,167 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import { ParameterToken } from './parameter';
4
- import { AtomToken } from './atom';
5
- import { SyntaxToken } from './syntax';
6
- import type { LintError } from '../base';
7
- /**
8
- * 模板或魔术字
9
- * @classdesc `{childNodes: [AtomToken|SyntaxToken, ...AtomToken, ...ParameterToken]}`
10
- */
11
- export declare abstract class TranscludeToken extends Token {
12
- #private;
13
- type: 'template' | 'magic-word';
14
- readonly modifier: string;
15
- readonly name: string;
16
- readonly childNodes: readonly [AtomToken | SyntaxToken, ...ParameterToken[]] | readonly [SyntaxToken, AtomToken, AtomToken, ...ParameterToken[]];
17
- abstract get firstChild(): AtomToken | SyntaxToken;
18
- abstract get lastChild(): AtomToken | SyntaxToken | ParameterToken;
19
- abstract get children(): [AtomToken | SyntaxToken, ...ParameterToken[]] | [SyntaxToken, AtomToken, AtomToken, ...ParameterToken[]];
20
- abstract get firstElementChild(): AtomToken | SyntaxToken;
21
- abstract get lastElementChild(): AtomToken | SyntaxToken | ParameterToken;
22
- /** 是否存在重复参数 */
23
- get duplication(): boolean;
24
- set duplication(duplication: boolean);
25
- /**
26
- * @param title 模板标题或魔术字
27
- * @param parts 参数各部分
28
- * @throws `SyntaxError` 非法的模板名称
29
- */
30
- constructor(title: string, parts: ([string] | [string | number, string])[], config?: Parser.Config, accum?: Token[]);
31
- /**
32
- * 设置引用修饰符
33
- * @param modifier 引用修饰符
34
- */
35
- setModifier(modifier: string): boolean;
36
- /** 是否是模板或模块 */
37
- isTemplate(): boolean;
38
- /** @override */
39
- text(): string;
40
- /** @override */
41
- lint(start?: number, re?: RegExp): LintError[];
42
- /**
43
- * @override
44
- * @param token 待插入的子节点
45
- * @param i 插入位置
46
- */
47
- insertAt<T extends ParameterToken>(token: T, i?: number): T;
48
- /** 获取所有参数 */
49
- getAllArgs(): ParameterToken[];
50
- /** 获取所有匿名参数 */
51
- getAnonArgs(): ParameterToken[];
52
- /**
53
- * 获取指定参数
54
- * @param key 参数名
55
- * @param exact 是否匹配匿名性
56
- * @param copy 是否返回一个备份
57
- */
58
- getArgs(key: string | number, exact?: boolean, copy?: boolean): Set<ParameterToken>;
59
- /**
60
- * 获取重名参数
61
- * @throws `Error` 仅用于模板
62
- */
63
- getDuplicatedArgs(): [string, ParameterToken[]][];
64
- /**
65
- * 对特定魔术字获取可能的取值
66
- * @throws `Error` 不是可接受的魔术字
67
- */
68
- getPossibleValues(): Token[];
69
- /** @override */
70
- print(): string;
71
- /** @override */
72
- cloneNode(): this;
73
- /** 替换引用 */
74
- subst(): void;
75
- /** 安全的替换引用 */
76
- safesubst(): void;
77
- /**
78
- * @override
79
- * @param i 移除位置
80
- */
81
- removeAt(i: number): ParameterToken;
82
- /**
83
- * 是否具有某参数
84
- * @param key 参数名
85
- * @param exact 是否匹配匿名性
86
- */
87
- hasArg(key: string | number, exact?: boolean): boolean;
88
- /**
89
- * 获取生效的指定参数
90
- * @param key 参数名
91
- * @param exact 是否匹配匿名性
92
- */
93
- getArg(key: string | number, exact?: boolean): ParameterToken | undefined;
94
- /**
95
- * 移除指定参数
96
- * @param key 参数名
97
- * @param exact 是否匹配匿名性
98
- */
99
- removeArg(key: string | number, exact?: boolean): void;
100
- /** 获取所有参数名 */
101
- getKeys(): string[];
102
- /**
103
- * 获取参数值
104
- * @param key 参数名
105
- */
106
- getValues(key: string | number): string[];
107
- /** 获取所有生效的参数值 */
108
- getValue(): Record<string, string>;
109
- /**
110
- * 获取生效的指定参数值
111
- * @param key 参数名
112
- */
113
- getValue(key: string | number): string | undefined;
114
- /**
115
- * 插入匿名参数
116
- * @param val 参数值
117
- */
118
- newAnonArg(val: string): ParameterToken;
119
- /**
120
- * 设置参数值
121
- * @param key 参数名
122
- * @param value 参数值
123
- * @throws `Error` 仅用于模板
124
- */
125
- setValue(key: string, value: string): void;
126
- /**
127
- * 将匿名参数改写为命名参数
128
- * @throws `Error` 仅用于模板
129
- */
130
- anonToNamed(): void;
131
- /**
132
- * 替换模板名
133
- * @param title 模板名
134
- * @throws `Error` 仅用于模板
135
- */
136
- replaceTemplate(title: string): void;
137
- /**
138
- * 替换模块名
139
- * @param title 模块名
140
- * @throws `Error` 仅用于模块
141
- */
142
- replaceModule(title: string): void;
143
- /**
144
- * 替换模块函数
145
- * @param func 模块函数名
146
- * @throws `Error` 仅用于模块
147
- * @throws `Error` 尚未指定模块名称
148
- */
149
- replaceFunction(func: string): void;
150
- /**
151
- * 重复参数计数
152
- * @throws `Error` 仅用于模板
153
- */
154
- hasDuplicatedArgs(): number;
155
- /**
156
- * 修复重名参数:
157
- * `aggressive = false`时只移除空参数和全同参数,优先保留匿名参数,否则将所有匿名参数更改为命名。
158
- * `aggressive = true`时还会尝试处理连续的以数字编号的参数。
159
- * @param aggressive 是否使用有更大风险的修复手段
160
- */
161
- fixDuplication(aggressive?: boolean): string[];
162
- /**
163
- * 转义模板内的表格
164
- * @throws `Error` 转义失败
165
- */
166
- escapeTables(): TranscludeToken;
167
- }