wikilint 2.16.3 → 2.16.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/coverage/badge.svg +1 -1
- package/data/signatures.json +43 -0
- package/dist/base.d.mts +84 -27
- package/dist/base.d.ts +84 -27
- package/dist/bin/cli.js +2 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +55 -11
- package/dist/lib/element.d.ts +56 -10
- package/dist/lib/element.js +97 -11
- package/dist/lib/lsp.d.ts +62 -27
- package/dist/lib/lsp.js +395 -304
- package/dist/lib/node.d.ts +51 -19
- package/dist/lib/node.js +80 -34
- package/dist/lib/text.d.ts +8 -2
- package/dist/lib/text.js +10 -3
- package/dist/lib/title.d.ts +23 -9
- package/dist/lib/title.js +56 -21
- package/dist/mixin/attributesParent.d.ts +4 -4
- package/dist/mixin/attributesParent.js +2 -4
- package/dist/mixin/hidden.d.ts +0 -2
- package/dist/mixin/hidden.js +0 -2
- package/dist/parser/braces.js +4 -2
- package/dist/parser/links.js +8 -7
- package/dist/parser/list.js +3 -1
- package/dist/parser/quotes.js +2 -1
- package/dist/parser/redirect.js +4 -1
- package/dist/src/arg.d.ts +4 -2
- package/dist/src/arg.js +8 -4
- package/dist/src/atom.d.ts +5 -1
- package/dist/src/atom.js +5 -1
- package/dist/src/attribute.d.ts +9 -3
- package/dist/src/attribute.js +9 -3
- package/dist/src/attributes.d.ts +12 -4
- package/dist/src/attributes.js +12 -4
- package/dist/src/converter.d.ts +3 -1
- package/dist/src/converter.js +8 -5
- package/dist/src/converterFlags.d.ts +13 -3
- package/dist/src/converterFlags.js +13 -3
- package/dist/src/converterRule.d.ts +3 -1
- package/dist/src/converterRule.js +3 -1
- package/dist/src/extLink.d.ts +2 -0
- package/dist/src/extLink.js +2 -0
- package/dist/src/gallery.d.ts +3 -1
- package/dist/src/gallery.js +7 -5
- package/dist/src/heading.d.ts +3 -1
- package/dist/src/heading.js +10 -8
- package/dist/src/hidden.d.ts +5 -1
- package/dist/src/hidden.js +5 -1
- package/dist/src/html.d.ts +9 -2
- package/dist/src/html.js +201 -146
- package/dist/src/imageParameter.d.ts +11 -3
- package/dist/src/imageParameter.js +12 -4
- package/dist/src/imagemap.d.ts +1 -1
- package/dist/src/imagemap.js +5 -4
- package/dist/src/imagemapLink.d.ts +2 -0
- package/dist/src/imagemapLink.js +2 -0
- package/dist/src/index.d.ts +5 -24
- package/dist/src/index.js +28 -73
- package/dist/src/link/base.d.ts +5 -1
- package/dist/src/link/base.js +17 -7
- package/dist/src/link/category.d.ts +4 -0
- package/dist/src/link/category.js +2 -0
- package/dist/src/link/file.d.ts +17 -7
- package/dist/src/link/file.js +28 -14
- package/dist/src/link/galleryImage.d.ts +5 -1
- package/dist/src/link/galleryImage.js +9 -5
- package/dist/src/link/index.d.ts +4 -0
- package/dist/src/link/index.js +2 -0
- package/dist/src/link/redirectTarget.d.ts +3 -1
- package/dist/src/link/redirectTarget.js +4 -2
- package/dist/src/magicLink.d.ts +12 -3
- package/dist/src/magicLink.js +36 -7
- package/dist/src/nested.d.ts +3 -1
- package/dist/src/nested.js +7 -4
- package/dist/src/nowiki/base.d.ts +3 -1
- package/dist/src/nowiki/base.js +3 -1
- package/dist/src/nowiki/comment.d.ts +5 -1
- package/dist/src/nowiki/comment.js +5 -1
- package/dist/src/nowiki/doubleUnderscore.d.ts +5 -1
- package/dist/src/nowiki/doubleUnderscore.js +5 -1
- package/dist/src/nowiki/index.d.ts +5 -1
- package/dist/src/nowiki/index.js +5 -1
- package/dist/src/nowiki/list.d.ts +5 -1
- package/dist/src/nowiki/list.js +5 -1
- package/dist/src/nowiki/noinclude.d.ts +5 -1
- package/dist/src/nowiki/noinclude.js +5 -1
- package/dist/src/nowiki/quote.d.ts +5 -1
- package/dist/src/nowiki/quote.js +5 -1
- package/dist/src/onlyinclude.d.ts +3 -1
- package/dist/src/onlyinclude.js +3 -1
- package/dist/src/paramTag/index.d.ts +1 -1
- package/dist/src/paramTag/index.js +1 -1
- package/dist/src/parameter.d.ts +3 -1
- package/dist/src/parameter.js +3 -1
- package/dist/src/pre.d.ts +1 -1
- package/dist/src/pre.js +1 -1
- package/dist/src/redirect.d.ts +2 -0
- package/dist/src/redirect.js +2 -0
- package/dist/src/syntax.d.ts +5 -1
- package/dist/src/syntax.js +5 -1
- package/dist/src/table/base.js +3 -1
- package/dist/src/table/index.d.ts +20 -15
- package/dist/src/table/index.js +22 -23
- package/dist/src/table/td.d.ts +9 -3
- package/dist/src/table/td.js +9 -3
- package/dist/src/table/tr.d.ts +3 -1
- package/dist/src/table/tr.js +4 -2
- package/dist/src/table/trBase.d.ts +9 -9
- package/dist/src/table/trBase.js +13 -18
- package/dist/src/tagPair/ext.d.ts +6 -1
- package/dist/src/tagPair/ext.js +151 -98
- package/dist/src/tagPair/include.d.ts +2 -0
- package/dist/src/tagPair/include.js +2 -0
- package/dist/src/tagPair/index.d.ts +6 -2
- package/dist/src/tagPair/index.js +6 -2
- package/dist/src/transclude.d.ts +39 -10
- package/dist/src/transclude.js +69 -18
- package/dist/util/debug.js +2 -16
- package/dist/util/string.js +2 -0
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +3 -2
- package/dist/bin/coverage.js +0 -20
package/dist/src/index.js
CHANGED
|
@@ -50,8 +50,10 @@ const index_1 = require("../index");
|
|
|
50
50
|
const element_1 = require("../lib/element");
|
|
51
51
|
const text_1 = require("../lib/text");
|
|
52
52
|
/**
|
|
53
|
+
* base class for all tokens
|
|
54
|
+
*
|
|
53
55
|
* 所有节点的基类
|
|
54
|
-
* @classdesc `{childNodes:
|
|
56
|
+
* @classdesc `{childNodes: (AstText|Token)[]}`
|
|
55
57
|
*/
|
|
56
58
|
class Token extends element_1.AstElement {
|
|
57
59
|
#type = 'plain';
|
|
@@ -80,7 +82,7 @@ class Token extends element_1.AstElement {
|
|
|
80
82
|
accum.push(this);
|
|
81
83
|
}
|
|
82
84
|
/** @private */
|
|
83
|
-
parseOnce(n = this.#stage, include = false) {
|
|
85
|
+
parseOnce(n = this.#stage, include = false, tidy) {
|
|
84
86
|
if (n < this.#stage || this.length === 0 || !this.getAttribute('plain')) {
|
|
85
87
|
return this;
|
|
86
88
|
}
|
|
@@ -110,10 +112,10 @@ class Token extends element_1.AstElement {
|
|
|
110
112
|
this.#parseHrAndDoubleUnderscore();
|
|
111
113
|
break;
|
|
112
114
|
case 5:
|
|
113
|
-
this.#parseLinks();
|
|
115
|
+
this.#parseLinks(tidy);
|
|
114
116
|
break;
|
|
115
117
|
case 6:
|
|
116
|
-
this.#parseQuotes();
|
|
118
|
+
this.#parseQuotes(tidy);
|
|
117
119
|
break;
|
|
118
120
|
case 7:
|
|
119
121
|
this.#parseExternalLinks();
|
|
@@ -130,7 +132,7 @@ class Token extends element_1.AstElement {
|
|
|
130
132
|
}
|
|
131
133
|
if (this.type === 'root') {
|
|
132
134
|
for (const token of this.#accum) {
|
|
133
|
-
token?.parseOnce(n, include); // eslint-disable-line @typescript-eslint/no-unnecessary-condition
|
|
135
|
+
token?.parseOnce(n, include, tidy); // eslint-disable-line @typescript-eslint/no-unnecessary-condition
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
138
|
this.#stage++;
|
|
@@ -179,10 +181,10 @@ class Token extends element_1.AstElement {
|
|
|
179
181
|
this.#built = true;
|
|
180
182
|
}
|
|
181
183
|
/** @private */
|
|
182
|
-
parse(n = constants_1.MAX_STAGE, include) {
|
|
184
|
+
parse(n = constants_1.MAX_STAGE, include, tidy) {
|
|
183
185
|
n = Math.min(n, constants_1.MAX_STAGE);
|
|
184
186
|
while (this.#stage < n) {
|
|
185
|
-
this.parseOnce(this.#stage, include);
|
|
187
|
+
this.parseOnce(this.#stage, include, tidy);
|
|
186
188
|
}
|
|
187
189
|
if (n) {
|
|
188
190
|
this.build();
|
|
@@ -237,20 +239,26 @@ class Token extends element_1.AstElement {
|
|
|
237
239
|
const { parseHrAndDoubleUnderscore } = require('../parser/hrAndDoubleUnderscore');
|
|
238
240
|
this.setText(parseHrAndDoubleUnderscore(this, this.#config, this.#accum));
|
|
239
241
|
}
|
|
240
|
-
/**
|
|
241
|
-
|
|
242
|
+
/**
|
|
243
|
+
* 解析内部链接
|
|
244
|
+
* @param tidy 是否整理
|
|
245
|
+
*/
|
|
246
|
+
#parseLinks(tidy) {
|
|
242
247
|
const { parseLinks } = require('../parser/links');
|
|
243
|
-
this.setText(parseLinks(this.firstChild.toString(), this.#config, this.#accum));
|
|
248
|
+
this.setText(parseLinks(this.firstChild.toString(), this.#config, this.#accum, tidy));
|
|
244
249
|
}
|
|
245
|
-
/**
|
|
246
|
-
|
|
250
|
+
/**
|
|
251
|
+
* 解析单引号
|
|
252
|
+
* @param tidy 是否整理
|
|
253
|
+
*/
|
|
254
|
+
#parseQuotes(tidy) {
|
|
247
255
|
if (this.#config.excludes?.includes('quote')) {
|
|
248
256
|
return;
|
|
249
257
|
}
|
|
250
258
|
const { parseQuotes } = require('../parser/quotes');
|
|
251
259
|
const lines = this.firstChild.toString().split('\n');
|
|
252
260
|
for (let i = 0; i < lines.length; i++) {
|
|
253
|
-
lines[i] = parseQuotes(lines[i], this.#config, this.#accum);
|
|
261
|
+
lines[i] = parseQuotes(lines[i], this.#config, this.#accum, tidy);
|
|
254
262
|
}
|
|
255
263
|
this.setText(lines.join('\n'));
|
|
256
264
|
}
|
|
@@ -276,8 +284,8 @@ class Token extends element_1.AstElement {
|
|
|
276
284
|
return;
|
|
277
285
|
}
|
|
278
286
|
const { parseList } = require('../parser/list');
|
|
279
|
-
const lines =
|
|
280
|
-
let i =
|
|
287
|
+
const { firstChild, type, name } = this, lines = firstChild.toString().split('\n'), state = { lastPrefix: '' };
|
|
288
|
+
let i = type === 'root' || type === 'ext-inner' && name === 'poem' ? 0 : 1;
|
|
281
289
|
for (; i < lines.length; i++) {
|
|
282
290
|
lines[i] = parseList(lines[i], state, this.#config, this.#accum);
|
|
283
291
|
}
|
|
@@ -323,14 +331,16 @@ class Token extends element_1.AstElement {
|
|
|
323
331
|
insertAt(child, i = this.length) {
|
|
324
332
|
const token = typeof child === 'string' ? new text_1.AstText(child) : child;
|
|
325
333
|
super.insertAt(token, i);
|
|
326
|
-
|
|
334
|
+
const { type, } = token;
|
|
335
|
+
if (type === 'root') {
|
|
327
336
|
token.type = 'plain';
|
|
328
337
|
}
|
|
329
338
|
return token;
|
|
330
339
|
}
|
|
331
340
|
/** @private */
|
|
332
|
-
normalizeTitle(title, defaultNs = 0, halfParsed, decode, selfLink) {
|
|
333
|
-
return index_1.default
|
|
341
|
+
normalizeTitle(title, defaultNs = 0, temporary, halfParsed, decode, selfLink) {
|
|
342
|
+
return index_1.default
|
|
343
|
+
.normalizeTitle(title, defaultNs, this.#include, this.#config, temporary, halfParsed, decode, selfLink);
|
|
334
344
|
}
|
|
335
345
|
/** @private */
|
|
336
346
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
@@ -419,60 +429,5 @@ class Token extends element_1.AstElement {
|
|
|
419
429
|
}
|
|
420
430
|
});
|
|
421
431
|
}
|
|
422
|
-
/**
|
|
423
|
-
* 找到给定位置
|
|
424
|
-
* @param index 位置
|
|
425
|
-
*/
|
|
426
|
-
caretPositionFromIndex(index) {
|
|
427
|
-
LSP: { // eslint-disable-line no-unused-labels
|
|
428
|
-
if (index === undefined) {
|
|
429
|
-
return undefined;
|
|
430
|
-
}
|
|
431
|
-
const { length } = this.toString();
|
|
432
|
-
if (index > length || index < -length) {
|
|
433
|
-
return undefined;
|
|
434
|
-
}
|
|
435
|
-
index += index < 0 ? length : 0;
|
|
436
|
-
let self = this, acc = 0, start = 0;
|
|
437
|
-
while (self.type !== 'text') {
|
|
438
|
-
const { childNodes } = self;
|
|
439
|
-
acc += self.getAttribute('padding');
|
|
440
|
-
for (let i = 0; acc < index && i < childNodes.length; i++) {
|
|
441
|
-
const cur = childNodes[i], l = cur.toString().length;
|
|
442
|
-
acc += l;
|
|
443
|
-
if (acc >= index) {
|
|
444
|
-
self = cur;
|
|
445
|
-
acc -= l;
|
|
446
|
-
start = acc;
|
|
447
|
-
break;
|
|
448
|
-
}
|
|
449
|
-
acc += self.getGaps(i);
|
|
450
|
-
}
|
|
451
|
-
if (self.childNodes === childNodes) {
|
|
452
|
-
return { offsetNode: self, offset: index - start };
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
return { offsetNode: self, offset: index - start };
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
/**
|
|
459
|
-
* 找到给定位置所在的最外层节点
|
|
460
|
-
* @param index 位置
|
|
461
|
-
*/
|
|
462
|
-
elementFromIndex(index) {
|
|
463
|
-
LSP: { // eslint-disable-line no-unused-labels
|
|
464
|
-
const node = this.caretPositionFromIndex(index)?.offsetNode;
|
|
465
|
-
return node?.type === 'text' ? node.parentNode : node;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* 找到给定位置所在的最外层节点
|
|
470
|
-
* @param x 列数
|
|
471
|
-
* @param y 行数
|
|
472
|
-
*/
|
|
473
|
-
elementFromPoint(x, y) {
|
|
474
|
-
// eslint-disable-next-line no-unused-labels
|
|
475
|
-
LSP: return this.elementFromIndex(this.indexFromPos(y, x));
|
|
476
|
-
}
|
|
477
432
|
}
|
|
478
433
|
exports.Token = Token;
|
package/dist/src/link/base.d.ts
CHANGED
|
@@ -4,8 +4,10 @@ import { AtomToken } from '../atom';
|
|
|
4
4
|
import type { LintError } from '../../base';
|
|
5
5
|
import type { Title } from '../../lib/title';
|
|
6
6
|
/**
|
|
7
|
+
* internal link
|
|
8
|
+
*
|
|
7
9
|
* 内链
|
|
8
|
-
* @classdesc `{childNodes: [AtomToken, ...Token]}`
|
|
10
|
+
* @classdesc `{childNodes: [AtomToken, ...Token[]]}`
|
|
9
11
|
*/
|
|
10
12
|
export declare abstract class LinkBaseToken extends Token {
|
|
11
13
|
#private;
|
|
@@ -14,6 +16,8 @@ export declare abstract class LinkBaseToken extends Token {
|
|
|
14
16
|
readonly childNodes: readonly [AtomToken, ...Token[]];
|
|
15
17
|
abstract get firstChild(): AtomToken;
|
|
16
18
|
abstract get lastChild(): Token;
|
|
19
|
+
/** full link / 完整链接 */
|
|
20
|
+
get link(): string | Title;
|
|
17
21
|
/**
|
|
18
22
|
* @param link 链接标题
|
|
19
23
|
* @param linkText 链接显示文字
|
package/dist/src/link/base.js
CHANGED
|
@@ -14,13 +14,20 @@ const atom_1 = require("../atom");
|
|
|
14
14
|
*/
|
|
15
15
|
const isLink = (type) => type === 'redirect-target' || type === 'link';
|
|
16
16
|
/**
|
|
17
|
+
* internal link
|
|
18
|
+
*
|
|
17
19
|
* 内链
|
|
18
|
-
* @classdesc `{childNodes: [AtomToken, ...Token]}`
|
|
20
|
+
* @classdesc `{childNodes: [AtomToken, ...Token[]]}`
|
|
19
21
|
*/
|
|
20
22
|
class LinkBaseToken extends index_2.Token {
|
|
21
23
|
#bracket = true;
|
|
22
24
|
#delimiter;
|
|
23
25
|
#title;
|
|
26
|
+
/** full link / 完整链接 */
|
|
27
|
+
get link() {
|
|
28
|
+
// eslint-disable-next-line no-unused-labels
|
|
29
|
+
LSP: return this.#title;
|
|
30
|
+
}
|
|
24
31
|
/**
|
|
25
32
|
* @param link 链接标题
|
|
26
33
|
* @param linkText 链接显示文字
|
|
@@ -91,9 +98,9 @@ class LinkBaseToken extends index_2.Token {
|
|
|
91
98
|
errors.push(e);
|
|
92
99
|
}
|
|
93
100
|
if (type === 'link' || type === 'category') {
|
|
94
|
-
const
|
|
101
|
+
const j = linkText?.childNodes.findIndex(c => c.type === 'text' && c.data.includes('|')), textNode = linkText?.childNodes[j];
|
|
95
102
|
if (textNode) {
|
|
96
|
-
const e = (0, lint_1.generateForChild)(linkText, rect, 'pipe-like', 'additional "|" in the link text', 'warning'), i = e.startIndex +
|
|
103
|
+
const e = (0, lint_1.generateForChild)(linkText, rect, 'pipe-like', 'additional "|" in the link text', 'warning'), i = e.startIndex + linkText.getRelativeIndex(j);
|
|
97
104
|
e.suggestions = [
|
|
98
105
|
{
|
|
99
106
|
desc: 'escape',
|
|
@@ -105,10 +112,13 @@ class LinkBaseToken extends index_2.Token {
|
|
|
105
112
|
}
|
|
106
113
|
}
|
|
107
114
|
if (fragment !== undefined && !isLink(type)) {
|
|
108
|
-
const e = (0, lint_1.generateForChild)(target, rect, 'no-ignored', 'useless fragment'),
|
|
115
|
+
const e = (0, lint_1.generateForChild)(target, rect, 'no-ignored', 'useless fragment'), j = target.childNodes.findIndex(c => c.type === 'text' && c.data.includes('#')), textNode = target.childNodes[j];
|
|
109
116
|
if (textNode) {
|
|
110
117
|
e.fix = {
|
|
111
|
-
range: [
|
|
118
|
+
range: [
|
|
119
|
+
e.startIndex + target.getRelativeIndex(j) + textNode.data.indexOf('#'),
|
|
120
|
+
e.endIndex,
|
|
121
|
+
],
|
|
112
122
|
text: '',
|
|
113
123
|
desc: 'remove',
|
|
114
124
|
};
|
|
@@ -118,8 +128,8 @@ class LinkBaseToken extends index_2.Token {
|
|
|
118
128
|
return errors;
|
|
119
129
|
}
|
|
120
130
|
/** @private */
|
|
121
|
-
getTitle(halfParsed) {
|
|
122
|
-
return this.normalizeTitle(this.firstChild.toString(true), 0, halfParsed, true, true);
|
|
131
|
+
getTitle(temporary, halfParsed) {
|
|
132
|
+
return this.normalizeTitle(this.firstChild.toString(true), 0, temporary, halfParsed, true, true);
|
|
123
133
|
}
|
|
124
134
|
}
|
|
125
135
|
exports.LinkBaseToken = LinkBaseToken;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { LinkBaseToken } from './base';
|
|
2
|
+
import type { Title } from '../../lib/title';
|
|
2
3
|
import type { Token, AtomToken } from '../../internal';
|
|
3
4
|
/**
|
|
5
|
+
* category
|
|
6
|
+
*
|
|
4
7
|
* 分类
|
|
5
8
|
* @classdesc `{childNodes: [AtomToken, ?Token]}`
|
|
6
9
|
*/
|
|
7
10
|
export declare abstract class CategoryToken extends LinkBaseToken {
|
|
8
11
|
readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token];
|
|
12
|
+
abstract get link(): Title;
|
|
9
13
|
get type(): 'category';
|
|
10
14
|
}
|
package/dist/src/link/file.d.ts
CHANGED
|
@@ -4,36 +4,46 @@ import { ImageParameterToken } from '../imageParameter';
|
|
|
4
4
|
import type { LintError } from '../../base';
|
|
5
5
|
import type { Token, AtomToken } from '../../internal';
|
|
6
6
|
/**
|
|
7
|
+
* image
|
|
8
|
+
*
|
|
7
9
|
* 图片
|
|
8
|
-
* @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
|
|
10
|
+
* @classdesc `{childNodes: [AtomToken, ...ImageParameterToken[]]}`
|
|
9
11
|
*/
|
|
10
12
|
export declare abstract class FileToken extends LinkBaseToken {
|
|
11
13
|
readonly childNodes: readonly [AtomToken, ...ImageParameterToken[]];
|
|
12
14
|
abstract get lastChild(): AtomToken | ImageParameterToken;
|
|
13
15
|
get type(): 'file' | 'gallery-image' | 'imagemap-image';
|
|
14
|
-
/** 扩展名 */
|
|
15
|
-
get extension(): string | undefined;
|
|
16
16
|
/**
|
|
17
17
|
* @param link 文件名
|
|
18
18
|
* @param text 图片参数
|
|
19
19
|
* @param delimiter `|`
|
|
20
20
|
*/
|
|
21
21
|
constructor(link: string, text?: string, config?: Parser.Config, accum?: Token[], delimiter?: string);
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Get all image parameter tokens
|
|
24
|
+
*
|
|
25
|
+
* 获取所有图片参数节点
|
|
26
|
+
*/
|
|
23
27
|
getAllArgs(): ImageParameterToken[];
|
|
24
28
|
/**
|
|
29
|
+
* Get image parameters with the specified name
|
|
30
|
+
*
|
|
25
31
|
* 获取指定图片参数
|
|
26
|
-
* @param key 参数名
|
|
32
|
+
* @param key parameter name / 参数名
|
|
27
33
|
*/
|
|
28
34
|
getArgs(key: string): ImageParameterToken[];
|
|
29
35
|
/**
|
|
36
|
+
* Get the effective image parameter with the specified name
|
|
37
|
+
*
|
|
30
38
|
* 获取生效的指定图片参数
|
|
31
|
-
* @param key 参数名
|
|
39
|
+
* @param key parameter name / 参数名
|
|
32
40
|
*/
|
|
33
41
|
getArg(key: string): ImageParameterToken | undefined;
|
|
34
42
|
/**
|
|
43
|
+
* Get the effective image parameter value
|
|
44
|
+
*
|
|
35
45
|
* 获取生效的指定图片参数值
|
|
36
|
-
* @param key 参数名
|
|
46
|
+
* @param key parameter name / 参数名
|
|
37
47
|
*/
|
|
38
48
|
getValue(key: string): string | true | undefined;
|
|
39
49
|
}
|
package/dist/src/link/file.js
CHANGED
|
@@ -41,17 +41,15 @@ const explode = (start, end, separator, str) => {
|
|
|
41
41
|
return exploded;
|
|
42
42
|
};
|
|
43
43
|
/**
|
|
44
|
+
* image
|
|
45
|
+
*
|
|
44
46
|
* 图片
|
|
45
|
-
* @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
|
|
47
|
+
* @classdesc `{childNodes: [AtomToken, ...ImageParameterToken[]]}`
|
|
46
48
|
*/
|
|
47
49
|
class FileToken extends base_1.LinkBaseToken {
|
|
48
50
|
get type() {
|
|
49
51
|
return 'file';
|
|
50
52
|
}
|
|
51
|
-
/** 扩展名 */
|
|
52
|
-
get extension() {
|
|
53
|
-
return this.getTitle().extension;
|
|
54
|
-
}
|
|
55
53
|
/**
|
|
56
54
|
* @param link 文件名
|
|
57
55
|
* @param text 图片参数
|
|
@@ -59,7 +57,7 @@ class FileToken extends base_1.LinkBaseToken {
|
|
|
59
57
|
*/
|
|
60
58
|
constructor(link, text, config = index_1.default.getConfig(), accum = [], delimiter = '|') {
|
|
61
59
|
super(link, undefined, config, accum, delimiter);
|
|
62
|
-
const { extension } = this.getTitle(true);
|
|
60
|
+
const { extension } = this.getTitle(true, true);
|
|
63
61
|
this.append(...explode('-{', '}-', '|', text).map(
|
|
64
62
|
// @ts-expect-error abstract class
|
|
65
63
|
(part) => new imageParameter_1.ImageParameterToken(part, extension, config, accum)));
|
|
@@ -70,7 +68,8 @@ class FileToken extends base_1.LinkBaseToken {
|
|
|
70
68
|
const visibleNodes = childNodes.filter(node => node.text().trim());
|
|
71
69
|
return visibleNodes.length !== 1 || visibleNodes[0].type !== 'arg';
|
|
72
70
|
}), keys = [...new Set(args.map(({ name }) => name))], frameKeys = keys.filter(key => frame.has(key)), horizAlignKeys = keys.filter(key => horizAlign.has(key)), vertAlignKeys = keys.filter(key => vertAlign.has(key)), [fr] = frameKeys, unscaled = fr === 'framed' || fr === 'manualthumb', rect = new rect_1.BoundingRect(this, start);
|
|
73
|
-
if (this.closest('ext-link-text')
|
|
71
|
+
if (this.closest('ext-link-text')
|
|
72
|
+
&& this.getValue('link')?.trim() !== '') {
|
|
74
73
|
errors.push((0, lint_1.generateForSelf)(this, rect, 'nested-link', 'internal link in an external link'));
|
|
75
74
|
}
|
|
76
75
|
if (unscaled) {
|
|
@@ -102,7 +101,10 @@ class FileToken extends base_1.LinkBaseToken {
|
|
|
102
101
|
}
|
|
103
102
|
let relevantArgs = args.filter(({ name }) => name === key);
|
|
104
103
|
if (key === 'caption') {
|
|
105
|
-
relevantArgs = [
|
|
104
|
+
relevantArgs = [
|
|
105
|
+
...relevantArgs.slice(0, -1).filter(arg => arg.text()),
|
|
106
|
+
...relevantArgs.slice(-1),
|
|
107
|
+
];
|
|
106
108
|
}
|
|
107
109
|
if (relevantArgs.length > 1) {
|
|
108
110
|
errors.push(...relevantArgs.map(generate('duplicated', key)));
|
|
@@ -112,35 +114,47 @@ class FileToken extends base_1.LinkBaseToken {
|
|
|
112
114
|
errors.push(...args.filter(({ name }) => frame.has(name)).map(generate('conflicting', 'frame')));
|
|
113
115
|
}
|
|
114
116
|
if (horizAlignKeys.length > 1) {
|
|
115
|
-
errors.push(...args.filter(({ name }) => horizAlign.has(name))
|
|
117
|
+
errors.push(...args.filter(({ name }) => horizAlign.has(name))
|
|
118
|
+
.map(generate('conflicting', 'horizontal-alignment')));
|
|
116
119
|
}
|
|
117
120
|
if (vertAlignKeys.length > 1) {
|
|
118
|
-
errors.push(...args.filter(({ name }) => vertAlign.has(name))
|
|
121
|
+
errors.push(...args.filter(({ name }) => vertAlign.has(name))
|
|
122
|
+
.map(generate('conflicting', 'vertical-alignment')));
|
|
119
123
|
}
|
|
120
124
|
return errors;
|
|
121
125
|
}
|
|
122
|
-
/**
|
|
126
|
+
/**
|
|
127
|
+
* Get all image parameter tokens
|
|
128
|
+
*
|
|
129
|
+
* 获取所有图片参数节点
|
|
130
|
+
*/
|
|
123
131
|
getAllArgs() {
|
|
124
132
|
return this.childNodes.slice(1);
|
|
125
133
|
}
|
|
126
134
|
/**
|
|
135
|
+
* Get image parameters with the specified name
|
|
136
|
+
*
|
|
127
137
|
* 获取指定图片参数
|
|
128
|
-
* @param key 参数名
|
|
138
|
+
* @param key parameter name / 参数名
|
|
129
139
|
*/
|
|
130
140
|
getArgs(key) {
|
|
131
141
|
return this.getAllArgs().filter(({ name }) => key === name);
|
|
132
142
|
}
|
|
133
143
|
/**
|
|
144
|
+
* Get the effective image parameter with the specified name
|
|
145
|
+
*
|
|
134
146
|
* 获取生效的指定图片参数
|
|
135
|
-
* @param key 参数名
|
|
147
|
+
* @param key parameter name / 参数名
|
|
136
148
|
*/
|
|
137
149
|
getArg(key) {
|
|
138
150
|
const args = this.getArgs(key);
|
|
139
151
|
return args[key === 'manualthumb' ? 0 : args.length - 1];
|
|
140
152
|
}
|
|
141
153
|
/**
|
|
154
|
+
* Get the effective image parameter value
|
|
155
|
+
*
|
|
142
156
|
* 获取生效的指定图片参数值
|
|
143
|
-
* @param key 参数名
|
|
157
|
+
* @param key parameter name / 参数名
|
|
144
158
|
*/
|
|
145
159
|
getValue(key) {
|
|
146
160
|
return this.getArg(key)?.getValue();
|
|
@@ -4,7 +4,11 @@ import { FileToken } from './file';
|
|
|
4
4
|
import type { Title } from '../../lib/title';
|
|
5
5
|
import type { LintError } from '../../base';
|
|
6
6
|
declare type GalleryTypes = 'gallery' | 'imagemap';
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* gallery image
|
|
9
|
+
*
|
|
10
|
+
* 图库图片
|
|
11
|
+
*/
|
|
8
12
|
export declare abstract class GalleryImageToken extends FileToken {
|
|
9
13
|
get type(): `${GalleryTypes}-image`;
|
|
10
14
|
/**
|
|
@@ -6,7 +6,11 @@ const constants_1 = require("../../util/constants");
|
|
|
6
6
|
const index_1 = require("../../index");
|
|
7
7
|
const index_2 = require("../index");
|
|
8
8
|
const file_1 = require("./file");
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* gallery image
|
|
11
|
+
*
|
|
12
|
+
* 图库图片
|
|
13
|
+
*/
|
|
10
14
|
class GalleryImageToken extends file_1.FileToken {
|
|
11
15
|
/** @private */
|
|
12
16
|
privateType = 'imagemap-image';
|
|
@@ -34,9 +38,9 @@ class GalleryImageToken extends file_1.FileToken {
|
|
|
34
38
|
this.seal('privateType', true);
|
|
35
39
|
}
|
|
36
40
|
/** @private */
|
|
37
|
-
getTitle() {
|
|
41
|
+
getTitle(temporary) {
|
|
38
42
|
const imagemap = this.type === 'imagemap-image';
|
|
39
|
-
return this.normalizeTitle(this.firstChild.toString(), imagemap ? 0 : 6, true, !imagemap);
|
|
43
|
+
return this.normalizeTitle(this.firstChild.toString(), imagemap ? 0 : 6, temporary, true, !imagemap);
|
|
40
44
|
}
|
|
41
45
|
/** @private */
|
|
42
46
|
getAttribute(key) {
|
|
@@ -44,8 +48,8 @@ class GalleryImageToken extends file_1.FileToken {
|
|
|
44
48
|
}
|
|
45
49
|
/** @private */
|
|
46
50
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
47
|
-
const errors = super.lint(start, re), { ns,
|
|
48
|
-
if (
|
|
51
|
+
const errors = super.lint(start, re), { ns, } = this.getAttribute('title');
|
|
52
|
+
if (ns !== 6) {
|
|
49
53
|
const e = (0, lint_1.generateForSelf)(this, { start }, 'invalid-gallery', 'invalid gallery image');
|
|
50
54
|
e.suggestions = [{ desc: 'prefix', range: [start, start], text: 'File:' }];
|
|
51
55
|
errors.push(e);
|
package/dist/src/link/index.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { LinkBaseToken } from './base';
|
|
2
2
|
import type { LintError } from '../../base';
|
|
3
|
+
import type { Title } from '../../lib/title';
|
|
3
4
|
import type { Token, AtomToken } from '../../internal';
|
|
4
5
|
/**
|
|
6
|
+
* internal link
|
|
7
|
+
*
|
|
5
8
|
* 内链
|
|
6
9
|
* @classdesc `{childNodes: [AtomToken, ?Token]}`
|
|
7
10
|
*/
|
|
8
11
|
export declare abstract class LinkToken extends LinkBaseToken {
|
|
9
12
|
readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token];
|
|
13
|
+
abstract get link(): Title;
|
|
10
14
|
get type(): 'link';
|
|
11
15
|
}
|
package/dist/src/link/index.js
CHANGED
|
@@ -4,17 +4,19 @@ import type { LintError, Config } from '../../base';
|
|
|
4
4
|
import type { Title } from '../../lib/title';
|
|
5
5
|
import type { Token, AtomToken } from '../../internal';
|
|
6
6
|
/**
|
|
7
|
+
* target of a redirect
|
|
8
|
+
*
|
|
7
9
|
* 重定向目标
|
|
8
10
|
* @classdesc `{childNodes: [AtomToken, ?NoincludeToken]}`
|
|
9
11
|
*/
|
|
10
12
|
export declare abstract class RedirectTargetToken extends LinkBaseToken {
|
|
11
13
|
readonly childNodes: readonly [AtomToken] | readonly [AtomToken, NoincludeToken];
|
|
12
14
|
abstract get lastChild(): AtomToken | NoincludeToken;
|
|
15
|
+
abstract get link(): Title;
|
|
13
16
|
get type(): 'redirect-target';
|
|
14
17
|
/**
|
|
15
18
|
* @param link 链接标题
|
|
16
19
|
* @param linkText 链接显示文字
|
|
17
|
-
* @param delimiter `|`
|
|
18
20
|
*/
|
|
19
21
|
constructor(link: string, linkText?: string, config?: Config, accum?: Token[]);
|
|
20
22
|
}
|
|
@@ -5,6 +5,8 @@ const lint_1 = require("../../util/lint");
|
|
|
5
5
|
const base_1 = require("./base");
|
|
6
6
|
const noinclude_1 = require("../nowiki/noinclude");
|
|
7
7
|
/**
|
|
8
|
+
* target of a redirect
|
|
9
|
+
*
|
|
8
10
|
* 重定向目标
|
|
9
11
|
* @classdesc `{childNodes: [AtomToken, ?NoincludeToken]}`
|
|
10
12
|
*/
|
|
@@ -15,7 +17,6 @@ class RedirectTargetToken extends base_1.LinkBaseToken {
|
|
|
15
17
|
/**
|
|
16
18
|
* @param link 链接标题
|
|
17
19
|
* @param linkText 链接显示文字
|
|
18
|
-
* @param delimiter `|`
|
|
19
20
|
*/
|
|
20
21
|
constructor(link, linkText, config, accum) {
|
|
21
22
|
super(link, undefined, config, accum);
|
|
@@ -26,7 +27,8 @@ class RedirectTargetToken extends base_1.LinkBaseToken {
|
|
|
26
27
|
}
|
|
27
28
|
/** @private */
|
|
28
29
|
getTitle() {
|
|
29
|
-
return this
|
|
30
|
+
return this
|
|
31
|
+
.normalizeTitle(this.firstChild.toString(), 0, false, true, true);
|
|
30
32
|
}
|
|
31
33
|
/** @private */
|
|
32
34
|
lint(start = this.getAbsoluteIndex()) {
|
package/dist/src/magicLink.d.ts
CHANGED
|
@@ -4,8 +4,10 @@ import type { LintError } from '../base';
|
|
|
4
4
|
import type { AstText, CommentToken, IncludeToken, NoincludeToken, TranscludeToken } from '../internal';
|
|
5
5
|
declare type ExtLinkTypes = 'free-ext-link' | 'ext-link-url' | 'magic-link';
|
|
6
6
|
/**
|
|
7
|
+
* free external link
|
|
8
|
+
*
|
|
7
9
|
* 自由外链
|
|
8
|
-
* @classdesc `{childNodes:
|
|
10
|
+
* @classdesc `{childNodes: (AstText|CommentToken|IncludeToken|NoincludeToken)[]}`
|
|
9
11
|
*/
|
|
10
12
|
export declare abstract class MagicLinkToken extends Token {
|
|
11
13
|
#private;
|
|
@@ -13,14 +15,21 @@ export declare abstract class MagicLinkToken extends Token {
|
|
|
13
15
|
abstract get firstChild(): AstText | TranscludeToken;
|
|
14
16
|
abstract get lastChild(): AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken;
|
|
15
17
|
get type(): ExtLinkTypes;
|
|
16
|
-
/** 链接显示文字 */
|
|
18
|
+
/** text of the link / 链接显示文字 */
|
|
17
19
|
get innerText(): string;
|
|
18
|
-
/**
|
|
20
|
+
/** link / 链接 */
|
|
19
21
|
get link(): string;
|
|
20
22
|
/**
|
|
21
23
|
* @param url 网址
|
|
22
24
|
* @param type 类型
|
|
23
25
|
*/
|
|
24
26
|
constructor(url?: string, type?: ExtLinkTypes, config?: Parser.Config, accum?: Token[]);
|
|
27
|
+
/**
|
|
28
|
+
* Get the URL
|
|
29
|
+
*
|
|
30
|
+
* 获取网址
|
|
31
|
+
* @param articlePath article path / 条目路径
|
|
32
|
+
*/
|
|
33
|
+
getUrl(articlePath?: string): URL | string;
|
|
25
34
|
}
|
|
26
35
|
export {};
|