wikiparser-node 1.9.2 → 1.9.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 (171) hide show
  1. package/bundle/bundle.min.js +39 -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 +58 -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 +32 -22
  13. package/config/.schema.json +0 -181
  14. package/dist/addon/table.js +0 -486
  15. package/dist/addon/token.js +0 -240
  16. package/dist/addon/transclude.js +0 -185
  17. package/dist/base.d.ts +0 -73
  18. package/dist/base.js +0 -39
  19. package/dist/index.d.ts +0 -31
  20. package/dist/index.js +0 -232
  21. package/dist/internal.d.ts +0 -46
  22. package/dist/lib/element.d.ts +0 -124
  23. package/dist/lib/element.js +0 -600
  24. package/dist/lib/node.d.ts +0 -166
  25. package/dist/lib/node.js +0 -472
  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 -54
  33. package/dist/lib/text.js +0 -345
  34. package/dist/lib/title.d.ts +0 -40
  35. package/dist/lib/title.js +0 -197
  36. package/dist/mixin/attributesParent.d.ts +0 -49
  37. package/dist/mixin/attributesParent.js +0 -82
  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 -41
  41. package/dist/mixin/flagsParent.js +0 -60
  42. package/dist/mixin/hidden.d.ts +0 -6
  43. package/dist/mixin/hidden.js +0 -29
  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 -27
  48. package/dist/mixin/sol.d.ts +0 -5
  49. package/dist/mixin/sol.js +0 -44
  50. package/dist/mixin/syntax.d.ts +0 -8
  51. package/dist/mixin/syntax.js +0 -47
  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 -97
  60. package/dist/parser/magicLinks.js +0 -53
  61. package/dist/parser/quotes.js +0 -67
  62. package/dist/parser/redirect.js +0 -26
  63. package/dist/parser/selector.js +0 -190
  64. package/dist/parser/table.js +0 -123
  65. package/dist/src/arg.d.ts +0 -52
  66. package/dist/src/arg.js +0 -213
  67. package/dist/src/atom.d.ts +0 -12
  68. package/dist/src/atom.js +0 -26
  69. package/dist/src/attribute.d.ts +0 -65
  70. package/dist/src/attribute.js +0 -483
  71. package/dist/src/attributes.d.ts +0 -103
  72. package/dist/src/attributes.js +0 -350
  73. package/dist/src/converter.d.ts +0 -29
  74. package/dist/src/converter.js +0 -134
  75. package/dist/src/converterFlags.d.ts +0 -81
  76. package/dist/src/converterFlags.js +0 -239
  77. package/dist/src/converterRule.d.ts +0 -73
  78. package/dist/src/converterRule.js +0 -210
  79. package/dist/src/extLink.d.ts +0 -37
  80. package/dist/src/extLink.js +0 -191
  81. package/dist/src/gallery.d.ts +0 -48
  82. package/dist/src/gallery.js +0 -139
  83. package/dist/src/heading.d.ts +0 -41
  84. package/dist/src/heading.js +0 -185
  85. package/dist/src/hidden.d.ts +0 -10
  86. package/dist/src/hidden.js +0 -79
  87. package/dist/src/html.d.ts +0 -58
  88. package/dist/src/html.js +0 -334
  89. package/dist/src/imageParameter.d.ts +0 -59
  90. package/dist/src/imageParameter.js +0 -246
  91. package/dist/src/imagemap.d.ts +0 -48
  92. package/dist/src/imagemap.js +0 -145
  93. package/dist/src/imagemapLink.d.ts +0 -31
  94. package/dist/src/imagemapLink.js +0 -93
  95. package/dist/src/index.d.ts +0 -130
  96. package/dist/src/index.js +0 -721
  97. package/dist/src/link/base.d.ts +0 -46
  98. package/dist/src/link/base.js +0 -224
  99. package/dist/src/link/category.d.ts +0 -22
  100. package/dist/src/link/category.js +0 -30
  101. package/dist/src/link/file.d.ts +0 -96
  102. package/dist/src/link/file.js +0 -274
  103. package/dist/src/link/galleryImage.d.ts +0 -30
  104. package/dist/src/link/galleryImage.js +0 -158
  105. package/dist/src/link/index.d.ts +0 -52
  106. package/dist/src/link/index.js +0 -133
  107. package/dist/src/link/redirectTarget.d.ts +0 -37
  108. package/dist/src/link/redirectTarget.js +0 -95
  109. package/dist/src/magicLink.d.ts +0 -60
  110. package/dist/src/magicLink.js +0 -270
  111. package/dist/src/nested.d.ts +0 -41
  112. package/dist/src/nested.js +0 -105
  113. package/dist/src/nowiki/base.d.ts +0 -31
  114. package/dist/src/nowiki/base.js +0 -91
  115. package/dist/src/nowiki/comment.d.ts +0 -15
  116. package/dist/src/nowiki/comment.js +0 -123
  117. package/dist/src/nowiki/dd.d.ts +0 -8
  118. package/dist/src/nowiki/dd.js +0 -24
  119. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -16
  120. package/dist/src/nowiki/doubleUnderscore.js +0 -96
  121. package/dist/src/nowiki/hr.d.ts +0 -5
  122. package/dist/src/nowiki/hr.js +0 -63
  123. package/dist/src/nowiki/index.d.ts +0 -14
  124. package/dist/src/nowiki/index.js +0 -29
  125. package/dist/src/nowiki/list.d.ts +0 -16
  126. package/dist/src/nowiki/list.js +0 -109
  127. package/dist/src/nowiki/listBase.d.ts +0 -5
  128. package/dist/src/nowiki/listBase.js +0 -61
  129. package/dist/src/nowiki/noinclude.d.ts +0 -10
  130. package/dist/src/nowiki/noinclude.js +0 -73
  131. package/dist/src/nowiki/quote.d.ts +0 -17
  132. package/dist/src/nowiki/quote.js +0 -131
  133. package/dist/src/onlyinclude.d.ts +0 -14
  134. package/dist/src/onlyinclude.js +0 -57
  135. package/dist/src/paramTag/index.d.ts +0 -31
  136. package/dist/src/paramTag/index.js +0 -77
  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 -66
  140. package/dist/src/parameter.js +0 -265
  141. package/dist/src/pre.d.ts +0 -29
  142. package/dist/src/pre.js +0 -59
  143. package/dist/src/redirect.d.ts +0 -31
  144. package/dist/src/redirect.js +0 -121
  145. package/dist/src/syntax.d.ts +0 -17
  146. package/dist/src/syntax.js +0 -84
  147. package/dist/src/table/base.d.ts +0 -29
  148. package/dist/src/table/base.js +0 -82
  149. package/dist/src/table/index.d.ts +0 -239
  150. package/dist/src/table/index.js +0 -502
  151. package/dist/src/table/td.d.ts +0 -78
  152. package/dist/src/table/td.js +0 -368
  153. package/dist/src/table/tr.d.ts +0 -30
  154. package/dist/src/table/tr.js +0 -57
  155. package/dist/src/table/trBase.d.ts +0 -49
  156. package/dist/src/table/trBase.js +0 -156
  157. package/dist/src/tagPair/ext.d.ts +0 -30
  158. package/dist/src/tagPair/ext.js +0 -201
  159. package/dist/src/tagPair/include.d.ts +0 -35
  160. package/dist/src/tagPair/include.js +0 -124
  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 -160
  164. package/dist/src/transclude.js +0 -579
  165. package/dist/util/constants.js +0 -25
  166. package/dist/util/debug.js +0 -97
  167. package/dist/util/diff.js +0 -83
  168. package/dist/util/lint.js +0 -32
  169. package/dist/util/string.js +0 -60
  170. package/errors/README +0 -1
  171. package/printed/README +0 -1
