wikiparser-node 0.7.0-m → 0.7.1-b
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/bundle/bundle.min.js +40 -0
- package/extensions/editor.css +60 -0
- package/extensions/editor.js +324 -0
- package/extensions/ui.css +119 -0
- package/package.json +11 -9
- package/config/default.json +0 -832
- package/config/llwiki.json +0 -595
- package/config/minimum.json +0 -142
- package/config/moegirl.json +0 -684
- package/config/zhwiki.json +0 -803
- package/index.js +0 -73
- package/lib/element.js +0 -137
- package/lib/node.js +0 -226
- package/lib/text.js +0 -124
- package/lib/title.js +0 -53
- package/mixin/hidden.js +0 -18
- package/parser/brackets.js +0 -119
- package/parser/commentAndExt.js +0 -61
- package/parser/converter.js +0 -45
- package/parser/externalLinks.js +0 -32
- package/parser/hrAndDoubleUnderscore.js +0 -37
- package/parser/html.js +0 -41
- package/parser/links.js +0 -93
- package/parser/list.js +0 -58
- package/parser/magicLinks.js +0 -40
- package/parser/quotes.js +0 -63
- package/parser/table.js +0 -113
- package/src/arg.js +0 -89
- package/src/atom/hidden.js +0 -11
- package/src/atom/index.js +0 -26
- package/src/attribute.js +0 -253
- package/src/attributes.js +0 -150
- package/src/charinsert.js +0 -41
- package/src/converter.js +0 -70
- package/src/converterFlags.js +0 -97
- package/src/converterRule.js +0 -75
- package/src/extLink.js +0 -60
- package/src/gallery.js +0 -101
- package/src/hasNowiki/index.js +0 -32
- package/src/hasNowiki/pre.js +0 -28
- package/src/heading.js +0 -83
- package/src/html.js +0 -133
- package/src/imageParameter.js +0 -106
- package/src/imagemap.js +0 -140
- package/src/imagemapLink.js +0 -29
- package/src/index.js +0 -389
- package/src/link/category.js +0 -13
- package/src/link/file.js +0 -125
- package/src/link/galleryImage.js +0 -62
- package/src/link/index.js +0 -115
- package/src/magicLink.js +0 -68
- package/src/nested/choose.js +0 -23
- package/src/nested/combobox.js +0 -22
- package/src/nested/index.js +0 -69
- package/src/nested/references.js +0 -22
- package/src/nowiki/comment.js +0 -47
- package/src/nowiki/dd.js +0 -13
- package/src/nowiki/doubleUnderscore.js +0 -26
- package/src/nowiki/hr.js +0 -22
- package/src/nowiki/index.js +0 -34
- package/src/nowiki/list.js +0 -13
- package/src/nowiki/noinclude.js +0 -14
- package/src/nowiki/quote.js +0 -55
- package/src/onlyinclude.js +0 -39
- package/src/paramTag/index.js +0 -66
- package/src/parameter.js +0 -97
- package/src/syntax.js +0 -23
- package/src/table/index.js +0 -46
- package/src/table/td.js +0 -119
- package/src/table/tr.js +0 -74
- package/src/tagPair/ext.js +0 -118
- package/src/tagPair/include.js +0 -36
- package/src/tagPair/index.js +0 -76
- package/src/transclude.js +0 -323
- package/util/base.js +0 -17
- package/util/diff.js +0 -76
- package/util/lint.js +0 -54
- package/util/string.js +0 -60
package/src/nowiki/quote.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {generateForSelf} = require('../../util/lint'),
|
|
4
|
-
Parser = require('../..'),
|
|
5
|
-
AstText = require('../../lib/text'),
|
|
6
|
-
NowikiToken = require('.');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* `<hr>`
|
|
10
|
-
* @classdesc `{childNodes: [AstText]}`
|
|
11
|
-
*/
|
|
12
|
-
class QuoteToken extends NowikiToken {
|
|
13
|
-
type = 'quote';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param {number} n 字符串长度
|
|
17
|
-
* @param {accum} accum
|
|
18
|
-
*/
|
|
19
|
-
constructor(n, config = Parser.getConfig(), accum = []) {
|
|
20
|
-
super("'".repeat(n), config, accum);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @override
|
|
25
|
-
* @this {AstText}
|
|
26
|
-
* @param {number} start 起始位置
|
|
27
|
-
*/
|
|
28
|
-
lint(start = 0) {
|
|
29
|
-
const {previousSibling, nextSibling} = this,
|
|
30
|
-
message = `孤立的"'"`,
|
|
31
|
-
/** @type {LintError[]} */ errors = [];
|
|
32
|
-
let refError, wikitext;
|
|
33
|
-
if (previousSibling?.type === 'text' && previousSibling.data.endsWith("'")) {
|
|
34
|
-
refError = generateForSelf(this, {start}, message);
|
|
35
|
-
wikitext = String(this.getRootNode());
|
|
36
|
-
const {startIndex: endIndex, startLine: endLine, startCol: endCol} = refError,
|
|
37
|
-
[, {length}] = previousSibling.data.match(/(?:^|[^'])('+)$/u),
|
|
38
|
-
startIndex = start - length,
|
|
39
|
-
excerpt = wikitext.slice(startIndex, startIndex + 50);
|
|
40
|
-
errors.push({...refError, startIndex, endIndex, startCol: endCol - length, endLine, endCol, excerpt});
|
|
41
|
-
}
|
|
42
|
-
if (nextSibling?.type === 'text' && nextSibling.data[0] === "'") {
|
|
43
|
-
refError ||= generateForSelf(this, {start}, message);
|
|
44
|
-
wikitext ||= String(this.getRootNode());
|
|
45
|
-
const {endIndex: startIndex, endLine: startLine, endCol: startCol} = refError,
|
|
46
|
-
[{length}] = nextSibling.data.match(/^'+/u),
|
|
47
|
-
endIndex = startIndex + length,
|
|
48
|
-
excerpt = wikitext.slice(Math.max(0, endIndex - 50), endIndex);
|
|
49
|
-
errors.push({...refError, startIndex, endIndex, startLine, startCol, endCol: startCol + length, excerpt});
|
|
50
|
-
}
|
|
51
|
-
return errors;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
module.exports = QuoteToken;
|
package/src/onlyinclude.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Parser = require('..'),
|
|
4
|
-
Token = require('.');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 嵌入时的`<onlyinclude>`
|
|
8
|
-
* @classdesc `{childNodes: ...AstText|Token}`
|
|
9
|
-
*/
|
|
10
|
-
class OnlyincludeToken extends Token {
|
|
11
|
-
type = 'onlyinclude';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @param {string} inner 标签内部wikitext
|
|
15
|
-
* @param {accum} accum
|
|
16
|
-
*/
|
|
17
|
-
constructor(inner, config = Parser.getConfig(), accum = []) {
|
|
18
|
-
super(inner, config, true, accum);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @override
|
|
23
|
-
*/
|
|
24
|
-
toString(selector) {
|
|
25
|
-
return `<onlyinclude>${super.toString()}</onlyinclude>`;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** @override */
|
|
29
|
-
getPadding() {
|
|
30
|
-
return 13;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** @override */
|
|
34
|
-
isPlain() {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
module.exports = OnlyincludeToken;
|
package/src/paramTag/index.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {generateForChild} = require('../../util/lint'),
|
|
4
|
-
Parser = require('../..'),
|
|
5
|
-
Token = require('..'),
|
|
6
|
-
AtomToken = require('../atom');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* `<inputbox>`
|
|
10
|
-
* @classdesc `{childNodes: ...AtomToken}`
|
|
11
|
-
*/
|
|
12
|
-
class ParamTagToken extends Token {
|
|
13
|
-
type = 'ext-inner';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param {string} wikitext wikitext
|
|
17
|
-
* @param {accum} accum
|
|
18
|
-
*/
|
|
19
|
-
constructor(wikitext, config = Parser.getConfig(), accum = []) {
|
|
20
|
-
super(undefined, config, true, accum, {
|
|
21
|
-
});
|
|
22
|
-
if (wikitext) {
|
|
23
|
-
const SingleLineAtomToken = AtomToken;
|
|
24
|
-
this.append(
|
|
25
|
-
...wikitext.split('\n').map(line => new SingleLineAtomToken(line, 'param-line', config, accum, {
|
|
26
|
-
})),
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @override
|
|
33
|
-
*/
|
|
34
|
-
toString(selector) {
|
|
35
|
-
return super.toString(selector, '\n');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** @override */
|
|
39
|
-
text() {
|
|
40
|
-
return super.text('\n');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** @override */
|
|
44
|
-
getGaps() {
|
|
45
|
-
return 1;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @override
|
|
50
|
-
* @param {number} start 起始位置
|
|
51
|
-
*/
|
|
52
|
-
lint(start = 0) {
|
|
53
|
-
let /** @type {{top: number, left: number}} */ rect;
|
|
54
|
-
return this.childNodes.filter(child => {
|
|
55
|
-
const {childNodes} = child,
|
|
56
|
-
i = childNodes.findIndex(({type}) => type !== 'text'),
|
|
57
|
-
str = (i >= 0 ? childNodes.slice(0, i).map(String).join('') : String(child)).trim();
|
|
58
|
-
return str && !(i >= 0 ? /^[a-z]+\s*(?:=|$)/iu : /^[a-z]+\s*=/iu).test(str);
|
|
59
|
-
}).map(child => {
|
|
60
|
-
rect ||= {start, ...this.getRootNode().posFromIndex(start)};
|
|
61
|
-
return generateForChild(child, rect, `${this.name}的无效参数`);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
module.exports = ParamTagToken;
|
package/src/parameter.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {extUrlChar, extUrlCharFirst} = require('../util/string'),
|
|
4
|
-
{generateForChild} = require('../util/lint'),
|
|
5
|
-
Parser = require('..'),
|
|
6
|
-
Token = require('.');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 模板或魔术字参数
|
|
10
|
-
* @classdesc `{childNodes: [Token, Token]}`
|
|
11
|
-
*/
|
|
12
|
-
class ParameterToken extends Token {
|
|
13
|
-
type = 'parameter';
|
|
14
|
-
|
|
15
|
-
/** 是否是匿名参数 */
|
|
16
|
-
get anon() {
|
|
17
|
-
return this.firstChild.length === 0;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @param {string|number} key 参数名
|
|
22
|
-
* @param {string} value 参数值
|
|
23
|
-
* @param {accum} accum
|
|
24
|
-
*/
|
|
25
|
-
constructor(key, value, config = Parser.getConfig(), accum = []) {
|
|
26
|
-
super(undefined, config, true, accum);
|
|
27
|
-
const keyToken = new Token(typeof key === 'number' ? undefined : key, config, true, accum, {
|
|
28
|
-
}),
|
|
29
|
-
token = new Token(value, config, true, accum);
|
|
30
|
-
keyToken.type = 'parameter-key';
|
|
31
|
-
token.type = 'parameter-value';
|
|
32
|
-
this.append(keyToken, token.setAttribute('stage', 2));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** @override */
|
|
36
|
-
afterBuild() {
|
|
37
|
-
if (!this.anon) {
|
|
38
|
-
const TranscludeToken = require('./transclude');
|
|
39
|
-
const name = String(this.firstChild).replace(/<!--.*?-->/gu, '')
|
|
40
|
-
.replace(/^[ \t\n\0\v]+|([^ \t\n\0\v])[ \t\n\0\v]+$/gu, '$1'),
|
|
41
|
-
{parentNode} = this;
|
|
42
|
-
this.setAttribute('name', name);
|
|
43
|
-
if (parentNode instanceof TranscludeToken) {
|
|
44
|
-
parentNode.getArgs(name, false, false).add(this);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @override
|
|
51
|
-
* @returns {string}
|
|
52
|
-
*/
|
|
53
|
-
toString(selector) {
|
|
54
|
-
return this.anon
|
|
55
|
-
? this.lastChild.toString(selector)
|
|
56
|
-
: super.toString(selector, '=');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @override
|
|
61
|
-
* @returns {string}
|
|
62
|
-
*/
|
|
63
|
-
text() {
|
|
64
|
-
return this.anon ? this.lastChild.text() : super.text('=');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** @override */
|
|
68
|
-
getGaps() {
|
|
69
|
-
return this.anon ? 0 : 1;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @override
|
|
74
|
-
* @param {number} start 起始位置
|
|
75
|
-
*/
|
|
76
|
-
lint(start = 0) {
|
|
77
|
-
const errors = super.lint(start),
|
|
78
|
-
{firstChild, lastChild} = this,
|
|
79
|
-
link = new RegExp(`https?://${extUrlCharFirst}${extUrlChar}$`, 'iu')
|
|
80
|
-
.exec(String(firstChild).replace(/<!--.*?-->/gu, ''))?.[0];
|
|
81
|
-
if (link && new URL(link).search) {
|
|
82
|
-
const e = generateForChild(firstChild, {start}, '匿名参数中未转义的查询参数');
|
|
83
|
-
errors.push({
|
|
84
|
-
...e,
|
|
85
|
-
startIndex: e.endIndex,
|
|
86
|
-
endIndex: e.endIndex + 1,
|
|
87
|
-
startLine: e.endLine,
|
|
88
|
-
startCol: e.endCol,
|
|
89
|
-
endCol: e.endCol + 1,
|
|
90
|
-
excerpt: `${String(firstChild).slice(-25)}=${String(lastChild).slice(0, 25)}`,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
return errors;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
module.exports = ParameterToken;
|
package/src/syntax.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Parser = require('..'),
|
|
4
|
-
Token = require('.');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 满足特定语法格式的plain Token
|
|
8
|
-
* @classdesc `{childNodes: ...AstText|Token}`
|
|
9
|
-
*/
|
|
10
|
-
class SyntaxToken extends Token {
|
|
11
|
-
/**
|
|
12
|
-
* @param {string} wikitext 语法wikitext
|
|
13
|
-
* @param {RegExp} pattern 语法正则
|
|
14
|
-
* @param {string} type Token.type
|
|
15
|
-
* @param {accum} accum
|
|
16
|
-
*/
|
|
17
|
-
constructor(wikitext, pattern, type = 'plain', config = Parser.getConfig(), accum = [], acceptable = undefined) {
|
|
18
|
-
super(wikitext, config, true, accum, acceptable);
|
|
19
|
-
this.type = type;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = SyntaxToken;
|
package/src/table/index.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {generateForChild} = require('../../util/lint'),
|
|
4
|
-
TrToken = require('./tr'),
|
|
5
|
-
SyntaxToken = require('../syntax');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 表格
|
|
9
|
-
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken, ...TrToken, ?SyntaxToken]}`
|
|
10
|
-
*/
|
|
11
|
-
class TableToken extends TrToken {
|
|
12
|
-
type = 'table';
|
|
13
|
-
|
|
14
|
-
/** 表格是否闭合 */
|
|
15
|
-
get closed() {
|
|
16
|
-
return this.lastChild.type === 'table-syntax';
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @override
|
|
21
|
-
* @param {number} start 起始位置
|
|
22
|
-
*/
|
|
23
|
-
lint(start = 0) {
|
|
24
|
-
const errors = super.lint(start);
|
|
25
|
-
if (!this.closed) {
|
|
26
|
-
const {firstChild, lastChild: tr} = this,
|
|
27
|
-
{lastChild: td} = tr,
|
|
28
|
-
error = generateForChild(firstChild, {start}, '未闭合的表格');
|
|
29
|
-
errors.push({...error, excerpt: String(td?.type === 'td' ? td : tr).slice(0, 50)});
|
|
30
|
-
}
|
|
31
|
-
return errors;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 闭合表格语法
|
|
36
|
-
* @complexity `n`
|
|
37
|
-
* @param {string} syntax 表格结尾语法
|
|
38
|
-
*/
|
|
39
|
-
close(syntax = '\n|}', halfParsed = false) {
|
|
40
|
-
const config = this.getAttribute('config'),
|
|
41
|
-
accum = this.getAttribute('accum');
|
|
42
|
-
super.insertAt(new SyntaxToken(syntax, undefined, 'table-syntax', config, accum));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
module.exports = TableToken;
|
package/src/table/td.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {generateForChild} = require('../../util/lint'),
|
|
4
|
-
Parser = require('../..'),
|
|
5
|
-
Token = require('..'),
|
|
6
|
-
TrToken = require('./tr');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* `<td>`、`<th>`和`<caption>`
|
|
10
|
-
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, Token]}`
|
|
11
|
-
*/
|
|
12
|
-
class TdToken extends TrToken {
|
|
13
|
-
type = 'td';
|
|
14
|
-
#innerSyntax = '';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 单元格类型
|
|
18
|
-
* @complexity `n`
|
|
19
|
-
*/
|
|
20
|
-
get subtype() {
|
|
21
|
-
return this.getSyntax().subtype;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 获取单元格语法信息
|
|
26
|
-
* @returns {{subtype: 'td'|'th'|'caption'}}
|
|
27
|
-
* @complexity `n`
|
|
28
|
-
*/
|
|
29
|
-
getSyntax() {
|
|
30
|
-
const syntax = this.firstChild.text(),
|
|
31
|
-
char = syntax.at(-1);
|
|
32
|
-
let subtype = 'td';
|
|
33
|
-
if (char === '!') {
|
|
34
|
-
subtype = 'th';
|
|
35
|
-
} else if (char === '+') {
|
|
36
|
-
subtype = 'caption';
|
|
37
|
-
}
|
|
38
|
-
return {subtype};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @param {string} syntax 单元格语法
|
|
43
|
-
* @param {string} inner 内部wikitext
|
|
44
|
-
* @param {accum} accum
|
|
45
|
-
*/
|
|
46
|
-
constructor(syntax, inner, config = Parser.getConfig(), accum = []) {
|
|
47
|
-
let innerSyntax = inner?.match(/\||\0\d+!\x7F/u),
|
|
48
|
-
attr = innerSyntax ? inner.slice(0, innerSyntax.index) : '';
|
|
49
|
-
if (/\[\[|-\{/u.test(attr)) {
|
|
50
|
-
innerSyntax = undefined;
|
|
51
|
-
attr = '';
|
|
52
|
-
}
|
|
53
|
-
super(syntax, attr, config, accum);
|
|
54
|
-
if (innerSyntax) {
|
|
55
|
-
[this.#innerSyntax] = innerSyntax;
|
|
56
|
-
}
|
|
57
|
-
// eslint-disable-next-line no-unsafe-optional-chaining
|
|
58
|
-
const innerToken = new Token(inner?.slice(innerSyntax?.index + this.#innerSyntax.length), config, true, accum);
|
|
59
|
-
innerToken.type = 'td-inner';
|
|
60
|
-
this.insertAt(innerToken.setAttribute('stage', 4));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** @override */
|
|
64
|
-
afterBuild() {
|
|
65
|
-
if (this.#innerSyntax.includes('\0')) {
|
|
66
|
-
this.#innerSyntax = this.getAttribute('buildFromStr')(this.#innerSyntax, 'string');
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @override
|
|
72
|
-
* @returns {string}
|
|
73
|
-
* @complexity `n`
|
|
74
|
-
*/
|
|
75
|
-
toString(selector) {
|
|
76
|
-
const {childNodes: [syntax, attr, inner]} = this;
|
|
77
|
-
return `${syntax.toString()}${attr.toString()}${this.#innerSyntax}${inner.toString()}`;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* @override
|
|
82
|
-
* @returns {string}
|
|
83
|
-
* @complexity `n`
|
|
84
|
-
*/
|
|
85
|
-
text() {
|
|
86
|
-
const {childNodes: [syntax, attr, inner]} = this;
|
|
87
|
-
return `${syntax.text()}${attr.text()}${this.#innerSyntax}${inner.text()}`;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* @override
|
|
92
|
-
* @param {number} i 子节点位置
|
|
93
|
-
*/
|
|
94
|
-
getGaps(i = 0) {
|
|
95
|
-
i = i < 0 ? i + this.length : i;
|
|
96
|
-
if (i === 1) {
|
|
97
|
-
return this.#innerSyntax.length;
|
|
98
|
-
}
|
|
99
|
-
return 0;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* @override
|
|
104
|
-
* @param {number} start 起始位置
|
|
105
|
-
*/
|
|
106
|
-
lint(start = 0) {
|
|
107
|
-
const errors = super.lint(start),
|
|
108
|
-
{lastChild} = this;
|
|
109
|
-
start += this.getRelativeIndex(-1);
|
|
110
|
-
for (const child of lastChild.childNodes) {
|
|
111
|
-
if (child.type === 'text' && child.data.includes('|')) {
|
|
112
|
-
errors.push(generateForChild(child, {start}, '表格单元格中多余的"|"', 'warning'));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return errors;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
module.exports = TdToken;
|
package/src/table/tr.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {generateForChild} = require('../../util/lint'),
|
|
4
|
-
Parser = require('../..'),
|
|
5
|
-
Token = require('..'),
|
|
6
|
-
SyntaxToken = require('../syntax'),
|
|
7
|
-
AttributesToken = require('../attributes');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 表格行,含开头的换行,不含结尾的换行
|
|
11
|
-
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken]}`
|
|
12
|
-
*/
|
|
13
|
-
class TrToken extends Token {
|
|
14
|
-
type = 'tr';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @param {string} syntax 表格语法
|
|
18
|
-
* @param {string} attr 表格属性
|
|
19
|
-
* @param {accum} accum
|
|
20
|
-
* @param {RegExp} pattern 表格语法正则
|
|
21
|
-
*/
|
|
22
|
-
constructor(syntax, attr = '', config = Parser.getConfig(), accum = [], pattern = undefined) {
|
|
23
|
-
super(undefined, config, true, accum, {
|
|
24
|
-
});
|
|
25
|
-
this.append(
|
|
26
|
-
new SyntaxToken(syntax, pattern, 'table-syntax', config, accum, {
|
|
27
|
-
}),
|
|
28
|
-
new AttributesToken(attr, 'table-attrs', this.type, config, accum),
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @override
|
|
34
|
-
* @param {number} start 起始位置
|
|
35
|
-
*/
|
|
36
|
-
lint(start = 0) {
|
|
37
|
-
const TranscludeToken = require('../transclude'),
|
|
38
|
-
ArgToken = require('../arg');
|
|
39
|
-
const errors = super.lint(start),
|
|
40
|
-
inter = this.childNodes.find(({type}) => type === 'table-inter');
|
|
41
|
-
if (!inter) {
|
|
42
|
-
return errors;
|
|
43
|
-
}
|
|
44
|
-
const /** @type {TranscludeToken & ArgToken} */ first = inter.childNodes.find(child => child.text().trim()),
|
|
45
|
-
tdPattern = /^\s*(?:!|\{\{\s*![!-]?\s*\}\})/u;
|
|
46
|
-
if (!first || first.type === 'arg' && tdPattern.test(first.default || '')) {
|
|
47
|
-
return errors;
|
|
48
|
-
} else if (first.type === 'magic-word') {
|
|
49
|
-
try {
|
|
50
|
-
const possibleValues = first.getPossibleValues();
|
|
51
|
-
if (possibleValues.every(token => tdPattern.test(token.text()))) {
|
|
52
|
-
return errors;
|
|
53
|
-
}
|
|
54
|
-
} catch {}
|
|
55
|
-
}
|
|
56
|
-
const error = generateForChild(inter, {start}, '将被移出表格的内容');
|
|
57
|
-
errors.push({
|
|
58
|
-
...error,
|
|
59
|
-
startIndex: error.startIndex + 1,
|
|
60
|
-
startLine: error.startLine + 1,
|
|
61
|
-
startCol: 0,
|
|
62
|
-
excerpt: error.excerpt.slice(1),
|
|
63
|
-
});
|
|
64
|
-
return errors;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** @override */
|
|
68
|
-
text() {
|
|
69
|
-
const str = super.text();
|
|
70
|
-
return this.type === 'tr' && !str.trim().includes('\n') ? '' : str;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
module.exports = TrToken;
|
package/src/tagPair/ext.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {generateForSelf} = require('../../util/lint'),
|
|
4
|
-
Parser = require('../..'),
|
|
5
|
-
Token = require('..'),
|
|
6
|
-
TagPairToken = require('.'),
|
|
7
|
-
AttributesToken = require('../attributes');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 扩展标签
|
|
11
|
-
* @classdesc `{childNodes: [AttributesToken, NowikiToken|Token]}`
|
|
12
|
-
*/
|
|
13
|
-
class ExtToken extends TagPairToken {
|
|
14
|
-
type = 'ext';
|
|
15
|
-
closed = true;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @param {string} name 标签名
|
|
19
|
-
* @param {string} attr 标签属性
|
|
20
|
-
* @param {string} inner 内部wikitext
|
|
21
|
-
* @param {string|undefined} closed 是否封闭
|
|
22
|
-
* @param {accum} accum
|
|
23
|
-
*/
|
|
24
|
-
constructor(name, attr = '', inner = '', closed = undefined, config = Parser.getConfig(), accum = []) {
|
|
25
|
-
attr = !attr || /^\s/u.test(attr) ? attr : ` ${attr}`;
|
|
26
|
-
const lcName = name.toLowerCase(),
|
|
27
|
-
attrToken = new AttributesToken(attr, 'ext-attrs', lcName, config, accum),
|
|
28
|
-
newConfig = structuredClone(config),
|
|
29
|
-
ext = new Set(newConfig.ext);
|
|
30
|
-
let /** @type {Token} */ innerToken;
|
|
31
|
-
ext.delete(lcName);
|
|
32
|
-
newConfig.ext = [...ext];
|
|
33
|
-
switch (lcName) {
|
|
34
|
-
case 'tab':
|
|
35
|
-
ext.delete('tabs');
|
|
36
|
-
newConfig.ext = [...ext];
|
|
37
|
-
// fall through
|
|
38
|
-
case 'indicator':
|
|
39
|
-
case 'poem':
|
|
40
|
-
case 'ref':
|
|
41
|
-
case 'option':
|
|
42
|
-
case 'combooption':
|
|
43
|
-
case 'tabs':
|
|
44
|
-
case 'poll':
|
|
45
|
-
case 'seo':
|
|
46
|
-
case 'inputbox':
|
|
47
|
-
innerToken = new Token(inner, newConfig, true, accum);
|
|
48
|
-
break;
|
|
49
|
-
case 'gallery': {
|
|
50
|
-
const GalleryToken = require('../gallery');
|
|
51
|
-
innerToken = new GalleryToken(inner, newConfig, accum);
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
case 'pre': {
|
|
55
|
-
const PreToken = require('../hasNowiki/pre');
|
|
56
|
-
innerToken = new PreToken(inner, newConfig, accum);
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
case 'charinsert': {
|
|
60
|
-
const CharinsertToken = require('../charinsert');
|
|
61
|
-
innerToken = new CharinsertToken(inner, newConfig, accum);
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
case 'references':
|
|
65
|
-
case 'choose':
|
|
66
|
-
case 'combobox': {
|
|
67
|
-
const NestedToken = require('../nested'),
|
|
68
|
-
/** @type {typeof NestedToken} */ NestedExtToken = require(`../nested/${lcName}`);
|
|
69
|
-
innerToken = new NestedExtToken(inner, newConfig, accum);
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
case 'imagemap': {
|
|
73
|
-
const ImagemapToken = require('../imagemap');
|
|
74
|
-
innerToken = new ImagemapToken(inner, config, accum);
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
case 'dynamicpagelist': {
|
|
78
|
-
const ParamTagToken = require('../paramTag');
|
|
79
|
-
innerToken = new ParamTagToken(inner, newConfig, accum);
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/*
|
|
84
|
-
* 更多定制扩展的代码示例:
|
|
85
|
-
* ```
|
|
86
|
-
* case 'extensionName': {
|
|
87
|
-
* const ExtensionToken = require('../extension');
|
|
88
|
-
* innerToken = new ExtensionToken(inner, newConfig, accum);
|
|
89
|
-
* break;
|
|
90
|
-
* }
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
default: {
|
|
94
|
-
const NowikiToken = require('../nowiki');
|
|
95
|
-
innerToken = new NowikiToken(inner, config);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
innerToken.setAttribute('name', lcName).type = 'ext-inner';
|
|
99
|
-
super(name, attrToken, innerToken, closed, config, accum);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* @override
|
|
104
|
-
* @param {number} start 起始位置
|
|
105
|
-
*/
|
|
106
|
-
lint(start = 0) {
|
|
107
|
-
const errors = super.lint(start);
|
|
108
|
-
if (this.name !== 'nowiki' && this.closest('html-attrs, table-attrs')) {
|
|
109
|
-
const root = this.getRootNode(),
|
|
110
|
-
excerpt = String(root).slice(Math.max(0, start - 25), start + 25),
|
|
111
|
-
rect = {start, ...root.posFromIndex(start)};
|
|
112
|
-
errors.push({...generateForSelf(this, rect, 'HTML标签属性中的扩展标签'), excerpt});
|
|
113
|
-
}
|
|
114
|
-
return errors;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
module.exports = ExtToken;
|
package/src/tagPair/include.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const hidden = require('../../mixin/hidden'),
|
|
4
|
-
{generateForSelf} = require('../../util/lint'),
|
|
5
|
-
Parser = require('../..'),
|
|
6
|
-
TagPairToken = require('.');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* `<includeonly>`或`<noinclude>`
|
|
10
|
-
* @classdesc `{childNodes: [AstText, AstText]}`
|
|
11
|
-
*/
|
|
12
|
-
class IncludeToken extends hidden(TagPairToken) {
|
|
13
|
-
type = 'include';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param {string} name 标签名
|
|
17
|
-
* @param {string} attr 标签属性
|
|
18
|
-
* @param {string|undefined} inner 内部wikitext
|
|
19
|
-
* @param {string|undefined} closed 是否封闭
|
|
20
|
-
* @param {accum} accum
|
|
21
|
-
*/
|
|
22
|
-
constructor(name, attr = '', inner = undefined, closed = undefined, config = Parser.getConfig(), accum = []) {
|
|
23
|
-
super(name, attr, inner ?? '', inner === undefined ? closed : closed ?? '', config, accum);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @override
|
|
28
|
-
* @param {number} start 起始位置
|
|
29
|
-
* @returns {LintError[]}
|
|
30
|
-
*/
|
|
31
|
-
lint(start = 0) {
|
|
32
|
-
return this.closed ? [] : [generateForSelf(this, {start}, '未闭合的标签')];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = IncludeToken;
|