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