wikilint 2.48.2 → 3.1.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/README.md +1 -1
- package/config/.schema.json +5 -0
- package/data/signatures.json +2 -2
- package/dist/base.d.mts +4 -2
- package/dist/base.d.ts +4 -2
- package/dist/base.js +1 -0
- package/dist/base.mjs +2 -1
- package/dist/bin/config.js +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +20 -14
- package/dist/internal.d.ts +1 -0
- package/dist/lib/document.d.ts +7 -6
- package/dist/lib/document.js +3 -1
- package/dist/lib/lintConfig.js +1 -0
- package/dist/lib/lsp.js +9 -7
- package/dist/lib/node.d.ts +0 -4
- package/dist/lib/node.js +8 -0
- package/dist/lib/text.js +4 -3
- package/dist/lib/title.js +6 -1
- package/dist/map.d.ts +2 -1
- package/dist/parser/commentAndExt.js +1 -1
- package/dist/parser/hrAndDoubleUnderscore.js +3 -2
- package/dist/parser/table.js +2 -1
- package/dist/src/arg.d.ts +1 -1
- package/dist/src/arg.js +1 -1
- package/dist/src/attributes.d.ts +4 -3
- package/dist/src/converter.d.ts +1 -1
- package/dist/src/converter.js +1 -1
- package/dist/src/converterRule.d.ts +1 -1
- package/dist/src/converterRule.js +1 -1
- package/dist/src/extLink.d.ts +1 -1
- package/dist/src/extLink.js +1 -1
- package/dist/src/index.js +54 -58
- package/dist/src/link/category.d.ts +1 -1
- package/dist/src/link/category.js +1 -1
- package/dist/src/link/galleryImage.js +1 -1
- package/dist/src/link/index.d.ts +1 -1
- package/dist/src/link/index.js +1 -1
- package/dist/src/link/redirectTarget.d.ts +1 -1
- package/dist/src/link/redirectTarget.js +1 -1
- package/dist/src/magicLink.d.ts +4 -3
- package/dist/src/magicLink.js +1 -1
- package/dist/src/multiLine/gallery.d.ts +4 -4
- package/dist/src/multiLine/gallery.js +13 -4
- package/dist/src/multiLine/imagemap.d.ts +5 -3
- package/dist/src/multiLine/imagemap.js +1 -1
- package/dist/src/nested.d.ts +1 -1
- package/dist/src/nested.js +1 -1
- package/dist/src/nowiki/list.js +6 -3
- package/dist/src/nowiki/listBase.d.ts +24 -0
- package/dist/src/nowiki/listBase.js +104 -0
- package/dist/src/paramLine.d.ts +1 -1
- package/dist/src/paramLine.js +1 -1
- package/dist/src/pre.d.ts +5 -3
- package/dist/src/redirect.d.ts +1 -1
- package/dist/src/redirect.js +1 -1
- package/dist/src/singleLine/charinsertLine.d.ts +1 -1
- package/dist/src/singleLine/charinsertLine.js +1 -1
- package/dist/src/table/index.d.ts +2 -2
- package/dist/src/table/index.js +1 -1
- package/dist/src/table/tr.d.ts +1 -1
- package/dist/src/table/tr.js +1 -1
- package/dist/src/tag/index.d.ts +7 -5
- package/dist/src/tag/index.js +9 -4
- package/dist/src/tagPair/ext.js +1 -1
- package/dist/src/transclude.d.ts +1 -1
- package/dist/src/transclude.js +1 -1
- package/dist/util/debug.js +7 -1
- package/i18n/en.json +1 -0
- package/i18n/zh-hans.json +1 -0
- package/i18n/zh-hant.json +1 -0
- package/package.json +2 -2
|
@@ -60,7 +60,7 @@ const getRuleFromTo = (text, type, config, accum) => {
|
|
|
60
60
|
* language conversion rule
|
|
61
61
|
*
|
|
62
62
|
* 转换规则
|
|
63
|
-
* @classdesc `{childNodes: [Token?, AtomToken
|
|
63
|
+
* @classdesc `{childNodes: [Token] | [Token?, AtomToken, Token]}`
|
|
64
64
|
*/
|
|
65
65
|
let ConverterRuleToken = (() => {
|
|
66
66
|
let _classDecorators = [noEscape_1.noEscape];
|
package/dist/src/extLink.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { Config, LintError } from '../base';
|
|
|
5
5
|
* external link
|
|
6
6
|
*
|
|
7
7
|
* 外链
|
|
8
|
-
* @classdesc `{childNodes: [MagicLinkToken, ?
|
|
8
|
+
* @classdesc `{childNodes: [MagicLinkToken, Token?]}`
|
|
9
9
|
*/
|
|
10
10
|
export declare abstract class ExtLinkToken extends Token {
|
|
11
11
|
#private;
|
package/dist/src/extLink.js
CHANGED
|
@@ -48,7 +48,7 @@ const magicLink_1 = require("./magicLink");
|
|
|
48
48
|
* external link
|
|
49
49
|
*
|
|
50
50
|
* 外链
|
|
51
|
-
* @classdesc `{childNodes: [MagicLinkToken, ?
|
|
51
|
+
* @classdesc `{childNodes: [MagicLinkToken, Token?]}`
|
|
52
52
|
*/
|
|
53
53
|
let ExtLinkToken = (() => {
|
|
54
54
|
let _classDecorators = [(0, padded_1.padded)('[')];
|
package/dist/src/index.js
CHANGED
|
@@ -1,48 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// PHP解析器的步骤:
|
|
3
|
-
// -2. 替换签名和`{{subst:}}`,参见Parser::preSaveTransform;这在revision中不可能保留,可以跳过
|
|
4
|
-
// -1. 移除特定字符`\0`和`\x7F`,参见Parser::parse
|
|
5
|
-
// 0. 重定向,参见WikitextContentHandler::extractRedirectTargetAndText
|
|
6
|
-
// 1. 注释/扩展标签('<'相关),参见Preprocessor_Hash::buildDomTreeArrayFromText和Sanitizer::decodeTagAttributes
|
|
7
|
-
// 2. 模板/模板变量/标题,注意rightmost法则,以及`-{`和`[[`可以破坏`{{`或`{{{`语法,
|
|
8
|
-
// 参见Preprocessor_Hash::buildDomTreeArrayFromText
|
|
9
|
-
// 3. HTML标签(允许不匹配),参见Sanitizer::internalRemoveHtmlTags
|
|
10
|
-
// 4. 表格,参见Parser::handleTables
|
|
11
|
-
// 5. 水平线、状态开关和余下的标题,参见Parser::internalParse
|
|
12
|
-
// 6. 内链,含文件和分类,参见Parser::handleInternalLinks2
|
|
13
|
-
// 7. `'`,参见Parser::doQuotes
|
|
14
|
-
// 8. 外链,参见Parser::handleExternalLinks
|
|
15
|
-
// 9. ISBN、RFC和自由外链,参见Parser::handleMagicLinks
|
|
16
|
-
// 10. 段落和列表,参见BlockLevelPass::execute
|
|
17
|
-
// 11. 转换,参见LanguageConverter::recursiveConvertTopLevel
|
|
18
|
-
// \0\d+.\x7F标记Token:
|
|
19
|
-
// !: `{{!}}`专用
|
|
20
|
-
// {: `{{(!}}`专用
|
|
21
|
-
// }: `{{!)}}`专用
|
|
22
|
-
// -: `{{!-}}`专用
|
|
23
|
-
// +: `{{!!}}`专用
|
|
24
|
-
// ~: `{{=}}`专用
|
|
25
|
-
// a: AttributeToken
|
|
26
|
-
// b: TableToken
|
|
27
|
-
// c: CommentToke
|
|
28
|
-
// d: ListToken
|
|
29
|
-
// e: ExtToken
|
|
30
|
-
// f: ImageParameterToken内的MagicLinkToken
|
|
31
|
-
// g: TranslateToken或OnlyincludeToken
|
|
32
|
-
// h: HeadingToken
|
|
33
|
-
// i: RFC/PMID/ISBN
|
|
34
|
-
// l: LinkToken
|
|
35
|
-
// m: `{{server}}`、`{{fullurl:}}`、`{{canonicalurl:}}`或`{{filepath:}}`
|
|
36
|
-
// n: NoIncludeToken、IncludeToken、TvarToken、DoubleUnderscoreToken或`{{#vardefine:}}`
|
|
37
|
-
// o: RedirectToken
|
|
38
|
-
// q: QuoteToken
|
|
39
|
-
// r: HrToken
|
|
40
|
-
// s: `{{{|subst:}}}`
|
|
41
|
-
// t: ArgToken或TranscludeToken
|
|
42
|
-
// u: `__toc__`
|
|
43
|
-
// v: ConverterToken
|
|
44
|
-
// w: ExtLinkToken或free-ext-link
|
|
45
|
-
// x: HtmlToken
|
|
46
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
47
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
48
4
|
};
|
|
@@ -55,7 +11,7 @@ const debug_1 = require("../util/debug");
|
|
|
55
11
|
const index_1 = __importDefault(require("../index"));
|
|
56
12
|
const element_1 = require("../lib/element");
|
|
57
13
|
const text_1 = require("../lib/text");
|
|
58
|
-
const lintSelectors = ['category', 'html-attr#id,ext-attr#id,table-attr#id'];
|
|
14
|
+
const lintSelectors = ['category', 'html-attr#id,ext-attr#id,table-attr#id', 'ext#indicator'];
|
|
59
15
|
/**
|
|
60
16
|
* base class for all tokens
|
|
61
17
|
*
|
|
@@ -302,7 +258,7 @@ class Token extends element_1.AstElement {
|
|
|
302
258
|
}
|
|
303
259
|
const { parseList } = require('../parser/list');
|
|
304
260
|
const { firstChild, type, name } = this, lines = firstChild.toString().split('\n'), state = { lastPrefix: '' };
|
|
305
|
-
let i = type === 'root' || type === 'ext-inner' && name
|
|
261
|
+
let i = type === 'root' || type === 'ext-inner' && (0, debug_1.isIsolated)(name) ? 0 : 1;
|
|
306
262
|
for (; i < lines.length; i++) {
|
|
307
263
|
lines[i] = parseList(lines[i], state, this.#config, this.#accum);
|
|
308
264
|
}
|
|
@@ -386,18 +342,24 @@ class Token extends element_1.AstElement {
|
|
|
386
342
|
const { lintConfig } = index_1.default, { computeEditInfo, fix: needFix, ignoreDisables, configurationComment } = lintConfig;
|
|
387
343
|
let errors = super.lint(start, re);
|
|
388
344
|
if (this.type === 'root') {
|
|
389
|
-
const
|
|
390
|
-
|
|
345
|
+
const r = 'no-duplicate', s = ['category', 'id', 'indicator'].map(key => lintConfig.getSeverity(r, key)), msgs = ['category', 'id', 'name'], wikitext = this.toString();
|
|
346
|
+
for (let i = 0; i < s.length; i++) {
|
|
347
|
+
const severity = s[i];
|
|
348
|
+
if (!severity) {
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
const record = new Map(), selector = lintSelectors[i];
|
|
391
352
|
for (const cat of this.querySelectorAll(selector)) {
|
|
392
353
|
let key;
|
|
393
|
-
if (
|
|
354
|
+
if (i === 0) { // category
|
|
394
355
|
key = cat.name;
|
|
395
356
|
}
|
|
396
|
-
else {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
357
|
+
else if (i === 1) { // id
|
|
358
|
+
key = cat.getValue().replace(/\s+/gu, '_');
|
|
359
|
+
}
|
|
360
|
+
else { // indicator
|
|
361
|
+
key = cat.getAttr('name')
|
|
362
|
+
?.replace(/\s+/gu, '_');
|
|
401
363
|
}
|
|
402
364
|
if (key) {
|
|
403
365
|
const thisCat = record.get(key);
|
|
@@ -410,11 +372,10 @@ class Token extends element_1.AstElement {
|
|
|
410
372
|
}
|
|
411
373
|
}
|
|
412
374
|
for (const [key, value] of record) {
|
|
413
|
-
if (value.size > 1 && !key.startsWith('
|
|
414
|
-
const isCat = !key.startsWith('#'), msg = `duplicate-${isCat ? 'category' : 'id'}`, severity = s[isCat ? 0 : 1];
|
|
375
|
+
if (value.size > 1 && (i !== 1 || !key.startsWith('mw-customcollapsible-'))) {
|
|
415
376
|
errors.push(...[...value].map(cat => {
|
|
416
|
-
const e = (0, lint_1.generateForSelf)(cat, { start: cat.getAbsoluteIndex() }, r,
|
|
417
|
-
if (computeEditInfo &&
|
|
377
|
+
const e = (0, lint_1.generateForSelf)(cat, { start: cat.getAbsoluteIndex() }, r, `duplicate-${msgs[i]}`, severity);
|
|
378
|
+
if (computeEditInfo && i === 0) {
|
|
418
379
|
e.suggestions = [(0, lint_1.fixByRemove)(e)];
|
|
419
380
|
}
|
|
420
381
|
return e;
|
|
@@ -494,5 +455,40 @@ class Token extends element_1.AstElement {
|
|
|
494
455
|
}
|
|
495
456
|
});
|
|
496
457
|
}
|
|
458
|
+
/**
|
|
459
|
+
* 构建列表
|
|
460
|
+
* @param recursive 是否递归
|
|
461
|
+
*/
|
|
462
|
+
#buildLists(recursive) {
|
|
463
|
+
PRINT: for (let i = 0; i < this.length; i++) {
|
|
464
|
+
const child = this.childNodes[i];
|
|
465
|
+
if (child.is('list') || child.is('dd')) {
|
|
466
|
+
child.getRange();
|
|
467
|
+
}
|
|
468
|
+
else if (recursive && child.type !== 'text') {
|
|
469
|
+
child.#buildLists(true);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
/** @private */
|
|
474
|
+
buildLists() {
|
|
475
|
+
PRINT: this.#buildLists(true);
|
|
476
|
+
}
|
|
477
|
+
/** @private */
|
|
478
|
+
concat(elements) {
|
|
479
|
+
PRINT: {
|
|
480
|
+
if (elements.length === 0) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
const { childNodes, lastChild } = this, first = elements[0], last = elements.at(-1);
|
|
484
|
+
for (const element of elements) {
|
|
485
|
+
element.setAttribute('parentNode', this);
|
|
486
|
+
}
|
|
487
|
+
lastChild?.setAttribute('nextSibling', first);
|
|
488
|
+
first.setAttribute('previousSibling', lastChild);
|
|
489
|
+
last.setAttribute('nextSibling', undefined);
|
|
490
|
+
this.setAttribute('childNodes', [...childNodes, ...elements]);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
497
493
|
}
|
|
498
494
|
exports.Token = Token;
|
|
@@ -5,7 +5,7 @@ import type { Token, AtomToken } from '../../internal';
|
|
|
5
5
|
* category
|
|
6
6
|
*
|
|
7
7
|
* 分类
|
|
8
|
-
* @classdesc `{childNodes: [AtomToken, ?
|
|
8
|
+
* @classdesc `{childNodes: [AtomToken, Token?]}`
|
|
9
9
|
*/
|
|
10
10
|
export declare abstract class CategoryToken extends LinkBaseToken {
|
|
11
11
|
readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token];
|
|
@@ -92,7 +92,7 @@ let GalleryImageToken = (() => {
|
|
|
92
92
|
/** @private */
|
|
93
93
|
getTitle(temporary) {
|
|
94
94
|
const imagemap = this.type === 'imagemap-image';
|
|
95
|
-
return this.normalizeTitle(this.firstChild
|
|
95
|
+
return this.normalizeTitle(this.firstChild[imagemap ? 'toString' : 'text'](), imagemap ? 0 : 6, { halfParsed: true, temporary, decode: !imagemap, page: '' });
|
|
96
96
|
}
|
|
97
97
|
/** 判定无效的图片 */
|
|
98
98
|
#lint() {
|
package/dist/src/link/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { Token, AtomToken } from '../../internal';
|
|
|
6
6
|
* internal link
|
|
7
7
|
*
|
|
8
8
|
* 内链
|
|
9
|
-
* @classdesc `{childNodes: [AtomToken, ?
|
|
9
|
+
* @classdesc `{childNodes: [AtomToken, Token?]}`
|
|
10
10
|
*/
|
|
11
11
|
export declare abstract class LinkToken extends LinkBaseToken {
|
|
12
12
|
readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token];
|
package/dist/src/link/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import type { Token, AtomToken } from '../../internal';
|
|
|
7
7
|
* target of a redirect
|
|
8
8
|
*
|
|
9
9
|
* 重定向目标
|
|
10
|
-
* @classdesc `{childNodes: [AtomToken, ?
|
|
10
|
+
* @classdesc `{childNodes: [AtomToken, NoincludeToken?]}`
|
|
11
11
|
*/
|
|
12
12
|
export declare abstract class RedirectTargetToken extends LinkBaseToken {
|
|
13
13
|
readonly childNodes: readonly [AtomToken] | readonly [AtomToken, NoincludeToken];
|
|
@@ -12,7 +12,7 @@ const noinclude_1 = require("../nowiki/noinclude");
|
|
|
12
12
|
* target of a redirect
|
|
13
13
|
*
|
|
14
14
|
* 重定向目标
|
|
15
|
-
* @classdesc `{childNodes: [AtomToken, ?
|
|
15
|
+
* @classdesc `{childNodes: [AtomToken, NoincludeToken?]}`
|
|
16
16
|
*/
|
|
17
17
|
class RedirectTargetToken extends base_1.LinkBaseToken {
|
|
18
18
|
get type() {
|
package/dist/src/magicLink.d.ts
CHANGED
|
@@ -3,17 +3,18 @@ import { Token } from './index';
|
|
|
3
3
|
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
|
+
declare type Child = CommentToken | IncludeToken | NoincludeToken | TranscludeToken;
|
|
6
7
|
/**
|
|
7
8
|
* free external link
|
|
8
9
|
*
|
|
9
10
|
* 自由外链
|
|
10
|
-
* @classdesc `{childNodes: (AstText|CommentToken|IncludeToken|NoincludeToken)[]}`
|
|
11
|
+
* @classdesc `{childNodes: (AstText|CommentToken|IncludeToken|NoincludeToken|TranscludeToken)[]}`
|
|
11
12
|
*/
|
|
12
13
|
export declare abstract class MagicLinkToken extends Token {
|
|
13
14
|
#private;
|
|
14
|
-
readonly childNodes: readonly (AstText |
|
|
15
|
+
readonly childNodes: readonly (AstText | Child)[];
|
|
15
16
|
abstract get firstChild(): AstText | TranscludeToken;
|
|
16
|
-
abstract get lastChild(): AstText |
|
|
17
|
+
abstract get lastChild(): AstText | Child;
|
|
17
18
|
get type(): ExtLinkTypes;
|
|
18
19
|
/**
|
|
19
20
|
* text of the link
|
package/dist/src/magicLink.js
CHANGED
|
@@ -15,7 +15,7 @@ const spaceRegex = new RegExp(`${space}+`, 'gu');
|
|
|
15
15
|
* free external link
|
|
16
16
|
*
|
|
17
17
|
* 自由外链
|
|
18
|
-
* @classdesc `{childNodes: (AstText|CommentToken|IncludeToken|NoincludeToken)[]}`
|
|
18
|
+
* @classdesc `{childNodes: (AstText|CommentToken|IncludeToken|NoincludeToken|TranscludeToken)[]}`
|
|
19
19
|
*/
|
|
20
20
|
class MagicLinkToken extends index_2.Token {
|
|
21
21
|
#type;
|
|
@@ -3,7 +3,7 @@ import { GalleryImageToken } from '../link/galleryImage';
|
|
|
3
3
|
import { CommentLineToken } from '../nowiki/commentLine';
|
|
4
4
|
import type { Config, LintError } from '../../base';
|
|
5
5
|
import type { AstText, Token } from '../../internal';
|
|
6
|
-
declare type Child = GalleryImageToken | CommentLineToken
|
|
6
|
+
declare type Child = GalleryImageToken | CommentLineToken;
|
|
7
7
|
/**
|
|
8
8
|
* `<gallery>`
|
|
9
9
|
* @classdesc `{childNodes: (GalleryImageToken|CommentLineToken|AstText)[]}`
|
|
@@ -11,9 +11,9 @@ declare type Child = GalleryImageToken | CommentLineToken | AstText;
|
|
|
11
11
|
export declare abstract class GalleryToken extends MultiLineToken {
|
|
12
12
|
#private;
|
|
13
13
|
readonly name: 'gallery';
|
|
14
|
-
readonly childNodes: readonly Child[];
|
|
15
|
-
abstract get firstChild(): Child | undefined;
|
|
16
|
-
abstract get lastChild(): Child | undefined;
|
|
14
|
+
readonly childNodes: readonly (AstText | Child)[];
|
|
15
|
+
abstract get firstChild(): AstText | Child | undefined;
|
|
16
|
+
abstract get lastChild(): AstText | Child | undefined;
|
|
17
17
|
/** @param inner 标签内部wikitext */
|
|
18
18
|
constructor(inner?: string, config?: Config, accum?: Token[]);
|
|
19
19
|
}
|
|
@@ -5,10 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.GalleryToken = void 0;
|
|
7
7
|
const lint_1 = require("../../util/lint");
|
|
8
|
+
const string_1 = require("../../util/string");
|
|
9
|
+
const replace_1 = require("../../util/replace");
|
|
8
10
|
const index_1 = __importDefault(require("../../index"));
|
|
9
11
|
const index_2 = require("./index");
|
|
10
12
|
const galleryImage_1 = require("../link/galleryImage");
|
|
11
13
|
const commentLine_1 = require("../nowiki/commentLine");
|
|
14
|
+
const comment_1 = require("../nowiki/comment");
|
|
12
15
|
/**
|
|
13
16
|
* `<gallery>`
|
|
14
17
|
* @classdesc `{childNodes: (GalleryImageToken|CommentLineToken|AstText)[]}`
|
|
@@ -18,7 +21,12 @@ class GalleryToken extends index_2.MultiLineToken {
|
|
|
18
21
|
constructor(inner, config, accum = []) {
|
|
19
22
|
super(undefined, config, accum, {});
|
|
20
23
|
if (inner) {
|
|
21
|
-
for (
|
|
24
|
+
for (let line of inner.split('\n')) {
|
|
25
|
+
line = (0, replace_1.safeStringReplace)(line, '<!--', '-->', false, p => {
|
|
26
|
+
// @ts-expect-error abstract class
|
|
27
|
+
new comment_1.CommentToken(p, true, config, accum);
|
|
28
|
+
return `\0${accum.length}c\x7F`;
|
|
29
|
+
});
|
|
22
30
|
const matches = /^([^|]+)(?:\|(.*))?/u.exec(line);
|
|
23
31
|
if (!matches) {
|
|
24
32
|
super.insertAt((line.trim()
|
|
@@ -28,7 +36,7 @@ class GalleryToken extends index_2.MultiLineToken {
|
|
|
28
36
|
continue;
|
|
29
37
|
}
|
|
30
38
|
const [, file, alt] = matches;
|
|
31
|
-
if (this.#checkFile(file)) { // eslint-disable-line unicorn/prefer-ternary
|
|
39
|
+
if (this.#checkFile(file, true)) { // eslint-disable-line unicorn/prefer-ternary
|
|
32
40
|
// @ts-expect-error abstract class
|
|
33
41
|
super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
|
|
34
42
|
}
|
|
@@ -43,9 +51,10 @@ class GalleryToken extends index_2.MultiLineToken {
|
|
|
43
51
|
/**
|
|
44
52
|
* 检查文件名是否有效
|
|
45
53
|
* @param file 文件名
|
|
54
|
+
* @param parsing 是否在解析过程中
|
|
46
55
|
*/
|
|
47
|
-
#checkFile(file) {
|
|
48
|
-
return this.normalizeTitle(file, 6, { halfParsed: true, temporary: true, decode: true, page: '' }).valid;
|
|
56
|
+
#checkFile(file, parsing) {
|
|
57
|
+
return this.normalizeTitle(parsing ? (0, string_1.removeComment)(file) : file, 6, { halfParsed: true, temporary: true, decode: true, page: '' }).valid;
|
|
49
58
|
}
|
|
50
59
|
/** @private */
|
|
51
60
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
@@ -5,17 +5,19 @@ import { GalleryImageToken } from '../link/galleryImage';
|
|
|
5
5
|
import { ImagemapLinkToken } from '../singleLine/imagemapLink';
|
|
6
6
|
import type { LintError } from '../../base';
|
|
7
7
|
import type { AstText, Token } from '../../internal';
|
|
8
|
+
declare type Child = GalleryImageToken | CommentLineToken | ImagemapLinkToken;
|
|
8
9
|
/**
|
|
9
10
|
* `<imagemap>`
|
|
10
|
-
* @classdesc `{childNodes:
|
|
11
|
+
* @classdesc `{childNodes: (GalleryImageToken|CommentLineToken|ImagemapLinkToken|AstText)[]]}`
|
|
11
12
|
*/
|
|
12
13
|
export declare abstract class ImagemapToken extends MultiLineToken {
|
|
13
14
|
readonly name: 'imagemap';
|
|
14
|
-
readonly childNodes: readonly (
|
|
15
|
+
readonly childNodes: readonly (Child | AstText)[];
|
|
15
16
|
abstract get firstChild(): GalleryImageToken | CommentLineToken | undefined;
|
|
16
|
-
abstract get lastChild():
|
|
17
|
+
abstract get lastChild(): Child | AstText | undefined;
|
|
17
18
|
/** 图片 */
|
|
18
19
|
get image(): GalleryImageToken | undefined;
|
|
19
20
|
/** @param inner 标签内部wikitext */
|
|
20
21
|
constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
|
|
21
22
|
}
|
|
23
|
+
export {};
|
|
@@ -14,7 +14,7 @@ const galleryImage_1 = require("../link/galleryImage");
|
|
|
14
14
|
const imagemapLink_1 = require("../singleLine/imagemapLink");
|
|
15
15
|
/**
|
|
16
16
|
* `<imagemap>`
|
|
17
|
-
* @classdesc `{childNodes:
|
|
17
|
+
* @classdesc `{childNodes: (GalleryImageToken|CommentLineToken|ImagemapLinkToken|AstText)[]]}`
|
|
18
18
|
*/
|
|
19
19
|
class ImagemapToken extends index_2.MultiLineToken {
|
|
20
20
|
/** 图片 */
|
package/dist/src/nested.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ declare type Child = ExtToken | NoincludeToken | CommentToken | IncludeToken | A
|
|
|
8
8
|
* extension tag that has a nested structure
|
|
9
9
|
*
|
|
10
10
|
* 嵌套式的扩展标签
|
|
11
|
-
* @classdesc `{childNodes: (ExtToken|NoincludeToken|CommentToken)[]}`
|
|
11
|
+
* @classdesc `{childNodes: (ExtToken|NoincludeToken|CommentToken|IncludeToken|ArgToken|TranscludeToken)[]}`
|
|
12
12
|
*/
|
|
13
13
|
export declare abstract class NestedToken extends Token {
|
|
14
14
|
#private;
|
package/dist/src/nested.js
CHANGED
|
@@ -20,7 +20,7 @@ const childTypes = new Set(['comment', 'include', 'arg', 'template', 'magic-word
|
|
|
20
20
|
* extension tag that has a nested structure
|
|
21
21
|
*
|
|
22
22
|
* 嵌套式的扩展标签
|
|
23
|
-
* @classdesc `{childNodes: (ExtToken|NoincludeToken|CommentToken)[]}`
|
|
23
|
+
* @classdesc `{childNodes: (ExtToken|NoincludeToken|CommentToken|IncludeToken|ArgToken|TranscludeToken)[]}`
|
|
24
24
|
*/
|
|
25
25
|
class NestedToken extends index_2.Token {
|
|
26
26
|
#tags;
|
package/dist/src/nowiki/list.js
CHANGED
|
@@ -22,11 +22,14 @@ class ListToken extends listBase_1.ListBaseToken {
|
|
|
22
22
|
LINT: {
|
|
23
23
|
const rule = 'syntax-like', s = index_1.default.lintConfig.getSeverity(rule, 'redirect'), { innerText } = this;
|
|
24
24
|
if (s && innerText === '#') {
|
|
25
|
-
// eslint-disable-next-line prefer-const
|
|
26
25
|
let { nextSibling } = this;
|
|
26
|
+
PRINT: if (nextSibling?.is('list-range')) {
|
|
27
|
+
nextSibling = nextSibling.firstChild;
|
|
28
|
+
}
|
|
27
29
|
if (nextSibling?.type === 'text' && linkTypes.has(nextSibling.nextSibling?.type)) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
31
|
+
/^redirect[^\S\n]*(?::[^\S\n]*)?$/iu;
|
|
32
|
+
const re = new RegExp(String.raw `^(?:${this.getAttribute('config').redirection.join('|')})[^\S\n]*(?::[^\S\n]*)?$`, 'iu');
|
|
30
33
|
if (re.test(`#${nextSibling.data}`)) {
|
|
31
34
|
const e = (0, lint_1.generateForSelf)(nextSibling, { start: start + 1 }, rule, 'redirect-like', s);
|
|
32
35
|
e.startIndex--;
|
|
@@ -1,5 +1,29 @@
|
|
|
1
|
+
import { AstText } from '../../lib/text';
|
|
2
|
+
import { Token } from '../index';
|
|
1
3
|
import { NowikiBaseToken } from './base';
|
|
4
|
+
import type { DdToken, ListToken } from '../../internal';
|
|
5
|
+
export interface ListRangeToken extends Token {
|
|
6
|
+
readonly type: 'list-range';
|
|
7
|
+
readonly previousSibling: ListToken | DdToken;
|
|
8
|
+
readonly nextSibling: DdToken | AstText | undefined;
|
|
9
|
+
}
|
|
2
10
|
/** `;:*#` */
|
|
3
11
|
export declare abstract class ListBaseToken extends NowikiBaseToken {
|
|
4
12
|
abstract get type(): 'dd' | 'list';
|
|
13
|
+
/** whether to contain `;` / 是否包含`;` */
|
|
14
|
+
get dt(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* number of indentation
|
|
17
|
+
*
|
|
18
|
+
* 缩进数
|
|
19
|
+
* @since v1.16.5
|
|
20
|
+
*/
|
|
21
|
+
get indent(): number;
|
|
22
|
+
/**
|
|
23
|
+
* Get the range of the list
|
|
24
|
+
*
|
|
25
|
+
* 获取列表行的范围
|
|
26
|
+
* @throws `Error` if the token has no parent node
|
|
27
|
+
*/
|
|
28
|
+
getRange(): ListRangeToken;
|
|
5
29
|
}
|
|
@@ -1,8 +1,112 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ListBaseToken = void 0;
|
|
4
|
+
const debug_1 = require("../../util/debug");
|
|
5
|
+
const text_1 = require("../../lib/text");
|
|
6
|
+
const index_1 = require("../index");
|
|
4
7
|
const base_1 = require("./base");
|
|
5
8
|
/** `;:*#` */
|
|
6
9
|
class ListBaseToken extends base_1.NowikiBaseToken {
|
|
10
|
+
/** whether to contain `;` / 是否包含`;` */
|
|
11
|
+
get dt() {
|
|
12
|
+
PRINT: return this.innerText.includes(';');
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* number of indentation
|
|
16
|
+
*
|
|
17
|
+
* 缩进数
|
|
18
|
+
* @since v1.16.5
|
|
19
|
+
*/
|
|
20
|
+
get indent() {
|
|
21
|
+
PRINT: return this.innerText.split(':').length - 1;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the range of the list
|
|
25
|
+
*
|
|
26
|
+
* 获取列表行的范围
|
|
27
|
+
* @throws `Error` if the token has no parent node
|
|
28
|
+
*/
|
|
29
|
+
getRange() {
|
|
30
|
+
PRINT: {
|
|
31
|
+
const { parentNode } = this;
|
|
32
|
+
if (!parentNode) {
|
|
33
|
+
throw new Error('There is no parent node!');
|
|
34
|
+
}
|
|
35
|
+
let { nextSibling } = this;
|
|
36
|
+
if (nextSibling?.is('list-range')) {
|
|
37
|
+
return nextSibling;
|
|
38
|
+
}
|
|
39
|
+
const { dt, type } = this;
|
|
40
|
+
let nDt = 0;
|
|
41
|
+
while (nextSibling && (nextSibling.type !== 'text' || !nextSibling.data.includes('\n'))) {
|
|
42
|
+
if (type === 'list') {
|
|
43
|
+
if (nextSibling.is('dd')) {
|
|
44
|
+
nDt -= nextSibling.indent;
|
|
45
|
+
if (dt && nDt < 0) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if (nextSibling.is('list') && nextSibling.dt) {
|
|
50
|
+
nDt++;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (nextSibling.is('dd')) {
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
({ nextSibling } = nextSibling);
|
|
57
|
+
}
|
|
58
|
+
let start, end, contents;
|
|
59
|
+
if (nextSibling && nextSibling.type !== 'text') {
|
|
60
|
+
const { childNodes } = parentNode;
|
|
61
|
+
start = childNodes.indexOf(this) + 1;
|
|
62
|
+
end = childNodes.indexOf(nextSibling);
|
|
63
|
+
contents = childNodes.slice(start, end);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
if (type === 'list') {
|
|
67
|
+
while (this.previousSibling?.is('list')) {
|
|
68
|
+
this.setText(this.previousSibling.innerText + this.innerText);
|
|
69
|
+
this.previousSibling.removeInternal();
|
|
70
|
+
}
|
|
71
|
+
for (let i = 0; i < nDt; i++) {
|
|
72
|
+
const token = this.nextSibling;
|
|
73
|
+
this.setText(this.innerText + token.innerText);
|
|
74
|
+
token.removeInternal();
|
|
75
|
+
}
|
|
76
|
+
if (parentNode.is('list-range')) {
|
|
77
|
+
parentNode.previousSibling.setText(parentNode.previousSibling.innerText + this.innerText);
|
|
78
|
+
this.removeInternal();
|
|
79
|
+
return parentNode;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const { childNodes } = parentNode;
|
|
83
|
+
start = childNodes.indexOf(this) + 1;
|
|
84
|
+
if (nextSibling) {
|
|
85
|
+
const { data } = nextSibling, offset = data.indexOf('\n'), text = new text_1.AstText(data.slice(0, offset));
|
|
86
|
+
end = childNodes.indexOf(nextSibling);
|
|
87
|
+
contents = childNodes.slice(start, end);
|
|
88
|
+
const last = contents.at(-1);
|
|
89
|
+
if (last) {
|
|
90
|
+
last.setAttribute('nextSibling', text);
|
|
91
|
+
text.setAttribute('previousSibling', last);
|
|
92
|
+
}
|
|
93
|
+
contents.push(text);
|
|
94
|
+
nextSibling.setAttribute('data', data.slice(offset));
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
end = childNodes.length;
|
|
98
|
+
contents = childNodes.slice(start);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const token = debug_1.Shadow.run(() => {
|
|
102
|
+
const t = new index_1.Token(undefined, this.getAttribute('config'));
|
|
103
|
+
t.type = 'list-range';
|
|
104
|
+
return t;
|
|
105
|
+
});
|
|
106
|
+
token.concat(contents); // eslint-disable-line unicorn/no-unused-builtin-method-return
|
|
107
|
+
(0, debug_1.setChildNodes)(parentNode, start, end - start, [token]);
|
|
108
|
+
return token;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
7
111
|
}
|
|
8
112
|
exports.ListBaseToken = ListBaseToken;
|
package/dist/src/paramLine.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { ParamTagToken, FuncTagToken } from '../internal';
|
|
|
6
6
|
* parameter of certain extension tags
|
|
7
7
|
*
|
|
8
8
|
* 某些扩展标签的参数
|
|
9
|
-
* @classdesc `{childNodes: [AtomToken
|
|
9
|
+
* @classdesc `{childNodes: [AtomToken, AtomToken?]}`
|
|
10
10
|
*/
|
|
11
11
|
export declare abstract class ParamLineToken extends Token {
|
|
12
12
|
readonly name: string;
|
package/dist/src/paramLine.js
CHANGED
|
@@ -49,7 +49,7 @@ const skipTypes = new Set(['comment', 'include', 'noinclude']);
|
|
|
49
49
|
* parameter of certain extension tags
|
|
50
50
|
*
|
|
51
51
|
* 某些扩展标签的参数
|
|
52
|
-
* @classdesc `{childNodes: [AtomToken
|
|
52
|
+
* @classdesc `{childNodes: [AtomToken, AtomToken?]}`
|
|
53
53
|
*/
|
|
54
54
|
let ParamLineToken = (() => {
|
|
55
55
|
let _classDecorators = [(0, gapped_1.gapped)()];
|
package/dist/src/pre.d.ts
CHANGED
|
@@ -2,15 +2,16 @@ import { Token } from './index';
|
|
|
2
2
|
import { NoincludeToken } from './nowiki/noinclude';
|
|
3
3
|
import type { Config, LintError } from '../base';
|
|
4
4
|
import type { AstText, AttributesToken, ExtToken, ConverterToken } from '../internal';
|
|
5
|
+
declare type Child = NoincludeToken | ConverterToken;
|
|
5
6
|
/**
|
|
6
7
|
* `<pre>`
|
|
7
8
|
* @classdesc `{childNodes: (AstText|NoincludeToken|ConverterToken)[]}`
|
|
8
9
|
*/
|
|
9
10
|
export declare abstract class PreToken extends Token {
|
|
10
11
|
readonly name: 'pre';
|
|
11
|
-
readonly childNodes: readonly (
|
|
12
|
-
abstract get firstChild():
|
|
13
|
-
abstract get lastChild():
|
|
12
|
+
readonly childNodes: readonly (Child | AstText)[];
|
|
13
|
+
abstract get firstChild(): Child | AstText | undefined;
|
|
14
|
+
abstract get lastChild(): Child | AstText | undefined;
|
|
14
15
|
abstract get nextSibling(): undefined;
|
|
15
16
|
abstract get previousSibling(): AttributesToken | undefined;
|
|
16
17
|
abstract get parentNode(): ExtToken | undefined;
|
|
@@ -18,3 +19,4 @@ export declare abstract class PreToken extends Token {
|
|
|
18
19
|
/** @class */
|
|
19
20
|
constructor(wikitext?: string, config?: Config, accum?: Token[]);
|
|
20
21
|
}
|
|
22
|
+
export {};
|
package/dist/src/redirect.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { Config, LintError } from '../base';
|
|
|
6
6
|
* redirect
|
|
7
7
|
*
|
|
8
8
|
* 重定向
|
|
9
|
-
* @classdesc `{childNodes: [SyntaxToken,
|
|
9
|
+
* @classdesc `{childNodes: [SyntaxToken, RedirectTargetToken]}`
|
|
10
10
|
*/
|
|
11
11
|
export declare abstract class RedirectToken extends Token {
|
|
12
12
|
#private;
|
package/dist/src/redirect.js
CHANGED
|
@@ -44,7 +44,7 @@ const redirectTarget_1 = require("./link/redirectTarget");
|
|
|
44
44
|
* redirect
|
|
45
45
|
*
|
|
46
46
|
* 重定向
|
|
47
|
-
* @classdesc `{childNodes: [SyntaxToken,
|
|
47
|
+
* @classdesc `{childNodes: [SyntaxToken, RedirectTargetToken]}`
|
|
48
48
|
*/
|
|
49
49
|
let RedirectToken = (() => {
|
|
50
50
|
let _classDecorators = [(0, hidden_1.hiddenToken)(false, false), noEscape_1.noEscape];
|