wikiparser-node 1.12.4 → 1.12.5-b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/bundle/bundle.min.js +37 -0
  2. package/config/default.json +29 -30
  3. package/config/enwiki.json +15 -829
  4. package/config/llwiki.json +21 -56
  5. package/config/minimum.json +6 -1
  6. package/config/moegirl.json +21 -65
  7. package/config/zhwiki.json +28 -494
  8. package/extensions/dist/base.js +163 -0
  9. package/extensions/dist/codejar.js +52 -0
  10. package/extensions/dist/editor.js +159 -0
  11. package/extensions/dist/highlight.js +30 -0
  12. package/extensions/dist/lint.js +72 -0
  13. package/extensions/editor.css +59 -0
  14. package/extensions/ui.css +162 -0
  15. package/package.json +28 -21
  16. package/config/.schema.json +0 -203
  17. package/dist/addon/table.js +0 -494
  18. package/dist/addon/token.js +0 -392
  19. package/dist/addon/transclude.js +0 -184
  20. package/dist/base.d.ts +0 -81
  21. package/dist/base.js +0 -40
  22. package/dist/index.d.ts +0 -33
  23. package/dist/index.js +0 -275
  24. package/dist/internal.d.ts +0 -47
  25. package/dist/lib/element.d.ts +0 -125
  26. package/dist/lib/element.js +0 -377
  27. package/dist/lib/node.d.ts +0 -173
  28. package/dist/lib/node.js +0 -478
  29. package/dist/lib/range.d.ts +0 -105
  30. package/dist/lib/range.js +0 -406
  31. package/dist/lib/ranges.d.ts +0 -28
  32. package/dist/lib/ranges.js +0 -126
  33. package/dist/lib/rect.d.ts +0 -18
  34. package/dist/lib/rect.js +0 -36
  35. package/dist/lib/text.d.ts +0 -58
  36. package/dist/lib/text.js +0 -414
  37. package/dist/lib/title.d.ts +0 -49
  38. package/dist/lib/title.js +0 -253
  39. package/dist/mixin/attributesParent.d.ts +0 -49
  40. package/dist/mixin/attributesParent.js +0 -80
  41. package/dist/mixin/fixed.d.ts +0 -5
  42. package/dist/mixin/fixed.js +0 -32
  43. package/dist/mixin/flagsParent.d.ts +0 -43
  44. package/dist/mixin/flagsParent.js +0 -64
  45. package/dist/mixin/hidden.d.ts +0 -7
  46. package/dist/mixin/hidden.js +0 -39
  47. package/dist/mixin/magicLinkParent.d.ts +0 -19
  48. package/dist/mixin/magicLinkParent.js +0 -43
  49. package/dist/mixin/singleLine.d.ts +0 -5
  50. package/dist/mixin/singleLine.js +0 -25
  51. package/dist/mixin/sol.d.ts +0 -6
  52. package/dist/mixin/sol.js +0 -45
  53. package/dist/mixin/syntax.d.ts +0 -8
  54. package/dist/mixin/syntax.js +0 -46
  55. package/dist/parser/braces.js +0 -152
  56. package/dist/parser/commentAndExt.js +0 -84
  57. package/dist/parser/converter.js +0 -41
  58. package/dist/parser/externalLinks.js +0 -39
  59. package/dist/parser/hrAndDoubleUnderscore.js +0 -44
  60. package/dist/parser/html.js +0 -40
  61. package/dist/parser/links.js +0 -103
  62. package/dist/parser/list.js +0 -116
  63. package/dist/parser/magicLinks.js +0 -55
  64. package/dist/parser/quotes.js +0 -69
  65. package/dist/parser/redirect.js +0 -28
  66. package/dist/parser/selector.js +0 -393
  67. package/dist/parser/table.js +0 -125
  68. package/dist/src/arg.d.ts +0 -49
  69. package/dist/src/arg.js +0 -219
  70. package/dist/src/atom.d.ts +0 -14
  71. package/dist/src/atom.js +0 -54
  72. package/dist/src/attribute.d.ts +0 -64
  73. package/dist/src/attribute.js +0 -478
  74. package/dist/src/attributes.d.ts +0 -103
  75. package/dist/src/attributes.js +0 -380
  76. package/dist/src/converter.d.ts +0 -28
  77. package/dist/src/converter.js +0 -153
  78. package/dist/src/converterFlags.d.ts +0 -80
  79. package/dist/src/converterFlags.js +0 -241
  80. package/dist/src/converterRule.d.ts +0 -71
  81. package/dist/src/converterRule.js +0 -218
  82. package/dist/src/extLink.d.ts +0 -36
  83. package/dist/src/extLink.js +0 -223
  84. package/dist/src/gallery.d.ts +0 -47
  85. package/dist/src/gallery.js +0 -145
  86. package/dist/src/heading.d.ts +0 -44
  87. package/dist/src/heading.js +0 -222
  88. package/dist/src/hidden.d.ts +0 -9
  89. package/dist/src/hidden.js +0 -82
  90. package/dist/src/html.d.ts +0 -61
  91. package/dist/src/html.js +0 -344
  92. package/dist/src/imageParameter.d.ts +0 -60
  93. package/dist/src/imageParameter.js +0 -262
  94. package/dist/src/imagemap.d.ts +0 -47
  95. package/dist/src/imagemap.js +0 -148
  96. package/dist/src/imagemapLink.d.ts +0 -35
  97. package/dist/src/imagemapLink.js +0 -99
  98. package/dist/src/index.d.ts +0 -136
  99. package/dist/src/index.js +0 -790
  100. package/dist/src/link/base.d.ts +0 -52
  101. package/dist/src/link/base.js +0 -258
  102. package/dist/src/link/category.d.ts +0 -22
  103. package/dist/src/link/category.js +0 -36
  104. package/dist/src/link/file.d.ts +0 -102
  105. package/dist/src/link/file.js +0 -335
  106. package/dist/src/link/galleryImage.d.ts +0 -29
  107. package/dist/src/link/galleryImage.js +0 -133
  108. package/dist/src/link/index.d.ts +0 -39
  109. package/dist/src/link/index.js +0 -100
  110. package/dist/src/link/redirectTarget.d.ts +0 -27
  111. package/dist/src/link/redirectTarget.js +0 -71
  112. package/dist/src/magicLink.d.ts +0 -57
  113. package/dist/src/magicLink.js +0 -261
  114. package/dist/src/nested.d.ts +0 -40
  115. package/dist/src/nested.js +0 -108
  116. package/dist/src/nowiki/base.d.ts +0 -28
  117. package/dist/src/nowiki/base.js +0 -90
  118. package/dist/src/nowiki/comment.d.ts +0 -14
  119. package/dist/src/nowiki/comment.js +0 -123
  120. package/dist/src/nowiki/dd.d.ts +0 -8
  121. package/dist/src/nowiki/dd.js +0 -74
  122. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  123. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  124. package/dist/src/nowiki/hr.d.ts +0 -5
  125. package/dist/src/nowiki/hr.js +0 -72
  126. package/dist/src/nowiki/index.d.ts +0 -14
  127. package/dist/src/nowiki/index.js +0 -30
  128. package/dist/src/nowiki/list.d.ts +0 -5
  129. package/dist/src/nowiki/list.js +0 -67
  130. package/dist/src/nowiki/listBase.d.ts +0 -23
  131. package/dist/src/nowiki/listBase.js +0 -100
  132. package/dist/src/nowiki/noinclude.d.ts +0 -6
  133. package/dist/src/nowiki/noinclude.js +0 -77
  134. package/dist/src/nowiki/quote.d.ts +0 -14
  135. package/dist/src/nowiki/quote.js +0 -149
  136. package/dist/src/onlyinclude.d.ts +0 -13
  137. package/dist/src/onlyinclude.js +0 -60
  138. package/dist/src/paramTag/index.d.ts +0 -28
  139. package/dist/src/paramTag/index.js +0 -80
  140. package/dist/src/paramTag/inputbox.d.ts +0 -8
  141. package/dist/src/paramTag/inputbox.js +0 -24
  142. package/dist/src/parameter.d.ts +0 -60
  143. package/dist/src/parameter.js +0 -267
  144. package/dist/src/pre.d.ts +0 -28
  145. package/dist/src/pre.js +0 -62
  146. package/dist/src/redirect.d.ts +0 -30
  147. package/dist/src/redirect.js +0 -128
  148. package/dist/src/syntax.d.ts +0 -15
  149. package/dist/src/syntax.js +0 -87
  150. package/dist/src/table/base.d.ts +0 -28
  151. package/dist/src/table/base.js +0 -81
  152. package/dist/src/table/index.d.ts +0 -230
  153. package/dist/src/table/index.js +0 -506
  154. package/dist/src/table/td.d.ts +0 -72
  155. package/dist/src/table/td.js +0 -375
  156. package/dist/src/table/tr.d.ts +0 -30
  157. package/dist/src/table/tr.js +0 -61
  158. package/dist/src/table/trBase.d.ts +0 -49
  159. package/dist/src/table/trBase.js +0 -165
  160. package/dist/src/tagPair/ext.d.ts +0 -29
  161. package/dist/src/tagPair/ext.js +0 -217
  162. package/dist/src/tagPair/include.d.ts +0 -33
  163. package/dist/src/tagPair/include.js +0 -132
  164. package/dist/src/tagPair/index.d.ts +0 -23
  165. package/dist/src/tagPair/index.js +0 -130
  166. package/dist/src/transclude.d.ts +0 -159
  167. package/dist/src/transclude.js +0 -598
  168. package/dist/util/constants.js +0 -26
  169. package/dist/util/debug.js +0 -95
  170. package/dist/util/diff.js +0 -83
  171. package/dist/util/html.js +0 -146
  172. package/dist/util/lint.js +0 -32
  173. package/dist/util/string.js +0 -107
  174. package/errors/README +0 -3
  175. package/printed/README +0 -3
