wikiparser-node 1.5.2-b → 1.5.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 (163) hide show
  1. package/config/.schema.json +172 -0
  2. package/config/enwiki.json +814 -1
  3. package/config/llwiki.json +35 -1
  4. package/config/moegirl.json +44 -1
  5. package/config/zhwiki.json +466 -1
  6. package/dist/addon/table.d.ts +6 -0
  7. package/dist/addon/table.js +564 -0
  8. package/dist/base.d.ts +72 -0
  9. package/dist/base.js +38 -0
  10. package/dist/index.d.ts +30 -0
  11. package/dist/index.js +214 -0
  12. package/dist/internal.d.ts +44 -0
  13. package/dist/lib/element.d.ts +150 -0
  14. package/dist/lib/element.js +613 -0
  15. package/dist/lib/node.d.ts +146 -0
  16. package/dist/lib/node.js +428 -0
  17. package/dist/lib/range.d.ts +104 -0
  18. package/dist/lib/range.js +385 -0
  19. package/dist/lib/ranges.d.ts +26 -0
  20. package/dist/lib/ranges.js +118 -0
  21. package/dist/lib/text.d.ts +62 -0
  22. package/dist/lib/text.js +361 -0
  23. package/dist/lib/title.d.ts +38 -0
  24. package/dist/lib/title.js +166 -0
  25. package/dist/mixin/attributesParent.d.ts +50 -0
  26. package/dist/mixin/attributesParent.js +78 -0
  27. package/dist/mixin/fixed.d.ts +6 -0
  28. package/dist/mixin/fixed.js +30 -0
  29. package/dist/mixin/flagsParent.d.ts +72 -0
  30. package/dist/mixin/flagsParent.js +59 -0
  31. package/dist/mixin/hidden.d.ts +5 -0
  32. package/dist/mixin/hidden.js +24 -0
  33. package/dist/mixin/magicLinkParent.d.ts +40 -0
  34. package/dist/mixin/magicLinkParent.js +42 -0
  35. package/dist/mixin/singleLine.d.ts +6 -0
  36. package/dist/mixin/singleLine.js +26 -0
  37. package/dist/mixin/sol.d.ts +6 -0
  38. package/dist/mixin/sol.js +43 -0
  39. package/dist/mixin/syntax.d.ts +9 -0
  40. package/dist/mixin/syntax.js +50 -0
  41. package/dist/parser/braces.js +131 -0
  42. package/dist/parser/commentAndExt.js +90 -0
  43. package/dist/parser/converter.js +41 -0
  44. package/dist/parser/externalLinks.js +32 -0
  45. package/dist/parser/hrAndDoubleUnderscore.js +41 -0
  46. package/dist/parser/html.js +39 -0
  47. package/dist/parser/links.js +95 -0
  48. package/dist/parser/list.js +98 -0
  49. package/dist/parser/magicLinks.js +43 -0
  50. package/dist/parser/quotes.js +68 -0
  51. package/dist/parser/selector.js +162 -0
  52. package/dist/parser/table.js +124 -0
  53. package/dist/src/arg.d.ts +58 -0
  54. package/dist/src/arg.js +214 -0
  55. package/dist/src/atom.d.ts +12 -0
  56. package/dist/src/atom.js +27 -0
  57. package/dist/src/attribute.d.ts +71 -0
  58. package/dist/src/attribute.js +502 -0
  59. package/dist/src/attributes.d.ts +109 -0
  60. package/dist/src/attributes.js +356 -0
  61. package/dist/src/converter.d.ts +33 -0
  62. package/dist/src/converter.js +134 -0
  63. package/dist/src/converterFlags.d.ts +87 -0
  64. package/dist/src/converterFlags.js +242 -0
  65. package/dist/src/converterRule.d.ts +77 -0
  66. package/dist/src/converterRule.js +209 -0
  67. package/dist/src/extLink.d.ts +43 -0
  68. package/dist/src/extLink.js +186 -0
  69. package/dist/src/gallery.d.ts +54 -0
  70. package/dist/src/gallery.js +139 -0
  71. package/dist/src/heading.d.ts +47 -0
  72. package/dist/src/heading.js +190 -0
  73. package/dist/src/hidden.d.ts +7 -0
  74. package/dist/src/hidden.js +23 -0
  75. package/dist/src/html.d.ts +65 -0
  76. package/dist/src/html.js +358 -0
  77. package/dist/src/imageParameter.d.ts +65 -0
  78. package/dist/src/imageParameter.js +257 -0
  79. package/dist/src/imagemap.d.ts +56 -0
  80. package/dist/src/imagemap.js +150 -0
  81. package/dist/src/imagemapLink.d.ts +31 -0
  82. package/dist/src/imagemapLink.js +93 -0
  83. package/dist/src/index.d.ts +143 -0
  84. package/dist/src/index.js +813 -0
  85. package/dist/src/link/base.d.ts +52 -0
  86. package/dist/src/link/base.js +229 -0
  87. package/dist/src/link/category.d.ts +13 -0
  88. package/dist/src/link/category.js +28 -0
  89. package/dist/src/link/file.d.ts +98 -0
  90. package/dist/src/link/file.js +272 -0
  91. package/dist/src/link/galleryImage.d.ts +32 -0
  92. package/dist/src/link/galleryImage.js +157 -0
  93. package/dist/src/link/index.d.ts +56 -0
  94. package/dist/src/link/index.js +133 -0
  95. package/dist/src/magicLink.d.ts +59 -0
  96. package/dist/src/magicLink.js +223 -0
  97. package/dist/src/nested.d.ts +43 -0
  98. package/dist/src/nested.js +105 -0
  99. package/dist/src/nowiki/base.d.ts +31 -0
  100. package/dist/src/nowiki/base.js +93 -0
  101. package/dist/src/nowiki/comment.d.ts +25 -0
  102. package/dist/src/nowiki/comment.js +76 -0
  103. package/dist/src/nowiki/dd.d.ts +8 -0
  104. package/dist/src/nowiki/dd.js +24 -0
  105. package/dist/src/nowiki/doubleUnderscore.d.ts +18 -0
  106. package/dist/src/nowiki/doubleUnderscore.js +101 -0
  107. package/dist/src/nowiki/hr.d.ts +5 -0
  108. package/dist/src/nowiki/hr.js +63 -0
  109. package/dist/src/nowiki/index.d.ts +16 -0
  110. package/dist/src/nowiki/index.js +27 -0
  111. package/dist/src/nowiki/list.d.ts +16 -0
  112. package/dist/src/nowiki/list.js +97 -0
  113. package/dist/src/nowiki/listBase.d.ts +5 -0
  114. package/dist/src/nowiki/listBase.js +61 -0
  115. package/dist/src/nowiki/noinclude.d.ts +10 -0
  116. package/dist/src/nowiki/noinclude.js +23 -0
  117. package/dist/src/nowiki/quote.d.ts +14 -0
  118. package/dist/src/nowiki/quote.js +131 -0
  119. package/dist/src/onlyinclude.d.ts +16 -0
  120. package/dist/src/onlyinclude.js +57 -0
  121. package/dist/src/paramTag/index.d.ts +37 -0
  122. package/dist/src/paramTag/index.js +77 -0
  123. package/dist/src/paramTag/inputbox.d.ts +8 -0
  124. package/dist/src/paramTag/inputbox.js +22 -0
  125. package/dist/src/parameter.d.ts +70 -0
  126. package/dist/src/parameter.js +264 -0
  127. package/dist/src/pre.d.ts +28 -0
  128. package/dist/src/pre.js +55 -0
  129. package/dist/src/syntax.d.ts +20 -0
  130. package/dist/src/syntax.js +86 -0
  131. package/dist/src/table/base.d.ts +30 -0
  132. package/dist/src/table/base.js +132 -0
  133. package/dist/src/table/index.d.ts +233 -0
  134. package/dist/src/table/index.js +396 -0
  135. package/dist/src/table/td.d.ts +86 -0
  136. package/dist/src/table/td.js +350 -0
  137. package/dist/src/table/tr.d.ts +32 -0
  138. package/dist/src/table/tr.js +58 -0
  139. package/dist/src/table/trBase.d.ts +53 -0
  140. package/dist/src/table/trBase.js +152 -0
  141. package/dist/src/tagPair/ext.d.ts +32 -0
  142. package/dist/src/tagPair/ext.js +203 -0
  143. package/dist/src/tagPair/include.d.ts +35 -0
  144. package/dist/src/tagPair/include.js +74 -0
  145. package/dist/src/tagPair/index.d.ts +27 -0
  146. package/dist/src/tagPair/index.js +128 -0
  147. package/dist/src/transclude.d.ts +167 -0
  148. package/dist/src/transclude.js +717 -0
  149. package/dist/util/constants.js +28 -0
  150. package/dist/util/debug.js +88 -0
  151. package/dist/util/diff.js +83 -0
  152. package/dist/util/lint.js +31 -0
  153. package/dist/util/string.js +54 -0
  154. package/errors/README +1 -0
  155. package/package.json +14 -27
  156. package/printed/README +1 -0
  157. package/bundle/bundle.min.js +0 -37
  158. package/extensions/dist/base.js +0 -64
  159. package/extensions/dist/editor.js +0 -159
  160. package/extensions/dist/highlight.js +0 -59
  161. package/extensions/dist/lint.js +0 -60
  162. package/extensions/editor.css +0 -63
  163. package/extensions/ui.css +0 -141
