wikiparser-node 1.12.5 → 1.12.6-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 (174) 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/moegirl.json +21 -65
  6. package/config/zhwiki.json +28 -494
  7. package/extensions/dist/base.js +163 -0
  8. package/extensions/dist/codejar.js +52 -0
  9. package/extensions/dist/editor.js +159 -0
  10. package/extensions/dist/highlight.js +30 -0
  11. package/extensions/dist/lint.js +72 -0
  12. package/extensions/editor.css +59 -0
  13. package/extensions/ui.css +162 -0
  14. package/package.json +28 -21
  15. package/config/.schema.json +0 -203
  16. package/dist/addon/table.js +0 -494
  17. package/dist/addon/token.js +0 -392
  18. package/dist/addon/transclude.js +0 -184
  19. package/dist/base.d.ts +0 -81
  20. package/dist/base.js +0 -40
  21. package/dist/index.d.ts +0 -33
  22. package/dist/index.js +0 -275
  23. package/dist/internal.d.ts +0 -47
  24. package/dist/lib/element.d.ts +0 -125
  25. package/dist/lib/element.js +0 -377
  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 -36
  34. package/dist/lib/text.d.ts +0 -58
  35. package/dist/lib/text.js +0 -414
  36. package/dist/lib/title.d.ts +0 -49
  37. package/dist/lib/title.js +0 -253
  38. package/dist/mixin/attributesParent.d.ts +0 -49
  39. package/dist/mixin/attributesParent.js +0 -80
  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 -43
  43. package/dist/mixin/flagsParent.js +0 -64
  44. package/dist/mixin/hidden.d.ts +0 -7
  45. package/dist/mixin/hidden.js +0 -39
  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 -45
  52. package/dist/mixin/syntax.d.ts +0 -8
  53. package/dist/mixin/syntax.js +0 -46
  54. package/dist/parser/braces.js +0 -152
  55. package/dist/parser/commentAndExt.js +0 -84
  56. package/dist/parser/converter.js +0 -41
  57. package/dist/parser/externalLinks.js +0 -39
  58. package/dist/parser/hrAndDoubleUnderscore.js +0 -44
  59. package/dist/parser/html.js +0 -40
  60. package/dist/parser/links.js +0 -103
  61. package/dist/parser/list.js +0 -116
  62. package/dist/parser/magicLinks.js +0 -55
  63. package/dist/parser/quotes.js +0 -69
  64. package/dist/parser/redirect.js +0 -28
  65. package/dist/parser/selector.js +0 -393
  66. package/dist/parser/table.js +0 -125
  67. package/dist/src/arg.d.ts +0 -49
  68. package/dist/src/arg.js +0 -220
  69. package/dist/src/atom.d.ts +0 -14
  70. package/dist/src/atom.js +0 -54
  71. package/dist/src/attribute.d.ts +0 -64
  72. package/dist/src/attribute.js +0 -482
  73. package/dist/src/attributes.d.ts +0 -103
  74. package/dist/src/attributes.js +0 -380
  75. package/dist/src/converter.d.ts +0 -28
  76. package/dist/src/converter.js +0 -153
  77. package/dist/src/converterFlags.d.ts +0 -80
  78. package/dist/src/converterFlags.js +0 -241
  79. package/dist/src/converterRule.d.ts +0 -71
  80. package/dist/src/converterRule.js +0 -218
  81. package/dist/src/extLink.d.ts +0 -36
  82. package/dist/src/extLink.js +0 -223
  83. package/dist/src/gallery.d.ts +0 -51
  84. package/dist/src/gallery.js +0 -166
  85. package/dist/src/heading.d.ts +0 -44
  86. package/dist/src/heading.js +0 -222
  87. package/dist/src/hidden.d.ts +0 -9
  88. package/dist/src/hidden.js +0 -82
  89. package/dist/src/html.d.ts +0 -61
  90. package/dist/src/html.js +0 -344
  91. package/dist/src/imageParameter.d.ts +0 -60
  92. package/dist/src/imageParameter.js +0 -262
  93. package/dist/src/imagemap.d.ts +0 -47
  94. package/dist/src/imagemap.js +0 -148
  95. package/dist/src/imagemapLink.d.ts +0 -35
  96. package/dist/src/imagemapLink.js +0 -99
  97. package/dist/src/index.d.ts +0 -136
  98. package/dist/src/index.js +0 -790
  99. package/dist/src/link/base.d.ts +0 -52
  100. package/dist/src/link/base.js +0 -258
  101. package/dist/src/link/category.d.ts +0 -22
  102. package/dist/src/link/category.js +0 -36
  103. package/dist/src/link/file.d.ts +0 -102
  104. package/dist/src/link/file.js +0 -345
  105. package/dist/src/link/galleryImage.d.ts +0 -29
  106. package/dist/src/link/galleryImage.js +0 -133
  107. package/dist/src/link/index.d.ts +0 -39
  108. package/dist/src/link/index.js +0 -100
  109. package/dist/src/link/redirectTarget.d.ts +0 -27
  110. package/dist/src/link/redirectTarget.js +0 -71
  111. package/dist/src/magicLink.d.ts +0 -57
  112. package/dist/src/magicLink.js +0 -261
  113. package/dist/src/nested.d.ts +0 -40
  114. package/dist/src/nested.js +0 -108
  115. package/dist/src/nowiki/base.d.ts +0 -28
  116. package/dist/src/nowiki/base.js +0 -90
  117. package/dist/src/nowiki/comment.d.ts +0 -14
  118. package/dist/src/nowiki/comment.js +0 -123
  119. package/dist/src/nowiki/dd.d.ts +0 -8
  120. package/dist/src/nowiki/dd.js +0 -74
  121. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  122. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  123. package/dist/src/nowiki/hr.d.ts +0 -5
  124. package/dist/src/nowiki/hr.js +0 -72
  125. package/dist/src/nowiki/index.d.ts +0 -14
  126. package/dist/src/nowiki/index.js +0 -30
  127. package/dist/src/nowiki/list.d.ts +0 -5
  128. package/dist/src/nowiki/list.js +0 -67
  129. package/dist/src/nowiki/listBase.d.ts +0 -23
  130. package/dist/src/nowiki/listBase.js +0 -100
  131. package/dist/src/nowiki/noinclude.d.ts +0 -6
  132. package/dist/src/nowiki/noinclude.js +0 -77
  133. package/dist/src/nowiki/quote.d.ts +0 -14
  134. package/dist/src/nowiki/quote.js +0 -149
  135. package/dist/src/onlyinclude.d.ts +0 -13
  136. package/dist/src/onlyinclude.js +0 -60
  137. package/dist/src/paramTag/index.d.ts +0 -28
  138. package/dist/src/paramTag/index.js +0 -80
  139. package/dist/src/paramTag/inputbox.d.ts +0 -8
  140. package/dist/src/paramTag/inputbox.js +0 -24
  141. package/dist/src/parameter.d.ts +0 -60
  142. package/dist/src/parameter.js +0 -267
  143. package/dist/src/pre.d.ts +0 -28
  144. package/dist/src/pre.js +0 -62
  145. package/dist/src/redirect.d.ts +0 -30
  146. package/dist/src/redirect.js +0 -128
  147. package/dist/src/syntax.d.ts +0 -15
  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 -506
  153. package/dist/src/table/td.d.ts +0 -72
  154. package/dist/src/table/td.js +0 -375
  155. package/dist/src/table/tr.d.ts +0 -30
  156. package/dist/src/table/tr.js +0 -61
  157. package/dist/src/table/trBase.d.ts +0 -49
  158. package/dist/src/table/trBase.js +0 -165
  159. package/dist/src/tagPair/ext.d.ts +0 -29
  160. package/dist/src/tagPair/ext.js +0 -229
  161. package/dist/src/tagPair/include.d.ts +0 -33
  162. package/dist/src/tagPair/include.js +0 -132
  163. package/dist/src/tagPair/index.d.ts +0 -23
  164. package/dist/src/tagPair/index.js +0 -130
  165. package/dist/src/transclude.d.ts +0 -159
  166. package/dist/src/transclude.js +0 -598
  167. package/dist/util/constants.js +0 -26
  168. package/dist/util/debug.js +0 -95
  169. package/dist/util/diff.js +0 -83
  170. package/dist/util/html.js +0 -146
  171. package/dist/util/lint.js +0 -32
  172. package/dist/util/string.js +0 -107
  173. package/errors/README +0 -3
  174. package/printed/README +0 -3
