wikiparser-node 1.8.0-b → 1.8.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.
- package/config/.schema.json +181 -0
- package/config/enwiki.json +814 -1
- package/config/llwiki.json +35 -1
- package/config/moegirl.json +44 -1
- package/config/zhwiki.json +466 -1
- package/dist/addon/table.js +485 -0
- package/dist/addon/token.js +237 -0
- package/dist/addon/transclude.js +183 -0
- package/dist/base.d.ts +71 -0
- package/dist/base.js +38 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +211 -0
- package/dist/internal.d.ts +46 -0
- package/dist/lib/element.d.ts +140 -0
- package/dist/lib/element.js +597 -0
- package/dist/lib/node.d.ts +166 -0
- package/dist/lib/node.js +480 -0
- package/dist/lib/range.d.ts +105 -0
- package/dist/lib/range.js +406 -0
- package/dist/lib/ranges.d.ts +28 -0
- package/dist/lib/ranges.js +126 -0
- package/dist/lib/text.d.ts +63 -0
- package/dist/lib/text.js +355 -0
- package/dist/lib/title.d.ts +40 -0
- package/dist/lib/title.js +197 -0
- package/dist/mixin/attributesParent.d.ts +49 -0
- package/dist/mixin/attributesParent.js +81 -0
- package/dist/mixin/fixed.d.ts +5 -0
- package/dist/mixin/fixed.js +30 -0
- package/dist/mixin/flagsParent.d.ts +41 -0
- package/dist/mixin/flagsParent.js +59 -0
- package/dist/mixin/hidden.d.ts +4 -0
- package/dist/mixin/hidden.js +24 -0
- package/dist/mixin/magicLinkParent.d.ts +19 -0
- package/dist/mixin/magicLinkParent.js +42 -0
- package/dist/mixin/singleLine.d.ts +5 -0
- package/dist/mixin/singleLine.js +26 -0
- package/dist/mixin/sol.d.ts +5 -0
- package/dist/mixin/sol.js +43 -0
- package/dist/mixin/syntax.d.ts +8 -0
- package/dist/mixin/syntax.js +50 -0
- package/dist/parser/braces.js +130 -0
- package/dist/parser/commentAndExt.js +89 -0
- package/dist/parser/converter.js +40 -0
- package/dist/parser/externalLinks.js +44 -0
- package/dist/parser/hrAndDoubleUnderscore.js +40 -0
- package/dist/parser/html.js +38 -0
- package/dist/parser/links.js +99 -0
- package/dist/parser/list.js +97 -0
- package/dist/parser/magicLinks.js +42 -0
- package/dist/parser/quotes.js +67 -0
- package/dist/parser/redirect.js +26 -0
- package/dist/parser/selector.js +190 -0
- package/dist/parser/table.js +123 -0
- package/dist/src/arg.d.ts +58 -0
- package/dist/src/arg.js +214 -0
- package/dist/src/atom.d.ts +12 -0
- package/dist/src/atom.js +27 -0
- package/dist/src/attribute.d.ts +71 -0
- package/dist/src/attribute.js +502 -0
- package/dist/src/attributes.d.ts +109 -0
- package/dist/src/attributes.js +356 -0
- package/dist/src/converter.d.ts +33 -0
- package/dist/src/converter.js +134 -0
- package/dist/src/converterFlags.d.ts +87 -0
- package/dist/src/converterFlags.js +242 -0
- package/dist/src/converterRule.d.ts +77 -0
- package/dist/src/converterRule.js +209 -0
- package/dist/src/extLink.d.ts +43 -0
- package/dist/src/extLink.js +191 -0
- package/dist/src/gallery.d.ts +54 -0
- package/dist/src/gallery.js +139 -0
- package/dist/src/heading.d.ts +47 -0
- package/dist/src/heading.js +190 -0
- package/dist/src/hidden.d.ts +7 -0
- package/dist/src/hidden.js +23 -0
- package/dist/src/html.d.ts +65 -0
- package/dist/src/html.js +358 -0
- package/dist/src/imageParameter.d.ts +65 -0
- package/dist/src/imageParameter.js +257 -0
- package/dist/src/imagemap.d.ts +54 -0
- package/dist/src/imagemap.js +144 -0
- package/dist/src/imagemapLink.d.ts +31 -0
- package/dist/src/imagemapLink.js +93 -0
- package/dist/src/index.d.ts +142 -0
- package/dist/src/index.js +701 -0
- package/dist/src/link/base.d.ts +52 -0
- package/dist/src/link/base.js +228 -0
- package/dist/src/link/category.d.ts +22 -0
- package/dist/src/link/category.js +30 -0
- package/dist/src/link/file.d.ts +98 -0
- package/dist/src/link/file.js +272 -0
- package/dist/src/link/galleryImage.d.ts +32 -0
- package/dist/src/link/galleryImage.js +158 -0
- package/dist/src/link/index.d.ts +56 -0
- package/dist/src/link/index.js +133 -0
- package/dist/src/link/redirectTarget.d.ts +51 -0
- package/dist/src/link/redirectTarget.js +101 -0
- package/dist/src/magicLink.d.ts +59 -0
- package/dist/src/magicLink.js +220 -0
- package/dist/src/nested.d.ts +43 -0
- package/dist/src/nested.js +105 -0
- package/dist/src/nowiki/base.d.ts +31 -0
- package/dist/src/nowiki/base.js +93 -0
- package/dist/src/nowiki/comment.d.ts +25 -0
- package/dist/src/nowiki/comment.js +76 -0
- package/dist/src/nowiki/dd.d.ts +8 -0
- package/dist/src/nowiki/dd.js +24 -0
- package/dist/src/nowiki/doubleUnderscore.d.ts +18 -0
- package/dist/src/nowiki/doubleUnderscore.js +101 -0
- package/dist/src/nowiki/hr.d.ts +5 -0
- package/dist/src/nowiki/hr.js +63 -0
- package/dist/src/nowiki/index.d.ts +16 -0
- package/dist/src/nowiki/index.js +27 -0
- package/dist/src/nowiki/list.d.ts +16 -0
- package/dist/src/nowiki/list.js +109 -0
- package/dist/src/nowiki/listBase.d.ts +5 -0
- package/dist/src/nowiki/listBase.js +61 -0
- package/dist/src/nowiki/noinclude.d.ts +10 -0
- package/dist/src/nowiki/noinclude.js +23 -0
- package/dist/src/nowiki/quote.d.ts +19 -0
- package/dist/src/nowiki/quote.js +137 -0
- package/dist/src/onlyinclude.d.ts +16 -0
- package/dist/src/onlyinclude.js +57 -0
- package/dist/src/paramTag/index.d.ts +37 -0
- package/dist/src/paramTag/index.js +77 -0
- package/dist/src/paramTag/inputbox.d.ts +8 -0
- package/dist/src/paramTag/inputbox.js +22 -0
- package/dist/src/parameter.d.ts +70 -0
- package/dist/src/parameter.js +264 -0
- package/dist/src/pre.d.ts +31 -0
- package/dist/src/pre.js +59 -0
- package/dist/src/redirect.d.ts +34 -0
- package/dist/src/redirect.js +119 -0
- package/dist/src/syntax.d.ts +19 -0
- package/dist/src/syntax.js +86 -0
- package/dist/src/table/base.d.ts +27 -0
- package/dist/src/table/base.js +81 -0
- package/dist/src/table/index.d.ts +242 -0
- package/dist/src/table/index.js +498 -0
- package/dist/src/table/td.d.ts +86 -0
- package/dist/src/table/td.js +355 -0
- package/dist/src/table/tr.d.ts +32 -0
- package/dist/src/table/tr.js +58 -0
- package/dist/src/table/trBase.d.ts +53 -0
- package/dist/src/table/trBase.js +156 -0
- package/dist/src/tagPair/ext.d.ts +32 -0
- package/dist/src/tagPair/ext.js +203 -0
- package/dist/src/tagPair/include.d.ts +35 -0
- package/dist/src/tagPair/include.js +74 -0
- package/dist/src/tagPair/index.d.ts +27 -0
- package/dist/src/tagPair/index.js +128 -0
- package/dist/src/transclude.d.ts +166 -0
- package/dist/src/transclude.js +584 -0
- package/dist/util/constants.js +27 -0
- package/dist/util/debug.js +81 -0
- package/dist/util/diff.js +83 -0
- package/dist/util/lint.js +31 -0
- package/dist/util/string.js +60 -0
- package/errors/README +1 -0
- package/package.json +17 -29
- package/printed/README +1 -0
- package/bundle/bundle.min.js +0 -38
- package/extensions/dist/base.js +0 -64
- package/extensions/dist/editor.js +0 -159
- package/extensions/dist/highlight.js +0 -58
- package/extensions/dist/lint.js +0 -72
- package/extensions/editor.css +0 -64
- package/extensions/ui.css +0 -144
|
@@ -0,0 +1,272 @@
|
|
|
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 debug_1 = require("../../util/debug");
|
|
7
|
+
const constants_1 = require("../../util/constants");
|
|
8
|
+
const index_1 = require("../../index");
|
|
9
|
+
const base_1 = require("./base");
|
|
10
|
+
const imageParameter_1 = require("../imageParameter");
|
|
11
|
+
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']);
|
|
12
|
+
/**
|
|
13
|
+
* a more sophisticated string-explode function
|
|
14
|
+
* @param start start syntax of a nested AST node
|
|
15
|
+
* @param end end syntax of a nested AST node
|
|
16
|
+
* @param separator syntax for explosion
|
|
17
|
+
* @param str string to be exploded
|
|
18
|
+
*/
|
|
19
|
+
const explode = (start, end, separator, str) => {
|
|
20
|
+
if (str === undefined) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
const regex = new RegExp(`${[start, end, separator].map(string_1.escapeRegExp).join('|')}`, 'gu'), exploded = [];
|
|
24
|
+
let mt = regex.exec(str), depth = 0, lastIndex = 0;
|
|
25
|
+
while (mt) {
|
|
26
|
+
const { 0: match, index } = mt;
|
|
27
|
+
if (match !== separator) {
|
|
28
|
+
depth += match === start ? 1 : -1;
|
|
29
|
+
}
|
|
30
|
+
else if (depth === 0) {
|
|
31
|
+
exploded.push(str.slice(lastIndex, index));
|
|
32
|
+
({ lastIndex } = regex);
|
|
33
|
+
}
|
|
34
|
+
mt = regex.exec(str);
|
|
35
|
+
}
|
|
36
|
+
exploded.push(str.slice(lastIndex));
|
|
37
|
+
return exploded;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* 图片
|
|
41
|
+
* @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
|
|
42
|
+
*/
|
|
43
|
+
class FileToken extends base_1.LinkBaseToken {
|
|
44
|
+
type = 'file';
|
|
45
|
+
/* NOT FOR BROWSER END */
|
|
46
|
+
/** 扩展名 */
|
|
47
|
+
get extension() {
|
|
48
|
+
return this.getTitle().extension;
|
|
49
|
+
}
|
|
50
|
+
/* NOT FOR BROWSER */
|
|
51
|
+
/** 图片链接 */
|
|
52
|
+
get link() {
|
|
53
|
+
return this.getArg('link')?.link ?? super.link;
|
|
54
|
+
}
|
|
55
|
+
set link(value) {
|
|
56
|
+
this.setValue('link', value);
|
|
57
|
+
}
|
|
58
|
+
/** 图片大小 */
|
|
59
|
+
get size() {
|
|
60
|
+
return this.getArg('width')?.size;
|
|
61
|
+
}
|
|
62
|
+
set size(size) {
|
|
63
|
+
this.setValue('width', size && size.width + (size.height && 'x') + size.height);
|
|
64
|
+
}
|
|
65
|
+
/** 图片宽度 */
|
|
66
|
+
get width() {
|
|
67
|
+
return this.size?.width;
|
|
68
|
+
}
|
|
69
|
+
set width(width) {
|
|
70
|
+
const arg = this.getArg('width');
|
|
71
|
+
if (arg) {
|
|
72
|
+
arg.width = width;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.setValue('width', width);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** 图片高度 */
|
|
79
|
+
get height() {
|
|
80
|
+
return this.size?.height;
|
|
81
|
+
}
|
|
82
|
+
set height(height) {
|
|
83
|
+
const arg = this.getArg('width');
|
|
84
|
+
if (arg) {
|
|
85
|
+
arg.height = height;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this.setValue('width', height && `x${height}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/* NOT FOR BROWSER END */
|
|
92
|
+
/**
|
|
93
|
+
* @param link 文件名
|
|
94
|
+
* @param text 图片参数
|
|
95
|
+
* @param delimiter `|`
|
|
96
|
+
*/
|
|
97
|
+
constructor(link, text, config = index_1.default.getConfig(), accum = [], delimiter = '|') {
|
|
98
|
+
super(link, undefined, config, accum, delimiter);
|
|
99
|
+
/* NOT FOR BROWSER */
|
|
100
|
+
this.setAttribute('acceptable', { AtomToken: 0, ImageParameterToken: '1:' });
|
|
101
|
+
/* NOT FOR BROWSER END */
|
|
102
|
+
const { extension } = this.getTitle(true);
|
|
103
|
+
this.append(...explode('-{', '}-', '|', text).map(
|
|
104
|
+
// @ts-expect-error abstract class
|
|
105
|
+
part => new imageParameter_1.ImageParameterToken(part, extension, config, accum)));
|
|
106
|
+
}
|
|
107
|
+
/** @override */
|
|
108
|
+
lint(start = this.getAbsoluteIndex(), re) {
|
|
109
|
+
const errors = super.lint(start, re), args = this.getAllArgs().filter(({ childNodes }) => {
|
|
110
|
+
const visibleNodes = childNodes.filter(node => node.text().trim());
|
|
111
|
+
return visibleNodes.length !== 1 || visibleNodes[0].type !== 'arg';
|
|
112
|
+
}), 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));
|
|
113
|
+
if (this.closest('ext-link-text') && this.getValue('link')?.trim() !== '') {
|
|
114
|
+
errors.push((0, lint_1.generateForSelf)(this, { start }, 'nested-link', 'internal link in an external link'));
|
|
115
|
+
}
|
|
116
|
+
if (args.length === keys.length
|
|
117
|
+
&& frameKeys.length < 2
|
|
118
|
+
&& horizAlignKeys.length < 2
|
|
119
|
+
&& vertAlignKeys.length < 2) {
|
|
120
|
+
return errors;
|
|
121
|
+
}
|
|
122
|
+
const rect = { start, ...this.getRootNode().posFromIndex(start) };
|
|
123
|
+
/**
|
|
124
|
+
* 图片参数到语法错误的映射
|
|
125
|
+
* @param msg 消息键
|
|
126
|
+
* @param p1 替换$1
|
|
127
|
+
*/
|
|
128
|
+
const generate = (msg, p1) => (arg) => (0, lint_1.generateForChild)(arg, rect, 'no-duplicate', index_1.default.msg(`${msg} image $1 parameter`, p1));
|
|
129
|
+
for (const key of keys) {
|
|
130
|
+
let relevantArgs = args.filter(({ name }) => name === key);
|
|
131
|
+
if (key === 'caption') {
|
|
132
|
+
relevantArgs = [...relevantArgs.slice(0, -1).filter(arg => arg.text()), ...relevantArgs.slice(-1)];
|
|
133
|
+
}
|
|
134
|
+
if (relevantArgs.length > 1) {
|
|
135
|
+
errors.push(...relevantArgs.map(generate('duplicated', key)));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (frameKeys.length > 1) {
|
|
139
|
+
errors.push(...args.filter(({ name }) => frame.has(name)).map(generate('conflicting', 'frame')));
|
|
140
|
+
}
|
|
141
|
+
if (horizAlignKeys.length > 1) {
|
|
142
|
+
errors.push(...args.filter(({ name }) => horizAlign.has(name)).map(generate('conflicting', 'horizontal-alignment')));
|
|
143
|
+
}
|
|
144
|
+
if (vertAlignKeys.length > 1) {
|
|
145
|
+
errors.push(...args.filter(({ name }) => vertAlign.has(name)).map(generate('conflicting', 'vertical-alignment')));
|
|
146
|
+
}
|
|
147
|
+
return errors;
|
|
148
|
+
}
|
|
149
|
+
/** 获取所有图片参数节点 */
|
|
150
|
+
getAllArgs() {
|
|
151
|
+
return this.childNodes.slice(1);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* 获取指定图片参数
|
|
155
|
+
* @param key 参数名
|
|
156
|
+
*/
|
|
157
|
+
getArgs(key) {
|
|
158
|
+
return this.getAllArgs().filter(({ name }) => key === name);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* 获取特定类型的图片属性参数节点
|
|
162
|
+
* @param keys 接受的参数名
|
|
163
|
+
* @param type 类型名
|
|
164
|
+
*/
|
|
165
|
+
#getTypedArgs(keys, type) {
|
|
166
|
+
const args = this.getAllArgs().filter(({ name }) => keys.has(name));
|
|
167
|
+
/* NOT FOR BROWSER */
|
|
168
|
+
if (args.length > 1) {
|
|
169
|
+
index_1.default.warn(`图片 ${this.name} 带有 ${args.length} 个${type}参数,只有最后 1 个 ${args[0].name} 会生效!`);
|
|
170
|
+
}
|
|
171
|
+
/* NOT FOR BROWSER END */
|
|
172
|
+
return args;
|
|
173
|
+
}
|
|
174
|
+
/** 获取图片框架属性参数节点 */
|
|
175
|
+
getFrameArgs() {
|
|
176
|
+
return this.#getTypedArgs(frame, '框架');
|
|
177
|
+
}
|
|
178
|
+
/** 获取图片水平对齐参数节点 */
|
|
179
|
+
getHorizAlignArgs() {
|
|
180
|
+
return this.#getTypedArgs(horizAlign, '水平对齐');
|
|
181
|
+
}
|
|
182
|
+
/** 获取图片垂直对齐参数节点 */
|
|
183
|
+
getVertAlignArgs() {
|
|
184
|
+
return this.#getTypedArgs(vertAlign, '垂直对齐');
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* 获取生效的指定图片参数
|
|
188
|
+
* @param key 参数名
|
|
189
|
+
*/
|
|
190
|
+
getArg(key) {
|
|
191
|
+
const args = this.getArgs(key);
|
|
192
|
+
return args[args.length - 1];
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* 获取生效的指定图片参数值
|
|
196
|
+
* @param key 参数名
|
|
197
|
+
*/
|
|
198
|
+
getValue(key) {
|
|
199
|
+
return this.getArg(key)?.getValue();
|
|
200
|
+
}
|
|
201
|
+
/* NOT FOR BROWSER */
|
|
202
|
+
/**
|
|
203
|
+
* 是否具有指定图片参数
|
|
204
|
+
* @param key 参数名
|
|
205
|
+
*/
|
|
206
|
+
hasArg(key) {
|
|
207
|
+
return this.getArgs(key).length > 0;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* 移除指定图片参数
|
|
211
|
+
* @param key 参数名
|
|
212
|
+
*/
|
|
213
|
+
removeArg(key) {
|
|
214
|
+
for (const token of this.getArgs(key)) {
|
|
215
|
+
this.removeChild(token);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/** 获取图片参数名 */
|
|
219
|
+
getKeys() {
|
|
220
|
+
return new Set(this.getAllArgs().map(({ name }) => name));
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* 获取指定的图片参数值
|
|
224
|
+
* @param key 参数名
|
|
225
|
+
*/
|
|
226
|
+
getValues(key) {
|
|
227
|
+
return this.getArgs(key).map(token => token.getValue());
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* 设置图片参数
|
|
231
|
+
* @param key 参数名
|
|
232
|
+
* @param value 参数值
|
|
233
|
+
* @throws `RangeError` 未定义的图片参数
|
|
234
|
+
*/
|
|
235
|
+
setValue(key, value = false) {
|
|
236
|
+
if (value === false) {
|
|
237
|
+
this.removeArg(key);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const token = this.getArg(key);
|
|
241
|
+
if (token) {
|
|
242
|
+
token.setValue(value);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const config = this.getAttribute('config'), syntax = key === 'caption' ? '$1' : Object.entries(config.img).find(([, name]) => name === key)?.[0];
|
|
246
|
+
if (syntax === undefined) {
|
|
247
|
+
throw new RangeError(`未定义的图片参数: ${key}`);
|
|
248
|
+
}
|
|
249
|
+
const free = syntax.includes('$1');
|
|
250
|
+
if (value === true && free) {
|
|
251
|
+
this.typeError('setValue', 'String');
|
|
252
|
+
}
|
|
253
|
+
const parameter = debug_1.Shadow.run(
|
|
254
|
+
// @ts-expect-error abstract class
|
|
255
|
+
() => new imageParameter_1.ImageParameterToken(syntax.replace('$1', ''), this.extension, config));
|
|
256
|
+
if (free) {
|
|
257
|
+
const { childNodes } = index_1.default.parse(value, this.getAttribute('include'), undefined, config);
|
|
258
|
+
parameter.replaceChildren(...childNodes);
|
|
259
|
+
}
|
|
260
|
+
parameter.afterBuild();
|
|
261
|
+
this.insertAt(parameter);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* @override
|
|
265
|
+
* @throws `Error` 不适用于图片
|
|
266
|
+
*/
|
|
267
|
+
setLinkText() {
|
|
268
|
+
throw new Error('setLinkText 方法不适用于图片!');
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
exports.FileToken = FileToken;
|
|
272
|
+
constants_1.classes['FileToken'] = __filename;
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
#private;
|
|
11
|
+
type: `${GalleryTypes}-image`;
|
|
12
|
+
/** 图片链接 */
|
|
13
|
+
get link(): string | Title;
|
|
14
|
+
set link(value: string);
|
|
15
|
+
/**
|
|
16
|
+
* @param type 图片类型
|
|
17
|
+
* @param link 图片文件名
|
|
18
|
+
* @param text 图片参数
|
|
19
|
+
*/
|
|
20
|
+
constructor(type: GalleryTypes, link: string, text?: string, config?: Parser.Config, accum?: Token[]);
|
|
21
|
+
/** @override */
|
|
22
|
+
lint(start?: number, re?: RegExp): LintError[];
|
|
23
|
+
/**
|
|
24
|
+
* @override
|
|
25
|
+
* @param token 待插入的子节点
|
|
26
|
+
* @param i 插入位置
|
|
27
|
+
* @throws `RangeError` 不可插入多余子节点
|
|
28
|
+
* @throws `TypeError` 不可插入文本节点
|
|
29
|
+
*/
|
|
30
|
+
insertAt<T extends AtomToken | ImageParameterToken>(child: T, i?: number): T;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,158 @@
|
|
|
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 debug_1 = require("../../util/debug");
|
|
41
|
+
const singleLine_1 = require("../../mixin/singleLine");
|
|
42
|
+
const index_1 = require("../../index");
|
|
43
|
+
const index_2 = require("../index");
|
|
44
|
+
const file_1 = require("./file");
|
|
45
|
+
const imageParameter_1 = require("../imageParameter");
|
|
46
|
+
/** 图库图片 */
|
|
47
|
+
let GalleryImageToken = (() => {
|
|
48
|
+
let _classDecorators = [singleLine_1.singleLine];
|
|
49
|
+
let _classDescriptor;
|
|
50
|
+
let _classExtraInitializers = [];
|
|
51
|
+
let _classThis;
|
|
52
|
+
let _classSuper = file_1.FileToken;
|
|
53
|
+
var GalleryImageToken = class extends _classSuper {
|
|
54
|
+
static { _classThis = this; }
|
|
55
|
+
static {
|
|
56
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
57
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
58
|
+
GalleryImageToken = _classThis = _classDescriptor.value;
|
|
59
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
60
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
61
|
+
}
|
|
62
|
+
/* NOT FOR BROWSER */
|
|
63
|
+
/** 图片链接 */
|
|
64
|
+
get link() {
|
|
65
|
+
return this.type === 'imagemap-image' ? '' : super.link;
|
|
66
|
+
}
|
|
67
|
+
set link(value) {
|
|
68
|
+
if (this.type !== 'imagemap-image') {
|
|
69
|
+
super.link = value;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/* NOT FOR BROWSER END */
|
|
73
|
+
/**
|
|
74
|
+
* @param type 图片类型
|
|
75
|
+
* @param link 图片文件名
|
|
76
|
+
* @param text 图片参数
|
|
77
|
+
*/
|
|
78
|
+
constructor(type, link, text, config = index_1.default.getConfig(), accum = []) {
|
|
79
|
+
let token;
|
|
80
|
+
if (text !== undefined) {
|
|
81
|
+
const { length } = accum;
|
|
82
|
+
token = new index_2.Token(text, config, accum);
|
|
83
|
+
token.type = 'plain';
|
|
84
|
+
for (let n = 1; n < constants_1.MAX_STAGE; n++) {
|
|
85
|
+
token.parseOnce();
|
|
86
|
+
}
|
|
87
|
+
accum.splice(length, 1);
|
|
88
|
+
}
|
|
89
|
+
super(link, token?.toString(), config, accum);
|
|
90
|
+
this.setAttribute('bracket', false);
|
|
91
|
+
this.type = `${type}-image`;
|
|
92
|
+
}
|
|
93
|
+
/** @private */
|
|
94
|
+
getTitle() {
|
|
95
|
+
const imagemap = this.type === 'imagemap-image';
|
|
96
|
+
return this.normalizeTitle(String(this.firstChild), imagemap ? 0 : 6, true, !imagemap);
|
|
97
|
+
}
|
|
98
|
+
/** @private */
|
|
99
|
+
getAttribute(key) {
|
|
100
|
+
return key === 'padding' ? 0 : super.getAttribute(key);
|
|
101
|
+
}
|
|
102
|
+
/** @override */
|
|
103
|
+
lint(start = this.getAbsoluteIndex(), re) {
|
|
104
|
+
const errors = super.lint(start, re), { ns, interwiki } = this.getAttribute('title');
|
|
105
|
+
if (interwiki || ns !== 6) {
|
|
106
|
+
errors.push((0, lint_1.generateForSelf)(this, { start }, 'invalid-gallery', 'invalid gallery image'));
|
|
107
|
+
}
|
|
108
|
+
return errors;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 设置`#title`
|
|
112
|
+
* @param title Title对象
|
|
113
|
+
*/
|
|
114
|
+
#setName(title) {
|
|
115
|
+
this.setAttribute('title', title);
|
|
116
|
+
/* NOT FOR BROWSER */
|
|
117
|
+
this.setAttribute('name', title.title);
|
|
118
|
+
}
|
|
119
|
+
/** @private */
|
|
120
|
+
afterBuild() {
|
|
121
|
+
this.#setName(this.getTitle());
|
|
122
|
+
/* NOT FOR BROWSER */
|
|
123
|
+
const /** @implements */ linkListener = (e, data) => {
|
|
124
|
+
const { prevTarget } = e;
|
|
125
|
+
if (prevTarget?.type === 'link-target') {
|
|
126
|
+
const name = String(prevTarget), title = this.getTitle(), { interwiki, ns, valid } = title;
|
|
127
|
+
if (!valid) {
|
|
128
|
+
(0, debug_1.undo)(e, data);
|
|
129
|
+
throw new Error(`非法的图片文件名:${name}`);
|
|
130
|
+
}
|
|
131
|
+
else if (interwiki || ns !== 6) {
|
|
132
|
+
(0, debug_1.undo)(e, data);
|
|
133
|
+
throw new Error(`图片链接不可更改命名空间:${name}`);
|
|
134
|
+
}
|
|
135
|
+
this.#setName(title);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
this.addEventListener(['remove', 'insert', 'replace', 'text'], linkListener);
|
|
139
|
+
}
|
|
140
|
+
/* NOT FOR BROWSER */
|
|
141
|
+
/**
|
|
142
|
+
* @override
|
|
143
|
+
* @param token 待插入的子节点
|
|
144
|
+
* @param i 插入位置
|
|
145
|
+
* @throws `RangeError` 不可插入多余子节点
|
|
146
|
+
* @throws `TypeError` 不可插入文本节点
|
|
147
|
+
*/
|
|
148
|
+
insertAt(child, i) {
|
|
149
|
+
if (this.type === 'gallery-image' && child.type === 'image-parameter' && !imageParameter_1.galleryParams.has(child.name)) {
|
|
150
|
+
child.setAttribute('name', 'invalid');
|
|
151
|
+
}
|
|
152
|
+
return super.insertAt(child, i);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
return GalleryImageToken = _classThis;
|
|
156
|
+
})();
|
|
157
|
+
exports.GalleryImageToken = GalleryImageToken;
|
|
158
|
+
constants_1.classes['GalleryImageToken'] = __filename;
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
#private;
|
|
11
|
+
readonly type = "link";
|
|
12
|
+
readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token];
|
|
13
|
+
abstract get children(): [AtomToken] | [AtomToken, Token];
|
|
14
|
+
abstract get link(): Title;
|
|
15
|
+
abstract set link(link: string);
|
|
16
|
+
/** 链接显示文字 */
|
|
17
|
+
get innerText(): string;
|
|
18
|
+
set innerText(text: string);
|
|
19
|
+
/** 是否链接到自身 */
|
|
20
|
+
get selfLink(): boolean;
|
|
21
|
+
set selfLink(selfLink: boolean);
|
|
22
|
+
/** @override */
|
|
23
|
+
get fragment(): string | undefined;
|
|
24
|
+
set fragment(fragment: string | undefined);
|
|
25
|
+
/** interwiki */
|
|
26
|
+
get interwiki(): string;
|
|
27
|
+
/** @throws `RangeError` 非法的跨维基前缀 */
|
|
28
|
+
set interwiki(interwiki: string);
|
|
29
|
+
/** @override */
|
|
30
|
+
lint(start?: number, re?: RegExp): LintError[];
|
|
31
|
+
/** @override */
|
|
32
|
+
setTarget(link: string): void;
|
|
33
|
+
/**
|
|
34
|
+
* 设置跨语言链接
|
|
35
|
+
* @param lang 语言前缀
|
|
36
|
+
* @param link 页面标题
|
|
37
|
+
* @throws `SyntaxError` 仅有fragment
|
|
38
|
+
*/
|
|
39
|
+
setLangLink(lang: string, link: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* 设置fragment
|
|
42
|
+
* @param fragment fragment
|
|
43
|
+
*/
|
|
44
|
+
setFragment(fragment?: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* 修改为到自身的链接
|
|
47
|
+
* @param fragment fragment
|
|
48
|
+
* @throws `RangeError` 空fragment
|
|
49
|
+
*/
|
|
50
|
+
asSelfLink(fragment?: string | undefined): void;
|
|
51
|
+
/**
|
|
52
|
+
* 自动生成管道符后的链接文字
|
|
53
|
+
* @throws `Error` 带有"#"或"%"时不可用
|
|
54
|
+
*/
|
|
55
|
+
pipeTrick(): void;
|
|
56
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
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 base_1 = require("./base");
|
|
7
|
+
/**
|
|
8
|
+
* 内链
|
|
9
|
+
* @classdesc `{childNodes: [AtomToken, ?Token]}`
|
|
10
|
+
*/
|
|
11
|
+
class LinkToken extends base_1.LinkBaseToken {
|
|
12
|
+
type = 'link';
|
|
13
|
+
/** 链接显示文字 */
|
|
14
|
+
get innerText() {
|
|
15
|
+
return this.length > 1 ? this.lastChild.text() : this.firstChild.text().replace(/^\s*:?/u, '');
|
|
16
|
+
}
|
|
17
|
+
set innerText(text) {
|
|
18
|
+
this.setLinkText(text);
|
|
19
|
+
}
|
|
20
|
+
/** 是否链接到自身 */
|
|
21
|
+
get selfLink() {
|
|
22
|
+
const { link: { title, fragment } } = this;
|
|
23
|
+
return !title && Boolean(fragment);
|
|
24
|
+
}
|
|
25
|
+
set selfLink(selfLink) {
|
|
26
|
+
if (selfLink) {
|
|
27
|
+
this.asSelfLink();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** @override */
|
|
31
|
+
get fragment() {
|
|
32
|
+
return super.fragment;
|
|
33
|
+
}
|
|
34
|
+
set fragment(fragment) {
|
|
35
|
+
this.#setFragment(fragment);
|
|
36
|
+
}
|
|
37
|
+
/** interwiki */
|
|
38
|
+
get interwiki() {
|
|
39
|
+
return this.link.interwiki;
|
|
40
|
+
}
|
|
41
|
+
/** @throws `RangeError` 非法的跨维基前缀 */
|
|
42
|
+
set interwiki(interwiki) {
|
|
43
|
+
const { link: { prefix, main, fragment } } = this, link = `${interwiki}:${prefix}${main}${fragment === undefined ? '' : `#${fragment}`}`;
|
|
44
|
+
if (interwiki && !this.isInterwiki(link)) {
|
|
45
|
+
throw new RangeError(`${interwiki} 不是合法的跨维基前缀!`);
|
|
46
|
+
}
|
|
47
|
+
this.setTarget(link);
|
|
48
|
+
}
|
|
49
|
+
/* NOT FOR BROWSER END */
|
|
50
|
+
/** @override */
|
|
51
|
+
lint(start = this.getAbsoluteIndex(), re) {
|
|
52
|
+
const errors = super.lint(start, re);
|
|
53
|
+
if (this.closest('ext-link-text')) {
|
|
54
|
+
errors.push((0, lint_1.generateForSelf)(this, { start }, 'nested-link', 'internal link in an external link'));
|
|
55
|
+
}
|
|
56
|
+
return errors;
|
|
57
|
+
}
|
|
58
|
+
/* NOT FOR BROWSER */
|
|
59
|
+
/** @override */
|
|
60
|
+
setTarget(link) {
|
|
61
|
+
super.setTarget((/^\s*[:#]/u.test(link) ? '' : ':') + link);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 设置跨语言链接
|
|
65
|
+
* @param lang 语言前缀
|
|
66
|
+
* @param link 页面标题
|
|
67
|
+
* @throws `SyntaxError` 仅有fragment
|
|
68
|
+
*/
|
|
69
|
+
setLangLink(lang, link) {
|
|
70
|
+
link = link.trim();
|
|
71
|
+
if (link.startsWith('#')) {
|
|
72
|
+
throw new SyntaxError('跨语言链接不能仅为fragment!');
|
|
73
|
+
}
|
|
74
|
+
super.setTarget(lang + (link.startsWith(':') ? '' : ':') + link);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 设置fragment
|
|
78
|
+
* @param fragment fragment
|
|
79
|
+
* @param page 是否是其他页面
|
|
80
|
+
*/
|
|
81
|
+
#setFragment(fragment, page = true) {
|
|
82
|
+
fragment &&= fragment.replace(/[<>[\]#|=]/gu, p => encodeURIComponent(p));
|
|
83
|
+
this.setTarget(`${page ? this.name : ''}${fragment === undefined ? '' : `#${fragment}`}`);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 设置fragment
|
|
87
|
+
* @param fragment fragment
|
|
88
|
+
*/
|
|
89
|
+
setFragment(fragment) {
|
|
90
|
+
this.#setFragment(fragment);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 修改为到自身的链接
|
|
94
|
+
* @param fragment fragment
|
|
95
|
+
* @throws `RangeError` 空fragment
|
|
96
|
+
*/
|
|
97
|
+
asSelfLink(fragment = this.fragment) {
|
|
98
|
+
if (!fragment?.trim()) {
|
|
99
|
+
throw new RangeError('asSelfLink 方法必须指定非空的 fragment!');
|
|
100
|
+
}
|
|
101
|
+
this.#setFragment(fragment, false);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 自动生成管道符后的链接文字
|
|
105
|
+
* @throws `Error` 带有"#"或"%"时不可用
|
|
106
|
+
*/
|
|
107
|
+
pipeTrick() {
|
|
108
|
+
const linkText = this.firstChild.text();
|
|
109
|
+
if (linkText.includes('#') || linkText.includes('%')) {
|
|
110
|
+
throw new Error('Pipe trick 不能用于带有"#"或"%"的场合!');
|
|
111
|
+
}
|
|
112
|
+
const m1 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+)\(.+\)$/u.exec(linkText);
|
|
113
|
+
if (m1) {
|
|
114
|
+
this.setLinkText(m1[1].trim());
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const m2 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+)(.+)$/u.exec(linkText);
|
|
118
|
+
if (m2) {
|
|
119
|
+
this.setLinkText(m2[1].trim());
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
// eslint-disable-next-line es-x/no-regexp-lookbehind-assertions
|
|
123
|
+
const m3 = /^:?(?:[ \w\x80-\xFF-]+:)?(.+?)(?:(?<!\()\(.+\))?(?:, |,|، )./u
|
|
124
|
+
.exec(linkText);
|
|
125
|
+
if (m3) {
|
|
126
|
+
this.setLinkText(m3[1].trim());
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
this.setLinkText(linkText);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.LinkToken = LinkToken;
|
|
133
|
+
constants_1.classes['LinkToken'] = __filename;
|