wikiparser-node 1.0.0-beta.0 → 1.0.0-beta.2
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 +26 -0
- package/dist/index.d.ts +11 -9
- package/dist/index.js +22 -24
- package/dist/internal.d.ts +44 -0
- package/dist/lib/element.d.ts +42 -32
- package/dist/lib/element.js +59 -56
- package/dist/lib/node.d.ts +29 -36
- package/dist/lib/node.js +33 -48
- package/dist/lib/range.d.ts +132 -0
- package/dist/lib/range.js +387 -0
- package/dist/lib/ranges.d.ts +2 -12
- package/dist/lib/ranges.js +6 -11
- package/dist/lib/text.d.ts +11 -5
- package/dist/lib/text.js +25 -13
- package/dist/lib/title.d.ts +4 -5
- package/dist/lib/title.js +17 -7
- package/dist/mixin/attributesParent.js +6 -3
- package/dist/mixin/fixed.js +8 -5
- package/dist/mixin/hidden.js +7 -3
- package/dist/mixin/singleLine.js +6 -3
- package/dist/mixin/sol.js +6 -3
- package/dist/parser/{brackets.js → braces.js} +34 -26
- package/dist/parser/commentAndExt.js +25 -15
- package/dist/parser/converter.js +16 -9
- package/dist/parser/externalLinks.js +15 -9
- package/dist/parser/hrAndDoubleUnderscore.js +17 -10
- package/dist/parser/html.js +18 -9
- package/dist/parser/links.js +22 -14
- package/dist/parser/list.js +20 -10
- package/dist/parser/magicLinks.js +14 -7
- package/dist/parser/quotes.js +21 -11
- package/dist/parser/selector.js +19 -12
- package/dist/parser/table.js +25 -16
- package/dist/src/arg.d.ts +7 -8
- package/dist/src/arg.js +27 -24
- package/dist/src/atom.d.ts +4 -5
- package/dist/src/atom.js +9 -7
- package/dist/src/attribute.d.ts +13 -13
- package/dist/src/attribute.js +28 -25
- package/dist/src/attributes.d.ts +11 -10
- package/dist/src/attributes.js +40 -45
- package/dist/src/converter.d.ts +5 -7
- package/dist/src/converter.js +22 -16
- package/dist/src/converterFlags.d.ts +11 -12
- package/dist/src/converterFlags.js +17 -14
- package/dist/src/converterRule.d.ts +9 -10
- package/dist/src/converterRule.js +27 -27
- package/dist/src/extLink.d.ts +4 -6
- package/dist/src/extLink.js +25 -22
- package/dist/src/gallery.d.ts +9 -13
- package/dist/src/gallery.js +28 -23
- package/dist/src/heading.d.ts +11 -11
- package/dist/src/heading.js +19 -19
- package/dist/src/hidden.d.ts +4 -5
- package/dist/src/hidden.js +10 -8
- package/dist/src/html.d.ts +15 -12
- package/dist/src/html.js +18 -15
- package/dist/src/imageParameter.d.ts +11 -13
- package/dist/src/imageParameter.js +21 -16
- package/dist/src/imagemap.d.ts +11 -15
- package/dist/src/imagemap.js +26 -21
- package/dist/src/imagemapLink.d.ts +12 -17
- package/dist/src/imagemapLink.js +19 -14
- package/dist/src/index.d.ts +24 -20
- package/dist/src/index.js +65 -75
- package/dist/src/link/base.d.ts +8 -10
- package/dist/src/link/base.js +28 -22
- package/dist/src/link/category.d.ts +2 -3
- package/dist/src/link/category.js +7 -5
- package/dist/src/link/file.d.ts +9 -11
- package/dist/src/link/file.js +53 -26
- package/dist/src/link/galleryImage.d.ts +8 -8
- package/dist/src/link/galleryImage.js +18 -16
- package/dist/src/link/index.d.ts +6 -6
- package/dist/src/link/index.js +14 -16
- package/dist/src/magicLink.d.ts +9 -6
- package/dist/src/magicLink.js +23 -18
- package/dist/src/nested.d.ts +10 -10
- package/dist/src/nested.js +25 -17
- package/dist/src/nowiki/base.d.ts +7 -8
- package/dist/src/nowiki/base.js +10 -8
- package/dist/src/nowiki/comment.d.ts +7 -7
- package/dist/src/nowiki/comment.js +12 -9
- package/dist/src/nowiki/dd.d.ts +2 -3
- package/dist/src/nowiki/dd.js +7 -11
- package/dist/src/nowiki/doubleUnderscore.d.ts +5 -7
- package/dist/src/nowiki/doubleUnderscore.js +11 -8
- package/dist/src/nowiki/hr.d.ts +6 -7
- package/dist/src/nowiki/hr.js +11 -8
- package/dist/src/nowiki/index.d.ts +5 -7
- package/dist/src/nowiki/index.js +8 -6
- package/dist/src/nowiki/list.d.ts +4 -4
- package/dist/src/nowiki/list.js +8 -6
- package/dist/src/nowiki/noinclude.d.ts +3 -3
- package/dist/src/nowiki/noinclude.js +8 -6
- package/dist/src/nowiki/quote.d.ts +6 -7
- package/dist/src/nowiki/quote.js +11 -8
- package/dist/src/onlyinclude.d.ts +3 -5
- package/dist/src/onlyinclude.js +9 -7
- package/dist/src/paramTag/index.d.ts +8 -10
- package/dist/src/paramTag/index.js +15 -13
- package/dist/src/paramTag/inputbox.d.ts +4 -6
- package/dist/src/paramTag/inputbox.js +10 -8
- package/dist/src/parameter.d.ts +11 -12
- package/dist/src/parameter.js +25 -22
- package/dist/src/pre.d.ts +5 -10
- package/dist/src/pre.js +16 -11
- package/dist/src/syntax.d.ts +6 -7
- package/dist/src/syntax.js +12 -10
- package/dist/src/table/base.d.ts +14 -9
- package/dist/src/table/base.js +18 -15
- package/dist/src/table/index.d.ts +24 -17
- package/dist/src/table/index.js +39 -67
- package/dist/src/table/td.d.ts +17 -21
- package/dist/src/table/td.js +20 -28
- package/dist/src/table/tr.d.ts +6 -11
- package/dist/src/table/tr.js +8 -6
- package/dist/src/table/trBase.d.ts +12 -22
- package/dist/src/table/trBase.js +23 -19
- package/dist/src/tagPair/ext.d.ts +10 -10
- package/dist/src/tagPair/ext.js +47 -24
- package/dist/src/tagPair/include.d.ts +6 -7
- package/dist/src/tagPair/include.js +11 -8
- package/dist/src/tagPair/index.d.ts +12 -11
- package/dist/src/tagPair/index.js +13 -11
- package/dist/src/transclude.d.ts +8 -10
- package/dist/src/transclude.js +70 -77
- package/dist/util/debug.js +2 -12
- package/dist/util/diff.js +4 -2
- package/dist/util/lint.js +5 -5
- package/dist/util/string.js +2 -31
- package/package.json +13 -13
- package/dist/util/base.js +0 -26
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseMagicLinks = void 0;
|
|
2
4
|
const string_1 = require("../util/string");
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
const index_1 = require("../index");
|
|
6
|
+
const magicLink_1 = require("../src/magicLink");
|
|
7
|
+
/**
|
|
8
|
+
* 解析自由外链
|
|
9
|
+
* @param wikitext
|
|
10
|
+
* @param config
|
|
11
|
+
* @param accum
|
|
12
|
+
*/
|
|
13
|
+
const parseMagicLinks = (wikitext, config = index_1.default.getConfig(), accum = []) => {
|
|
7
14
|
const regex = new RegExp(`(?<![\\p{L}\\d_])(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})`, 'giu');
|
|
8
15
|
return wikitext.replace(regex, (m, p1) => {
|
|
9
16
|
let trail = '', url = m;
|
|
@@ -24,9 +31,9 @@ const parseMagicLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
|
24
31
|
if (trail.length >= p1.length) {
|
|
25
32
|
return m;
|
|
26
33
|
}
|
|
27
|
-
new MagicLinkToken(url, false, config, accum);
|
|
34
|
+
new magicLink_1.MagicLinkToken(url, false, config, accum);
|
|
28
35
|
return `\0${accum.length - 1}w\x7F${trail}`;
|
|
29
36
|
});
|
|
30
37
|
};
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
exports.parseMagicLinks = parseMagicLinks;
|
|
39
|
+
index_1.default.parsers['parseMagicLinks'] = __filename;
|
package/dist/parser/quotes.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseQuotes = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
const quote_1 = require("../src/nowiki/quote");
|
|
6
|
+
/**
|
|
7
|
+
* 解析单引号
|
|
8
|
+
* @param wikitext
|
|
9
|
+
* @param config
|
|
10
|
+
* @param accum
|
|
11
|
+
*/
|
|
12
|
+
const parseQuotes = (wikitext, config = index_1.default.getConfig(), accum = []) => {
|
|
6
13
|
const arr = wikitext.split(/('{2,})/u), { length } = arr;
|
|
7
14
|
if (length === 1) {
|
|
8
15
|
return wikitext;
|
|
@@ -20,11 +27,11 @@ const parseQuotes = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
|
20
27
|
// fall through
|
|
21
28
|
case 3:
|
|
22
29
|
nBold++;
|
|
23
|
-
if (firstSingle) {
|
|
30
|
+
if (firstSingle !== undefined) {
|
|
24
31
|
break;
|
|
25
32
|
}
|
|
26
33
|
else if (arr[i - 1].endsWith(' ')) {
|
|
27
|
-
if (
|
|
34
|
+
if (firstMulti === undefined && firstSpace === undefined) {
|
|
28
35
|
firstSpace = i;
|
|
29
36
|
}
|
|
30
37
|
}
|
|
@@ -44,14 +51,17 @@ const parseQuotes = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
|
44
51
|
}
|
|
45
52
|
if (nItalic % 2 === 1 && nBold % 2 === 1) {
|
|
46
53
|
const i = firstSingle ?? firstMulti ?? firstSpace;
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
if (i !== undefined) {
|
|
55
|
+
arr[i] = `''`;
|
|
56
|
+
arr[i - 1] += `'`;
|
|
57
|
+
}
|
|
49
58
|
}
|
|
50
59
|
for (let i = 1; i < length; i += 2) {
|
|
51
|
-
|
|
60
|
+
// @ts-expect-error abstract class
|
|
61
|
+
new quote_1.QuoteToken(arr[i].length, config, accum);
|
|
52
62
|
arr[i] = `\0${accum.length - 1}q\x7F`;
|
|
53
63
|
}
|
|
54
64
|
return arr.join('');
|
|
55
65
|
};
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
exports.parseQuotes = parseQuotes;
|
|
67
|
+
index_1.default.parsers['parseQuotes'] = __filename;
|
package/dist/parser/selector.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseSelector = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
3
5
|
const simplePseudos = new Set([
|
|
4
6
|
'root',
|
|
5
7
|
'first-child',
|
|
@@ -45,21 +47,25 @@ const specialChars = [
|
|
|
45
47
|
['&', '&'],
|
|
46
48
|
];
|
|
47
49
|
const pseudoRegex = new RegExp(`:(${complexPseudos.join('|')})$`, 'u'), regularRegex = /[[(,>+~]|\s+/u, attributeRegex = /^\s*(\w+)\s*(?:([~|^$*!]?=)\s*("[^"]*"|'[^']*'|[^\s[\]]+)(?:\s+(i))?\s*)?\]/u, functionRegex = /^(\s*"[^"]*"\s*|\s*'[^']*'\s*|[^()]*)\)/u, grouping = new Set([',', '>', '+', '~']), combinator = new Set(['>', '+', '~', '']);
|
|
48
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* 清理转义符号
|
|
52
|
+
* @param selector
|
|
53
|
+
*/
|
|
49
54
|
const sanitize = (selector) => {
|
|
50
|
-
let s = selector;
|
|
51
55
|
for (const [c, escaped] of specialChars) {
|
|
52
|
-
|
|
56
|
+
selector = selector.replaceAll(`\\${c}`, escaped);
|
|
53
57
|
}
|
|
54
|
-
return
|
|
58
|
+
return selector;
|
|
55
59
|
};
|
|
56
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* 还原转义符号
|
|
62
|
+
* @param selector
|
|
63
|
+
*/
|
|
57
64
|
const desanitize = (selector) => {
|
|
58
|
-
let str = selector;
|
|
59
65
|
for (const [c, escaped] of specialChars) {
|
|
60
|
-
|
|
66
|
+
selector = selector.replaceAll(escaped, c);
|
|
61
67
|
}
|
|
62
|
-
return
|
|
68
|
+
return selector.trim();
|
|
63
69
|
};
|
|
64
70
|
/**
|
|
65
71
|
* 去除首尾的引号
|
|
@@ -86,6 +92,7 @@ const pushSimple = (step, str) => {
|
|
|
86
92
|
};
|
|
87
93
|
/**
|
|
88
94
|
* 解析选择器
|
|
95
|
+
* @param selector
|
|
89
96
|
* @throws `SyntaxError` 非法的选择器
|
|
90
97
|
*/
|
|
91
98
|
const parseSelector = (selector) => {
|
|
@@ -148,11 +155,11 @@ const parseSelector = (selector) => {
|
|
|
148
155
|
pushSimple(step, sanitized);
|
|
149
156
|
const pseudos = new Set(stack.flat(2).filter(e => typeof e === 'string' && e.startsWith(':')));
|
|
150
157
|
if (pseudos.size > 0) {
|
|
151
|
-
|
|
158
|
+
index_1.default.warn('检测到伪选择器,请确认是否需要将":"转义成"\\:"。', pseudos);
|
|
152
159
|
}
|
|
153
160
|
return stack;
|
|
154
161
|
}
|
|
155
162
|
throw new SyntaxError(`非法的选择器!\n${s}\n检测到未闭合的'${regex === attributeRegex ? '[' : '('}'`);
|
|
156
163
|
};
|
|
157
|
-
|
|
158
|
-
|
|
164
|
+
exports.parseSelector = parseSelector;
|
|
165
|
+
index_1.default.parsers['parseSelector'] = __filename;
|
package/dist/parser/table.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseTable = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
const src_1 = require("../src");
|
|
6
|
+
const table_1 = require("../src/table");
|
|
7
|
+
const tr_1 = require("../src/table/tr");
|
|
8
|
+
const td_1 = require("../src/table/td");
|
|
9
|
+
const dd_1 = require("../src/nowiki/dd");
|
|
8
10
|
/**
|
|
9
11
|
* 解析表格,注意`tr`和`td`包含开头的换行
|
|
10
12
|
* @param {Token & {firstChild: AstText}} root 根节点
|
|
13
|
+
* @param config
|
|
14
|
+
* @param accum
|
|
11
15
|
*/
|
|
12
|
-
const parseTable = ({ firstChild: { data }, type, name }, config =
|
|
16
|
+
const parseTable = ({ firstChild: { data }, type, name }, config = index_1.default.getConfig(), accum = []) => {
|
|
13
17
|
const stack = [], lines = data.split('\n');
|
|
14
18
|
let out = type === 'root' || type === 'parameter-value' || type === 'ext-inner' && name === 'poem'
|
|
15
19
|
? ''
|
|
@@ -25,11 +29,11 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
|
|
|
25
29
|
return;
|
|
26
30
|
}
|
|
27
31
|
const { lastChild } = top;
|
|
28
|
-
if (lastChild.constructor === Token) {
|
|
32
|
+
if (lastChild.constructor === src_1.Token) {
|
|
29
33
|
lastChild.setText(String(lastChild) + str);
|
|
30
34
|
}
|
|
31
35
|
else {
|
|
32
|
-
const token = new Token(str, config, true, accum);
|
|
36
|
+
const token = new src_1.Token(str, config, true, accum);
|
|
33
37
|
token.type = 'table-inter';
|
|
34
38
|
top.insertAt(token.setAttribute('stage', 3));
|
|
35
39
|
}
|
|
@@ -44,10 +48,12 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
|
|
|
44
48
|
}
|
|
45
49
|
const [, indent, moreSpaces, tableSyntax, attr] = matchesStart;
|
|
46
50
|
if (indent) {
|
|
47
|
-
|
|
51
|
+
// @ts-expect-error abstract class
|
|
52
|
+
new dd_1.DdToken(indent, config, accum);
|
|
48
53
|
}
|
|
49
54
|
push(`\n${spaces}${indent && `\0${accum.length - 1}d\x7F`}${moreSpaces}\0${accum.length}b\x7F`, top);
|
|
50
|
-
|
|
55
|
+
// @ts-expect-error abstract class
|
|
56
|
+
const table = new table_1.TableToken(tableSyntax, attr, config, accum);
|
|
51
57
|
stack.push(...top ? [top] : [], table);
|
|
52
58
|
continue;
|
|
53
59
|
}
|
|
@@ -78,7 +84,8 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
|
|
|
78
84
|
if (top.type === 'tr') {
|
|
79
85
|
top = stack.pop();
|
|
80
86
|
}
|
|
81
|
-
|
|
87
|
+
// @ts-expect-error abstract class
|
|
88
|
+
const tr = new tr_1.TrToken(`\n${spaces}${row}`, attr, config, accum);
|
|
82
89
|
stack.push(top, tr);
|
|
83
90
|
top.insertAt(tr);
|
|
84
91
|
}
|
|
@@ -91,18 +98,20 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
|
|
|
91
98
|
: /(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu;
|
|
92
99
|
let mt = regex.exec(attr), lastIndex = 0, lastSyntax = `\n${spaces}${cell}`;
|
|
93
100
|
while (mt) {
|
|
94
|
-
|
|
101
|
+
// @ts-expect-error abstract class
|
|
102
|
+
const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex, mt.index), config, accum);
|
|
95
103
|
top.insertAt(td);
|
|
96
104
|
({ lastIndex } = regex);
|
|
97
105
|
[lastSyntax] = mt;
|
|
98
106
|
mt = regex.exec(attr);
|
|
99
107
|
}
|
|
100
|
-
|
|
108
|
+
// @ts-expect-error abstract class
|
|
109
|
+
const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex), config, accum);
|
|
101
110
|
stack.push(top, td);
|
|
102
111
|
top.insertAt(td);
|
|
103
112
|
}
|
|
104
113
|
}
|
|
105
114
|
return out.slice(1);
|
|
106
115
|
};
|
|
107
|
-
|
|
108
|
-
|
|
116
|
+
exports.parseTable = parseTable;
|
|
117
|
+
index_1.default.parsers['parseTable'] = __filename;
|
package/dist/src/arg.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { Token } from '.';
|
|
2
|
+
import { AtomToken } from './atom';
|
|
3
|
+
import { HiddenToken } from './hidden';
|
|
4
|
+
import type { LintError } from '../index';
|
|
5
5
|
/**
|
|
6
6
|
* `{{{}}}`包裹的参数
|
|
7
7
|
* @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
|
|
8
8
|
*/
|
|
9
|
-
declare abstract class ArgToken extends Token {
|
|
9
|
+
export declare abstract class ArgToken extends Token {
|
|
10
10
|
/** @browser */
|
|
11
11
|
readonly type = "arg";
|
|
12
12
|
name: string;
|
|
@@ -24,7 +24,7 @@ declare abstract class ArgToken extends Token {
|
|
|
24
24
|
* @browser
|
|
25
25
|
* @param parts 以'|'分隔的各部分
|
|
26
26
|
*/
|
|
27
|
-
constructor(parts: string[], config?:
|
|
27
|
+
constructor(parts: string[], config?: import("../index").Config, accum?: Token[]);
|
|
28
28
|
/**
|
|
29
29
|
* @override
|
|
30
30
|
* @browser
|
|
@@ -44,7 +44,7 @@ declare abstract class ArgToken extends Token {
|
|
|
44
44
|
* @override
|
|
45
45
|
* @browser
|
|
46
46
|
*/
|
|
47
|
-
lint(start?: number):
|
|
47
|
+
lint(start?: number): LintError[];
|
|
48
48
|
/** @override */
|
|
49
49
|
cloneNode(): this;
|
|
50
50
|
/** 移除无效部分 */
|
|
@@ -75,4 +75,3 @@ declare abstract class ArgToken extends Token {
|
|
|
75
75
|
*/
|
|
76
76
|
setDefault(value: string): void;
|
|
77
77
|
}
|
|
78
|
-
export = ArgToken;
|
package/dist/src/arg.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArgToken = void 0;
|
|
2
4
|
const string_1 = require("../util/string");
|
|
3
5
|
const lint_1 = require("../util/lint");
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const index_1 = require("../index");
|
|
7
|
+
const _1 = require(".");
|
|
8
|
+
const atom_1 = require("./atom");
|
|
9
|
+
const hidden_1 = require("./hidden");
|
|
8
10
|
/**
|
|
9
11
|
* `{{{}}}`包裹的参数
|
|
10
12
|
* @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
|
|
11
13
|
*/
|
|
12
|
-
class ArgToken extends Token {
|
|
14
|
+
class ArgToken extends _1.Token {
|
|
13
15
|
/** @browser */
|
|
14
16
|
type = 'arg';
|
|
15
17
|
/**
|
|
@@ -23,25 +25,25 @@ class ArgToken extends Token {
|
|
|
23
25
|
* @browser
|
|
24
26
|
* @param parts 以'|'分隔的各部分
|
|
25
27
|
*/
|
|
26
|
-
constructor(parts, config =
|
|
28
|
+
constructor(parts, config = index_1.default.getConfig(), accum = []) {
|
|
27
29
|
super(undefined, config, true, accum, {
|
|
28
30
|
AtomToken: 0, Token: 1, HiddenToken: '2:',
|
|
29
31
|
});
|
|
30
32
|
for (let i = 0; i < parts.length; i++) {
|
|
31
33
|
if (i === 0) {
|
|
32
|
-
const token = new AtomToken(parts[i], 'arg-name', config, accum, {
|
|
34
|
+
const token = new atom_1.AtomToken(parts[i], 'arg-name', config, accum, {
|
|
33
35
|
'Stage-2': ':', '!HeadingToken': '',
|
|
34
36
|
});
|
|
35
37
|
super.insertAt(token);
|
|
36
38
|
}
|
|
37
39
|
else if (i > 1) {
|
|
38
|
-
const token = new HiddenToken(parts[i], config, accum, {
|
|
40
|
+
const token = new hidden_1.HiddenToken(parts[i], config, accum, {
|
|
39
41
|
'Stage-2': ':', '!HeadingToken': '',
|
|
40
42
|
});
|
|
41
43
|
super.insertAt(token);
|
|
42
44
|
}
|
|
43
45
|
else {
|
|
44
|
-
const token = new Token(parts[i], config, true, accum);
|
|
46
|
+
const token = new _1.Token(parts[i], config, true, accum);
|
|
45
47
|
token.type = 'arg-default';
|
|
46
48
|
super.insertAt(token.setAttribute('stage', 2));
|
|
47
49
|
}
|
|
@@ -67,8 +69,8 @@ class ArgToken extends Token {
|
|
|
67
69
|
return 3;
|
|
68
70
|
}
|
|
69
71
|
/** @private */
|
|
70
|
-
getGaps() {
|
|
71
|
-
return 1;
|
|
72
|
+
getGaps(i) {
|
|
73
|
+
return i < this.length - 1 ? 1 : 0;
|
|
72
74
|
}
|
|
73
75
|
/**
|
|
74
76
|
* @override
|
|
@@ -92,7 +94,7 @@ class ArgToken extends Token {
|
|
|
92
94
|
if (rest.length > 0) {
|
|
93
95
|
const rect = { start, ...this.getRootNode().posFromIndex(start) };
|
|
94
96
|
errors.push(...rest.map(child => {
|
|
95
|
-
const error = (0, lint_1.generateForChild)(child, rect, 'invisible content inside triple
|
|
97
|
+
const error = (0, lint_1.generateForChild)(child, rect, 'invisible content inside triple braces'), { startIndex, startCol, excerpt } = error;
|
|
96
98
|
return { ...error, startIndex: startIndex - 1, startCol: startCol - 1, excerpt: `|${excerpt}` };
|
|
97
99
|
}));
|
|
98
100
|
}
|
|
@@ -101,7 +103,8 @@ class ArgToken extends Token {
|
|
|
101
103
|
/** @override */
|
|
102
104
|
cloneNode() {
|
|
103
105
|
const [name, ...cloned] = this.cloneChildNodes();
|
|
104
|
-
return
|
|
106
|
+
return index_1.default.run(() => {
|
|
107
|
+
// @ts-expect-error abstract class
|
|
105
108
|
const token = new ArgToken([''], this.getAttribute('config'));
|
|
106
109
|
token.firstChild.safeReplaceWith(name);
|
|
107
110
|
token.append(...cloned);
|
|
@@ -121,7 +124,7 @@ class ArgToken extends Token {
|
|
|
121
124
|
}
|
|
122
125
|
/** 移除无效部分 */
|
|
123
126
|
removeRedundant() {
|
|
124
|
-
|
|
127
|
+
index_1.default.run(() => {
|
|
125
128
|
for (let i = this.length - 1; i > 1; i--) {
|
|
126
129
|
super.removeAt(i);
|
|
127
130
|
}
|
|
@@ -164,13 +167,13 @@ class ArgToken extends Token {
|
|
|
164
167
|
* @throws `SyntaxError` 非法的参数名
|
|
165
168
|
*/
|
|
166
169
|
setName(name) {
|
|
167
|
-
const root =
|
|
168
|
-
if (length
|
|
169
|
-
|
|
170
|
+
const root = index_1.default.parse(`{{{${name}}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: arg } = root;
|
|
171
|
+
if (length === 1 && arg instanceof ArgToken && arg.length === 1) {
|
|
172
|
+
const { firstChild } = arg;
|
|
173
|
+
arg.destroy();
|
|
174
|
+
this.firstChild.safeReplaceWith(firstChild);
|
|
170
175
|
}
|
|
171
|
-
|
|
172
|
-
arg.destroy();
|
|
173
|
-
this.firstChild.safeReplaceWith(firstChild);
|
|
176
|
+
throw new SyntaxError(`非法的参数名称:${(0, string_1.noWrap)(name)}`);
|
|
174
177
|
}
|
|
175
178
|
/**
|
|
176
179
|
* 设置预设值
|
|
@@ -178,8 +181,8 @@ class ArgToken extends Token {
|
|
|
178
181
|
* @throws `SyntaxError` 非法的参数预设值
|
|
179
182
|
*/
|
|
180
183
|
setDefault(value) {
|
|
181
|
-
const root =
|
|
182
|
-
if (length !== 1 || arg
|
|
184
|
+
const root = index_1.default.parse(`{{{|${value}}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: arg } = root;
|
|
185
|
+
if (length !== 1 || !(arg instanceof ArgToken) || arg.length !== 2) {
|
|
183
186
|
throw new SyntaxError(`非法的参数预设值:${(0, string_1.noWrap)(value)}`);
|
|
184
187
|
}
|
|
185
188
|
const { childNodes: [, oldDefault] } = this, { lastChild } = arg;
|
|
@@ -192,5 +195,5 @@ class ArgToken extends Token {
|
|
|
192
195
|
}
|
|
193
196
|
}
|
|
194
197
|
}
|
|
195
|
-
|
|
196
|
-
|
|
198
|
+
exports.ArgToken = ArgToken;
|
|
199
|
+
index_1.default.classes['ArgToken'] = __filename;
|
package/dist/src/atom.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import Token = require('.');
|
|
1
|
+
import { Token } from '.';
|
|
3
2
|
declare type AtomTypes = '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' | 'converter-rule-noconvert' | 'invoke-function' | 'invoke-module' | 'template-name' | 'link-target' | 'param-line';
|
|
4
3
|
/** 不会被继续解析的plain Token */
|
|
5
|
-
declare class AtomToken extends Token {
|
|
4
|
+
export declare class AtomToken extends Token {
|
|
6
5
|
type: AtomTypes;
|
|
7
6
|
/** @browser */
|
|
8
|
-
constructor(wikitext: string | undefined, type: AtomTypes, config?:
|
|
7
|
+
constructor(wikitext: string | undefined, type: AtomTypes, config?: import("../index").Config, accum?: Token[], acceptable?: Acceptable);
|
|
9
8
|
/** @override */
|
|
10
9
|
cloneNode(): this;
|
|
11
10
|
}
|
|
12
|
-
export
|
|
11
|
+
export {};
|
package/dist/src/atom.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AtomToken = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
const _1 = require(".");
|
|
4
6
|
/** 不会被继续解析的plain Token */
|
|
5
|
-
class AtomToken extends Token {
|
|
7
|
+
class AtomToken extends _1.Token {
|
|
6
8
|
/** @browser */
|
|
7
|
-
constructor(wikitext, type, config =
|
|
9
|
+
constructor(wikitext, type, config = index_1.default.getConfig(), accum = [], acceptable) {
|
|
8
10
|
super(wikitext, config, true, accum, acceptable);
|
|
9
11
|
this.type = type;
|
|
10
12
|
}
|
|
11
13
|
/** @override */
|
|
12
14
|
cloneNode() {
|
|
13
15
|
const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAttribute('acceptable');
|
|
14
|
-
return
|
|
16
|
+
return index_1.default.run(() => {
|
|
15
17
|
const token = new AtomToken(undefined, this.type, config, [], acceptable);
|
|
16
18
|
token.append(...cloned);
|
|
17
19
|
return token;
|
|
18
20
|
});
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
exports.AtomToken = AtomToken;
|
|
24
|
+
index_1.default.classes['AtomToken'] = __filename;
|
package/dist/src/attribute.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import type {
|
|
1
|
+
import { Token } from '.';
|
|
2
|
+
import { AtomToken } from './atom';
|
|
3
|
+
import type { LintError } from '../index';
|
|
4
|
+
import type { AttributesToken } from '../internal';
|
|
5
5
|
declare type AttributeTypes = 'ext-attr' | 'html-attr' | 'table-attr';
|
|
6
6
|
declare const AttributeToken_base: ((abstract new (...args: any[]) => {
|
|
7
7
|
removeAt(): never;
|
|
8
|
-
insertAt(token: string, i?: number | undefined): import("../
|
|
9
|
-
insertAt<T extends import("../
|
|
8
|
+
insertAt(token: string, i?: number | undefined): import("../index").AstText;
|
|
9
|
+
insertAt<T extends import("../index").AstNodes>(token: T, i?: number | undefined): T;
|
|
10
10
|
length: number;
|
|
11
11
|
toString(selector?: string | undefined, separator?: string | undefined): string;
|
|
12
12
|
text(separator?: string | undefined): string;
|
|
@@ -17,7 +17,7 @@ declare const AttributeToken_base: ((abstract new (...args: any[]) => {
|
|
|
17
17
|
* 扩展和HTML标签属性
|
|
18
18
|
* @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
|
|
19
19
|
*/
|
|
20
|
-
declare abstract class AttributeToken extends AttributeToken_base {
|
|
20
|
+
export declare abstract class AttributeToken extends AttributeToken_base {
|
|
21
21
|
#private;
|
|
22
22
|
type: AttributeTypes;
|
|
23
23
|
name: string;
|
|
@@ -26,8 +26,8 @@ declare abstract class AttributeToken extends AttributeToken_base {
|
|
|
26
26
|
abstract get firstElementChild(): AtomToken;
|
|
27
27
|
abstract get lastChild(): Token;
|
|
28
28
|
abstract get lastElementChild(): Token;
|
|
29
|
-
abstract get parentNode():
|
|
30
|
-
abstract get parentElement():
|
|
29
|
+
abstract get parentNode(): AttributesToken | undefined;
|
|
30
|
+
abstract get parentElement(): AttributesToken | undefined;
|
|
31
31
|
abstract get nextSibling(): AtomToken | this | undefined;
|
|
32
32
|
abstract get nextElementSibling(): AtomToken | this | undefined;
|
|
33
33
|
abstract get previousSibling(): AtomToken | this | undefined;
|
|
@@ -57,7 +57,7 @@ declare abstract class AttributeToken extends AttributeToken_base {
|
|
|
57
57
|
* @param value 属性值
|
|
58
58
|
* @param quotes 引号
|
|
59
59
|
*/
|
|
60
|
-
constructor(type: AttributeTypes, tag: string, key: string, equal?: string, value?: string, quotes?: [string?, string?], config?:
|
|
60
|
+
constructor(type: AttributeTypes, tag: string, key: string, equal?: string, value?: string, quotes?: [string?, string?], config?: import("../index").Config, accum?: Token[]);
|
|
61
61
|
/**
|
|
62
62
|
* @override
|
|
63
63
|
* @browser
|
|
@@ -77,7 +77,7 @@ declare abstract class AttributeToken extends AttributeToken_base {
|
|
|
77
77
|
* @override
|
|
78
78
|
* @browser
|
|
79
79
|
*/
|
|
80
|
-
lint(start?: number):
|
|
80
|
+
lint(start?: number): LintError[];
|
|
81
81
|
/**
|
|
82
82
|
* 获取属性值
|
|
83
83
|
* @browser
|
|
@@ -99,8 +99,8 @@ declare abstract class AttributeToken extends AttributeToken_base {
|
|
|
99
99
|
* 修改属性名
|
|
100
100
|
* @param key 新属性名
|
|
101
101
|
* @throws `Error` title属性不能更名
|
|
102
|
-
* @throws `SyntaxError`
|
|
102
|
+
* @throws `SyntaxError` 非法的标签属性名
|
|
103
103
|
*/
|
|
104
104
|
rename(key: string): void;
|
|
105
105
|
}
|
|
106
|
-
export
|
|
106
|
+
export {};
|