wikiparser-node 0.8.1 → 0.9.0-m
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/default.json +0 -1
- package/config/llwiki.json +0 -35
- package/config/moegirl.json +1 -44
- package/config/zhwiki.json +0 -466
- package/i18n/zh-hans.json +44 -0
- package/i18n/zh-hant.json +44 -0
- package/index.js +16 -256
- package/lib/element.js +29 -504
- package/lib/node.js +6 -542
- package/lib/text.js +10 -127
- package/lib/title.js +7 -32
- package/mixin/hidden.js +0 -3
- package/package.json +8 -8
- package/parser/brackets.js +8 -3
- package/parser/commentAndExt.js +1 -5
- package/parser/converter.js +0 -1
- package/parser/externalLinks.js +0 -1
- package/parser/hrAndDoubleUnderscore.js +0 -1
- package/parser/html.js +0 -1
- package/parser/links.js +5 -6
- package/parser/list.js +0 -1
- package/parser/magicLinks.js +0 -1
- package/parser/quotes.js +1 -2
- package/parser/table.js +0 -1
- package/src/arg.js +9 -119
- package/src/atom/hidden.js +0 -2
- package/src/atom/index.js +0 -17
- package/src/attribute.js +7 -181
- package/src/attributes.js +8 -312
- package/src/converter.js +2 -108
- package/src/converterFlags.js +3 -190
- package/src/converterRule.js +3 -187
- package/src/extLink.js +2 -121
- package/src/gallery.js +5 -62
- package/src/hasNowiki/index.js +0 -12
- package/src/hasNowiki/pre.js +0 -12
- package/src/heading.js +7 -58
- package/src/html.js +18 -127
- package/src/imageParameter.js +61 -200
- package/src/imagemap.js +7 -66
- package/src/imagemapLink.js +2 -14
- package/src/index.js +11 -534
- package/src/link/category.js +1 -37
- package/src/link/file.js +18 -168
- package/src/link/galleryImage.js +6 -64
- package/src/link/index.js +9 -277
- package/src/magicLink.js +2 -85
- package/src/nested/choose.js +0 -1
- package/src/nested/combobox.js +0 -1
- package/src/nested/index.js +3 -33
- package/src/nested/references.js +0 -1
- package/src/nowiki/comment.js +3 -27
- package/src/nowiki/dd.js +1 -47
- package/src/nowiki/doubleUnderscore.js +1 -31
- package/src/nowiki/hr.js +1 -20
- package/src/nowiki/index.js +3 -25
- package/src/nowiki/list.js +2 -5
- package/src/nowiki/noinclude.js +0 -14
- package/src/nowiki/quote.js +3 -17
- package/src/onlyinclude.js +1 -26
- package/src/paramTag/index.js +4 -27
- package/src/paramTag/inputbox.js +1 -4
- package/src/parameter.js +7 -149
- package/src/syntax.js +0 -68
- package/src/table/index.js +4 -942
- package/src/table/td.js +9 -230
- package/src/table/tr.js +4 -249
- package/src/tagPair/ext.js +13 -27
- package/src/tagPair/include.js +0 -24
- package/src/tagPair/index.js +2 -51
- package/src/transclude.js +38 -528
- package/util/lint.js +8 -7
- package/util/string.js +12 -44
- package/README.md +0 -39
- package/lib/ranges.js +0 -130
- package/mixin/attributeParent.js +0 -117
- package/mixin/fixedToken.js +0 -40
- package/mixin/singleLine.js +0 -31
- package/mixin/sol.js +0 -65
- package/parser/selector.js +0 -177
- package/src/charinsert.js +0 -97
- package/tool/index.js +0 -1202
- package/util/debug.js +0 -73
package/src/syntax.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const Parser = require('..'),
|
|
4
|
-
{undo} = require('../util/debug'),
|
|
5
|
-
{text} = require('../util/string'),
|
|
6
4
|
Token = require('.');
|
|
7
5
|
|
|
8
6
|
/**
|
|
@@ -10,82 +8,16 @@ const Parser = require('..'),
|
|
|
10
8
|
* @classdesc `{childNodes: ...AstText|Token}`
|
|
11
9
|
*/
|
|
12
10
|
class SyntaxToken extends Token {
|
|
13
|
-
#pattern;
|
|
14
|
-
|
|
15
11
|
/**
|
|
16
12
|
* @param {string} wikitext 语法wikitext
|
|
17
13
|
* @param {RegExp} pattern 语法正则
|
|
18
14
|
* @param {string} type Token.type
|
|
19
15
|
* @param {accum} accum
|
|
20
|
-
* @param {acceptable} acceptable 可接受的子节点设置
|
|
21
|
-
* @throws `RangeError` 含有g修饰符的语法正则
|
|
22
16
|
*/
|
|
23
17
|
constructor(wikitext, pattern, type = 'plain', config = Parser.getConfig(), accum = [], acceptable = undefined) {
|
|
24
|
-
if (pattern.global) {
|
|
25
|
-
throw new RangeError(`SyntaxToken 的语法正则不能含有 g 修饰符:${pattern}`);
|
|
26
|
-
}
|
|
27
18
|
super(wikitext, config, true, accum, acceptable);
|
|
28
19
|
this.type = type;
|
|
29
|
-
this.#pattern = pattern;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** @override */
|
|
33
|
-
cloneNode() {
|
|
34
|
-
const cloned = this.cloneChildNodes(),
|
|
35
|
-
config = this.getAttribute('config'),
|
|
36
|
-
acceptable = this.getAttribute('acceptable');
|
|
37
|
-
return Parser.run(() => {
|
|
38
|
-
const token = new SyntaxToken(undefined, this.#pattern, this.type, config, [], acceptable);
|
|
39
|
-
token.append(...cloned);
|
|
40
|
-
token.afterBuild();
|
|
41
|
-
return token;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** @override */
|
|
46
|
-
afterBuild() {
|
|
47
|
-
const /** @type {AstListener} */ syntaxListener = (e, data) => {
|
|
48
|
-
const pattern = this.#pattern;
|
|
49
|
-
if (!Parser.running && !pattern.test(this.text())) {
|
|
50
|
-
undo(e, data);
|
|
51
|
-
Parser.error(`不可修改 ${this.constructor.name} 的语法!`, pattern);
|
|
52
|
-
throw new Error(`不可修改 ${this.constructor.name} 的语法!`);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
this.addEventListener(['remove', 'insert', 'replace', 'text'], syntaxListener);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @override
|
|
60
|
-
* @template {string} T
|
|
61
|
-
* @param {T} key 属性键
|
|
62
|
-
* @returns {TokenAttribute<T>}
|
|
63
|
-
*/
|
|
64
|
-
getAttribute(key) {
|
|
65
|
-
return key === 'pattern' ? this.#pattern : super.getAttribute(key);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @override
|
|
70
|
-
* @param {PropertyKey} key 属性键
|
|
71
|
-
*/
|
|
72
|
-
hasAttribute(key) {
|
|
73
|
-
return key === 'pattern' || super.hasAttribute(key);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @override
|
|
78
|
-
* @param {...Token} elements 待替换的子节点
|
|
79
|
-
* @complexity `n`
|
|
80
|
-
*/
|
|
81
|
-
replaceChildren(...elements) {
|
|
82
|
-
if (this.#pattern.test(text(elements))) {
|
|
83
|
-
Parser.run(() => {
|
|
84
|
-
super.replaceChildren(...elements);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
20
|
}
|
|
88
21
|
}
|
|
89
22
|
|
|
90
|
-
Parser.classes.SyntaxToken = __filename;
|
|
91
23
|
module.exports = SyntaxToken;
|