wikiparser-node 1.5.2 → 1.5.3-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 +37 -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 +141 -0
  12. package/package.json +30 -17
  13. package/config/.schema.json +0 -172
  14. package/dist/addon/table.d.ts +0 -6
  15. package/dist/addon/table.js +0 -564
  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 -150
  22. package/dist/lib/element.js +0 -613
  23. package/dist/lib/node.d.ts +0 -146
  24. package/dist/lib/node.js +0 -428
  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 -118
  29. package/dist/lib/text.d.ts +0 -62
  30. package/dist/lib/text.js +0 -361
  31. package/dist/lib/title.d.ts +0 -38
  32. package/dist/lib/title.js +0 -166
  33. package/dist/mixin/attributesParent.d.ts +0 -50
  34. package/dist/mixin/attributesParent.js +0 -78
  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 -186
  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 -56
  88. package/dist/src/imagemap.js +0 -150
  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 -813
  93. package/dist/src/link/base.d.ts +0 -52
  94. package/dist/src/link/base.js +0 -229
  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 -97
  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 -28
  136. package/dist/src/pre.js +0 -55
  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 -30
  140. package/dist/src/table/base.js +0 -132
  141. package/dist/src/table/index.d.ts +0 -233
  142. package/dist/src/table/index.js +0 -396
  143. package/dist/src/table/td.d.ts +0 -86
  144. package/dist/src/table/td.js +0 -350
  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 -152
  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,65 +0,0 @@
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
- }
package/dist/src/html.js DELETED
@@ -1,358 +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.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;
@@ -1,65 +0,0 @@
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
- }