wikiparser-node 1.11.1 → 1.12.0-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 +28 -28
  3. package/config/enwiki.json +14 -827
  4. package/config/llwiki.json +20 -54
  5. package/config/minimum.json +1 -1
  6. package/config/moegirl.json +20 -63
  7. package/config/zhwiki.json +27 -492
  8. package/extensions/dist/base.js +162 -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 +159 -0
  15. package/package.json +29 -21
  16. package/config/.schema.json +0 -186
  17. package/dist/addon/table.js +0 -486
  18. package/dist/addon/token.js +0 -304
  19. package/dist/addon/transclude.js +0 -184
  20. package/dist/base.d.ts +0 -81
  21. package/dist/base.js +0 -39
  22. package/dist/index.d.ts +0 -33
  23. package/dist/index.js +0 -235
  24. package/dist/internal.d.ts +0 -46
  25. package/dist/lib/element.d.ts +0 -125
  26. package/dist/lib/element.js +0 -375
  27. package/dist/lib/node.d.ts +0 -173
  28. package/dist/lib/node.js +0 -477
  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 -34
  35. package/dist/lib/text.d.ts +0 -58
  36. package/dist/lib/text.js +0 -400
  37. package/dist/lib/title.d.ts +0 -42
  38. package/dist/lib/title.js +0 -208
  39. package/dist/mixin/attributesParent.d.ts +0 -49
  40. package/dist/mixin/attributesParent.js +0 -79
  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 -37
  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 -150
  56. package/dist/parser/commentAndExt.js +0 -79
  57. package/dist/parser/converter.js +0 -39
  58. package/dist/parser/externalLinks.js +0 -37
  59. package/dist/parser/hrAndDoubleUnderscore.js +0 -42
  60. package/dist/parser/html.js +0 -38
  61. package/dist/parser/links.js +0 -101
  62. package/dist/parser/list.js +0 -114
  63. package/dist/parser/magicLinks.js +0 -52
  64. package/dist/parser/quotes.js +0 -67
  65. package/dist/parser/redirect.js +0 -26
  66. package/dist/parser/selector.js +0 -394
  67. package/dist/parser/table.js +0 -123
  68. package/dist/src/arg.d.ts +0 -51
  69. package/dist/src/arg.js +0 -214
  70. package/dist/src/atom.d.ts +0 -14
  71. package/dist/src/atom.js +0 -52
  72. package/dist/src/attribute.d.ts +0 -64
  73. package/dist/src/attribute.js +0 -480
  74. package/dist/src/attributes.d.ts +0 -101
  75. package/dist/src/attributes.js +0 -381
  76. package/dist/src/converter.d.ts +0 -28
  77. package/dist/src/converter.js +0 -148
  78. package/dist/src/converterFlags.d.ts +0 -80
  79. package/dist/src/converterFlags.js +0 -239
  80. package/dist/src/converterRule.d.ts +0 -71
  81. package/dist/src/converterRule.js +0 -216
  82. package/dist/src/extLink.d.ts +0 -36
  83. package/dist/src/extLink.js +0 -218
  84. package/dist/src/gallery.d.ts +0 -47
  85. package/dist/src/gallery.js +0 -143
  86. package/dist/src/heading.d.ts +0 -40
  87. package/dist/src/heading.js +0 -192
  88. package/dist/src/hidden.d.ts +0 -9
  89. package/dist/src/hidden.js +0 -80
  90. package/dist/src/html.d.ts +0 -61
  91. package/dist/src/html.js +0 -343
  92. package/dist/src/imageParameter.d.ts +0 -60
  93. package/dist/src/imageParameter.js +0 -260
  94. package/dist/src/imagemap.d.ts +0 -47
  95. package/dist/src/imagemap.js +0 -146
  96. package/dist/src/imagemapLink.d.ts +0 -31
  97. package/dist/src/imagemapLink.js +0 -97
  98. package/dist/src/index.d.ts +0 -136
  99. package/dist/src/index.js +0 -834
  100. package/dist/src/link/base.d.ts +0 -52
  101. package/dist/src/link/base.js +0 -256
  102. package/dist/src/link/category.d.ts +0 -22
  103. package/dist/src/link/category.js +0 -34
  104. package/dist/src/link/file.d.ts +0 -102
  105. package/dist/src/link/file.js +0 -333
  106. package/dist/src/link/galleryImage.d.ts +0 -29
  107. package/dist/src/link/galleryImage.js +0 -132
  108. package/dist/src/link/index.d.ts +0 -39
  109. package/dist/src/link/index.js +0 -98
  110. package/dist/src/link/redirectTarget.d.ts +0 -27
  111. package/dist/src/link/redirectTarget.js +0 -69
  112. package/dist/src/magicLink.d.ts +0 -58
  113. package/dist/src/magicLink.js +0 -256
  114. package/dist/src/nested.d.ts +0 -40
  115. package/dist/src/nested.js +0 -106
  116. package/dist/src/nowiki/base.d.ts +0 -28
  117. package/dist/src/nowiki/base.js +0 -89
  118. package/dist/src/nowiki/comment.d.ts +0 -14
  119. package/dist/src/nowiki/comment.js +0 -121
  120. package/dist/src/nowiki/dd.d.ts +0 -8
  121. package/dist/src/nowiki/dd.js +0 -72
  122. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  123. package/dist/src/nowiki/doubleUnderscore.js +0 -97
  124. package/dist/src/nowiki/hr.d.ts +0 -5
  125. package/dist/src/nowiki/hr.js +0 -70
  126. package/dist/src/nowiki/index.d.ts +0 -14
  127. package/dist/src/nowiki/index.js +0 -28
  128. package/dist/src/nowiki/list.d.ts +0 -5
  129. package/dist/src/nowiki/list.js +0 -65
  130. package/dist/src/nowiki/listBase.d.ts +0 -23
  131. package/dist/src/nowiki/listBase.js +0 -99
  132. package/dist/src/nowiki/noinclude.d.ts +0 -6
  133. package/dist/src/nowiki/noinclude.js +0 -75
  134. package/dist/src/nowiki/quote.d.ts +0 -14
  135. package/dist/src/nowiki/quote.js +0 -140
  136. package/dist/src/onlyinclude.d.ts +0 -13
  137. package/dist/src/onlyinclude.js +0 -58
  138. package/dist/src/paramTag/index.d.ts +0 -28
  139. package/dist/src/paramTag/index.js +0 -78
  140. package/dist/src/paramTag/inputbox.d.ts +0 -8
  141. package/dist/src/paramTag/inputbox.js +0 -22
  142. package/dist/src/parameter.d.ts +0 -60
  143. package/dist/src/parameter.js +0 -264
  144. package/dist/src/pre.d.ts +0 -28
  145. package/dist/src/pre.js +0 -60
  146. package/dist/src/redirect.d.ts +0 -30
  147. package/dist/src/redirect.js +0 -126
  148. package/dist/src/syntax.d.ts +0 -17
  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 -370
  156. package/dist/src/table/tr.d.ts +0 -30
  157. package/dist/src/table/tr.js +0 -59
  158. package/dist/src/table/trBase.d.ts +0 -49
  159. package/dist/src/table/trBase.js +0 -164
  160. package/dist/src/tagPair/ext.d.ts +0 -29
  161. package/dist/src/tagPair/ext.js +0 -220
  162. package/dist/src/tagPair/include.d.ts +0 -33
  163. package/dist/src/tagPair/include.js +0 -130
  164. package/dist/src/tagPair/index.d.ts +0 -23
  165. package/dist/src/tagPair/index.js +0 -128
  166. package/dist/src/transclude.d.ts +0 -159
  167. package/dist/src/transclude.js +0 -587
  168. package/dist/util/constants.js +0 -25
  169. package/dist/util/debug.js +0 -95
  170. package/dist/util/diff.js +0 -83
  171. package/dist/util/html.js +0 -143
  172. package/dist/util/lint.js +0 -32
  173. package/dist/util/string.js +0 -87
  174. package/errors/README +0 -3
  175. package/printed/README +0 -3
