wikilint 2.48.0 → 3.0.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 +1 -1
- package/data/signatures.json +2 -2
- package/dist/base.d.mts +4 -3
- package/dist/base.d.ts +4 -3
- package/dist/base.js +1 -0
- package/dist/base.mjs +2 -1
- package/dist/bin/cli.js +2 -2
- package/dist/bin/config.js +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +17 -11
- package/dist/internal.d.ts +1 -0
- package/dist/lib/document.d.ts +12 -12
- package/dist/lib/document.js +2 -4
- package/dist/lib/lintConfig.js +1 -0
- package/dist/lib/lsp.js +7 -4
- package/dist/lib/node.d.ts +0 -4
- package/dist/lib/node.js +9 -1
- package/dist/lib/text.js +1 -1
- package/dist/map.d.ts +2 -1
- package/dist/parser/commentAndExt.js +1 -2
- 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/attribute.js +12 -12
- 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 +2 -2
- package/dist/src/extLink.d.ts +1 -1
- package/dist/src/extLink.js +1 -1
- package/dist/src/index.js +55 -14
- package/dist/src/link/base.js +2 -2
- package/dist/src/link/category.d.ts +1 -1
- package/dist/src/link/category.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 +1 -1
- 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 +2 -2
- package/dist/util/ajv.js +26 -0
- package/dist/util/debug.js +7 -1
- package/dist/util/string.js +1 -0
- package/i18n/en.json +1 -0
- package/i18n/zh-hans.json +1 -0
- package/i18n/zh-hant.json +1 -0
- package/package.json +16 -16
package/dist/src/index.js
CHANGED
|
@@ -55,7 +55,7 @@ const debug_1 = require("../util/debug");
|
|
|
55
55
|
const index_1 = __importDefault(require("../index"));
|
|
56
56
|
const element_1 = require("../lib/element");
|
|
57
57
|
const text_1 = require("../lib/text");
|
|
58
|
-
const lintSelectors = ['category', 'html-attr#id,ext-attr#id,table-attr#id'];
|
|
58
|
+
const lintSelectors = ['category', 'html-attr#id,ext-attr#id,table-attr#id', 'ext#indicator'];
|
|
59
59
|
/**
|
|
60
60
|
* base class for all tokens
|
|
61
61
|
*
|
|
@@ -113,6 +113,7 @@ class Token extends element_1.AstElement {
|
|
|
113
113
|
return this;
|
|
114
114
|
}
|
|
115
115
|
/* c8 ignore start */
|
|
116
|
+
// eslint-disable-next-line unicorn/prefer-combined-guards
|
|
116
117
|
if (this.#stage >= constants_1.MAX_STAGE) {
|
|
117
118
|
return this;
|
|
118
119
|
}
|
|
@@ -301,7 +302,7 @@ class Token extends element_1.AstElement {
|
|
|
301
302
|
}
|
|
302
303
|
const { parseList } = require('../parser/list');
|
|
303
304
|
const { firstChild, type, name } = this, lines = firstChild.toString().split('\n'), state = { lastPrefix: '' };
|
|
304
|
-
let i = type === 'root' || type === 'ext-inner' && name
|
|
305
|
+
let i = type === 'root' || type === 'ext-inner' && (0, debug_1.isIsolated)(name) ? 0 : 1;
|
|
305
306
|
for (; i < lines.length; i++) {
|
|
306
307
|
lines[i] = parseList(lines[i], state, this.#config, this.#accum);
|
|
307
308
|
}
|
|
@@ -385,18 +386,24 @@ class Token extends element_1.AstElement {
|
|
|
385
386
|
const { lintConfig } = index_1.default, { computeEditInfo, fix: needFix, ignoreDisables, configurationComment } = lintConfig;
|
|
386
387
|
let errors = super.lint(start, re);
|
|
387
388
|
if (this.type === 'root') {
|
|
388
|
-
const
|
|
389
|
-
|
|
389
|
+
const r = 'no-duplicate', s = ['category', 'id', 'indicator'].map(key => lintConfig.getSeverity(r, key)), msgs = ['category', 'id', 'name'], wikitext = this.toString();
|
|
390
|
+
for (let i = 0; i < s.length; i++) {
|
|
391
|
+
const severity = s[i];
|
|
392
|
+
if (!severity) {
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
const record = new Map(), selector = lintSelectors[i];
|
|
390
396
|
for (const cat of this.querySelectorAll(selector)) {
|
|
391
397
|
let key;
|
|
392
|
-
if (
|
|
398
|
+
if (i === 0) { // category
|
|
393
399
|
key = cat.name;
|
|
394
400
|
}
|
|
395
|
-
else {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
401
|
+
else if (i === 1) { // id
|
|
402
|
+
key = cat.getValue().replace(/\s+/gu, '_');
|
|
403
|
+
}
|
|
404
|
+
else { // indicator
|
|
405
|
+
key = cat.getAttr('name')
|
|
406
|
+
?.replace(/\s+/gu, '_');
|
|
400
407
|
}
|
|
401
408
|
if (key) {
|
|
402
409
|
const thisCat = record.get(key);
|
|
@@ -409,11 +416,10 @@ class Token extends element_1.AstElement {
|
|
|
409
416
|
}
|
|
410
417
|
}
|
|
411
418
|
for (const [key, value] of record) {
|
|
412
|
-
if (value.size > 1 && !key.startsWith('
|
|
413
|
-
const isCat = !key.startsWith('#'), msg = `duplicate-${isCat ? 'category' : 'id'}`, severity = s[isCat ? 0 : 1];
|
|
419
|
+
if (value.size > 1 && (i !== 1 || !key.startsWith('mw-customcollapsible-'))) {
|
|
414
420
|
errors.push(...[...value].map(cat => {
|
|
415
|
-
const e = (0, lint_1.generateForSelf)(cat, { start: cat.getAbsoluteIndex() }, r,
|
|
416
|
-
if (computeEditInfo &&
|
|
421
|
+
const e = (0, lint_1.generateForSelf)(cat, { start: cat.getAbsoluteIndex() }, r, `duplicate-${msgs[i]}`, severity);
|
|
422
|
+
if (computeEditInfo && i === 0) {
|
|
417
423
|
e.suggestions = [(0, lint_1.fixByRemove)(e)];
|
|
418
424
|
}
|
|
419
425
|
return e;
|
|
@@ -495,5 +501,40 @@ class Token extends element_1.AstElement {
|
|
|
495
501
|
}
|
|
496
502
|
});
|
|
497
503
|
}
|
|
504
|
+
/**
|
|
505
|
+
* 构建列表
|
|
506
|
+
* @param recursive 是否递归
|
|
507
|
+
*/
|
|
508
|
+
#buildLists(recursive) {
|
|
509
|
+
PRINT: for (let i = 0; i < this.length; i++) {
|
|
510
|
+
const child = this.childNodes[i];
|
|
511
|
+
if (child.is('list') || child.is('dd')) {
|
|
512
|
+
child.getRange();
|
|
513
|
+
}
|
|
514
|
+
else if (recursive && child.type !== 'text') {
|
|
515
|
+
child.#buildLists(true);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
/** @private */
|
|
520
|
+
buildLists() {
|
|
521
|
+
PRINT: this.#buildLists(true);
|
|
522
|
+
}
|
|
523
|
+
/** @private */
|
|
524
|
+
concat(elements) {
|
|
525
|
+
PRINT: {
|
|
526
|
+
if (elements.length === 0) {
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
const { childNodes, lastChild } = this, first = elements[0], last = elements.at(-1);
|
|
530
|
+
for (const element of elements) {
|
|
531
|
+
element.setAttribute('parentNode', this);
|
|
532
|
+
}
|
|
533
|
+
lastChild?.setAttribute('nextSibling', first);
|
|
534
|
+
first.setAttribute('previousSibling', lastChild);
|
|
535
|
+
last.setAttribute('nextSibling', undefined);
|
|
536
|
+
this.setAttribute('childNodes', [...childNodes, ...elements]);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
498
539
|
}
|
|
499
540
|
exports.Token = Token;
|
package/dist/src/link/base.js
CHANGED
|
@@ -124,7 +124,7 @@ let LinkBaseToken = (() => {
|
|
|
124
124
|
/** @private */
|
|
125
125
|
toString(skip) {
|
|
126
126
|
const str = super.toString(skip, this.#delimiter);
|
|
127
|
-
if (this.#bracket) { //
|
|
127
|
+
if (this.#bracket) { // eslint-disable-line unicorn/prefer-ternary
|
|
128
128
|
return `[[${str}]]`;
|
|
129
129
|
}
|
|
130
130
|
return str;
|
|
@@ -137,7 +137,7 @@ let LinkBaseToken = (() => {
|
|
|
137
137
|
'trim']()
|
|
138
138
|
: `${target.trim()}|${(0, string_1.text)(childNodes.slice(1)
|
|
139
139
|
.filter(({ type: t, name }) => t !== 'image-parameter' || name !== 'invalid'), '|')}`;
|
|
140
|
-
if (this.#bracket) { //
|
|
140
|
+
if (this.#bracket) { // eslint-disable-line unicorn/prefer-ternary
|
|
141
141
|
return `[[${str}]]`;
|
|
142
142
|
}
|
|
143
143
|
return str;
|
|
@@ -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];
|
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
|
}
|
|
@@ -28,7 +28,7 @@ class GalleryToken extends index_2.MultiLineToken {
|
|
|
28
28
|
continue;
|
|
29
29
|
}
|
|
30
30
|
const [, file, alt] = matches;
|
|
31
|
-
if (this.#checkFile(file)) {
|
|
31
|
+
if (this.#checkFile(file)) { // eslint-disable-line unicorn/prefer-ternary
|
|
32
32
|
// @ts-expect-error abstract class
|
|
33
33
|
super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
|
|
34
34
|
}
|
|
@@ -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];
|
|
@@ -6,7 +6,7 @@ import type { Token, CharinsertToken, AstText } from '../../internal';
|
|
|
6
6
|
* lines in `<charinsert>`
|
|
7
7
|
*
|
|
8
8
|
* `<charinsert>` 的行
|
|
9
|
-
* @classdesc `{childNodes: (AstText
|
|
9
|
+
* @classdesc `{childNodes: (AstText|ExtToken)[]}`
|
|
10
10
|
*/
|
|
11
11
|
export declare abstract class CharinsertLineToken extends SingleLineToken {
|
|
12
12
|
readonly childNodes: readonly (AstText | ExtToken)[];
|
|
@@ -13,7 +13,7 @@ const ext_1 = require("../tagPair/ext");
|
|
|
13
13
|
* lines in `<charinsert>`
|
|
14
14
|
*
|
|
15
15
|
* `<charinsert>` 的行
|
|
16
|
-
* @classdesc `{childNodes: (AstText
|
|
16
|
+
* @classdesc `{childNodes: (AstText|ExtToken)[]}`
|
|
17
17
|
*/
|
|
18
18
|
class CharinsertLineToken extends index_2.SingleLineToken {
|
|
19
19
|
get type() {
|
|
@@ -6,13 +6,13 @@ import type { TableCoords } from './trBase';
|
|
|
6
6
|
export type TableTokens = TableToken | TrToken | TdToken;
|
|
7
7
|
/** @extends {Array<TableCoords[]>} */
|
|
8
8
|
export declare class Layout extends Array<TableCoords[]> {
|
|
9
|
-
|
|
9
|
+
static from: (arr: TableCoords[][]) => Layout;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* table
|
|
13
13
|
*
|
|
14
14
|
* 表格
|
|
15
|
-
* @classdesc `{childNodes: [SyntaxToken, AttributesToken,
|
|
15
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ...TdToken[], ...TrToken[], SyntaxToken?]}`
|
|
16
16
|
*/
|
|
17
17
|
export declare abstract class TableToken extends TrBaseToken {
|
|
18
18
|
readonly childNodes: readonly [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[], SyntaxToken] | readonly [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[]];
|
package/dist/src/table/index.js
CHANGED
|
@@ -53,7 +53,7 @@ exports.Layout = Layout;
|
|
|
53
53
|
* table
|
|
54
54
|
*
|
|
55
55
|
* 表格
|
|
56
|
-
* @classdesc `{childNodes: [SyntaxToken, AttributesToken,
|
|
56
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ...TdToken[], ...TrToken[], SyntaxToken?]}`
|
|
57
57
|
*/
|
|
58
58
|
let TableToken = (() => {
|
|
59
59
|
let _classSuper = trBase_1.TrBaseToken;
|
package/dist/src/table/tr.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { Token, TdToken, TableToken, SyntaxToken, AttributesToken } from '.
|
|
|
5
5
|
* table row that contains the newline at the beginning but not at the end
|
|
6
6
|
*
|
|
7
7
|
* 表格行,含开头的换行,不含结尾的换行
|
|
8
|
-
* @classdesc `{childNodes: [SyntaxToken, AttributesToken,
|
|
8
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ...TdToken[]]}`
|
|
9
9
|
*/
|
|
10
10
|
export declare abstract class TrToken extends TrBaseToken {
|
|
11
11
|
readonly childNodes: readonly [SyntaxToken, AttributesToken, ...TdToken[]];
|
package/dist/src/table/tr.js
CHANGED
|
@@ -6,7 +6,7 @@ const trBase_1 = require("./trBase");
|
|
|
6
6
|
* table row that contains the newline at the beginning but not at the end
|
|
7
7
|
*
|
|
8
8
|
* 表格行,含开头的换行,不含结尾的换行
|
|
9
|
-
* @classdesc `{childNodes: [SyntaxToken, AttributesToken,
|
|
9
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ...TdToken[]]}`
|
|
10
10
|
*/
|
|
11
11
|
class TrToken extends trBase_1.TrBaseToken {
|
|
12
12
|
get type() {
|
package/dist/src/tag/index.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { Token } from '../index';
|
|
2
2
|
import type { Config } from '../../base';
|
|
3
3
|
import type { AttributesToken, SyntaxToken } from '../../internal';
|
|
4
|
+
declare type Child = AttributesToken | SyntaxToken;
|
|
4
5
|
/**
|
|
5
6
|
* HTML tag
|
|
6
7
|
*
|
|
7
8
|
* HTML标签
|
|
8
|
-
* @classdesc `{childNodes: [AttributesToken]}`
|
|
9
|
+
* @classdesc `{childNodes: [AttributesToken|SyntaxToken]}`
|
|
9
10
|
*/
|
|
10
11
|
export declare abstract class TagToken extends Token {
|
|
11
12
|
#private;
|
|
12
|
-
readonly childNodes: readonly [
|
|
13
|
-
abstract get firstChild():
|
|
14
|
-
abstract get lastChild():
|
|
13
|
+
readonly childNodes: readonly [Child];
|
|
14
|
+
abstract get firstChild(): Child;
|
|
15
|
+
abstract get lastChild(): Child;
|
|
15
16
|
abstract get type(): 'html' | 'tvar';
|
|
16
17
|
abstract get selfClosing(): boolean | undefined;
|
|
17
18
|
/** whether to be a closing tag / 是否是闭合标签 */
|
|
@@ -21,7 +22,7 @@ export declare abstract class TagToken extends Token {
|
|
|
21
22
|
* @param attr 标签属性
|
|
22
23
|
* @param closing 是否闭合
|
|
23
24
|
*/
|
|
24
|
-
constructor(tag: string, attr:
|
|
25
|
+
constructor(tag: string, attr: Child, closing: boolean, config?: Config, accum?: Token[]);
|
|
25
26
|
/**
|
|
26
27
|
* Find the matching tag
|
|
27
28
|
*
|
|
@@ -29,3 +30,4 @@ export declare abstract class TagToken extends Token {
|
|
|
29
30
|
*/
|
|
30
31
|
findMatchingTag(): this | undefined;
|
|
31
32
|
}
|
|
33
|
+
export {};
|