@@ -1,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,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,145 +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
- /* NOT FOR BROWSER END */
12
- /**
13
- * gallery标签
14
- * @classdesc `{childNodes: ...(GalleryImageToken|NoincludeToken|AstText)}`
15
- */
16
- class GalleryToken extends index_2.Token {
17
- /* NOT FOR BROWSER END */
18
- get type() {
19
- return 'ext-inner';
20
- }
21
- /* NOT FOR BROWSER */
22
- /** 所有图片 */
23
- get images() {
24
- return this.childNodes.filter((0, debug_1.isToken)('gallery-image'));
25
- }
26
- /* NOT FOR BROWSER END */
27
- /** @param inner 标签内部wikitext */
28
- constructor(inner, config = index_1.default.getConfig(), accum = []) {
29
- super(undefined, config, accum, {
30
- AstText: ':', GalleryImageToken: ':', NoincludeToken: ':',
31
- });
32
- for (const line of inner?.split('\n') ?? []) {
33
- const matches = /^([^|]+)(?:\|(.*))?/u.exec(line);
34
- if (!matches) {
35
- // @ts-expect-error abstract class
36
- super.insertAt((line.trim() ? new noinclude_1.NoincludeToken(line, config, accum) : line));
37
- continue;
38
- }
39
- const [, file, alt] = matches;
40
- if (this.#checkFile(file)) {
41
- // @ts-expect-error abstract class
42
- super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
43
- }
44
- else {
45
- // @ts-expect-error abstract class
46
- super.insertAt(new noinclude_1.NoincludeToken(line, config, accum));
47
- }
48
- }
49
- }
50
- /**
51
- * 检查文件名是否有效
52
- * @param file 文件名
53
- */
54
- #checkFile(file) {
55
- return this.normalizeTitle(file, 6, true, true).valid;
56
- }
57
- /** @private */
58
- toString(skip) {
59
- return super.toString(skip, '\n');
60
- }
61
- /** @private */
62
- text() {
63
- return super.text('\n').replace(/\n\s*\n/gu, '\n');
64
- }
65
- /** @private */
66
- getGaps() {
67
- return 1;
68
- }
69
- /** @private */
70
- lint(start = this.getAbsoluteIndex(), re) {
71
- const { top, left } = this.getRootNode().posFromIndex(start), errors = [];
72
- for (const [i, child] of this.childNodes.entries()) {
73
- const str = child.toString(), { length } = str, trimmed = str.trim(), startLine = top + i, startCol = i ? 0 : left;
74
- if (child.type === 'noinclude' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
75
- const endIndex = start + length;
76
- errors.push({
77
- rule: 'no-ignored',
78
- message: index_1.default.msg('invalid content in <$1>', 'gallery'),
79
- severity: trimmed.startsWith('|') ? 'warning' : 'error',
80
- startIndex: start,
81
- endIndex,
82
- startLine,
83
- endLine: startLine,
84
- startCol,
85
- endCol: startCol + length,
86
- suggestions: [
87
- {
88
- desc: 'remove',
89
- range: [start, endIndex],
90
- text: '',
91
- },
92
- {
93
- desc: 'comment',
94
- range: [start, endIndex],
95
- text: `<!--${str}-->`,
96
- },
97
- ],
98
- });
99
- }
100
- else if (child.type !== 'noinclude' && child.type !== 'text') {
101
- errors.push(...child.lint(start, re));
102
- }
103
- start += length + 1;
104
- }
105
- return errors;
106
- }
107
- /** @private */
108
- print() {
109
- return super.print({ sep: '\n' });
110
- }
111
- /* NOT FOR BROWSER */
112
- cloneNode() {
113
- const cloned = this.cloneChildNodes();
114
- return debug_1.Shadow.run(() => {
115
- // @ts-expect-error abstract class
116
- const token = new GalleryToken(undefined, this.getAttribute('config'));
117
- token.append(...cloned);
118
- return token;
119
- });
120
- }
121
- /**
122
- * 插入图片
123
- * @param file 图片文件名
124
- * @param i 插入位置
125
- * @throws `SyntaxError` 非法的文件名
126
- */
127
- insertImage(file, i) {
128
- if (this.#checkFile(file)) {
129
- const token = debug_1.Shadow.run(
130
- // @ts-expect-error abstract class
131
- () => new galleryImage_1.GalleryImageToken('gallery', file, undefined, this.getAttribute('config')));
132
- token.afterBuild();
133
- return this.insertAt(token, i);
134
- }
135
- throw new SyntaxError(`Invalid file name: ${file}`);
136
- }
137
- insertAt(token, i = this.length) {
138
- if (!debug_1.Shadow.running && (typeof token === 'string' && token.trim() || token instanceof noinclude_1.NoincludeToken)) {
139
- throw new RangeError('Please do not insert invisible content into <gallery>!');
140
- }
141
- return super.insertAt(token, i);
142
- }
143
- }
144
- exports.GalleryToken = GalleryToken;
145
- 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
- }
@@ -1,222 +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 debug_1 = require("../util/debug");
40
- const rect_1 = require("../lib/rect");
41
- const index_1 = require("../index");
42
- const index_2 = require("./index");
43
- const syntax_1 = require("./syntax");
44
- /* NOT FOR BROWSER */
45
- const constants_1 = require("../util/constants");
46
- const string_1 = require("../util/string");
47
- const fixed_1 = require("../mixin/fixed");
48
- const sol_1 = require("../mixin/sol");
49
- /* NOT FOR BROWSER END */
50
- /**
51
- * 章节标题
52
- * @classdesc `{childNodes: [Token, SyntaxToken]}`
53
- */
54
- let HeadingToken = (() => {
55
- let _classDecorators = [fixed_1.fixedToken, (0, sol_1.sol)()];
56
- let _classDescriptor;
57
- let _classExtraInitializers = [];
58
- let _classThis;
59
- let _classSuper = index_2.Token;
60
- var HeadingToken = class extends _classSuper {
61
- static { _classThis = this; }
62
- static {
63
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
64
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
65
- HeadingToken = _classThis = _classDescriptor.value;
66
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
67
- __runInitializers(_classThis, _classExtraInitializers);
68
- }
69
- #level;
70
- /* NOT FOR BROWSER END */
71
- get type() {
72
- return 'heading';
73
- }
74
- /** 标题格式的等号 */
75
- get #equals() {
76
- return '='.repeat(this.level);
77
- }
78
- /** 标题层级 */
79
- get level() {
80
- return this.#level;
81
- }
82
- /* NOT FOR BROWSER */
83
- set level(n) {
84
- this.setLevel(n);
85
- }
86
- /** 内部wikitext */
87
- get innerText() {
88
- return this.firstChild.text().trim();
89
- }
90
- /** @throws `Error` 首尾包含`=` */
91
- set innerText(text) {
92
- if (text.length > 1 && text.startsWith('=') && text.endsWith('=')) {
93
- throw new Error('Please use HeadingToken.setLevel method to change the level of the heading!');
94
- }
95
- const { childNodes } = index_1.default.parse(text, this.getAttribute('include'), undefined, this.getAttribute('config'));
96
- this.firstChild.replaceChildren(...childNodes);
97
- }
98
- /** id属性 */
99
- get id() {
100
- return this.#getId(true);
101
- }
102
- /* NOT FOR BROWSER END */
103
- /**
104
- * @param level 标题层级
105
- * @param input 标题文字
106
- */
107
- constructor(level, input, config = index_1.default.getConfig(), accum = []) {
108
- super(undefined, config, accum);
109
- this.#level = level;
110
- const token = new index_2.Token(input[0], config, accum);
111
- token.type = 'heading-title';
112
- token.setAttribute('stage', 2);
113
- const trail = new syntax_1.SyntaxToken(input[1], /^\s*$/u, 'heading-trail', config, accum, {
114
- 'Stage-1': ':', '!ExtToken': '',
115
- });
116
- this.append(token, trail);
117
- }
118
- /** @private */
119
- toString(skip) {
120
- const equals = this.#equals;
121
- return equals + this.firstChild.toString(skip) + equals + this.lastChild.toString(skip);
122
- }
123
- /** @private */
124
- text() {
125
- const equals = this.#equals;
126
- return equals + this.firstChild.text() + equals;
127
- }
128
- /** @private */
129
- getAttribute(key) {
130
- return key === 'padding' ? this.level : super.getAttribute(key);
131
- }
132
- /** @private */
133
- getGaps() {
134
- return this.level;
135
- }
136
- /** @private */
137
- lint(start = this.getAbsoluteIndex(), re) {
138
- 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);
139
- if (this.level === 1) {
140
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'h1', '<h1>'));
141
- }
142
- if (innerStr.startsWith('=') || innerStr.endsWith('=')) {
143
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'unbalanced-header', index_1.default.msg('unbalanced $1 in a section header', '"="')));
144
- }
145
- if (this.closest('html-attrs,table-attrs')) {
146
- errors.push((0, lint_1.generateForSelf)(this, rect, 'parsing-order', 'section header in a HTML tag'));
147
- }
148
- if (boldQuotes.length % 2) {
149
- 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')));
150
- }
151
- if (italicQuotes.length % 2) {
152
- 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')));
153
- }
154
- return errors;
155
- }
156
- /** @private */
157
- print() {
158
- const equals = this.#equals;
159
- return super.print({ pre: equals, sep: equals });
160
- }
161
- /** @override */
162
- json() {
163
- const json = super.json();
164
- json['level'] = this.level;
165
- return json;
166
- }
167
- /* NOT FOR BROWSER */
168
- cloneNode() {
169
- const [title, trail] = this.cloneChildNodes();
170
- return debug_1.Shadow.run(() => {
171
- // @ts-expect-error abstract class
172
- const token = new HeadingToken(this.level, [], this.getAttribute('config'));
173
- token.firstChild.safeReplaceWith(title);
174
- token.lastChild.safeReplaceWith(trail);
175
- return token;
176
- });
177
- }
178
- /**
179
- * 设置标题层级
180
- * @param n 标题层级
181
- */
182
- setLevel(n) {
183
- this.#level = Math.min(Math.max(n, 1), 6);
184
- }
185
- /** 移除标题后的不可见内容 */
186
- removeTrail() {
187
- this.lastChild.replaceChildren();
188
- }
189
- /**
190
- * id属性
191
- * @param expand 是否展开模板
192
- */
193
- #getId(expand) {
194
- const token = expand ? this.firstChild.expand() : this.firstChild;
195
- let id = (0, string_1.decodeHtml)((0, string_1.sanitizeAlt)(token.toHtmlInternal(false, true))).replace(/[\s_]+/gu, '_');
196
- if (id.endsWith('_')) {
197
- id = id.slice(0, -1);
198
- }
199
- return id;
200
- }
201
- /** @private */
202
- toHtmlInternal() {
203
- let id = this.#getId();
204
- const { level, firstChild } = this, lcId = id.toLowerCase(), headings = constants_1.states.get(this.getRootNode())?.headings;
205
- if (headings?.has(lcId)) {
206
- let i = 2;
207
- for (; headings.has(`${lcId}_${i}`); i++) {
208
- // pass
209
- }
210
- id = `${id}_${i}`;
211
- headings.add(`${lcId}_${i}`);
212
- }
213
- else {
214
- headings?.add(lcId);
215
- }
216
- return `<div class="mw-heading mw-heading${level}"><h${level} id="${(0, string_1.sanitizeId)(id)}">${firstChild.toHtmlInternal().trim()}</h${level}></div>`;
217
- }
218
- };
219
- return HeadingToken = _classThis;
220
- })();
221
- exports.HeadingToken = HeadingToken;
222
- constants_1.classes['HeadingToken'] = __filename;