wikiparser-node 0.3.1 → 0.5.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/README.md +1 -1
- package/config/default.json +13 -17
- package/config/llwiki.json +11 -79
- package/config/moegirl.json +7 -1
- package/config/zhwiki.json +1269 -0
- package/index.js +130 -97
- package/lib/element.js +410 -518
- package/lib/node.js +493 -115
- package/lib/ranges.js +27 -19
- package/lib/text.js +175 -0
- package/lib/title.js +14 -6
- package/mixin/attributeParent.js +70 -24
- package/mixin/fixedToken.js +18 -10
- package/mixin/hidden.js +6 -4
- package/mixin/sol.js +39 -12
- package/package.json +17 -4
- package/parser/brackets.js +18 -18
- package/parser/commentAndExt.js +16 -14
- package/parser/converter.js +14 -13
- package/parser/externalLinks.js +12 -11
- package/parser/hrAndDoubleUnderscore.js +24 -14
- package/parser/html.js +8 -7
- package/parser/links.js +13 -13
- package/parser/list.js +12 -11
- package/parser/magicLinks.js +11 -10
- package/parser/quotes.js +6 -5
- package/parser/selector.js +175 -0
- package/parser/table.js +31 -24
- package/src/arg.js +91 -43
- package/src/atom/hidden.js +5 -2
- package/src/atom/index.js +17 -9
- package/src/attribute.js +210 -101
- package/src/converter.js +78 -43
- package/src/converterFlags.js +104 -45
- package/src/converterRule.js +136 -78
- package/src/extLink.js +81 -27
- package/src/gallery.js +63 -20
- package/src/heading.js +58 -20
- package/src/html.js +138 -48
- package/src/imageParameter.js +93 -58
- package/src/index.js +314 -186
- package/src/link/category.js +22 -54
- package/src/link/file.js +83 -32
- package/src/link/galleryImage.js +21 -7
- package/src/link/index.js +170 -81
- package/src/magicLink.js +64 -14
- package/src/nowiki/comment.js +36 -10
- package/src/nowiki/dd.js +37 -22
- package/src/nowiki/doubleUnderscore.js +21 -7
- package/src/nowiki/hr.js +11 -7
- package/src/nowiki/index.js +16 -9
- package/src/nowiki/list.js +2 -2
- package/src/nowiki/noinclude.js +8 -4
- package/src/nowiki/quote.js +38 -7
- package/src/onlyinclude.js +24 -7
- package/src/parameter.js +102 -62
- package/src/syntax.js +23 -20
- package/src/table/index.js +282 -174
- package/src/table/td.js +112 -61
- package/src/table/tr.js +135 -74
- package/src/tagPair/ext.js +30 -23
- package/src/tagPair/include.js +26 -11
- package/src/tagPair/index.js +72 -29
- package/src/transclude.js +235 -127
- package/tool/index.js +42 -32
- package/util/debug.js +21 -18
- package/util/diff.js +76 -0
- package/util/lint.js +40 -0
- package/util/string.js +56 -26
- package/.eslintrc.json +0 -319
- package/errors/README +0 -1
- package/jsconfig.json +0 -7
- package/printed/README +0 -1
- package/typings/element.d.ts +0 -28
- package/typings/index.d.ts +0 -52
- package/typings/node.d.ts +0 -23
- package/typings/parser.d.ts +0 -9
- package/typings/table.d.ts +0 -14
- package/typings/token.d.ts +0 -22
- package/typings/tool.d.ts +0 -10
package/src/syntax.js
CHANGED
|
@@ -2,21 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
const {undo} = require('../util/debug'),
|
|
4
4
|
{text} = require('../util/string'),
|
|
5
|
-
|
|
5
|
+
Parser = require('..'),
|
|
6
6
|
Token = require('.');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* 满足特定语法格式的plain Token
|
|
10
|
-
* @classdesc `{childNodes: (
|
|
10
|
+
* @classdesc `{childNodes: (AstText|Token)[]}`
|
|
11
11
|
*/
|
|
12
12
|
class SyntaxToken extends Token {
|
|
13
13
|
#pattern;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {RegExp} pattern
|
|
16
|
+
* @param {string} wikitext 语法wikitext
|
|
17
|
+
* @param {RegExp} pattern 语法正则
|
|
18
|
+
* @param {string} type Token.type
|
|
18
19
|
* @param {accum} accum
|
|
19
|
-
* @param {acceptable} acceptable
|
|
20
|
+
* @param {acceptable} acceptable 可接受的子节点设置
|
|
21
|
+
* @throws `RangeError` 含有g修饰符的语法正则
|
|
20
22
|
*/
|
|
21
23
|
constructor(wikitext, pattern, type = 'plain', config = Parser.getConfig(), accum = [], acceptable = null) {
|
|
22
24
|
if (pattern.global) {
|
|
@@ -27,8 +29,9 @@ class SyntaxToken extends Token {
|
|
|
27
29
|
this.#pattern = pattern;
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
/** @override */
|
|
30
33
|
cloneNode() {
|
|
31
|
-
const cloned = this.
|
|
34
|
+
const cloned = this.cloneChildNodes(),
|
|
32
35
|
config = this.getAttribute('config'),
|
|
33
36
|
acceptable = this.getAttribute('acceptable');
|
|
34
37
|
return Parser.run(() => {
|
|
@@ -38,33 +41,33 @@ class SyntaxToken extends Token {
|
|
|
38
41
|
});
|
|
39
42
|
}
|
|
40
43
|
|
|
44
|
+
/** @override */
|
|
41
45
|
afterBuild() {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
const /** @type {AstListener} */ syntaxListener = (e, data) => {
|
|
47
|
+
const pattern = this.#pattern;
|
|
48
|
+
if (!Parser.running && !pattern.test(this.text())) {
|
|
49
|
+
undo(e, data);
|
|
50
|
+
Parser.error(`不可修改 ${this.constructor.name} 的语法!`, pattern);
|
|
51
|
+
throw new Error(`不可修改 ${this.constructor.name} 的语法!`);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
50
54
|
this.addEventListener(['remove', 'insert', 'replace', 'text'], syntaxListener);
|
|
51
55
|
return this;
|
|
52
56
|
}
|
|
53
57
|
|
|
54
58
|
/**
|
|
59
|
+
* @override
|
|
55
60
|
* @template {string} T
|
|
56
|
-
* @param {T} key
|
|
61
|
+
* @param {T} key 属性键
|
|
57
62
|
* @returns {TokenAttribute<T>}
|
|
58
63
|
*/
|
|
59
64
|
getAttribute(key) {
|
|
60
|
-
|
|
61
|
-
return this.#pattern;
|
|
62
|
-
}
|
|
63
|
-
return super.getAttribute(key);
|
|
65
|
+
return key === 'pattern' ? this.#pattern : super.getAttribute(key);
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
/**
|
|
67
|
-
* @
|
|
69
|
+
* @override
|
|
70
|
+
* @param {...Token} elements 待替换的子节点
|
|
68
71
|
* @complexity `n`
|
|
69
72
|
*/
|
|
70
73
|
replaceChildren(...elements) {
|