wikilint 2.9.2 → 2.10.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/config/.schema.json +5 -0
- package/config/enwiki.json +2 -1
- package/config/llwiki.json +2 -1
- package/config/moegirl.json +2 -1
- package/config/zhwiki.json +2 -1
- package/dist/base.d.ts +11 -4
- package/dist/index.js +3 -4
- package/dist/lib/element.js +13 -13
- package/dist/lib/node.d.ts +9 -1
- package/dist/lib/node.js +7 -0
- package/dist/lib/text.d.ts +1 -3
- package/dist/lib/text.js +8 -6
- package/dist/mixin/hidden.d.ts +1 -0
- package/dist/mixin/hidden.js +2 -2
- package/dist/parser/list.js +8 -6
- package/dist/parser/table.js +5 -5
- package/dist/src/arg.d.ts +1 -1
- package/dist/src/arg.js +5 -3
- package/dist/src/atom.d.ts +5 -2
- package/dist/src/atom.js +25 -1
- package/dist/src/attribute.d.ts +1 -1
- package/dist/src/attribute.js +13 -25
- package/dist/src/attributes.d.ts +2 -1
- package/dist/src/attributes.js +6 -2
- package/dist/src/converter.d.ts +2 -2
- package/dist/src/converter.js +7 -4
- package/dist/src/converterFlags.d.ts +1 -1
- package/dist/src/converterFlags.js +5 -3
- package/dist/src/converterRule.d.ts +1 -1
- package/dist/src/converterRule.js +12 -14
- package/dist/src/extLink.d.ts +1 -1
- package/dist/src/extLink.js +6 -4
- package/dist/src/gallery.d.ts +1 -1
- package/dist/src/gallery.js +7 -5
- package/dist/src/heading.d.ts +1 -1
- package/dist/src/heading.js +7 -4
- package/dist/src/hidden.d.ts +1 -1
- package/dist/src/hidden.js +4 -2
- package/dist/src/html.d.ts +1 -1
- package/dist/src/html.js +5 -3
- package/dist/src/imageParameter.d.ts +1 -1
- package/dist/src/imageParameter.js +5 -3
- package/dist/src/imagemap.d.ts +1 -1
- package/dist/src/imagemap.js +5 -3
- package/dist/src/imagemapLink.d.ts +1 -1
- package/dist/src/imagemapLink.js +3 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +17 -10
- package/dist/src/link/base.d.ts +1 -1
- package/dist/src/link/base.js +12 -7
- package/dist/src/link/category.d.ts +1 -1
- package/dist/src/link/category.js +3 -1
- package/dist/src/link/file.d.ts +1 -1
- package/dist/src/link/file.js +4 -2
- package/dist/src/link/galleryImage.d.ts +1 -2
- package/dist/src/link/galleryImage.js +7 -13
- package/dist/src/link/index.d.ts +1 -1
- package/dist/src/link/index.js +3 -1
- package/dist/src/link/redirectTarget.d.ts +2 -2
- package/dist/src/link/redirectTarget.js +5 -7
- package/dist/src/magicLink.d.ts +4 -1
- package/dist/src/magicLink.js +42 -54
- package/dist/src/nested.d.ts +1 -1
- package/dist/src/nested.js +3 -1
- package/dist/src/nowiki/base.d.ts +1 -1
- package/dist/src/nowiki/comment.d.ts +1 -1
- package/dist/src/nowiki/comment.js +6 -4
- package/dist/src/nowiki/dd.d.ts +1 -1
- package/dist/src/nowiki/dd.js +3 -1
- package/dist/src/nowiki/doubleUnderscore.d.ts +1 -1
- package/dist/src/nowiki/doubleUnderscore.js +4 -2
- package/dist/src/nowiki/hr.d.ts +1 -1
- package/dist/src/nowiki/hr.js +3 -1
- package/dist/src/nowiki/index.d.ts +1 -1
- package/dist/src/nowiki/index.js +3 -1
- package/dist/src/nowiki/list.d.ts +1 -1
- package/dist/src/nowiki/list.js +3 -1
- package/dist/src/nowiki/listBase.d.ts +1 -1
- package/dist/src/nowiki/noinclude.d.ts +1 -1
- package/dist/src/nowiki/noinclude.js +8 -2
- package/dist/src/nowiki/quote.d.ts +1 -1
- package/dist/src/nowiki/quote.js +3 -1
- package/dist/src/onlyinclude.d.ts +1 -1
- package/dist/src/onlyinclude.js +5 -3
- package/dist/src/paramTag/index.d.ts +1 -1
- package/dist/src/paramTag/index.js +5 -3
- package/dist/src/parameter.d.ts +1 -2
- package/dist/src/parameter.js +14 -11
- package/dist/src/pre.d.ts +1 -1
- package/dist/src/pre.js +3 -1
- package/dist/src/redirect.d.ts +1 -1
- package/dist/src/redirect.js +6 -4
- package/dist/src/syntax.d.ts +5 -4
- package/dist/src/syntax.js +8 -4
- package/dist/src/table/base.d.ts +1 -1
- package/dist/src/table/index.d.ts +1 -1
- package/dist/src/table/index.js +3 -1
- package/dist/src/table/td.d.ts +1 -5
- package/dist/src/table/td.js +5 -7
- package/dist/src/table/tr.d.ts +1 -1
- package/dist/src/table/tr.js +3 -1
- package/dist/src/table/trBase.d.ts +1 -1
- package/dist/src/table/trBase.js +3 -4
- package/dist/src/tagPair/ext.d.ts +1 -1
- package/dist/src/tagPair/ext.js +7 -3
- package/dist/src/tagPair/include.d.ts +1 -1
- package/dist/src/tagPair/include.js +8 -2
- package/dist/src/tagPair/index.d.ts +1 -1
- package/dist/src/tagPair/index.js +3 -3
- package/dist/src/transclude.d.ts +1 -1
- package/dist/src/transclude.js +19 -15
- package/dist/util/lint.js +1 -1
- package/errors/README +2 -0
- package/package.json +1 -1
package/config/.schema.json
CHANGED
package/config/enwiki.json
CHANGED
package/config/llwiki.json
CHANGED
package/config/moegirl.json
CHANGED
package/config/zhwiki.json
CHANGED
package/dist/base.d.ts
CHANGED
|
@@ -38,13 +38,20 @@ export interface LintError {
|
|
|
38
38
|
}
|
|
39
39
|
/** 类似Node */
|
|
40
40
|
export interface AstNode {
|
|
41
|
-
type: string;
|
|
42
41
|
readonly childNodes: readonly AstNode[];
|
|
42
|
+
/** 节点类型 */
|
|
43
|
+
type: string;
|
|
43
44
|
/** Linter */
|
|
44
45
|
lint(): LintError[];
|
|
45
46
|
}
|
|
46
|
-
/**
|
|
47
|
-
interface
|
|
47
|
+
/** 所有节点的基类 */
|
|
48
|
+
interface Token extends AstNode {
|
|
49
|
+
readonly name?: string;
|
|
50
|
+
/**
|
|
51
|
+
* 符合选择器的所有后代节点
|
|
52
|
+
* @param selector 选择器
|
|
53
|
+
*/
|
|
54
|
+
querySelectorAll<T = Token>(selector: string): T[];
|
|
48
55
|
}
|
|
49
56
|
export interface Parser {
|
|
50
57
|
config: Config | string;
|
|
@@ -56,6 +63,6 @@ export interface Parser {
|
|
|
56
63
|
* @param include 是否嵌入
|
|
57
64
|
* @param maxStage 最大解析层级
|
|
58
65
|
*/
|
|
59
|
-
parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config):
|
|
66
|
+
parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): Token;
|
|
60
67
|
}
|
|
61
68
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -11,8 +11,7 @@ const string_1 = require("./util/string");
|
|
|
11
11
|
* @param file 文件名
|
|
12
12
|
* @param dir 子路径
|
|
13
13
|
*/
|
|
14
|
-
const rootRequire = (file, dir) => require(
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
14
|
+
const rootRequire = (file, dir) => require(path.isAbsolute(file) ? file : path.join('..', file.includes('/') ? '' : dir, file));
|
|
16
15
|
const Parser = {
|
|
17
16
|
config: 'default',
|
|
18
17
|
i18n: undefined,
|
|
@@ -20,7 +19,7 @@ const Parser = {
|
|
|
20
19
|
/** @implements */
|
|
21
20
|
getConfig() {
|
|
22
21
|
if (typeof this.config === 'string') {
|
|
23
|
-
this.config = rootRequire(this.config, 'config
|
|
22
|
+
this.config = rootRequire(this.config, 'config');
|
|
24
23
|
return this.getConfig();
|
|
25
24
|
}
|
|
26
25
|
return {
|
|
@@ -31,7 +30,7 @@ const Parser = {
|
|
|
31
30
|
/** @implements */
|
|
32
31
|
msg(msg, arg = '') {
|
|
33
32
|
if (typeof this.i18n === 'string') {
|
|
34
|
-
this.i18n = rootRequire(this.i18n, 'i18n
|
|
33
|
+
this.i18n = rootRequire(this.i18n, 'i18n');
|
|
35
34
|
return this.msg(msg, arg);
|
|
36
35
|
}
|
|
37
36
|
return msg && (this.i18n?.[msg] ?? msg).replace('$1', this.msg(arg));
|
package/dist/lib/element.js
CHANGED
|
@@ -4,6 +4,14 @@ exports.AstElement = void 0;
|
|
|
4
4
|
const string_1 = require("../util/string");
|
|
5
5
|
const debug_1 = require("../util/debug");
|
|
6
6
|
const node_1 = require("./node");
|
|
7
|
+
/**
|
|
8
|
+
* 将选择器转化为类型谓词
|
|
9
|
+
* @param selector 选择器
|
|
10
|
+
*/
|
|
11
|
+
const getCondition = (selector) => {
|
|
12
|
+
const types = new Set(selector.split(',').map(str => str.trim()));
|
|
13
|
+
return (({ type }) => types.has(type));
|
|
14
|
+
};
|
|
7
15
|
/** 类似HTMLElement */
|
|
8
16
|
class AstElement extends node_1.AstNode {
|
|
9
17
|
/** 子节点总数 */
|
|
@@ -51,20 +59,12 @@ class AstElement extends node_1.AstNode {
|
|
|
51
59
|
(0, debug_1.setChildNodes)(this, i, 0, [node]);
|
|
52
60
|
return node;
|
|
53
61
|
}
|
|
54
|
-
/**
|
|
55
|
-
* 将选择器转化为类型谓词
|
|
56
|
-
* @param selector 选择器
|
|
57
|
-
*/
|
|
58
|
-
#getCondition(selector) {
|
|
59
|
-
const types = new Set(selector.split(',').map(str => str.trim()));
|
|
60
|
-
return (({ type }) => types.has(type));
|
|
61
|
-
}
|
|
62
62
|
/**
|
|
63
63
|
* 最近的祖先节点
|
|
64
64
|
* @param selector 选择器
|
|
65
65
|
*/
|
|
66
66
|
closest(selector) {
|
|
67
|
-
const condition =
|
|
67
|
+
const condition = getCondition(selector);
|
|
68
68
|
let { parentNode } = this;
|
|
69
69
|
while (parentNode) {
|
|
70
70
|
if (condition(parentNode)) {
|
|
@@ -98,7 +98,7 @@ class AstElement extends node_1.AstNode {
|
|
|
98
98
|
* @param selector 选择器
|
|
99
99
|
*/
|
|
100
100
|
querySelector(selector) {
|
|
101
|
-
const condition =
|
|
101
|
+
const condition = getCondition(selector);
|
|
102
102
|
return this.#getElementBy(condition);
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
@@ -123,7 +123,7 @@ class AstElement extends node_1.AstNode {
|
|
|
123
123
|
* @param selector 选择器
|
|
124
124
|
*/
|
|
125
125
|
querySelectorAll(selector) {
|
|
126
|
-
const condition =
|
|
126
|
+
const condition = getCondition(selector);
|
|
127
127
|
return this.#getElementsBy(condition);
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
@@ -158,8 +158,8 @@ class AstElement extends node_1.AstNode {
|
|
|
158
158
|
return data;
|
|
159
159
|
}
|
|
160
160
|
/** @private */
|
|
161
|
-
toString(separator = '') {
|
|
162
|
-
return this.childNodes.map(
|
|
161
|
+
toString(skip, separator = '') {
|
|
162
|
+
return this.childNodes.map(child => child.toString(skip)).join(separator);
|
|
163
163
|
}
|
|
164
164
|
/** @private */
|
|
165
165
|
lint(start = this.getAbsoluteIndex(), re) {
|
package/dist/lib/node.d.ts
CHANGED
|
@@ -16,9 +16,12 @@ export interface CaretPosition {
|
|
|
16
16
|
/** 类似Node */
|
|
17
17
|
export declare abstract class AstNode implements AstNodeBase {
|
|
18
18
|
#private;
|
|
19
|
-
type: TokenTypes | 'text';
|
|
20
19
|
data?: string | undefined;
|
|
21
20
|
readonly childNodes: readonly AstNodes[];
|
|
21
|
+
abstract get type(): TokenTypes | 'text';
|
|
22
|
+
abstract set type(value: TokenTypes | 'text');
|
|
23
|
+
/** 可见部分 */
|
|
24
|
+
text(): string;
|
|
22
25
|
lint(): LintError[];
|
|
23
26
|
/** 首位子节点 */
|
|
24
27
|
get firstChild(): AstNodes | undefined;
|
|
@@ -48,4 +51,9 @@ export declare abstract class AstNode implements AstNodeBase {
|
|
|
48
51
|
getRelativeIndex(j?: number): number;
|
|
49
52
|
/** 获取当前节点的绝对位置 */
|
|
50
53
|
getAbsoluteIndex(): number;
|
|
54
|
+
/**
|
|
55
|
+
* 是否是某种类型的节点
|
|
56
|
+
* @param type 节点类型
|
|
57
|
+
*/
|
|
58
|
+
is<T extends Token>(type: string): this is T;
|
|
51
59
|
}
|
package/dist/lib/node.js
CHANGED
package/dist/lib/text.d.ts
CHANGED
|
@@ -3,13 +3,11 @@ import type { LintError } from '../base';
|
|
|
3
3
|
/** 文本节点 */
|
|
4
4
|
export declare class AstText extends AstNode {
|
|
5
5
|
#private;
|
|
6
|
-
readonly type = "text";
|
|
7
6
|
readonly name: undefined;
|
|
8
7
|
readonly data: string;
|
|
8
|
+
get type(): 'text';
|
|
9
9
|
/** @param text 包含文本 */
|
|
10
10
|
constructor(text: string);
|
|
11
|
-
/** 可见部分 */
|
|
12
|
-
text(): string;
|
|
13
11
|
/**
|
|
14
12
|
* 替换字符串
|
|
15
13
|
* @param text 替换的字符串
|
package/dist/lib/text.js
CHANGED
|
@@ -45,14 +45,15 @@ const source = String.raw `<\s*(?:/\s*)?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])
|
|
|
45
45
|
];
|
|
46
46
|
/** 文本节点 */
|
|
47
47
|
class AstText extends node_1.AstNode {
|
|
48
|
-
type = 'text';
|
|
49
48
|
data = '';
|
|
49
|
+
get type() {
|
|
50
|
+
return 'text';
|
|
51
|
+
}
|
|
50
52
|
/** @param text 包含文本 */
|
|
51
53
|
constructor(text) {
|
|
52
54
|
super();
|
|
53
55
|
Object.defineProperties(this, {
|
|
54
56
|
childNodes: { enumerable: false, configurable: false },
|
|
55
|
-
type: { enumerable: false, writable: false },
|
|
56
57
|
data: {
|
|
57
58
|
value: text,
|
|
58
59
|
},
|
|
@@ -62,12 +63,15 @@ class AstText extends node_1.AstNode {
|
|
|
62
63
|
toString() {
|
|
63
64
|
return this.data;
|
|
64
65
|
}
|
|
65
|
-
/**
|
|
66
|
+
/** @private */
|
|
66
67
|
text() {
|
|
67
68
|
return this.data;
|
|
68
69
|
}
|
|
69
70
|
/** @private */
|
|
70
71
|
lint(start = this.getAbsoluteIndex(), errorRegex) {
|
|
72
|
+
if (errorRegex === false) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
71
75
|
const { data, parentNode, nextSibling, previousSibling } = this;
|
|
72
76
|
if (!parentNode) {
|
|
73
77
|
throw new Error('An isolated text node cannot be linted!');
|
|
@@ -107,9 +111,7 @@ class AstText extends node_1.AstNode {
|
|
|
107
111
|
|| char === '['
|
|
108
112
|
&& type === 'ext-link-text'
|
|
109
113
|
&& (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
|
|
110
|
-
||
|
|
111
|
-
&& nextName === 'nowiki'
|
|
112
|
-
&& nextSibling.innerText?.includes(']'))) {
|
|
114
|
+
|| nextSibling?.is('ext') && nextName === 'nowiki' && nextSibling.innerText?.includes(']'))) {
|
|
113
115
|
continue;
|
|
114
116
|
}
|
|
115
117
|
else if (char === ']' && (index || length > 1)) {
|
package/dist/mixin/hidden.d.ts
CHANGED
package/dist/mixin/hidden.js
CHANGED
|
@@ -5,17 +5,17 @@ const debug_1 = require("../util/debug");
|
|
|
5
5
|
/**
|
|
6
6
|
* 解析后不可见的类
|
|
7
7
|
* @param linter 是否覆写 lint 方法
|
|
8
|
+
* @param html 是否覆写 toHtml 方法
|
|
8
9
|
* @param constructor 基类
|
|
9
10
|
* @param _ context
|
|
10
11
|
*/
|
|
11
|
-
const hiddenToken = (linter) => (constructor, _) => {
|
|
12
|
+
const hiddenToken = (linter = true, html = true) => (constructor, _) => {
|
|
12
13
|
/** 解析后不可见的类 */
|
|
13
14
|
class AnyHiddenToken extends constructor {
|
|
14
15
|
/** 没有可见部分 */
|
|
15
16
|
text() {
|
|
16
17
|
return '';
|
|
17
18
|
}
|
|
18
|
-
/** @private */
|
|
19
19
|
lint(start) {
|
|
20
20
|
// @ts-expect-error private argument
|
|
21
21
|
return linter ? [] : super.lint(start);
|
package/dist/parser/list.js
CHANGED
|
@@ -10,18 +10,20 @@ const dd_1 = require("../src/nowiki/dd");
|
|
|
10
10
|
* @param accum
|
|
11
11
|
*/
|
|
12
12
|
const parseList = (wikitext, config, accum) => {
|
|
13
|
-
const mt = /^((?:\0\d+c\x7F)*)([;:*#]
|
|
13
|
+
const mt = /^((?:\0\d+c\x7F)*)([;:*#]+\s*)/u.exec(wikitext);
|
|
14
14
|
if (!mt) {
|
|
15
15
|
return wikitext;
|
|
16
16
|
}
|
|
17
|
-
const [total, comment, prefix] = mt;
|
|
18
|
-
let text =
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const [total, comment, prefix] = mt, parts = prefix.split(/(?=;)/u);
|
|
18
|
+
let text = comment + parts.map((_, i) => `\0${accum.length + i}d\x7F`).join('') + wikitext.slice(total.length), dt = parts.length - (parts[0].startsWith(';') ? 0 : 1);
|
|
19
|
+
for (const part of parts) {
|
|
20
|
+
// @ts-expect-error abstract class
|
|
21
|
+
new list_1.ListToken(part, config, accum);
|
|
22
|
+
}
|
|
21
23
|
if (!dt) {
|
|
22
24
|
return text;
|
|
23
25
|
}
|
|
24
|
-
const { html: [normalTags] } = config, fullRegex =
|
|
26
|
+
const { html: [normalTags] } = config, fullRegex = /:+\s*|-\{|\0\d+[xq]\x7F/gu;
|
|
25
27
|
let regex = fullRegex, ex = regex.exec(text), lt = 0, lb = false, li = false, lc = 0;
|
|
26
28
|
/**
|
|
27
29
|
* 创建`DdToken`
|
package/dist/parser/table.js
CHANGED
|
@@ -67,8 +67,8 @@ const parseTable = ({ firstChild: { data }, type, name }, config, accum) => {
|
|
|
67
67
|
out += `\n${outLine}`;
|
|
68
68
|
continue;
|
|
69
69
|
}
|
|
70
|
-
// eslint-disable-
|
|
71
|
-
|
|
70
|
+
const matches = // eslint-disable-line @stylistic/operator-linebreak
|
|
71
|
+
/^(?:(\|\}|\0\d+!\x7F\}|\0\d+\}\x7F)|(\|-+|\0\d+!\x7F-+|\0\d+-\x7F-*)(?!-)|(!|(?:\||\0\d+!\x7F)\+?))(.*)$/u
|
|
72
72
|
.exec(line);
|
|
73
73
|
if (!matches) {
|
|
74
74
|
push(`\n${outLine}`, top);
|
|
@@ -101,19 +101,19 @@ const parseTable = ({ firstChild: { data }, type, name }, config, accum) => {
|
|
|
101
101
|
* 创建表格单元格
|
|
102
102
|
* @param tr 当前表格行
|
|
103
103
|
*/
|
|
104
|
-
const
|
|
104
|
+
const newTd = (tr) => {
|
|
105
105
|
// @ts-expect-error abstract class
|
|
106
106
|
const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex, mt?.index), config, accum);
|
|
107
107
|
tr.insertAt(td);
|
|
108
108
|
return td;
|
|
109
109
|
};
|
|
110
110
|
while (mt) {
|
|
111
|
-
|
|
111
|
+
newTd(top);
|
|
112
112
|
({ lastIndex } = regex);
|
|
113
113
|
[lastSyntax] = mt;
|
|
114
114
|
mt = regex.exec(attr);
|
|
115
115
|
}
|
|
116
|
-
stack.push(top,
|
|
116
|
+
stack.push(top, newTd(top));
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
return out.slice(1);
|
package/dist/src/arg.d.ts
CHANGED
|
@@ -8,10 +8,10 @@ import type { LintError } from '../base';
|
|
|
8
8
|
* @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
|
|
9
9
|
*/
|
|
10
10
|
export declare abstract class ArgToken extends Token {
|
|
11
|
-
readonly type = "arg";
|
|
12
11
|
readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token, ...HiddenToken[]];
|
|
13
12
|
abstract get firstChild(): AtomToken;
|
|
14
13
|
abstract get lastChild(): Token;
|
|
14
|
+
get type(): 'arg';
|
|
15
15
|
/** 预设值 */
|
|
16
16
|
get default(): string | false;
|
|
17
17
|
/** @param parts 以'|'分隔的各部分 */
|
package/dist/src/arg.js
CHANGED
|
@@ -13,7 +13,9 @@ const hidden_1 = require("./hidden");
|
|
|
13
13
|
* @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
|
|
14
14
|
*/
|
|
15
15
|
class ArgToken extends index_2.Token {
|
|
16
|
-
type
|
|
16
|
+
get type() {
|
|
17
|
+
return 'arg';
|
|
18
|
+
}
|
|
17
19
|
/** 预设值 */
|
|
18
20
|
get default() {
|
|
19
21
|
return this.childNodes[1]?.text() ?? false;
|
|
@@ -39,8 +41,8 @@ class ArgToken extends index_2.Token {
|
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
/** @private */
|
|
42
|
-
toString() {
|
|
43
|
-
return `{{{${super.toString('|')}}}}`;
|
|
44
|
+
toString(skip) {
|
|
45
|
+
return `{{{${super.toString(skip, '|')}}}}`;
|
|
44
46
|
}
|
|
45
47
|
/** @private */
|
|
46
48
|
text() {
|
package/dist/src/atom.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Token } from './index';
|
|
2
2
|
import type { Config } from '../base';
|
|
3
|
-
declare
|
|
3
|
+
declare const atomTypes: readonly ["arg-name", "attr-key", "attr-value", "ext-attr-dirty", "html-attr-dirty", "table-attr-dirty", "converter-flag", "converter-rule-variant", "converter-rule-to", "converter-rule-from", "invoke-function", "invoke-module", "template-name", "link-target", "param-line"];
|
|
4
|
+
declare type AtomTypes = typeof atomTypes[number];
|
|
4
5
|
/** 不会被继续解析的plain Token */
|
|
5
6
|
export declare class AtomToken extends Token {
|
|
6
|
-
|
|
7
|
+
#private;
|
|
8
|
+
get type(): AtomTypes;
|
|
9
|
+
set type(value: AtomTypes);
|
|
7
10
|
/** @class */
|
|
8
11
|
constructor(wikitext: string | undefined, type: AtomTypes, config?: Config, accum?: Token[], acceptable?: Acceptable);
|
|
9
12
|
}
|
package/dist/src/atom.js
CHANGED
|
@@ -2,12 +2,36 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AtomToken = void 0;
|
|
4
4
|
const index_1 = require("./index");
|
|
5
|
+
const atomTypes = [
|
|
6
|
+
'arg-name',
|
|
7
|
+
'attr-key',
|
|
8
|
+
'attr-value',
|
|
9
|
+
'ext-attr-dirty',
|
|
10
|
+
'html-attr-dirty',
|
|
11
|
+
'table-attr-dirty',
|
|
12
|
+
'converter-flag',
|
|
13
|
+
'converter-rule-variant',
|
|
14
|
+
'converter-rule-to',
|
|
15
|
+
'converter-rule-from',
|
|
16
|
+
'invoke-function',
|
|
17
|
+
'invoke-module',
|
|
18
|
+
'template-name',
|
|
19
|
+
'link-target',
|
|
20
|
+
'param-line',
|
|
21
|
+
];
|
|
5
22
|
/** 不会被继续解析的plain Token */
|
|
6
23
|
class AtomToken extends index_1.Token {
|
|
24
|
+
#type;
|
|
25
|
+
get type() {
|
|
26
|
+
return this.#type;
|
|
27
|
+
}
|
|
28
|
+
set type(value) {
|
|
29
|
+
this.#type = value;
|
|
30
|
+
}
|
|
7
31
|
/** @class */
|
|
8
32
|
constructor(wikitext, type, config, accum, acceptable) {
|
|
9
33
|
super(wikitext, config, accum, acceptable);
|
|
10
|
-
this
|
|
34
|
+
this.#type = type;
|
|
11
35
|
}
|
|
12
36
|
}
|
|
13
37
|
exports.AtomToken = AtomToken;
|
package/dist/src/attribute.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ export type AttributeTypes = 'ext-attr' | 'html-attr' | 'table-attr';
|
|
|
10
10
|
*/
|
|
11
11
|
export declare abstract class AttributeToken extends Token {
|
|
12
12
|
#private;
|
|
13
|
-
type: AttributeTypes;
|
|
14
13
|
readonly name: string;
|
|
15
14
|
readonly childNodes: readonly [AtomToken, Token];
|
|
16
15
|
abstract get firstChild(): AtomToken;
|
|
@@ -18,6 +17,7 @@ export declare abstract class AttributeToken extends Token {
|
|
|
18
17
|
abstract get parentNode(): AttributesToken | undefined;
|
|
19
18
|
abstract get nextSibling(): AtomToken | this | undefined;
|
|
20
19
|
abstract get previousSibling(): AtomToken | this | undefined;
|
|
20
|
+
get type(): AttributeTypes;
|
|
21
21
|
/** 标签名 */
|
|
22
22
|
get tag(): string;
|
|
23
23
|
/** 引号是否匹配 */
|
package/dist/src/attribute.js
CHANGED
|
@@ -60,7 +60,6 @@ const commonHtmlAttrs = new Set([
|
|
|
60
60
|
img: new Set(['alt', 'src', 'width', 'height', 'srcset']),
|
|
61
61
|
font: new Set(['size', 'color', 'face']),
|
|
62
62
|
hr: widthAttrs,
|
|
63
|
-
rt: new Set(['rbspan']),
|
|
64
63
|
data: new Set(['value']),
|
|
65
64
|
time: new Set(['datetime']),
|
|
66
65
|
meta: new Set(['itemprop', 'content']),
|
|
@@ -170,9 +169,13 @@ const commonHtmlAttrs = new Set([
|
|
|
170
169
|
* @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
|
|
171
170
|
*/
|
|
172
171
|
class AttributeToken extends index_2.Token {
|
|
172
|
+
#type;
|
|
173
173
|
#tag;
|
|
174
174
|
#equal;
|
|
175
175
|
#quotes;
|
|
176
|
+
get type() {
|
|
177
|
+
return this.#type;
|
|
178
|
+
}
|
|
176
179
|
/** 标签名 */
|
|
177
180
|
get tag() {
|
|
178
181
|
return this.#tag;
|
|
@@ -190,23 +193,15 @@ class AttributeToken extends index_2.Token {
|
|
|
190
193
|
* @param quotes 引号
|
|
191
194
|
*/
|
|
192
195
|
constructor(type, tag, key, equal = '', value, quotes = [], config = index_1.default.getConfig(), accum = []) {
|
|
193
|
-
const keyToken = new atom_1.AtomToken(key, 'attr-key', config, accum
|
|
196
|
+
const keyToken = new atom_1.AtomToken(key, 'attr-key', config, accum);
|
|
194
197
|
let valueToken;
|
|
195
198
|
if (key === 'title' || tag === 'img' && key === 'alt') {
|
|
196
199
|
valueToken = new index_2.Token(value, config, accum, {});
|
|
197
200
|
valueToken.type = 'attr-value';
|
|
198
201
|
valueToken.setAttribute('stage', constants_1.MAX_STAGE - 1);
|
|
199
202
|
}
|
|
200
|
-
else if (tag === 'gallery' && key === 'caption'
|
|
201
|
-
|
|
202
|
-
...config,
|
|
203
|
-
excludes: [...config.excludes, 'quote', 'extLink', 'magicLink', 'list'],
|
|
204
|
-
};
|
|
205
|
-
valueToken = new index_2.Token(value, newConfig, accum, {});
|
|
206
|
-
valueToken.type = 'attr-value';
|
|
207
|
-
valueToken.setAttribute('stage', 5);
|
|
208
|
-
}
|
|
209
|
-
else if (tag === 'choose' && (key === 'before' || key === 'after')) {
|
|
203
|
+
else if (tag === 'gallery' && key === 'caption'
|
|
204
|
+
|| tag === 'choose' && (key === 'before' || key === 'after')) {
|
|
210
205
|
const newConfig = {
|
|
211
206
|
...config,
|
|
212
207
|
excludes: [...config.excludes, 'heading', 'html', 'table', 'hr', 'list'],
|
|
@@ -219,7 +214,7 @@ class AttributeToken extends index_2.Token {
|
|
|
219
214
|
valueToken = new atom_1.AtomToken(value, 'attr-value', config, accum, {});
|
|
220
215
|
}
|
|
221
216
|
super(undefined, config, accum);
|
|
222
|
-
this
|
|
217
|
+
this.#type = type;
|
|
223
218
|
this.append(keyToken, valueToken);
|
|
224
219
|
this.#equal = equal;
|
|
225
220
|
this.#quotes = [...quotes];
|
|
@@ -234,13 +229,13 @@ class AttributeToken extends index_2.Token {
|
|
|
234
229
|
if (this.parentNode) {
|
|
235
230
|
this.#tag = this.parentNode.name;
|
|
236
231
|
}
|
|
237
|
-
this.setAttribute('name', this.firstChild.
|
|
232
|
+
this.setAttribute('name', this.firstChild.toString(true).trim().toLowerCase());
|
|
238
233
|
super.afterBuild();
|
|
239
234
|
}
|
|
240
235
|
/** @private */
|
|
241
|
-
toString() {
|
|
236
|
+
toString(skip) {
|
|
242
237
|
const [quoteStart = '', quoteEnd = ''] = this.#quotes;
|
|
243
|
-
return this.#equal ? super.toString(this.#equal + quoteStart) + quoteEnd : this.firstChild.toString();
|
|
238
|
+
return this.#equal ? super.toString(skip, this.#equal + quoteStart) + quoteEnd : this.firstChild.toString(skip);
|
|
244
239
|
}
|
|
245
240
|
/** @private */
|
|
246
241
|
text() {
|
|
@@ -288,7 +283,7 @@ class AttributeToken extends index_2.Token {
|
|
|
288
283
|
else if (name === 'style' && typeof value === 'string' && insecureStyle.test(value)) {
|
|
289
284
|
errors.push((0, lint_1.generateForChild)(lastChild, rect, 'insecure-style', 'insecure style'));
|
|
290
285
|
}
|
|
291
|
-
else if (name === 'tabindex' && typeof value === 'string' && value
|
|
286
|
+
else if (name === 'tabindex' && typeof value === 'string' && value !== '0') {
|
|
292
287
|
const e = (0, lint_1.generateForChild)(lastChild, rect, 'illegal-attr', 'nonzero tabindex');
|
|
293
288
|
e.suggestions = [
|
|
294
289
|
{
|
|
@@ -308,14 +303,7 @@ class AttributeToken extends index_2.Token {
|
|
|
308
303
|
}
|
|
309
304
|
/** 获取属性值 */
|
|
310
305
|
getValue() {
|
|
311
|
-
|
|
312
|
-
const value = this.lastChild.text();
|
|
313
|
-
if (this.#quotes[1]) {
|
|
314
|
-
return value;
|
|
315
|
-
}
|
|
316
|
-
return value[this.#quotes[0] ? 'trimEnd' : 'trim']();
|
|
317
|
-
}
|
|
318
|
-
return this.type === 'ext-attr' || '';
|
|
306
|
+
return this.#equal ? this.lastChild.text().trim() : this.type === 'ext-attr' || '';
|
|
319
307
|
}
|
|
320
308
|
}
|
|
321
309
|
exports.AttributeToken = AttributeToken;
|
package/dist/src/attributes.d.ts
CHANGED
|
@@ -11,12 +11,13 @@ declare type AttributesTypes = `${AttributeTypes}s`;
|
|
|
11
11
|
* @classdesc `{childNodes: ...AtomToken|AttributeToken}`
|
|
12
12
|
*/
|
|
13
13
|
export declare abstract class AttributesToken extends Token {
|
|
14
|
-
|
|
14
|
+
#private;
|
|
15
15
|
readonly name: string;
|
|
16
16
|
readonly childNodes: readonly (AtomToken | AttributeToken)[];
|
|
17
17
|
abstract get firstChild(): AtomToken | AttributeToken | undefined;
|
|
18
18
|
abstract get lastChild(): AtomToken | AttributeToken | undefined;
|
|
19
19
|
abstract get parentNode(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
|
|
20
|
+
get type(): AttributesTypes;
|
|
20
21
|
/**
|
|
21
22
|
* @param attr 标签属性
|
|
22
23
|
* @param type 标签类型
|
package/dist/src/attributes.js
CHANGED
|
@@ -24,6 +24,10 @@ const toDirty = (type) => `${toAttributeType(type)}-dirty`;
|
|
|
24
24
|
* @classdesc `{childNodes: ...AtomToken|AttributeToken}`
|
|
25
25
|
*/
|
|
26
26
|
class AttributesToken extends index_2.Token {
|
|
27
|
+
#type;
|
|
28
|
+
get type() {
|
|
29
|
+
return this.#type;
|
|
30
|
+
}
|
|
27
31
|
/**
|
|
28
32
|
* @param attr 标签属性
|
|
29
33
|
* @param type 标签类型
|
|
@@ -31,7 +35,7 @@ class AttributesToken extends index_2.Token {
|
|
|
31
35
|
*/
|
|
32
36
|
constructor(attr, type, name, config = index_1.default.getConfig(), accum = []) {
|
|
33
37
|
super(undefined, config, accum, {});
|
|
34
|
-
this
|
|
38
|
+
this.#type = type;
|
|
35
39
|
this.setAttribute('name', name);
|
|
36
40
|
if (attr) {
|
|
37
41
|
regex.lastIndex = 0;
|
|
@@ -119,7 +123,7 @@ class AttributesToken extends index_2.Token {
|
|
|
119
123
|
duplicated.add(name);
|
|
120
124
|
attrs.get(name).push(attr);
|
|
121
125
|
}
|
|
122
|
-
else
|
|
126
|
+
else {
|
|
123
127
|
attrs.set(name, [attr]);
|
|
124
128
|
}
|
|
125
129
|
}
|
package/dist/src/converter.d.ts
CHANGED
|
@@ -7,10 +7,10 @@ import { ConverterRuleToken } from './converterRule';
|
|
|
7
7
|
* @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken]}`
|
|
8
8
|
*/
|
|
9
9
|
export declare abstract class ConverterToken extends Token {
|
|
10
|
-
readonly
|
|
11
|
-
readonly childNodes: readonly [ConverterFlagsToken, ...ConverterRuleToken[]];
|
|
10
|
+
readonly childNodes: readonly [ConverterFlagsToken, ConverterRuleToken, ...ConverterRuleToken[]];
|
|
12
11
|
abstract get firstChild(): ConverterFlagsToken;
|
|
13
12
|
abstract get lastChild(): ConverterFlagsToken | ConverterRuleToken;
|
|
13
|
+
get type(): 'converter';
|
|
14
14
|
/**
|
|
15
15
|
* @param flags 转换类型标记
|
|
16
16
|
* @param rules 转换规则
|