wikiparser-node 0.2.1 → 0.2.2
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/package.json +1 -1
- package/parser/table.js +7 -3
- package/src/attribute.js +16 -23
- package/src/converterFlags.js +1 -0
- package/src/converterRule.js +1 -0
- package/src/extLink.js +1 -1
- package/src/index.js +5 -6
- package/src/link/category.js +1 -0
- package/src/magicLink.js +5 -1
- package/src/nowiki/dd.js +4 -4
- package/src/table/td.js +1 -1
- package/src/tagPair/index.js +1 -1
- package/util/string.js +1 -1
- package/errors/2022-07-04T22:30:41.785Z +0 -1
- package/errors/2022-07-04T22:30:41.785Z.err +0 -11
- package/errors/2022-07-04T22:30:41.785Z.json +0 -5
package/package.json
CHANGED
package/parser/table.js
CHANGED
|
@@ -12,6 +12,7 @@ const parseTable = ({firstChild, type}, config = Parser.getConfig(), accum = [])
|
|
|
12
12
|
TableToken = require('../src/table'),
|
|
13
13
|
TrToken = require('../src/table/tr'),
|
|
14
14
|
TdToken = require('../src/table/td'),
|
|
15
|
+
DdToken = require('../src/nowiki/dd'),
|
|
15
16
|
/** @type {TrToken[]} */ stack = [],
|
|
16
17
|
lines = firstChild.split('\n');
|
|
17
18
|
let out = type === 'root' ? '' : `\n${lines.shift()}`;
|
|
@@ -33,10 +34,13 @@ const parseTable = ({firstChild, type}, config = Parser.getConfig(), accum = [])
|
|
|
33
34
|
let top = stack.pop();
|
|
34
35
|
const [spaces] = outLine.match(/^(?:\s|\x00\d+c\x7f)*/);
|
|
35
36
|
const line = outLine.slice(spaces.length),
|
|
36
|
-
matchesStart = line.match(/^(:*(?:\s|\x00\d+c\x7f)*)({\||{\x00\d+!\x7f|\x00\d+{\x7f)(.*)/);
|
|
37
|
+
matchesStart = line.match(/^(:*)((?:\s|\x00\d+c\x7f)*)({\||{\x00\d+!\x7f|\x00\d+{\x7f)(.*)/);
|
|
37
38
|
if (matchesStart) {
|
|
38
|
-
const [, indent, tableSyntax, attr] = matchesStart;
|
|
39
|
-
|
|
39
|
+
const [, indent, moreSpaces, tableSyntax, attr] = matchesStart;
|
|
40
|
+
if (indent) {
|
|
41
|
+
new DdToken(indent, config, accum);
|
|
42
|
+
}
|
|
43
|
+
push(`\n${spaces}${indent && `\x00${accum.length - 1}d\x7f`}${moreSpaces}\x00${accum.length}b\x7f`, top);
|
|
40
44
|
const table = new TableToken(tableSyntax, attr, config, accum);
|
|
41
45
|
stack.push(...top ? [top] : [], table);
|
|
42
46
|
continue;
|
package/src/attribute.js
CHANGED
|
@@ -108,31 +108,24 @@ class AttributeToken extends Token {
|
|
|
108
108
|
return super.getAttribute(key);
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
if (built) {
|
|
129
|
-
this.#attr.set(key, text);
|
|
111
|
+
afterBuild() {
|
|
112
|
+
if (this.type !== 'ext-attr') {
|
|
113
|
+
for (let [key, text] of this.#attr) {
|
|
114
|
+
let built = false;
|
|
115
|
+
if (key.includes('\x00')) {
|
|
116
|
+
this.#attr.delete(key);
|
|
117
|
+
key = this.buildFromStr(key).map(String).join('');
|
|
118
|
+
built = true;
|
|
119
|
+
}
|
|
120
|
+
if (typeof text === 'string' && text.includes('\x00')) {
|
|
121
|
+
text = this.buildFromStr(text).map(String).join('');
|
|
122
|
+
built = true;
|
|
123
|
+
}
|
|
124
|
+
if (built) {
|
|
125
|
+
this.#attr.set(key, text);
|
|
126
|
+
}
|
|
130
127
|
}
|
|
131
128
|
}
|
|
132
|
-
return this;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
afterBuild() {
|
|
136
129
|
const that = this,
|
|
137
130
|
/** @type {AstListener} */ attributeListener = ({type, target}) => {
|
|
138
131
|
if (type === 'text' || target !== that) {
|
package/src/converterFlags.js
CHANGED
package/src/converterRule.js
CHANGED
package/src/extLink.js
CHANGED
|
@@ -116,7 +116,7 @@ class ExtLinkToken extends Token {
|
|
|
116
116
|
if (this.childNodes.length === 1) {
|
|
117
117
|
this.appendChild(lastChild);
|
|
118
118
|
} else {
|
|
119
|
-
this.lastElementChild.
|
|
119
|
+
this.lastElementChild.safeReplaceWith(lastChild);
|
|
120
120
|
}
|
|
121
121
|
this.#space ||= ' ';
|
|
122
122
|
}
|
package/src/index.js
CHANGED
|
@@ -51,11 +51,8 @@ const {externalUse} = require('../util/debug'),
|
|
|
51
51
|
class Token extends AstElement {
|
|
52
52
|
type = 'root';
|
|
53
53
|
/** 解析阶段,参见顶部注释。只对plain Token有意义。 */ #stage = 0;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* 这个数组起两个作用:1. 数组中的Token会在build时替换`/\x00\d+.\x7f/`标记;2. 数组中的Token会依次执行parseOnce和build方法。
|
|
57
|
-
* @type {accum}
|
|
58
|
-
*/
|
|
54
|
+
#config;
|
|
55
|
+
/** 这个数组起两个作用:1. 数组中的Token会在build时替换`/\x00\d+.\x7f/`标记;2. 数组中的Token会依次执行parseOnce和build方法。 */
|
|
59
56
|
#accum;
|
|
60
57
|
/** @type {Record<string, Ranges>} */ #acceptable;
|
|
61
58
|
#protectedChildren = new Ranges();
|
|
@@ -71,7 +68,9 @@ class Token extends AstElement {
|
|
|
71
68
|
if (typeof wikitext === 'string') {
|
|
72
69
|
this.appendChild(halfParsed ? wikitext : wikitext.replace(/[\x00\x7f]/g, ''));
|
|
73
70
|
}
|
|
74
|
-
this
|
|
71
|
+
this.#config = config;
|
|
72
|
+
this.#accum = accum;
|
|
73
|
+
this.setAttribute('acceptable', acceptable);
|
|
75
74
|
accum.push(this);
|
|
76
75
|
}
|
|
77
76
|
|
package/src/link/category.js
CHANGED
package/src/magicLink.js
CHANGED
|
@@ -42,10 +42,14 @@ class MagicLinkToken extends Token {
|
|
|
42
42
|
if (parameter?.getValue() === this.text()) {
|
|
43
43
|
this.replaceWith(this.toString());
|
|
44
44
|
}
|
|
45
|
+
return this;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
getUrl() {
|
|
48
|
-
|
|
49
|
+
let url = this.text();
|
|
50
|
+
if (url.startsWith('//')) {
|
|
51
|
+
url = `https:${url}`;
|
|
52
|
+
}
|
|
49
53
|
try {
|
|
50
54
|
return new URL(url);
|
|
51
55
|
} catch (e) {
|
package/src/nowiki/dd.js
CHANGED
|
@@ -9,10 +9,10 @@ const /** @type {Parser} */ Parser = require('../..'),
|
|
|
9
9
|
*/
|
|
10
10
|
class DdToken extends NowikiToken {
|
|
11
11
|
type = 'dd';
|
|
12
|
-
dt;
|
|
13
|
-
ul;
|
|
14
|
-
ol;
|
|
15
|
-
indent;
|
|
12
|
+
dt = false;
|
|
13
|
+
ul = false;
|
|
14
|
+
ol = false;
|
|
15
|
+
indent = 0;
|
|
16
16
|
|
|
17
17
|
/** @param {string} str */
|
|
18
18
|
#update(str) {
|
package/src/table/td.js
CHANGED
package/src/tagPair/index.js
CHANGED
|
@@ -57,7 +57,7 @@ class TagPairToken extends fixedToken(Token) {
|
|
|
57
57
|
}
|
|
58
58
|
return selfClosing
|
|
59
59
|
? `<${opening}${String(firstChild)}/>`
|
|
60
|
-
: `<${opening}${String(firstChild)}>${String(lastChild)}${closed ? `</${closing}>` : ''}`;
|
|
60
|
+
: `<${opening}${String(firstChild)}>${String(lastChild)}${this.closed ? `</${closing}>` : ''}`;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
getPadding() {
|
package/util/string.js
CHANGED
|
@@ -70,6 +70,6 @@ const normalizeSpace = (token = '', separator = '') => {
|
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
const extUrlChar = '(?:[\\d.]+|\\[[\\da-f:.]+\\]|[^[\\]<>"\\x00-\\x20\\x7f\\p{Zs}\\ufffd])'
|
|
73
|
-
+ '[^[\\]<>"\\x00-\\x20\\x7f\\p{Zs}\\ufffd]*';
|
|
73
|
+
+ '(?:[^[\\]<>"\\x00-\\x20\\x7f\\p{Zs}\\ufffd]|\\x00\\d+c\\x7f)*';
|
|
74
74
|
|
|
75
75
|
module.exports = {toCase, removeComment, ucfirst, escapeRegExp, text, explode, noWrap, normalizeSpace, extUrlChar};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{|
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
TypeError: normalizeSpace is not a function
|
|
2
|
-
at AttributeToken.toString (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/src/attribute.js:249:44)
|
|
3
|
-
at #parseAttr (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/src/attribute.js:58:21)
|
|
4
|
-
at new AttributeToken (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/src/attribute.js:87:45)
|
|
5
|
-
at new TrToken (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/src/table/tr.js:28:4)
|
|
6
|
-
at new TableToken (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/src/table/index.js:66:3)
|
|
7
|
-
at parseTable (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/parser/table.js:40:18)
|
|
8
|
-
at #parseTable (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/src/index.js:553:16)
|
|
9
|
-
at Token.parseOnce (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/src/index.js:431:21)
|
|
10
|
-
at Token.parse (/Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/src/index.js:526:9)
|
|
11
|
-
at /Users/mengxiwu/Documents/CCM-RP/node/wikiparser-node/index.js:134:11
|