wikiparser-node 1.11.0-b → 1.11.0

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/config/.schema.json +186 -0
  2. package/config/enwiki.json +814 -1
  3. package/config/llwiki.json +35 -1
  4. package/config/moegirl.json +44 -1
  5. package/config/zhwiki.json +466 -1
  6. package/dist/addon/table.js +486 -0
  7. package/dist/addon/token.js +304 -0
  8. package/dist/addon/transclude.js +184 -0
  9. package/dist/base.d.ts +81 -0
  10. package/dist/base.js +39 -0
  11. package/dist/index.d.ts +33 -0
  12. package/dist/index.js +235 -0
  13. package/dist/internal.d.ts +46 -0
  14. package/dist/lib/element.d.ts +125 -0
  15. package/dist/lib/element.js +375 -0
  16. package/dist/lib/node.d.ts +173 -0
  17. package/dist/lib/node.js +478 -0
  18. package/dist/lib/range.d.ts +105 -0
  19. package/dist/lib/range.js +406 -0
  20. package/dist/lib/ranges.d.ts +28 -0
  21. package/dist/lib/ranges.js +126 -0
  22. package/dist/lib/rect.d.ts +18 -0
  23. package/dist/lib/rect.js +34 -0
  24. package/dist/lib/text.d.ts +58 -0
  25. package/dist/lib/text.js +400 -0
  26. package/dist/lib/title.d.ts +42 -0
  27. package/dist/lib/title.js +208 -0
  28. package/dist/mixin/attributesParent.d.ts +49 -0
  29. package/dist/mixin/attributesParent.js +79 -0
  30. package/dist/mixin/fixed.d.ts +5 -0
  31. package/dist/mixin/fixed.js +32 -0
  32. package/dist/mixin/flagsParent.d.ts +43 -0
  33. package/dist/mixin/flagsParent.js +64 -0
  34. package/dist/mixin/hidden.d.ts +7 -0
  35. package/dist/mixin/hidden.js +37 -0
  36. package/dist/mixin/magicLinkParent.d.ts +19 -0
  37. package/dist/mixin/magicLinkParent.js +43 -0
  38. package/dist/mixin/singleLine.d.ts +5 -0
  39. package/dist/mixin/singleLine.js +25 -0
  40. package/dist/mixin/sol.d.ts +6 -0
  41. package/dist/mixin/sol.js +45 -0
  42. package/dist/mixin/syntax.d.ts +8 -0
  43. package/dist/mixin/syntax.js +46 -0
  44. package/dist/parser/braces.js +150 -0
  45. package/dist/parser/commentAndExt.js +79 -0
  46. package/dist/parser/converter.js +39 -0
  47. package/dist/parser/externalLinks.js +37 -0
  48. package/dist/parser/hrAndDoubleUnderscore.js +42 -0
  49. package/dist/parser/html.js +38 -0
  50. package/dist/parser/links.js +101 -0
  51. package/dist/parser/list.js +114 -0
  52. package/dist/parser/magicLinks.js +52 -0
  53. package/dist/parser/quotes.js +67 -0
  54. package/dist/parser/redirect.js +26 -0
  55. package/dist/parser/selector.js +394 -0
  56. package/dist/parser/table.js +123 -0
  57. package/dist/src/arg.d.ts +51 -0
  58. package/dist/src/arg.js +214 -0
  59. package/dist/src/atom.d.ts +14 -0
  60. package/dist/src/atom.js +52 -0
  61. package/dist/src/attribute.d.ts +64 -0
  62. package/dist/src/attribute.js +480 -0
  63. package/dist/src/attributes.d.ts +101 -0
  64. package/dist/src/attributes.js +381 -0
  65. package/dist/src/converter.d.ts +28 -0
  66. package/dist/src/converter.js +148 -0
  67. package/dist/src/converterFlags.d.ts +80 -0
  68. package/dist/src/converterFlags.js +239 -0
  69. package/dist/src/converterRule.d.ts +71 -0
  70. package/dist/src/converterRule.js +216 -0
  71. package/dist/src/extLink.d.ts +36 -0
  72. package/dist/src/extLink.js +218 -0
  73. package/dist/src/gallery.d.ts +47 -0
  74. package/dist/src/gallery.js +143 -0
  75. package/dist/src/heading.d.ts +40 -0
  76. package/dist/src/heading.js +192 -0
  77. package/dist/src/hidden.d.ts +9 -0
  78. package/dist/src/hidden.js +80 -0
  79. package/dist/src/html.d.ts +61 -0
  80. package/dist/src/html.js +343 -0
  81. package/dist/src/imageParameter.d.ts +60 -0
  82. package/dist/src/imageParameter.js +260 -0
  83. package/dist/src/imagemap.d.ts +47 -0
  84. package/dist/src/imagemap.js +146 -0
  85. package/dist/src/imagemapLink.d.ts +31 -0
  86. package/dist/src/imagemapLink.js +97 -0
  87. package/dist/src/index.d.ts +136 -0
  88. package/dist/src/index.js +834 -0
  89. package/dist/src/link/base.d.ts +52 -0
  90. package/dist/src/link/base.js +256 -0
  91. package/dist/src/link/category.d.ts +22 -0
  92. package/dist/src/link/category.js +34 -0
  93. package/dist/src/link/file.d.ts +102 -0
  94. package/dist/src/link/file.js +333 -0
  95. package/dist/src/link/galleryImage.d.ts +29 -0
  96. package/dist/src/link/galleryImage.js +132 -0
  97. package/dist/src/link/index.d.ts +39 -0
  98. package/dist/src/link/index.js +98 -0
  99. package/dist/src/link/redirectTarget.d.ts +27 -0
  100. package/dist/src/link/redirectTarget.js +69 -0
  101. package/dist/src/magicLink.d.ts +58 -0
  102. package/dist/src/magicLink.js +256 -0
  103. package/dist/src/nested.d.ts +40 -0
  104. package/dist/src/nested.js +106 -0
  105. package/dist/src/nowiki/base.d.ts +28 -0
  106. package/dist/src/nowiki/base.js +89 -0
  107. package/dist/src/nowiki/comment.d.ts +14 -0
  108. package/dist/src/nowiki/comment.js +121 -0
  109. package/dist/src/nowiki/dd.d.ts +8 -0
  110. package/dist/src/nowiki/dd.js +72 -0
  111. package/dist/src/nowiki/doubleUnderscore.d.ts +15 -0
  112. package/dist/src/nowiki/doubleUnderscore.js +97 -0
  113. package/dist/src/nowiki/hr.d.ts +5 -0
  114. package/dist/src/nowiki/hr.js +70 -0
  115. package/dist/src/nowiki/index.d.ts +14 -0
  116. package/dist/src/nowiki/index.js +28 -0
  117. package/dist/src/nowiki/list.d.ts +5 -0
  118. package/dist/src/nowiki/list.js +65 -0
  119. package/dist/src/nowiki/listBase.d.ts +23 -0
  120. package/dist/src/nowiki/listBase.js +99 -0
  121. package/dist/src/nowiki/noinclude.d.ts +6 -0
  122. package/dist/src/nowiki/noinclude.js +75 -0
  123. package/dist/src/nowiki/quote.d.ts +14 -0
  124. package/dist/src/nowiki/quote.js +140 -0
  125. package/dist/src/onlyinclude.d.ts +13 -0
  126. package/dist/src/onlyinclude.js +58 -0
  127. package/dist/src/paramTag/index.d.ts +28 -0
  128. package/dist/src/paramTag/index.js +78 -0
  129. package/dist/src/paramTag/inputbox.d.ts +8 -0
  130. package/dist/src/paramTag/inputbox.js +22 -0
  131. package/dist/src/parameter.d.ts +60 -0
  132. package/dist/src/parameter.js +264 -0
  133. package/dist/src/pre.d.ts +28 -0
  134. package/dist/src/pre.js +60 -0
  135. package/dist/src/redirect.d.ts +30 -0
  136. package/dist/src/redirect.js +126 -0
  137. package/dist/src/syntax.d.ts +17 -0
  138. package/dist/src/syntax.js +87 -0
  139. package/dist/src/table/base.d.ts +28 -0
  140. package/dist/src/table/base.js +81 -0
  141. package/dist/src/table/index.d.ts +230 -0
  142. package/dist/src/table/index.js +506 -0
  143. package/dist/src/table/td.d.ts +72 -0
  144. package/dist/src/table/td.js +370 -0
  145. package/dist/src/table/tr.d.ts +30 -0
  146. package/dist/src/table/tr.js +59 -0
  147. package/dist/src/table/trBase.d.ts +49 -0
  148. package/dist/src/table/trBase.js +164 -0
  149. package/dist/src/tagPair/ext.d.ts +29 -0
  150. package/dist/src/tagPair/ext.js +220 -0
  151. package/dist/src/tagPair/include.d.ts +33 -0
  152. package/dist/src/tagPair/include.js +130 -0
  153. package/dist/src/tagPair/index.d.ts +23 -0
  154. package/dist/src/tagPair/index.js +128 -0
  155. package/dist/src/transclude.d.ts +159 -0
  156. package/dist/src/transclude.js +587 -0
  157. package/dist/util/constants.js +25 -0
  158. package/dist/util/debug.js +95 -0
  159. package/dist/util/diff.js +83 -0
  160. package/dist/util/html.js +143 -0
  161. package/dist/util/lint.js +32 -0
  162. package/dist/util/string.js +87 -0
  163. package/errors/README +3 -0
  164. package/package.json +22 -32
  165. package/printed/README +3 -0
  166. package/bundle/bundle.min.js +0 -38
  167. package/extensions/dist/base.js +0 -64
  168. package/extensions/dist/editor.js +0 -159
  169. package/extensions/dist/highlight.js +0 -56
  170. package/extensions/dist/lint.js +0 -72
  171. package/extensions/editor.css +0 -64
  172. package/extensions/ui.css +0 -144
