wikiparser-node 1.12.4 → 1.12.5
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.
- package/config/minimum.json +6 -1
- package/dist/lib/title.js +1 -1
- package/dist/src/arg.js +16 -15
- package/dist/src/attribute.js +14 -10
- package/dist/src/attributes.js +1 -1
- package/dist/src/gallery.d.ts +4 -0
- package/dist/src/gallery.js +21 -0
- package/dist/src/link/file.js +16 -6
- package/dist/src/tagPair/ext.js +12 -0
- package/dist/src/transclude.js +1 -1
- package/package.json +1 -1
package/config/minimum.json
CHANGED
package/dist/lib/title.js
CHANGED
package/dist/src/arg.js
CHANGED
|
@@ -73,6 +73,22 @@ class ArgToken extends index_2.Token {
|
|
|
73
73
|
getGaps() {
|
|
74
74
|
return 1;
|
|
75
75
|
}
|
|
76
|
+
/** 设置name */
|
|
77
|
+
#setName() {
|
|
78
|
+
this.setAttribute('name', this.firstChild.toString(true).trim());
|
|
79
|
+
}
|
|
80
|
+
/** @private */
|
|
81
|
+
afterBuild() {
|
|
82
|
+
this.#setName();
|
|
83
|
+
super.afterBuild();
|
|
84
|
+
/* NOT FOR BROWSER */
|
|
85
|
+
const /** @implements */ argListener = ({ prevTarget }) => {
|
|
86
|
+
if (prevTarget === this.firstChild) {
|
|
87
|
+
this.#setName();
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
this.addEventListener(['remove', 'insert', 'replace', 'text'], argListener);
|
|
91
|
+
}
|
|
76
92
|
/** @private */
|
|
77
93
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
78
94
|
const { childNodes: [argName, argDefault, ...rest] } = this;
|
|
@@ -125,21 +141,6 @@ class ArgToken extends index_2.Token {
|
|
|
125
141
|
return token;
|
|
126
142
|
});
|
|
127
143
|
}
|
|
128
|
-
/** 设置name */
|
|
129
|
-
#setName() {
|
|
130
|
-
this.setAttribute('name', this.firstChild.toString(true).trim());
|
|
131
|
-
}
|
|
132
|
-
/** @private */
|
|
133
|
-
afterBuild() {
|
|
134
|
-
this.#setName();
|
|
135
|
-
super.afterBuild();
|
|
136
|
-
const /** @implements */ argListener = ({ prevTarget }) => {
|
|
137
|
-
if (prevTarget === this.firstChild) {
|
|
138
|
-
this.#setName();
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
this.addEventListener(['remove', 'insert', 'replace', 'text'], argListener);
|
|
142
|
-
}
|
|
143
144
|
/** 移除无效部分 */
|
|
144
145
|
removeRedundant() {
|
|
145
146
|
debug_1.Shadow.run(() => {
|
package/dist/src/attribute.js
CHANGED
|
@@ -102,10 +102,14 @@ const commonHtmlAttrs = new Set([
|
|
|
102
102
|
time: new Set(['datetime']),
|
|
103
103
|
meta: new Set(['itemprop', 'content']),
|
|
104
104
|
link: new Set(['itemprop', 'href', 'title']),
|
|
105
|
-
gallery:
|
|
106
|
-
poem:
|
|
105
|
+
gallery: typeAttrs,
|
|
106
|
+
poem: blockAttrs,
|
|
107
|
+
categorytree: blockAttrs,
|
|
108
|
+
combooption: blockAttrs,
|
|
109
|
+
}, empty = new Set(), extAttrs = {
|
|
110
|
+
gallery: new Set(['mode', 'showfilename', 'caption', 'perrow', 'widths', 'heights', 'showthumbnails']),
|
|
111
|
+
poem: new Set(['compact']),
|
|
107
112
|
categorytree: new Set([
|
|
108
|
-
'align',
|
|
109
113
|
'hideroot',
|
|
110
114
|
'onlyroot',
|
|
111
115
|
'depth',
|
|
@@ -115,8 +119,7 @@ const commonHtmlAttrs = new Set([
|
|
|
115
119
|
'showcount',
|
|
116
120
|
'notranslations',
|
|
117
121
|
]),
|
|
118
|
-
combooption: new Set(['name', 'for', 'inline'
|
|
119
|
-
}, empty = new Set(), extAttrs = {
|
|
122
|
+
combooption: new Set(['name', 'for', 'inline']),
|
|
120
123
|
nowiki: empty,
|
|
121
124
|
indicator: new Set(['name']),
|
|
122
125
|
langconvert: new Set(['from', 'to']),
|
|
@@ -349,11 +352,12 @@ let AttributeToken = (() => {
|
|
|
349
352
|
errors.push(e);
|
|
350
353
|
}
|
|
351
354
|
const attrs = extAttrs[tag];
|
|
352
|
-
if (attrs &&
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
355
|
+
if (!(attrs && attrs.has(name))
|
|
356
|
+
&& (type === 'ext-attr' || !/\{\{[^{]+\}\}/u.test(name))
|
|
357
|
+
&& (type === 'ext-attr' && !(tag in htmlAttrs)
|
|
358
|
+
|| !htmlAttrs[tag]?.has(name)
|
|
359
|
+
&& !/^(?:xmlns:[\w:.-]+|data-(?!ooui|mw|parsoid)[^:]*)$/u.test(name)
|
|
360
|
+
&& (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name)))) {
|
|
357
361
|
errors.push((0, lint_1.generateForChild)(firstChild, rect, 'illegal-attr', 'illegal attribute name'));
|
|
358
362
|
}
|
|
359
363
|
else if (obsoleteAttrs[tag]?.has(name)) {
|
package/dist/src/attributes.js
CHANGED
|
@@ -117,7 +117,7 @@ class AttributesToken extends index_2.Token {
|
|
|
117
117
|
while (mt) {
|
|
118
118
|
const { index, 0: full, 1: key, 2: equal, 3: quoteStart, 4: quoted, 5: quoteEnd, 6: unquoted } = mt;
|
|
119
119
|
out += attr.slice(lastIndex, index);
|
|
120
|
-
if (/^(?:[\w:]|\0\d+
|
|
120
|
+
if (/^(?:[\w:]|\0\d+t\x7F)(?:[\w:.-]|\0\d+t\x7F)*$/u.test((0, string_1.removeComment)(key).trim())) {
|
|
121
121
|
const value = quoted ?? unquoted, quotes = [quoteStart, quoteEnd],
|
|
122
122
|
// @ts-expect-error abstract class
|
|
123
123
|
token = new attribute_1.AttributeToken(toAttributeType(type), name, key, equal, value, quotes, config, accum);
|
package/dist/src/gallery.d.ts
CHANGED
|
@@ -24,6 +24,10 @@ export declare abstract class GalleryToken extends Token {
|
|
|
24
24
|
abstract get previousElementSibling(): AttributesToken;
|
|
25
25
|
abstract get parentElement(): ExtToken | undefined;
|
|
26
26
|
get type(): 'ext-inner';
|
|
27
|
+
/** 图片宽度 */
|
|
28
|
+
get widths(): number;
|
|
29
|
+
/** 图片高度 */
|
|
30
|
+
get heights(): number;
|
|
27
31
|
/** 所有图片 */
|
|
28
32
|
get images(): GalleryImageToken[];
|
|
29
33
|
/** @param inner 标签内部wikitext */
|
package/dist/src/gallery.js
CHANGED
|
@@ -8,6 +8,7 @@ const noinclude_1 = require("./nowiki/noinclude");
|
|
|
8
8
|
/* NOT FOR BROWSER */
|
|
9
9
|
const debug_1 = require("../util/debug");
|
|
10
10
|
const constants_1 = require("../util/constants");
|
|
11
|
+
const html_1 = require("../util/html");
|
|
11
12
|
/* NOT FOR BROWSER END */
|
|
12
13
|
/**
|
|
13
14
|
* gallery标签
|
|
@@ -19,6 +20,14 @@ class GalleryToken extends index_2.Token {
|
|
|
19
20
|
return 'ext-inner';
|
|
20
21
|
}
|
|
21
22
|
/* NOT FOR BROWSER */
|
|
23
|
+
/** 图片宽度 */
|
|
24
|
+
get widths() {
|
|
25
|
+
return this.#getSize('widths');
|
|
26
|
+
}
|
|
27
|
+
/** 图片高度 */
|
|
28
|
+
get heights() {
|
|
29
|
+
return this.#getSize('heights');
|
|
30
|
+
}
|
|
22
31
|
/** 所有图片 */
|
|
23
32
|
get images() {
|
|
24
33
|
return this.childNodes.filter((0, debug_1.isToken)('gallery-image'));
|
|
@@ -140,6 +149,18 @@ class GalleryToken extends index_2.Token {
|
|
|
140
149
|
}
|
|
141
150
|
return super.insertAt(token, i);
|
|
142
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* 获取图片的宽度或高度
|
|
154
|
+
* @param key `widths` 或 `heights`
|
|
155
|
+
*/
|
|
156
|
+
#getSize(key) {
|
|
157
|
+
const widths = this.parentNode?.getAttr(key), mt = typeof widths === 'string' && /^(\d+)\s*(?:px)?$/u.exec(widths)?.[1];
|
|
158
|
+
return mt && Number(mt) || 120;
|
|
159
|
+
}
|
|
160
|
+
/** @private */
|
|
161
|
+
toHtmlInternal() {
|
|
162
|
+
return (0, html_1.html)(this.childNodes.filter((0, debug_1.isToken)('gallery-image')), '\n');
|
|
163
|
+
}
|
|
143
164
|
}
|
|
144
165
|
exports.GalleryToken = GalleryToken;
|
|
145
166
|
constants_1.classes['GalleryToken'] = __filename;
|
package/dist/src/link/file.js
CHANGED
|
@@ -77,7 +77,9 @@ class FileToken extends base_1.LinkBaseToken {
|
|
|
77
77
|
}
|
|
78
78
|
/** 图片宽度 */
|
|
79
79
|
get width() {
|
|
80
|
-
return this.
|
|
80
|
+
return this.type === 'gallery-image'
|
|
81
|
+
? this.parentNode?.widths.toString()
|
|
82
|
+
: this.size?.width;
|
|
81
83
|
}
|
|
82
84
|
set width(width) {
|
|
83
85
|
const arg = this.getArg('width');
|
|
@@ -90,7 +92,9 @@ class FileToken extends base_1.LinkBaseToken {
|
|
|
90
92
|
}
|
|
91
93
|
/** 图片高度 */
|
|
92
94
|
get height() {
|
|
93
|
-
return this.
|
|
95
|
+
return this.type === 'gallery-image'
|
|
96
|
+
? this.parentNode?.heights.toString()
|
|
97
|
+
: this.size?.height;
|
|
94
98
|
}
|
|
95
99
|
set height(height) {
|
|
96
100
|
const arg = this.getArg('width');
|
|
@@ -306,7 +310,7 @@ class FileToken extends base_1.LinkBaseToken {
|
|
|
306
310
|
toHtmlInternal(_, nocc) {
|
|
307
311
|
/** @ignore */
|
|
308
312
|
const isInteger = (n) => Boolean(n && /^\d+$/u.test(n));
|
|
309
|
-
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, nocc) ?? '', 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}"` : ''}>`;
|
|
313
|
+
const { link, width, height, type } = this, file = this.getAttribute('title'), fr = this.getFrame(), manual = fr instanceof title_1.Title, visibleCaption = manual || fr === 'thumbnail' || fr === 'framed' || type === 'gallery-image', caption = this.getArg('caption')?.toHtmlInternal(true, nocc) ?? '', titleFromCaption = visibleCaption && type !== 'gallery-image' ? '' : (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}"` : ''}>`;
|
|
310
314
|
let href = '';
|
|
311
315
|
if (link) {
|
|
312
316
|
try {
|
|
@@ -326,9 +330,15 @@ class FileToken extends base_1.LinkBaseToken {
|
|
|
326
330
|
const a = link
|
|
327
331
|
? `<a${href && ` href="${href}"`}${hasLink ? '' : ` class="mw-file-description"`}${titleAttr}${typeof link === 'string' ? ` rel="nofollow"` : ''}>${img}</a>`
|
|
328
332
|
: `<span${titleAttr}>${img}</span>`;
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
333
|
+
if (type !== 'gallery-image') {
|
|
334
|
+
return (0, html_1.font)(this, horiz || vert || visibleCaption
|
|
335
|
+
? `<figure${classAttr} typeof="mw:File${fr ? `/${manual ? 'Thumb' : frame.get(fr)}` : ''}">${a}<figcaption>${caption}</figcaption></figure>`
|
|
336
|
+
: `<span${classAttr}>${a}</span>`);
|
|
337
|
+
}
|
|
338
|
+
const parent = this.parentNode, mode = parent?.parentNode?.getAttr('mode'), nolines = typeof mode === 'string' && mode.toLowerCase() === 'nolines', padding = nolines ? 0 : 30, showfilename = parent?.parentNode?.getAttr('showfilename') !== undefined;
|
|
339
|
+
return `\t<li class="gallerybox" style="width: ${Number(width) + padding + 5}px">\n\t\t<div class="thumb" style="width: ${Number(width) + padding}px${nolines ? '' : `; height: ${Number(height) + padding}px`}"><span>${a}</span></div>\n\t\t<div class="gallerytext">${showfilename
|
|
340
|
+
? `<a href="${file.getUrl()}" class="galleryfilename galleryfilename-truncate" title="${file.title}">${file.main}</a>\n`
|
|
341
|
+
: ''}${caption}</div>\n\t</li>`;
|
|
332
342
|
}
|
|
333
343
|
}
|
|
334
344
|
exports.FileToken = FileToken;
|
package/dist/src/tagPair/ext.js
CHANGED
|
@@ -206,6 +206,18 @@ let ExtToken = (() => {
|
|
|
206
206
|
firstChild.classList.add('poem');
|
|
207
207
|
return (0, html_1.font)(this, `<div${firstChild.toHtmlInternal()}>${lastChild.toHtmlInternal(false, nocc).replace(/(?<!^|<hr>)\n(?!$)/gu, '<br>\n')
|
|
208
208
|
.replace(/^ +/gmu, p => ' '.repeat(p.length))}</div>`);
|
|
209
|
+
case 'gallery': {
|
|
210
|
+
const caption = firstChild.getAttrToken('caption'), perrow = parseInt(String(firstChild.getAttr('perrow'))), mode = firstChild.getAttr('mode'), nolines = typeof mode === 'string' && mode.toLowerCase() === 'nolines', padding = nolines ? 9 : 43;
|
|
211
|
+
firstChild.classList.add('gallery');
|
|
212
|
+
if (nolines) {
|
|
213
|
+
firstChild.classList.add('mw-gallery-nolines');
|
|
214
|
+
}
|
|
215
|
+
if (perrow > 0) {
|
|
216
|
+
const style = firstChild.getAttr('style');
|
|
217
|
+
firstChild.setAttr('style', `max-width: ${(lastChild.widths + padding) * perrow}px;${typeof style === 'string' ? style : ''}`);
|
|
218
|
+
}
|
|
219
|
+
return (0, html_1.font)(this, `<ul${firstChild.toHtmlInternal()}>\n${caption ? `\t<li class="gallerycaption">${caption.lastChild.toHtmlInternal(true)}</li>\n` : ''}${lastChild.toHtmlInternal()}\n</ul>`);
|
|
220
|
+
}
|
|
209
221
|
default:
|
|
210
222
|
return '';
|
|
211
223
|
}
|
package/dist/src/transclude.js
CHANGED
|
@@ -164,12 +164,12 @@ class TranscludeToken extends index_2.Token {
|
|
|
164
164
|
this.setAttribute('modifier', this.buildFromStr(this.modifier, constants_1.BuildMethod.String));
|
|
165
165
|
}
|
|
166
166
|
super.afterBuild();
|
|
167
|
-
/* NOT FOR BROWSER */
|
|
168
167
|
if (this.isTemplate()) {
|
|
169
168
|
const isTemplate = this.type === 'template';
|
|
170
169
|
if (isTemplate) {
|
|
171
170
|
this.setAttribute('name', this.#getTitle().title);
|
|
172
171
|
}
|
|
172
|
+
/* NOT FOR BROWSER */
|
|
173
173
|
/**
|
|
174
174
|
* 当事件bubble到`parameter`时,将`oldKey`和`newKey`保存进AstEventData。
|
|
175
175
|
* 当继续bubble到`template`时,处理并删除`oldKey`和`newKey`。
|