@@ -0,0 +1,65 @@
1
+ import Parser from '../index';
2
+ import { Token } from './index';
3
+ import type { LintError, AST } from '../base';
4
+ import type { AttributesParentBase } from '../mixin/attributesParent';
5
+ import type { AttributesToken } from '../internal';
6
+ export interface HtmlToken extends AttributesParentBase {
7
+ }
8
+ /**
9
+ * HTML标签
10
+ * @classdesc `{childNodes: [AttributesToken]}`
11
+ */
12
+ export declare abstract class HtmlToken extends Token {
13
+ #private;
14
+ readonly type = "html";
15
+ readonly name: string;
16
+ readonly childNodes: readonly [AttributesToken];
17
+ abstract get firstChild(): AttributesToken;
18
+ abstract get lastChild(): AttributesToken;
19
+ abstract get children(): [AttributesToken];
20
+ abstract get firstElementChild(): AttributesToken;
21
+ abstract get lastElementChild(): AttributesToken;
22
+ /** 是否自封闭 */
23
+ get selfClosing(): boolean;
24
+ /** 是否是闭合标签 */
25
+ get closing(): boolean;
26
+ /** @throws `Error` 自封闭标签或空标签 */
27
+ set closing(value: boolean);
28
+ /** @throws `Error` 闭合标签或无效自封闭标签 */
29
+ set selfClosing(value: boolean);
30
+ /**
31
+ * @param name 标签名
32
+ * @param attr 标签属性
33
+ * @param closing 是否闭合
34
+ * @param selfClosing 是否自封闭
35
+ */
36
+ constructor(name: string, attr: AttributesToken, closing: boolean, selfClosing: boolean, config?: Parser.Config, accum?: Token[]);
37
+ /** @override */
38
+ text(): string;
39
+ /** @override */
40
+ lint(start?: number): LintError[];
41
+ /**
42
+ * 搜索匹配的标签
43
+ * @throws `SyntaxError` 同时闭合和自封闭的标签
44
+ * @throws `SyntaxError` 无效自封闭标签
45
+ * @throws `SyntaxError` 未匹配的标签
46
+ */
47
+ findMatchingTag(): this | undefined;
48
+ /** @override */
49
+ print(): string;
50
+ /** @override */
51
+ json(): AST;
52
+ /** @override */
53
+ cloneNode(): this;
54
+ /**
55
+ * 更换标签名
56
+ * @param tag 标签名
57
+ * @throws `RangeError` 非法的HTML标签
58
+ */
59
+ replaceTag(tag: string): void;
60
+ /**
61
+ * 修复无效自封闭标签
62
+ * @throws `Error` 无法修复无效自封闭标签
63
+ */
64
+ fix(): void;
65
+ }
@@ -0,0 +1,358 @@
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.HtmlToken = void 0;
38
+ const lint_1 = require("../util/lint");
39
+ const string_1 = require("../util/string");
40
+ const debug_1 = require("../util/debug");
41
+ const constants_1 = require("../util/constants");
42
+ const fixed_1 = require("../mixin/fixed");
43
+ const attributesParent_1 = require("../mixin/attributesParent");
44
+ const index_1 = require("../index");
45
+ const index_2 = require("./index");
46
+ const magicWords = new Set(['if', 'ifeq', 'ifexpr', 'ifexist', 'iferror', 'switch']), formattingTags = new Set([
47
+ 'b',
48
+ 'big',
49
+ 'center',
50
+ 'cite',
51
+ 'code',
52
+ 'del',
53
+ 'dfn',
54
+ 'em',
55
+ 'font',
56
+ 'i',
57
+ 'ins',
58
+ 'kbd',
59
+ 'mark',
60
+ 'pre',
61
+ 'q',
62
+ 's',
63
+ 'samp',
64
+ 'small',
65
+ 'strike',
66
+ 'strong',
67
+ 'sub',
68
+ 'sup',
69
+ 'tt',
70
+ 'u',
71
+ 'var',
72
+ ]), obsoleteTags = new Set(['strike', 'big', 'center', 'font', 'tt']);
73
+ /* NOT FOR BROWSER END */
74
+ /**
75
+ * HTML标签
76
+ * @classdesc `{childNodes: [AttributesToken]}`
77
+ */
78
+ let HtmlToken = (() => {
79
+ let _classDecorators = [fixed_1.fixedToken, (0, attributesParent_1.attributesParent)()];
80
+ let _classDescriptor;
81
+ let _classExtraInitializers = [];
82
+ let _classThis;
83
+ let _classSuper = index_2.Token;
84
+ var HtmlToken = class extends _classSuper {
85
+ static { _classThis = this; }
86
+ static {
87
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
88
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
89
+ HtmlToken = _classThis = _classDescriptor.value;
90
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
91
+ __runInitializers(_classThis, _classExtraInitializers);
92
+ }
93
+ type = 'html';
94
+ #closing;
95
+ #selfClosing;
96
+ #tag;
97
+ /* NOT FOR BROWSER END */
98
+ /** 是否自封闭 */
99
+ get selfClosing() {
100
+ return this.#selfClosing;
101
+ }
102
+ /** 是否是闭合标签 */
103
+ get closing() {
104
+ return this.#closing;
105
+ }
106
+ /* NOT FOR BROWSER */
107
+ /** @throws `Error` 自封闭标签或空标签 */
108
+ set closing(value) {
109
+ if (!value) {
110
+ this.#closing = false;
111
+ return;
112
+ }
113
+ else if (this.selfClosing) {
114
+ throw new Error('这是一个自封闭标签!');
115
+ }
116
+ const { html: [, , tags] } = this.getAttribute('config');
117
+ if (tags.includes(this.name)) {
118
+ throw new Error('这是一个空标签!');
119
+ }
120
+ this.#closing = true;
121
+ }
122
+ /** @throws `Error` 闭合标签或无效自封闭标签 */
123
+ set selfClosing(value) {
124
+ if (!value) {
125
+ this.#selfClosing = false;
126
+ return;
127
+ }
128
+ else if (this.closing) {
129
+ throw new Error('这是一个闭合标签!');
130
+ }
131
+ const { html: [tags] } = this.getAttribute('config');
132
+ if (tags.includes(this.name)) {
133
+ throw new Error(`<${this.name}>标签自封闭无效!`);
134
+ }
135
+ this.#selfClosing = true;
136
+ }
137
+ /* NOT FOR BROWSER END */
138
+ /**
139
+ * @param name 标签名
140
+ * @param attr 标签属性
141
+ * @param closing 是否闭合
142
+ * @param selfClosing 是否自封闭
143
+ */
144
+ constructor(name, attr, closing, selfClosing, config = index_1.default.getConfig(), accum = []) {
145
+ super(undefined, config, accum);
146
+ this.insertAt(attr);
147
+ this.setAttribute('name', name.toLowerCase());
148
+ this.#closing = closing;
149
+ this.#selfClosing = selfClosing;
150
+ this.#tag = name;
151
+ }
152
+ /** @private */
153
+ toString() {
154
+ return `<${this.closing ? '/' : ''}${this.#tag}${super.toString()}${this.#selfClosing ? '/' : ''}>`;
155
+ }
156
+ /** @override */
157
+ text() {
158
+ const { closing,
159
+ /* NOT FOR BROWSER */
160
+ name, } = this, { html: [, , voidTags] } = this.getAttribute('config'), tag = `${this.#tag}${closing ? '' : super.text()}`;
161
+ /* NOT FOR BROWSER */
162
+ if (voidTags.includes(name)) {
163
+ return closing && name !== 'br' ? '' : `<${tag}/>`;
164
+ }
165
+ /* NOT FOR BROWSER END */
166
+ return `<${closing ? '/' : ''}${tag}${this.#selfClosing ? '/' : ''}>`;
167
+ }
168
+ /** @private */
169
+ getAttribute(key) {
170
+ /* NOT FOR BROWSER */
171
+ if (key === 'tag') {
172
+ return this.#tag;
173
+ }
174
+ /* NOT FOR BROWSER END */
175
+ return key === 'padding'
176
+ ? this.#tag.length + (this.closing ? 2 : 1)
177
+ : super.getAttribute(key);
178
+ }
179
+ /** @override */
180
+ lint(start = this.getAbsoluteIndex()) {
181
+ const errors = super.lint(start);
182
+ let refError;
183
+ if (this.name === 'h1' && !this.closing) {
184
+ refError = (0, lint_1.generateForSelf)(this, { start }, 'h1', '<h1>');
185
+ errors.push(refError);
186
+ }
187
+ if (this.closest('table-attrs')) {
188
+ refError ??= (0, lint_1.generateForSelf)(this, { start }, 'h1', '');
189
+ errors.push({
190
+ ...refError,
191
+ rule: 'parsing-order',
192
+ message: index_1.default.msg('HTML tag in table attributes'),
193
+ });
194
+ }
195
+ try {
196
+ this.findMatchingTag();
197
+ }
198
+ catch (e) {
199
+ if (e instanceof SyntaxError) {
200
+ const { message } = e;
201
+ refError ??= (0, lint_1.generateForSelf)(this, { start }, 'h1', '');
202
+ const [msg] = message.split(':'), error = { ...refError, rule: 'unmatched-tag', message: index_1.default.msg(msg) };
203
+ if (msg === 'unclosed tag' && !this.closest('heading-title')) {
204
+ if (formattingTags.has(this.name)) {
205
+ const childNodes = this.parentNode?.childNodes, i = childNodes?.indexOf(this);
206
+ if (!childNodes?.slice(0, i).some(({ type, name }) => type === 'html' && name === this.name)) {
207
+ error.severity = 'warning';
208
+ }
209
+ }
210
+ else {
211
+ error.severity = 'warning';
212
+ }
213
+ }
214
+ else if (msg === 'unmatched closing tag') {
215
+ const ancestor = this.closest('magic-word');
216
+ if (ancestor && magicWords.has(ancestor.name)) {
217
+ error.severity = 'warning';
218
+ }
219
+ else {
220
+ error.suggestions = [
221
+ {
222
+ desc: 'remove',
223
+ range: [start, error.endIndex],
224
+ text: '',
225
+ },
226
+ ];
227
+ }
228
+ }
229
+ else if (msg === 'tag that is both closing and self-closing') {
230
+ const { html: [, , voidTags] } = this.getAttribute('config');
231
+ if (voidTags.includes(this.name)) {
232
+ error.fix = {
233
+ range: [start + 1, start + 2],
234
+ text: '',
235
+ };
236
+ }
237
+ }
238
+ errors.push(error);
239
+ }
240
+ }
241
+ if (obsoleteTags.has(this.name)) {
242
+ refError ??= (0, lint_1.generateForSelf)(this, { start }, 'h1', '');
243
+ errors.push({
244
+ ...refError,
245
+ rule: 'obsolete-tag',
246
+ message: index_1.default.msg('obsolete HTML tag'),
247
+ severity: 'warning',
248
+ });
249
+ }
250
+ if ((this.name === 'b' || this.name === 'strong') && this.closest('heading-title')) {
251
+ refError ??= (0, lint_1.generateForSelf)(this, { start }, 'h1', '');
252
+ errors.push({
253
+ ...refError,
254
+ rule: 'bold-header',
255
+ message: index_1.default.msg('bold in section header'),
256
+ severity: 'warning',
257
+ });
258
+ }
259
+ return errors;
260
+ }
261
+ /**
262
+ * 搜索匹配的标签
263
+ * @throws `SyntaxError` 同时闭合和自封闭的标签
264
+ * @throws `SyntaxError` 无效自封闭标签
265
+ * @throws `SyntaxError` 未匹配的标签
266
+ */
267
+ findMatchingTag() {
268
+ const { html: [normalTags, flexibleTags, voidTags] } = this.getAttribute('config'), { name: tagName, parentNode, closing } = this, string = (0, string_1.noWrap)(String(this));
269
+ if (closing && (this.#selfClosing || voidTags.includes(tagName))) {
270
+ throw new SyntaxError(`tag that is both closing and self-closing: ${string}`);
271
+ }
272
+ else if (voidTags.includes(tagName) || this.#selfClosing && flexibleTags.includes(tagName)) { // 自封闭标签
273
+ return this;
274
+ }
275
+ else if (this.#selfClosing && normalTags.includes(tagName)) {
276
+ throw new SyntaxError(`invalid self-closing tag: ${string}`);
277
+ }
278
+ else if (!parentNode) {
279
+ return undefined;
280
+ }
281
+ const { childNodes } = parentNode, i = childNodes.indexOf(this), siblings = (closing ? childNodes.slice(0, i).reverse() : childNodes.slice(i + 1))
282
+ .filter((child) => child.type === 'html' && child.name === tagName);
283
+ let imbalance = closing ? -1 : 1;
284
+ for (const token of siblings) {
285
+ if (token.#closing) {
286
+ imbalance--;
287
+ }
288
+ else {
289
+ imbalance++;
290
+ }
291
+ if (imbalance === 0) {
292
+ return token;
293
+ }
294
+ }
295
+ throw new SyntaxError(`${closing ? 'unmatched closing' : 'unclosed'} tag: ${string}`);
296
+ }
297
+ /** @override */
298
+ print() {
299
+ return super.print({
300
+ pre: `&lt;${this.closing ? '/' : ''}${this.#tag}`,
301
+ post: `${this.#selfClosing ? '/' : ''}&gt;`,
302
+ });
303
+ }
304
+ /** @override */
305
+ json() {
306
+ const json = super.json();
307
+ Object.assign(json, { closing: this.closing, selfClosing: this.#selfClosing });
308
+ return json;
309
+ }
310
+ /* NOT FOR BROWSER */
311
+ /** @override */
312
+ cloneNode() {
313
+ const [attr] = this.cloneChildNodes(), config = this.getAttribute('config');
314
+ // @ts-expect-error abstract class
315
+ return debug_1.Shadow.run(() => new HtmlToken(this.#tag, attr, this.closing, this.selfClosing, config));
316
+ }
317
+ /**
318
+ * 更换标签名
319
+ * @param tag 标签名
320
+ * @throws `RangeError` 非法的HTML标签
321
+ */
322
+ replaceTag(tag) {
323
+ const name = tag.toLowerCase();
324
+ if (!this.getAttribute('config').html.flat().includes(name)) {
325
+ throw new RangeError(`非法的HTML标签:${tag}`);
326
+ }
327
+ this.setAttribute('name', name);
328
+ this.#tag = tag;
329
+ }
330
+ /**
331
+ * 修复无效自封闭标签
332
+ * @throws `Error` 无法修复无效自封闭标签
333
+ */
334
+ fix() {
335
+ const { html: [normalTags] } = this.getAttribute('config'), { parentNode, name: tagName, firstChild, selfClosing } = this;
336
+ if (!parentNode || !selfClosing || !normalTags.includes(tagName)) {
337
+ return;
338
+ }
339
+ else if (firstChild.text().trim()) {
340
+ this.#selfClosing = false;
341
+ this.after(index_1.default.parse(`</${this.name}>`, false, 3, this.getAttribute('config')).firstChild);
342
+ return;
343
+ }
344
+ const { childNodes } = parentNode, i = childNodes.indexOf(this), prevSiblings = childNodes.slice(0, i)
345
+ .filter((child) => child.type === 'html' && child.name === tagName), imbalance = prevSiblings.reduce((acc, { closing }) => acc + (closing ? 1 : -1), 0);
346
+ if (imbalance < 0) {
347
+ this.#selfClosing = false;
348
+ this.#closing = true;
349
+ }
350
+ else {
351
+ throw new Error(`无法修复无效自封闭标签:前文共有 ${imbalance} 个未匹配的闭合标签`);
352
+ }
353
+ }
354
+ };
355
+ return HtmlToken = _classThis;
356
+ })();
357
+ exports.HtmlToken = HtmlToken;
358
+ constants_1.classes['HtmlToken'] = __filename;
@@ -0,0 +1,65 @@
1
+ import Parser from '../index';
2
+ import { Token } from './index';
3
+ import type { LintError } from '../base';
4
+ import type { Title } from '../lib/title';
5
+ import type { AtomToken, FileToken, AstNodes, AstText } from '../internal';
6
+ export declare const galleryParams: Set<string>;
7
+ /** 图片参数 */
8
+ export declare abstract class ImageParameterToken extends Token {
9
+ #private;
10
+ readonly type = "image-parameter";
11
+ readonly name: string;
12
+ abstract get parentNode(): FileToken | undefined;
13
+ abstract get nextSibling(): this | undefined;
14
+ abstract get previousSibling(): AtomToken | this;
15
+ abstract get parentElement(): FileToken | undefined;
16
+ abstract get nextElementSibling(): this | undefined;
17
+ abstract get previousElementSibling(): AtomToken | this;
18
+ /** 图片链接 */
19
+ get link(): string | Title | undefined;
20
+ set link(value: string);
21
+ /** getValue()的getter */
22
+ get value(): string | true;
23
+ set value(value: string | true);
24
+ /** 图片大小 */
25
+ get size(): {
26
+ width: string;
27
+ height: string;
28
+ } | undefined;
29
+ set size(size: {
30
+ width: string;
31
+ height: string;
32
+ } | undefined);
33
+ /** 图片宽度 */
34
+ get width(): string | undefined;
35
+ set width(width: string | undefined);
36
+ /** 图片高度 */
37
+ get height(): string | undefined;
38
+ set height(height: string | undefined);
39
+ /** @param str 图片参数 */
40
+ constructor(str: string, extension: string | undefined, config?: Parser.Config, accum?: Token[]);
41
+ /** @override */
42
+ text(): string;
43
+ /** @override */
44
+ lint(start?: number): LintError[];
45
+ /** 获取参数值 */
46
+ getValue(): string | true;
47
+ /** @override */
48
+ print(): string;
49
+ /** @override */
50
+ cloneNode(): this;
51
+ /**
52
+ * @override
53
+ * @param token 待插入的子节点
54
+ * @param i 插入位置
55
+ * @throws `Error` 不接受自定义输入的图片参数
56
+ */
57
+ insertAt(token: string, i?: number): AstText;
58
+ insertAt<T extends AstNodes>(token: T, i?: number): T;
59
+ /**
60
+ * 设置参数值
61
+ * @param value 参数值
62
+ * @throws `Error` 无效参数
63
+ */
64
+ setValue(value?: string | boolean): void;
65
+ }