wikiparser-node 1.0.0-beta.4 → 1.0.1-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/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/package.json +29 -16
- package/config/.schema.json +0 -160
- package/dist/index.d.ts +0 -62
- package/dist/index.js +0 -305
- package/dist/internal.d.ts +0 -44
- package/dist/lib/element.d.ts +0 -190
- package/dist/lib/element.js +0 -674
- package/dist/lib/node.d.ts +0 -178
- package/dist/lib/node.js +0 -457
- package/dist/lib/range.d.ts +0 -132
- package/dist/lib/range.js +0 -384
- package/dist/lib/ranges.d.ts +0 -28
- package/dist/lib/ranges.js +0 -125
- package/dist/lib/text.d.ts +0 -78
- package/dist/lib/text.js +0 -227
- package/dist/lib/title.d.ts +0 -34
- package/dist/lib/title.js +0 -111
- package/dist/mixin/attributesParent.js +0 -93
- package/dist/mixin/fixed.js +0 -32
- package/dist/mixin/hidden.js +0 -23
- package/dist/mixin/singleLine.js +0 -26
- package/dist/mixin/sol.js +0 -44
- package/dist/parser/braces.js +0 -120
- package/dist/parser/commentAndExt.js +0 -64
- package/dist/parser/converter.js +0 -39
- package/dist/parser/externalLinks.js +0 -27
- package/dist/parser/hrAndDoubleUnderscore.js +0 -37
- package/dist/parser/html.js +0 -35
- package/dist/parser/links.js +0 -93
- package/dist/parser/list.js +0 -58
- package/dist/parser/magicLinks.js +0 -39
- package/dist/parser/quotes.js +0 -66
- package/dist/parser/selector.js +0 -162
- package/dist/parser/table.js +0 -108
- package/dist/src/arg.d.ts +0 -78
- package/dist/src/arg.js +0 -203
- package/dist/src/atom.d.ts +0 -12
- package/dist/src/atom.js +0 -24
- package/dist/src/attribute.d.ts +0 -107
- package/dist/src/attribute.js +0 -446
- package/dist/src/attributes.d.ts +0 -120
- package/dist/src/attributes.js +0 -360
- package/dist/src/converter.d.ts +0 -76
- package/dist/src/converter.js +0 -134
- package/dist/src/converterFlags.d.ts +0 -108
- package/dist/src/converterFlags.js +0 -237
- package/dist/src/converterRule.d.ts +0 -97
- package/dist/src/converterRule.js +0 -253
- package/dist/src/extLink.d.ts +0 -64
- package/dist/src/extLink.js +0 -156
- package/dist/src/gallery.d.ts +0 -72
- package/dist/src/gallery.js +0 -133
- package/dist/src/heading.d.ts +0 -84
- package/dist/src/heading.js +0 -134
- package/dist/src/hidden.d.ts +0 -20
- package/dist/src/hidden.js +0 -26
- package/dist/src/html.d.ts +0 -115
- package/dist/src/html.js +0 -247
- package/dist/src/imageParameter.d.ts +0 -83
- package/dist/src/imageParameter.js +0 -255
- package/dist/src/imagemap.d.ts +0 -79
- package/dist/src/imagemap.js +0 -164
- package/dist/src/imagemapLink.d.ts +0 -49
- package/dist/src/imagemapLink.js +0 -39
- package/dist/src/index.d.ts +0 -157
- package/dist/src/index.js +0 -818
- package/dist/src/link/base.d.ts +0 -70
- package/dist/src/link/base.js +0 -229
- package/dist/src/link/category.d.ts +0 -14
- package/dist/src/link/category.js +0 -29
- package/dist/src/link/file.d.ts +0 -106
- package/dist/src/link/file.js +0 -271
- package/dist/src/link/galleryImage.d.ts +0 -37
- package/dist/src/link/galleryImage.js +0 -101
- package/dist/src/link/index.d.ts +0 -50
- package/dist/src/link/index.js +0 -136
- package/dist/src/magicLink.d.ts +0 -47
- package/dist/src/magicLink.js +0 -130
- package/dist/src/nested.d.ts +0 -49
- package/dist/src/nested.js +0 -88
- package/dist/src/nowiki/base.d.ts +0 -39
- package/dist/src/nowiki/base.js +0 -31
- package/dist/src/nowiki/comment.d.ts +0 -43
- package/dist/src/nowiki/comment.js +0 -62
- package/dist/src/nowiki/dd.d.ts +0 -22
- package/dist/src/nowiki/dd.js +0 -47
- package/dist/src/nowiki/doubleUnderscore.d.ts +0 -37
- package/dist/src/nowiki/doubleUnderscore.js +0 -48
- package/dist/src/nowiki/hr.d.ts +0 -24
- package/dist/src/nowiki/hr.js +0 -29
- package/dist/src/nowiki/index.d.ts +0 -20
- package/dist/src/nowiki/index.js +0 -24
- package/dist/src/nowiki/list.d.ts +0 -16
- package/dist/src/nowiki/list.js +0 -14
- package/dist/src/nowiki/noinclude.d.ts +0 -21
- package/dist/src/nowiki/noinclude.js +0 -25
- package/dist/src/nowiki/quote.d.ts +0 -20
- package/dist/src/nowiki/quote.js +0 -66
- package/dist/src/onlyinclude.d.ts +0 -39
- package/dist/src/onlyinclude.js +0 -66
- package/dist/src/paramTag/index.d.ts +0 -52
- package/dist/src/paramTag/index.js +0 -78
- package/dist/src/paramTag/inputbox.d.ts +0 -8
- package/dist/src/paramTag/inputbox.js +0 -22
- package/dist/src/parameter.d.ts +0 -96
- package/dist/src/parameter.js +0 -203
- package/dist/src/pre.d.ts +0 -29
- package/dist/src/pre.js +0 -49
- package/dist/src/syntax.d.ts +0 -23
- package/dist/src/syntax.js +0 -67
- package/dist/src/table/base.d.ts +0 -61
- package/dist/src/table/base.js +0 -78
- package/dist/src/table/index.d.ts +0 -248
- package/dist/src/table/index.js +0 -782
- package/dist/src/table/td.d.ts +0 -121
- package/dist/src/table/td.js +0 -267
- package/dist/src/table/tr.d.ts +0 -32
- package/dist/src/table/tr.js +0 -51
- package/dist/src/table/trBase.d.ts +0 -62
- package/dist/src/table/trBase.js +0 -157
- package/dist/src/tagPair/ext.d.ts +0 -55
- package/dist/src/tagPair/ext.js +0 -138
- package/dist/src/tagPair/include.d.ts +0 -43
- package/dist/src/tagPair/include.js +0 -42
- package/dist/src/tagPair/index.d.ts +0 -57
- package/dist/src/tagPair/index.js +0 -107
- package/dist/src/transclude.d.ts +0 -201
- package/dist/src/transclude.js +0 -727
- package/dist/util/debug.js +0 -42
- package/dist/util/diff.js +0 -71
- package/dist/util/lint.js +0 -48
- package/dist/util/string.js +0 -75
- package/errors/README +0 -1
- package/printed/README +0 -1
package/dist/src/link/file.js
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FileToken = void 0;
|
|
4
|
-
const string_1 = require("../../util/string");
|
|
5
|
-
const lint_1 = require("../../util/lint");
|
|
6
|
-
const Parser = require("../../index");
|
|
7
|
-
const base_1 = require("./base");
|
|
8
|
-
const imageParameter_1 = require("../imageParameter");
|
|
9
|
-
const frame = new Set(['manualthumb', 'frameless', 'framed', 'thumbnail']), horizAlign = new Set(['left', 'right', 'center', 'none']), vertAlign = new Set(['baseline', 'sub', 'super', 'top', 'text-top', 'middle', 'bottom', 'text-bottom']);
|
|
10
|
-
/**
|
|
11
|
-
* a more sophisticated string-explode function
|
|
12
|
-
* @browser
|
|
13
|
-
* @param start start syntax of a nested AST node
|
|
14
|
-
* @param end end syntax of a nested AST node
|
|
15
|
-
* @param separator syntax for explosion
|
|
16
|
-
* @param str string to be exploded
|
|
17
|
-
*/
|
|
18
|
-
const explode = (start, end, separator, str) => {
|
|
19
|
-
if (str === undefined) {
|
|
20
|
-
return [];
|
|
21
|
-
}
|
|
22
|
-
const regex = new RegExp(`${[start, end, separator].map(string_1.escapeRegExp).join('|')}`, 'gu'), exploded = [];
|
|
23
|
-
let mt = regex.exec(str), depth = 0, lastIndex = 0;
|
|
24
|
-
while (mt) {
|
|
25
|
-
const { 0: match, index } = mt;
|
|
26
|
-
if (match !== separator) {
|
|
27
|
-
depth += match === start ? 1 : -1;
|
|
28
|
-
}
|
|
29
|
-
else if (depth === 0) {
|
|
30
|
-
exploded.push(str.slice(lastIndex, index));
|
|
31
|
-
({ lastIndex } = regex);
|
|
32
|
-
}
|
|
33
|
-
mt = regex.exec(str);
|
|
34
|
-
}
|
|
35
|
-
exploded.push(str.slice(lastIndex));
|
|
36
|
-
return exploded;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* 图片
|
|
40
|
-
* @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
|
|
41
|
-
*/
|
|
42
|
-
// @ts-expect-error not implementing all abstract methods
|
|
43
|
-
class FileToken extends base_1.LinkBaseToken {
|
|
44
|
-
/** @browser */
|
|
45
|
-
type = 'file';
|
|
46
|
-
/** 图片链接 */
|
|
47
|
-
get link() {
|
|
48
|
-
return this.getArg('link')?.link ?? super.link;
|
|
49
|
-
}
|
|
50
|
-
set link(value) {
|
|
51
|
-
this.setValue('link', String(value));
|
|
52
|
-
}
|
|
53
|
-
/** 图片大小 */
|
|
54
|
-
get size() {
|
|
55
|
-
return this.getArg('width')?.size;
|
|
56
|
-
}
|
|
57
|
-
/** 图片宽度 */
|
|
58
|
-
get width() {
|
|
59
|
-
return this.size?.width;
|
|
60
|
-
}
|
|
61
|
-
set width(width) {
|
|
62
|
-
const arg = this.getArg('width');
|
|
63
|
-
if (arg) {
|
|
64
|
-
arg.width = width;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
this.setValue('width', width);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/** 图片高度 */
|
|
71
|
-
get height() {
|
|
72
|
-
return this.size?.height;
|
|
73
|
-
}
|
|
74
|
-
set height(height) {
|
|
75
|
-
const arg = this.getArg('width');
|
|
76
|
-
if (arg) {
|
|
77
|
-
arg.height = height;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
this.setValue('width', height && `x${height}`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* @browser
|
|
85
|
-
* @param link 文件名
|
|
86
|
-
* @param text 图片参数
|
|
87
|
-
* @param delimiter `|`
|
|
88
|
-
*/
|
|
89
|
-
constructor(link, text, config = Parser.getConfig(), accum = [], delimiter = '|') {
|
|
90
|
-
super(link, undefined, config, accum, delimiter);
|
|
91
|
-
this.setAttribute('acceptable', { AtomToken: 0, ImageParameterToken: '1:' });
|
|
92
|
-
this.append(...explode('-{', '}-', '|', text).map(part => new imageParameter_1.ImageParameterToken(part, config, accum)));
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* @override
|
|
96
|
-
* @browser
|
|
97
|
-
*/
|
|
98
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
99
|
-
const errors = super.lint(start), args = this.getAllArgs().filter(({ childNodes }) => {
|
|
100
|
-
const visibleNodes = childNodes.filter(node => node.text().trim());
|
|
101
|
-
return visibleNodes.length !== 1 || visibleNodes[0].type !== 'arg';
|
|
102
|
-
}), keys = [...new Set(args.map(({ name }) => name))].filter(key => key !== 'invalid'), frameKeys = keys.filter(key => frame.has(key)), horizAlignKeys = keys.filter(key => horizAlign.has(key)), vertAlignKeys = keys.filter(key => vertAlign.has(key));
|
|
103
|
-
if (args.length === keys.length
|
|
104
|
-
&& frameKeys.length < 2 && horizAlignKeys.length < 2 && vertAlignKeys.length < 2) {
|
|
105
|
-
return errors;
|
|
106
|
-
}
|
|
107
|
-
const rect = { start, ...this.getRootNode().posFromIndex(start) };
|
|
108
|
-
/**
|
|
109
|
-
* 图片参数到语法错误的映射
|
|
110
|
-
* @param msg 消息键
|
|
111
|
-
* @param p1 替换$1
|
|
112
|
-
*/
|
|
113
|
-
const generate = (msg, p1) => (arg) => (0, lint_1.generateForChild)(arg, rect, Parser.msg(`${msg} image $1 parameter`, p1));
|
|
114
|
-
for (const key of keys) {
|
|
115
|
-
let relevantArgs = args.filter(({ name }) => name === key);
|
|
116
|
-
if (key === 'caption') {
|
|
117
|
-
relevantArgs = [
|
|
118
|
-
...relevantArgs.slice(0, -1).filter(arg => arg.text()),
|
|
119
|
-
...relevantArgs.slice(-1),
|
|
120
|
-
];
|
|
121
|
-
}
|
|
122
|
-
if (relevantArgs.length > 1) {
|
|
123
|
-
errors.push(...relevantArgs.map(generate('duplicated', key)));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (frameKeys.length > 1) {
|
|
127
|
-
errors.push(...args.filter(({ name }) => frame.has(name)).map(generate('conflicting', 'frame')));
|
|
128
|
-
}
|
|
129
|
-
if (horizAlignKeys.length > 1) {
|
|
130
|
-
errors.push(...args.filter(({ name }) => horizAlign.has(name)).map(generate('conflicting', 'horizontal-alignment')));
|
|
131
|
-
}
|
|
132
|
-
if (vertAlignKeys.length > 1) {
|
|
133
|
-
errors.push(...args.filter(({ name }) => vertAlign.has(name)).map(generate('conflicting', 'vertical-alignment')));
|
|
134
|
-
}
|
|
135
|
-
return errors;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* 获取所有图片参数节点
|
|
139
|
-
* @browser
|
|
140
|
-
*/
|
|
141
|
-
getAllArgs() {
|
|
142
|
-
return this.childNodes.slice(1);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* 获取指定图片参数
|
|
146
|
-
* @browser
|
|
147
|
-
* @param key 参数名
|
|
148
|
-
*/
|
|
149
|
-
getArgs(key) {
|
|
150
|
-
return this.getAllArgs().filter(({ name }) => key === name);
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* 获取特定类型的图片属性参数节点
|
|
154
|
-
* @browser
|
|
155
|
-
* @param keys 接受的参数名
|
|
156
|
-
* @param type 类型名
|
|
157
|
-
*/
|
|
158
|
-
#getTypedArgs(keys, type) {
|
|
159
|
-
const args = this.getAllArgs().filter(({ name }) => keys.has(name));
|
|
160
|
-
if (args.length > 1) {
|
|
161
|
-
Parser.warn(`图片 ${this.name} 带有 ${args.length} 个${type}参数,只有最后 1 个 ${args[0].name} 会生效!`);
|
|
162
|
-
}
|
|
163
|
-
return args;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* 获取图片框架属性参数节点
|
|
167
|
-
* @browser
|
|
168
|
-
*/
|
|
169
|
-
getFrameArgs() {
|
|
170
|
-
return this.#getTypedArgs(frame, '框架');
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* 获取图片水平对齐参数节点
|
|
174
|
-
* @browser
|
|
175
|
-
*/
|
|
176
|
-
getHorizAlignArgs() {
|
|
177
|
-
return this.#getTypedArgs(horizAlign, '水平对齐');
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* 获取图片垂直对齐参数节点
|
|
181
|
-
* @browser
|
|
182
|
-
*/
|
|
183
|
-
getVertAlignArgs() {
|
|
184
|
-
return this.#getTypedArgs(vertAlign, '垂直对齐');
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* 获取生效的指定图片参数
|
|
188
|
-
* @param key 参数名
|
|
189
|
-
*/
|
|
190
|
-
getArg(key) {
|
|
191
|
-
return this.getArgs(key).at(-1);
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* 是否具有指定图片参数
|
|
195
|
-
* @param key 参数名
|
|
196
|
-
*/
|
|
197
|
-
hasArg(key) {
|
|
198
|
-
return this.getArgs(key).length > 0;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* 移除指定图片参数
|
|
202
|
-
* @param key 参数名
|
|
203
|
-
*/
|
|
204
|
-
removeArg(key) {
|
|
205
|
-
for (const token of this.getArgs(key)) {
|
|
206
|
-
this.removeChild(token);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
/** 获取图片参数名 */
|
|
210
|
-
getKeys() {
|
|
211
|
-
return new Set(this.getAllArgs().map(({ name }) => name));
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* 获取指定的图片参数值
|
|
215
|
-
* @param key 参数名
|
|
216
|
-
*/
|
|
217
|
-
getValues(key) {
|
|
218
|
-
return this.getArgs(key).map(token => token.getValue());
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* 获取生效的指定图片参数值
|
|
222
|
-
* @param key 参数名
|
|
223
|
-
*/
|
|
224
|
-
getValue(key) {
|
|
225
|
-
return this.getArg(key)?.getValue();
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* 设置图片参数
|
|
229
|
-
* @param key 参数名
|
|
230
|
-
* @param value 参数值
|
|
231
|
-
* @throws `RangeError` 未定义的图片参数
|
|
232
|
-
* @throws `SyntaxError` 非法的参数
|
|
233
|
-
*/
|
|
234
|
-
setValue(key, value = false) {
|
|
235
|
-
if (value === false) {
|
|
236
|
-
this.removeArg(key);
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
const token = this.getArg(key);
|
|
240
|
-
if (token) {
|
|
241
|
-
token.setValue(value);
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
let syntax = '';
|
|
245
|
-
const config = this.getAttribute('config');
|
|
246
|
-
if (key !== 'caption') {
|
|
247
|
-
syntax = Object.entries(config.img).find(([, name]) => name === key)?.[0];
|
|
248
|
-
if (!syntax) {
|
|
249
|
-
throw new RangeError(`未定义的图片参数: ${key}`);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
if (value === true) {
|
|
253
|
-
if (syntax.includes('$1')) {
|
|
254
|
-
this.typeError('setValue', 'Boolean');
|
|
255
|
-
}
|
|
256
|
-
this.insertAt(Parser.run(() => new imageParameter_1.ImageParameterToken(syntax, config)));
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
const wikitext = `[[File:F|${syntax ? syntax.replace('$1', value) : value}]]`, root = Parser.parse(wikitext, this.getAttribute('include'), 6, config), { length, firstChild: file } = root;
|
|
260
|
-
if (length !== 1 || file.type !== 'file' || file.length !== 2) {
|
|
261
|
-
throw new SyntaxError(`非法的 ${key} 参数:${(0, string_1.noWrap)(value)}`);
|
|
262
|
-
}
|
|
263
|
-
const { name, lastChild: imageParameter } = file;
|
|
264
|
-
if (name !== 'File:F' || imageParameter.name !== key) {
|
|
265
|
-
throw new SyntaxError(`非法的 ${key} 参数:${(0, string_1.noWrap)(value)}`);
|
|
266
|
-
}
|
|
267
|
-
this.insertAt(imageParameter);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
exports.FileToken = FileToken;
|
|
271
|
-
Parser.classes['FileToken'] = __filename;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import * as Parser from '../../index';
|
|
2
|
-
import { Token } from '..';
|
|
3
|
-
import type { Title } from '../../lib/title';
|
|
4
|
-
import type { LintError } from '../../index';
|
|
5
|
-
declare const GalleryImageToken_base: (abstract new (...args: any[]) => {
|
|
6
|
-
toString(omit?: Set<string> | undefined): string;
|
|
7
|
-
text(): string;
|
|
8
|
-
length: number;
|
|
9
|
-
insertAt(token: unknown, i?: number | undefined): unknown;
|
|
10
|
-
}) & typeof Parser.FileToken;
|
|
11
|
-
/** 图库图片 */
|
|
12
|
-
export declare class GalleryImageToken extends GalleryImageToken_base {
|
|
13
|
-
#private;
|
|
14
|
-
type: 'gallery-image' | 'imagemap-image';
|
|
15
|
-
/** 图片链接 */
|
|
16
|
-
get link(): string | Title;
|
|
17
|
-
set link(value: string | Title);
|
|
18
|
-
/**
|
|
19
|
-
* @browser
|
|
20
|
-
* @param type 图片类型
|
|
21
|
-
* @param link 图片文件名
|
|
22
|
-
* @param text 图片参数
|
|
23
|
-
*/
|
|
24
|
-
constructor(type: 'gallery' | 'imagemap', link: string, text?: string, config?: Parser.Config, accum?: Token[]);
|
|
25
|
-
/**
|
|
26
|
-
* @override
|
|
27
|
-
* @browser
|
|
28
|
-
*/
|
|
29
|
-
lint(start?: number): LintError[];
|
|
30
|
-
/**
|
|
31
|
-
* @override
|
|
32
|
-
* @param link 链接目标
|
|
33
|
-
* @throws `SyntaxError` 非法的链接目标
|
|
34
|
-
*/
|
|
35
|
-
setTarget(link: string): void;
|
|
36
|
-
}
|
|
37
|
-
export {};
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GalleryImageToken = void 0;
|
|
4
|
-
const lint_1 = require("../../util/lint");
|
|
5
|
-
const debug_1 = require("../../util/debug");
|
|
6
|
-
const singleLine_1 = require("../../mixin/singleLine");
|
|
7
|
-
const Parser = require("../../index");
|
|
8
|
-
const __1 = require("..");
|
|
9
|
-
const file_1 = require("./file");
|
|
10
|
-
/** 图库图片 */
|
|
11
|
-
// @ts-expect-error not implementing all abstract methods
|
|
12
|
-
class GalleryImageToken extends (0, singleLine_1.singleLine)(file_1.FileToken) {
|
|
13
|
-
/** @browser */
|
|
14
|
-
#invalid = false;
|
|
15
|
-
/** 图片链接 */
|
|
16
|
-
get link() {
|
|
17
|
-
return this.type === 'imagemap-image' ? '' : super.link;
|
|
18
|
-
}
|
|
19
|
-
set link(value) {
|
|
20
|
-
if (this.type !== 'imagemap-image') {
|
|
21
|
-
super.link = value;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @browser
|
|
26
|
-
* @param type 图片类型
|
|
27
|
-
* @param link 图片文件名
|
|
28
|
-
* @param text 图片参数
|
|
29
|
-
*/
|
|
30
|
-
constructor(type, link, text, config = Parser.getConfig(), accum = []) {
|
|
31
|
-
let token;
|
|
32
|
-
if (text !== undefined) {
|
|
33
|
-
token = new __1.Token(text, config, true, accum);
|
|
34
|
-
token.type = 'plain';
|
|
35
|
-
for (let n = 1; n < Parser.MAX_STAGE; n++) {
|
|
36
|
-
token.parseOnce();
|
|
37
|
-
}
|
|
38
|
-
accum.splice(accum.indexOf(token), 1);
|
|
39
|
-
}
|
|
40
|
-
super(link, token?.toString(), config, accum);
|
|
41
|
-
this.setAttribute('bracket', false).type = `${type}-image`;
|
|
42
|
-
}
|
|
43
|
-
/** @private */
|
|
44
|
-
afterBuild() {
|
|
45
|
-
const initImagemap = this.type === 'imagemap-image', titleObj = this.normalizeTitle(String(this.firstChild), initImagemap ? 0 : 6, true, !initImagemap);
|
|
46
|
-
this.setAttribute('name', titleObj.title);
|
|
47
|
-
this.#invalid = Boolean(titleObj.interwiki) || titleObj.ns !== 6; // 只用于gallery-image的首次解析
|
|
48
|
-
const /** @implements */ linkListener = (e, data) => {
|
|
49
|
-
const { prevTarget } = e;
|
|
50
|
-
if (prevTarget?.type === 'link-target') {
|
|
51
|
-
const name = String(prevTarget), imagemap = this.type === 'imagemap-image', { title, interwiki, ns, valid } = this.normalizeTitle(name, imagemap ? 0 : 6, true, !imagemap);
|
|
52
|
-
if (!valid) {
|
|
53
|
-
(0, debug_1.undo)(e, data);
|
|
54
|
-
throw new Error(`非法的图片文件名:${name}`);
|
|
55
|
-
}
|
|
56
|
-
else if (interwiki || ns !== 6) {
|
|
57
|
-
(0, debug_1.undo)(e, data);
|
|
58
|
-
throw new Error(`图片链接不可更改命名空间:${name}`);
|
|
59
|
-
}
|
|
60
|
-
this.setAttribute('name', title);
|
|
61
|
-
this.#invalid = false;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
this.addEventListener(['remove', 'insert', 'replace', 'text'], linkListener);
|
|
65
|
-
}
|
|
66
|
-
/** @private */
|
|
67
|
-
getPadding() {
|
|
68
|
-
return 0;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* @override
|
|
72
|
-
* @browser
|
|
73
|
-
*/
|
|
74
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
75
|
-
const errors = super.lint(start);
|
|
76
|
-
if (this.#invalid) {
|
|
77
|
-
errors.push((0, lint_1.generateForSelf)(this, { start }, 'invalid gallery image'));
|
|
78
|
-
}
|
|
79
|
-
return errors;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* @override
|
|
83
|
-
* @param link 链接目标
|
|
84
|
-
* @throws `SyntaxError` 非法的链接目标
|
|
85
|
-
*/
|
|
86
|
-
setTarget(link) {
|
|
87
|
-
const include = this.getAttribute('include'), config = this.getAttribute('config'), root = Parser.parse(`<gallery>${link}</gallery>`, include, 1, config), { length, firstChild: ext } = root;
|
|
88
|
-
if (length !== 1 || ext.type !== 'ext') {
|
|
89
|
-
throw new SyntaxError(`非法的图库文件名:${link}`);
|
|
90
|
-
}
|
|
91
|
-
const { lastChild: gallery } = ext, { firstChild: image } = gallery;
|
|
92
|
-
if (gallery.length !== 1 || image.type !== 'gallery-image') {
|
|
93
|
-
throw new SyntaxError(`非法的图库文件名:${link}`);
|
|
94
|
-
}
|
|
95
|
-
const { firstChild } = image;
|
|
96
|
-
image.destroy();
|
|
97
|
-
this.firstChild.safeReplaceWith(firstChild);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
exports.GalleryImageToken = GalleryImageToken;
|
|
101
|
-
Parser.classes['GalleryImageToken'] = __filename;
|
package/dist/src/link/index.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { LinkBaseToken } from './base';
|
|
2
|
-
import type { Title } from '../../lib/title';
|
|
3
|
-
import type { Token, AtomToken } from '../../internal';
|
|
4
|
-
/**
|
|
5
|
-
* 内链
|
|
6
|
-
* @classdesc `{childNodes: [AtomToken, ?Token]}`
|
|
7
|
-
*/
|
|
8
|
-
export declare class LinkToken extends LinkBaseToken {
|
|
9
|
-
#private;
|
|
10
|
-
/** @browser */
|
|
11
|
-
readonly type: 'link' | 'category';
|
|
12
|
-
childNodes: [AtomToken] | [AtomToken, Token];
|
|
13
|
-
abstract get children(): [AtomToken] | [AtomToken, Token];
|
|
14
|
-
abstract get link(): Title;
|
|
15
|
-
abstract set link(link: Title);
|
|
16
|
-
/** 是否链接到自身 */
|
|
17
|
-
get selfLink(): boolean;
|
|
18
|
-
set selfLink(selfLink: boolean);
|
|
19
|
-
/** @override */
|
|
20
|
-
get fragment(): string | undefined;
|
|
21
|
-
set fragment(fragment: string | undefined);
|
|
22
|
-
/** interwiki */
|
|
23
|
-
get interwiki(): string;
|
|
24
|
-
/** @throws `RangeError` 非法的跨维基前缀 */
|
|
25
|
-
set interwiki(interwiki: string);
|
|
26
|
-
/**
|
|
27
|
-
* 设置跨语言链接
|
|
28
|
-
* @param lang 语言前缀
|
|
29
|
-
* @param link 页面标题
|
|
30
|
-
* @throws `SyntaxError` 仅有fragment
|
|
31
|
-
* @throws `SyntaxError` 非法的跨语言链接
|
|
32
|
-
*/
|
|
33
|
-
setLangLink(lang: string, link: string | Title): void;
|
|
34
|
-
/**
|
|
35
|
-
* 设置fragment
|
|
36
|
-
* @param fragment fragment
|
|
37
|
-
*/
|
|
38
|
-
setFragment(fragment?: string): void;
|
|
39
|
-
/**
|
|
40
|
-
* 修改为到自身的链接
|
|
41
|
-
* @param fragment fragment
|
|
42
|
-
* @throws `RangeError` 空fragment
|
|
43
|
-
*/
|
|
44
|
-
asSelfLink(fragment?: string | undefined): void;
|
|
45
|
-
/**
|
|
46
|
-
* 自动生成管道符后的链接文字
|
|
47
|
-
* @throws `Error` 带有"#"或"%"时不可用
|
|
48
|
-
*/
|
|
49
|
-
pipeTrick(): void;
|
|
50
|
-
}
|
package/dist/src/link/index.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LinkToken = void 0;
|
|
4
|
-
const Parser = require("../../index");
|
|
5
|
-
const base_1 = require("./base");
|
|
6
|
-
/**
|
|
7
|
-
* 内链
|
|
8
|
-
* @classdesc `{childNodes: [AtomToken, ?Token]}`
|
|
9
|
-
*/
|
|
10
|
-
// @ts-expect-error not implementing all abstract methods
|
|
11
|
-
class LinkToken extends base_1.LinkBaseToken {
|
|
12
|
-
/** @browser */
|
|
13
|
-
type = 'link';
|
|
14
|
-
/** 是否链接到自身 */
|
|
15
|
-
get selfLink() {
|
|
16
|
-
const { link: { title, fragment } } = this;
|
|
17
|
-
return !title && Boolean(fragment);
|
|
18
|
-
}
|
|
19
|
-
set selfLink(selfLink) {
|
|
20
|
-
if (selfLink) {
|
|
21
|
-
this.asSelfLink();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/** @override */
|
|
25
|
-
get fragment() {
|
|
26
|
-
return super.fragment;
|
|
27
|
-
}
|
|
28
|
-
set fragment(fragment) {
|
|
29
|
-
this.#setFragment(fragment);
|
|
30
|
-
}
|
|
31
|
-
/** interwiki */
|
|
32
|
-
get interwiki() {
|
|
33
|
-
return this.link.interwiki;
|
|
34
|
-
}
|
|
35
|
-
/** @throws `RangeError` 非法的跨维基前缀 */
|
|
36
|
-
set interwiki(interwiki) {
|
|
37
|
-
const { link: { prefix, main, fragment } } = this, link = `${interwiki}:${prefix}${main}${fragment === undefined ? '' : `#${fragment}`}`;
|
|
38
|
-
if (interwiki && !this.isInterwiki(link)) {
|
|
39
|
-
throw new RangeError(`${interwiki} 不是合法的跨维基前缀!`);
|
|
40
|
-
}
|
|
41
|
-
this.setTarget(link);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* 设置跨语言链接
|
|
45
|
-
* @param lang 语言前缀
|
|
46
|
-
* @param link 页面标题
|
|
47
|
-
* @throws `SyntaxError` 仅有fragment
|
|
48
|
-
* @throws `SyntaxError` 非法的跨语言链接
|
|
49
|
-
*/
|
|
50
|
-
setLangLink(lang, link) {
|
|
51
|
-
let strLink = String(link).trim();
|
|
52
|
-
const [char] = strLink;
|
|
53
|
-
if (char === '#') {
|
|
54
|
-
throw new SyntaxError('跨语言链接不能仅为fragment!');
|
|
55
|
-
}
|
|
56
|
-
else if (char === ':') {
|
|
57
|
-
strLink = strLink.slice(1);
|
|
58
|
-
}
|
|
59
|
-
const config = this.getAttribute('config'), include = this.getAttribute('include'), root = Parser.parse(`[[${lang}:${strLink}]]`, include, 6, config), { length, firstChild: wikiLink } = root;
|
|
60
|
-
if (length !== 1 || !(wikiLink instanceof LinkToken) || wikiLink.length !== 1) {
|
|
61
|
-
throw new SyntaxError(`非法的跨语言链接目标:${lang}:${strLink}`);
|
|
62
|
-
}
|
|
63
|
-
const { interwiki, firstChild } = wikiLink;
|
|
64
|
-
if (interwiki !== lang.toLowerCase()) {
|
|
65
|
-
throw new SyntaxError(`非法的跨语言链接目标:${lang}:${strLink}`);
|
|
66
|
-
}
|
|
67
|
-
wikiLink.destroy();
|
|
68
|
-
this.firstChild.safeReplaceWith(firstChild);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* 设置fragment
|
|
72
|
-
* @param fragment fragment
|
|
73
|
-
* @param page 是否是其他页面
|
|
74
|
-
* @throws `SyntaxError` 非法的fragment
|
|
75
|
-
*/
|
|
76
|
-
#setFragment(fragment, page = true) {
|
|
77
|
-
fragment &&= fragment.replace(/[<>[\]#|=]/gu, p => encodeURIComponent(p));
|
|
78
|
-
const include = this.getAttribute('include'), config = this.getAttribute('config'), root = Parser.parse(`[[${page ? `:${this.name}` : ''}${fragment === undefined ? '' : `#${fragment}`}]]`, include, 6, config), { length, firstChild: wikiLink } = root;
|
|
79
|
-
if (length !== 1 || !(wikiLink instanceof LinkToken) || wikiLink.length !== 1) {
|
|
80
|
-
throw new SyntaxError(`非法的 fragment:${fragment ?? ''}`);
|
|
81
|
-
}
|
|
82
|
-
else if (page) {
|
|
83
|
-
Parser.warn(`${this.constructor.name}.setFragment 方法会同时规范化页面名!`);
|
|
84
|
-
}
|
|
85
|
-
const { firstChild } = wikiLink;
|
|
86
|
-
wikiLink.destroy();
|
|
87
|
-
this.firstChild.safeReplaceWith(firstChild);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* 设置fragment
|
|
91
|
-
* @param fragment fragment
|
|
92
|
-
*/
|
|
93
|
-
setFragment(fragment) {
|
|
94
|
-
this.#setFragment(fragment);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* 修改为到自身的链接
|
|
98
|
-
* @param fragment fragment
|
|
99
|
-
* @throws `RangeError` 空fragment
|
|
100
|
-
*/
|
|
101
|
-
asSelfLink(fragment = this.fragment) {
|
|
102
|
-
if (!fragment?.trim()) {
|
|
103
|
-
throw new RangeError(`${this.constructor.name}.asSelfLink 方法必须指定非空的 fragment!`);
|
|
104
|
-
}
|
|
105
|
-
this.#setFragment(fragment, false);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* 自动生成管道符后的链接文字
|
|
109
|
-
* @throws `Error` 带有"#"或"%"时不可用
|
|
110
|
-
*/
|
|
111
|
-
pipeTrick() {
|
|
112
|
-
const linkText = this.firstChild.text();
|
|
113
|
-
if (linkText.includes('#') || linkText.includes('%')) {
|
|
114
|
-
throw new Error('Pipe trick 不能用于带有"#"或"%"的场合!');
|
|
115
|
-
}
|
|
116
|
-
const m1 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+)\(.+\)$/u.exec(linkText);
|
|
117
|
-
if (m1) {
|
|
118
|
-
this.setLinkText(m1[1].trim());
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
const m2 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+)(.+)$/u.exec(linkText);
|
|
122
|
-
if (m2) {
|
|
123
|
-
this.setLinkText(m2[1].trim());
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
const m3 = /^:?(?:[ \w\x80-\xFF-]+:)?(.+?)(?:(?<!\()\(.+\))?(?:, |,|، )./u
|
|
127
|
-
.exec(linkText);
|
|
128
|
-
if (m3) {
|
|
129
|
-
this.setLinkText(m3[1].trim());
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
this.setLinkText(linkText);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
exports.LinkToken = LinkToken;
|
|
136
|
-
Parser.classes['LinkToken'] = __filename;
|
package/dist/src/magicLink.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import * as Parser from '../index';
|
|
2
|
-
import { Token } from '.';
|
|
3
|
-
import type { LintError } from '../index';
|
|
4
|
-
/**
|
|
5
|
-
* 自由外链
|
|
6
|
-
* @classdesc `{childNodes: ...AstText|CommentToken|IncludeToken|NoincludeToken}`
|
|
7
|
-
*/
|
|
8
|
-
export declare class MagicLinkToken extends Token {
|
|
9
|
-
#private;
|
|
10
|
-
type: 'free-ext-link' | 'ext-link-url';
|
|
11
|
-
/** 协议 */
|
|
12
|
-
get protocol(): string | undefined;
|
|
13
|
-
/**
|
|
14
|
-
* @throws `RangeError` 非法协议
|
|
15
|
-
* @throws `Error` 特殊外链无法更改协议
|
|
16
|
-
*/
|
|
17
|
-
set protocol(value: string | undefined);
|
|
18
|
-
/** 和内链保持一致 */
|
|
19
|
-
get link(): string;
|
|
20
|
-
set link(url: string);
|
|
21
|
-
/**
|
|
22
|
-
* @browser
|
|
23
|
-
* @param url 网址
|
|
24
|
-
* @param doubleSlash 是否接受"//"作为协议
|
|
25
|
-
*/
|
|
26
|
-
constructor(url?: string, doubleSlash?: boolean, config?: Parser.Config, accum?: Token[]);
|
|
27
|
-
/**
|
|
28
|
-
* @override
|
|
29
|
-
* @browser
|
|
30
|
-
*/
|
|
31
|
-
lint(start?: number): LintError[];
|
|
32
|
-
/** @override */
|
|
33
|
-
cloneNode(): this;
|
|
34
|
-
/**
|
|
35
|
-
* 获取网址
|
|
36
|
-
* @throws `Error` 非标准协议
|
|
37
|
-
*/
|
|
38
|
-
getUrl(): URL;
|
|
39
|
-
/**
|
|
40
|
-
* 设置外链目标
|
|
41
|
-
* @param url 含协议的网址
|
|
42
|
-
* @throws `SyntaxError` 非法的自由外链目标
|
|
43
|
-
*/
|
|
44
|
-
setTarget(url: string): void;
|
|
45
|
-
/** 是否是模板或魔术字参数 */
|
|
46
|
-
isParamValue(): boolean;
|
|
47
|
-
}
|