wikiparser-node 0.8.0 → 0.8.1
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/lib/text.js +55 -3
- package/package.json +1 -1
- package/src/attribute.js +11 -1
- package/src/imageParameter.js +15 -14
- package/src/transclude.js +9 -7
package/lib/text.js
CHANGED
|
@@ -5,7 +5,59 @@ const Parser = require('..'),
|
|
|
5
5
|
AstElement = require('./element');
|
|
6
6
|
|
|
7
7
|
const errorSyntax = /https?:|\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\]+|<\s*\/?([a-z]\w*)(?=[\s/>])/giu,
|
|
8
|
-
errorSyntaxUrl = /\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\]+|<\s*\/?([a-z]\w*)(?=[\s/>])/giu
|
|
8
|
+
errorSyntaxUrl = /\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\]+|<\s*\/?([a-z]\w*)(?=[\s/>])/giu,
|
|
9
|
+
disallowedTags = [
|
|
10
|
+
'html',
|
|
11
|
+
'base',
|
|
12
|
+
'head',
|
|
13
|
+
'style',
|
|
14
|
+
'title',
|
|
15
|
+
'body',
|
|
16
|
+
'menu',
|
|
17
|
+
'a',
|
|
18
|
+
'area',
|
|
19
|
+
'audio',
|
|
20
|
+
'img',
|
|
21
|
+
'map',
|
|
22
|
+
'track',
|
|
23
|
+
'video',
|
|
24
|
+
'embed',
|
|
25
|
+
'iframe',
|
|
26
|
+
'object',
|
|
27
|
+
'picture',
|
|
28
|
+
'source',
|
|
29
|
+
'canvas',
|
|
30
|
+
'script',
|
|
31
|
+
'col',
|
|
32
|
+
'colgroup',
|
|
33
|
+
'tbody',
|
|
34
|
+
'tfoot',
|
|
35
|
+
'thead',
|
|
36
|
+
'button',
|
|
37
|
+
'datalist',
|
|
38
|
+
'fieldset',
|
|
39
|
+
'form',
|
|
40
|
+
'input',
|
|
41
|
+
'label',
|
|
42
|
+
'legend',
|
|
43
|
+
'meter',
|
|
44
|
+
'optgroup',
|
|
45
|
+
'option',
|
|
46
|
+
'output',
|
|
47
|
+
'progress',
|
|
48
|
+
'select',
|
|
49
|
+
'textarea',
|
|
50
|
+
'details',
|
|
51
|
+
'dialog',
|
|
52
|
+
'slot',
|
|
53
|
+
'template',
|
|
54
|
+
'dir',
|
|
55
|
+
'frame',
|
|
56
|
+
'frameset',
|
|
57
|
+
'marquee',
|
|
58
|
+
'param',
|
|
59
|
+
'xmp',
|
|
60
|
+
];
|
|
9
61
|
|
|
10
62
|
/** 文本节点 */
|
|
11
63
|
class AstText extends AstNode {
|
|
@@ -58,7 +110,7 @@ class AstText extends AstNode {
|
|
|
58
110
|
if (errors.length > 0) {
|
|
59
111
|
const root = this.getRootNode(),
|
|
60
112
|
{top, left} = root.posFromIndex(start),
|
|
61
|
-
|
|
113
|
+
tags = new Set([this.#config.ext, this.#config.html, disallowedTags].flat(2));
|
|
62
114
|
return errors.map(/** @returns {LintError} */ ({0: error, 1: prefix, 2: tag, index}) => {
|
|
63
115
|
if (prefix) {
|
|
64
116
|
index += prefix.length;
|
|
@@ -89,7 +141,7 @@ class AstText extends AstNode {
|
|
|
89
141
|
}
|
|
90
142
|
// no default
|
|
91
143
|
}
|
|
92
|
-
} else if (char === '<' && !
|
|
144
|
+
} else if (char === '<' && !tags.has(tag.toLowerCase())) {
|
|
93
145
|
return false;
|
|
94
146
|
}
|
|
95
147
|
return {
|
package/package.json
CHANGED
package/src/attribute.js
CHANGED
|
@@ -79,7 +79,17 @@ const stages = {'ext-attr': 0, 'html-attr': 2, 'table-attr': 3},
|
|
|
79
79
|
link: new Set(['itemprop', 'href', 'title']),
|
|
80
80
|
gallery: new Set(['mode', 'showfilename', 'caption', 'perrow', 'widths', 'heights', 'showthumbnails', 'type']),
|
|
81
81
|
poem: new Set(['compact', 'align']),
|
|
82
|
-
categorytree: new Set([
|
|
82
|
+
categorytree: new Set([
|
|
83
|
+
'align',
|
|
84
|
+
'hideroot',
|
|
85
|
+
'onlyroot',
|
|
86
|
+
'depth',
|
|
87
|
+
'mode',
|
|
88
|
+
'hideprefix',
|
|
89
|
+
'namespaces',
|
|
90
|
+
'showcount',
|
|
91
|
+
'notranslations',
|
|
92
|
+
]),
|
|
83
93
|
combooption: new Set(['name', 'for', 'inline', 'align']),
|
|
84
94
|
},
|
|
85
95
|
empty = new Set(),
|
package/src/imageParameter.js
CHANGED
|
@@ -126,26 +126,27 @@ class ImageParameterToken extends Token {
|
|
|
126
126
|
* @param {accum} accum
|
|
127
127
|
*/
|
|
128
128
|
constructor(str, config = Parser.getConfig(), accum = []) {
|
|
129
|
+
let mt;
|
|
129
130
|
const regexes = Object.entries(config.img).map(
|
|
130
131
|
/** @returns {[string, string, RegExp]} */
|
|
131
132
|
([syntax, param]) => [syntax, param, new RegExp(`^(\\s*)${syntax.replace('$1', '(.*)')}(\\s*)$`, 'u')],
|
|
132
133
|
),
|
|
133
|
-
param = regexes.find(([
|
|
134
|
+
param = regexes.find(([, key, regex]) => {
|
|
135
|
+
mt = regex.exec(str);
|
|
136
|
+
return mt && (mt.length !== 4 || ImageParameterToken.#validate(key, mt[2], config, true));
|
|
137
|
+
});
|
|
134
138
|
if (param) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
});
|
|
144
|
-
this.#syntax = `${mt[1]}${param[0]}${mt[3]}`;
|
|
145
|
-
}
|
|
146
|
-
this.setAttribute('name', param[1]);
|
|
147
|
-
return;
|
|
139
|
+
if (mt.length === 3) {
|
|
140
|
+
super(undefined, config, true, accum);
|
|
141
|
+
this.#syntax = str;
|
|
142
|
+
} else {
|
|
143
|
+
super(mt[2], config, true, accum, {
|
|
144
|
+
'Stage-2': ':', '!HeadingToken': ':',
|
|
145
|
+
});
|
|
146
|
+
this.#syntax = `${mt[1]}${param[0]}${mt[3]}`;
|
|
148
147
|
}
|
|
148
|
+
this.setAttribute('name', param[1]);
|
|
149
|
+
return;
|
|
149
150
|
}
|
|
150
151
|
super(str, {...config, excludes: [...config.excludes, 'list']}, true, accum);
|
|
151
152
|
this.setAttribute('name', 'caption').setAttribute('stage', 7);
|
package/src/transclude.js
CHANGED
|
@@ -195,12 +195,14 @@ class TranscludeToken extends Token {
|
|
|
195
195
|
* @complexity `n`
|
|
196
196
|
*/
|
|
197
197
|
text() {
|
|
198
|
-
const {childNodes, firstChild, modifier} = this;
|
|
199
|
-
return
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
198
|
+
const {childNodes, firstChild, modifier, type, name} = this;
|
|
199
|
+
return type === 'magic-word' && name === 'vardefine'
|
|
200
|
+
? ''
|
|
201
|
+
: `{{${modifier}${modifier && ':'}${
|
|
202
|
+
this.type === 'magic-word'
|
|
203
|
+
? `${firstChild.text()}${childNodes.length > 1 ? ':' : ''}${text(childNodes.slice(1), '|')}`
|
|
204
|
+
: super.text('|')
|
|
205
|
+
}}}`;
|
|
204
206
|
}
|
|
205
207
|
|
|
206
208
|
/** @override */
|
|
@@ -330,7 +332,7 @@ class TranscludeToken extends Token {
|
|
|
330
332
|
this.typeError('getArgs', 'String', 'Number');
|
|
331
333
|
}
|
|
332
334
|
copy ||= !Parser.debugging && externalUse('getArgs');
|
|
333
|
-
const keyStr = String(key).
|
|
335
|
+
const keyStr = String(key).replace(/^[ \t\n\0\v]+|(?<=[^ \t\n\0\v])[ \t\n\0\v]+$/gu, '');
|
|
334
336
|
let args;
|
|
335
337
|
if (Object.hasOwn(this.#args, keyStr)) {
|
|
336
338
|
args = this.#args[keyStr];
|