wikiparser-node 0.11.0 → 1.0.0-beta.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/dist/index.d.ts +59 -113
- package/dist/index.js +307 -0
- package/dist/lib/element.d.ts +122 -108
- package/dist/lib/element.js +656 -0
- package/dist/lib/node.d.ts +115 -221
- package/dist/lib/node.js +473 -0
- package/dist/lib/ranges.d.ts +27 -26
- package/dist/lib/ranges.js +130 -0
- package/dist/lib/text.d.ts +36 -28
- package/dist/lib/text.js +215 -0
- package/dist/lib/title.d.ts +25 -12
- package/dist/lib/title.js +100 -0
- package/dist/mixin/attributesParent.js +90 -0
- package/dist/mixin/fixed.js +29 -0
- package/dist/mixin/hidden.js +19 -0
- package/dist/mixin/singleLine.js +23 -0
- package/dist/mixin/sol.js +41 -0
- package/dist/parser/brackets.js +117 -0
- package/dist/parser/commentAndExt.js +48 -0
- package/dist/parser/converter.js +31 -0
- package/dist/parser/externalLinks.js +22 -0
- package/dist/parser/hrAndDoubleUnderscore.js +33 -0
- package/dist/parser/html.js +29 -0
- package/dist/parser/links.js +86 -0
- package/dist/parser/list.js +51 -0
- package/dist/parser/magicLinks.js +32 -0
- package/dist/parser/quotes.js +57 -0
- package/dist/parser/selector.js +158 -0
- package/dist/parser/table.js +108 -0
- package/dist/src/arg.d.ts +47 -23
- package/dist/src/arg.js +196 -0
- package/dist/src/atom.d.ts +12 -0
- package/dist/src/atom.js +22 -0
- package/dist/src/attribute.d.ts +74 -33
- package/dist/src/attribute.js +433 -0
- package/dist/src/attributes.d.ts +61 -55
- package/dist/src/attributes.js +371 -0
- package/dist/src/converter.d.ts +45 -71
- package/dist/src/converter.js +135 -0
- package/dist/src/converterFlags.d.ts +64 -39
- package/dist/src/converterFlags.js +235 -0
- package/dist/src/converterRule.d.ts +49 -27
- package/dist/src/converterRule.js +255 -0
- package/dist/src/extLink.d.ts +41 -38
- package/dist/src/extLink.js +154 -0
- package/dist/src/gallery.d.ts +59 -18
- package/dist/src/gallery.js +132 -0
- package/dist/src/heading.d.ts +60 -22
- package/dist/src/heading.js +135 -0
- package/dist/src/hidden.d.ts +20 -0
- package/dist/src/hidden.js +24 -0
- package/dist/src/html.d.ts +83 -29
- package/dist/src/html.js +242 -0
- package/dist/src/imageParameter.d.ts +59 -40
- package/dist/src/imageParameter.js +251 -0
- package/dist/src/imagemap.d.ts +65 -21
- package/dist/src/imagemap.js +164 -0
- package/dist/src/imagemapLink.d.ts +46 -14
- package/dist/src/imagemapLink.js +38 -0
- package/dist/src/index.d.ts +71 -105
- package/dist/src/index.js +826 -0
- package/dist/src/link/base.d.ts +71 -0
- package/dist/src/link/base.js +225 -0
- package/dist/src/link/category.d.ts +10 -11
- package/dist/src/link/category.js +26 -0
- package/dist/src/link/file.d.ts +61 -39
- package/dist/src/link/file.js +242 -0
- package/dist/src/link/galleryImage.d.ts +34 -12
- package/dist/src/link/galleryImage.js +98 -0
- package/dist/src/link/index.d.ts +25 -63
- package/dist/src/link/index.js +136 -0
- package/dist/src/magicLink.d.ts +22 -15
- package/dist/src/magicLink.js +126 -0
- package/dist/src/nested.d.ts +47 -0
- package/dist/src/nested.js +84 -0
- package/dist/src/nowiki/base.d.ts +39 -0
- package/dist/src/nowiki/base.js +29 -0
- package/dist/src/nowiki/comment.d.ts +31 -20
- package/dist/src/nowiki/comment.js +61 -0
- package/dist/src/nowiki/dd.d.ts +17 -11
- package/dist/src/nowiki/dd.js +50 -0
- package/dist/src/nowiki/doubleUnderscore.d.ts +28 -13
- package/dist/src/nowiki/doubleUnderscore.js +45 -0
- package/dist/src/nowiki/hr.d.ts +28 -10
- package/dist/src/nowiki/hr.js +33 -0
- package/dist/src/nowiki/index.d.ts +17 -23
- package/dist/src/nowiki/index.js +21 -0
- package/dist/src/nowiki/list.d.ts +15 -7
- package/dist/src/nowiki/list.js +11 -0
- package/dist/src/nowiki/noinclude.d.ts +20 -7
- package/dist/src/nowiki/noinclude.js +22 -0
- package/dist/src/nowiki/quote.d.ts +25 -10
- package/dist/src/nowiki/quote.js +55 -0
- package/dist/src/onlyinclude.d.ts +28 -12
- package/dist/src/onlyinclude.js +64 -0
- package/dist/src/paramTag/index.d.ts +40 -17
- package/dist/src/paramTag/index.js +76 -0
- package/dist/src/paramTag/inputbox.d.ts +8 -7
- package/dist/src/paramTag/inputbox.js +19 -0
- package/dist/src/parameter.d.ts +62 -41
- package/dist/src/parameter.js +201 -0
- package/dist/src/pre.d.ts +32 -0
- package/dist/src/pre.js +39 -0
- package/dist/src/syntax.d.ts +17 -14
- package/dist/src/syntax.js +65 -0
- package/dist/src/table/base.d.ts +55 -0
- package/dist/src/table/base.js +77 -0
- package/dist/src/table/index.d.ts +123 -156
- package/dist/src/table/index.js +811 -0
- package/dist/src/table/td.d.ts +90 -67
- package/dist/src/table/td.js +276 -0
- package/dist/src/table/tr.d.ts +30 -85
- package/dist/src/table/tr.js +48 -0
- package/dist/src/table/trBase.d.ts +72 -0
- package/dist/src/table/trBase.js +153 -0
- package/dist/src/tagPair/ext.d.ts +47 -11
- package/dist/src/tagPair/ext.js +127 -0
- package/dist/src/tagPair/include.d.ts +32 -13
- package/dist/src/tagPair/include.js +40 -0
- package/dist/src/tagPair/index.d.ts +44 -29
- package/dist/src/tagPair/index.js +111 -0
- package/dist/src/transclude.d.ts +88 -85
- package/dist/src/transclude.js +739 -0
- package/dist/util/base.js +26 -0
- package/dist/util/debug.js +52 -0
- package/dist/util/diff.js +69 -0
- package/dist/util/lint.js +38 -0
- package/dist/util/string.js +103 -0
- package/errors/README +1 -0
- package/i18n/zh-hans.json +1 -0
- package/i18n/zh-hant.json +1 -0
- package/package.json +11 -14
- package/printed/README +1 -0
- package/dist/mixin/attributeParent.d.ts +0 -9
- package/dist/mixin/fixedToken.d.ts +0 -8
- package/dist/mixin/hidden.d.ts +0 -8
- package/dist/mixin/singleLine.d.ts +0 -8
- package/dist/mixin/sol.d.ts +0 -8
- package/dist/parser/brackets.d.ts +0 -12
- package/dist/parser/commentAndExt.d.ts +0 -8
- package/dist/parser/converter.d.ts +0 -7
- package/dist/parser/externalLinks.d.ts +0 -7
- package/dist/parser/hrAndDoubleUnderscore.d.ts +0 -11
- package/dist/parser/html.d.ts +0 -7
- package/dist/parser/links.d.ts +0 -7
- package/dist/parser/list.d.ts +0 -7
- package/dist/parser/magicLinks.d.ts +0 -7
- package/dist/parser/quotes.d.ts +0 -7
- package/dist/parser/selector.d.ts +0 -12
- package/dist/parser/table.d.ts +0 -11
- package/dist/src/atom/hidden.d.ts +0 -5
- package/dist/src/atom/index.d.ts +0 -15
- package/dist/src/charinsert.d.ts +0 -32
- package/dist/src/hasNowiki/index.d.ts +0 -14
- package/dist/src/hasNowiki/pre.d.ts +0 -13
- package/dist/src/nested/choose.d.ts +0 -13
- package/dist/src/nested/combobox.d.ts +0 -13
- package/dist/src/nested/index.d.ts +0 -18
- package/dist/src/nested/references.d.ts +0 -13
- package/dist/tool/index.d.ts +0 -420
- package/dist/util/base.d.ts +0 -10
- package/dist/util/debug.d.ts +0 -20
- package/dist/util/diff.d.ts +0 -8
- package/dist/util/lint.d.ts +0 -28
- package/dist/util/string.d.ts +0 -55
- package/index.js +0 -333
- package/lib/element.js +0 -618
- package/lib/node.js +0 -730
- package/lib/ranges.js +0 -130
- package/lib/text.js +0 -265
- package/lib/title.js +0 -83
- package/mixin/attributeParent.js +0 -117
- package/mixin/fixedToken.js +0 -40
- package/mixin/hidden.js +0 -21
- package/mixin/singleLine.js +0 -31
- package/mixin/sol.js +0 -54
- package/parser/brackets.js +0 -128
- package/parser/commentAndExt.js +0 -62
- package/parser/converter.js +0 -46
- package/parser/externalLinks.js +0 -33
- package/parser/hrAndDoubleUnderscore.js +0 -49
- package/parser/html.js +0 -42
- package/parser/links.js +0 -94
- package/parser/list.js +0 -59
- package/parser/magicLinks.js +0 -41
- package/parser/quotes.js +0 -64
- package/parser/selector.js +0 -180
- package/parser/table.js +0 -114
- package/src/arg.js +0 -207
- package/src/atom/hidden.js +0 -13
- package/src/atom/index.js +0 -43
- package/src/attribute.js +0 -472
- package/src/attributes.js +0 -453
- package/src/charinsert.js +0 -97
- package/src/converter.js +0 -176
- package/src/converterFlags.js +0 -284
- package/src/converterRule.js +0 -256
- package/src/extLink.js +0 -180
- package/src/gallery.js +0 -149
- package/src/hasNowiki/index.js +0 -44
- package/src/hasNowiki/pre.js +0 -40
- package/src/heading.js +0 -134
- package/src/html.js +0 -254
- package/src/imageParameter.js +0 -303
- package/src/imagemap.js +0 -199
- package/src/imagemapLink.js +0 -41
- package/src/index.js +0 -938
- package/src/link/category.js +0 -44
- package/src/link/file.js +0 -287
- package/src/link/galleryImage.js +0 -120
- package/src/link/index.js +0 -388
- package/src/magicLink.js +0 -151
- package/src/nested/choose.js +0 -24
- package/src/nested/combobox.js +0 -23
- package/src/nested/index.js +0 -96
- package/src/nested/references.js +0 -23
- package/src/nowiki/comment.js +0 -71
- package/src/nowiki/dd.js +0 -59
- package/src/nowiki/doubleUnderscore.js +0 -56
- package/src/nowiki/hr.js +0 -41
- package/src/nowiki/index.js +0 -56
- package/src/nowiki/list.js +0 -16
- package/src/nowiki/noinclude.js +0 -28
- package/src/nowiki/quote.js +0 -69
- package/src/onlyinclude.js +0 -64
- package/src/paramTag/index.js +0 -89
- package/src/paramTag/inputbox.js +0 -35
- package/src/parameter.js +0 -239
- package/src/syntax.js +0 -91
- package/src/table/index.js +0 -985
- package/src/table/td.js +0 -343
- package/src/table/tr.js +0 -319
- package/src/tagPair/ext.js +0 -146
- package/src/tagPair/include.js +0 -50
- package/src/tagPair/index.js +0 -131
- package/src/transclude.js +0 -843
- package/tool/index.js +0 -1209
- package/typings/api.d.ts +0 -9
- package/typings/array.d.ts +0 -29
- package/typings/event.d.ts +0 -22
- package/typings/index.d.ts +0 -118
- package/typings/node.d.ts +0 -35
- package/typings/parser.d.ts +0 -12
- package/typings/table.d.ts +0 -10
- package/typings/token.d.ts +0 -31
- package/typings/tool.d.ts +0 -6
- package/util/base.js +0 -17
- package/util/debug.js +0 -73
- package/util/diff.js +0 -76
- package/util/lint.js +0 -57
- package/util/string.js +0 -126
package/src/nowiki/comment.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const hidden = require('../../mixin/hidden'),
|
|
4
|
-
{generateForSelf} = require('../../util/lint'),
|
|
5
|
-
Parser = require('../..'),
|
|
6
|
-
NowikiToken = require('.');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* HTML注释,不可见
|
|
10
|
-
* @classdesc `{childNodes: [AstText]}`
|
|
11
|
-
*/
|
|
12
|
-
class CommentToken extends hidden(NowikiToken) {
|
|
13
|
-
type = 'comment';
|
|
14
|
-
closed;
|
|
15
|
-
|
|
16
|
-
/** 内部wikitext */
|
|
17
|
-
get innerText() {
|
|
18
|
-
return String(this.firstChild);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @param {string} wikitext wikitext
|
|
23
|
-
* @param {boolean} closed 是否闭合
|
|
24
|
-
* @param {import('../../typings/token').accum} accum
|
|
25
|
-
*/
|
|
26
|
-
constructor(wikitext, closed = true, config = Parser.getConfig(), accum = []) {
|
|
27
|
-
super(wikitext, config, accum);
|
|
28
|
-
this.closed = closed;
|
|
29
|
-
Object.defineProperty(this, 'closed', {enumerable: false});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** @override */
|
|
33
|
-
getPadding() {
|
|
34
|
-
return 4;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** @override */
|
|
38
|
-
print() {
|
|
39
|
-
return super.print({pre: '<!--', post: this.closed ? '-->' : ''});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @override
|
|
44
|
-
* @param {number} start 起始位置
|
|
45
|
-
*/
|
|
46
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
47
|
-
return this.closed ? [] : [generateForSelf(this, {start}, 'unclosed HTML comment')];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @override
|
|
52
|
-
* @param {string} selector
|
|
53
|
-
*/
|
|
54
|
-
toString(selector) {
|
|
55
|
-
if (!this.closed && this.nextSibling) {
|
|
56
|
-
Parser.error('自动闭合HTML注释', this);
|
|
57
|
-
this.closed = true;
|
|
58
|
-
}
|
|
59
|
-
return selector && this.matches(selector)
|
|
60
|
-
? ''
|
|
61
|
-
: `<!--${String(this.firstChild)}${this.closed ? '-->' : ''}`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** @override */
|
|
65
|
-
cloneNode() {
|
|
66
|
-
return Parser.run(() => new CommentToken(String(this.firstChild), this.closed, this.getAttribute('config')));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
Parser.classes.CommentToken = __filename;
|
|
71
|
-
module.exports = CommentToken;
|
package/src/nowiki/dd.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Parser = require('../..'),
|
|
4
|
-
NowikiToken = require('.');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* :
|
|
8
|
-
* @classdesc `{childNodes: [AstText]}`
|
|
9
|
-
*/
|
|
10
|
-
class DdToken extends NowikiToken {
|
|
11
|
-
type = 'dd';
|
|
12
|
-
|
|
13
|
-
/** 是否包含<dt> */
|
|
14
|
-
get dt() {
|
|
15
|
-
return String(this).includes(';');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** 是否包含<ul> */
|
|
19
|
-
get ul() {
|
|
20
|
-
return String(this).includes('*');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** 是否包含<ol> */
|
|
24
|
-
get ol() {
|
|
25
|
-
return String(this).includes('#');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** 缩进数 */
|
|
29
|
-
get indent() {
|
|
30
|
-
return String(this).split(':').length - 1;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
set indent(indent) {
|
|
34
|
-
if (this.type === 'dd') {
|
|
35
|
-
if (!Number.isInteger(indent)) {
|
|
36
|
-
this.typeError('set indent', 'Number');
|
|
37
|
-
} else if (indent < 0) {
|
|
38
|
-
throw new RangeError(`indent 应为自然数!${indent}`);
|
|
39
|
-
}
|
|
40
|
-
this.setText(':'.repeat(indent));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @override
|
|
46
|
-
* @param {string} str 新文本
|
|
47
|
-
* @throws `RangeError` 错误的列表语法
|
|
48
|
-
*/
|
|
49
|
-
setText(str) {
|
|
50
|
-
const src = this.type === 'dd' ? ':' : ';:*#';
|
|
51
|
-
if (new RegExp(`[^${src}]`, 'u').test(str)) {
|
|
52
|
-
throw new RangeError(`${this.constructor.name} 仅能包含${[...src].map(c => `"${c}"`).join('、')}!`);
|
|
53
|
-
}
|
|
54
|
-
return super.setText(str);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
Parser.classes.DdToken = __filename;
|
|
59
|
-
module.exports = DdToken;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const hidden = require('../../mixin/hidden'),
|
|
4
|
-
Parser = require('../..'),
|
|
5
|
-
NowikiToken = require('.');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 状态开关
|
|
9
|
-
* @classdesc `{childNodes: [AstText]}`
|
|
10
|
-
*/
|
|
11
|
-
class DoubleUnderscoreToken extends hidden(NowikiToken) {
|
|
12
|
-
type = 'double-underscore';
|
|
13
|
-
|
|
14
|
-
/** @override */
|
|
15
|
-
getPadding() {
|
|
16
|
-
return 2;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** @override */
|
|
20
|
-
print() {
|
|
21
|
-
return super.print({pre: '__', post: '__'});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @override
|
|
26
|
-
* @param {string} selector
|
|
27
|
-
*/
|
|
28
|
-
toString(selector) {
|
|
29
|
-
return selector && this.matches(selector) ? '' : `__${String(this.firstChild)}__`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @param {string} word 状态开关名
|
|
34
|
-
* @param {import('../../typings/token').accum} accum
|
|
35
|
-
*/
|
|
36
|
-
constructor(word, config = Parser.getConfig(), accum = []) {
|
|
37
|
-
super(word, config, accum);
|
|
38
|
-
this.setAttribute('name', word.toLowerCase());
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** @override */
|
|
42
|
-
cloneNode() {
|
|
43
|
-
return Parser.run(() => new DoubleUnderscoreToken(String(this.firstChild), this.getAttribute('config')));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @override
|
|
48
|
-
* @throws `Error` 禁止修改
|
|
49
|
-
*/
|
|
50
|
-
setText() {
|
|
51
|
-
throw new Error(`禁止修改 ${this.constructor.name}!`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
Parser.classes.DoubleUnderscoreToken = __filename;
|
|
56
|
-
module.exports = DoubleUnderscoreToken;
|
package/src/nowiki/hr.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Parser = require('../..'),
|
|
4
|
-
sol = require('../../mixin/sol'),
|
|
5
|
-
NowikiToken = require('.');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* `<hr>`
|
|
9
|
-
* @classdesc `{childNodes: [AstText]}`
|
|
10
|
-
*/
|
|
11
|
-
class HrToken extends sol(NowikiToken) {
|
|
12
|
-
type = 'hr';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @param {number} n 字符串长度
|
|
16
|
-
* @param {import('../../typings/token').accum} accum
|
|
17
|
-
*/
|
|
18
|
-
constructor(n, config = Parser.getConfig(), accum = []) {
|
|
19
|
-
super('-'.repeat(n), config, accum);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** @override */
|
|
23
|
-
cloneNode() {
|
|
24
|
-
return Parser.run(() => new HrToken(String(this).length, this.getAttribute('config')));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @override
|
|
29
|
-
* @param {string} str 新文本
|
|
30
|
-
* @throws `RangeError` 错误的\<hr\>语法
|
|
31
|
-
*/
|
|
32
|
-
setText(str) {
|
|
33
|
-
if (str.length < 4 || /[^-]/u.test(str)) {
|
|
34
|
-
throw new RangeError('<hr>总是写作不少于4个的连续"-"!');
|
|
35
|
-
}
|
|
36
|
-
return super.setText(str);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
Parser.classes.HrToken = __filename;
|
|
41
|
-
module.exports = HrToken;
|
package/src/nowiki/index.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {generateForSelf} = require('../../util/lint'),
|
|
4
|
-
fixedToken = require('../../mixin/fixedToken'),
|
|
5
|
-
Parser = require('../..'),
|
|
6
|
-
AstText = require('../../lib/text'),
|
|
7
|
-
Token = require('..');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 纯文字Token,不会被解析
|
|
11
|
-
* @classdesc `{childNodes: [AstText]}`
|
|
12
|
-
*/
|
|
13
|
-
class NowikiToken extends fixedToken(Token) {
|
|
14
|
-
type = 'ext-inner';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @param {string} wikitext wikitext
|
|
18
|
-
* @param {import('../../typings/token').accum} accum
|
|
19
|
-
*/
|
|
20
|
-
constructor(wikitext, config = Parser.getConfig(), accum = []) {
|
|
21
|
-
super(wikitext, config, true, accum);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @override
|
|
26
|
-
* @param {number} start 起始位置
|
|
27
|
-
*/
|
|
28
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
29
|
-
const {type, name} = this;
|
|
30
|
-
return type === 'ext-inner' && (name === 'templatestyles' || name === 'section') && String(this)
|
|
31
|
-
? [generateForSelf(this, {start}, Parser.msg('nothing should be in <$1>', name))]
|
|
32
|
-
: super.lint(start);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @override
|
|
37
|
-
* @this {NowikiToken & {firstChild: AstText, constructor: typeof NowikiToken}}
|
|
38
|
-
*/
|
|
39
|
-
cloneNode() {
|
|
40
|
-
const {constructor, firstChild: {data}, type} = this,
|
|
41
|
-
token = Parser.run(() => new constructor(data, this.getAttribute('config')));
|
|
42
|
-
token.type = type;
|
|
43
|
-
return token;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @override
|
|
48
|
-
* @param {string} str 新文本
|
|
49
|
-
*/
|
|
50
|
-
setText(str) {
|
|
51
|
-
return super.setText(str, 0);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
Parser.classes.NowikiToken = __filename;
|
|
56
|
-
module.exports = NowikiToken;
|
package/src/nowiki/list.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const sol = require('../../mixin/sol'),
|
|
4
|
-
Parser = require('../..'),
|
|
5
|
-
DdToken = require('./dd');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* ;:*#
|
|
9
|
-
* @classdesc `{childNodes: [AstText]}`
|
|
10
|
-
*/
|
|
11
|
-
class ListToken extends sol(DdToken) {
|
|
12
|
-
type = 'list';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
Parser.classes.ListToken = __filename;
|
|
16
|
-
module.exports = ListToken;
|
package/src/nowiki/noinclude.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const hidden = require('../../mixin/hidden'),
|
|
4
|
-
Parser = require('../..'),
|
|
5
|
-
NowikiToken = require('.');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* `<noinclude>`和`</noinclude>`,不可进行任何更改
|
|
9
|
-
* @classdesc `{childNodes: [AstText]}`
|
|
10
|
-
*/
|
|
11
|
-
class NoincludeToken extends hidden(NowikiToken) {
|
|
12
|
-
type = 'noinclude';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @override
|
|
16
|
-
* @param {string} str 新文本
|
|
17
|
-
* @throws `Error` 不可更改
|
|
18
|
-
*/
|
|
19
|
-
setText(str) {
|
|
20
|
-
if (/^<\/?(?:(?:no|only)include|includeonly)(?:\s.*)?\/?>$/isu.test(String(this))) {
|
|
21
|
-
throw new Error(`${this.constructor.name} 不可更改文字内容!`);
|
|
22
|
-
}
|
|
23
|
-
return super.setText(str);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
Parser.classes.NoincludeToken = __filename;
|
|
28
|
-
module.exports = NoincludeToken;
|
package/src/nowiki/quote.js
DELETED
|
@@ -1,69 +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 {import('../../typings/token').accum} accum
|
|
18
|
-
*/
|
|
19
|
-
constructor(n, config = Parser.getConfig(), accum = []) {
|
|
20
|
-
super(`'`.repeat(n), config, accum);
|
|
21
|
-
this.setAttribute('name', String(n));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @override
|
|
26
|
-
* @this {AstText}
|
|
27
|
-
* @param {number} start 起始位置
|
|
28
|
-
*/
|
|
29
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
30
|
-
const {previousSibling, nextSibling} = this,
|
|
31
|
-
message = Parser.msg('lonely "$1"', `'`),
|
|
32
|
-
/** @type {import('../../typings/token').LintError[]} */ errors = [];
|
|
33
|
-
let refError, wikitext;
|
|
34
|
-
if (previousSibling?.type === 'text' && previousSibling.data.endsWith(`'`)) {
|
|
35
|
-
refError = generateForSelf(this, {start}, message);
|
|
36
|
-
wikitext = String(this.getRootNode());
|
|
37
|
-
const {startIndex: endIndex, startLine: endLine, startCol: endCol} = refError,
|
|
38
|
-
[{length}] = previousSibling.data.match(/(?<!')'+$/u),
|
|
39
|
-
startIndex = start - length,
|
|
40
|
-
excerpt = wikitext.slice(startIndex, startIndex + 50);
|
|
41
|
-
errors.push({...refError, startIndex, endIndex, startCol: endCol - length, endLine, endCol, excerpt});
|
|
42
|
-
}
|
|
43
|
-
if (nextSibling?.type === 'text' && nextSibling.data[0] === `'`) {
|
|
44
|
-
refError ||= generateForSelf(this, {start}, message);
|
|
45
|
-
wikitext ||= String(this.getRootNode());
|
|
46
|
-
const {endIndex: startIndex, endLine: startLine, endCol: startCol} = refError,
|
|
47
|
-
[{length}] = nextSibling.data.match(/^'+/u),
|
|
48
|
-
endIndex = startIndex + length,
|
|
49
|
-
excerpt = wikitext.slice(Math.max(0, endIndex - 50), endIndex);
|
|
50
|
-
errors.push({...refError, startIndex, endIndex, startLine, startCol, endCol: startCol + length, excerpt});
|
|
51
|
-
}
|
|
52
|
-
return errors;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @override
|
|
57
|
-
* @param {string} str 新文本
|
|
58
|
-
* @throws `RangeError` 错误的单引号语法
|
|
59
|
-
*/
|
|
60
|
-
setText(str) {
|
|
61
|
-
if (str === `''` || str === `'''` || str === `'''''`) {
|
|
62
|
-
return super.setText(str);
|
|
63
|
-
}
|
|
64
|
-
throw new RangeError(`${this.constructor.name} 的内部文本只能为连续 2/3/5 个"'"!`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
Parser.classes.QuoteToken = __filename;
|
|
69
|
-
module.exports = QuoteToken;
|
package/src/onlyinclude.js
DELETED
|
@@ -1,64 +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
|
-
/** 内部wikitext */
|
|
14
|
-
get innerText() {
|
|
15
|
-
return this.text();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @param {string} inner 标签内部wikitext
|
|
20
|
-
* @param {import('../typings/token').accum} accum
|
|
21
|
-
*/
|
|
22
|
-
constructor(inner, config = Parser.getConfig(), accum = []) {
|
|
23
|
-
super(inner, config, true, accum);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @override
|
|
28
|
-
* @param {string} selector
|
|
29
|
-
*/
|
|
30
|
-
toString(selector) {
|
|
31
|
-
return selector && this.matches(selector) ? '' : `<onlyinclude>${super.toString(selector)}</onlyinclude>`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** @override */
|
|
35
|
-
getPadding() {
|
|
36
|
-
return 13;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** @override */
|
|
40
|
-
print() {
|
|
41
|
-
return super.print({
|
|
42
|
-
pre: '<span class="wpb-ext"><onlyinclude></span>',
|
|
43
|
-
post: '<span class="wpb-ext"></onlyinclude></span>',
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** @override */
|
|
48
|
-
isPlain() {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** @override */
|
|
53
|
-
cloneNode() {
|
|
54
|
-
const cloned = this.cloneChildNodes();
|
|
55
|
-
return Parser.run(() => {
|
|
56
|
-
const token = new OnlyincludeToken(undefined, this.getAttribute('config'));
|
|
57
|
-
token.append(...cloned);
|
|
58
|
-
return token;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
Parser.classes.OnlyincludeToken = __filename;
|
|
64
|
-
module.exports = OnlyincludeToken;
|
package/src/paramTag/index.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {generateForChild} = require('../../util/lint'),
|
|
4
|
-
singleLine = require('../../mixin/singleLine'),
|
|
5
|
-
Parser = require('../..'),
|
|
6
|
-
Token = require('..'),
|
|
7
|
-
AtomToken = require('../atom');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* `<inputbox>`
|
|
11
|
-
* @classdesc `{childNodes: ...AtomToken}`
|
|
12
|
-
*/
|
|
13
|
-
class ParamTagToken extends Token {
|
|
14
|
-
type = 'ext-inner';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @param {string} wikitext wikitext
|
|
18
|
-
* @param {import('../../typings/token').accum} accum
|
|
19
|
-
*/
|
|
20
|
-
constructor(wikitext, config = Parser.getConfig(), accum = []) {
|
|
21
|
-
super(undefined, config, true, accum, {
|
|
22
|
-
SingleLineAtomToken: ':',
|
|
23
|
-
});
|
|
24
|
-
if (wikitext) {
|
|
25
|
-
const SingleLineAtomToken = singleLine(AtomToken);
|
|
26
|
-
this.append(
|
|
27
|
-
...wikitext.split('\n').map(line => new SingleLineAtomToken(line, 'param-line', config, accum, {
|
|
28
|
-
AstText: ':',
|
|
29
|
-
})),
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @override
|
|
36
|
-
* @param {string} selector
|
|
37
|
-
*/
|
|
38
|
-
toString(selector) {
|
|
39
|
-
return super.toString(selector, '\n');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** @override */
|
|
43
|
-
text() {
|
|
44
|
-
return super.text('\n');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** @override */
|
|
48
|
-
getGaps() {
|
|
49
|
-
return 1;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** @override */
|
|
53
|
-
print() {
|
|
54
|
-
return super.print({sep: '\n'});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @override
|
|
59
|
-
* @param {number} start 起始位置
|
|
60
|
-
*/
|
|
61
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
62
|
-
let /** @type {{top: number, left: number}} */ rect;
|
|
63
|
-
return this.childNodes.filter(child => {
|
|
64
|
-
const {childNodes} = child,
|
|
65
|
-
i = childNodes.findIndex(({type}) => type !== 'text'),
|
|
66
|
-
str = (i >= 0 ? childNodes.slice(0, i).map(String).join('') : String(child)).trim();
|
|
67
|
-
return str && !(i >= 0 ? /^[a-z]+(?:\[\])?\s*(?:=|$)/iu : /^[a-z]+(?:\[\])?\s*=/iu).test(str);
|
|
68
|
-
}).map(child => {
|
|
69
|
-
rect ||= {start, ...this.getRootNode().posFromIndex(start)};
|
|
70
|
-
return generateForChild(child, rect, Parser.msg('invalid parameter of $1', this.name));
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @override
|
|
76
|
-
* @this {ParamTagToken & {constructor: typeof ParamTagToken}}
|
|
77
|
-
*/
|
|
78
|
-
cloneNode() {
|
|
79
|
-
const cloned = this.cloneChildNodes();
|
|
80
|
-
return Parser.run(() => {
|
|
81
|
-
const token = new this.constructor(undefined, this.getAttribute('config'));
|
|
82
|
-
token.append(...cloned);
|
|
83
|
-
return token;
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
Parser.classes.ParamTagToken = __filename;
|
|
89
|
-
module.exports = ParamTagToken;
|
package/src/paramTag/inputbox.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const parseBrackets = require('../../parser/brackets'),
|
|
4
|
-
singleLine = require('../../mixin/singleLine'),
|
|
5
|
-
Parser = require('../..'),
|
|
6
|
-
ParamTagToken = require('.'),
|
|
7
|
-
AtomToken = require('../atom');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* `<inputbox>`
|
|
11
|
-
* @classdesc `{childNodes: ...SingleLineAtomToken}`
|
|
12
|
-
*/
|
|
13
|
-
class InputboxToken extends ParamTagToken {
|
|
14
|
-
name = 'inputbox';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @param {string} wikitext wikitext
|
|
18
|
-
* @param {import('../../typings/token').accum} accum
|
|
19
|
-
*/
|
|
20
|
-
constructor(wikitext, config = Parser.getConfig(), accum = []) {
|
|
21
|
-
super(undefined, config, accum);
|
|
22
|
-
wikitext = parseBrackets(wikitext, config, accum);
|
|
23
|
-
accum.splice(accum.indexOf(this), 1);
|
|
24
|
-
accum.push(this);
|
|
25
|
-
if (wikitext) {
|
|
26
|
-
const SingleLineAtomToken = singleLine(AtomToken);
|
|
27
|
-
this.append(...wikitext.split('\n').map(line => new SingleLineAtomToken(line, 'param-line', config, accum, {
|
|
28
|
-
AstText: ':', ArgToken: ':', TranscludeToken: ':',
|
|
29
|
-
})));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
Parser.classes.InputboxToken = __filename;
|
|
35
|
-
module.exports = InputboxToken;
|