wikiparser-node 1.10.0 → 1.11.0-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 (173) 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/i18n/zh-hans.json +1 -1
  13. package/i18n/zh-hant.json +1 -1
  14. package/package.json +43 -33
  15. package/config/.schema.json +0 -186
  16. package/dist/addon/table.js +0 -486
  17. package/dist/addon/token.js +0 -324
  18. package/dist/addon/transclude.js +0 -185
  19. package/dist/base.d.ts +0 -81
  20. package/dist/base.js +0 -39
  21. package/dist/index.d.ts +0 -33
  22. package/dist/index.js +0 -231
  23. package/dist/internal.d.ts +0 -46
  24. package/dist/lib/element.d.ts +0 -125
  25. package/dist/lib/element.js +0 -374
  26. package/dist/lib/node.d.ts +0 -173
  27. package/dist/lib/node.js +0 -478
  28. package/dist/lib/range.d.ts +0 -105
  29. package/dist/lib/range.js +0 -406
  30. package/dist/lib/ranges.d.ts +0 -28
  31. package/dist/lib/ranges.js +0 -126
  32. package/dist/lib/rect.d.ts +0 -18
  33. package/dist/lib/rect.js +0 -34
  34. package/dist/lib/text.d.ts +0 -58
  35. package/dist/lib/text.js +0 -361
  36. package/dist/lib/title.d.ts +0 -42
  37. package/dist/lib/title.js +0 -205
  38. package/dist/mixin/attributesParent.d.ts +0 -49
  39. package/dist/mixin/attributesParent.js +0 -79
  40. package/dist/mixin/fixed.d.ts +0 -5
  41. package/dist/mixin/fixed.js +0 -32
  42. package/dist/mixin/flagsParent.d.ts +0 -41
  43. package/dist/mixin/flagsParent.js +0 -60
  44. package/dist/mixin/hidden.d.ts +0 -7
  45. package/dist/mixin/hidden.js +0 -37
  46. package/dist/mixin/magicLinkParent.d.ts +0 -19
  47. package/dist/mixin/magicLinkParent.js +0 -43
  48. package/dist/mixin/singleLine.d.ts +0 -5
  49. package/dist/mixin/singleLine.js +0 -25
  50. package/dist/mixin/sol.d.ts +0 -6
  51. package/dist/mixin/sol.js +0 -44
  52. package/dist/mixin/syntax.d.ts +0 -8
  53. package/dist/mixin/syntax.js +0 -46
  54. package/dist/parser/braces.js +0 -150
  55. package/dist/parser/commentAndExt.js +0 -79
  56. package/dist/parser/converter.js +0 -39
  57. package/dist/parser/externalLinks.js +0 -37
  58. package/dist/parser/hrAndDoubleUnderscore.js +0 -42
  59. package/dist/parser/html.js +0 -38
  60. package/dist/parser/links.js +0 -101
  61. package/dist/parser/list.js +0 -99
  62. package/dist/parser/magicLinks.js +0 -53
  63. package/dist/parser/quotes.js +0 -67
  64. package/dist/parser/redirect.js +0 -26
  65. package/dist/parser/selector.js +0 -394
  66. package/dist/parser/table.js +0 -123
  67. package/dist/src/arg.d.ts +0 -51
  68. package/dist/src/arg.js +0 -214
  69. package/dist/src/atom.d.ts +0 -14
  70. package/dist/src/atom.js +0 -52
  71. package/dist/src/attribute.d.ts +0 -64
  72. package/dist/src/attribute.js +0 -483
  73. package/dist/src/attributes.d.ts +0 -101
  74. package/dist/src/attributes.js +0 -382
  75. package/dist/src/converter.d.ts +0 -28
  76. package/dist/src/converter.js +0 -147
  77. package/dist/src/converterFlags.d.ts +0 -80
  78. package/dist/src/converterFlags.js +0 -242
  79. package/dist/src/converterRule.d.ts +0 -71
  80. package/dist/src/converterRule.js +0 -216
  81. package/dist/src/extLink.d.ts +0 -36
  82. package/dist/src/extLink.js +0 -198
  83. package/dist/src/gallery.d.ts +0 -47
  84. package/dist/src/gallery.js +0 -142
  85. package/dist/src/heading.d.ts +0 -40
  86. package/dist/src/heading.js +0 -191
  87. package/dist/src/hidden.d.ts +0 -9
  88. package/dist/src/hidden.js +0 -80
  89. package/dist/src/html.d.ts +0 -57
  90. package/dist/src/html.js +0 -343
  91. package/dist/src/imageParameter.d.ts +0 -58
  92. package/dist/src/imageParameter.js +0 -247
  93. package/dist/src/imagemap.d.ts +0 -47
  94. package/dist/src/imagemap.js +0 -146
  95. package/dist/src/imagemapLink.d.ts +0 -31
  96. package/dist/src/imagemapLink.js +0 -97
  97. package/dist/src/index.d.ts +0 -141
  98. package/dist/src/index.js +0 -795
  99. package/dist/src/link/base.d.ts +0 -54
  100. package/dist/src/link/base.js +0 -263
  101. package/dist/src/link/category.d.ts +0 -22
  102. package/dist/src/link/category.js +0 -34
  103. package/dist/src/link/file.d.ts +0 -96
  104. package/dist/src/link/file.js +0 -276
  105. package/dist/src/link/galleryImage.d.ts +0 -29
  106. package/dist/src/link/galleryImage.js +0 -132
  107. package/dist/src/link/index.d.ts +0 -39
  108. package/dist/src/link/index.js +0 -99
  109. package/dist/src/link/redirectTarget.d.ts +0 -27
  110. package/dist/src/link/redirectTarget.js +0 -72
  111. package/dist/src/magicLink.d.ts +0 -61
  112. package/dist/src/magicLink.js +0 -261
  113. package/dist/src/nested.d.ts +0 -40
  114. package/dist/src/nested.js +0 -106
  115. package/dist/src/nowiki/base.d.ts +0 -30
  116. package/dist/src/nowiki/base.js +0 -89
  117. package/dist/src/nowiki/comment.d.ts +0 -14
  118. package/dist/src/nowiki/comment.js +0 -124
  119. package/dist/src/nowiki/dd.d.ts +0 -8
  120. package/dist/src/nowiki/dd.js +0 -72
  121. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  122. package/dist/src/nowiki/doubleUnderscore.js +0 -97
  123. package/dist/src/nowiki/hr.d.ts +0 -5
  124. package/dist/src/nowiki/hr.js +0 -70
  125. package/dist/src/nowiki/index.d.ts +0 -14
  126. package/dist/src/nowiki/index.js +0 -31
  127. package/dist/src/nowiki/list.d.ts +0 -5
  128. package/dist/src/nowiki/list.js +0 -65
  129. package/dist/src/nowiki/listBase.d.ts +0 -17
  130. package/dist/src/nowiki/listBase.js +0 -75
  131. package/dist/src/nowiki/noinclude.d.ts +0 -6
  132. package/dist/src/nowiki/noinclude.js +0 -75
  133. package/dist/src/nowiki/quote.d.ts +0 -14
  134. package/dist/src/nowiki/quote.js +0 -135
  135. package/dist/src/onlyinclude.d.ts +0 -13
  136. package/dist/src/onlyinclude.js +0 -58
  137. package/dist/src/paramTag/index.d.ts +0 -30
  138. package/dist/src/paramTag/index.js +0 -78
  139. package/dist/src/paramTag/inputbox.d.ts +0 -8
  140. package/dist/src/paramTag/inputbox.js +0 -22
  141. package/dist/src/parameter.d.ts +0 -60
  142. package/dist/src/parameter.js +0 -268
  143. package/dist/src/pre.d.ts +0 -28
  144. package/dist/src/pre.js +0 -60
  145. package/dist/src/redirect.d.ts +0 -30
  146. package/dist/src/redirect.js +0 -126
  147. package/dist/src/syntax.d.ts +0 -17
  148. package/dist/src/syntax.js +0 -87
  149. package/dist/src/table/base.d.ts +0 -28
  150. package/dist/src/table/base.js +0 -81
  151. package/dist/src/table/index.d.ts +0 -230
  152. package/dist/src/table/index.js +0 -505
  153. package/dist/src/table/td.d.ts +0 -72
  154. package/dist/src/table/td.js +0 -370
  155. package/dist/src/table/tr.d.ts +0 -30
  156. package/dist/src/table/tr.js +0 -59
  157. package/dist/src/table/trBase.d.ts +0 -49
  158. package/dist/src/table/trBase.js +0 -164
  159. package/dist/src/tagPair/ext.d.ts +0 -29
  160. package/dist/src/tagPair/ext.js +0 -220
  161. package/dist/src/tagPair/include.d.ts +0 -33
  162. package/dist/src/tagPair/include.js +0 -130
  163. package/dist/src/tagPair/index.d.ts +0 -23
  164. package/dist/src/tagPair/index.js +0 -128
  165. package/dist/src/transclude.d.ts +0 -159
  166. package/dist/src/transclude.js +0 -587
  167. package/dist/util/constants.js +0 -25
  168. package/dist/util/debug.js +0 -95
  169. package/dist/util/diff.js +0 -83
  170. package/dist/util/lint.js +0 -32
  171. package/dist/util/string.js +0 -84
  172. package/errors/README +0 -3
  173. 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,57 +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
