wikiparser-node 1.0.0-beta.2 → 1.0.0-beta.4
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/minimum.json +136 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/internal.d.ts +1 -1
- package/dist/lib/element.d.ts +12 -8
- package/dist/lib/element.js +72 -57
- package/dist/lib/node.js +4 -5
- package/dist/lib/range.js +5 -8
- package/dist/lib/ranges.js +2 -2
- package/dist/lib/text.d.ts +2 -2
- package/dist/lib/text.js +5 -5
- package/dist/lib/title.d.ts +3 -2
- package/dist/lib/title.js +11 -10
- package/dist/mixin/attributesParent.js +2 -2
- package/dist/mixin/fixed.js +3 -3
- package/dist/mixin/hidden.js +2 -2
- package/dist/mixin/singleLine.js +4 -4
- package/dist/mixin/sol.js +6 -6
- package/dist/parser/braces.js +4 -9
- package/dist/parser/commentAndExt.js +24 -18
- package/dist/parser/converter.js +8 -7
- package/dist/parser/externalLinks.js +3 -4
- package/dist/parser/hrAndDoubleUnderscore.js +4 -7
- package/dist/parser/html.js +4 -7
- package/dist/parser/links.js +4 -5
- package/dist/parser/list.js +3 -6
- package/dist/parser/magicLinks.js +3 -3
- package/dist/parser/quotes.js +4 -5
- package/dist/parser/selector.js +4 -7
- package/dist/parser/table.js +6 -15
- package/dist/src/arg.d.ts +6 -5
- package/dist/src/arg.js +31 -27
- package/dist/src/atom.d.ts +2 -1
- package/dist/src/atom.js +4 -4
- package/dist/src/attribute.d.ts +14 -13
- package/dist/src/attribute.js +41 -31
- package/dist/src/attributes.d.ts +4 -3
- package/dist/src/attributes.js +15 -21
- package/dist/src/converter.d.ts +4 -3
- package/dist/src/converter.js +10 -17
- package/dist/src/converterFlags.d.ts +9 -8
- package/dist/src/converterFlags.js +14 -15
- package/dist/src/converterRule.d.ts +4 -3
- package/dist/src/converterRule.js +20 -22
- package/dist/src/extLink.d.ts +5 -4
- package/dist/src/extLink.js +16 -17
- package/dist/src/gallery.d.ts +7 -5
- package/dist/src/gallery.js +15 -19
- package/dist/src/heading.d.ts +12 -10
- package/dist/src/heading.js +17 -18
- package/dist/src/hidden.d.ts +4 -3
- package/dist/src/hidden.js +4 -4
- package/dist/src/html.d.ts +17 -15
- package/dist/src/html.js +25 -23
- package/dist/src/imageParameter.d.ts +5 -4
- package/dist/src/imageParameter.js +22 -23
- package/dist/src/imagemap.d.ts +7 -5
- package/dist/src/imagemap.js +14 -19
- package/dist/src/imagemapLink.d.ts +8 -7
- package/dist/src/imagemapLink.js +4 -8
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +48 -46
- package/dist/src/link/base.d.ts +5 -4
- package/dist/src/link/base.js +26 -28
- package/dist/src/link/category.d.ts +1 -1
- package/dist/src/link/category.js +3 -2
- package/dist/src/link/file.d.ts +5 -4
- package/dist/src/link/file.js +22 -20
- package/dist/src/link/galleryImage.d.ts +5 -5
- package/dist/src/link/galleryImage.js +11 -10
- package/dist/src/link/index.d.ts +1 -1
- package/dist/src/link/index.js +8 -6
- package/dist/src/magicLink.d.ts +3 -2
- package/dist/src/magicLink.js +10 -11
- package/dist/src/nested.d.ts +4 -2
- package/dist/src/nested.js +5 -9
- package/dist/src/nowiki/base.d.ts +6 -5
- package/dist/src/nowiki/base.js +4 -4
- package/dist/src/nowiki/comment.d.ts +6 -5
- package/dist/src/nowiki/comment.js +8 -10
- package/dist/src/nowiki/dd.d.ts +1 -1
- package/dist/src/nowiki/dd.js +3 -2
- package/dist/src/nowiki/doubleUnderscore.d.ts +8 -6
- package/dist/src/nowiki/doubleUnderscore.js +13 -13
- package/dist/src/nowiki/hr.d.ts +2 -8
- package/dist/src/nowiki/hr.js +4 -11
- package/dist/src/nowiki/index.d.ts +2 -1
- package/dist/src/nowiki/index.js +6 -5
- package/dist/src/nowiki/list.d.ts +4 -4
- package/dist/src/nowiki/list.js +3 -2
- package/dist/src/nowiki/noinclude.d.ts +2 -2
- package/dist/src/nowiki/noinclude.js +3 -2
- package/dist/src/nowiki/quote.d.ts +1 -8
- package/dist/src/nowiki/quote.js +25 -17
- package/dist/src/onlyinclude.d.ts +5 -4
- package/dist/src/onlyinclude.js +13 -13
- package/dist/src/paramTag/index.d.ts +5 -3
- package/dist/src/paramTag/index.js +7 -7
- package/dist/src/paramTag/inputbox.d.ts +3 -2
- package/dist/src/paramTag/inputbox.js +6 -5
- package/dist/src/parameter.d.ts +11 -10
- package/dist/src/parameter.js +29 -30
- package/dist/src/pre.d.ts +4 -2
- package/dist/src/pre.js +19 -14
- package/dist/src/syntax.d.ts +2 -1
- package/dist/src/syntax.js +7 -7
- package/dist/src/table/base.d.ts +6 -5
- package/dist/src/table/base.js +6 -8
- package/dist/src/table/index.d.ts +9 -8
- package/dist/src/table/index.js +23 -24
- package/dist/src/table/td.d.ts +12 -10
- package/dist/src/table/td.js +19 -20
- package/dist/src/table/tr.d.ts +3 -2
- package/dist/src/table/tr.js +4 -3
- package/dist/src/table/trBase.d.ts +3 -3
- package/dist/src/table/trBase.js +10 -10
- package/dist/src/tagPair/ext.d.ts +7 -6
- package/dist/src/tagPair/ext.js +5 -17
- package/dist/src/tagPair/include.d.ts +5 -5
- package/dist/src/tagPair/include.js +4 -5
- package/dist/src/tagPair/index.d.ts +7 -7
- package/dist/src/tagPair/index.js +13 -19
- package/dist/src/transclude.d.ts +10 -9
- package/dist/src/transclude.js +41 -46
- package/dist/util/lint.js +14 -4
- package/dist/util/string.js +21 -20
- package/package.json +11 -9
package/dist/src/gallery.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GalleryToken = void 0;
|
|
4
|
-
const
|
|
4
|
+
const Parser = require("../index");
|
|
5
5
|
const _1 = require(".");
|
|
6
6
|
const galleryImage_1 = require("./link/galleryImage");
|
|
7
7
|
const hidden_1 = require("./hidden");
|
|
@@ -20,7 +20,7 @@ class GalleryToken extends _1.Token {
|
|
|
20
20
|
* @browser
|
|
21
21
|
* @param inner 标签内部wikitext
|
|
22
22
|
*/
|
|
23
|
-
constructor(inner, config =
|
|
23
|
+
constructor(inner, config = Parser.getConfig(), accum = []) {
|
|
24
24
|
super(undefined, config, true, accum, {
|
|
25
25
|
AstText: ':', GalleryImageToken: ':', HiddenToken: ':',
|
|
26
26
|
});
|
|
@@ -36,7 +36,6 @@ class GalleryToken extends _1.Token {
|
|
|
36
36
|
}
|
|
37
37
|
const [, file, alt] = matches, title = this.normalizeTitle(file, 6, true, true);
|
|
38
38
|
if (title.valid) {
|
|
39
|
-
// @ts-expect-error abstract class
|
|
40
39
|
super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
|
|
41
40
|
}
|
|
42
41
|
else {
|
|
@@ -50,8 +49,8 @@ class GalleryToken extends _1.Token {
|
|
|
50
49
|
* @override
|
|
51
50
|
* @browser
|
|
52
51
|
*/
|
|
53
|
-
toString(
|
|
54
|
-
return super.toString(
|
|
52
|
+
toString(omit) {
|
|
53
|
+
return super.toString(omit, '\n');
|
|
55
54
|
}
|
|
56
55
|
/**
|
|
57
56
|
* @override
|
|
@@ -64,13 +63,6 @@ class GalleryToken extends _1.Token {
|
|
|
64
63
|
getGaps(i) {
|
|
65
64
|
return i < this.length - 1 ? 1 : 0;
|
|
66
65
|
}
|
|
67
|
-
/**
|
|
68
|
-
* @override
|
|
69
|
-
* @browser
|
|
70
|
-
*/
|
|
71
|
-
print() {
|
|
72
|
-
return super.print({ sep: '\n' });
|
|
73
|
-
}
|
|
74
66
|
/**
|
|
75
67
|
* @override
|
|
76
68
|
* @browser
|
|
@@ -81,7 +73,7 @@ class GalleryToken extends _1.Token {
|
|
|
81
73
|
const child = this.childNodes[i], str = String(child), { length } = str, trimmed = str.trim(), startLine = top + i, startCol = i ? 0 : left;
|
|
82
74
|
if (child.type === 'hidden' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
|
|
83
75
|
errors.push({
|
|
84
|
-
message:
|
|
76
|
+
message: Parser.msg('invalid content in <$1>', 'gallery'),
|
|
85
77
|
severity: 'error',
|
|
86
78
|
startIndex: start,
|
|
87
79
|
endIndex: start + length,
|
|
@@ -99,11 +91,17 @@ class GalleryToken extends _1.Token {
|
|
|
99
91
|
}
|
|
100
92
|
return errors;
|
|
101
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* @override
|
|
96
|
+
* @browser
|
|
97
|
+
*/
|
|
98
|
+
print() {
|
|
99
|
+
return super.print({ sep: '\n' });
|
|
100
|
+
}
|
|
102
101
|
/** @override */
|
|
103
102
|
cloneNode() {
|
|
104
103
|
const cloned = this.cloneChildNodes();
|
|
105
|
-
return
|
|
106
|
-
// @ts-expect-error abstract class
|
|
104
|
+
return Parser.run(() => {
|
|
107
105
|
const token = new GalleryToken(undefined, this.getAttribute('config'));
|
|
108
106
|
token.append(...cloned);
|
|
109
107
|
return token;
|
|
@@ -118,9 +116,7 @@ class GalleryToken extends _1.Token {
|
|
|
118
116
|
insertImage(file, i = this.length) {
|
|
119
117
|
const title = this.normalizeTitle(file, 6, true, true);
|
|
120
118
|
if (title.valid) {
|
|
121
|
-
const token =
|
|
122
|
-
// @ts-expect-error abstract class
|
|
123
|
-
() => new galleryImage_1.GalleryImageToken('gallery', file, undefined, this.getAttribute('config')));
|
|
119
|
+
const token = Parser.run(() => new galleryImage_1.GalleryImageToken('gallery', file, undefined, this.getAttribute('config')));
|
|
124
120
|
return this.insertAt(token, i);
|
|
125
121
|
}
|
|
126
122
|
throw new SyntaxError(`非法的文件名:${file}`);
|
|
@@ -134,4 +130,4 @@ class GalleryToken extends _1.Token {
|
|
|
134
130
|
}
|
|
135
131
|
}
|
|
136
132
|
exports.GalleryToken = GalleryToken;
|
|
137
|
-
|
|
133
|
+
Parser.classes['GalleryToken'] = __filename;
|
package/dist/src/heading.d.ts
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
|
+
import * as Parser from '../index';
|
|
1
2
|
import { Token } from '.';
|
|
2
3
|
import { SyntaxToken } from './syntax';
|
|
3
4
|
import type { LintError } from '../index';
|
|
4
5
|
declare const HeadingToken_base: (abstract new (...args: any[]) => {
|
|
5
6
|
"__#7@#isRoot"(): boolean;
|
|
6
7
|
prependNewLine(): string;
|
|
7
|
-
toString(
|
|
8
|
+
toString(omit?: Set<string> | undefined): string;
|
|
8
9
|
getPadding(): number;
|
|
9
10
|
text(): string;
|
|
10
11
|
length: number;
|
|
11
12
|
insertAt(token: unknown, i?: number | undefined): unknown;
|
|
12
13
|
}) & ((abstract new (...args: any[]) => {
|
|
14
|
+
/** @browser */
|
|
13
15
|
removeAt(): never;
|
|
14
|
-
insertAt(token: string, i?: number | undefined):
|
|
15
|
-
insertAt<T extends
|
|
16
|
+
insertAt(token: string, i?: number | undefined): Parser.AstText;
|
|
17
|
+
insertAt<T extends Parser.AstNodes>(token: T, i?: number | undefined): T;
|
|
16
18
|
length: number;
|
|
17
|
-
toString(
|
|
19
|
+
toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
|
|
18
20
|
text(separator?: string | undefined): string;
|
|
19
21
|
}) & {
|
|
20
22
|
readonly fixed: true;
|
|
21
|
-
}) & typeof Token;
|
|
23
|
+
}) & typeof Parser.Token;
|
|
22
24
|
/**
|
|
23
25
|
* 章节标题
|
|
24
26
|
* @classdesc `{childNodes: [Token, SyntaxToken]}`
|
|
25
27
|
*/
|
|
26
|
-
export declare
|
|
28
|
+
export declare class HeadingToken extends HeadingToken_base {
|
|
27
29
|
#private;
|
|
28
30
|
/** @browser */
|
|
29
31
|
readonly type = "heading";
|
|
@@ -48,12 +50,12 @@ export declare abstract class HeadingToken extends HeadingToken_base {
|
|
|
48
50
|
* @param level 标题层级
|
|
49
51
|
* @param input 标题文字
|
|
50
52
|
*/
|
|
51
|
-
constructor(level: number, input: string
|
|
53
|
+
constructor(level: number, input: [string?, string?], config?: Parser.Config, accum?: Token[]);
|
|
52
54
|
/**
|
|
53
55
|
* @override
|
|
54
56
|
* @browser
|
|
55
57
|
*/
|
|
56
|
-
toString(
|
|
58
|
+
toString(omit?: Set<string>): string;
|
|
57
59
|
/**
|
|
58
60
|
* @override
|
|
59
61
|
* @browser
|
|
@@ -63,12 +65,12 @@ export declare abstract class HeadingToken extends HeadingToken_base {
|
|
|
63
65
|
* @override
|
|
64
66
|
* @browser
|
|
65
67
|
*/
|
|
66
|
-
|
|
68
|
+
lint(start?: number): LintError[];
|
|
67
69
|
/**
|
|
68
70
|
* @override
|
|
69
71
|
* @browser
|
|
70
72
|
*/
|
|
71
|
-
|
|
73
|
+
print(): string;
|
|
72
74
|
/** @override */
|
|
73
75
|
cloneNode(): this;
|
|
74
76
|
/**
|
package/dist/src/heading.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.HeadingToken = void 0;
|
|
|
4
4
|
const lint_1 = require("../util/lint");
|
|
5
5
|
const fixed_1 = require("../mixin/fixed");
|
|
6
6
|
const sol_1 = require("../mixin/sol");
|
|
7
|
-
const
|
|
7
|
+
const Parser = require("../index");
|
|
8
8
|
const _1 = require(".");
|
|
9
9
|
const syntax_1 = require("./syntax");
|
|
10
10
|
/**
|
|
@@ -41,7 +41,7 @@ class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixed)(_1.Token)) {
|
|
|
41
41
|
* @param level 标题层级
|
|
42
42
|
* @param input 标题文字
|
|
43
43
|
*/
|
|
44
|
-
constructor(level, input, config =
|
|
44
|
+
constructor(level, input, config = Parser.getConfig(), accum = []) {
|
|
45
45
|
super(undefined, config, true, accum);
|
|
46
46
|
this.setAttribute('name', String(level));
|
|
47
47
|
const token = new _1.Token(input[0], config, true, accum);
|
|
@@ -56,11 +56,11 @@ class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixed)(_1.Token)) {
|
|
|
56
56
|
* @override
|
|
57
57
|
* @browser
|
|
58
58
|
*/
|
|
59
|
-
toString(
|
|
59
|
+
toString(omit) {
|
|
60
60
|
const equals = this.#equals;
|
|
61
|
-
return
|
|
61
|
+
return omit && this.matchesTypes(omit)
|
|
62
62
|
? ''
|
|
63
|
-
: `${this.prependNewLine()}${equals}${this.firstChild.toString(
|
|
63
|
+
: `${this.prependNewLine()}${equals}${this.firstChild.toString(omit)}${equals}${this.lastChild.toString(omit)}`;
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* @override
|
|
@@ -78,14 +78,6 @@ class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixed)(_1.Token)) {
|
|
|
78
78
|
getGaps(i) {
|
|
79
79
|
return i === 0 ? this.level : 0;
|
|
80
80
|
}
|
|
81
|
-
/**
|
|
82
|
-
* @override
|
|
83
|
-
* @browser
|
|
84
|
-
*/
|
|
85
|
-
print() {
|
|
86
|
-
const equals = this.#equals;
|
|
87
|
-
return super.print({ pre: equals, sep: equals });
|
|
88
|
-
}
|
|
89
81
|
/**
|
|
90
82
|
* @override
|
|
91
83
|
* @browser
|
|
@@ -99,19 +91,26 @@ class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixed)(_1.Token)) {
|
|
|
99
91
|
}
|
|
100
92
|
if (innerStr.startsWith('=') || innerStr.endsWith('=')) {
|
|
101
93
|
refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
|
|
102
|
-
errors.push({ ...refError, message:
|
|
94
|
+
errors.push({ ...refError, message: Parser.msg('unbalanced "=" in a section header') });
|
|
103
95
|
}
|
|
104
96
|
if (this.closest('html-attrs, table-attrs')) {
|
|
105
97
|
refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
|
|
106
|
-
errors.push({ ...refError, message:
|
|
98
|
+
errors.push({ ...refError, message: Parser.msg('section header in a HTML tag') });
|
|
107
99
|
}
|
|
108
100
|
return errors;
|
|
109
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* @override
|
|
104
|
+
* @browser
|
|
105
|
+
*/
|
|
106
|
+
print() {
|
|
107
|
+
const equals = this.#equals;
|
|
108
|
+
return super.print({ pre: equals, sep: equals });
|
|
109
|
+
}
|
|
110
110
|
/** @override */
|
|
111
111
|
cloneNode() {
|
|
112
112
|
const [title, trail] = this.cloneChildNodes();
|
|
113
|
-
return
|
|
114
|
-
// @ts-expect-error abstract class
|
|
113
|
+
return Parser.run(() => {
|
|
115
114
|
const token = new HeadingToken(this.level, [], this.getAttribute('config'));
|
|
116
115
|
token.firstChild.safeReplaceWith(title);
|
|
117
116
|
token.lastChild.safeReplaceWith(trail);
|
|
@@ -132,4 +131,4 @@ class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixed)(_1.Token)) {
|
|
|
132
131
|
}
|
|
133
132
|
}
|
|
134
133
|
exports.HeadingToken = HeadingToken;
|
|
135
|
-
|
|
134
|
+
Parser.classes['HeadingToken'] = __filename;
|
package/dist/src/hidden.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
+
import * as Parser from '../index';
|
|
1
2
|
import { Token } from '.';
|
|
2
3
|
declare const HiddenToken_base: ((abstract new (...args: any[]) => {
|
|
3
4
|
text(): string;
|
|
4
5
|
length: number;
|
|
5
|
-
toString(
|
|
6
|
+
toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
|
|
6
7
|
insertAt(token: unknown, i?: number | undefined): unknown;
|
|
7
8
|
}) & {
|
|
8
9
|
readonly hidden: true;
|
|
9
|
-
}) & typeof Token;
|
|
10
|
+
}) & typeof Parser.Token;
|
|
10
11
|
/** 不可见的节点 */
|
|
11
12
|
export declare class HiddenToken extends HiddenToken_base {
|
|
12
13
|
/** @browser */
|
|
13
14
|
readonly type = "hidden";
|
|
14
15
|
/** @browser */
|
|
15
|
-
constructor(wikitext?: string, config?:
|
|
16
|
+
constructor(wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
|
|
16
17
|
/** @override */
|
|
17
18
|
cloneNode(): this;
|
|
18
19
|
}
|
package/dist/src/hidden.js
CHANGED
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HiddenToken = void 0;
|
|
4
4
|
const hidden_1 = require("../mixin/hidden");
|
|
5
|
-
const
|
|
5
|
+
const Parser = require("../index");
|
|
6
6
|
const _1 = require(".");
|
|
7
7
|
/** 不可见的节点 */
|
|
8
8
|
class HiddenToken extends (0, hidden_1.hidden)(_1.Token) {
|
|
9
9
|
/** @browser */
|
|
10
10
|
type = 'hidden';
|
|
11
11
|
/** @browser */
|
|
12
|
-
constructor(wikitext, config =
|
|
12
|
+
constructor(wikitext, config = Parser.getConfig(), accum = [], acceptable) {
|
|
13
13
|
super(wikitext, config, true, accum, acceptable);
|
|
14
14
|
}
|
|
15
15
|
/** @override */
|
|
16
16
|
cloneNode() {
|
|
17
17
|
const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAttribute('acceptable');
|
|
18
|
-
return
|
|
18
|
+
return Parser.run(() => {
|
|
19
19
|
const token = new HiddenToken(undefined, config, [], acceptable);
|
|
20
20
|
token.append(...cloned);
|
|
21
21
|
return token;
|
|
@@ -23,4 +23,4 @@ class HiddenToken extends (0, hidden_1.hidden)(_1.Token) {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
exports.HiddenToken = HiddenToken;
|
|
26
|
-
|
|
26
|
+
Parser.classes['HiddenToken'] = __filename;
|
package/dist/src/html.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as Parser from '../index';
|
|
1
2
|
import { Token } from '.';
|
|
2
3
|
import type { LintError } from '../index';
|
|
3
4
|
import type { AttributesToken } from '../internal';
|
|
@@ -6,12 +7,13 @@ declare const HtmlToken_base: (abstract new (...args: any[]) => {
|
|
|
6
7
|
* HTML标签
|
|
7
8
|
* @classdesc `{childNodes: [AttributesToken]}`
|
|
8
9
|
*/
|
|
9
|
-
childNodes:
|
|
10
|
-
readonly "__#4@#attributesChild": AttributesToken;
|
|
10
|
+
childNodes: Parser.AstNodes[];
|
|
11
|
+
readonly "__#4@#attributesChild": Parser.AttributesToken;
|
|
11
12
|
readonly attributes: Record<string, string | true>;
|
|
12
13
|
className: string;
|
|
13
14
|
readonly classList: Set<string>;
|
|
14
15
|
id: string;
|
|
16
|
+
/** @browser */
|
|
15
17
|
hasAttr(key: string): boolean;
|
|
16
18
|
getAttr(key: string): string | true | undefined;
|
|
17
19
|
getAttrNames(): Set<string>;
|
|
@@ -21,24 +23,24 @@ declare const HtmlToken_base: (abstract new (...args: any[]) => {
|
|
|
21
23
|
removeAttr(key: string): void;
|
|
22
24
|
toggleAttr(key: string, force?: boolean | undefined): void;
|
|
23
25
|
length: number;
|
|
24
|
-
toString(
|
|
26
|
+
toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
|
|
25
27
|
text(separator?: string | undefined): string;
|
|
26
28
|
insertAt(token: unknown, i?: number | undefined): unknown;
|
|
27
29
|
}) & ((abstract new (...args: any[]) => {
|
|
28
30
|
removeAt(): never;
|
|
29
|
-
insertAt(token: string, i?: number | undefined):
|
|
30
|
-
insertAt<T extends
|
|
31
|
+
insertAt(token: string, i?: number | undefined): Parser.AstText;
|
|
32
|
+
insertAt<T extends Parser.AstNodes>(token: T, i?: number | undefined): T;
|
|
31
33
|
length: number;
|
|
32
|
-
toString(
|
|
34
|
+
toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
|
|
33
35
|
text(separator?: string | undefined): string;
|
|
34
36
|
}) & {
|
|
35
37
|
readonly fixed: true;
|
|
36
|
-
}) & typeof Token;
|
|
38
|
+
}) & typeof Parser.Token;
|
|
37
39
|
/**
|
|
38
40
|
* HTML标签
|
|
39
41
|
* @classdesc `{childNodes: [AttributesToken]}`
|
|
40
42
|
*/
|
|
41
|
-
export declare
|
|
43
|
+
export declare class HtmlToken extends HtmlToken_base {
|
|
42
44
|
#private;
|
|
43
45
|
/** @browser */
|
|
44
46
|
readonly type = "html";
|
|
@@ -67,22 +69,17 @@ export declare abstract class HtmlToken extends HtmlToken_base {
|
|
|
67
69
|
* @param closing 是否闭合
|
|
68
70
|
* @param selfClosing 是否自封闭
|
|
69
71
|
*/
|
|
70
|
-
constructor(name: string, attr: AttributesToken, closing: boolean, selfClosing: boolean, config?:
|
|
72
|
+
constructor(name: string, attr: AttributesToken, closing: boolean, selfClosing: boolean, config?: Parser.Config, accum?: Token[]);
|
|
71
73
|
/**
|
|
72
74
|
* @override
|
|
73
75
|
* @browser
|
|
74
76
|
*/
|
|
75
|
-
toString(
|
|
77
|
+
toString(omit?: Set<string>): string;
|
|
76
78
|
/**
|
|
77
79
|
* @override
|
|
78
80
|
* @browser
|
|
79
81
|
*/
|
|
80
82
|
text(): string;
|
|
81
|
-
/**
|
|
82
|
-
* @override
|
|
83
|
-
* @browser
|
|
84
|
-
*/
|
|
85
|
-
print(): string;
|
|
86
83
|
/**
|
|
87
84
|
* @override
|
|
88
85
|
* @browser
|
|
@@ -96,6 +93,11 @@ export declare abstract class HtmlToken extends HtmlToken_base {
|
|
|
96
93
|
* @throws `SyntaxError` 未闭合的标签
|
|
97
94
|
*/
|
|
98
95
|
findMatchingTag(): this | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* @override
|
|
98
|
+
* @browser
|
|
99
|
+
*/
|
|
100
|
+
print(): string;
|
|
99
101
|
/** @override */
|
|
100
102
|
cloneNode(): this;
|
|
101
103
|
/**
|
package/dist/src/html.js
CHANGED
|
@@ -5,7 +5,7 @@ const lint_1 = require("../util/lint");
|
|
|
5
5
|
const string_1 = require("../util/string");
|
|
6
6
|
const fixed_1 = require("../mixin/fixed");
|
|
7
7
|
const attributesParent_1 = require("../mixin/attributesParent");
|
|
8
|
-
const
|
|
8
|
+
const Parser = require("../index");
|
|
9
9
|
const _1 = require(".");
|
|
10
10
|
const magicWords = new Set(['if', 'ifeq', 'ifexpr', 'ifexist', 'iferror', 'switch']);
|
|
11
11
|
/**
|
|
@@ -69,7 +69,7 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
|
|
|
69
69
|
* @param closing 是否闭合
|
|
70
70
|
* @param selfClosing 是否自封闭
|
|
71
71
|
*/
|
|
72
|
-
constructor(name, attr, closing, selfClosing, config =
|
|
72
|
+
constructor(name, attr, closing, selfClosing, config = Parser.getConfig(), accum = []) {
|
|
73
73
|
super(undefined, config, true, accum);
|
|
74
74
|
this.insertAt(attr);
|
|
75
75
|
this.setAttribute('name', name.toLowerCase());
|
|
@@ -81,10 +81,10 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
|
|
|
81
81
|
* @override
|
|
82
82
|
* @browser
|
|
83
83
|
*/
|
|
84
|
-
toString(
|
|
85
|
-
return
|
|
84
|
+
toString(omit) {
|
|
85
|
+
return omit && this.matchesTypes(omit)
|
|
86
86
|
? ''
|
|
87
|
-
: `<${this.#closing ? '/' : ''}${this.#tag}${super.toString(
|
|
87
|
+
: `<${this.#closing ? '/' : ''}${this.#tag}${super.toString(omit)}${this.#selfClosing ? '/' : ''}>`;
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* @override
|
|
@@ -97,16 +97,6 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
|
|
|
97
97
|
getPadding() {
|
|
98
98
|
return this.#tag.length + (this.#closing ? 2 : 1);
|
|
99
99
|
}
|
|
100
|
-
/**
|
|
101
|
-
* @override
|
|
102
|
-
* @browser
|
|
103
|
-
*/
|
|
104
|
-
print() {
|
|
105
|
-
return super.print({
|
|
106
|
-
pre: `<${this.#closing ? '/' : ''}${this.#tag}`,
|
|
107
|
-
post: `${this.#selfClosing ? '/' : ''}>`,
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
100
|
/**
|
|
111
101
|
* @override
|
|
112
102
|
* @browser
|
|
@@ -122,8 +112,11 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
|
|
|
122
112
|
if (this.closest('table-attrs')) {
|
|
123
113
|
wikitext ??= String(this.getRootNode());
|
|
124
114
|
refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
|
|
125
|
-
|
|
126
|
-
|
|
115
|
+
errors.push({
|
|
116
|
+
...refError,
|
|
117
|
+
message: Parser.msg('HTML tag in table attributes'),
|
|
118
|
+
excerpt: wikitext.slice(Math.max(0, start - 25), start + 25),
|
|
119
|
+
});
|
|
127
120
|
}
|
|
128
121
|
try {
|
|
129
122
|
this.findMatchingTag();
|
|
@@ -133,7 +126,7 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
|
|
|
133
126
|
const { message: errorMsg } = e;
|
|
134
127
|
wikitext ??= String(this.getRootNode());
|
|
135
128
|
refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
|
|
136
|
-
const [msg] = errorMsg.split(':'), error = { ...refError, message:
|
|
129
|
+
const [msg] = errorMsg.split(':'), error = { ...refError, message: Parser.msg(msg) };
|
|
137
130
|
if (msg === 'unclosed tag') {
|
|
138
131
|
error.severity = 'warning';
|
|
139
132
|
error.excerpt = wikitext.slice(start, start + 50);
|
|
@@ -188,11 +181,20 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
|
|
|
188
181
|
}
|
|
189
182
|
throw new SyntaxError(`${this.#closing ? 'unmatched closing' : 'unclosed'} tag: ${string}`);
|
|
190
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* @override
|
|
186
|
+
* @browser
|
|
187
|
+
*/
|
|
188
|
+
print() {
|
|
189
|
+
return super.print({
|
|
190
|
+
pre: `<${this.#closing ? '/' : ''}${this.#tag}`,
|
|
191
|
+
post: `${this.#selfClosing ? '/' : ''}>`,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
191
194
|
/** @override */
|
|
192
195
|
cloneNode() {
|
|
193
196
|
const [attr] = this.cloneChildNodes(), config = this.getAttribute('config');
|
|
194
|
-
|
|
195
|
-
return index_1.default.run(() => new HtmlToken(this.#tag, attr, this.#closing, this.#selfClosing, config));
|
|
197
|
+
return Parser.run(() => new HtmlToken(this.#tag, attr, this.#closing, this.#selfClosing, config));
|
|
196
198
|
}
|
|
197
199
|
/** @private */
|
|
198
200
|
getAttribute(key) {
|
|
@@ -213,7 +215,7 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
|
|
|
213
215
|
/** 局部闭合 */
|
|
214
216
|
#localMatch() {
|
|
215
217
|
this.#selfClosing = false;
|
|
216
|
-
const root =
|
|
218
|
+
const root = Parser.parse(`</${this.name}>`, false, 3, this.getAttribute('config'));
|
|
217
219
|
this.after(root.firstChild);
|
|
218
220
|
}
|
|
219
221
|
/**
|
|
@@ -236,10 +238,10 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
|
|
|
236
238
|
this.#closing = true;
|
|
237
239
|
}
|
|
238
240
|
else {
|
|
239
|
-
|
|
241
|
+
Parser.warn('无法修复无效自封闭标签', (0, string_1.noWrap)(String(this)));
|
|
240
242
|
throw new Error(`无法修复无效自封闭标签:前文共有 ${imbalance} 个未匹配的闭合标签`);
|
|
241
243
|
}
|
|
242
244
|
}
|
|
243
245
|
}
|
|
244
246
|
exports.HtmlToken = HtmlToken;
|
|
245
|
-
|
|
247
|
+
Parser.classes['HtmlToken'] = __filename;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import * as Parser from '../index';
|
|
1
2
|
import { Token } from '.';
|
|
2
|
-
import type { LintError
|
|
3
|
+
import type { LintError } from '../index';
|
|
3
4
|
import type { Title } from '../lib/title';
|
|
4
5
|
import type { AstNodes, AstText, AtomToken, FileToken } from '../internal';
|
|
5
6
|
/** 图片参数 */
|
|
6
|
-
export declare
|
|
7
|
+
export declare class ImageParameterToken extends Token {
|
|
7
8
|
#private;
|
|
8
9
|
/** @browser */
|
|
9
10
|
readonly type = "image-parameter";
|
|
@@ -38,12 +39,12 @@ export declare abstract class ImageParameterToken extends Token {
|
|
|
38
39
|
* @browser
|
|
39
40
|
* @param str 图片参数
|
|
40
41
|
*/
|
|
41
|
-
constructor(str: string, config?: Config, accum?: Token[]);
|
|
42
|
+
constructor(str: string, config?: Parser.Config, accum?: Token[]);
|
|
42
43
|
/**
|
|
43
44
|
* @override
|
|
44
45
|
* @browser
|
|
45
46
|
*/
|
|
46
|
-
toString(
|
|
47
|
+
toString(omit?: Set<string>): string;
|
|
47
48
|
/**
|
|
48
49
|
* @override
|
|
49
50
|
* @browser
|
|
@@ -3,28 +3,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ImageParameterToken = void 0;
|
|
4
4
|
const string_1 = require("../util/string");
|
|
5
5
|
const lint_1 = require("../util/lint");
|
|
6
|
-
const
|
|
6
|
+
const Parser = require("../index");
|
|
7
7
|
const _1 = require(".");
|
|
8
8
|
const params = new Set(['alt', 'link', 'lang', 'page', 'caption']);
|
|
9
9
|
/** @ignore */
|
|
10
|
-
function validate(key, val, config =
|
|
11
|
-
|
|
12
|
-
let value =
|
|
10
|
+
function validate(key, val, config = Parser.getConfig(), halfParsed = false) {
|
|
11
|
+
val = val.trim();
|
|
12
|
+
let value = val.replace(/\0\d+t\x7F/gu, '').trim();
|
|
13
13
|
switch (key) {
|
|
14
14
|
case 'width':
|
|
15
15
|
return /^(?:\d+x?|\d*x\d+)$/u.test(value);
|
|
16
16
|
case 'link': {
|
|
17
17
|
if (!value) {
|
|
18
|
-
return
|
|
18
|
+
return val;
|
|
19
19
|
}
|
|
20
20
|
const regex = new RegExp(`^(?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\\d+m\x7F)${string_1.extUrlChar}$`, 'iu');
|
|
21
21
|
if (regex.test(value)) {
|
|
22
|
-
return
|
|
22
|
+
return val;
|
|
23
23
|
}
|
|
24
24
|
else if (value.startsWith('[[') && value.endsWith(']]')) {
|
|
25
25
|
value = value.slice(2, -2);
|
|
26
26
|
}
|
|
27
|
-
const title =
|
|
27
|
+
const title = Parser.normalizeTitle(value, 0, false, config, halfParsed, true, true);
|
|
28
28
|
return title.valid && title;
|
|
29
29
|
}
|
|
30
30
|
case 'lang':
|
|
@@ -71,7 +71,7 @@ class ImageParameterToken extends _1.Token {
|
|
|
71
71
|
const [width, height = ''] = size.split('x');
|
|
72
72
|
return { width, height };
|
|
73
73
|
}
|
|
74
|
-
const token =
|
|
74
|
+
const token = Parser.parse(size, false, 2, this.getAttribute('config')), i = token.childNodes.findIndex(child => child.type === 'text' && child.data.includes('x')), str = token.childNodes[i];
|
|
75
75
|
if (i === -1) {
|
|
76
76
|
return { width: size, height: '' };
|
|
77
77
|
}
|
|
@@ -104,7 +104,7 @@ class ImageParameterToken extends _1.Token {
|
|
|
104
104
|
* @browser
|
|
105
105
|
* @param str 图片参数
|
|
106
106
|
*/
|
|
107
|
-
constructor(str, config =
|
|
107
|
+
constructor(str, config = Parser.getConfig(), accum = []) {
|
|
108
108
|
let mt;
|
|
109
109
|
const regexes = Object.entries(config.img).map(([syntax, param]) => [
|
|
110
110
|
syntax,
|
|
@@ -147,10 +147,10 @@ class ImageParameterToken extends _1.Token {
|
|
|
147
147
|
* @override
|
|
148
148
|
* @browser
|
|
149
149
|
*/
|
|
150
|
-
toString(
|
|
151
|
-
return this.#syntax && !(
|
|
152
|
-
? this.#syntax.replace('$1', super.toString(
|
|
153
|
-
: super.toString(
|
|
150
|
+
toString(omit) {
|
|
151
|
+
return this.#syntax && !(omit && this.matchesTypes(omit))
|
|
152
|
+
? this.#syntax.replace('$1', super.toString(omit))
|
|
153
|
+
: super.toString(omit);
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
156
|
* @override
|
|
@@ -168,8 +168,8 @@ class ImageParameterToken extends _1.Token {
|
|
|
168
168
|
* @browser
|
|
169
169
|
*/
|
|
170
170
|
lint(start = this.getAbsoluteIndex()) {
|
|
171
|
-
const errors = super.lint(start), { link } = this;
|
|
172
|
-
if (
|
|
171
|
+
const errors = super.lint(start), { link, name } = this;
|
|
172
|
+
if (name === 'invalid') {
|
|
173
173
|
errors.push((0, lint_1.generateForSelf)(this, { start }, 'invalid gallery image parameter'));
|
|
174
174
|
}
|
|
175
175
|
else if (typeof link === 'object' && link.encoded) {
|
|
@@ -189,8 +189,7 @@ class ImageParameterToken extends _1.Token {
|
|
|
189
189
|
/** @override */
|
|
190
190
|
cloneNode() {
|
|
191
191
|
const cloned = this.cloneChildNodes(), config = this.getAttribute('config');
|
|
192
|
-
return
|
|
193
|
-
// @ts-expect-error abstract class
|
|
192
|
+
return Parser.run(() => {
|
|
194
193
|
const token = new ImageParameterToken(this.#syntax.replace('$1', ''), config);
|
|
195
194
|
token.replaceChildren(...cloned);
|
|
196
195
|
return token;
|
|
@@ -210,7 +209,7 @@ class ImageParameterToken extends _1.Token {
|
|
|
210
209
|
}
|
|
211
210
|
/** @ignore */
|
|
212
211
|
insertAt(token, i = this.length) {
|
|
213
|
-
if (!
|
|
212
|
+
if (!Parser.running && this.#isVoid()) {
|
|
214
213
|
throw new Error(`图片参数 ${this.name} 不接受自定义输入!`);
|
|
215
214
|
}
|
|
216
215
|
return super.insertAt(token, i);
|
|
@@ -241,16 +240,16 @@ class ImageParameterToken extends _1.Token {
|
|
|
241
240
|
else if (typeof value !== 'string') {
|
|
242
241
|
this.typeError('setValue', 'String');
|
|
243
242
|
}
|
|
244
|
-
const root =
|
|
243
|
+
const root = Parser.parse(`[[File:F|${this.#syntax ? this.#syntax.replace('$1', value) : value}]]`, this.getAttribute('include'), 6, this.getAttribute('config')), { length, firstChild: file } = root;
|
|
245
244
|
if (length !== 1 || file.type !== 'file' || file.length !== 2) {
|
|
246
245
|
throw new SyntaxError(`非法的 ${this.name} 参数:${(0, string_1.noWrap)(value)}`);
|
|
247
246
|
}
|
|
248
247
|
const { lastChild: imageParameter, name } = file;
|
|
249
|
-
if (name
|
|
250
|
-
this.
|
|
248
|
+
if (name !== 'File:F' || imageParameter.name !== this.name) {
|
|
249
|
+
throw new SyntaxError(`非法的 ${this.name} 参数:${(0, string_1.noWrap)(value)}`);
|
|
251
250
|
}
|
|
252
|
-
|
|
251
|
+
this.replaceChildren(...imageParameter.childNodes);
|
|
253
252
|
}
|
|
254
253
|
}
|
|
255
254
|
exports.ImageParameterToken = ImageParameterToken;
|
|
256
|
-
|
|
255
|
+
Parser.classes['ImageParameterToken'] = __filename;
|