wikilint 2.4.1 → 2.4.3
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/index.js +3 -1
- package/dist/lib/element.d.ts +0 -5
- package/dist/lib/element.js +3 -31
- package/dist/lib/node.js +7 -0
- package/dist/lib/text.js +76 -40
- package/dist/lib/title.d.ts +1 -1
- package/dist/lib/title.js +17 -7
- package/dist/parser/braces.js +2 -2
- package/dist/parser/commentAndExt.js +2 -2
- package/dist/parser/converter.js +2 -2
- package/dist/parser/externalLinks.js +2 -2
- package/dist/parser/hrAndDoubleUnderscore.js +2 -2
- package/dist/parser/html.js +2 -2
- package/dist/parser/links.js +8 -8
- package/dist/parser/list.js +2 -2
- package/dist/parser/magicLinks.js +2 -2
- package/dist/parser/quotes.js +3 -3
- package/dist/parser/table.js +7 -7
- package/dist/src/arg.d.ts +1 -1
- package/dist/src/arg.js +7 -7
- package/dist/src/atom.d.ts +1 -1
- package/dist/src/atom.js +4 -4
- package/dist/src/attribute.d.ts +1 -2
- package/dist/src/attribute.js +50 -16
- package/dist/src/attributes.d.ts +1 -1
- package/dist/src/attributes.js +5 -5
- package/dist/src/converter.d.ts +6 -2
- package/dist/src/converter.js +6 -7
- package/dist/src/converterFlags.d.ts +1 -1
- package/dist/src/converterFlags.js +7 -7
- package/dist/src/converterRule.d.ts +1 -1
- package/dist/src/converterRule.js +7 -7
- package/dist/src/extLink.d.ts +6 -2
- package/dist/src/extLink.js +8 -9
- package/dist/src/gallery.d.ts +1 -1
- package/dist/src/gallery.js +7 -7
- package/dist/src/heading.d.ts +1 -1
- package/dist/src/heading.js +11 -13
- package/dist/src/html.d.ts +1 -1
- package/dist/src/html.js +10 -10
- package/dist/src/imageParameter.d.ts +1 -1
- package/dist/src/imageParameter.js +8 -10
- package/dist/src/imagemap.d.ts +1 -1
- package/dist/src/imagemap.js +7 -8
- package/dist/src/imagemapLink.d.ts +1 -1
- package/dist/src/imagemapLink.js +6 -6
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +5 -5
- package/dist/src/link/base.d.ts +1 -1
- package/dist/src/link/base.js +10 -11
- package/dist/src/link/file.d.ts +1 -1
- package/dist/src/link/file.js +3 -3
- package/dist/src/link/galleryImage.d.ts +1 -1
- package/dist/src/link/galleryImage.js +6 -6
- package/dist/src/magicLink.d.ts +1 -1
- package/dist/src/magicLink.js +6 -6
- package/dist/src/nested.d.ts +1 -1
- package/dist/src/nested.js +5 -5
- package/dist/src/nowiki/base.d.ts +1 -1
- package/dist/src/nowiki/base.js +4 -4
- package/dist/src/nowiki/comment.d.ts +1 -1
- package/dist/src/nowiki/comment.js +4 -4
- package/dist/src/nowiki/doubleUnderscore.d.ts +1 -1
- package/dist/src/nowiki/doubleUnderscore.js +3 -3
- package/dist/src/nowiki/index.js +2 -2
- package/dist/src/nowiki/quote.js +3 -3
- package/dist/src/onlyinclude.js +1 -1
- package/dist/src/paramTag/index.d.ts +1 -1
- package/dist/src/paramTag/index.js +7 -7
- package/dist/src/paramTag/inputbox.d.ts +1 -1
- package/dist/src/paramTag/inputbox.js +4 -4
- package/dist/src/parameter.d.ts +1 -1
- package/dist/src/parameter.js +9 -13
- package/dist/src/pre.d.ts +1 -1
- package/dist/src/pre.js +4 -4
- package/dist/src/syntax.d.ts +1 -1
- package/dist/src/syntax.js +4 -4
- package/dist/src/table/base.d.ts +1 -1
- package/dist/src/table/base.js +4 -4
- package/dist/src/table/index.d.ts +1 -1
- package/dist/src/table/index.js +7 -5
- package/dist/src/table/td.d.ts +1 -1
- package/dist/src/table/td.js +9 -7
- package/dist/src/table/tr.d.ts +1 -1
- package/dist/src/table/tr.js +2 -2
- package/dist/src/tagPair/ext.d.ts +1 -1
- package/dist/src/tagPair/ext.js +7 -6
- package/dist/src/tagPair/include.d.ts +1 -1
- package/dist/src/tagPair/include.js +5 -5
- package/dist/src/tagPair/index.d.ts +1 -1
- package/dist/src/tagPair/index.js +7 -8
- package/dist/src/transclude.d.ts +1 -1
- package/dist/src/transclude.js +10 -12
- package/dist/util/debug.js +1 -0
- package/dist/util/diff.js +11 -1
- package/dist/util/lint.js +2 -2
- package/package.json +3 -4
- package/dist/mixin/flagsParent.js +0 -14
- package/dist/mixin/magicLinkParent.js +0 -14
package/dist/index.js
CHANGED
package/dist/lib/element.d.ts
CHANGED
|
@@ -31,11 +31,6 @@ export declare abstract class AstElement extends AstNode {
|
|
|
31
31
|
* @param selector 选择器
|
|
32
32
|
*/
|
|
33
33
|
closest<T = Token>(selector: string): T | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* 符合选择器的所有后代节点
|
|
36
|
-
* @param selector 选择器
|
|
37
|
-
*/
|
|
38
|
-
querySelectorAll<T = Token>(selector: string): T[];
|
|
39
34
|
/**
|
|
40
35
|
* 在末尾批量插入子节点
|
|
41
36
|
* @param elements 插入节点
|
package/dist/lib/element.js
CHANGED
|
@@ -56,11 +56,8 @@ class AstElement extends node_1.AstNode {
|
|
|
56
56
|
* @param selector 选择器
|
|
57
57
|
*/
|
|
58
58
|
#getCondition(selector) {
|
|
59
|
-
let condition;
|
|
60
59
|
const types = new Set(selector.split(',').map(str => str.trim()));
|
|
61
|
-
|
|
62
|
-
condition = (token => types.has(token.type));
|
|
63
|
-
return condition;
|
|
60
|
+
return (({ type }) => types.has(type));
|
|
64
61
|
}
|
|
65
62
|
/**
|
|
66
63
|
* 最近的祖先节点
|
|
@@ -77,31 +74,6 @@ class AstElement extends node_1.AstNode {
|
|
|
77
74
|
}
|
|
78
75
|
return undefined;
|
|
79
76
|
}
|
|
80
|
-
/**
|
|
81
|
-
* 符合条件的所有后代节点
|
|
82
|
-
* @param condition 条件
|
|
83
|
-
*/
|
|
84
|
-
#getElementsBy(condition) {
|
|
85
|
-
const descendants = [];
|
|
86
|
-
for (const child of this.childNodes) {
|
|
87
|
-
if (child.type === 'text') {
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
else if (condition(child)) {
|
|
91
|
-
descendants.push(child);
|
|
92
|
-
}
|
|
93
|
-
descendants.push(...child.#getElementsBy(condition));
|
|
94
|
-
}
|
|
95
|
-
return descendants;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* 符合选择器的所有后代节点
|
|
99
|
-
* @param selector 选择器
|
|
100
|
-
*/
|
|
101
|
-
querySelectorAll(selector) {
|
|
102
|
-
const condition = this.#getCondition(selector);
|
|
103
|
-
return this.#getElementsBy(condition);
|
|
104
|
-
}
|
|
105
77
|
/**
|
|
106
78
|
* 在末尾批量插入子节点
|
|
107
79
|
* @param elements 插入节点
|
|
@@ -134,8 +106,8 @@ class AstElement extends node_1.AstNode {
|
|
|
134
106
|
return data;
|
|
135
107
|
}
|
|
136
108
|
/** @private */
|
|
137
|
-
toString(
|
|
138
|
-
return this.childNodes.map(
|
|
109
|
+
toString(separator = '') {
|
|
110
|
+
return this.childNodes.map(String).join(separator);
|
|
139
111
|
}
|
|
140
112
|
/**
|
|
141
113
|
* @override
|
package/dist/lib/node.js
CHANGED
|
@@ -111,5 +111,12 @@ class AstNode {
|
|
|
111
111
|
const { parentNode } = this;
|
|
112
112
|
return parentNode ? parentNode.getAbsoluteIndex() + this.getRelativeIndex() : 0;
|
|
113
113
|
}
|
|
114
|
+
/** @private */
|
|
115
|
+
seal(key, permanent) {
|
|
116
|
+
Object.defineProperty(this, key, {
|
|
117
|
+
enumerable: !permanent && Boolean(this[key]),
|
|
118
|
+
configurable: true,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
114
121
|
}
|
|
115
122
|
exports.AstNode = AstNode;
|
package/dist/lib/text.js
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AstText = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_1 = require("../index");
|
|
5
5
|
const node_1 = require("./node");
|
|
6
|
-
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
7
|
+
/<\s*(?:\/\s*)?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])|((?:^|\])[^[]*?)\]+|https?[:/]\/+/giu;
|
|
8
|
+
const source = '<\\s*(?:\\/\\s*)?([a-z]\\w*)' // 疑似标签
|
|
9
|
+
+ '|'
|
|
10
|
+
+ '\\{+|\\}+' // `{`、`}`
|
|
11
|
+
+ '|'
|
|
12
|
+
+ '\\[{2,}|\\[(?![^[]*?\\])' // `[`
|
|
13
|
+
+ '|'
|
|
14
|
+
+ '((?:^|\\])[^[]*?)\\]+', // `]`
|
|
15
|
+
errorSyntax = new RegExp(`${source}|https?[:/]\\/+`, 'giu'), errorSyntaxUrl = new RegExp(source, 'giu'), regexes = {
|
|
16
|
+
'[': /[[\]]/u,
|
|
17
|
+
'{': /[{}]/u,
|
|
18
|
+
']': /[[\]](?=[^[\]]*$)/u,
|
|
19
|
+
'}': /[{}](?=[^{}]*$)/u,
|
|
20
|
+
}, disallowedTags = [
|
|
7
21
|
'html',
|
|
8
22
|
'head',
|
|
9
23
|
'style',
|
|
@@ -38,6 +52,8 @@ class AstText extends node_1.AstNode {
|
|
|
38
52
|
constructor(text) {
|
|
39
53
|
super();
|
|
40
54
|
Object.defineProperties(this, {
|
|
55
|
+
childNodes: { enumerable: false, configurable: false },
|
|
56
|
+
type: { enumerable: false, writable: false },
|
|
41
57
|
data: {
|
|
42
58
|
value: text,
|
|
43
59
|
},
|
|
@@ -58,7 +74,7 @@ class AstText extends node_1.AstNode {
|
|
|
58
74
|
lint(start = this.getAbsoluteIndex()) {
|
|
59
75
|
const { data, parentNode, nextSibling, previousSibling } = this;
|
|
60
76
|
const { NowikiToken } = require('../src/nowiki');
|
|
61
|
-
const { type, name } = parentNode, nowiki = name === 'nowiki' || name === 'pre'
|
|
77
|
+
const { type, name } = parentNode, nowiki = name === 'nowiki' || name === 'pre';
|
|
62
78
|
let errorRegex;
|
|
63
79
|
if (type === 'ext-inner' && (name === 'pre' || parentNode instanceof NowikiToken)) {
|
|
64
80
|
errorRegex = new RegExp(`<\\s*(?:\\/\\s*)${nowiki ? '' : '?'}(${name})\\b`, 'giu');
|
|
@@ -72,53 +88,73 @@ class AstText extends node_1.AstNode {
|
|
|
72
88
|
else {
|
|
73
89
|
errorRegex = errorSyntax;
|
|
74
90
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
if (data.search(errorRegex) === -1) {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
errorRegex.lastIndex = 0;
|
|
95
|
+
const errors = [], nextType = nextSibling?.type, nextName = nextSibling?.name, previousType = previousSibling?.type, root = this.getRootNode(), { ext, html } = root.getAttribute('config'), { top, left } = root.posFromIndex(start), tags = new Set(['onlyinclude', 'noinclude', 'includeonly', ext, html, disallowedTags].flat(2));
|
|
96
|
+
for (let mt = errorRegex.exec(data); mt; mt = errorRegex.exec(data)) {
|
|
97
|
+
const [, tag, prefix] = mt;
|
|
98
|
+
let { 0: error, index } = mt;
|
|
99
|
+
if (prefix && prefix !== ']') {
|
|
100
|
+
const { length } = prefix;
|
|
101
|
+
index += length;
|
|
102
|
+
error = error.slice(length);
|
|
103
|
+
}
|
|
104
|
+
const { 0: char, length } = error;
|
|
105
|
+
if (char === '<' && !tags.has(tag.toLowerCase())
|
|
106
|
+
|| char === '['
|
|
89
107
|
&& type === 'ext-link-text'
|
|
90
108
|
&& (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
|
|
91
109
|
|| nextType === 'ext'
|
|
92
110
|
&& nextName === 'nowiki'
|
|
93
111
|
&& nextSibling.innerText?.includes(']'))) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
else if (char === ']' && (index || length > 1)) {
|
|
115
|
+
errorRegex.lastIndex--;
|
|
116
|
+
}
|
|
117
|
+
const startIndex = start + index, endIndex = startIndex + length, rootStr = String(root), nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], severity = length > 1 && (char !== '<' || !nowiki && /[\s/>]/u.test(nextChar ?? ''))
|
|
118
|
+
|| char === '{' && (nextChar === char || previousChar === '-')
|
|
119
|
+
|| char === '}' && (previousChar === char || nextChar === '-')
|
|
120
|
+
|| char === '[' && (nextChar === char
|
|
121
|
+
|| type === 'ext-link-text'
|
|
122
|
+
|| !data.slice(index + 1).trim() && nextType === 'free-ext-link')
|
|
123
|
+
|| char === ']' && (previousChar === char
|
|
124
|
+
|| !data.slice(0, index).trim() && previousType === 'free-ext-link')
|
|
125
|
+
? 'error'
|
|
126
|
+
: 'warning';
|
|
127
|
+
const leftBracket = char === '{' || char === '[', rightBracket = char === ']' || char === '}';
|
|
128
|
+
if (severity === 'warning' && (leftBracket || rightBracket)) {
|
|
129
|
+
const regex = regexes[char], remains = leftBracket ? data.slice(index + 1) : data.slice(0, index);
|
|
130
|
+
if (char === '{' && regex.exec(remains)?.[0] === '}'
|
|
131
|
+
|| char === '}' && regex.exec(remains)?.[0] === '{') {
|
|
94
132
|
continue;
|
|
95
133
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
: 'warning';
|
|
106
|
-
if (char !== '<' || tags.has(tag.toLowerCase())) {
|
|
107
|
-
errors.push({
|
|
108
|
-
message: Parser.msg('lonely "$1"', char === 'h' ? error : char),
|
|
109
|
-
severity,
|
|
110
|
-
startIndex,
|
|
111
|
-
endIndex,
|
|
112
|
-
startLine,
|
|
113
|
-
endLine: startLine,
|
|
114
|
-
startCol,
|
|
115
|
-
endCol: startCol + length,
|
|
116
|
-
});
|
|
134
|
+
else if (!remains.includes(char)) {
|
|
135
|
+
const sibling = leftBracket ? 'nextSibling' : 'previousSibling';
|
|
136
|
+
let cur = this[sibling];
|
|
137
|
+
while (cur && (cur.type !== 'text' || !regex.test(cur.data))) {
|
|
138
|
+
cur = cur[sibling];
|
|
139
|
+
}
|
|
140
|
+
if (cur && regex.exec(cur.data)[0] !== char) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
117
143
|
}
|
|
118
144
|
}
|
|
119
|
-
|
|
145
|
+
const lines = data.slice(0, index).split('\n'), startLine = lines.length + top - 1, line = lines[lines.length - 1], startCol = lines.length === 1 ? left + line.length : line.length;
|
|
146
|
+
errors.push({
|
|
147
|
+
message: index_1.default.msg('lonely "$1"', char === 'h' ? error : char),
|
|
148
|
+
severity,
|
|
149
|
+
startIndex,
|
|
150
|
+
endIndex,
|
|
151
|
+
startLine,
|
|
152
|
+
endLine: startLine,
|
|
153
|
+
startCol,
|
|
154
|
+
endCol: startCol + length,
|
|
155
|
+
});
|
|
120
156
|
}
|
|
121
|
-
return
|
|
157
|
+
return errors;
|
|
122
158
|
}
|
|
123
159
|
/**
|
|
124
160
|
* 修改内容
|
package/dist/lib/title.d.ts
CHANGED
package/dist/lib/title.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Title = void 0;
|
|
4
4
|
const string_1 = require("../util/string");
|
|
5
|
-
const
|
|
5
|
+
const index_1 = require("../index");
|
|
6
6
|
/** MediaWiki页面标题对象 */
|
|
7
7
|
class Title {
|
|
8
8
|
valid;
|
|
@@ -16,8 +16,7 @@ class Title {
|
|
|
16
16
|
* @param decode 是否需要解码
|
|
17
17
|
* @param selfLink 是否允许selfLink
|
|
18
18
|
*/
|
|
19
|
-
constructor(title, defaultNs = 0, config =
|
|
20
|
-
const { nsid, } = config;
|
|
19
|
+
constructor(title, defaultNs = 0, config = index_1.default.getConfig(), decode = false, selfLink = false) {
|
|
21
20
|
title = (0, string_1.decodeHtml)(title);
|
|
22
21
|
if (decode && title.includes('%')) {
|
|
23
22
|
try {
|
|
@@ -35,7 +34,7 @@ class Title {
|
|
|
35
34
|
}
|
|
36
35
|
const m = title.split(':');
|
|
37
36
|
if (m.length > 1) {
|
|
38
|
-
const id = nsid[m[0].trim().toLowerCase()];
|
|
37
|
+
const id = config.nsid[m[0].trim().toLowerCase()];
|
|
39
38
|
if (id) {
|
|
40
39
|
ns = id;
|
|
41
40
|
title = m.slice(1).join(':').trim();
|
|
@@ -44,13 +43,24 @@ class Title {
|
|
|
44
43
|
this.ns = ns;
|
|
45
44
|
const i = title.indexOf('#');
|
|
46
45
|
if (i !== -1) {
|
|
47
|
-
// eslint-disable-next-line prefer-const
|
|
48
46
|
let fragment = title.slice(i + 1).trimEnd();
|
|
47
|
+
if (fragment.includes('%')) {
|
|
48
|
+
try {
|
|
49
|
+
fragment = decodeURIComponent(fragment);
|
|
50
|
+
}
|
|
51
|
+
catch { }
|
|
52
|
+
}
|
|
53
|
+
else if (fragment.includes('.')) {
|
|
54
|
+
try {
|
|
55
|
+
fragment = decodeURIComponent(fragment.replace(/\./gu, '%'));
|
|
56
|
+
}
|
|
57
|
+
catch { }
|
|
58
|
+
}
|
|
49
59
|
this.fragment = fragment;
|
|
50
60
|
title = title.slice(0, i).trim();
|
|
51
61
|
}
|
|
52
|
-
this.valid = Boolean(title
|
|
53
|
-
|
|
62
|
+
this.valid = Boolean(title || this.interwiki || selfLink && this.fragment !== undefined)
|
|
63
|
+
&& !/^:|\0\d+[eh!+-]\x7F|[<>[\]{}|]|%[\da-f]{2}/iu.test(title);
|
|
54
64
|
}
|
|
55
65
|
}
|
|
56
66
|
exports.Title = Title;
|
package/dist/parser/braces.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseBraces = void 0;
|
|
4
4
|
const string_1 = require("../util/string");
|
|
5
|
-
const
|
|
5
|
+
const index_1 = require("../index");
|
|
6
6
|
const heading_1 = require("../src/heading");
|
|
7
7
|
const transclude_1 = require("../src/transclude");
|
|
8
8
|
const arg_1 = require("../src/arg");
|
|
@@ -13,7 +13,7 @@ const arg_1 = require("../src/arg");
|
|
|
13
13
|
* @param accum
|
|
14
14
|
* @throws TranscludeToken.constructor()
|
|
15
15
|
*/
|
|
16
|
-
const parseBraces = (wikitext, config =
|
|
16
|
+
const parseBraces = (wikitext, config = index_1.default.getConfig(), accum = []) => {
|
|
17
17
|
const source = `${config.excludes?.includes('heading') ? '' : '^(\0\\d+c\x7F)*={1,6}|'}\\[\\[|\\{{2,}|-\\{(?!\\{)`, { parserFunction: [, , , subst] } = config, stack = [], closes = { '=': '\n', '{': '\\}{2,}|\\|', '-': '\\}-', '[': '\\]\\]' }, marks = new Map([['!', '!'], ['!!', '+'], ['(!', '{'], ['!)', '}'], ['!-', '-'], ['=', '~']]);
|
|
18
18
|
let regex = new RegExp(source, 'gmu'), mt = regex.exec(wikitext), moreBraces = wikitext.includes('}}'), lastIndex;
|
|
19
19
|
while (mt
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseCommentAndExt = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_1 = require("../index");
|
|
5
5
|
const onlyinclude_1 = require("../src/onlyinclude");
|
|
6
6
|
const noinclude_1 = require("../src/nowiki/noinclude");
|
|
7
7
|
const include_1 = require("../src/tagPair/include");
|
|
@@ -14,7 +14,7 @@ const comment_1 = require("../src/nowiki/comment");
|
|
|
14
14
|
* @param accum
|
|
15
15
|
* @param includeOnly 是否嵌入
|
|
16
16
|
*/
|
|
17
|
-
const parseCommentAndExt = (wikitext, config =
|
|
17
|
+
const parseCommentAndExt = (wikitext, config = index_1.default.getConfig(), accum = [], includeOnly = false) => {
|
|
18
18
|
const onlyincludeLeft = '<onlyinclude>', onlyincludeRight = '</onlyinclude>', { length } = onlyincludeLeft;
|
|
19
19
|
/** 更新`<onlyinclude>`和`</onlyinclude>`的位置 */
|
|
20
20
|
const update = () => {
|
package/dist/parser/converter.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseConverter = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_1 = require("../index");
|
|
5
5
|
const converter_1 = require("../src/converter");
|
|
6
6
|
/**
|
|
7
7
|
* 解析语言变体转换
|
|
@@ -9,7 +9,7 @@ const converter_1 = require("../src/converter");
|
|
|
9
9
|
* @param config
|
|
10
10
|
* @param accum
|
|
11
11
|
*/
|
|
12
|
-
const parseConverter = (text, config =
|
|
12
|
+
const parseConverter = (text, config = index_1.default.getConfig(), accum = []) => {
|
|
13
13
|
const regex1 = /-\{/gu, regex2 = /-\{|\}-/gu, stack = [];
|
|
14
14
|
let regex = regex1, mt = regex.exec(text);
|
|
15
15
|
while (mt) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseExternalLinks = void 0;
|
|
4
4
|
const string_1 = require("../util/string");
|
|
5
|
-
const
|
|
5
|
+
const index_1 = require("../index");
|
|
6
6
|
const extLink_1 = require("../src/extLink");
|
|
7
7
|
/**
|
|
8
8
|
* 解析外部链接
|
|
@@ -10,7 +10,7 @@ const extLink_1 = require("../src/extLink");
|
|
|
10
10
|
* @param config
|
|
11
11
|
* @param accum
|
|
12
12
|
*/
|
|
13
|
-
const parseExternalLinks = (wikitext, config =
|
|
13
|
+
const parseExternalLinks = (wikitext, config = index_1.default.getConfig(), accum = []) => {
|
|
14
14
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
15
15
|
/\[((?:\[[\da-f:.]+\]|[^[\]\t\n\p{Zs}])[^[\]\t\n\p{Zs}]*(?=[[\]\t\p{Zs}]|\0\d))(\p{Zs}*(?=\P{Zs}))([^\]\n]*)\]/giu;
|
|
16
16
|
const regex = new RegExp(`\\[((?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\\d+m\x7F)${string_1.extUrlChar}(?=[[\\]<>"\\t\\p{Zs}]|\0\\d))`
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseHrAndDoubleUnderscore = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_1 = require("../index");
|
|
5
5
|
const hr_1 = require("../src/nowiki/hr");
|
|
6
6
|
const doubleUnderscore_1 = require("../src/nowiki/doubleUnderscore");
|
|
7
7
|
const heading_1 = require("../src/heading");
|
|
@@ -11,7 +11,7 @@ const heading_1 = require("../src/heading");
|
|
|
11
11
|
* @param config
|
|
12
12
|
* @param accum
|
|
13
13
|
*/
|
|
14
|
-
const parseHrAndDoubleUnderscore = ({ firstChild: { data }, type, name }, config =
|
|
14
|
+
const parseHrAndDoubleUnderscore = ({ firstChild: { data }, type, name }, config = index_1.default.getConfig(), accum = []) => {
|
|
15
15
|
const { doubleUnderscore } = config, insensitive = new Set(doubleUnderscore[0]), sensitive = new Set(doubleUnderscore[1]);
|
|
16
16
|
if (type !== 'root' && (type !== 'ext-inner' || name !== 'poem')) {
|
|
17
17
|
data = `\0${data}`;
|
package/dist/parser/html.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseHtml = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_1 = require("../index");
|
|
5
5
|
const attributes_1 = require("../src/attributes");
|
|
6
6
|
const html_1 = require("../src/html");
|
|
7
7
|
/**
|
|
@@ -10,7 +10,7 @@ const html_1 = require("../src/html");
|
|
|
10
10
|
* @param config
|
|
11
11
|
* @param accum
|
|
12
12
|
*/
|
|
13
|
-
const parseHtml = (wikitext, config =
|
|
13
|
+
const parseHtml = (wikitext, config = index_1.default.getConfig(), accum = []) => {
|
|
14
14
|
const regex = /^(\/?)([a-z][^\s/>]*)((?:\s|\/(?!>))[^>]*?)?(\/?>)([^<]*)$/iu, elements = new Set(config.html.flat()), bits = wikitext.split('<');
|
|
15
15
|
let text = bits.shift();
|
|
16
16
|
for (const x of bits) {
|
package/dist/parser/links.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseLinks = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
const index_2 = require("../src/link/index");
|
|
6
6
|
const file_1 = require("../src/link/file");
|
|
7
7
|
const category_1 = require("../src/link/category");
|
|
8
8
|
/**
|
|
@@ -11,7 +11,7 @@ const category_1 = require("../src/link/category");
|
|
|
11
11
|
* @param config
|
|
12
12
|
* @param accum
|
|
13
13
|
*/
|
|
14
|
-
const parseLinks = (wikitext, config =
|
|
14
|
+
const parseLinks = (wikitext, config = index_1.default.getConfig(), accum = []) => {
|
|
15
15
|
const { parseQuotes } = require('./quotes');
|
|
16
16
|
const regex = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)(.*?[^\]]))?\]\](.*)$/su, regexImg = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(\||\0\d+!\x7F)(.*)$/su, regexExt = new RegExp(`^\\s*(?:${config.protocol}|//)`, 'iu'), bits = wikitext.split('[[');
|
|
17
17
|
let s = bits.shift();
|
|
@@ -41,13 +41,13 @@ const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
|
41
41
|
s += `[[${x}`;
|
|
42
42
|
continue;
|
|
43
43
|
}
|
|
44
|
-
const title =
|
|
44
|
+
const title = index_1.default.normalizeTitle(link, 0, false, config, true, true, true), { ns, valid, interwiki } = title;
|
|
45
45
|
if (!valid) {
|
|
46
46
|
s += `[[${x}`;
|
|
47
47
|
continue;
|
|
48
48
|
}
|
|
49
49
|
else if (mightBeImg) {
|
|
50
|
-
if (ns !== 6) {
|
|
50
|
+
if (interwiki || ns !== 6) {
|
|
51
51
|
s += `[[${x}`;
|
|
52
52
|
continue;
|
|
53
53
|
}
|
|
@@ -76,12 +76,12 @@ const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
|
76
76
|
}
|
|
77
77
|
text &&= parseQuotes(text, config, accum);
|
|
78
78
|
s += `\0${accum.length}l\x7F${after}`;
|
|
79
|
-
let SomeLinkToken =
|
|
79
|
+
let SomeLinkToken = index_2.LinkToken;
|
|
80
80
|
if (!force) {
|
|
81
|
-
if (ns === 6) {
|
|
81
|
+
if (!interwiki && ns === 6) {
|
|
82
82
|
SomeLinkToken = file_1.FileToken;
|
|
83
83
|
}
|
|
84
|
-
else if (ns === 14) {
|
|
84
|
+
else if (!interwiki && ns === 14) {
|
|
85
85
|
SomeLinkToken = category_1.CategoryToken;
|
|
86
86
|
}
|
|
87
87
|
}
|
package/dist/parser/list.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseList = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_1 = require("../index");
|
|
5
5
|
const list_1 = require("../src/nowiki/list");
|
|
6
6
|
const dd_1 = require("../src/nowiki/dd");
|
|
7
7
|
/**
|
|
@@ -10,7 +10,7 @@ const dd_1 = require("../src/nowiki/dd");
|
|
|
10
10
|
* @param config
|
|
11
11
|
* @param accum
|
|
12
12
|
*/
|
|
13
|
-
const parseList = (wikitext, config =
|
|
13
|
+
const parseList = (wikitext, config = index_1.default.getConfig(), accum = []) => {
|
|
14
14
|
const mt = /^((?:\0\d+c\x7F)*)([;:*#]+)/u.exec(wikitext);
|
|
15
15
|
if (!mt) {
|
|
16
16
|
return wikitext;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseMagicLinks = void 0;
|
|
4
4
|
const string_1 = require("../util/string");
|
|
5
|
-
const
|
|
5
|
+
const index_1 = require("../index");
|
|
6
6
|
const magicLink_1 = require("../src/magicLink");
|
|
7
7
|
/**
|
|
8
8
|
* 解析自由外链
|
|
@@ -10,7 +10,7 @@ const magicLink_1 = require("../src/magicLink");
|
|
|
10
10
|
* @param config
|
|
11
11
|
* @param accum
|
|
12
12
|
*/
|
|
13
|
-
const parseMagicLinks = (wikitext, config =
|
|
13
|
+
const parseMagicLinks = (wikitext, config = index_1.default.getConfig(), accum = []) => {
|
|
14
14
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
15
15
|
/(^|[^\p{L}\d_])((?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])(?:[^[\]<>"\0\t\n\p{Zs}]|\0\d+c\x7F)*)/giu;
|
|
16
16
|
const regex = new RegExp(`(^|[^\\p{L}\\d_])(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})`, 'giu');
|
package/dist/parser/quotes.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseQuotes = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_1 = require("../index");
|
|
5
5
|
const quote_1 = require("../src/nowiki/quote");
|
|
6
6
|
/**
|
|
7
7
|
* 解析单引号
|
|
@@ -9,14 +9,14 @@ const quote_1 = require("../src/nowiki/quote");
|
|
|
9
9
|
* @param config
|
|
10
10
|
* @param accum
|
|
11
11
|
*/
|
|
12
|
-
const parseQuotes = (wikitext, config =
|
|
12
|
+
const parseQuotes = (wikitext, config = index_1.default.getConfig(), accum = []) => {
|
|
13
13
|
const arr = wikitext.split(/('{2,})/u), { length } = arr;
|
|
14
14
|
if (length === 1) {
|
|
15
15
|
return wikitext;
|
|
16
16
|
}
|
|
17
17
|
let nBold = 0, nItalic = 0, firstSingle, firstMulti, firstSpace;
|
|
18
18
|
for (let i = 1; i < length; i += 2) {
|
|
19
|
-
const
|
|
19
|
+
const len = arr[i].length;
|
|
20
20
|
switch (len) {
|
|
21
21
|
case 2:
|
|
22
22
|
nItalic++;
|
package/dist/parser/table.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseTable = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
const index_2 = require("../src/index");
|
|
6
|
+
const index_3 = require("../src/table/index");
|
|
7
7
|
const tr_1 = require("../src/table/tr");
|
|
8
8
|
const td_1 = require("../src/table/td");
|
|
9
9
|
const dd_1 = require("../src/nowiki/dd");
|
|
@@ -11,14 +11,14 @@ const dd_1 = require("../src/nowiki/dd");
|
|
|
11
11
|
* 判断是否为表格行或表格
|
|
12
12
|
* @param token 表格节点
|
|
13
13
|
*/
|
|
14
|
-
const isTr = (token) => token.lastChild.constructor !==
|
|
14
|
+
const isTr = (token) => token.lastChild.constructor !== index_2.Token;
|
|
15
15
|
/**
|
|
16
16
|
* 解析表格,注意`tr`和`td`包含开头的换行
|
|
17
17
|
* @param {Token & {firstChild: AstText}} root 根节点
|
|
18
18
|
* @param config
|
|
19
19
|
* @param accum
|
|
20
20
|
*/
|
|
21
|
-
const parseTable = ({ firstChild: { data }, type, name }, config =
|
|
21
|
+
const parseTable = ({ firstChild: { data }, type, name }, config = index_1.default.getConfig(), accum = []) => {
|
|
22
22
|
const stack = [], lines = data.split('\n');
|
|
23
23
|
let out = type === 'root' || type === 'parameter-value' || type === 'ext-inner' && name === 'poem'
|
|
24
24
|
? ''
|
|
@@ -35,7 +35,7 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
|
|
|
35
35
|
}
|
|
36
36
|
const { lastChild } = topToken;
|
|
37
37
|
if (isTr(topToken)) {
|
|
38
|
-
const token = new
|
|
38
|
+
const token = new index_2.Token(str, config, accum);
|
|
39
39
|
token.type = 'table-inter';
|
|
40
40
|
token.setAttribute('stage', 3);
|
|
41
41
|
topToken.insertAt(token);
|
|
@@ -61,7 +61,7 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
|
|
|
61
61
|
}
|
|
62
62
|
push(`\n${spaces}${indent && `\0${accum.length - 1}d\x7F`}${moreSpaces}\0${accum.length}b\x7F`, top);
|
|
63
63
|
// @ts-expect-error abstract class
|
|
64
|
-
stack.push(...top ? [top] : [], new
|
|
64
|
+
stack.push(...top ? [top] : [], new index_3.TableToken(tableSyntax, attr, config, accum));
|
|
65
65
|
continue;
|
|
66
66
|
}
|
|
67
67
|
else if (!top) {
|
package/dist/src/arg.d.ts
CHANGED
package/dist/src/arg.js
CHANGED
|
@@ -3,22 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ArgToken = void 0;
|
|
4
4
|
const string_1 = require("../util/string");
|
|
5
5
|
const lint_1 = require("../util/lint");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const index_1 = require("../index");
|
|
7
|
+
const index_2 = require("./index");
|
|
8
8
|
const atom_1 = require("./atom");
|
|
9
9
|
const hidden_1 = require("./hidden");
|
|
10
10
|
/**
|
|
11
11
|
* `{{{}}}`包裹的参数
|
|
12
12
|
* @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
|
|
13
13
|
*/
|
|
14
|
-
class ArgToken extends
|
|
14
|
+
class ArgToken extends index_2.Token {
|
|
15
15
|
type = 'arg';
|
|
16
16
|
/** 预设值 */
|
|
17
17
|
get default() {
|
|
18
18
|
return this.childNodes[1]?.text() ?? false;
|
|
19
19
|
}
|
|
20
20
|
/** @param parts 以'|'分隔的各部分 */
|
|
21
|
-
constructor(parts, config =
|
|
21
|
+
constructor(parts, config = index_1.default.getConfig(), accum = []) {
|
|
22
22
|
super(undefined, config, accum, {});
|
|
23
23
|
for (let i = 0; i < parts.length; i++) {
|
|
24
24
|
if (i === 0) {
|
|
@@ -30,7 +30,7 @@ class ArgToken extends index_1.Token {
|
|
|
30
30
|
super.insertAt(token);
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
|
-
const token = new
|
|
33
|
+
const token = new index_2.Token(parts[i], config, accum);
|
|
34
34
|
token.type = 'arg-default';
|
|
35
35
|
token.setAttribute('stage', 2);
|
|
36
36
|
super.insertAt(token);
|
|
@@ -38,8 +38,8 @@ class ArgToken extends index_1.Token {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
/** @private */
|
|
41
|
-
toString(
|
|
42
|
-
return `{{{${super.toString(
|
|
41
|
+
toString() {
|
|
42
|
+
return `{{{${super.toString('|')}}}}`;
|
|
43
43
|
}
|
|
44
44
|
/** @override */
|
|
45
45
|
text() {
|