wikiparser-node 1.13.1-b → 1.13.1

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/config/.schema.json +203 -0
  2. package/config/default.json +32 -31
  3. package/config/enwiki.json +829 -15
  4. package/config/llwiki.json +56 -21
  5. package/config/moegirl.json +65 -21
  6. package/config/zhwiki.json +498 -32
  7. package/dist/addon/table.js +494 -0
  8. package/dist/addon/token.js +392 -0
  9. package/dist/addon/transclude.js +184 -0
  10. package/dist/base.d.ts +110 -0
  11. package/dist/base.js +67 -0
  12. package/dist/index.d.ts +33 -0
  13. package/dist/index.js +279 -0
  14. package/dist/internal.d.ts +47 -0
  15. package/dist/lib/element.d.ts +125 -0
  16. package/dist/lib/element.js +364 -0
  17. package/dist/lib/node.d.ts +173 -0
  18. package/dist/lib/node.js +478 -0
  19. package/dist/lib/range.d.ts +105 -0
  20. package/dist/lib/range.js +406 -0
  21. package/dist/lib/ranges.d.ts +28 -0
  22. package/dist/lib/ranges.js +126 -0
  23. package/dist/lib/rect.d.ts +18 -0
  24. package/dist/lib/rect.js +36 -0
  25. package/dist/lib/text.d.ts +58 -0
  26. package/dist/lib/text.js +414 -0
  27. package/dist/lib/title.d.ts +49 -0
  28. package/dist/lib/title.js +251 -0
  29. package/dist/mixin/attributesParent.d.ts +49 -0
  30. package/dist/mixin/attributesParent.js +80 -0
  31. package/dist/mixin/fixed.d.ts +5 -0
  32. package/dist/mixin/fixed.js +32 -0
  33. package/dist/mixin/flagsParent.d.ts +43 -0
  34. package/dist/mixin/flagsParent.js +64 -0
  35. package/dist/mixin/hidden.d.ts +7 -0
  36. package/dist/mixin/hidden.js +39 -0
  37. package/dist/mixin/magicLinkParent.d.ts +19 -0
  38. package/dist/mixin/magicLinkParent.js +43 -0
  39. package/dist/mixin/singleLine.d.ts +5 -0
  40. package/dist/mixin/singleLine.js +25 -0
  41. package/dist/mixin/sol.d.ts +6 -0
  42. package/dist/mixin/sol.js +45 -0
  43. package/dist/mixin/syntax.d.ts +8 -0
  44. package/dist/mixin/syntax.js +46 -0
  45. package/dist/parser/braces.js +152 -0
  46. package/dist/parser/commentAndExt.js +84 -0
  47. package/dist/parser/converter.js +41 -0
  48. package/dist/parser/externalLinks.js +39 -0
  49. package/dist/parser/hrAndDoubleUnderscore.js +44 -0
  50. package/dist/parser/html.js +40 -0
  51. package/dist/parser/links.js +103 -0
  52. package/dist/parser/list.js +116 -0
  53. package/dist/parser/magicLinks.js +55 -0
  54. package/dist/parser/quotes.js +69 -0
  55. package/dist/parser/redirect.js +28 -0
  56. package/dist/parser/selector.js +443 -0
  57. package/dist/parser/table.js +125 -0
  58. package/dist/src/arg.d.ts +49 -0
  59. package/dist/src/arg.js +220 -0
  60. package/dist/src/atom.d.ts +14 -0
  61. package/dist/src/atom.js +54 -0
  62. package/dist/src/attribute.d.ts +64 -0
  63. package/dist/src/attribute.js +482 -0
  64. package/dist/src/attributes.d.ts +103 -0
  65. package/dist/src/attributes.js +383 -0
  66. package/dist/src/converter.d.ts +28 -0
  67. package/dist/src/converter.js +153 -0
  68. package/dist/src/converterFlags.d.ts +80 -0
  69. package/dist/src/converterFlags.js +241 -0
  70. package/dist/src/converterRule.d.ts +71 -0
  71. package/dist/src/converterRule.js +218 -0
  72. package/dist/src/extLink.d.ts +36 -0
  73. package/dist/src/extLink.js +223 -0
  74. package/dist/src/gallery.d.ts +51 -0
  75. package/dist/src/gallery.js +166 -0
  76. package/dist/src/heading.d.ts +44 -0
  77. package/dist/src/heading.js +222 -0
  78. package/dist/src/hidden.d.ts +9 -0
  79. package/dist/src/hidden.js +82 -0
  80. package/dist/src/html.d.ts +61 -0
  81. package/dist/src/html.js +344 -0
  82. package/dist/src/imageParameter.d.ts +60 -0
  83. package/dist/src/imageParameter.js +262 -0
  84. package/dist/src/imagemap.d.ts +47 -0
  85. package/dist/src/imagemap.js +148 -0
  86. package/dist/src/imagemapLink.d.ts +35 -0
  87. package/dist/src/imagemapLink.js +99 -0
  88. package/dist/src/index.d.ts +136 -0
  89. package/dist/src/index.js +790 -0
  90. package/dist/src/link/base.d.ts +52 -0
  91. package/dist/src/link/base.js +258 -0
  92. package/dist/src/link/category.d.ts +22 -0
  93. package/dist/src/link/category.js +36 -0
  94. package/dist/src/link/file.d.ts +102 -0
  95. package/dist/src/link/file.js +345 -0
  96. package/dist/src/link/galleryImage.d.ts +29 -0
  97. package/dist/src/link/galleryImage.js +133 -0
  98. package/dist/src/link/index.d.ts +39 -0
  99. package/dist/src/link/index.js +100 -0
  100. package/dist/src/link/redirectTarget.d.ts +27 -0
  101. package/dist/src/link/redirectTarget.js +71 -0
  102. package/dist/src/magicLink.d.ts +57 -0
  103. package/dist/src/magicLink.js +261 -0
  104. package/dist/src/nested.d.ts +40 -0
  105. package/dist/src/nested.js +108 -0
  106. package/dist/src/nowiki/base.d.ts +28 -0
  107. package/dist/src/nowiki/base.js +90 -0
  108. package/dist/src/nowiki/comment.d.ts +14 -0
  109. package/dist/src/nowiki/comment.js +123 -0
  110. package/dist/src/nowiki/dd.d.ts +8 -0
  111. package/dist/src/nowiki/dd.js +74 -0
  112. package/dist/src/nowiki/doubleUnderscore.d.ts +15 -0
  113. package/dist/src/nowiki/doubleUnderscore.js +101 -0
  114. package/dist/src/nowiki/hr.d.ts +5 -0
  115. package/dist/src/nowiki/hr.js +72 -0
  116. package/dist/src/nowiki/index.d.ts +14 -0
  117. package/dist/src/nowiki/index.js +30 -0
  118. package/dist/src/nowiki/list.d.ts +5 -0
  119. package/dist/src/nowiki/list.js +67 -0
  120. package/dist/src/nowiki/listBase.d.ts +23 -0
  121. package/dist/src/nowiki/listBase.js +100 -0
  122. package/dist/src/nowiki/noinclude.d.ts +6 -0
  123. package/dist/src/nowiki/noinclude.js +77 -0
  124. package/dist/src/nowiki/quote.d.ts +14 -0
  125. package/dist/src/nowiki/quote.js +149 -0
  126. package/dist/src/onlyinclude.d.ts +13 -0
  127. package/dist/src/onlyinclude.js +60 -0
  128. package/dist/src/paramTag/index.d.ts +28 -0
  129. package/dist/src/paramTag/index.js +80 -0
  130. package/dist/src/paramTag/inputbox.d.ts +8 -0
  131. package/dist/src/paramTag/inputbox.js +38 -0
  132. package/dist/src/parameter.d.ts +60 -0
  133. package/dist/src/parameter.js +267 -0
  134. package/dist/src/pre.d.ts +28 -0
  135. package/dist/src/pre.js +70 -0
  136. package/dist/src/redirect.d.ts +30 -0
  137. package/dist/src/redirect.js +128 -0
  138. package/dist/src/syntax.d.ts +15 -0
  139. package/dist/src/syntax.js +87 -0
  140. package/dist/src/table/base.d.ts +28 -0
  141. package/dist/src/table/base.js +81 -0
  142. package/dist/src/table/index.d.ts +230 -0
  143. package/dist/src/table/index.js +506 -0
  144. package/dist/src/table/td.d.ts +72 -0
  145. package/dist/src/table/td.js +375 -0
  146. package/dist/src/table/tr.d.ts +30 -0
  147. package/dist/src/table/tr.js +61 -0
  148. package/dist/src/table/trBase.d.ts +49 -0
  149. package/dist/src/table/trBase.js +165 -0
  150. package/dist/src/tagPair/ext.d.ts +29 -0
  151. package/dist/src/tagPair/ext.js +229 -0
  152. package/dist/src/tagPair/include.d.ts +33 -0
  153. package/dist/src/tagPair/include.js +145 -0
  154. package/dist/src/tagPair/index.d.ts +23 -0
  155. package/dist/src/tagPair/index.js +130 -0
  156. package/dist/src/transclude.d.ts +159 -0
  157. package/dist/src/transclude.js +598 -0
  158. package/dist/util/constants.js +26 -0
  159. package/dist/util/debug.js +95 -0
  160. package/dist/util/diff.js +83 -0
  161. package/dist/util/html.js +146 -0
  162. package/dist/util/lint.js +32 -0
  163. package/dist/util/string.js +107 -0
  164. package/errors/README +3 -0
  165. package/package.json +21 -28
  166. package/printed/README +3 -0
  167. package/bundle/bundle.min.js +0 -37
  168. package/extensions/dist/base.js +0 -163
  169. package/extensions/dist/codejar.js +0 -53
  170. package/extensions/dist/editor.js +0 -159
  171. package/extensions/dist/highlight.js +0 -30
  172. package/extensions/dist/lint.js +0 -72
  173. package/extensions/editor.css +0 -59
  174. package/extensions/ui.css +0 -162
@@ -0,0 +1,223 @@
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;
@@ -0,0 +1,51 @@
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
+ }
@@ -0,0 +1,166 @@
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;
@@ -0,0 +1,44 @@
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
+ }