@@ -1,191 +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.ExtLinkToken = void 0;
38
- const constants_1 = require("../util/constants");
39
- const lint_1 = require("../util/lint");
40
- const string_1 = require("../util/string");
41
- const debug_1 = require("../util/debug");
42
- const magicLinkParent_1 = require("../mixin/magicLinkParent");
43
- const index_1 = require("../index");
44
- const index_2 = require("./index");
45
- const magicLink_1 = require("./magicLink");
46
- /**
47
- * 外链
48
- * @classdesc `{childNodes: [MagicLinkToken, ?Token]}`
49
- */
50
- let ExtLinkToken = (() => {
51
- let _classDecorators = [magicLinkParent_1.magicLinkParent];
52
- let _classDescriptor;
53
- let _classExtraInitializers = [];
54
- let _classThis;
55
- let _classSuper = index_2.Token;
56
- var ExtLinkToken = class extends _classSuper {
57
- static { _classThis = this; }
58
- static {
59
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
60
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
61
- ExtLinkToken = _classThis = _classDescriptor.value;
62
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
63
- __runInitializers(_classThis, _classExtraInitializers);
64
- }
65
- type = 'ext-link';
66
- #space;
67
- /** 链接显示文字 */
68
- get innerText() {
69
- return this.length > 1
70
- ? this.lastChild.text()
71
- : `[${this.getRootNode().querySelectorAll('ext-link[childElementCount=1]').indexOf(this) + 1}]`;
72
- }
73
- set innerText(text) {
74
- this.setLinkText(text);
75
- }
76
- /* NOT FOR BROWSER END */
77
- /**
78
- * @param url 网址
79
- * @param space 空白字符
80
- * @param text 链接文字
81
- */
82
- constructor(url, space = '', text = '', config = index_1.default.getConfig(), accum = []) {
83
- super(undefined, config, accum, {
84
- MagicLinkToken: 0, Token: 1,
85
- });
86
- const link = url && /\0\d+f\x7F/u.test(url)
87
- ? accum[Number(url.slice(1, -2))]
88
- // @ts-expect-error abstract class
89
- : new magicLink_1.MagicLinkToken(url, 'ext-link-url', config, accum);
90
- this.insertAt(link);
91
- this.#space = space;
92
- if (text) {
93
- const inner = new index_2.Token(text, config, accum, {
94
- 'Stage-7': ':', ConverterToken: ':',
95
- });
96
- inner.type = 'ext-link-text';
97
- inner.setAttribute('stage', constants_1.MAX_STAGE - 1);
98
- this.insertAt(inner);
99
- }
100
- /* NOT FOR BROWSER */
101
- this.protectChildren(0);
102
- }
103
- /** @private */
104
- toString() {
105
- if (this.length === 1) {
106
- return `[${super.toString()}${this.#space}]`;
107
- }
108
- /* NOT FOR BROWSER */
109
- this.#correct();
110
- (0, string_1.normalizeSpace)(this.lastChild);
111
- /* NOT FOR BROWSER END */
112
- return `[${super.toString(this.#space)}]`;
113
- }
114
- /** @private */
115
- text() {
116
- /* NOT FOR BROWSER */
117
- (0, string_1.normalizeSpace)(this.childNodes[1]);
118
- /* NOT FOR BROWSER END */
119
- return `[${super.text(' ')}]`;
120
- }
121
- /** @private */
122
- getAttribute(key) {
123
- return key === 'padding' ? 1 : super.getAttribute(key);
124
- }
125
- /** @private */
126
- getGaps() {
127
- /* NOT FOR BROWSER */
128
- this.#correct();
129
- /* NOT FOR BROWSER END */
130
- return this.#space.length;
131
- }
132
- /** @private */
133
- lint(start = this.getAbsoluteIndex(), re) {
134
- const errors = super.lint(start, re);
135
- if (this.length === 1 && this.closest('heading-title')) {
136
- errors.push((0, lint_1.generateForSelf)(this, { start }, 'var-anchor', 'variable anchor in a section header'));
137
- }
138
- return errors;
139
- }
140
- /** @private */
141
- print() {
142
- return super.print(this.length === 1 ? { pre: '[', post: `${this.#space}]` } : { pre: '[', sep: this.#space, post: ']' });
143
- }
144
- /* NOT FOR BROWSER */
145
- /** @override */
146
- cloneNode() {
147
- const [url, text] = this.cloneChildNodes();
148
- return debug_1.Shadow.run(() => {
149
- // @ts-expect-error abstract class
150
- const token = new ExtLinkToken(undefined, '', '', this.getAttribute('config'));
151
- token.firstChild.safeReplaceWith(url);
152
- if (text) {
153
- token.insertAt(text);
154
- }
155
- return token;
156
- });
157
- }
158
- /** 修正空白字符 */
159
- #correct() {
160
- const { lastChild, length } = this, { firstChild } = lastChild;
161
- if (!this.#space
162
- && length > 1
163
- && (firstChild?.type === 'text' || firstChild?.type === 'converter')
164
- // 都替换成`<`肯定不对,但无妨
165
- && /^[^[\]<>"\0-\x1F\x7F\p{Zs}\uFFFD]/u.test(lastChild.text().replace(/&[lg]t;/u, '<'))) {
166
- this.#space = ' ';
167
- }
168
- }
169
- /**
170
- * 设置链接显示文字
171
- * @param str 链接显示文字
172
- */
173
- setLinkText(str) {
174
- const root = index_1.default.parse(str, this.getAttribute('include'), 7, this.getAttribute('config'));
175
- if (this.length === 1) {
176
- root.type = 'ext-link-text';
177
- root.setAttribute('acceptable', {
178
- 'Stage-7': ':', ConverterToken: ':',
179
- });
180
- this.insertAt(root);
181
- }
182
- else {
183
- this.lastChild.replaceChildren(...root.childNodes);
184
- }
185
- this.#space ||= ' ';
186
- }
187
- };
188
- return ExtLinkToken = _classThis;
189
- })();
190
- exports.ExtLinkToken = ExtLinkToken;
191
- constants_1.classes['ExtLinkToken'] = __filename;
@@ -1,48 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import { GalleryImageToken } from './link/galleryImage';
4
- import { NoincludeToken } from './nowiki/noinclude';
5
- import type { LintError } from '../base';
6
- import type { AstText, AttributesToken, ExtToken, AstNodes } from '../internal';
7
- /**
8
- * gallery标签
9
- * @classdesc `{childNodes: ...(GalleryImageToken|NoincludeToken|AstText)}`
10
- */
11
- export declare abstract class GalleryToken extends Token {
12
- #private;
13
- readonly type = "ext-inner";
14
- readonly name: 'gallery';
15
- readonly childNodes: readonly (GalleryImageToken | NoincludeToken | AstText)[];
16
- abstract get firstChild(): GalleryImageToken | NoincludeToken | AstText | undefined;
17
- abstract get lastChild(): GalleryImageToken | NoincludeToken | AstText | undefined;
18
- abstract get nextSibling(): undefined;
19
- abstract get previousSibling(): AttributesToken;
20
- abstract get parentNode(): ExtToken | undefined;
21
- abstract get children(): (GalleryImageToken | NoincludeToken)[];
22
- abstract get firstElementChild(): GalleryImageToken | NoincludeToken | undefined;
23
- abstract get lastElementChild(): GalleryImageToken | NoincludeToken | undefined;
24
- abstract get nextElementSibling(): undefined;
25
- abstract get previousElementSibling(): AttributesToken;
26
- abstract get parentElement(): ExtToken | undefined;
27
- /** 所有图片 */
28
- get images(): GalleryImageToken[];
29
- /** @param inner 标签内部wikitext */
30
- constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
31
- /** @override */
32
- cloneNode(): this;
33
- /**
34
- * 插入图片
35
- * @param file 图片文件名
36
- * @param i 插入位置
37
- * @throws `SyntaxError` 非法的文件名
38
- */
39
- insertImage(file: string, i?: number): GalleryImageToken;
40
- /**
41
- * @override
42
- * @param token 待插入的节点
43
- * @param i 插入位置
44
- * @throws `RangeError` 插入不可见内容
45
- */
46
- insertAt(token: string, i?: number): AstText;
47
- insertAt<T extends AstNodes>(token: T, i?: number): T;
48
- }
@@ -1,139 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GalleryToken = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- const index_1 = require("../index");
7
- const index_2 = require("./index");
8
- const galleryImage_1 = require("./link/galleryImage");
9
- const noinclude_1 = require("./nowiki/noinclude");
10
- /**
11
- * gallery标签
12
- * @classdesc `{childNodes: ...(GalleryImageToken|NoincludeToken|AstText)}`
13
- */
14
- class GalleryToken extends index_2.Token {
15
- type = 'ext-inner';
16
- /** 所有图片 */
17
- get images() {
18
- return this.childNodes.filter((0, debug_1.isToken)('gallery-image'));
19
- }
20
- /* NOT FOR BROWSER END */
21
- /** @param inner 标签内部wikitext */
22
- constructor(inner, config = index_1.default.getConfig(), accum = []) {
23
- super(undefined, config, accum, {
24
- AstText: ':', GalleryImageToken: ':', NoincludeToken: ':',
25
- });
26
- for (const line of inner?.split('\n') ?? []) {
27
- const matches = /^([^|]+)(?:\|(.*))?/u.exec(line);
28
- if (!matches) {
29
- // @ts-expect-error abstract class
30
- super.insertAt((line.trim() ? new noinclude_1.NoincludeToken(line, config) : line));
31
- continue;
32
- }
33
- const [, file, alt] = matches;
34
- if (this.#checkFile(file)) {
35
- // @ts-expect-error abstract class
36
- super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
37
- }
38
- else {
39
- // @ts-expect-error abstract class
40
- super.insertAt(new noinclude_1.NoincludeToken(line, config));
41
- }
42
- }
43
- }
44
- /**
45
- * 检查文件名是否有效
46
- * @param file 文件名
47
- */
48
- #checkFile(file) {
49
- return this.normalizeTitle(file, 6, true, true).valid;
50
- }
51
- /** @private */
52
- toString() {
53
- return super.toString('\n');
54
- }
55
- /** @private */
56
- text() {
57
- return super.text('\n').replace(/\n\s*\n/gu, '\n');
58
- }
59
- /** @private */
60
- getGaps() {
61
- return 1;
62
- }
63
- /** @private */
64
- lint(start = this.getAbsoluteIndex(), re) {
65
- const { top, left } = this.getRootNode().posFromIndex(start), errors = [];
66
- for (let i = 0; i < this.length; i++) {
67
- const child = this.childNodes[i], str = child.toString(), { length } = str, trimmed = str.trim(), startLine = top + i, startCol = i ? 0 : left;
68
- if (child.type === 'noinclude' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
69
- errors.push({
70
- rule: 'no-ignored',
71
- message: index_1.default.msg('invalid content in <$1>', 'gallery'),
72
- severity: trimmed.startsWith('|') ? 'warning' : 'error',
73
- startIndex: start,
74
- endIndex: start + length,
75
- startLine,
76
- endLine: startLine,
77
- startCol,
78
- endCol: startCol + length,
79
- suggestions: [
80
- {
81
- desc: 'remove',
82
- range: [start, start + length],
83
- text: '',
84
- },
85
- {
86
- desc: 'comment',
87
- range: [start, start + length],
88
- text: `<!--${str}-->`,
89
- },
90
- ],
91
- });
92
- }
93
- else if (child.type !== 'noinclude' && child.type !== 'text') {
94
- errors.push(...child.lint(start, re));
95
- }
96
- start += length + 1;
97
- }
98
- return errors;
99
- }
100
- /** @private */
101
- print() {
102
- return super.print({ sep: '\n' });
103
- }
104
- /* NOT FOR BROWSER */
105
- /** @override */
106
- cloneNode() {
107
- const cloned = this.cloneChildNodes();
108
- return debug_1.Shadow.run(() => {
109
- // @ts-expect-error abstract class
110
- const token = new GalleryToken(undefined, this.getAttribute('config'));
111
- token.append(...cloned);
112
- return token;
113
- });
114
- }
115
- /**
116
- * 插入图片
117
- * @param file 图片文件名
118
- * @param i 插入位置
119
- * @throws `SyntaxError` 非法的文件名
120
- */
121
- insertImage(file, i) {
122
- if (this.#checkFile(file)) {
123
- const token = debug_1.Shadow.run(
124
- // @ts-expect-error abstract class
125
- () => new galleryImage_1.GalleryImageToken('gallery', file, undefined, this.getAttribute('config')));
126
- token.afterBuild();
127
- return this.insertAt(token, i);
128
- }
129
- throw new SyntaxError(`Invalid file name: ${file}`);
130
- }
131
- insertAt(token, i = this.length) {
132
- if (typeof token === 'string' && token.trim() || token instanceof noinclude_1.NoincludeToken) {
133
- throw new RangeError('Please do not insert invisible content into <gallery>!');
134
- }
135
- return super.insertAt(token, i);
136
- }
137
- }
138
- exports.GalleryToken = GalleryToken;
139
- constants_1.classes['GalleryToken'] = __filename;
@@ -1,41 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import { SyntaxToken } from './syntax';
4
- import type { LintError, AST } from '../base';
5
- /**
6
- * 章节标题
7
- * @classdesc `{childNodes: [Token, SyntaxToken]}`
8
- */
9
- export declare abstract class HeadingToken extends Token {
10
- #private;
11
- readonly type = "heading";
12
- readonly childNodes: readonly [Token, SyntaxToken];
13
- abstract get firstChild(): Token;
14
- abstract get lastChild(): SyntaxToken;
15
- abstract get children(): [Token, SyntaxToken];
16
- abstract get firstElementChild(): Token;
17
- abstract get lastElementChild(): SyntaxToken;
18
- /** 标题层级 */
19
- get level(): number;
20
- set level(n: number);
21
- /** 内部wikitext */
22
- get innerText(): string;
23
- /** @throws `Error` 首尾包含`=` */
24
- set innerText(text: string);
25
- /**
26
- * @param level 标题层级
27
- * @param input 标题文字
28
- */
29
- constructor(level: number, input: readonly [string?, string?], config?: Parser.Config, accum?: Token[]);
30
- /** @override */
31
- json(): AST;
32
- /** @override */
33
- cloneNode(): this;
34
- /**
35
- * 设置标题层级
36
- * @param n 标题层级
37
- */
38
- setLevel(n: number): void;
39
- /** 移除标题后的不可见内容 */
40
- removeTrail(): void;
41
- }
@@ -1,185 +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.HeadingToken = void 0;
38
- const lint_1 = require("../util/lint");
39
- const rect_1 = require("../lib/rect");
40
- const debug_1 = require("../util/debug");
41
- const constants_1 = require("../util/constants");
42
- const fixed_1 = require("../mixin/fixed");
43
- const sol_1 = require("../mixin/sol");
44
- const index_1 = require("../index");
45
- const index_2 = require("./index");
46
- const syntax_1 = require("./syntax");
47
- /**
48
- * 章节标题
49
- * @classdesc `{childNodes: [Token, SyntaxToken]}`
50
- */
51
- let HeadingToken = (() => {
52
- let _classDecorators = [fixed_1.fixedToken, sol_1.sol];
53
- let _classDescriptor;
54
- let _classExtraInitializers = [];
55
- let _classThis;
56
- let _classSuper = index_2.Token;
57
- var HeadingToken = class extends _classSuper {
58
- static { _classThis = this; }
59
- static {
60
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
61
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
62
- HeadingToken = _classThis = _classDescriptor.value;
63
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
64
- __runInitializers(_classThis, _classExtraInitializers);
65
- }
66
- type = 'heading';
67
- #level;
68
- /* NOT FOR BROWSER END */
69
- /** 标题格式的等号 */
70
- get #equals() {
71
- return '='.repeat(this.level);
72
- }
73
- /** 标题层级 */
74
- get level() {
75
- return this.#level;
76
- }
77
- /* NOT FOR BROWSER */
78
- set level(n) {
79
- this.setLevel(n);
80
- }
81
- /** 内部wikitext */
82
- get innerText() {
83
- return this.firstChild.text().trim();
84
- }
85
- /** @throws `Error` 首尾包含`=` */
86
- set innerText(text) {
87
- if (text.length > 1 && text.startsWith('=') && text.endsWith('=')) {
88
- throw new Error('Please use HeadingToken.setLevel method to change the level of the heading!');
89
- }
90
- const { childNodes } = index_1.default.parse(text, this.getAttribute('include'), undefined, this.getAttribute('config'));
91
- this.firstChild.replaceChildren(...childNodes);
92
- }
93
- /* NOT FOR BROWSER END */
94
- /**
95
- * @param level 标题层级
96
- * @param input 标题文字
97
- */
98
- constructor(level, input, config = index_1.default.getConfig(), accum = []) {
99
- super(undefined, config, accum);
100
- this.#level = level;
101
- const token = new index_2.Token(input[0], config, accum);
102
- token.type = 'heading-title';
103
- token.setAttribute('stage', 2);
104
- const trail = new syntax_1.SyntaxToken(input[1], /^[^\S\n]*$/u, 'heading-trail', config, accum, {
105
- 'Stage-1': ':', '!ExtToken': '',
106
- });
107
- this.append(token, trail);
108
- }
109
- /** @private */
110
- toString() {
111
- const equals = this.#equals;
112
- return equals + this.firstChild.toString() + equals + this.lastChild.toString();
113
- }
114
- /** @private */
115
- text() {
116
- const equals = this.#equals;
117
- return equals + this.firstChild.text() + equals;
118
- }
119
- /** @private */
120
- getAttribute(key) {
121
- return key === 'padding' ? this.level : super.getAttribute(key);
122
- }
123
- /** @private */
124
- getGaps() {
125
- return this.level;
126
- }
127
- /** @private */
128
- lint(start = this.getAbsoluteIndex(), re) {
129
- const errors = super.lint(start, re), { firstChild, level } = this, innerStr = firstChild.toString(), quotes = firstChild.childNodes.filter((node) => node.type === 'quote'), boldQuotes = quotes.filter(({ bold }) => bold), italicQuotes = quotes.filter(({ italic }) => italic), rect = new rect_1.BoundingRect(this, start);
130
- if (this.level === 1) {
131
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'h1', '<h1>'));
132
- }
133
- if (innerStr.startsWith('=') || innerStr.endsWith('=')) {
134
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'unbalanced-header', index_1.default.msg('unbalanced $1 in a section header', '"="')));
135
- }
136
- if (this.closest('html-attrs, table-attrs')) {
137
- errors.push((0, lint_1.generateForSelf)(this, rect, 'parsing-order', 'section header in a HTML tag'));
138
- }
139
- if (boldQuotes.length % 2) {
140
- errors.push((0, lint_1.generateForChild)(boldQuotes[boldQuotes.length - 1], { ...rect, start: start + level, left: rect.left + level }, 'format-leakage', index_1.default.msg('unbalanced $1 in a section header', 'bold apostrophes')));
141
- }
142
- if (italicQuotes.length % 2) {
143
- errors.push((0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, 'format-leakage', index_1.default.msg('unbalanced $1 in a section header', 'italic apostrophes')));
144
- }
145
- return errors;
146
- }
147
- /** @private */
148
- print() {
149
- const equals = this.#equals;
150
- return super.print({ pre: equals, sep: equals });
151
- }
152
- /** @override */
153
- json() {
154
- const json = super.json();
155
- json['level'] = this.level;
156
- return json;
157
- }
158
- /* NOT FOR BROWSER */
159
- /** @override */
160
- cloneNode() {
161
- const [title, trail] = this.cloneChildNodes();
162
- return debug_1.Shadow.run(() => {
163
- // @ts-expect-error abstract class
164
- const token = new HeadingToken(this.level, [], this.getAttribute('config'));
165
- token.firstChild.safeReplaceWith(title);
166
- token.lastChild.safeReplaceWith(trail);
167
- return token;
168
- });
169
- }
170
- /**
171
- * 设置标题层级
172
- * @param n 标题层级
173
- */
174
- setLevel(n) {
175
- this.#level = Math.min(Math.max(n, 1), 6);
176
- }
177
- /** 移除标题后的不可见内容 */
178
- removeTrail() {
179
- this.lastChild.replaceChildren();
180
- }
181
- };
182
- return HeadingToken = _classThis;
183
- })();
184
- exports.HeadingToken = HeadingToken;
185
- constants_1.classes['HeadingToken'] = __filename;
@@ -1,10 +0,0 @@
1
- import { Token } from './index';
2
- import type { Config } from '../base';
3
- /** 不可见的节点 */
4
- export declare class HiddenToken extends Token {
5
- readonly type = "hidden";
6
- /** @class */
7
- constructor(wikitext?: string, config?: Config, accum?: Token[]);
8
- /** @override */
9
- cloneNode(): this;
10
- }