- /**
30
- * @param name 标签名
31
- * @param attr 标签属性
32
- * @param closing 是否闭合
33
- * @param selfClosing 是否自封闭
34
- */
35
- constructor(name: string, attr: AttributesToken, closing: boolean, selfClosing: boolean, config?: Config, accum?: Token[]);
36
- /**
37
- * 搜索匹配的标签
38
- * @throws `SyntaxError` 同时闭合和自封闭的标签
39
- * @throws `SyntaxError` 无效自封闭标签
40
- * @throws `SyntaxError` 未匹配的标签
41
- */
42
- findMatchingTag(): this | undefined;
43
- /** @override */
44
- json(): AST;
45
- cloneNode(): this;
46
- /**
47
- * 更换标签名
48
- * @param tag 标签名
49
- * @throws `RangeError` 非法的HTML标签
50
- */
51
- replaceTag(tag: string): void;
52
- /**
53
- * 修复无效自封闭标签
54
- * @throws `Error` 无法修复无效自封闭标签
55
- */
56
- fix(): void;
57
- }
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
- /* NOT FOR BROWSER END */
141
- /**
142
- * @param name 标签名
143
- * @param attr 标签属性
144
- * @param closing 是否闭合
145
- * @param selfClosing 是否自封闭
146
- */
147
- constructor(name, attr, closing, selfClosing, config, accum) {
148
- super(undefined, config, accum);
149
- this.insertAt(attr);
150
- this.setAttribute('name', name.toLowerCase());
151
- this.#closing = closing;
152
- this.#selfClosing = selfClosing;
153
- this.#tag = name;
154
- }
155
- /** @private */
156
- toString(skip) {
157
- return `<${this.closing ? '/' : ''}${this.#tag}${super.toString(skip)}${this.#selfClosing ? '/' : ''}>`;
158
- }
159
- /** @private */
160
- text() {
161
- const { closing,
162
- /* NOT FOR BROWSER */
163
- name, } = this, { html: [, , voidTags] } = this.getAttribute('config'), tag = this.#tag + (closing ? '' : super.text());
164
- /* NOT FOR BROWSER */
165
- if (voidTags.includes(name)) {
166
- return closing && name !== 'br' ? '' : `<${tag}/>`;
167
- }
168
- /* NOT FOR BROWSER END */
169
- return `<${closing ? '/' : ''}${tag}${this.#selfClosing ? '/' : ''}>`;
170
- }
171
- /** @private */
172
- getAttribute(key) {
173
- return key === 'padding'
174
- ? this.#tag.length + (this.closing ? 2 : 1)
175
- : super.getAttribute(key);
176
- }
177
- /** @private */
178
- lint(start = this.getAbsoluteIndex(), re) {
179
- const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
180
- if (this.name === 'h1' && !this.closing) {
181
- errors.push((0, lint_1.generateForSelf)(this, rect, 'h1', '<h1>'));
182
- }
183
- if (this.closest('table-attrs')) {
184
- errors.push((0, lint_1.generateForSelf)(this, rect, 'parsing-order', 'HTML tag in table attributes'));
185
- }
186
- try {
187
- this.findMatchingTag();
188
- }
189
- catch (e) {
190
- if (e instanceof SyntaxError) {
191
- const { message } = e;
192
- const msg = message.split(':')[0].toLowerCase(), error = (0, lint_1.generateForSelf)(this, rect, 'unmatched-tag', msg);
193
- if (msg === 'unclosed tag' && !this.closest('heading-title')) {
194
- if (formattingTags.has(this.name)) {
195
- const childNodes = this.parentNode?.childNodes, i = childNodes?.indexOf(this);
196
- if (!childNodes?.slice(0, i).some(({ type, name }) => type === 'html' && name === this.name)) {
197
- error.severity = 'warning';
198
- }
199
- }
200
- else {
201
- error.severity = 'warning';
202
- }
203
- }
204
- else if (msg === 'unmatched closing tag') {
205
- const ancestor = this.closest('magic-word');
206
- if (ancestor && magicWords.has(ancestor.name)) {
207
- error.severity = 'warning';
208
- }
209
- else {
210
- error.suggestions = [
211
- {
212
- desc: 'remove',
213
- range: [start, error.endIndex],
214
- text: '',
215
- },
216
- ];
217
- }
218
- }
219
- else if (msg === 'tag that is both closing and self-closing') {
220
- const { html: [, , voidTags] } = this.getAttribute('config');
221
- if (voidTags.includes(this.name)) {
222
- error.fix = {
223
- range: [start + 1, start + 2],
224
- text: '',
225
- };
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
- toHtml() {
333
- const { closing, name } = this, { html: [, selfClosingTags, voidTags] } = this.getAttribute('config'), tag = name + (closing ? '' : super.toHtml());
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,58 +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
- }