wikiparser-node 0.11.0 → 1.0.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.
- package/README.md +10 -9
- package/bundle/bundle.min.js +37 -0
- package/config/llwiki.json +1 -35
- package/config/minimum.json +136 -0
- package/config/moegirl.json +1 -44
- package/config/zhwiki.json +1 -466
- package/extensions/dist/base.js +105 -0
- package/extensions/dist/editor.js +172 -0
- package/extensions/dist/highlight.js +46 -0
- package/extensions/dist/lint.js +43 -0
- package/extensions/editor.css +63 -0
- package/extensions/ui.css +119 -0
- package/i18n/zh-hans.json +1 -0
- package/i18n/zh-hant.json +1 -0
- package/package.json +38 -31
- package/config/.schema.json +0 -134
- package/dist/index.d.ts +0 -114
- package/dist/lib/element.d.ts +0 -162
- package/dist/lib/node.d.ts +0 -291
- package/dist/lib/ranges.d.ts +0 -37
- package/dist/lib/text.d.ts +0 -64
- package/dist/lib/title.d.ts +0 -21
- package/dist/mixin/attributeParent.d.ts +0 -9
- package/dist/mixin/fixedToken.d.ts +0 -8
- package/dist/mixin/hidden.d.ts +0 -8
- package/dist/mixin/singleLine.d.ts +0 -8
- package/dist/mixin/sol.d.ts +0 -8
- package/dist/parser/brackets.d.ts +0 -12
- package/dist/parser/commentAndExt.d.ts +0 -8
- package/dist/parser/converter.d.ts +0 -7
- package/dist/parser/externalLinks.d.ts +0 -7
- package/dist/parser/hrAndDoubleUnderscore.d.ts +0 -11
- package/dist/parser/html.d.ts +0 -7
- package/dist/parser/links.d.ts +0 -7
- package/dist/parser/list.d.ts +0 -7
- package/dist/parser/magicLinks.d.ts +0 -7
- package/dist/parser/quotes.d.ts +0 -7
- package/dist/parser/selector.d.ts +0 -12
- package/dist/parser/table.d.ts +0 -11
- package/dist/src/arg.d.ts +0 -54
- package/dist/src/atom/hidden.d.ts +0 -5
- package/dist/src/atom/index.d.ts +0 -15
- package/dist/src/attribute.d.ts +0 -65
- package/dist/src/attributes.d.ts +0 -112
- package/dist/src/charinsert.d.ts +0 -32
- package/dist/src/converter.d.ts +0 -103
- package/dist/src/converterFlags.d.ts +0 -83
- package/dist/src/converterRule.d.ts +0 -75
- package/dist/src/extLink.d.ts +0 -62
- package/dist/src/gallery.d.ts +0 -33
- package/dist/src/hasNowiki/index.d.ts +0 -14
- package/dist/src/hasNowiki/pre.d.ts +0 -13
- package/dist/src/heading.d.ts +0 -44
- package/dist/src/html.d.ts +0 -56
- package/dist/src/imageParameter.d.ts +0 -65
- package/dist/src/imagemap.d.ts +0 -37
- package/dist/src/imagemapLink.d.ts +0 -21
- package/dist/src/index.d.ts +0 -186
- package/dist/src/link/category.d.ts +0 -16
- package/dist/src/link/file.d.ts +0 -85
- package/dist/src/link/galleryImage.d.ts +0 -15
- package/dist/src/link/index.d.ts +0 -88
- package/dist/src/magicLink.d.ts +0 -36
- package/dist/src/nested/choose.d.ts +0 -13
- package/dist/src/nested/combobox.d.ts +0 -13
- package/dist/src/nested/index.d.ts +0 -18
- package/dist/src/nested/references.d.ts +0 -13
- package/dist/src/nowiki/comment.d.ts +0 -31
- package/dist/src/nowiki/dd.d.ts +0 -17
- package/dist/src/nowiki/doubleUnderscore.d.ts +0 -22
- package/dist/src/nowiki/hr.d.ts +0 -13
- package/dist/src/nowiki/index.d.ts +0 -27
- package/dist/src/nowiki/list.d.ts +0 -8
- package/dist/src/nowiki/noinclude.d.ts +0 -8
- package/dist/src/nowiki/quote.d.ts +0 -13
- package/dist/src/onlyinclude.d.ts +0 -24
- package/dist/src/paramTag/index.d.ts +0 -29
- package/dist/src/paramTag/inputbox.d.ts +0 -8
- package/dist/src/parameter.d.ts +0 -75
- package/dist/src/syntax.d.ts +0 -20
- package/dist/src/table/index.d.ts +0 -273
- package/dist/src/table/td.d.ts +0 -100
- package/dist/src/table/tr.d.ts +0 -91
- package/dist/src/tagPair/ext.d.ts +0 -18
- package/dist/src/tagPair/include.d.ts +0 -25
- package/dist/src/tagPair/index.d.ts +0 -41
- package/dist/src/transclude.d.ts +0 -199
- package/dist/tool/index.d.ts +0 -420
- package/dist/util/base.d.ts +0 -10
- package/dist/util/debug.d.ts +0 -20
- package/dist/util/diff.d.ts +0 -8
- package/dist/util/lint.d.ts +0 -28
- package/dist/util/string.d.ts +0 -55
- package/index.js +0 -333
- package/lib/element.js +0 -618
- package/lib/node.js +0 -730
- package/lib/ranges.js +0 -130
- package/lib/text.js +0 -265
- package/lib/title.js +0 -83
- package/mixin/attributeParent.js +0 -117
- package/mixin/fixedToken.js +0 -40
- package/mixin/hidden.js +0 -21
- package/mixin/singleLine.js +0 -31
- package/mixin/sol.js +0 -54
- package/parser/brackets.js +0 -128
- package/parser/commentAndExt.js +0 -62
- package/parser/converter.js +0 -46
- package/parser/externalLinks.js +0 -33
- package/parser/hrAndDoubleUnderscore.js +0 -49
- package/parser/html.js +0 -42
- package/parser/links.js +0 -94
- package/parser/list.js +0 -59
- package/parser/magicLinks.js +0 -41
- package/parser/quotes.js +0 -64
- package/parser/selector.js +0 -180
- package/parser/table.js +0 -114
- package/src/arg.js +0 -207
- package/src/atom/hidden.js +0 -13
- package/src/atom/index.js +0 -43
- package/src/attribute.js +0 -472
- package/src/attributes.js +0 -453
- package/src/charinsert.js +0 -97
- package/src/converter.js +0 -176
- package/src/converterFlags.js +0 -284
- package/src/converterRule.js +0 -256
- package/src/extLink.js +0 -180
- package/src/gallery.js +0 -149
- package/src/hasNowiki/index.js +0 -44
- package/src/hasNowiki/pre.js +0 -40
- package/src/heading.js +0 -134
- package/src/html.js +0 -254
- package/src/imageParameter.js +0 -303
- package/src/imagemap.js +0 -199
- package/src/imagemapLink.js +0 -41
- package/src/index.js +0 -938
- package/src/link/category.js +0 -44
- package/src/link/file.js +0 -287
- package/src/link/galleryImage.js +0 -120
- package/src/link/index.js +0 -388
- package/src/magicLink.js +0 -151
- package/src/nested/choose.js +0 -24
- package/src/nested/combobox.js +0 -23
- package/src/nested/index.js +0 -96
- package/src/nested/references.js +0 -23
- package/src/nowiki/comment.js +0 -71
- package/src/nowiki/dd.js +0 -59
- package/src/nowiki/doubleUnderscore.js +0 -56
- package/src/nowiki/hr.js +0 -41
- package/src/nowiki/index.js +0 -56
- package/src/nowiki/list.js +0 -16
- package/src/nowiki/noinclude.js +0 -28
- package/src/nowiki/quote.js +0 -69
- package/src/onlyinclude.js +0 -64
- package/src/paramTag/index.js +0 -89
- package/src/paramTag/inputbox.js +0 -35
- package/src/parameter.js +0 -239
- package/src/syntax.js +0 -91
- package/src/table/index.js +0 -985
- package/src/table/td.js +0 -343
- package/src/table/tr.js +0 -319
- package/src/tagPair/ext.js +0 -146
- package/src/tagPair/include.js +0 -50
- package/src/tagPair/index.js +0 -131
- package/src/transclude.js +0 -843
- package/tool/index.js +0 -1209
- package/typings/api.d.ts +0 -9
- package/typings/array.d.ts +0 -29
- package/typings/event.d.ts +0 -22
- package/typings/index.d.ts +0 -118
- package/typings/node.d.ts +0 -35
- package/typings/parser.d.ts +0 -12
- package/typings/table.d.ts +0 -10
- package/typings/token.d.ts +0 -31
- package/typings/tool.d.ts +0 -6
- package/util/base.js +0 -17
- package/util/debug.js +0 -73
- package/util/diff.js +0 -76
- package/util/lint.js +0 -57
- package/util/string.js +0 -126
package/src/link/category.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {decodeHtml} = require('../../util/string'),
|
|
4
|
-
Parser = require('../..'),
|
|
5
|
-
LinkToken = require('.');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 分类
|
|
9
|
-
* @classdesc `{childNodes: [AtomToken, ?Token]}`
|
|
10
|
-
*/
|
|
11
|
-
class CategoryToken extends LinkToken {
|
|
12
|
-
type = 'category';
|
|
13
|
-
|
|
14
|
-
/** 分类排序关键字 */
|
|
15
|
-
get sortkey() {
|
|
16
|
-
return decodeHtml(this.childNodes[1]?.text());
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
set sortkey(text) {
|
|
20
|
-
this.setSortkey(text);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @param {string} link 分类名
|
|
25
|
-
* @param {string|undefined} text 排序关键字
|
|
26
|
-
* @param {import('../../typings/token').accum} accum
|
|
27
|
-
* @param {string} delimiter `|`
|
|
28
|
-
*/
|
|
29
|
-
constructor(link, text, config = Parser.getConfig(), accum = [], delimiter = '|') {
|
|
30
|
-
super(link, text, config, accum, delimiter);
|
|
31
|
-
this.seal(['selfLink', 'interwiki', 'setLangLink', 'setFragment', 'asSelfLink', 'pipeTrick'], true);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 设置排序关键字
|
|
36
|
-
* @param {string} text 排序关键字
|
|
37
|
-
*/
|
|
38
|
-
setSortkey(text) {
|
|
39
|
-
this.setLinkText(text);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
Parser.classes.CategoryToken = __filename;
|
|
44
|
-
module.exports = CategoryToken;
|
package/src/link/file.js
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {explode, noWrap} = require('../../util/string'),
|
|
4
|
-
{generateForChild} = require('../../util/lint'),
|
|
5
|
-
Parser = require('../..'),
|
|
6
|
-
LinkToken = require('.'),
|
|
7
|
-
ImageParameterToken = require('../imageParameter');
|
|
8
|
-
|
|
9
|
-
const frame = new Set(['manualthumb', 'frameless', 'framed', 'thumbnail']),
|
|
10
|
-
horizAlign = new Set(['left', 'right', 'center', 'none']),
|
|
11
|
-
vertAlign = new Set(['baseline', 'sub', 'super', 'top', 'text-top', 'middle', 'bottom', 'text-bottom']);
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 图片
|
|
15
|
-
* @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
|
|
16
|
-
*/
|
|
17
|
-
class FileToken extends LinkToken {
|
|
18
|
-
type = 'file';
|
|
19
|
-
|
|
20
|
-
/** 图片链接 */
|
|
21
|
-
get link() {
|
|
22
|
-
return this.getArg('link')?.link;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
set link(value) {
|
|
26
|
-
this.setValue('link', value);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** 图片大小 */
|
|
30
|
-
get size() {
|
|
31
|
-
return this.getArg('width')?.size;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** 图片宽度 */
|
|
35
|
-
get width() {
|
|
36
|
-
return this.size?.width;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
set width(width) {
|
|
40
|
-
const arg = this.getArg('width');
|
|
41
|
-
if (arg) {
|
|
42
|
-
arg.width = width;
|
|
43
|
-
} else {
|
|
44
|
-
this.setValue('width', width);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** 图片高度 */
|
|
49
|
-
get height() {
|
|
50
|
-
return this.size?.height;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
set height(height) {
|
|
54
|
-
const arg = this.getArg('width');
|
|
55
|
-
if (arg) {
|
|
56
|
-
arg.height = height;
|
|
57
|
-
} else {
|
|
58
|
-
this.setValue('width', `x${height}`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @param {string} link 文件名
|
|
64
|
-
* @param {string|undefined} text 图片参数
|
|
65
|
-
* @param {import('../../typings/token').accum} accum
|
|
66
|
-
* @param {string} delimiter `|`
|
|
67
|
-
* @complexity `n`
|
|
68
|
-
*/
|
|
69
|
-
constructor(link, text, config = Parser.getConfig(), accum = [], delimiter = '|') {
|
|
70
|
-
super(link, undefined, config, accum, delimiter);
|
|
71
|
-
this.setAttribute('acceptable', {AtomToken: 0, ImageParameterToken: '1:'});
|
|
72
|
-
this.append(...explode('-{', '}-', '|', text).map(part => new ImageParameterToken(part, config, accum)));
|
|
73
|
-
this.seal(
|
|
74
|
-
['selfLink', 'interwiki', 'setLangLink', 'setFragment', 'asSelfLink', 'setLinkText', 'pipeTrick'],
|
|
75
|
-
true,
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @override
|
|
81
|
-
* @param {number} start 起始位置
|
|
82
|
-
*/
|
|
83
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
84
|
-
const errors = super.lint(start),
|
|
85
|
-
args = this.getAllArgs().filter(({childNodes}) => {
|
|
86
|
-
const visibleNodes = childNodes.filter(node => node.text().trim());
|
|
87
|
-
return visibleNodes.length !== 1 || visibleNodes[0].type !== 'arg';
|
|
88
|
-
}),
|
|
89
|
-
keys = [...new Set(args.map(({name}) => name))].filter(key => key !== 'invalid'),
|
|
90
|
-
frameKeys = keys.filter(key => frame.has(key)),
|
|
91
|
-
horizAlignKeys = keys.filter(key => horizAlign.has(key)),
|
|
92
|
-
vertAlignKeys = keys.filter(key => vertAlign.has(key));
|
|
93
|
-
if (args.length === keys.length
|
|
94
|
-
&& frameKeys.length < 2 && horizAlignKeys.length < 2 && vertAlignKeys.length < 2
|
|
95
|
-
) {
|
|
96
|
-
return errors;
|
|
97
|
-
}
|
|
98
|
-
const rect = {start, ...this.getRootNode().posFromIndex(start)};
|
|
99
|
-
for (const key of keys) {
|
|
100
|
-
let relevantArgs = args.filter(({name}) => name === key);
|
|
101
|
-
if (key === 'caption') {
|
|
102
|
-
relevantArgs = [
|
|
103
|
-
...relevantArgs.slice(0, -1).filter(arg => arg.text()),
|
|
104
|
-
relevantArgs.at(-1),
|
|
105
|
-
];
|
|
106
|
-
}
|
|
107
|
-
if (relevantArgs.length > 1) {
|
|
108
|
-
errors.push(...relevantArgs.map(
|
|
109
|
-
arg => generateForChild(arg, rect, Parser.msg('duplicated image $1 parameter', key)),
|
|
110
|
-
));
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (frameKeys.size > 1) {
|
|
114
|
-
errors.push(
|
|
115
|
-
...args.filter(({name}) => frame.has(name)).map(
|
|
116
|
-
arg => generateForChild(arg, rect, 'conflicting image $1 parameter', 'frame'),
|
|
117
|
-
),
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
if (horizAlignKeys.size > 1) {
|
|
121
|
-
errors.push(
|
|
122
|
-
...args.filter(({name}) => horizAlign.has(name))
|
|
123
|
-
.map(arg => generateForChild(arg, rect, 'conflicting image $1 parameter', 'horizontal-alignment')),
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
if (vertAlignKeys.size > 1) {
|
|
127
|
-
errors.push(
|
|
128
|
-
...args.filter(({name}) => vertAlign.has(name))
|
|
129
|
-
.map(arg => generateForChild(arg, rect, 'conflicting image $1 parameter', 'vertical-alignment')),
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
return errors;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* 获取所有图片参数节点
|
|
137
|
-
* @returns {ImageParameterToken[]}
|
|
138
|
-
*/
|
|
139
|
-
getAllArgs() {
|
|
140
|
-
return this.childNodes.slice(1);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* 获取指定图片参数
|
|
145
|
-
* @param {string} key 参数名
|
|
146
|
-
* @complexity `n`
|
|
147
|
-
*/
|
|
148
|
-
getArgs(key) {
|
|
149
|
-
return typeof key === 'string'
|
|
150
|
-
? this.getAllArgs().filter(({name}) => key === name)
|
|
151
|
-
: this.typeError('getArgs', 'String');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* 获取特定类型的图片属性参数节点
|
|
156
|
-
* @param {Set<string>} keys 接受的参数名
|
|
157
|
-
* @param {type} type 类型名
|
|
158
|
-
* @complexity `n`
|
|
159
|
-
*/
|
|
160
|
-
#getTypedArgs(keys, type) {
|
|
161
|
-
const args = this.getAllArgs().filter(({name}) => keys.has(name));
|
|
162
|
-
if (args.length > 1) {
|
|
163
|
-
Parser.warn(`图片 ${this.name} 带有 ${args.length} 个${type}参数,只有最后 1 个 ${args[0].name} 会生效!`);
|
|
164
|
-
}
|
|
165
|
-
return args;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/** 获取图片框架属性参数节点 */
|
|
169
|
-
getFrameArgs() {
|
|
170
|
-
return this.#getTypedArgs(frame, '框架');
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/** 获取图片水平对齐参数节点 */
|
|
174
|
-
getHorizAlignArgs() {
|
|
175
|
-
return this.#getTypedArgs(horizAlign, '水平对齐');
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/** 获取图片垂直对齐参数节点 */
|
|
179
|
-
getVertAlignArgs() {
|
|
180
|
-
return this.#getTypedArgs(vertAlign, '垂直对齐');
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* 获取生效的指定图片参数
|
|
185
|
-
* @param {string} key 参数名
|
|
186
|
-
* @complexity `n`
|
|
187
|
-
*/
|
|
188
|
-
getArg(key) {
|
|
189
|
-
return this.getArgs(key).at(-1);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* 是否具有指定图片参数
|
|
194
|
-
* @param {string} key 参数名
|
|
195
|
-
* @complexity `n`
|
|
196
|
-
*/
|
|
197
|
-
hasArg(key) {
|
|
198
|
-
return this.getArgs(key).length > 0;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* 移除指定图片参数
|
|
203
|
-
* @param {string} key 参数名
|
|
204
|
-
* @complexity `n`
|
|
205
|
-
*/
|
|
206
|
-
removeArg(key) {
|
|
207
|
-
for (const token of this.getArgs(key)) {
|
|
208
|
-
this.removeChild(token);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* 获取图片参数名
|
|
214
|
-
* @complexity `n`
|
|
215
|
-
*/
|
|
216
|
-
getKeys() {
|
|
217
|
-
return this.getAllArgs().map(({name}) => name);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* 获取指定的图片参数值
|
|
222
|
-
* @param {string} key 参数名
|
|
223
|
-
* @complexity `n`
|
|
224
|
-
*/
|
|
225
|
-
getValues(key) {
|
|
226
|
-
return this.getArgs(key).map(token => token.getValue());
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* 获取生效的指定图片参数值
|
|
231
|
-
* @param {string} key 参数名
|
|
232
|
-
* @complexity `n`
|
|
233
|
-
*/
|
|
234
|
-
getValue(key) {
|
|
235
|
-
return this.getArg(key)?.getValue();
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* 设置图片参数
|
|
240
|
-
* @param {string} key 参数名
|
|
241
|
-
* @param {string|boolean} value 参数值
|
|
242
|
-
* @complexity `n`
|
|
243
|
-
* @throws `RangeError` 未定义的图片参数
|
|
244
|
-
* @throws `SyntaxError` 非法的参数
|
|
245
|
-
*/
|
|
246
|
-
setValue(key, value) {
|
|
247
|
-
if (typeof key !== 'string') {
|
|
248
|
-
this.typeError('setValue', 'String');
|
|
249
|
-
} else if (value === false) {
|
|
250
|
-
this.removeArg(key);
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
const token = this.getArg(key);
|
|
254
|
-
value = value === true ? value : String(value);
|
|
255
|
-
if (token) {
|
|
256
|
-
token.setValue(value);
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
let syntax = '';
|
|
260
|
-
const config = this.getAttribute('config');
|
|
261
|
-
if (key !== 'caption') {
|
|
262
|
-
syntax = Object.entries(config.img).find(([, name]) => name === key)?.[0];
|
|
263
|
-
if (!syntax) {
|
|
264
|
-
throw new RangeError(`未定义的图片参数: ${key}`);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
if (value === true) {
|
|
268
|
-
if (syntax.includes('$1')) {
|
|
269
|
-
this.typeError('setValue', 'Boolean');
|
|
270
|
-
}
|
|
271
|
-
const newArg = Parser.run(() => new ImageParameterToken(syntax, config));
|
|
272
|
-
this.insertAt(newArg);
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
const wikitext = `[[File:F|${syntax ? syntax.replace('$1', value) : value}]]`,
|
|
276
|
-
root = Parser.parse(wikitext, this.getAttribute('include'), 6, config),
|
|
277
|
-
{length, firstChild: file} = root,
|
|
278
|
-
{name, type, length: fileLength, lastChild: imageParameter} = file;
|
|
279
|
-
if (length !== 1 || type !== 'file' || name !== 'File:F' || fileLength !== 2 || imageParameter.name !== key) {
|
|
280
|
-
throw new SyntaxError(`非法的 ${key} 参数:${noWrap(value)}`);
|
|
281
|
-
}
|
|
282
|
-
this.insertAt(imageParameter);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
Parser.classes.FileToken = __filename;
|
|
287
|
-
module.exports = FileToken;
|
package/src/link/galleryImage.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {generateForSelf} = require('../../util/lint'),
|
|
4
|
-
{undo} = require('../../util/debug'),
|
|
5
|
-
singleLine = require('../../mixin/singleLine'),
|
|
6
|
-
Parser = require('../..'),
|
|
7
|
-
Token = require('..'),
|
|
8
|
-
FileToken = require('./file');
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 图片
|
|
12
|
-
* @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
|
|
13
|
-
*/
|
|
14
|
-
class GalleryImageToken extends singleLine(FileToken) {
|
|
15
|
-
type = 'gallery-image';
|
|
16
|
-
#invalid = false;
|
|
17
|
-
|
|
18
|
-
/** 图片链接 */
|
|
19
|
-
get link() {
|
|
20
|
-
return this.type === 'imagemap-image' ? undefined : super.link;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
set link(value) {
|
|
24
|
-
if (this.type !== 'imagemap-image') {
|
|
25
|
-
super.link = value;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @param {string} link 图片文件名
|
|
31
|
-
* @param {string|undefined} text 图片参数
|
|
32
|
-
* @param {import('../../typings/token').accum} accum
|
|
33
|
-
*/
|
|
34
|
-
constructor(link, text, config = Parser.getConfig(), accum = []) {
|
|
35
|
-
let token;
|
|
36
|
-
if (text !== undefined) {
|
|
37
|
-
token = new Token(text, config, true, accum);
|
|
38
|
-
token.type = 'temp';
|
|
39
|
-
for (let n = 1; n < Parser.MAX_STAGE; n++) {
|
|
40
|
-
token.getAttribute('parseOnce')();
|
|
41
|
-
}
|
|
42
|
-
accum.splice(accum.indexOf(token), 1);
|
|
43
|
-
}
|
|
44
|
-
super(link, token?.toString(), config, accum);
|
|
45
|
-
this.setAttribute('bracket', false);
|
|
46
|
-
if (!Object.values(config.img).includes('width')) {
|
|
47
|
-
this.seal(['size', 'width', 'height'], true);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @override
|
|
53
|
-
* @throws `Error` 非法的内链目标
|
|
54
|
-
* @throws `Error` 不可更改命名空间
|
|
55
|
-
*/
|
|
56
|
-
afterBuild() {
|
|
57
|
-
const initImagemap = this.type === 'imagemap-image',
|
|
58
|
-
titleObj = this.normalizeTitle(String(this.firstChild), initImagemap ? 0 : 6, true, !initImagemap);
|
|
59
|
-
this.setAttribute('name', titleObj.title);
|
|
60
|
-
this.#invalid = titleObj.interwiki || titleObj.ns !== 6; // 只用于gallery-image的首次解析
|
|
61
|
-
const /** @type {import('../../typings/event').AstListener} */ linkListener = (e, data) => {
|
|
62
|
-
const {prevTarget} = e;
|
|
63
|
-
if (prevTarget?.type === 'link-target') {
|
|
64
|
-
const name = String(prevTarget),
|
|
65
|
-
imagemap = this.type === 'imagemap-image',
|
|
66
|
-
{title, interwiki, ns, valid} = this.normalizeTitle(name, imagemap ? 0 : 6, true, !imagemap);
|
|
67
|
-
if (!valid) {
|
|
68
|
-
undo(e, data);
|
|
69
|
-
throw new Error(`非法的图片文件名:${name}`);
|
|
70
|
-
} else if (interwiki || ns !== 6) {
|
|
71
|
-
undo(e, data);
|
|
72
|
-
throw new Error(`图片链接不可更改命名空间:${name}`);
|
|
73
|
-
}
|
|
74
|
-
this.setAttribute('name', title);
|
|
75
|
-
this.#invalid = false;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
this.addEventListener(['remove', 'insert', 'replace', 'text'], linkListener);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** @override */
|
|
82
|
-
getPadding() {
|
|
83
|
-
return 0;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @override
|
|
88
|
-
* @param {number} start 起始位置
|
|
89
|
-
*/
|
|
90
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
91
|
-
const errors = super.lint(start);
|
|
92
|
-
if (this.#invalid) {
|
|
93
|
-
errors.push(generateForSelf(this, {start}, 'invalid gallery image'));
|
|
94
|
-
}
|
|
95
|
-
return errors;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @override
|
|
100
|
-
* @param {string} link 链接目标
|
|
101
|
-
* @throws `SyntaxError` 非法的链接目标
|
|
102
|
-
*/
|
|
103
|
-
setTarget(link) {
|
|
104
|
-
link = String(link);
|
|
105
|
-
const include = this.getAttribute('include'),
|
|
106
|
-
config = this.getAttribute('config'),
|
|
107
|
-
root = Parser.parse(`<gallery>${link}</gallery>`, include, 1, config),
|
|
108
|
-
{length, firstChild: gallery} = root,
|
|
109
|
-
{type, lastChild: {length: galleryLength, firstChild: image}} = gallery;
|
|
110
|
-
if (length !== 1 || type !== 'ext' || galleryLength !== 1 || image.type !== 'gallery-image') {
|
|
111
|
-
throw new SyntaxError(`非法的图库文件名:${link}`);
|
|
112
|
-
}
|
|
113
|
-
const {firstChild} = image;
|
|
114
|
-
image.destroy();
|
|
115
|
-
this.firstChild.safeReplaceWith(firstChild);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
Parser.classes.GalleryImageToken = __filename;
|
|
120
|
-
module.exports = GalleryImageToken;
|