wikilint 2.0.0-beta.1 → 2.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 +3 -2
- package/bin/cli.js +3 -0
- package/dist/bin/cli.js +0 -0
- package/dist/index.d.ts +1 -5
- package/dist/index.js +18 -18
- package/dist/internal.d.ts +5 -5
- package/dist/lib/element.d.ts +3 -24
- package/dist/lib/element.js +10 -30
- package/dist/lib/node.d.ts +10 -40
- package/dist/lib/node.js +23 -60
- package/dist/lib/text.d.ts +2 -17
- package/dist/lib/text.js +4 -18
- package/dist/lib/title.d.ts +0 -5
- package/dist/lib/title.js +3 -7
- package/dist/mixin/flagsParent.js +14 -0
- package/dist/mixin/hidden.js +0 -1
- package/dist/mixin/magicLinkParent.js +14 -0
- package/dist/parser/braces.js +3 -1
- package/dist/parser/hrAndDoubleUnderscore.js +4 -4
- package/dist/parser/links.js +4 -4
- package/dist/parser/table.js +7 -6
- package/dist/src/arg.d.ts +5 -23
- package/dist/src/arg.js +17 -29
- package/dist/src/atom.d.ts +2 -2
- package/dist/src/atom.js +3 -3
- package/dist/src/attribute.d.ts +6 -33
- package/dist/src/attribute.js +18 -51
- package/dist/src/attributes.d.ts +6 -13
- package/dist/src/attributes.js +7 -13
- package/dist/src/converter.d.ts +9 -14
- package/dist/src/converter.js +7 -14
- package/dist/src/converterFlags.d.ts +6 -27
- package/dist/src/converterFlags.js +10 -30
- package/dist/src/converterRule.d.ts +2 -12
- package/dist/src/converterRule.js +4 -12
- package/dist/src/extLink.d.ts +9 -14
- package/dist/src/extLink.js +13 -19
- package/dist/src/gallery.d.ts +5 -19
- package/dist/src/gallery.js +14 -20
- package/dist/src/heading.d.ts +4 -20
- package/dist/src/heading.js +17 -32
- package/dist/src/hidden.d.ts +1 -4
- package/dist/src/hidden.js +2 -3
- package/dist/src/html.d.ts +4 -21
- package/dist/src/html.js +11 -27
- package/dist/src/imageParameter.d.ts +7 -24
- package/dist/src/imageParameter.js +20 -35
- package/dist/src/imagemap.d.ts +7 -26
- package/dist/src/imagemap.js +11 -27
- package/dist/src/imagemapLink.d.ts +2 -4
- package/dist/src/imagemapLink.js +4 -6
- package/dist/src/index.d.ts +1 -11
- package/dist/src/index.js +35 -83
- package/dist/src/link/base.d.ts +3 -15
- package/dist/src/link/base.js +25 -35
- package/dist/src/link/category.d.ts +2 -3
- package/dist/src/link/category.js +2 -3
- package/dist/src/link/file.d.ts +5 -23
- package/dist/src/link/file.js +5 -26
- package/dist/src/link/galleryImage.d.ts +2 -6
- package/dist/src/link/galleryImage.js +15 -19
- package/dist/src/link/index.d.ts +1 -2
- package/dist/src/link/index.js +0 -1
- package/dist/src/magicLink.d.ts +6 -6
- package/dist/src/magicLink.js +6 -9
- package/dist/src/nested.d.ts +2 -7
- package/dist/src/nested.js +6 -13
- package/dist/src/nowiki/base.d.ts +6 -1
- package/dist/src/nowiki/base.js +11 -2
- package/dist/src/nowiki/comment.d.ts +3 -17
- package/dist/src/nowiki/comment.js +6 -16
- package/dist/src/nowiki/dd.d.ts +3 -4
- package/dist/src/nowiki/dd.js +2 -3
- package/dist/src/nowiki/doubleUnderscore.d.ts +5 -6
- package/dist/src/nowiki/doubleUnderscore.js +12 -8
- package/dist/src/nowiki/hr.d.ts +0 -1
- package/dist/src/nowiki/hr.js +0 -1
- package/dist/src/nowiki/index.d.ts +1 -5
- package/dist/src/nowiki/index.js +3 -7
- package/dist/src/nowiki/list.d.ts +2 -3
- package/dist/src/nowiki/list.js +2 -3
- package/dist/src/nowiki/listBase.d.ts +5 -0
- package/dist/src/nowiki/listBase.js +9 -0
- package/dist/src/nowiki/noinclude.d.ts +0 -3
- package/dist/src/nowiki/noinclude.js +0 -1
- package/dist/src/nowiki/quote.d.ts +1 -5
- package/dist/src/nowiki/quote.js +1 -5
- package/dist/src/onlyinclude.d.ts +1 -17
- package/dist/src/onlyinclude.js +9 -20
- package/dist/src/paramTag/index.d.ts +4 -16
- package/dist/src/paramTag/index.js +8 -18
- package/dist/src/paramTag/inputbox.d.ts +3 -3
- package/dist/src/paramTag/inputbox.js +3 -3
- package/dist/src/parameter.d.ts +4 -20
- package/dist/src/parameter.js +19 -27
- package/dist/src/pre.d.ts +2 -3
- package/dist/src/pre.js +7 -7
- package/dist/src/syntax.d.ts +2 -6
- package/dist/src/syntax.js +4 -10
- package/dist/src/table/base.d.ts +2 -3
- package/dist/src/table/base.js +3 -4
- package/dist/src/table/index.d.ts +4 -20
- package/dist/src/table/index.js +9 -23
- package/dist/src/table/td.d.ts +4 -24
- package/dist/src/table/td.js +11 -25
- package/dist/src/table/tr.d.ts +0 -2
- package/dist/src/table/tr.js +0 -2
- package/dist/src/table/trBase.d.ts +1 -9
- package/dist/src/table/trBase.js +1 -12
- package/dist/src/tagPair/ext.d.ts +3 -7
- package/dist/src/tagPair/ext.js +12 -13
- package/dist/src/tagPair/include.d.ts +1 -8
- package/dist/src/tagPair/include.js +2 -4
- package/dist/src/tagPair/index.d.ts +3 -15
- package/dist/src/tagPair/index.js +10 -23
- package/dist/src/transclude.d.ts +7 -35
- package/dist/src/transclude.js +43 -57
- package/dist/util/constants.js +4 -0
- package/dist/util/debug.js +11 -0
- package/dist/util/diff.js +4 -3
- package/dist/util/string.js +0 -5
- package/i18n/zh-hans.json +2 -0
- package/i18n/zh-hant.json +2 -0
- package/package.json +11 -10
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
[](https://www.npmjs.com/package/wikilint)
|
|
2
|
-
[](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/codeql.yml)
|
|
3
|
+
[](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/node.js.yml)
|
|
3
4
|
|
|
4
5
|
# wikilint
|
|
5
6
|
This is a minimal version of [wikiparser-node](https://www.npmjs.com/package/wikiparser-node) customized for [eslint-plugin-wikitext](https://www.npmjs.com/package/eslint-plugin-wikitext).
|
|
@@ -7,7 +8,7 @@ This is a minimal version of [wikiparser-node](https://www.npmjs.com/package/wik
|
|
|
7
8
|
You can also directly lint Wikitext articles in the command line using this package:
|
|
8
9
|
|
|
9
10
|
```sh
|
|
10
|
-
npx wikilint --config zhwiki --include *.wiki
|
|
11
|
+
npx wikilint --config zhwiki --include --lang zh-hans *.wiki
|
|
11
12
|
```
|
|
12
13
|
|
|
13
14
|
## CLI Options
|
package/bin/cli.js
ADDED
package/dist/bin/cli.js
CHANGED
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
@@ -23,13 +23,10 @@ export interface LintError {
|
|
|
23
23
|
endCol: number;
|
|
24
24
|
}
|
|
25
25
|
declare interface Parser {
|
|
26
|
-
/** @browser */
|
|
27
26
|
config: string | Config;
|
|
28
|
-
|
|
29
|
-
i18n?: string | Record<string, string>;
|
|
27
|
+
i18n: string | Record<string, string> | undefined;
|
|
30
28
|
/**
|
|
31
29
|
* 规范化页面标题
|
|
32
|
-
* @browser
|
|
33
30
|
* @param title 标题(含或不含命名空间前缀)
|
|
34
31
|
* @param defaultNs 命名空间
|
|
35
32
|
* @param include 是否嵌入
|
|
@@ -40,7 +37,6 @@ declare interface Parser {
|
|
|
40
37
|
normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): Title;
|
|
41
38
|
/**
|
|
42
39
|
* 解析wikitext
|
|
43
|
-
* @browser
|
|
44
40
|
* @param include 是否嵌入
|
|
45
41
|
* @param maxStage 最大解析层级
|
|
46
42
|
*/
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
/* eslint n/exports-style: 0 */
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const path = require("path");
|
|
5
|
+
const debug_1 = require("./util/debug");
|
|
6
|
+
const constants_1 = require("./util/constants");
|
|
5
7
|
/**
|
|
6
8
|
* 从根路径require
|
|
7
9
|
* @param file 文件名
|
|
@@ -11,14 +13,17 @@ const rootRequire = (file, dir) => require(file.startsWith('/') ? file : `../${f
|
|
|
11
13
|
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
12
14
|
const Parser = {
|
|
13
15
|
config: 'default',
|
|
14
|
-
|
|
16
|
+
i18n: undefined,
|
|
15
17
|
/** @implements */
|
|
16
18
|
getConfig() {
|
|
17
19
|
if (typeof this.config === 'string') {
|
|
18
20
|
this.config = rootRequire(this.config, 'config/');
|
|
19
21
|
return this.getConfig();
|
|
20
22
|
}
|
|
21
|
-
return {
|
|
23
|
+
return {
|
|
24
|
+
...this.config,
|
|
25
|
+
excludes: [],
|
|
26
|
+
};
|
|
22
27
|
},
|
|
23
28
|
/** @implements */
|
|
24
29
|
msg(msg, arg = '') {
|
|
@@ -34,15 +39,15 @@ const Parser = {
|
|
|
34
39
|
if (halfParsed) {
|
|
35
40
|
return new Title(title, defaultNs, config, decode, selfLink);
|
|
36
41
|
}
|
|
37
|
-
const { Token } = require('./src');
|
|
38
|
-
const token =
|
|
42
|
+
const { Token } = require('./src/index');
|
|
43
|
+
const token = debug_1.Shadow.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token), defaultNs, config, decode, selfLink);
|
|
39
44
|
return titleObj;
|
|
40
45
|
},
|
|
41
46
|
/** @implements */
|
|
42
|
-
parse(wikitext, include, maxStage =
|
|
43
|
-
const { Token } = require('./src');
|
|
47
|
+
parse(wikitext, include, maxStage = constants_1.MAX_STAGE, config = Parser.getConfig()) {
|
|
48
|
+
const { Token } = require('./src/index');
|
|
44
49
|
let token;
|
|
45
|
-
|
|
50
|
+
debug_1.Shadow.run(() => {
|
|
46
51
|
token = new Token(wikitext.replace(/[\0\x7F]/gu, ''), config);
|
|
47
52
|
try {
|
|
48
53
|
token.parse(maxStage, include);
|
|
@@ -50,7 +55,7 @@ const Parser = {
|
|
|
50
55
|
catch (e) {
|
|
51
56
|
if (e instanceof Error) {
|
|
52
57
|
const file = path.join(__dirname, '..', 'errors', new Date().toISOString()), stage = token.getAttribute('stage');
|
|
53
|
-
fs.writeFileSync(file, stage ===
|
|
58
|
+
fs.writeFileSync(file, stage === constants_1.MAX_STAGE ? wikitext : String(token));
|
|
54
59
|
fs.writeFileSync(`${file}.err`, e.stack);
|
|
55
60
|
fs.writeFileSync(`${file}.json`, JSON.stringify({
|
|
56
61
|
stage, include: token.getAttribute('include'), config: this.config,
|
|
@@ -61,18 +66,13 @@ const Parser = {
|
|
|
61
66
|
});
|
|
62
67
|
return token;
|
|
63
68
|
},
|
|
64
|
-
/** @implements */
|
|
65
|
-
run(callback) {
|
|
66
|
-
const result = callback();
|
|
67
|
-
return result;
|
|
68
|
-
},
|
|
69
69
|
};
|
|
70
|
-
const def = {},
|
|
70
|
+
const def = {}, enumerable = new Set([
|
|
71
|
+
'normalizeTitle',
|
|
72
|
+
'parse',
|
|
73
|
+
]);
|
|
71
74
|
for (const key in Parser) {
|
|
72
|
-
if (
|
|
73
|
-
def[key] = { enumerable: false, writable: false };
|
|
74
|
-
}
|
|
75
|
-
else if (!enumerable.has(key)) {
|
|
75
|
+
if (!enumerable.has(key)) {
|
|
76
76
|
def[key] = { enumerable: false };
|
|
77
77
|
}
|
|
78
78
|
}
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { AstNodes, } from './lib/node';
|
|
2
2
|
export type * from './lib/text';
|
|
3
|
-
export type * from './src';
|
|
3
|
+
export type * from './src/index';
|
|
4
4
|
export type * from './src/onlyinclude';
|
|
5
5
|
export type * from './src/nowiki/noinclude';
|
|
6
6
|
export type * from './src/tagPair/include';
|
|
@@ -18,10 +18,10 @@ export type * from './src/heading';
|
|
|
18
18
|
export type * from './src/html';
|
|
19
19
|
export type { TdToken } from './src/table/td';
|
|
20
20
|
export type * from './src/table/tr';
|
|
21
|
-
export type * from './src/table';
|
|
21
|
+
export type * from './src/table/index';
|
|
22
22
|
export type * from './src/nowiki/hr';
|
|
23
23
|
export type * from './src/nowiki/doubleUnderscore';
|
|
24
|
-
export type * from './src/link';
|
|
24
|
+
export type * from './src/link/index';
|
|
25
25
|
export type * from './src/link/category';
|
|
26
26
|
export type * from './src/imageParameter';
|
|
27
27
|
export type * from './src/link/file';
|
|
@@ -34,9 +34,9 @@ export type * from './src/nowiki/list';
|
|
|
34
34
|
export type * from './src/converterFlags';
|
|
35
35
|
export type * from './src/converterRule';
|
|
36
36
|
export type * from './src/converter';
|
|
37
|
-
export type * from './src/nowiki';
|
|
37
|
+
export type * from './src/nowiki/index';
|
|
38
38
|
export type * from './src/pre';
|
|
39
|
-
export type * from './src/paramTag';
|
|
39
|
+
export type * from './src/paramTag/index';
|
|
40
40
|
export type * from './src/paramTag/inputbox';
|
|
41
41
|
export type * from './src/nested';
|
|
42
42
|
export type * from './src/gallery';
|
package/dist/lib/element.d.ts
CHANGED
|
@@ -3,33 +3,24 @@ import type { LintError } from '../index';
|
|
|
3
3
|
import type { AstNodes, Token } from '../internal';
|
|
4
4
|
/** 类似HTMLElement */
|
|
5
5
|
export declare abstract class AstElement extends AstNode {
|
|
6
|
-
/** @browser */
|
|
7
6
|
name?: string;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @browser
|
|
11
|
-
*/
|
|
7
|
+
data: undefined;
|
|
8
|
+
/** 子节点总数 */
|
|
12
9
|
get length(): number;
|
|
13
10
|
/**
|
|
14
11
|
* 可见部分
|
|
15
|
-
* @browser
|
|
16
12
|
* @param separator 子节点间的连接符
|
|
17
13
|
*/
|
|
18
14
|
text(separator?: string): string;
|
|
19
|
-
/**
|
|
20
|
-
* 合并相邻的文本子节点
|
|
21
|
-
* @browser
|
|
22
|
-
*/
|
|
15
|
+
/** 合并相邻的文本子节点 */
|
|
23
16
|
normalize(): void;
|
|
24
17
|
/**
|
|
25
18
|
* 移除子节点
|
|
26
|
-
* @browser
|
|
27
19
|
* @param i 移除位置
|
|
28
20
|
*/
|
|
29
21
|
removeAt(i: number): AstNodes;
|
|
30
22
|
/**
|
|
31
23
|
* 插入子节点
|
|
32
|
-
* @browser
|
|
33
24
|
* @param node 待插入的子节点
|
|
34
25
|
* @param i 插入位置
|
|
35
26
|
* @throws `RangeError` 不能插入祖先节点
|
|
@@ -37,40 +28,28 @@ export declare abstract class AstElement extends AstNode {
|
|
|
37
28
|
insertAt<T extends AstNodes>(node: T, i?: number): T;
|
|
38
29
|
/**
|
|
39
30
|
* 最近的祖先节点
|
|
40
|
-
* @browser
|
|
41
31
|
* @param selector 选择器
|
|
42
32
|
*/
|
|
43
33
|
closest(selector: string): Token | undefined;
|
|
44
34
|
/**
|
|
45
35
|
* 在末尾批量插入子节点
|
|
46
|
-
* @browser
|
|
47
36
|
* @param elements 插入节点
|
|
48
37
|
*/
|
|
49
38
|
append(...elements: (AstNodes | string)[]): void;
|
|
50
39
|
/**
|
|
51
40
|
* 批量替换子节点
|
|
52
|
-
* @browser
|
|
53
41
|
* @param elements 新的子节点
|
|
54
42
|
*/
|
|
55
43
|
replaceChildren(...elements: (AstNodes | string)[]): void;
|
|
56
44
|
/**
|
|
57
45
|
* 修改文本子节点
|
|
58
|
-
* @browser
|
|
59
46
|
* @param str 新文本
|
|
60
47
|
* @param i 子节点位置
|
|
61
48
|
* @throws `RangeError` 对应位置的子节点不是文本节点
|
|
62
49
|
*/
|
|
63
50
|
setText(str: string, i?: number): string;
|
|
64
|
-
/**
|
|
65
|
-
* 还原为wikitext
|
|
66
|
-
* @browser
|
|
67
|
-
* @param omit 忽略的节点类型
|
|
68
|
-
* @param separator 子节点间的连接符
|
|
69
|
-
*/
|
|
70
|
-
toString(omit?: Set<string>, separator?: string): string;
|
|
71
51
|
/**
|
|
72
52
|
* Linter
|
|
73
|
-
* @browser
|
|
74
53
|
* @param start
|
|
75
54
|
*/
|
|
76
55
|
lint(start?: number): LintError[];
|
package/dist/lib/element.js
CHANGED
|
@@ -22,46 +22,36 @@ const lintIgnoredExt = new Set([
|
|
|
22
22
|
]);
|
|
23
23
|
/** 类似HTMLElement */
|
|
24
24
|
class AstElement extends node_1.AstNode {
|
|
25
|
-
/**
|
|
26
|
-
name;
|
|
27
|
-
/**
|
|
28
|
-
* 子节点总数
|
|
29
|
-
* @browser
|
|
30
|
-
*/
|
|
25
|
+
/** 子节点总数 */
|
|
31
26
|
get length() {
|
|
32
27
|
return this.childNodes.length;
|
|
33
28
|
}
|
|
34
29
|
/**
|
|
35
30
|
* 可见部分
|
|
36
|
-
* @browser
|
|
37
31
|
* @param separator 子节点间的连接符
|
|
38
32
|
*/
|
|
39
33
|
text(separator) {
|
|
40
34
|
return (0, string_1.text)(this.childNodes, separator);
|
|
41
35
|
}
|
|
42
|
-
/**
|
|
43
|
-
* 合并相邻的文本子节点
|
|
44
|
-
* @browser
|
|
45
|
-
*/
|
|
36
|
+
/** 合并相邻的文本子节点 */
|
|
46
37
|
normalize() {
|
|
47
38
|
const { childNodes } = this;
|
|
48
39
|
for (let i = childNodes.length - 1; i >= 0; i--) {
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
40
|
+
const { type, data } = childNodes[i], prev = childNodes[i - 1];
|
|
41
|
+
if (type !== 'text' || this.getGaps(i - 1)) {
|
|
51
42
|
//
|
|
52
43
|
}
|
|
53
|
-
else if (
|
|
44
|
+
else if (data === '') {
|
|
54
45
|
childNodes.splice(i, 1);
|
|
55
46
|
}
|
|
56
47
|
else if (prev?.type === 'text') {
|
|
57
|
-
prev.setAttribute('data', prev.data +
|
|
48
|
+
prev.setAttribute('data', prev.data + data);
|
|
58
49
|
childNodes.splice(i, 1);
|
|
59
50
|
}
|
|
60
51
|
}
|
|
61
52
|
}
|
|
62
53
|
/**
|
|
63
54
|
* 移除子节点
|
|
64
|
-
* @browser
|
|
65
55
|
* @param i 移除位置
|
|
66
56
|
*/
|
|
67
57
|
removeAt(i) {
|
|
@@ -70,7 +60,6 @@ class AstElement extends node_1.AstNode {
|
|
|
70
60
|
}
|
|
71
61
|
/**
|
|
72
62
|
* 插入子节点
|
|
73
|
-
* @browser
|
|
74
63
|
* @param node 待插入的子节点
|
|
75
64
|
* @param i 插入位置
|
|
76
65
|
* @throws `RangeError` 不能插入祖先节点
|
|
@@ -83,7 +72,6 @@ class AstElement extends node_1.AstNode {
|
|
|
83
72
|
}
|
|
84
73
|
/**
|
|
85
74
|
* 最近的祖先节点
|
|
86
|
-
* @browser
|
|
87
75
|
* @param selector 选择器
|
|
88
76
|
*/
|
|
89
77
|
closest(selector) {
|
|
@@ -101,7 +89,6 @@ class AstElement extends node_1.AstNode {
|
|
|
101
89
|
}
|
|
102
90
|
/**
|
|
103
91
|
* 在末尾批量插入子节点
|
|
104
|
-
* @browser
|
|
105
92
|
* @param elements 插入节点
|
|
106
93
|
*/
|
|
107
94
|
append(...elements) {
|
|
@@ -111,7 +98,6 @@ class AstElement extends node_1.AstNode {
|
|
|
111
98
|
}
|
|
112
99
|
/**
|
|
113
100
|
* 批量替换子节点
|
|
114
|
-
* @browser
|
|
115
101
|
* @param elements 新的子节点
|
|
116
102
|
*/
|
|
117
103
|
replaceChildren(...elements) {
|
|
@@ -120,28 +106,22 @@ class AstElement extends node_1.AstNode {
|
|
|
120
106
|
}
|
|
121
107
|
/**
|
|
122
108
|
* 修改文本子节点
|
|
123
|
-
* @browser
|
|
124
109
|
* @param str 新文本
|
|
125
110
|
* @param i 子节点位置
|
|
126
111
|
* @throws `RangeError` 对应位置的子节点不是文本节点
|
|
127
112
|
*/
|
|
128
113
|
setText(str, i = 0) {
|
|
129
|
-
const oldText = this.childNodes
|
|
114
|
+
const oldText = this.childNodes.at(i);
|
|
115
|
+
const { data } = oldText;
|
|
130
116
|
oldText.replaceData(str);
|
|
131
117
|
return data;
|
|
132
118
|
}
|
|
133
|
-
/**
|
|
134
|
-
* 还原为wikitext
|
|
135
|
-
* @browser
|
|
136
|
-
* @param omit 忽略的节点类型
|
|
137
|
-
* @param separator 子节点间的连接符
|
|
138
|
-
*/
|
|
119
|
+
/** @private */
|
|
139
120
|
toString(omit, separator = '') {
|
|
140
121
|
return this.childNodes.map(child => child.toString()).join(separator);
|
|
141
122
|
}
|
|
142
123
|
/**
|
|
143
124
|
* Linter
|
|
144
|
-
* @browser
|
|
145
125
|
* @param start
|
|
146
126
|
*/
|
|
147
127
|
lint(start = this.getAbsoluteIndex()) {
|
|
@@ -151,7 +131,7 @@ class AstElement extends node_1.AstNode {
|
|
|
151
131
|
return [];
|
|
152
132
|
}
|
|
153
133
|
const errors = [];
|
|
154
|
-
for (let i = 0, cur = start + this.
|
|
134
|
+
for (let i = 0, cur = start + this.getAttribute('padding'); i < this.length; i++) {
|
|
155
135
|
const child = this.childNodes[i];
|
|
156
136
|
errors.push(...child.lint(cur));
|
|
157
137
|
cur += String(child).length + this.getGaps(i);
|
package/dist/lib/node.d.ts
CHANGED
|
@@ -16,65 +16,35 @@ export interface CaretPosition {
|
|
|
16
16
|
/** 类似Node */
|
|
17
17
|
export declare abstract class AstNode {
|
|
18
18
|
#private;
|
|
19
|
-
/** @browser */
|
|
20
19
|
type: TokenTypes | 'text';
|
|
21
|
-
|
|
20
|
+
data?: string | undefined;
|
|
22
21
|
readonly childNodes: AstNodes[];
|
|
23
|
-
/**
|
|
24
|
-
* 首位子节点
|
|
25
|
-
* @browser
|
|
26
|
-
*/
|
|
22
|
+
/** 首位子节点 */
|
|
27
23
|
get firstChild(): AstNodes | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* 末位子节点
|
|
30
|
-
* @browser
|
|
31
|
-
*/
|
|
24
|
+
/** 末位子节点 */
|
|
32
25
|
get lastChild(): AstNodes | undefined;
|
|
33
|
-
/**
|
|
34
|
-
* 父节点
|
|
35
|
-
* @browser
|
|
36
|
-
*/
|
|
26
|
+
/** 父节点 */
|
|
37
27
|
get parentNode(): Token | undefined;
|
|
38
|
-
/**
|
|
39
|
-
* 后一个兄弟节点
|
|
40
|
-
* @browser
|
|
41
|
-
*/
|
|
28
|
+
/** 后一个兄弟节点 */
|
|
42
29
|
get nextSibling(): AstNodes | undefined;
|
|
43
|
-
/**
|
|
44
|
-
* 前一个兄弟节点
|
|
45
|
-
* @browser
|
|
46
|
-
*/
|
|
30
|
+
/** 前一个兄弟节点 */
|
|
47
31
|
get previousSibling(): AstNodes | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* 行数
|
|
50
|
-
* @browser
|
|
51
|
-
*/
|
|
32
|
+
/** 行数 */
|
|
52
33
|
get offsetHeight(): number;
|
|
53
|
-
/**
|
|
54
|
-
* 最后一行的列数
|
|
55
|
-
* @browser
|
|
56
|
-
*/
|
|
34
|
+
/** 最后一行的列数 */
|
|
57
35
|
get offsetWidth(): number;
|
|
58
|
-
/**
|
|
59
|
-
* 获取根节点
|
|
60
|
-
* @browser
|
|
61
|
-
*/
|
|
36
|
+
/** 获取根节点 */
|
|
62
37
|
getRootNode(): Token | this;
|
|
63
38
|
/**
|
|
64
39
|
* 将字符位置转换为行列号
|
|
65
|
-
* @browser
|
|
66
40
|
* @param index 字符位置
|
|
67
41
|
*/
|
|
68
42
|
posFromIndex(index: number): Position | undefined;
|
|
69
43
|
/**
|
|
70
44
|
* 获取当前节点的相对字符位置,或其第`j`个子节点的相对字符位置
|
|
71
|
-
* @browser
|
|
72
45
|
* @param j 子节点序号
|
|
73
46
|
*/
|
|
74
47
|
getRelativeIndex(j?: number): number;
|
|
75
|
-
/**
|
|
76
|
-
* 获取当前节点的绝对位置
|
|
77
|
-
* @browser
|
|
78
|
-
*/
|
|
48
|
+
/** 获取当前节点的绝对位置 */
|
|
79
49
|
getAbsoluteIndex(): number;
|
|
80
50
|
}
|
package/dist/lib/node.js
CHANGED
|
@@ -3,70 +3,44 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AstNode = void 0;
|
|
4
4
|
/** 类似Node */
|
|
5
5
|
class AstNode {
|
|
6
|
-
/** @browser */
|
|
7
|
-
type;
|
|
8
|
-
/** @browser */
|
|
9
6
|
childNodes = [];
|
|
10
|
-
/** @browser */
|
|
11
7
|
#parentNode;
|
|
12
|
-
/**
|
|
13
|
-
* 首位子节点
|
|
14
|
-
* @browser
|
|
15
|
-
*/
|
|
8
|
+
/** 首位子节点 */
|
|
16
9
|
get firstChild() {
|
|
17
10
|
return this.childNodes[0];
|
|
18
11
|
}
|
|
19
|
-
/**
|
|
20
|
-
* 末位子节点
|
|
21
|
-
* @browser
|
|
22
|
-
*/
|
|
12
|
+
/** 末位子节点 */
|
|
23
13
|
get lastChild() {
|
|
24
14
|
return this.childNodes.at(-1);
|
|
25
15
|
}
|
|
26
|
-
/**
|
|
27
|
-
* 父节点
|
|
28
|
-
* @browser
|
|
29
|
-
*/
|
|
16
|
+
/** 父节点 */
|
|
30
17
|
get parentNode() {
|
|
31
18
|
return this.#parentNode;
|
|
32
19
|
}
|
|
33
|
-
/**
|
|
34
|
-
* 后一个兄弟节点
|
|
35
|
-
* @browser
|
|
36
|
-
*/
|
|
20
|
+
/** 后一个兄弟节点 */
|
|
37
21
|
get nextSibling() {
|
|
38
22
|
const childNodes = this.#parentNode?.childNodes;
|
|
39
23
|
return childNodes && childNodes[childNodes.indexOf(this) + 1];
|
|
40
24
|
}
|
|
41
|
-
/**
|
|
42
|
-
* 前一个兄弟节点
|
|
43
|
-
* @browser
|
|
44
|
-
*/
|
|
25
|
+
/** 前一个兄弟节点 */
|
|
45
26
|
get previousSibling() {
|
|
46
27
|
const childNodes = this.#parentNode?.childNodes;
|
|
47
28
|
return childNodes && childNodes[childNodes.indexOf(this) - 1];
|
|
48
29
|
}
|
|
49
|
-
/**
|
|
50
|
-
* 行数
|
|
51
|
-
* @browser
|
|
52
|
-
*/
|
|
30
|
+
/** 行数 */
|
|
53
31
|
get offsetHeight() {
|
|
54
32
|
return this.#getDimension().height;
|
|
55
33
|
}
|
|
56
|
-
/**
|
|
57
|
-
* 最后一行的列数
|
|
58
|
-
* @browser
|
|
59
|
-
*/
|
|
34
|
+
/** 最后一行的列数 */
|
|
60
35
|
get offsetWidth() {
|
|
61
36
|
return this.#getDimension().width;
|
|
62
37
|
}
|
|
63
38
|
/** @private */
|
|
64
|
-
hasAttribute(key) {
|
|
65
|
-
return key in this;
|
|
66
|
-
}
|
|
67
|
-
/** @private */
|
|
68
39
|
getAttribute(key) {
|
|
69
|
-
|
|
40
|
+
if (key === 'padding') {
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
return key in this
|
|
70
44
|
// @ts-expect-error noImplicitAny
|
|
71
45
|
? String(this[key])
|
|
72
46
|
: undefined;
|
|
@@ -80,12 +54,8 @@ class AstNode {
|
|
|
80
54
|
// @ts-expect-error noImplicitAny
|
|
81
55
|
this[key] = value;
|
|
82
56
|
}
|
|
83
|
-
return this;
|
|
84
57
|
}
|
|
85
|
-
/**
|
|
86
|
-
* 获取根节点
|
|
87
|
-
* @browser
|
|
88
|
-
*/
|
|
58
|
+
/** 获取根节点 */
|
|
89
59
|
getRootNode() {
|
|
90
60
|
let { parentNode } = this;
|
|
91
61
|
while (parentNode?.parentNode) {
|
|
@@ -95,37 +65,33 @@ class AstNode {
|
|
|
95
65
|
}
|
|
96
66
|
/**
|
|
97
67
|
* 将字符位置转换为行列号
|
|
98
|
-
* @browser
|
|
99
68
|
* @param index 字符位置
|
|
100
69
|
*/
|
|
101
70
|
posFromIndex(index) {
|
|
102
71
|
const str = String(this);
|
|
103
72
|
if (index >= -str.length && index <= str.length) {
|
|
104
73
|
const lines = str.slice(0, index).split('\n');
|
|
105
|
-
return {
|
|
74
|
+
return {
|
|
75
|
+
top: lines.length - 1,
|
|
76
|
+
left: lines.at(-1).length,
|
|
77
|
+
};
|
|
106
78
|
}
|
|
107
79
|
return undefined;
|
|
108
80
|
}
|
|
109
|
-
/**
|
|
110
|
-
* 获取行数和最后一行的列数
|
|
111
|
-
* @browser
|
|
112
|
-
*/
|
|
81
|
+
/** 获取行数和最后一行的列数 */
|
|
113
82
|
#getDimension() {
|
|
114
83
|
const lines = String(this).split('\n');
|
|
115
|
-
return {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return 0;
|
|
84
|
+
return {
|
|
85
|
+
height: lines.length,
|
|
86
|
+
width: lines.at(-1).length,
|
|
87
|
+
};
|
|
120
88
|
}
|
|
121
89
|
/** @private */
|
|
122
|
-
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
123
90
|
getGaps(i) {
|
|
124
91
|
return 0;
|
|
125
92
|
}
|
|
126
93
|
/**
|
|
127
94
|
* 获取当前节点的相对字符位置,或其第`j`个子节点的相对字符位置
|
|
128
|
-
* @browser
|
|
129
95
|
* @param j 子节点序号
|
|
130
96
|
*/
|
|
131
97
|
getRelativeIndex(j) {
|
|
@@ -136,7 +102,7 @@ class AstNode {
|
|
|
136
102
|
* @param parent 父节点
|
|
137
103
|
*/
|
|
138
104
|
const getIndex = (end, parent) => childNodes.slice(0, end).reduce((acc, cur, i) => acc + String(cur).length + parent.getGaps(i), 0)
|
|
139
|
-
+ parent.
|
|
105
|
+
+ parent.getAttribute('padding');
|
|
140
106
|
if (j === undefined) {
|
|
141
107
|
const { parentNode } = this;
|
|
142
108
|
if (parentNode) {
|
|
@@ -148,10 +114,7 @@ class AstNode {
|
|
|
148
114
|
({ childNodes } = this);
|
|
149
115
|
return getIndex(j, this);
|
|
150
116
|
}
|
|
151
|
-
/**
|
|
152
|
-
* 获取当前节点的绝对位置
|
|
153
|
-
* @browser
|
|
154
|
-
*/
|
|
117
|
+
/** 获取当前节点的绝对位置 */
|
|
155
118
|
getAbsoluteIndex() {
|
|
156
119
|
const { parentNode } = this;
|
|
157
120
|
return parentNode ? parentNode.getAbsoluteIndex() + this.getRelativeIndex() : 0;
|
package/dist/lib/text.d.ts
CHANGED
|
@@ -3,35 +3,20 @@ import type { LintError } from '../index';
|
|
|
3
3
|
/** 文本节点 */
|
|
4
4
|
export declare class AstText extends AstNode {
|
|
5
5
|
#private;
|
|
6
|
-
/** @browser */
|
|
7
6
|
readonly type = "text";
|
|
8
7
|
name: undefined;
|
|
9
|
-
/** @browser */
|
|
10
8
|
data: string;
|
|
11
|
-
/**
|
|
12
|
-
* @browser
|
|
13
|
-
* @param text 包含文本
|
|
14
|
-
*/
|
|
9
|
+
/** @param text 包含文本 */
|
|
15
10
|
constructor(text: string);
|
|
16
|
-
/**
|
|
17
|
-
* 输出字符串
|
|
18
|
-
* @browser
|
|
19
|
-
*/
|
|
20
|
-
toString(): string;
|
|
21
|
-
/**
|
|
22
|
-
* 可见部分
|
|
23
|
-
* @browser
|
|
24
|
-
*/
|
|
11
|
+
/** 可见部分 */
|
|
25
12
|
text(): string;
|
|
26
13
|
/**
|
|
27
14
|
* Linter
|
|
28
|
-
* @browser
|
|
29
15
|
* @param start
|
|
30
16
|
*/
|
|
31
17
|
lint(start?: number): LintError[];
|
|
32
18
|
/**
|
|
33
19
|
* 替换字符串
|
|
34
|
-
* @browser
|
|
35
20
|
* @param text 替换的字符串
|
|
36
21
|
*/
|
|
37
22
|
replaceData(text: string): void;
|