@@ -1,223 +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 index_1 = require("../index");
41
- const index_2 = require("./index");
42
- const magicLink_1 = require("./magicLink");
43
- /* NOT FOR BROWSER */
44
- const string_1 = require("../util/string");
45
- const html_1 = require("../util/html");
46
- const debug_1 = require("../util/debug");
47
- const magicLinkParent_1 = require("../mixin/magicLinkParent");
48
- /* NOT FOR BROWSER END */
49
- /**
50
- * 外链
51
- * @classdesc `{childNodes: [MagicLinkToken, ?Token]}`
52
- */
53
- let ExtLinkToken = (() => {
54
- let _classDecorators = [magicLinkParent_1.magicLinkParent];
55
- let _classDescriptor;
56
- let _classExtraInitializers = [];
57
- let _classThis;
58
- let _classSuper = index_2.Token;
59
- var ExtLinkToken = class extends _classSuper {
60
- static { _classThis = this; }
61
- static {
62
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
63
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
64
- ExtLinkToken = _classThis = _classDescriptor.value;
65
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
66
- __runInitializers(_classThis, _classExtraInitializers);
67
- }
68
- #space;
69
- /* NOT FOR BROWSER END */
70
- get type() {
71
- return 'ext-link';
72
- }
73
- /* NOT FOR BROWSER */
74
- /** 链接显示文字 */
75
- get innerText() {
76
- return this.length > 1
77
- ? this.lastChild.text()
78
- : `[${this.getRootNode().querySelectorAll('ext-link[childElementCount=1]').indexOf(this) + 1}]`;
79
- }
80
- set innerText(text) {
81
- this.setLinkText(text);
82
- }
83
- /* NOT FOR BROWSER END */
84
- /**
85
- * @param url 网址
86
- * @param space 空白字符
87
- * @param text 链接文字
88
- */
89
- constructor(url, space = '', text = '', config = index_1.default.getConfig(), accum = []) {
90
- super(undefined, config, accum, {
91
- MagicLinkToken: 0, Token: 1,
92
- });
93
- const link = url && /^\0\d+f\x7F$/u.test(url)
94
- ? accum[Number(url.slice(1, -2))]
95
- // @ts-expect-error abstract class
96
- : new magicLink_1.MagicLinkToken(url, 'ext-link-url', config, accum);
97
- this.insertAt(link);
98
- this.#space = space;
99
- if (text) {
100
- const inner = new index_2.Token(text, config, accum, {
101
- 'Stage-7': ':', ConverterToken: ':',
102
- });
103
- inner.type = 'ext-link-text';
104
- inner.setAttribute('stage', constants_1.MAX_STAGE - 1);
105
- this.insertAt(inner);
106
- }
107
- /* NOT FOR BROWSER */
108
- this.protectChildren(0);
109
- }
110
- /** @private */
111
- toString(skip) {
112
- if (this.length === 1) {
113
- return `[${super.toString(skip)}${this.#space}]`;
114
- }
115
- /* NOT FOR BROWSER */
116
- this.#correct();
117
- (0, string_1.normalizeSpace)(this.lastChild);
118
- /* NOT FOR BROWSER END */
119
- return `[${super.toString(skip, this.#space)}]`;
120
- }
121
- /** @private */
122
- text() {
123
- /* NOT FOR BROWSER */
124
- (0, string_1.normalizeSpace)(this.childNodes[1]);
125
- /* NOT FOR BROWSER END */
126
- return `[${super.text(' ')}]`;
127
- }
128
- /** @private */
129
- getAttribute(key) {
130
- return key === 'padding' ? 1 : super.getAttribute(key);
131
- }
132
- /** @private */
133
- getGaps() {
134
- /* NOT FOR BROWSER */
135
- this.#correct();
136
- /* NOT FOR BROWSER END */
137
- return this.#space.length;
138
- }
139
- /** @private */
140
- lint(start = this.getAbsoluteIndex(), re) {
141
- const errors = super.lint(start, re);
142
- if (this.length === 1 && this.closest('heading-title')) {
143
- errors.push((0, lint_1.generateForSelf)(this, { start }, 'var-anchor', 'variable anchor in a section header'));
144
- }
145
- return errors;
146
- }
147
- /** @private */
148
- print() {
149
- return super.print(this.length === 1 ? { pre: '[', post: `${this.#space}]` } : { pre: '[', sep: this.#space, post: ']' });
150
- }
151
- /* NOT FOR BROWSER */
152
- cloneNode() {
153
- const [url, text] = this.cloneChildNodes();
154
- return debug_1.Shadow.run(() => {
155
- // @ts-expect-error abstract class
156
- const token = new ExtLinkToken(undefined, '', '', this.getAttribute('config'));
157
- token.firstChild.safeReplaceWith(url);
158
- if (text) {
159
- token.insertAt(text);
160
- }
161
- return token;
162
- });
163
- }
164
- /** 修正空白字符 */
165
- #correct() {
166
- const { lastChild, length } = this, { firstChild } = lastChild;
167
- if (!this.#space
168
- && length > 1
169
- && (firstChild?.type === 'text' || firstChild?.type === 'converter')
170
- // 都替换成`<`肯定不对,但无妨
171
- && /^[^[\]<>"\0-\x1F\x7F\p{Zs}\uFFFD]/u.test(lastChild.text().replace(/&[lg]t;/u, '<'))) {
172
- this.#space = ' ';
173
- }
174
- }
175
- /**
176
- * 设置链接显示文字
177
- * @param str 链接显示文字
178
- */
179
- setLinkText(str) {
180
- const root = index_1.default.parse(str, this.getAttribute('include'), 7, this.getAttribute('config'));
181
- if (this.length === 1) {
182
- root.type = 'ext-link-text';
183
- root.setAttribute('acceptable', {
184
- 'Stage-7': ':', ConverterToken: ':',
185
- });
186
- this.insertAt(root);
187
- }
188
- else {
189
- this.lastChild.replaceChildren(...root.childNodes);
190
- }
191
- this.#space ||= ' ';
192
- }
193
- /** @private */
194
- toHtmlInternal(nowrap, nocc) {
195
- const { length, lastChild } = this;
196
- let trail = '', innerText, autonumber = false, href;
197
- if (length > 1) {
198
- lastChild.normalize();
199
- const { childNodes } = lastChild, i = childNodes.findIndex(child => child.type === 'link'
200
- || child.is('file') && child.getValue('link')?.trim() !== '');
201
- if (i !== -1) {
202
- const after = childNodes.slice(i);
203
- this.after(...after);
204
- trail = (0, html_1.html)(after, '', nowrap, nocc);
205
- }
206
- innerText = lastChild.toHtmlInternal(false, nocc);
207
- }
208
- else {
209
- ({ innerText } = this);
210
- autonumber = true;
211
- }
212
- try {
213
- ({ href } = this.getUrl());
214
- }
215
- catch { }
216
- const a = `<a rel="nofollow" class="external"${href === undefined ? '' : ` href="${href}"`}>${innerText}</a>${trail}`;
217
- return autonumber ? (0, html_1.font)(this, a) : a;
218
- }
219
- };
220
- return ExtLinkToken = _classThis;
221
- })();
222
- exports.ExtLinkToken = ExtLinkToken;
223
- constants_1.classes['ExtLinkToken'] = __filename;
@@ -1,51 +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 name: 'gallery';
14
- readonly childNodes: readonly (GalleryImageToken | NoincludeToken | AstText)[];
15
- abstract get firstChild(): GalleryImageToken | NoincludeToken | AstText | undefined;
16
- abstract get lastChild(): GalleryImageToken | NoincludeToken | AstText | undefined;
17
- abstract get nextSibling(): undefined;
18
- abstract get previousSibling(): AttributesToken;
19
- abstract get parentNode(): ExtToken | undefined;
20
- abstract get children(): (GalleryImageToken | NoincludeToken)[];
21
- abstract get firstElementChild(): GalleryImageToken | NoincludeToken | undefined;
22
- abstract get lastElementChild(): GalleryImageToken | NoincludeToken | undefined;
23
- abstract get nextElementSibling(): undefined;
24
- abstract get previousElementSibling(): AttributesToken;
25
- abstract get parentElement(): ExtToken | undefined;
26
- get type(): 'ext-inner';
27
- /** 图片宽度 */
28
- get widths(): number;
29
- /** 图片高度 */
30
- get heights(): number;
31
- /** 所有图片 */
32
- get images(): GalleryImageToken[];
33
- /** @param inner 标签内部wikitext */
34
- constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
35
- cloneNode(): this;
36
- /**
37
- * 插入图片
38
- * @param file 图片文件名
39
- * @param i 插入位置
40
- * @throws `SyntaxError` 非法的文件名
41
- */
42
- insertImage(file: string, i?: number): GalleryImageToken;
43
- /**
44
- * @override
45
- * @param token 待插入的节点
46
- * @param i 插入位置
47
- * @throws `RangeError` 插入不可见内容
48
- */
49
- insertAt(token: string, i?: number): AstText;
50
- insertAt<T extends AstNodes>(token: T, i?: number): T;
51
- }
@@ -1,166 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GalleryToken = void 0;
4
- const index_1 = require("../index");
5
- const index_2 = require("./index");
6
- const galleryImage_1 = require("./link/galleryImage");
7
- const noinclude_1 = require("./nowiki/noinclude");
8
- /* NOT FOR BROWSER */
9
- const debug_1 = require("../util/debug");
10
- const constants_1 = require("../util/constants");
11
- const html_1 = require("../util/html");
12
- /* NOT FOR BROWSER END */
13
- /**
14
- * gallery标签
15
- * @classdesc `{childNodes: ...(GalleryImageToken|NoincludeToken|AstText)}`
16
- */
17
- class GalleryToken extends index_2.Token {
18
- /* NOT FOR BROWSER END */
19
- get type() {
20
- return 'ext-inner';
21
- }
22
- /* NOT FOR BROWSER */
23
- /** 图片宽度 */
24
- get widths() {
25
- return this.#getSize('widths');
26
- }
27
- /** 图片高度 */
28
- get heights() {
29
- return this.#getSize('heights');
30
- }
31
- /** 所有图片 */
32
- get images() {
33
- return this.childNodes.filter((0, debug_1.isToken)('gallery-image'));
34
- }
35
- /* NOT FOR BROWSER END */
36
- /** @param inner 标签内部wikitext */
37
- constructor(inner, config = index_1.default.getConfig(), accum = []) {
38
- super(undefined, config, accum, {
39
- AstText: ':', GalleryImageToken: ':', NoincludeToken: ':',
40
- });
41
- for (const line of inner?.split('\n') ?? []) {
42
- const matches = /^([^|]+)(?:\|(.*))?/u.exec(line);
43
- if (!matches) {
44
- // @ts-expect-error abstract class
45
- super.insertAt((line.trim() ? new noinclude_1.NoincludeToken(line, config, accum) : line));
46
- continue;
47
- }
48
- const [, file, alt] = matches;
49
- if (this.#checkFile(file)) {
50
- // @ts-expect-error abstract class
51
- super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
52
- }
53
- else {
54
- // @ts-expect-error abstract class
55
- super.insertAt(new noinclude_1.NoincludeToken(line, config, accum));
56
- }
57
- }
58
- }
59
- /**
60
- * 检查文件名是否有效
61
- * @param file 文件名
62
- */
63
- #checkFile(file) {
64
- return this.normalizeTitle(file, 6, true, true).valid;
65
- }
66
- /** @private */
67
- toString(skip) {
68
- return super.toString(skip, '\n');
69
- }
70
- /** @private */
71
- text() {
72
- return super.text('\n').replace(/\n\s*\n/gu, '\n');
73
- }
74
- /** @private */
75
- getGaps() {
76
- return 1;
77
- }
78
- /** @private */
79
- lint(start = this.getAbsoluteIndex(), re) {
80
- const { top, left } = this.getRootNode().posFromIndex(start), errors = [];
81
- for (const [i, child] of this.childNodes.entries()) {
82
- const str = child.toString(), { length } = str, trimmed = str.trim(), startLine = top + i, startCol = i ? 0 : left;
83
- if (child.type === 'noinclude' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
84
- const endIndex = start + length;
85
- errors.push({
86
- rule: 'no-ignored',
87
- message: index_1.default.msg('invalid content in <$1>', 'gallery'),
88
- severity: trimmed.startsWith('|') ? 'warning' : 'error',
89
- startIndex: start,
90
- endIndex,
91
- startLine,
92
- endLine: startLine,
93
- startCol,
94
- endCol: startCol + length,
95
- suggestions: [
96
- {
97
- desc: 'remove',
98
- range: [start, endIndex],
99
- text: '',
100
- },
101
- {
102
- desc: 'comment',
103
- range: [start, endIndex],
104
- text: `<!--${str}-->`,
105
- },
106
- ],
107
- });
108
- }
109
- else if (child.type !== 'noinclude' && child.type !== 'text') {
110
- errors.push(...child.lint(start, re));
111
- }
112
- start += length + 1;
113
- }
114
- return errors;
115
- }
116
- /** @private */
117
- print() {
118
- return super.print({ sep: '\n' });
119
- }
120
- /* NOT FOR BROWSER */
121
- cloneNode() {
122
- const cloned = this.cloneChildNodes();
123
- return debug_1.Shadow.run(() => {
124
- // @ts-expect-error abstract class
125
- const token = new GalleryToken(undefined, this.getAttribute('config'));
126
- token.append(...cloned);
127
- return token;
128
- });
129
- }
130
- /**
131
- * 插入图片
132
- * @param file 图片文件名
133
- * @param i 插入位置
134
- * @throws `SyntaxError` 非法的文件名
135
- */
136
- insertImage(file, i) {
137
- if (this.#checkFile(file)) {
138
- const token = debug_1.Shadow.run(
139
- // @ts-expect-error abstract class
140
- () => new galleryImage_1.GalleryImageToken('gallery', file, undefined, this.getAttribute('config')));
141
- token.afterBuild();
142
- return this.insertAt(token, i);
143
- }
144
- throw new SyntaxError(`Invalid file name: ${file}`);
145
- }
146
- insertAt(token, i = this.length) {
147
- if (!debug_1.Shadow.running && (typeof token === 'string' && token.trim() || token instanceof noinclude_1.NoincludeToken)) {
148
- throw new RangeError('Please do not insert invisible content into <gallery>!');
149
- }
150
- return super.insertAt(token, i);
151
- }
152
- /**
153
- * 获取图片的宽度或高度
154
- * @param key `widths` 或 `heights`
155
- */
156
- #getSize(key) {
157
- const widths = this.parentNode?.getAttr(key), mt = typeof widths === 'string' && /^(\d+)\s*(?:px)?$/u.exec(widths)?.[1];
158
- return mt && Number(mt) || 120;
159
- }
160
- /** @private */
161
- toHtmlInternal() {
162
- return (0, html_1.html)(this.childNodes.filter((0, debug_1.isToken)('gallery-image')), '\n');
163
- }
164
- }
165
- exports.GalleryToken = GalleryToken;
166
- constants_1.classes['GalleryToken'] = __filename;
@@ -1,44 +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
- import type { AstText } from '../internal';
6
- /**
7
- * 章节标题
8
- * @classdesc `{childNodes: [Token, SyntaxToken]}`
9
- */
10
- export declare abstract class HeadingToken extends Token {
11
- #private;
12
- readonly childNodes: readonly [Token, SyntaxToken];
13
- abstract get firstChild(): Token;
14
- abstract get lastChild(): SyntaxToken;
15
- abstract get nextSibling(): AstText | undefined;
16
- abstract get children(): [Token, SyntaxToken];
17
- abstract get firstElementChild(): Token;
18
- abstract get lastElementChild(): SyntaxToken;
19
- get type(): 'heading';
20
- /** 标题层级 */
21
- get level(): number;
22
- set level(n: number);
23
- /** 内部wikitext */
24
- get innerText(): string;
25
- /** @throws `Error` 首尾包含`=` */
26
- set innerText(text: string);
27
- /** id属性 */
28
- get id(): string;
29
- /**
30
- * @param level 标题层级
31
- * @param input 标题文字
32
- */
33
- constructor(level: number, input: readonly [string?, string?], config?: Parser.Config, accum?: Token[]);
34
- /** @override */
35
- json(): AST;
36
- cloneNode(): this;
37
- /**
38
- * 设置标题层级
39
- * @param n 标题层级
40
- */
41
- setLevel(n: number): void;
42
- /** 移除标题后的不可见内容 */
43
- removeTrail(): void;
44
- }