wikiparser-node 1.11.0 → 1.11.1-b

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