wikilint 2.16.4 → 2.16.6
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/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 +42 -16
- package/dist/lib/element.js +45 -17
- package/dist/lib/lsp.d.ts +64 -35
- package/dist/lib/lsp.js +208 -159
- package/dist/lib/node.d.ts +50 -18
- package/dist/lib/node.js +66 -27
- package/dist/lib/text.d.ts +8 -2
- package/dist/lib/text.js +10 -3
- package/dist/lib/title.d.ts +19 -10
- package/dist/lib/title.js +28 -22
- package/dist/mixin/attributesParent.d.ts +4 -4
- package/dist/mixin/attributesParent.js +0 -2
- package/dist/mixin/hidden.d.ts +0 -2
- package/dist/mixin/hidden.js +0 -2
- package/dist/parser/braces.js +52 -20
- package/dist/parser/commentAndExt.js +17 -4
- 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 +4 -2
- package/dist/src/hidden.d.ts +5 -1
- package/dist/src/hidden.js +5 -1
- package/dist/src/html.d.ts +6 -2
- package/dist/src/html.js +6 -2
- 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 -3
- package/dist/src/index.js +28 -18
- package/dist/src/link/base.d.ts +4 -2
- package/dist/src/link/base.js +12 -6
- package/dist/src/link/category.d.ts +2 -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 +2 -0
- package/dist/src/link/index.js +2 -0
- package/dist/src/link/redirectTarget.d.ts +2 -1
- package/dist/src/link/redirectTarget.js +4 -2
- package/dist/src/magicLink.d.ts +8 -4
- package/dist/src/magicLink.js +16 -9
- 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 +3 -1
- package/dist/src/tagPair/ext.js +3 -1
- 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 +34 -10
- package/dist/src/transclude.js +47 -17
- 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 +2 -2
package/dist/src/gallery.js
CHANGED
|
@@ -6,8 +6,10 @@ const index_2 = require("./index");
|
|
|
6
6
|
const galleryImage_1 = require("./link/galleryImage");
|
|
7
7
|
const noinclude_1 = require("./nowiki/noinclude");
|
|
8
8
|
/**
|
|
9
|
+
* gallery tag
|
|
10
|
+
*
|
|
9
11
|
* gallery标签
|
|
10
|
-
* @classdesc `{childNodes:
|
|
12
|
+
* @classdesc `{childNodes: (GalleryImageToken|NoincludeToken|AstText)[]}`
|
|
11
13
|
*/
|
|
12
14
|
class GalleryToken extends index_2.Token {
|
|
13
15
|
get type() {
|
|
@@ -39,7 +41,7 @@ class GalleryToken extends index_2.Token {
|
|
|
39
41
|
* @param file 文件名
|
|
40
42
|
*/
|
|
41
43
|
#checkFile(file) {
|
|
42
|
-
return this.normalizeTitle(file, 6, true, true).valid;
|
|
44
|
+
return this.normalizeTitle(file, 6, true, true, true).valid;
|
|
43
45
|
}
|
|
44
46
|
/** @private */
|
|
45
47
|
toString(skip) {
|
|
@@ -57,8 +59,8 @@ class GalleryToken extends index_2.Token {
|
|
|
57
59
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
58
60
|
const { top, left } = this.getRootNode().posFromIndex(start), errors = [];
|
|
59
61
|
for (const [i, child] of this.childNodes.entries()) {
|
|
60
|
-
const str = child.toString(), { length } = str, trimmed = str.trim(), startLine = top + i, startCol = i ? 0 : left;
|
|
61
|
-
if (
|
|
62
|
+
const str = child.toString(), { length } = str, trimmed = str.trim(), { type } = child, startLine = top + i, startCol = i ? 0 : left;
|
|
63
|
+
if (type === 'noinclude' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
|
|
62
64
|
const endIndex = start + length;
|
|
63
65
|
errors.push({
|
|
64
66
|
rule: 'no-ignored',
|
|
@@ -76,7 +78,7 @@ class GalleryToken extends index_2.Token {
|
|
|
76
78
|
],
|
|
77
79
|
});
|
|
78
80
|
}
|
|
79
|
-
else if (
|
|
81
|
+
else if (type !== 'noinclude' && type !== 'text') {
|
|
80
82
|
errors.push(...child.lint(start, re));
|
|
81
83
|
}
|
|
82
84
|
start += length + 1;
|
package/dist/src/heading.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { SyntaxToken } from './syntax';
|
|
|
4
4
|
import type { LintError } from '../base';
|
|
5
5
|
import type { AstText } from '../internal';
|
|
6
6
|
/**
|
|
7
|
+
* section heading
|
|
8
|
+
*
|
|
7
9
|
* 章节标题
|
|
8
10
|
* @classdesc `{childNodes: [Token, SyntaxToken]}`
|
|
9
11
|
*/
|
|
@@ -14,7 +16,7 @@ export declare abstract class HeadingToken extends Token {
|
|
|
14
16
|
abstract get lastChild(): SyntaxToken;
|
|
15
17
|
abstract get nextSibling(): AstText | undefined;
|
|
16
18
|
get type(): 'heading';
|
|
17
|
-
/** 标题层级 */
|
|
19
|
+
/** level of the heading / 标题层级 */
|
|
18
20
|
get level(): number;
|
|
19
21
|
/**
|
|
20
22
|
* @param level 标题层级
|
package/dist/src/heading.js
CHANGED
|
@@ -8,6 +8,8 @@ const index_1 = require("../index");
|
|
|
8
8
|
const index_2 = require("./index");
|
|
9
9
|
const syntax_1 = require("./syntax");
|
|
10
10
|
/**
|
|
11
|
+
* section heading
|
|
12
|
+
*
|
|
11
13
|
* 章节标题
|
|
12
14
|
* @classdesc `{childNodes: [Token, SyntaxToken]}`
|
|
13
15
|
*/
|
|
@@ -16,7 +18,7 @@ class HeadingToken extends index_2.Token {
|
|
|
16
18
|
get type() {
|
|
17
19
|
return 'heading';
|
|
18
20
|
}
|
|
19
|
-
/** 标题层级 */
|
|
21
|
+
/** level of the heading / 标题层级 */
|
|
20
22
|
get level() {
|
|
21
23
|
return this.#level;
|
|
22
24
|
}
|
|
@@ -87,7 +89,7 @@ class HeadingToken extends index_2.Token {
|
|
|
87
89
|
errors.push(e);
|
|
88
90
|
}
|
|
89
91
|
if (this.closest('html-attrs,table-attrs')) {
|
|
90
|
-
errors.push((0, lint_1.generateForSelf)(this, rect, 'parsing-order', 'section header in
|
|
92
|
+
errors.push((0, lint_1.generateForSelf)(this, rect, 'parsing-order', 'section header in an HTML tag'));
|
|
91
93
|
}
|
|
92
94
|
const rootStr = this.getRootNode().toString();
|
|
93
95
|
if (boldQuotes.length % 2) {
|
package/dist/src/hidden.d.ts
CHANGED
package/dist/src/hidden.js
CHANGED
|
@@ -37,7 +37,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
37
37
|
exports.HiddenToken = void 0;
|
|
38
38
|
const hidden_1 = require("../mixin/hidden");
|
|
39
39
|
const index_1 = require("./index");
|
|
40
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* invisible token
|
|
42
|
+
*
|
|
43
|
+
* 不可见的节点
|
|
44
|
+
*/
|
|
41
45
|
let HiddenToken = (() => {
|
|
42
46
|
let _classDecorators = [(0, hidden_1.hiddenToken)()];
|
|
43
47
|
let _classDescriptor;
|
package/dist/src/html.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ import type { AttributesToken } from '../internal';
|
|
|
5
5
|
export interface HtmlToken extends AttributesParentBase {
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
+
* HTML tag
|
|
9
|
+
*
|
|
8
10
|
* HTML标签
|
|
9
11
|
* @classdesc `{childNodes: [AttributesToken]}`
|
|
10
12
|
*/
|
|
@@ -15,9 +17,9 @@ export declare abstract class HtmlToken extends Token {
|
|
|
15
17
|
abstract get firstChild(): AttributesToken;
|
|
16
18
|
abstract get lastChild(): AttributesToken;
|
|
17
19
|
get type(): 'html';
|
|
18
|
-
/** 是否自封闭 */
|
|
20
|
+
/** whether to be self-closing / 是否自封闭 */
|
|
19
21
|
get selfClosing(): boolean;
|
|
20
|
-
/** 是否是闭合标签 */
|
|
22
|
+
/** whether to be a closing tag / 是否是闭合标签 */
|
|
21
23
|
get closing(): boolean;
|
|
22
24
|
/**
|
|
23
25
|
* @param name 标签名
|
|
@@ -27,6 +29,8 @@ export declare abstract class HtmlToken extends Token {
|
|
|
27
29
|
*/
|
|
28
30
|
constructor(name: string, attr: AttributesToken, closing: boolean, selfClosing: boolean, config?: Config, accum?: Token[]);
|
|
29
31
|
/**
|
|
32
|
+
* Find the matching tag
|
|
33
|
+
*
|
|
30
34
|
* 搜索匹配的标签
|
|
31
35
|
* @throws `SyntaxError` 同时闭合和自封闭的标签
|
|
32
36
|
* @throws `SyntaxError` 无效自封闭标签
|
package/dist/src/html.js
CHANGED
|
@@ -68,6 +68,8 @@ const magicWords = new Set(['if', 'ifeq', 'ifexpr', 'ifexist', 'iferror', 'switc
|
|
|
68
68
|
'var',
|
|
69
69
|
]), obsoleteTags = new Set(['strike', 'big', 'center', 'font', 'tt']);
|
|
70
70
|
/**
|
|
71
|
+
* HTML tag
|
|
72
|
+
*
|
|
71
73
|
* HTML标签
|
|
72
74
|
* @classdesc `{childNodes: [AttributesToken]}`
|
|
73
75
|
*/
|
|
@@ -92,11 +94,11 @@ let HtmlToken = (() => {
|
|
|
92
94
|
get type() {
|
|
93
95
|
return 'html';
|
|
94
96
|
}
|
|
95
|
-
/** 是否自封闭 */
|
|
97
|
+
/** whether to be self-closing / 是否自封闭 */
|
|
96
98
|
get selfClosing() {
|
|
97
99
|
return this.#selfClosing;
|
|
98
100
|
}
|
|
99
|
-
/** 是否是闭合标签 */
|
|
101
|
+
/** whether to be a closing tag / 是否是闭合标签 */
|
|
100
102
|
get closing() {
|
|
101
103
|
return this.#closing;
|
|
102
104
|
}
|
|
@@ -208,6 +210,8 @@ let HtmlToken = (() => {
|
|
|
208
210
|
return errors;
|
|
209
211
|
}
|
|
210
212
|
/**
|
|
213
|
+
* Find the matching tag
|
|
214
|
+
*
|
|
211
215
|
* 搜索匹配的标签
|
|
212
216
|
* @throws `SyntaxError` 同时闭合和自封闭的标签
|
|
213
217
|
* @throws `SyntaxError` 无效自封闭标签
|
|
@@ -4,7 +4,11 @@ import type { LintError } from '../base';
|
|
|
4
4
|
import type { Title } from '../lib/title';
|
|
5
5
|
import type { AtomToken, FileToken } from '../internal';
|
|
6
6
|
export declare const galleryParams: Set<string>;
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* image parameter
|
|
9
|
+
*
|
|
10
|
+
* 图片参数
|
|
11
|
+
*/
|
|
8
12
|
export declare abstract class ImageParameterToken extends Token {
|
|
9
13
|
#private;
|
|
10
14
|
readonly name: string;
|
|
@@ -12,10 +16,14 @@ export declare abstract class ImageParameterToken extends Token {
|
|
|
12
16
|
abstract get nextSibling(): this | undefined;
|
|
13
17
|
abstract get previousSibling(): AtomToken | this;
|
|
14
18
|
get type(): 'image-parameter';
|
|
15
|
-
/** 图片链接 */
|
|
19
|
+
/** image link / 图片链接 */
|
|
16
20
|
get link(): string | Title | undefined;
|
|
17
21
|
/** @param str 图片参数 */
|
|
18
22
|
constructor(str: string, extension: string | undefined, config?: Parser.Config, accum?: Token[]);
|
|
19
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Get the parameter value
|
|
25
|
+
*
|
|
26
|
+
* 获取参数值
|
|
27
|
+
*/
|
|
20
28
|
getValue(): string | true;
|
|
21
29
|
}
|
|
@@ -24,7 +24,7 @@ function validate(key, val, config, halfParsed, ext) {
|
|
|
24
24
|
else if (value.startsWith('[[') && value.endsWith(']]')) {
|
|
25
25
|
value = value.slice(2, -2);
|
|
26
26
|
}
|
|
27
|
-
const title = index_1.default.normalizeTitle(value, 0, false, config, halfParsed, true, true);
|
|
27
|
+
const title = index_1.default.normalizeTitle(value, 0, false, config, false, halfParsed, true, true);
|
|
28
28
|
return title.valid && title;
|
|
29
29
|
}
|
|
30
30
|
case 'lang':
|
|
@@ -39,13 +39,17 @@ function validate(key, val, config, halfParsed, ext) {
|
|
|
39
39
|
return Boolean(value) && !isNaN(value);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* image parameter
|
|
44
|
+
*
|
|
45
|
+
* 图片参数
|
|
46
|
+
*/
|
|
43
47
|
class ImageParameterToken extends index_2.Token {
|
|
44
48
|
#syntax = '';
|
|
45
49
|
get type() {
|
|
46
50
|
return 'image-parameter';
|
|
47
51
|
}
|
|
48
|
-
/** 图片链接 */
|
|
52
|
+
/** image link / 图片链接 */
|
|
49
53
|
get link() {
|
|
50
54
|
return this.name === 'link' ? validate('link', super.text(), this.getAttribute('config')) : undefined;
|
|
51
55
|
}
|
|
@@ -121,7 +125,11 @@ class ImageParameterToken extends index_2.Token {
|
|
|
121
125
|
#isVoid() {
|
|
122
126
|
return this.#syntax && !this.#syntax.includes('$1');
|
|
123
127
|
}
|
|
124
|
-
/**
|
|
128
|
+
/**
|
|
129
|
+
* Get the parameter value
|
|
130
|
+
*
|
|
131
|
+
* 获取参数值
|
|
132
|
+
*/
|
|
125
133
|
getValue() {
|
|
126
134
|
return this.name === 'invalid' ? this.text() : this.#isVoid() || super.text();
|
|
127
135
|
}
|
package/dist/src/imagemap.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { AstText, AttributesToken, ExtToken } from '../internal';
|
|
|
8
8
|
declare type Child = GalleryImageToken | NoincludeToken;
|
|
9
9
|
/**
|
|
10
10
|
* `<imagemap>`
|
|
11
|
-
* @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
|
|
11
|
+
* @classdesc `{childNodes: [...NoincludeToken[], GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)[]]}`
|
|
12
12
|
*/
|
|
13
13
|
export declare abstract class ImagemapToken extends Token {
|
|
14
14
|
readonly name: 'imagemap';
|
package/dist/src/imagemap.js
CHANGED
|
@@ -11,7 +11,7 @@ const galleryImage_1 = require("./link/galleryImage");
|
|
|
11
11
|
const imagemapLink_1 = require("./imagemapLink");
|
|
12
12
|
/**
|
|
13
13
|
* `<imagemap>`
|
|
14
|
-
* @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
|
|
14
|
+
* @classdesc `{childNodes: [...NoincludeToken[], GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)[]]}`
|
|
15
15
|
*/
|
|
16
16
|
class ImagemapToken extends index_2.Token {
|
|
17
17
|
get type() {
|
|
@@ -35,8 +35,9 @@ class ImagemapToken extends index_2.Token {
|
|
|
35
35
|
//
|
|
36
36
|
}
|
|
37
37
|
else if (first) {
|
|
38
|
-
const pipe = line.indexOf('|'), file = pipe === -1 ? line : line.slice(0, pipe),
|
|
39
|
-
if (
|
|
38
|
+
const pipe = line.indexOf('|'), file = pipe === -1 ? line : line.slice(0, pipe), { valid, ns, } = this.normalizeTitle(file, 0, true, true);
|
|
39
|
+
if (valid
|
|
40
|
+
&& ns === 6) {
|
|
40
41
|
// @ts-expect-error abstract class
|
|
41
42
|
const token = new galleryImage_1.GalleryImageToken('imagemap', file, pipe === -1 ? undefined : line.slice(pipe + 1), config, accum);
|
|
42
43
|
super.insertAt(token);
|
|
@@ -55,7 +56,7 @@ class ImagemapToken extends index_2.Token {
|
|
|
55
56
|
const i = line.indexOf('['), substr = line.slice(i), mtIn = /^\[\[([^|]+)(?:\|([^\]]+))?\]\][\w\s]*$/u
|
|
56
57
|
.exec(substr);
|
|
57
58
|
if (mtIn) {
|
|
58
|
-
if (this.normalizeTitle(mtIn[1], 0, true, false, true).valid) {
|
|
59
|
+
if (this.normalizeTitle(mtIn[1], 0, true, true, false, true).valid) {
|
|
59
60
|
// @ts-expect-error abstract class
|
|
60
61
|
super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtIn.slice(1), substr.slice(substr.indexOf(']]') + 2), config, accum));
|
|
61
62
|
continue;
|
|
@@ -5,6 +5,8 @@ import { LinkToken } from './link/index';
|
|
|
5
5
|
import { ExtLinkToken } from './extLink';
|
|
6
6
|
import type { AstText, ImagemapToken, GalleryImageToken } from '../internal';
|
|
7
7
|
/**
|
|
8
|
+
* link inside the `<imagemap>`
|
|
9
|
+
*
|
|
8
10
|
* `<imagemap>`内的链接
|
|
9
11
|
* @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
|
|
10
12
|
*/
|
package/dist/src/imagemapLink.js
CHANGED
|
@@ -7,6 +7,8 @@ const noinclude_1 = require("./nowiki/noinclude");
|
|
|
7
7
|
const index_3 = require("./link/index");
|
|
8
8
|
const extLink_1 = require("./extLink");
|
|
9
9
|
/**
|
|
10
|
+
* link inside the `<imagemap>`
|
|
11
|
+
*
|
|
10
12
|
* `<imagemap>`内的链接
|
|
11
13
|
* @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
|
|
12
14
|
*/
|
package/dist/src/index.d.ts
CHANGED
|
@@ -5,8 +5,10 @@ import type { LintError, TokenTypes } from '../base';
|
|
|
5
5
|
import type { Title } from '../lib/title';
|
|
6
6
|
import type { AstNodes } from '../internal';
|
|
7
7
|
/**
|
|
8
|
+
* base class for all tokens
|
|
9
|
+
*
|
|
8
10
|
* 所有节点的基类
|
|
9
|
-
* @classdesc `{childNodes:
|
|
11
|
+
* @classdesc `{childNodes: (AstText|Token)[]}`
|
|
10
12
|
*/
|
|
11
13
|
export declare class Token extends AstElement {
|
|
12
14
|
#private;
|
|
@@ -16,8 +18,8 @@ export declare class Token extends AstElement {
|
|
|
16
18
|
constructor(wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
|
|
17
19
|
/**
|
|
18
20
|
* @override
|
|
19
|
-
* @param child 待插入的子节点
|
|
20
|
-
* @param i 插入位置
|
|
21
|
+
* @param child node to be inserted / 待插入的子节点
|
|
22
|
+
* @param i position to be inserted at / 插入位置
|
|
21
23
|
*/
|
|
22
24
|
insertAt(child: string, i?: number): AstText;
|
|
23
25
|
insertAt<T extends AstNodes>(child: T, i?: number): T;
|
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) {
|
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,7 +16,7 @@ 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;
|
|
17
|
-
/** 完整链接 */
|
|
19
|
+
/** full link / 完整链接 */
|
|
18
20
|
get link(): string | Title;
|
|
19
21
|
/**
|
|
20
22
|
* @param link 链接标题
|
package/dist/src/link/base.js
CHANGED
|
@@ -14,16 +14,19 @@ 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;
|
|
24
|
-
/** 完整链接 */
|
|
26
|
+
/** full link / 完整链接 */
|
|
25
27
|
get link() {
|
|
26
|
-
|
|
28
|
+
// eslint-disable-next-line no-unused-labels
|
|
29
|
+
LSP: return this.#title;
|
|
27
30
|
}
|
|
28
31
|
/**
|
|
29
32
|
* @param link 链接标题
|
|
@@ -112,7 +115,10 @@ class LinkBaseToken extends index_2.Token {
|
|
|
112
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];
|
|
113
116
|
if (textNode) {
|
|
114
117
|
e.fix = {
|
|
115
|
-
range: [
|
|
118
|
+
range: [
|
|
119
|
+
e.startIndex + target.getRelativeIndex(j) + textNode.data.indexOf('#'),
|
|
120
|
+
e.endIndex,
|
|
121
|
+
],
|
|
116
122
|
text: '',
|
|
117
123
|
desc: 'remove',
|
|
118
124
|
};
|
|
@@ -122,8 +128,8 @@ class LinkBaseToken extends index_2.Token {
|
|
|
122
128
|
return errors;
|
|
123
129
|
}
|
|
124
130
|
/** @private */
|
|
125
|
-
getTitle(halfParsed) {
|
|
126
|
-
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);
|
|
127
133
|
}
|
|
128
134
|
}
|
|
129
135
|
exports.LinkBaseToken = LinkBaseToken;
|
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
|
}
|