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