@@ -0,0 +1,333 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileToken = void 0;
4
+ const string_1 = require("../../util/string");
5
+ const html_1 = require("../../util/html");
6
+ const lint_1 = require("../../util/lint");
7
+ const rect_1 = require("../../lib/rect");
8
+ const title_1 = require("../../lib/title");
9
+ const debug_1 = require("../../util/debug");
10
+ const constants_1 = require("../../util/constants");
11
+ const index_1 = require("../../index");
12
+ const base_1 = require("./base");
13
+ const imageParameter_1 = require("../imageParameter");
14
+ const frame = new Map([
15
+ ['manualthumb', 'Thumb'],
16
+ ['frameless', 'Frameless'],
17
+ ['framed', 'Frame'],
18
+ ['thumbnail', 'Thumb'],
19
+ ]), horizAlign = new Set(['left', 'right', 'center', 'none']), vertAlign = new Set(['baseline', 'sub', 'super', 'top', 'text-top', 'middle', 'bottom', 'text-bottom']);
20
+ /**
21
+ * a more sophisticated string-explode function
22
+ * @param start start syntax of a nested AST node
23
+ * @param end end syntax of a nested AST node
24
+ * @param separator syntax for explosion
25
+ * @param str string to be exploded
26
+ */
27
+ const explode = (start, end, separator, str) => {
28
+ if (str === undefined) {
29
+ return [];
30
+ }
31
+ const regex = new RegExp(`${[start, end, separator].map(string_1.escapeRegExp).join('|')}`, 'gu'), exploded = [];
32
+ let mt = regex.exec(str), depth = 0, lastIndex = 0;
33
+ while (mt) {
34
+ const { 0: match, index } = mt;
35
+ if (match !== separator) {
36
+ depth += match === start ? 1 : -1;
37
+ }
38
+ else if (depth === 0) {
39
+ exploded.push(str.slice(lastIndex, index));
40
+ ({ lastIndex } = regex);
41
+ }
42
+ mt = regex.exec(str);
43
+ }
44
+ exploded.push(str.slice(lastIndex));
45
+ return exploded;
46
+ };
47
+ /**
48
+ * 图片
49
+ * @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
50
+ */
51
+ class FileToken extends base_1.LinkBaseToken {
52
+ /* NOT FOR BROWSER END */
53
+ get type() {
54
+ return 'file';
55
+ }
56
+ /** 扩展名 */
57
+ get extension() {
58
+ return this.getTitle().extension;
59
+ }
60
+ /* NOT FOR BROWSER */
61
+ /** 图片链接 */
62
+ get link() {
63
+ return this.getArg('link')?.link ?? super.link;
64
+ }
65
+ set link(value) {
66
+ this.setValue('link', value);
67
+ }
68
+ /** 图片大小 */
69
+ get size() {
70
+ const fr = this.getFrame();
71
+ return fr === 'framed' || fr instanceof title_1.Title ? undefined : this.getArg('width')?.size;
72
+ }
73
+ set size(size) {
74
+ this.setValue('width', size && size.width + (size.height && 'x') + size.height);
75
+ }
76
+ /** 图片宽度 */
77
+ get width() {
78
+ return this.size?.width;
79
+ }
80
+ set width(width) {
81
+ const arg = this.getArg('width');
82
+ if (arg) {
83
+ arg.width = width;
84
+ }
85
+ else {
86
+ this.setValue('width', width);
87
+ }
88
+ }
89
+ /** 图片高度 */
90
+ get height() {
91
+ return this.size?.height;
92
+ }
93
+ set height(height) {
94
+ const arg = this.getArg('width');
95
+ if (arg) {
96
+ arg.height = height;
97
+ }
98
+ else {
99
+ this.setValue('width', height && `x${height}`);
100
+ }
101
+ }
102
+ /* NOT FOR BROWSER END */
103
+ /**
104
+ * @param link 文件名
105
+ * @param text 图片参数
106
+ * @param delimiter `|`
107
+ */
108
+ constructor(link, text, config = index_1.default.getConfig(), accum = [], delimiter = '|') {
109
+ super(link, undefined, config, accum, delimiter);
110
+ /* NOT FOR BROWSER */
111
+ this.setAttribute('acceptable', { AtomToken: 0, ImageParameterToken: '1:' });
112
+ /* NOT FOR BROWSER END */
113
+ const { extension } = this.getTitle(true);
114
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
115
+ /-\{|\}-|\|/gu;
116
+ this.append(...explode('-{', '}-', '|', text).map(
117
+ // @ts-expect-error abstract class
118
+ (part) => new imageParameter_1.ImageParameterToken(part, extension, config, accum)));
119
+ }
120
+ /** @private */
121
+ lint(start = this.getAbsoluteIndex(), re) {
122
+ const errors = super.lint(start, re), args = this.getAllArgs().filter(({ childNodes }) => {
123
+ const visibleNodes = childNodes.filter(node => node.text().trim());
124
+ return visibleNodes.length !== 1 || visibleNodes[0].type !== 'arg';
125
+ }), keys = [...new Set(args.map(({ name }) => name))], frameKeys = keys.filter(key => frame.has(key)), horizAlignKeys = keys.filter(key => horizAlign.has(key)), vertAlignKeys = keys.filter(key => vertAlign.has(key)), [fr] = frameKeys, unscaled = fr === 'framed' || fr === 'manualthumb', rect = new rect_1.BoundingRect(this, start);
126
+ if (this.closest('ext-link-text') && this.getValue('link')?.trim() !== '') {
127
+ errors.push((0, lint_1.generateForSelf)(this, rect, 'nested-link', 'internal link in an external link'));
128
+ }
129
+ if (unscaled) {
130
+ for (const arg of args.filter(({ name }) => name === 'width')) {
131
+ const e = (0, lint_1.generateForChild)(arg, rect, 'invalid-gallery', 'invalid image parameter');
132
+ e.fix = { range: [e.startIndex - 1, e.endIndex], text: '' };
133
+ errors.push(e);
134
+ }
135
+ }
136
+ if (args.length === keys.length
137
+ && frameKeys.length < 2
138
+ && horizAlignKeys.length < 2
139
+ && vertAlignKeys.length < 2) {
140
+ return errors;
141
+ }
142
+ /**
143
+ * 图片参数到语法错误的映射
144
+ * @param msg 消息键
145
+ * @param p1 替换$1
146
+ */
147
+ const generate = (msg, p1) => (arg) => (0, lint_1.generateForChild)(arg, rect, 'no-duplicate', index_1.default.msg(`${msg} image $1 parameter`, p1));
148
+ for (const key of keys) {
149
+ if (key === 'invalid' || key === 'width' && unscaled) {
150
+ continue;
151
+ }
152
+ let relevantArgs = args.filter(({ name }) => name === key);
153
+ if (key === 'caption') {
154
+ relevantArgs = [...relevantArgs.slice(0, -1).filter(arg => arg.text()), ...relevantArgs.slice(-1)];
155
+ }
156
+ if (relevantArgs.length > 1) {
157
+ errors.push(...relevantArgs.map(generate('duplicated', key)));
158
+ }
159
+ }
160
+ if (frameKeys.length > 1) {
161
+ errors.push(...args.filter(({ name }) => frame.has(name)).map(generate('conflicting', 'frame')));
162
+ }
163
+ if (horizAlignKeys.length > 1) {
164
+ errors.push(...args.filter(({ name }) => horizAlign.has(name)).map(generate('conflicting', 'horizontal-alignment')));
165
+ }
166
+ if (vertAlignKeys.length > 1) {
167
+ errors.push(...args.filter(({ name }) => vertAlign.has(name)).map(generate('conflicting', 'vertical-alignment')));
168
+ }
169
+ return errors;
170
+ }
171
+ /** 获取所有图片参数节点 */
172
+ getAllArgs() {
173
+ return this.childNodes.slice(1);
174
+ }
175
+ /**
176
+ * 获取指定图片参数
177
+ * @param key 参数名
178
+ */
179
+ getArgs(key) {
180
+ return this.getAllArgs().filter(({ name }) => key === name);
181
+ }
182
+ /**
183
+ * 获取生效的指定图片参数
184
+ * @param key 参数名
185
+ */
186
+ getArg(key) {
187
+ const args = this.getArgs(key);
188
+ return args[key === 'manualthumb' ? 0 : args.length - 1];
189
+ }
190
+ /**
191
+ * 获取生效的指定图片参数值
192
+ * @param key 参数名
193
+ */
194
+ getValue(key) {
195
+ return this.getArg(key)?.getValue();
196
+ }
197
+ /* NOT FOR BROWSER */
198
+ /**
199
+ * 获取特定类型的图片属性参数节点
200
+ * @param keys 接受的参数名
201
+ * @param type 类型名
202
+ */
203
+ #getTypedArgs(keys, type) {
204
+ const args = this.getAllArgs().filter(({ name }) => keys.has(name));
205
+ if (args.length > 1) {
206
+ index_1.default.warn(`The image ${this.name} has ${args.length} ${type} parameters. Only the last ${args[0].name} will take effect!`);
207
+ }
208
+ return args;
209
+ }
210
+ /** 获取图片框架属性参数节点 */
211
+ getFrameArgs() {
212
+ return this.#getTypedArgs(frame, 'frame');
213
+ }
214
+ /** 获取图片水平对齐参数节点 */
215
+ getHorizAlignArgs() {
216
+ return this.#getTypedArgs(horizAlign, 'horizontal-align');
217
+ }
218
+ /** 获取图片垂直对齐参数节点 */
219
+ getVertAlignArgs() {
220
+ return this.#getTypedArgs(vertAlign, 'vertical-align');
221
+ }
222
+ /** 获取生效的图片框架属性参数 */
223
+ getFrame() {
224
+ const [arg] = this.getFrameArgs(), val = arg?.name;
225
+ return val === 'manualthumb' ? this.normalizeTitle(arg.getValue(), 6) : val;
226
+ }
227
+ /** 获取生效的图片水平对齐参数 */
228
+ getHorizAlign() {
229
+ return this.getHorizAlignArgs()[0]?.name;
230
+ }
231
+ /** 获取生效的图片垂直对齐参数 */
232
+ getVertAlign() {
233
+ return this.getVertAlignArgs()[0]?.name;
234
+ }
235
+ /**
236
+ * 是否具有指定图片参数
237
+ * @param key 参数名
238
+ */
239
+ hasArg(key) {
240
+ return this.getArgs(key).length > 0;
241
+ }
242
+ /**
243
+ * 移除指定图片参数
244
+ * @param key 参数名
245
+ */
246
+ removeArg(key) {
247
+ for (const token of this.getArgs(key)) {
248
+ this.removeChild(token);
249
+ }
250
+ }
251
+ /** 获取图片参数名 */
252
+ getKeys() {
253
+ return new Set(this.getAllArgs().map(({ name }) => name));
254
+ }
255
+ /**
256
+ * 获取指定的图片参数值
257
+ * @param key 参数名
258
+ */
259
+ getValues(key) {
260
+ return this.getArgs(key).map(token => token.getValue());
261
+ }
262
+ /**
263
+ * 设置图片参数
264
+ * @param key 参数名
265
+ * @param value 参数值
266
+ * @throws `RangeError` 未定义的图片参数
267
+ */
268
+ setValue(key, value = false) {
269
+ if (value === false) {
270
+ this.removeArg(key);
271
+ return;
272
+ }
273
+ const token = this.getArg(key);
274
+ if (token) {
275
+ token.setValue(value);
276
+ return;
277
+ }
278
+ const config = this.getAttribute('config'), syntax = key === 'caption' ? '$1' : Object.entries(config.img).find(([, name]) => name === key)?.[0];
279
+ if (syntax === undefined) {
280
+ throw new RangeError(`Unknown image parameter: ${key}`);
281
+ }
282
+ const free = syntax.includes('$1');
283
+ if (value === true && free) {
284
+ this.typeError('setValue', 'String');
285
+ }
286
+ const parameter = debug_1.Shadow.run(
287
+ // @ts-expect-error abstract class
288
+ () => new imageParameter_1.ImageParameterToken(syntax.replace('$1', ''), this.extension, config));
289
+ if (free) {
290
+ const { childNodes } = index_1.default.parse(value, this.getAttribute('include'), undefined, config);
291
+ parameter.replaceChildren(...childNodes);
292
+ }
293
+ parameter.afterBuild();
294
+ this.insertAt(parameter);
295
+ }
296
+ /**
297
+ * @override
298
+ * @throws `Error` 不适用于图片
299
+ */
300
+ setLinkText() {
301
+ throw new Error('LinkBaseToken.setLinkText method is not applicable to images!');
302
+ }
303
+ /** @private */
304
+ toHtmlInternal() {
305
+ /** @ignore */
306
+ const isInteger = (n) => Boolean(n && /^\d+$/u.test(n));
307
+ const { link, width, height } = this, file = this.getAttribute('title'), fr = this.getFrame(), manual = fr instanceof title_1.Title, visibleCaption = manual || fr === 'thumbnail' || fr === 'framed', caption = this.getArg('caption')?.toHtmlInternal(true) ?? '', titleFromCaption = visibleCaption ? '' : (0, string_1.sanitizeAlt)(caption), hasLink = manual || link !== file, title = titleFromCaption || (hasLink && typeof link !== 'string' ? link.getTitleAttr() : ''), titleAttr = title && ` title="${title}"`, alt = (0, string_1.sanitizeAlt)(this.getArg('alt')?.toHtmlInternal(true)) ?? titleFromCaption, horiz = this.getHorizAlign() ?? '', vert = this.getVertAlign() ?? '', className = `${horiz ? `mw-halign-${horiz}` : vert && `mw-valign-${vert}`}${this.getValue('border') ? ' mw-image-border' : ''} ${(0, string_1.sanitizeAlt)(this.getValue('class')) ?? ''}`.trim(), classAttr = className && ` class="${className}"`, img = `<img${alt && ` alt="${alt}"`} src="${(manual ? fr : file).getUrl()}" class="mw-file-element"${isInteger(width) ? ` width="${width}"` : ''}${isInteger(height) ? ` height="${height}"` : ''}>`;
308
+ let href = '';
309
+ if (link) {
310
+ try {
311
+ href = typeof link === 'string' ? this.getArg('link').getUrl() : link.getUrl();
312
+ if (link === file) {
313
+ const lang = this.getValue('lang'), page = this.getValue('page');
314
+ if (lang) {
315
+ href += `?lang=${lang}`;
316
+ }
317
+ else if (page) {
318
+ href += `?page=${page}`;
319
+ }
320
+ }
321
+ }
322
+ catch { }
323
+ }
324
+ const a = link
325
+ ? `<a${href && ` href="${href}"`}${hasLink ? '' : ` class="mw-file-description"`}${titleAttr}${typeof link === 'string' ? ` rel="nofollow"` : ''}>${img}</a>`
326
+ : `<span${titleAttr}>${img}</span>`;
327
+ return (0, html_1.font)(this, horiz || vert || visibleCaption
328
+ ? `<figure${classAttr} typeof="mw:File${fr ? `/${manual ? 'Thumb' : frame.get(fr)}` : ''}">${a}<figcaption>${caption}</figcaption></figure>`
329
+ : `<span${classAttr}>${a}</span>`);
330
+ }
331
+ }
332
+ exports.FileToken = FileToken;
333
+ constants_1.classes['FileToken'] = __filename;
@@ -0,0 +1,29 @@
1
+ import Parser from '../../index';
2
+ import { Token } from '../index';
3
+ import { FileToken } from './file';
4
+ import type { Title } from '../../lib/title';
5
+ import type { LintError } from '../../base';
6
+ import type { AtomToken, ImageParameterToken } from '../../internal';
7
+ declare type GalleryTypes = 'gallery' | 'imagemap';
8
+ /** 图库图片 */
9
+ export declare abstract class GalleryImageToken extends FileToken {
10
+ get type(): `${GalleryTypes}-image`;
11
+ /** 图片链接 */
12
+ get link(): string | Title;
13
+ set link(value: string);
14
+ /**
15
+ * @param type 图片类型
16
+ * @param link 图片文件名
17
+ * @param text 图片参数
18
+ */
19
+ constructor(type: GalleryTypes, link: string, text?: string, config?: Parser.Config, accum?: Token[]);
20
+ /**
21
+ * @override
22
+ * @param token 待插入的子节点
23
+ * @param i 插入位置
24
+ * @throws `RangeError` 不可插入多余子节点
25
+ * @throws `TypeError` 不可插入文本节点
26
+ */
27
+ insertAt<T extends AtomToken | ImageParameterToken>(child: T, i?: number): T;
28
+ }
29
+ export {};
@@ -0,0 +1,132 @@
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.GalleryImageToken = void 0;
38
+ const lint_1 = require("../../util/lint");
39
+ const constants_1 = require("../../util/constants");
40
+ const singleLine_1 = require("../../mixin/singleLine");
41
+ const index_1 = require("../../index");
42
+ const index_2 = require("../index");
43
+ const file_1 = require("./file");
44
+ const imageParameter_1 = require("../imageParameter");
45
+ /** 图库图片 */
46
+ let GalleryImageToken = (() => {
47
+ let _classDecorators = [singleLine_1.singleLine];
48
+ let _classDescriptor;
49
+ let _classExtraInitializers = [];
50
+ let _classThis;
51
+ let _classSuper = file_1.FileToken;
52
+ var GalleryImageToken = class extends _classSuper {
53
+ static { _classThis = this; }
54
+ static {
55
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
56
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
57
+ GalleryImageToken = _classThis = _classDescriptor.value;
58
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
59
+ __runInitializers(_classThis, _classExtraInitializers);
60
+ }
61
+ /** @private */
62
+ privateType = 'imagemap-image';
63
+ get type() {
64
+ return this.privateType;
65
+ }
66
+ /* NOT FOR BROWSER */
67
+ /** 图片链接 */
68
+ get link() {
69
+ return this.type === 'imagemap-image' ? '' : super.link;
70
+ }
71
+ set link(value) {
72
+ if (this.type !== 'imagemap-image') {
73
+ super.link = value;
74
+ }
75
+ }
76
+ /* NOT FOR BROWSER END */
77
+ /**
78
+ * @param type 图片类型
79
+ * @param link 图片文件名
80
+ * @param text 图片参数
81
+ */
82
+ constructor(type, link, text, config = index_1.default.getConfig(), accum = []) {
83
+ let token;
84
+ if (text !== undefined) {
85
+ const { length } = accum;
86
+ token = new index_2.Token(text, config, accum);
87
+ for (let n = 1; n < constants_1.MAX_STAGE; n++) {
88
+ token.parseOnce();
89
+ }
90
+ accum.splice(length, 1);
91
+ }
92
+ super(link, token?.toString(), config, accum);
93
+ this.setAttribute('bracket', false);
94
+ this.privateType = `${type}-image`;
95
+ this.seal('privateType', true);
96
+ }
97
+ /** @private */
98
+ getTitle() {
99
+ const imagemap = this.type === 'imagemap-image';
100
+ return this.normalizeTitle(this.firstChild.toString(), imagemap ? 0 : 6, true, !imagemap);
101
+ }
102
+ /** @private */
103
+ getAttribute(key) {
104
+ return key === 'padding' ? 0 : super.getAttribute(key);
105
+ }
106
+ /** @private */
107
+ lint(start = this.getAbsoluteIndex(), re) {
108
+ const errors = super.lint(start, re), { ns, interwiki } = this.getAttribute('title');
109
+ if (interwiki || ns !== 6) {
110
+ errors.push((0, lint_1.generateForSelf)(this, { start }, 'invalid-gallery', 'invalid gallery image'));
111
+ }
112
+ return errors;
113
+ }
114
+ /* NOT FOR BROWSER */
115
+ /**
116
+ * @override
117
+ * @param token 待插入的子节点
118
+ * @param i 插入位置
119
+ * @throws `RangeError` 不可插入多余子节点
120
+ * @throws `TypeError` 不可插入文本节点
121
+ */
122
+ insertAt(child, i) {
123
+ if (this.type === 'gallery-image' && child.type === 'image-parameter' && !imageParameter_1.galleryParams.has(child.name)) {
124
+ child.setAttribute('name', 'invalid');
125
+ }
126
+ return super.insertAt(child, i);
127
+ }
128
+ };
129
+ return GalleryImageToken = _classThis;
130
+ })();
131
+ exports.GalleryImageToken = GalleryImageToken;
132
+ constants_1.classes['GalleryImageToken'] = __filename;
@@ -0,0 +1,39 @@
1
+ import { LinkBaseToken } from './base';
2
+ import type { LintError } from '../../base';
3
+ import type { Title } from '../../lib/title';
4
+ import type { Token, AtomToken } from '../../internal';
5
+ /**
6
+ * 内链
7
+ * @classdesc `{childNodes: [AtomToken, ?Token]}`
8
+ */
9
+ export declare abstract class LinkToken extends LinkBaseToken {
10
+ readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token];
11
+ abstract get children(): [AtomToken] | [AtomToken, Token];
12
+ abstract get link(): Title;
13
+ abstract set link(link: string);
14
+ get type(): 'link';
15
+ /** 链接显示文字 */
16
+ get innerText(): string;
17
+ set innerText(text: string);
18
+ /** 是否链接到自身 */
19
+ get selfLink(): boolean;
20
+ set selfLink(selfLink: boolean);
21
+ /**
22
+ * 设置跨语言链接
23
+ * @param lang 语言前缀
24
+ * @param link 页面标题
25
+ * @throws `SyntaxError` 仅有fragment
26
+ */
27
+ setLangLink(lang: string, link: string): void;
28
+ /**
29
+ * 修改为到自身的链接
30
+ * @param fragment fragment
31
+ * @throws `RangeError` 空fragment
32
+ */
33
+ asSelfLink(fragment?: string | undefined): void;
34
+ /**
35
+ * 自动生成管道符后的链接文字
36
+ * @throws `Error` 带有"#"或"%"时不可用
37
+ */
38
+ pipeTrick(): void;
39
+ }
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LinkToken = void 0;
4
+ const lint_1 = require("../../util/lint");
5
+ const constants_1 = require("../../util/constants");
6
+ const string_1 = require("../../util/string");
7
+ const base_1 = require("./base");
8
+ /**
9
+ * 内链
10
+ * @classdesc `{childNodes: [AtomToken, ?Token]}`
11
+ */
12
+ class LinkToken extends base_1.LinkBaseToken {
13
+ /* NOT FOR BROWSER END */
14
+ get type() {
15
+ return 'link';
16
+ }
17
+ /* NOT FOR BROWSER */
18
+ /** 链接显示文字 */
19
+ get innerText() {
20
+ return this.length > 1 ? this.lastChild.text() : (0, string_1.rawurldecode)(this.firstChild.text().replace(/^\s*:?/u, ''));
21
+ }
22
+ set innerText(text) {
23
+ this.setLinkText(text);
24
+ }
25
+ /** 是否链接到自身 */
26
+ get selfLink() {
27
+ const { link: { title, fragment } } = this;
28
+ return !title && Boolean(fragment);
29
+ }
30
+ set selfLink(selfLink) {
31
+ if (selfLink) {
32
+ this.asSelfLink();
33
+ }
34
+ }
35
+ /* NOT FOR BROWSER END */
36
+ /** @private */
37
+ lint(start = this.getAbsoluteIndex(), re) {
38
+ const errors = super.lint(start, re);
39
+ if (this.closest('ext-link-text')) {
40
+ errors.push((0, lint_1.generateForSelf)(this, { start }, 'nested-link', 'internal link in an external link'));
41
+ }
42
+ return errors;
43
+ }
44
+ /* NOT FOR BROWSER */
45
+ /**
46
+ * 设置跨语言链接
47
+ * @param lang 语言前缀
48
+ * @param link 页面标题
49
+ * @throws `SyntaxError` 仅有fragment
50
+ */
51
+ setLangLink(lang, link) {
52
+ link = link.trim();
53
+ if (link.startsWith('#')) {
54
+ throw new SyntaxError('An interlanguage link cannot be fragment only!');
55
+ }
56
+ super.setTarget(lang + (link.startsWith(':') ? '' : ':') + link);
57
+ }
58
+ /**
59
+ * 修改为到自身的链接
60
+ * @param fragment fragment
61
+ * @throws `RangeError` 空fragment
62
+ */
63
+ asSelfLink(fragment = this.fragment) {
64
+ if (!fragment?.trim()) {
65
+ throw new RangeError('LinkToken.asSelfLink method must specify a non-empty fragment!');
66
+ }
67
+ this.setTarget(`#${(0, string_1.encode)(fragment)}`);
68
+ }
69
+ /**
70
+ * 自动生成管道符后的链接文字
71
+ * @throws `Error` 带有"#"或"%"时不可用
72
+ */
73
+ pipeTrick() {
74
+ const linkText = this.firstChild.text();
75
+ if (linkText.includes('#') || linkText.includes('%')) {
76
+ throw new Error('Pipe trick cannot be used with "#" or "%"!');
77
+ }
78
+ const m1 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+?) ?\(.+\)$/u.exec(linkText);
79
+ if (m1) {
80
+ this.setLinkText(m1[1]);
81
+ return;
82
+ }
83
+ const m2 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+?) ?(.+)$/u.exec(linkText);
84
+ if (m2) {
85
+ this.setLinkText(m2[1]);
86
+ return;
87
+ }
88
+ const m3 = /^:?(?:[ \w\x80-\xFF-]+:)?(.+?)(?: ?(?<!\()\(.+\))?(?:(?:, |,|، ).|$)/u
89
+ .exec(linkText);
90
+ if (m3) {
91
+ this.setLinkText(m3[1]);
92
+ return;
93
+ }
94
+ this.setLinkText(linkText);
95
+ }
96
+ }
97
+ exports.LinkToken = LinkToken;
98
+ constants_1.classes['LinkToken'] = __filename;
@@ -0,0 +1,27 @@
1
+ import Parser from '../../index';
2
+ import { LinkBaseToken } from './base';
3
+ import { NoincludeToken } from '../nowiki/noinclude';
4
+ import type { LintError } from '../../base';
5
+ import type { Title } from '../../lib/title';
6
+ import type { Token, AtomToken } from '../../internal';
7
+ /**
8
+ * 重定向目标
9
+ * @classdesc `{childNodes: [AtomToken, ?NoincludeToken]}`
10
+ */
11
+ export declare abstract class RedirectTargetToken extends LinkBaseToken {
12
+ readonly childNodes: readonly [AtomToken] | readonly [AtomToken, NoincludeToken];
13
+ abstract get lastChild(): AtomToken | NoincludeToken;
14
+ abstract get children(): [AtomToken] | [AtomToken, NoincludeToken];
15
+ abstract get lastElementChild(): AtomToken | NoincludeToken;
16
+ abstract get link(): Title;
17
+ abstract set link(link: string);
18
+ get type(): 'redirect-target';
19
+ /** 链接显示文字 */
20
+ get innerText(): string;
21
+ /**
22
+ * @param link 链接标题
23
+ * @param linkText 链接显示文字
24
+ * @param delimiter `|`
25
+ */
26
+ constructor(link: string, linkText?: string, config?: Parser.Config, accum?: Token[]);
27
+ }