wikiparser-node 0.0.0 → 0.0.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/package.json +1 -1
- package/parser/links.js +7 -2
- package/parser/table.js +7 -6
- package/src/extLink.js +1 -1
- package/src/imageParameter.js +3 -4
- package/src/table/index.js +2 -2
- package/src/table/tr.js +2 -2
package/package.json
CHANGED
package/parser/links.js
CHANGED
|
@@ -35,8 +35,13 @@ const parseLinks = (firstChild, config = Parser.getConfig(), accum = []) => {
|
|
|
35
35
|
s += `[[${x}`;
|
|
36
36
|
continue;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
let page = link;
|
|
39
|
+
if (link.includes('%')) {
|
|
40
|
+
try {
|
|
41
|
+
page = decodeURIComponent(link);
|
|
42
|
+
} catch {}
|
|
43
|
+
}
|
|
44
|
+
const force = link.trim().startsWith(':');
|
|
40
45
|
if (force && mightBeImg) {
|
|
41
46
|
s += `[[${x}`;
|
|
42
47
|
continue;
|
package/parser/table.js
CHANGED
|
@@ -8,7 +8,8 @@ const /** @type {Parser} */ Parser = require('..');
|
|
|
8
8
|
* @param {accum} accum
|
|
9
9
|
*/
|
|
10
10
|
const parseTable = ({firstChild, type}, config = Parser.getConfig(), accum = []) => {
|
|
11
|
-
const
|
|
11
|
+
const Token = require('../src'),
|
|
12
|
+
TableToken = require('../src/table'),
|
|
12
13
|
TrToken = require('../src/table/tr'),
|
|
13
14
|
TdToken = require('../src/table/td'),
|
|
14
15
|
/** @type {TrToken[]} */ stack = [],
|
|
@@ -19,13 +20,13 @@ const parseTable = ({firstChild, type}, config = Parser.getConfig(), accum = [])
|
|
|
19
20
|
out += str;
|
|
20
21
|
return;
|
|
21
22
|
}
|
|
22
|
-
const {lastElementChild
|
|
23
|
-
if (
|
|
23
|
+
const {lastElementChild} = top;
|
|
24
|
+
if (lastElementChild.isPlain()) {
|
|
24
25
|
lastElementChild.setText(lastElementChild.firstChild + str, 0);
|
|
25
|
-
} else if (typeof lastChild === 'string') {
|
|
26
|
-
top.setText(lastChild + str, 2);
|
|
27
26
|
} else {
|
|
28
|
-
|
|
27
|
+
const token = new Token(str, config, true, accum);
|
|
28
|
+
token.type = 'table-inter';
|
|
29
|
+
top.appendChild(token.setAttribute('stage', 3));
|
|
29
30
|
}
|
|
30
31
|
};
|
|
31
32
|
for (const outLine of lines) {
|
package/src/extLink.js
CHANGED
package/src/imageParameter.js
CHANGED
|
@@ -19,10 +19,9 @@ class ImageParameterToken extends Token {
|
|
|
19
19
|
* @param {string} value
|
|
20
20
|
*/
|
|
21
21
|
static #validate(key, value, config = Parser.getConfig()) {
|
|
22
|
-
value = value.trim();
|
|
22
|
+
value = value.replace(/\x00\d+t\x7f/g, '').trim();
|
|
23
23
|
if (key === 'width') {
|
|
24
|
-
|
|
25
|
-
return Number(mt?.[1]) > 0 || Number(mt?.[2]) > 0;
|
|
24
|
+
return /^\d*(?:x\d*)?$/.test(value);
|
|
26
25
|
} else if (['alt', 'class', 'manualthumb', 'frameless', 'framed', 'thumbnail'].includes(key)) {
|
|
27
26
|
return true;
|
|
28
27
|
} else if (key === 'link') {
|
|
@@ -68,7 +67,7 @@ class ImageParameterToken extends Token {
|
|
|
68
67
|
super(mt[2], config, true, accum, {'Stage-2': ':', '!HeadingToken': ':'});
|
|
69
68
|
this.#syntax = `${mt[1]}${param[0]}${mt[3]}`;
|
|
70
69
|
}
|
|
71
|
-
this.setAttribute('name', param[1]).setAttribute('stage',
|
|
70
|
+
this.setAttribute('name', param[1]).setAttribute('stage', Parser.MAX_STAGE);
|
|
72
71
|
return;
|
|
73
72
|
}
|
|
74
73
|
}
|
package/src/table/index.js
CHANGED
|
@@ -50,7 +50,7 @@ class Layout extends Array {
|
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* 表格
|
|
53
|
-
* @classdesc `{childNodes: [SyntaxToken, AttributeToken, ?
|
|
53
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributeToken, ?Token, ...TdToken, ...TrToken, ?SyntaxToken]}`
|
|
54
54
|
*/
|
|
55
55
|
class TableToken extends TrToken {
|
|
56
56
|
type = 'table';
|
|
@@ -65,7 +65,7 @@ class TableToken extends TrToken {
|
|
|
65
65
|
constructor(syntax, attr = '', config = Parser.getConfig(), accum = []) {
|
|
66
66
|
super(syntax, attr, config, accum, TableToken.openingPattern);
|
|
67
67
|
this.setAttribute('acceptable', {
|
|
68
|
-
|
|
68
|
+
Token: 2, SyntaxToken: [0, -1], AttributeToken: 1, TdToken: '2:', TrToken: '2:',
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
|
package/src/table/tr.js
CHANGED
|
@@ -9,7 +9,7 @@ const attributeParent = require('../../mixin/attributeParent'),
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* 表格行,含开头的换行,不含结尾的换行
|
|
12
|
-
* @classdesc `{childNodes: [SyntaxToken, AttributeToken, ?
|
|
12
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributeToken, ?Token, ...TdToken]}`
|
|
13
13
|
*/
|
|
14
14
|
class TrToken extends attributeParent(Token, 1) {
|
|
15
15
|
type = 'tr';
|
|
@@ -21,7 +21,7 @@ class TrToken extends attributeParent(Token, 1) {
|
|
|
21
21
|
* @param {accum} accum
|
|
22
22
|
*/
|
|
23
23
|
constructor(syntax, attr = '', config = Parser.getConfig(), accum = [], pattern = TrToken.openingPattern) {
|
|
24
|
-
super(undefined, config, true, accum, {
|
|
24
|
+
super(undefined, config, true, accum, {Token: 2, SyntaxToken: 0, AttributeToken: 1, TdToken: '2:'});
|
|
25
25
|
this.append(
|
|
26
26
|
new SyntaxToken(syntax, pattern, 'table-syntax', config, accum, {
|
|
27
27
|
'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':',
|