@@ -1,260 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ImageParameterToken = exports.galleryParams = void 0;
4
- const string_1 = require("../util/string");
5
- const lint_1 = require("../util/lint");
6
- const debug_1 = require("../util/debug");
7
- const constants_1 = require("../util/constants");
8
- const index_1 = require("../index");
9
- const index_2 = require("./index");
10
- exports.galleryParams = new Set(['alt', 'link', 'lang', 'page', 'caption']);
11
- function validate(key, val, config, halfParsed, ext) {
12
- val = val.trim();
13
- let value = val.replace(key === 'link' ? /\0\d+[tq]\x7F/gu : /\0\d+t\x7F/gu, '').trim();
14
- switch (key) {
15
- case 'width':
16
- return !value && Boolean(val) || /^(?:\d+x?|\d*x\d+)(?:\s*px)?$/u.test(value);
17
- case 'link': {
18
- if (!value) {
19
- return val;
20
- }
21
- /* eslint-disable @typescript-eslint/no-unused-expressions */
22
- /^(?:ftp:\/\/|\/\/|\0\d+m\x7F)/iu;
23
- /^(?:(?:ftp:\/\/|\/\/)(?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])|\0\d+m\x7F)[^[\]<>"\0\t\n\p{Zs}]*$/iu;
24
- /* eslint-enable @typescript-eslint/no-unused-expressions */
25
- const re1 = new RegExp(String.raw `^(?:${config.protocol}|//|\0\d+m\x7F)`, 'iu'), re2 = new RegExp(String.raw `^(?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\d+m\x7F)${string_1.extUrlChar}$`, 'iu');
26
- if (re1.test(value)) {
27
- return re2.test(value) && val;
28
- }
29
- else if (value.startsWith('[[') && value.endsWith(']]')) {
30
- value = value.slice(2, -2);
31
- }
32
- const title = index_1.default.normalizeTitle(value, 0, false, config, halfParsed, true, true);
33
- return title.valid && title;
34
- }
35
- case 'lang':
36
- return (ext === 'svg' || ext === 'svgz') && !/[^a-z\d-]/u.test(value);
37
- case 'alt':
38
- case 'class':
39
- case 'manualthumb':
40
- return true;
41
- case 'page':
42
- return (ext === 'djvu' || ext === 'djv' || ext === 'pdf') && Number(value) > 0;
43
- default:
44
- return Boolean(value) && !isNaN(value);
45
- }
46
- }
47
- /** 图片参数 */
48
- class ImageParameterToken extends index_2.Token {
49
- #syntax = '';
50
- #extension;
51
- /* NOT FOR BROWSER END */
52
- get type() {
53
- return 'image-parameter';
54
- }
55
- /** 图片链接 */
56
- get link() {
57
- return this.name === 'link' ? validate('link', super.text(), this.getAttribute('config')) : undefined;
58
- }
59
- /* NOT FOR BROWSER */
60
- set link(value) {
61
- if (this.name === 'link') {
62
- this.setValue(value);
63
- }
64
- }
65
- /** getValue()的getter */
66
- get value() {
67
- return this.getValue();
68
- }
69
- set value(value) {
70
- this.setValue(value);
71
- }
72
- /** 图片大小 */
73
- get size() {
74
- if (this.name === 'width') {
75
- const size = this.getValue().trim().replace(/px$/u, '').trim();
76
- if (!size.includes('{{')) {
77
- const [width, height = ''] = size.split('x');
78
- return { width, height };
79
- }
80
- const token = index_1.default.parse(size, false, 2, this.getAttribute('config')), i = token.childNodes.findIndex(({ type, data }) => type === 'text' && data.includes('x'));
81
- if (i === -1) {
82
- return { width: size, height: '' };
83
- }
84
- const str = token.childNodes[i];
85
- str.splitText(str.data.indexOf('x')).splitText(1);
86
- return { width: (0, string_1.text)(token.childNodes.slice(0, i + 1)), height: (0, string_1.text)(token.childNodes.slice(i + 2)) };
87
- }
88
- return undefined;
89
- }
90
- set size(size) {
91
- if (this.name === 'width') {
92
- this.setValue(size && size.width + (size.height && 'x') + size.height);
93
- }
94
- }
95
- /** 图片宽度 */
96
- get width() {
97
- return this.size?.width;
98
- }
99
- set width(width) {
100
- if (this.name === 'width') {
101
- const { height } = this;
102
- this.setValue((width || '') + (height && 'x') + height);
103
- }
104
- }
105
- /** 图片高度 */
106
- get height() {
107
- return this.size?.height;
108
- }
109
- set height(height) {
110
- if (this.name === 'width') {
111
- this.setValue(`${this.width}${height ? `x${height}` : ''}`);
112
- }
113
- }
114
- /* NOT FOR BROWSER END */
115
- /** @param str 图片参数 */
116
- constructor(str, extension, config = index_1.default.getConfig(), accum) {
117
- let mt;
118
- /* eslint-disable @typescript-eslint/no-unused-expressions */
119
- /^(\s*)link=(.*)(?=$|\n)(\s*)$/u;
120
- /^(\s*(?!\s))(.*)px(\s*)$/u;
121
- /* eslint-enable @typescript-eslint/no-unused-expressions */
122
- const regexes = Object.entries(config.img).map(([syntax, param]) => [
123
- syntax,
124
- param,
125
- new RegExp(String.raw `^(\s*(?!\s))${syntax.replace('$1', '(.*)')}${syntax.endsWith('$1') ? '(?=$|\n)' : ''}(\s*)$`, 'u'),
126
- ]), param = regexes.find(([, key, regex]) => {
127
- mt = regex.exec(str);
128
- return mt
129
- && (mt.length !== 4
130
- || validate(key, mt[2], config, true, extension) !== false);
131
- });
132
- // @ts-expect-error mt already assigned
133
- if (param && mt) {
134
- if (mt.length === 3) {
135
- super(undefined, config, accum);
136
- this.#syntax = str;
137
- }
138
- else {
139
- super(mt[2], config, accum, {
140
- 'Stage-2': ':', '!HeadingToken': ':',
141
- });
142
- this.#syntax = mt[1] + param[0] + mt[3];
143
- }
144
- this.setAttribute('name', param[1]);
145
- return;
146
- }
147
- super(str, { ...config, excludes: [...config.excludes ?? [], 'list'] }, accum);
148
- this.setAttribute('name', 'caption');
149
- this.setAttribute('stage', 7);
150
- /* NOT FOR BROWSER */
151
- this.#extension = extension;
152
- }
153
- /** @private */
154
- afterBuild() {
155
- if (this.parentNode?.type === 'gallery-image' && !exports.galleryParams.has(this.name)) {
156
- this.setAttribute('name', 'invalid');
157
- }
158
- super.afterBuild();
159
- }
160
- /** @private */
161
- toString(skip) {
162
- return this.#syntax ? this.#syntax.replace('$1', super.toString(skip)) : super.toString(skip);
163
- }
164
- /** @private */
165
- text() {
166
- return this.#syntax ? this.#syntax.replace('$1', super.text()).trim() : super.text().trim();
167
- }
168
- /** @private */
169
- getAttribute(key) {
170
- if (key === 'plain') {
171
- return (this.name === 'caption');
172
- }
173
- return key === 'padding'
174
- ? Math.max(0, this.#syntax.indexOf('$1'))
175
- : super.getAttribute(key);
176
- }
177
- /** @private */
178
- lint(start = this.getAbsoluteIndex(), re) {
179
- const errors = super.lint(start, re), { link, name } = this;
180
- if (name === 'invalid') {
181
- const e = (0, lint_1.generateForSelf)(this, { start }, 'invalid-gallery', 'invalid image parameter');
182
- e.fix = { range: [start - 1, e.endIndex], text: '' };
183
- errors.push(e);
184
- }
185
- else if (typeof link === 'object' && link.encoded) {
186
- errors.push((0, lint_1.generateForSelf)(this, { start }, 'url-encoding', 'unnecessary URL encoding in an internal link'));
187
- }
188
- return errors;
189
- }
190
- /** 是否是不可变参数 */
191
- #isVoid() {
192
- return this.#syntax && !this.#syntax.includes('$1');
193
- }
194
- /** 获取参数值 */
195
- getValue() {
196
- return this.name === 'invalid' ? this.text() : this.#isVoid() || super.text();
197
- }
198
- /** @private */
199
- print() {
200
- if (this.#syntax) {
201
- return `<span class="wpb-image-parameter">${this.#syntax.replace('$1', `<span class="wpb-image-caption">${(0, string_1.print)(this.childNodes)}</span>`)}</span>`;
202
- }
203
- return super.print({ class: 'image-caption' });
204
- }
205
- /* NOT FOR BROWSER */
206
- cloneNode() {
207
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config');
208
- return debug_1.Shadow.run(() => {
209
- // @ts-expect-error abstract class
210
- const token = new ImageParameterToken(this.#syntax.replace('$1', ''), this.#extension, config);
211
- token.replaceChildren(...cloned);
212
- return token;
213
- });
214
- }
215
- insertAt(token, i) {
216
- if (!debug_1.Shadow.running && this.#isVoid()) {
217
- throw new Error(`Image parameter ${this.name} does not accept custom input!`);
218
- }
219
- return super.insertAt(token, i);
220
- }
221
- /**
222
- * 设置参数值
223
- * @param value 参数值
224
- * @throws `Error` 无效参数
225
- */
226
- setValue(value = false) {
227
- const { name } = this;
228
- if (value === false) {
229
- this.remove();
230
- return;
231
- }
232
- else if (name === 'invalid') {
233
- throw new Error('Invalid image parameter!');
234
- }
235
- const type = this.#isVoid() ? 'Boolean' : 'String';
236
- if (typeof value !== type.toLowerCase()) { // eslint-disable-line valid-typeof
237
- this.typeError('setValue', type);
238
- }
239
- else if (value !== true) {
240
- const include = this.getAttribute('include'), config = this.getAttribute('config'), { childNodes } = index_1.default.parse(value, include, name === 'caption' ? undefined : 5, config);
241
- this.replaceChildren(...childNodes);
242
- }
243
- }
244
- /** 获取网址 */
245
- getUrl() {
246
- let { link } = this;
247
- if (!link) {
248
- return link;
249
- }
250
- else if (typeof link !== 'string') {
251
- return link.getUrl();
252
- }
253
- else if (link.startsWith('//')) {
254
- link = `https:${link}`;
255
- }
256
- return new URL(link).href;
257
- }
258
- }
259
- exports.ImageParameterToken = ImageParameterToken;
260
- constants_1.classes['ImageParameterToken'] = __filename;
@@ -1,47 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import { NoincludeToken } from './nowiki/noinclude';
4
- import { GalleryImageToken } from './link/galleryImage';
5
- import { ImagemapLinkToken } from './imagemapLink';
6
- import type { LintError } from '../base';
7
- import type { AstText, AttributesToken, ExtToken, AstNodes } from '../internal';
8
- /**
9
- * `<imagemap>`
10
- * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
11
- */
12
- export declare abstract class ImagemapToken extends Token {
13
- readonly name: 'imagemap';
14
- readonly childNodes: readonly (GalleryImageToken | NoincludeToken | ImagemapLinkToken | AstText)[];
15
- abstract get firstChild(): NoincludeToken | GalleryImageToken | undefined;
16
- abstract get lastChild(): GalleryImageToken | NoincludeToken | ImagemapLinkToken | AstText | undefined;
17
- abstract get nextSibling(): undefined;
18
- abstract get previousSibling(): AttributesToken;
19
- abstract get parentNode(): ExtToken | undefined;
20
- abstract get children(): (GalleryImageToken | NoincludeToken | ImagemapLinkToken)[];
21
- abstract get firstElementChild(): NoincludeToken | GalleryImageToken | undefined;
22
- abstract get lastElementChild(): GalleryImageToken | NoincludeToken | ImagemapLinkToken | 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 image(): GalleryImageToken | undefined;
29
- /** @param inner 标签内部wikitext */
30
- constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
31
- /**
32
- * @override
33
- * @param token 待插入的节点
34
- * @param i 插入位置
35
- * @throws `Error` 当前缺少合法图片
36
- * @throws `RangeError` 已有一张合法图片
37
- */
38
- insertAt(token: string, i?: number): AstText;
39
- insertAt<T extends AstNodes>(token: T, i?: number): T;
40
- /**
41
- * @override
42
- * @param i 移除位置
43
- * @throws `Error` 禁止移除图片
44
- */
45
- removeAt(i: number): AstNodes;
46
- cloneNode(): this;
47
- }
@@ -1,146 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ImagemapToken = void 0;
4
- const lint_1 = require("../util/lint");
5
- const rect_1 = require("../lib/rect");
6
- const debug_1 = require("../util/debug");
7
- const constants_1 = require("../util/constants");
8
- const singleLine_1 = require("../mixin/singleLine");
9
- const index_1 = require("../index");
10
- const index_2 = require("./index");
11
- const noinclude_1 = require("./nowiki/noinclude");
12
- const galleryImage_1 = require("./link/galleryImage");
13
- const imagemapLink_1 = require("./imagemapLink");
14
- /**
15
- * `<imagemap>`
16
- * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
17
- */
18
- class ImagemapToken extends index_2.Token {
19
- /* NOT FOR BROWSER END */
20
- get type() {
21
- return 'ext-inner';
22
- }
23
- /** 图片 */
24
- get image() {
25
- return this.childNodes.find((0, debug_1.isToken)('imagemap-image'));
26
- }
27
- /** @param inner 标签内部wikitext */
28
- constructor(inner, config = index_1.default.getConfig(), accum = []) {
29
- super(undefined, config, accum, {
30
- GalleryImageToken: ':', ImagemapLinkToken: ':', NoincludeToken: ':', AstText: ':',
31
- });
32
- if (!inner) {
33
- return;
34
- }
35
- const lines = inner.split('\n'), protocols = new Set(config.protocol.split('|')), SingleLineNoincludeToken = (0, singleLine_1.singleLine)(noinclude_1.NoincludeToken);
36
- let first = true, error = false;
37
- for (const line of lines) {
38
- const trimmed = line.trim();
39
- if (error || !trimmed || trimmed.startsWith('#')) {
40
- //
41
- }
42
- else if (first) {
43
- const [file, ...options] = line.split('|'), title = this.normalizeTitle(file, 0, true);
44
- if (title.valid && !title.interwiki && title.ns === 6) {
45
- // @ts-expect-error abstract class
46
- const token = new galleryImage_1.GalleryImageToken('imagemap', file, options.length > 0 ? options.join('|') : undefined, config, accum);
47
- super.insertAt(token);
48
- first = false;
49
- continue;
50
- }
51
- else {
52
- error = true;
53
- }
54
- }
55
- else if (line.trim().split(/[\t ]/u)[0] === 'desc') {
56
- super.insertAt(line);
57
- continue;
58
- }
59
- else if (line.includes('[')) {
60
- const i = line.indexOf('['), substr = line.slice(i), mtIn = /^\[\[([^|]+)(?:\|([^\]]+))?\]\][\w\s]*$/u
61
- .exec(substr);
62
- if (mtIn) {
63
- if (this.normalizeTitle(mtIn[1], 0, true, false, true).valid) {
64
- // @ts-expect-error abstract class
65
- super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtIn.slice(1), substr.slice(substr.indexOf(']]') + 2), config, accum));
66
- continue;
67
- }
68
- }
69
- else if (protocols.has(substr.slice(1, substr.indexOf(':') + 1))
70
- || protocols.has(substr.slice(1, substr.indexOf('//') + 2))) {
71
- const mtEx = /^\[([^\]\s]+)(?:(\s+(?!\s))([^\]]*))?\][\w\s]*$/u
72
- .exec(substr);
73
- if (mtEx) {
74
- // @ts-expect-error abstract class
75
- super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtEx.slice(1), substr.slice(substr.indexOf(']') + 1), config, accum));
76
- continue;
77
- }
78
- }
79
- }
80
- // @ts-expect-error abstract class
81
- super.insertAt(new SingleLineNoincludeToken(line, config, accum));
82
- }
83
- }
84
- /** @private */
85
- toString(skip) {
86
- return super.toString(skip, '\n');
87
- }
88
- /** @private */
89
- text() {
90
- return super.text('\n').replace(/\n{2,}/gu, '\n');
91
- }
92
- /** @private */
93
- getGaps() {
94
- return 1;
95
- }
96
- /** @private */
97
- lint(start = this.getAbsoluteIndex(), re) {
98
- const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
99
- if (this.image) {
100
- errors.push(...this.childNodes.filter(child => {
101
- const str = child.toString().trim();
102
- return child.type === 'noinclude' && str && !str.startsWith('#');
103
- }).map(child => (0, lint_1.generateForChild)(child, rect, 'invalid-imagemap', 'invalid link in <imagemap>')));
104
- }
105
- else {
106
- errors.push((0, lint_1.generateForSelf)(this, rect, 'invalid-imagemap', '<imagemap> without an image'));
107
- }
108
- return errors;
109
- }
110
- /** @private */
111
- print() {
112
- return super.print({ sep: '\n' });
113
- }
114
- insertAt(token, i) {
115
- const { image } = this;
116
- if (!image && (typeof token === 'string' || token.type === 'imagemap-link' || token.type === 'text')) {
117
- throw new Error('Missing a valid image!');
118
- }
119
- else if (image && typeof token !== 'string' && token.type === 'imagemap-image') {
120
- throw new RangeError('Already have a valid image!');
121
- }
122
- return super.insertAt(token, i);
123
- }
124
- /**
125
- * @override
126
- * @param i 移除位置
127
- * @throws `Error` 禁止移除图片
128
- */
129
- removeAt(i) {
130
- if (this.childNodes[i]?.type === 'imagemap-image') {
131
- throw new Error('Do not remove the image in <imagemap>!');
132
- }
133
- return super.removeAt(i);
134
- }
135
- cloneNode() {
136
- const cloned = this.cloneChildNodes();
137
- return debug_1.Shadow.run(() => {
138
- // @ts-expect-error abstract class
139
- const token = new ImagemapToken(undefined, this.getAttribute('config'));
140
- token.append(...cloned);
141
- return token;
142
- });
143
- }
144
- }
145
- exports.ImagemapToken = ImagemapToken;
146
- constants_1.classes['ImagemapToken'] = __filename;
@@ -1,31 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import { NoincludeToken } from './nowiki/noinclude';
4
- import { LinkToken } from './link/index';
5
- import { ExtLinkToken } from './extLink';
6
- import type { Title } from '../lib/title';
7
- import type { AstText, ImagemapToken } from '../internal';
8
- /**
9
- * `<imagemap>`内的链接
10
- * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
11
- */
12
- export declare abstract class ImagemapLinkToken extends Token {
13
- readonly childNodes: readonly [AstText, LinkToken | ExtLinkToken, NoincludeToken];
14
- abstract get firstChild(): AstText;
15
- abstract get lastChild(): NoincludeToken;
16
- abstract get parentNode(): ImagemapToken | undefined;
17
- abstract get children(): [LinkToken | ExtLinkToken, NoincludeToken];
18
- abstract get firstElementChild(): LinkToken | ExtLinkToken;
19
- abstract get lastElementChild(): NoincludeToken;
20
- abstract get parentElement(): ImagemapToken | undefined;
21
- get type(): 'imagemap-link';
22
- /** 内外链接 */
23
- get link(): string | Title;
24
- set link(link: string);
25
- /**
26
- * @param pre 链接前的文本
27
- * @param linkStuff 内外链接
28
- * @param post 链接后的文本
29
- */
30
- constructor(pre: string, linkStuff: readonly [string, string | undefined, string | undefined] | readonly [string, string | undefined], post: string, config?: Parser.Config, accum?: Token[]);
31
- }
@@ -1,97 +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.ImagemapLinkToken = void 0;
38
- const constants_1 = require("../util/constants");
39
- const fixed_1 = require("../mixin/fixed");
40
- const singleLine_1 = require("../mixin/singleLine");
41
- const index_1 = require("../index");
42
- const index_2 = require("./index");
43
- const noinclude_1 = require("./nowiki/noinclude");
44
- const index_3 = require("./link/index");
45
- const extLink_1 = require("./extLink");
46
- /**
47
- * `<imagemap>`内的链接
48
- * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
49
- */
50
- let ImagemapLinkToken = (() => {
51
- let _classDecorators = [fixed_1.fixedToken, singleLine_1.singleLine];
52
- let _classDescriptor;
53
- let _classExtraInitializers = [];
54
- let _classThis;
55
- let _classSuper = index_2.Token;
56
- var ImagemapLinkToken = class extends _classSuper {
57
- static { _classThis = this; }
58
- static {
59
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
60
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
61
- ImagemapLinkToken = _classThis = _classDescriptor.value;
62
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
63
- __runInitializers(_classThis, _classExtraInitializers);
64
- }
65
- /* NOT FOR BROWSER END */
66
- get type() {
67
- return 'imagemap-link';
68
- }
69
- /* NOT FOR BROWSER */
70
- /** 内外链接 */
71
- get link() {
72
- return this.childNodes[1].link;
73
- }
74
- set link(link) {
75
- this.childNodes[1].link = link;
76
- }
77
- /* NOT FOR BROWSER END */
78
- /**
79
- * @param pre 链接前的文本
80
- * @param linkStuff 内外链接
81
- * @param post 链接后的文本
82
- */
83
- constructor(pre, linkStuff, post, config = index_1.default.getConfig(), accum = []) {
84
- super(undefined, config, accum);
85
- this.append(pre, linkStuff.length === 2
86
- // @ts-expect-error abstract class
87
- ? new index_3.LinkToken(...linkStuff, config, accum)
88
- // @ts-expect-error abstract class
89
- : new extLink_1.ExtLinkToken(...linkStuff, config, accum),
90
- // @ts-expect-error abstract class
91
- new noinclude_1.NoincludeToken(post, config, accum));
92
- }
93
- };
94
- return ImagemapLinkToken = _classThis;
95
- })();
96
- exports.ImagemapLinkToken = ImagemapLinkToken;
97
- constants_1.classes['ImagemapLinkToken'] = __filename;