wikiparser-node 1.0.0-beta.0 → 1.0.0-beta.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/config/.schema.json +26 -0
- package/dist/index.d.ts +11 -9
- package/dist/index.js +22 -24
- package/dist/internal.d.ts +44 -0
- package/dist/lib/element.d.ts +42 -32
- package/dist/lib/element.js +59 -56
- package/dist/lib/node.d.ts +29 -36
- package/dist/lib/node.js +33 -48
- package/dist/lib/range.d.ts +132 -0
- package/dist/lib/range.js +387 -0
- package/dist/lib/ranges.d.ts +2 -12
- package/dist/lib/ranges.js +6 -11
- package/dist/lib/text.d.ts +11 -5
- package/dist/lib/text.js +25 -13
- package/dist/lib/title.d.ts +4 -5
- package/dist/lib/title.js +17 -7
- package/dist/mixin/attributesParent.js +6 -3
- package/dist/mixin/fixed.js +8 -5
- package/dist/mixin/hidden.js +7 -3
- package/dist/mixin/singleLine.js +6 -3
- package/dist/mixin/sol.js +6 -3
- package/dist/parser/{brackets.js → braces.js} +34 -26
- package/dist/parser/commentAndExt.js +25 -15
- package/dist/parser/converter.js +16 -9
- package/dist/parser/externalLinks.js +15 -9
- package/dist/parser/hrAndDoubleUnderscore.js +17 -10
- package/dist/parser/html.js +18 -9
- package/dist/parser/links.js +22 -14
- package/dist/parser/list.js +20 -10
- package/dist/parser/magicLinks.js +14 -7
- package/dist/parser/quotes.js +21 -11
- package/dist/parser/selector.js +19 -12
- package/dist/parser/table.js +25 -16
- package/dist/src/arg.d.ts +7 -8
- package/dist/src/arg.js +27 -24
- package/dist/src/atom.d.ts +4 -5
- package/dist/src/atom.js +9 -7
- package/dist/src/attribute.d.ts +13 -13
- package/dist/src/attribute.js +28 -25
- package/dist/src/attributes.d.ts +11 -10
- package/dist/src/attributes.js +40 -45
- package/dist/src/converter.d.ts +5 -7
- package/dist/src/converter.js +22 -16
- package/dist/src/converterFlags.d.ts +11 -12
- package/dist/src/converterFlags.js +17 -14
- package/dist/src/converterRule.d.ts +9 -10
- package/dist/src/converterRule.js +27 -27
- package/dist/src/extLink.d.ts +4 -6
- package/dist/src/extLink.js +25 -22
- package/dist/src/gallery.d.ts +9 -13
- package/dist/src/gallery.js +28 -23
- package/dist/src/heading.d.ts +11 -11
- package/dist/src/heading.js +19 -19
- package/dist/src/hidden.d.ts +4 -5
- package/dist/src/hidden.js +10 -8
- package/dist/src/html.d.ts +15 -12
- package/dist/src/html.js +18 -15
- package/dist/src/imageParameter.d.ts +11 -13
- package/dist/src/imageParameter.js +21 -16
- package/dist/src/imagemap.d.ts +11 -15
- package/dist/src/imagemap.js +26 -21
- package/dist/src/imagemapLink.d.ts +12 -17
- package/dist/src/imagemapLink.js +19 -14
- package/dist/src/index.d.ts +24 -20
- package/dist/src/index.js +65 -75
- package/dist/src/link/base.d.ts +8 -10
- package/dist/src/link/base.js +28 -22
- package/dist/src/link/category.d.ts +2 -3
- package/dist/src/link/category.js +7 -5
- package/dist/src/link/file.d.ts +9 -11
- package/dist/src/link/file.js +53 -26
- package/dist/src/link/galleryImage.d.ts +8 -8
- package/dist/src/link/galleryImage.js +18 -16
- package/dist/src/link/index.d.ts +6 -6
- package/dist/src/link/index.js +14 -16
- package/dist/src/magicLink.d.ts +9 -6
- package/dist/src/magicLink.js +23 -18
- package/dist/src/nested.d.ts +10 -10
- package/dist/src/nested.js +25 -17
- package/dist/src/nowiki/base.d.ts +7 -8
- package/dist/src/nowiki/base.js +10 -8
- package/dist/src/nowiki/comment.d.ts +7 -7
- package/dist/src/nowiki/comment.js +12 -9
- package/dist/src/nowiki/dd.d.ts +2 -3
- package/dist/src/nowiki/dd.js +7 -11
- package/dist/src/nowiki/doubleUnderscore.d.ts +5 -7
- package/dist/src/nowiki/doubleUnderscore.js +11 -8
- package/dist/src/nowiki/hr.d.ts +6 -7
- package/dist/src/nowiki/hr.js +11 -8
- package/dist/src/nowiki/index.d.ts +5 -7
- package/dist/src/nowiki/index.js +8 -6
- package/dist/src/nowiki/list.d.ts +4 -4
- package/dist/src/nowiki/list.js +8 -6
- package/dist/src/nowiki/noinclude.d.ts +3 -3
- package/dist/src/nowiki/noinclude.js +8 -6
- package/dist/src/nowiki/quote.d.ts +6 -7
- package/dist/src/nowiki/quote.js +11 -8
- package/dist/src/onlyinclude.d.ts +3 -5
- package/dist/src/onlyinclude.js +9 -7
- package/dist/src/paramTag/index.d.ts +8 -10
- package/dist/src/paramTag/index.js +15 -13
- package/dist/src/paramTag/inputbox.d.ts +4 -6
- package/dist/src/paramTag/inputbox.js +10 -8
- package/dist/src/parameter.d.ts +11 -12
- package/dist/src/parameter.js +25 -22
- package/dist/src/pre.d.ts +5 -10
- package/dist/src/pre.js +16 -11
- package/dist/src/syntax.d.ts +6 -7
- package/dist/src/syntax.js +12 -10
- package/dist/src/table/base.d.ts +14 -9
- package/dist/src/table/base.js +18 -15
- package/dist/src/table/index.d.ts +24 -17
- package/dist/src/table/index.js +39 -67
- package/dist/src/table/td.d.ts +17 -21
- package/dist/src/table/td.js +20 -28
- package/dist/src/table/tr.d.ts +6 -11
- package/dist/src/table/tr.js +8 -6
- package/dist/src/table/trBase.d.ts +12 -22
- package/dist/src/table/trBase.js +23 -19
- package/dist/src/tagPair/ext.d.ts +10 -10
- package/dist/src/tagPair/ext.js +47 -24
- package/dist/src/tagPair/include.d.ts +6 -7
- package/dist/src/tagPair/include.js +11 -8
- package/dist/src/tagPair/index.d.ts +12 -11
- package/dist/src/tagPair/index.js +13 -11
- package/dist/src/transclude.d.ts +8 -10
- package/dist/src/transclude.js +70 -77
- package/dist/util/debug.js +2 -12
- package/dist/util/diff.js +4 -2
- package/dist/util/lint.js +5 -5
- package/dist/util/string.js +2 -31
- package/package.json +13 -13
- package/dist/util/base.js +0 -26
package/dist/src/heading.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HeadingToken = void 0;
|
|
2
4
|
const lint_1 = require("../util/lint");
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const fixed_1 = require("../mixin/fixed");
|
|
6
|
+
const sol_1 = require("../mixin/sol");
|
|
7
|
+
const index_1 = require("../index");
|
|
8
|
+
const _1 = require(".");
|
|
9
|
+
const syntax_1 = require("./syntax");
|
|
8
10
|
/**
|
|
9
11
|
* 章节标题
|
|
10
12
|
* @classdesc `{childNodes: [Token, SyntaxToken]}`
|
|
11
13
|
*/
|
|
12
|
-
class HeadingToken extends sol(fixed(Token)) {
|
|
14
|
+
class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixed)(_1.Token)) {
|
|
13
15
|
/** @browser */
|
|
14
16
|
type = 'heading';
|
|
15
17
|
/**
|
|
@@ -39,13 +41,13 @@ class HeadingToken extends sol(fixed(Token)) {
|
|
|
39
41
|
* @param level 标题层级
|
|
40
42
|
* @param input 标题文字
|
|
41
43
|
*/
|
|
42
|
-
constructor(level, input, config =
|
|
44
|
+
constructor(level, input, config = index_1.default.getConfig(), accum = []) {
|
|
43
45
|
super(undefined, config, true, accum);
|
|
44
46
|
this.setAttribute('name', String(level));
|
|
45
|
-
const token = new Token(input[0], config, true, accum);
|
|
47
|
+
const token = new _1.Token(input[0], config, true, accum);
|
|
46
48
|
token.type = 'heading-title';
|
|
47
49
|
token.setAttribute('stage', 2);
|
|
48
|
-
const trail = new SyntaxToken(input[1], /^[^\S\n]*$/u, 'heading-trail', config, accum, {
|
|
50
|
+
const trail = new syntax_1.SyntaxToken(input[1], /^[^\S\n]*$/u, 'heading-trail', config, accum, {
|
|
49
51
|
'Stage-1': ':', '!ExtToken': '',
|
|
50
52
|
});
|
|
51
53
|
this.append(token, trail);
|
|
@@ -73,8 +75,8 @@ class HeadingToken extends sol(fixed(Token)) {
|
|
|
73
75
|
return super.getPadding() + this.level;
|
|
74
76
|
}
|
|
75
77
|
/** @private */
|
|
76
|
-
getGaps() {
|
|
77
|
-
return this.level;
|
|
78
|
+
getGaps(i) {
|
|
79
|
+
return i === 0 ? this.level : 0;
|
|
78
80
|
}
|
|
79
81
|
/**
|
|
80
82
|
* @override
|
|
@@ -97,18 +99,19 @@ class HeadingToken extends sol(fixed(Token)) {
|
|
|
97
99
|
}
|
|
98
100
|
if (innerStr.startsWith('=') || innerStr.endsWith('=')) {
|
|
99
101
|
refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
|
|
100
|
-
errors.push({ ...refError, message:
|
|
102
|
+
errors.push({ ...refError, message: index_1.default.msg('unbalanced "=" in a section header') });
|
|
101
103
|
}
|
|
102
104
|
if (this.closest('html-attrs, table-attrs')) {
|
|
103
105
|
refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
|
|
104
|
-
errors.push({ ...refError, message:
|
|
106
|
+
errors.push({ ...refError, message: index_1.default.msg('section header in a HTML tag') });
|
|
105
107
|
}
|
|
106
108
|
return errors;
|
|
107
109
|
}
|
|
108
110
|
/** @override */
|
|
109
111
|
cloneNode() {
|
|
110
112
|
const [title, trail] = this.cloneChildNodes();
|
|
111
|
-
return
|
|
113
|
+
return index_1.default.run(() => {
|
|
114
|
+
// @ts-expect-error abstract class
|
|
112
115
|
const token = new HeadingToken(this.level, [], this.getAttribute('config'));
|
|
113
116
|
token.firstChild.safeReplaceWith(title);
|
|
114
117
|
token.lastChild.safeReplaceWith(trail);
|
|
@@ -120,9 +123,6 @@ class HeadingToken extends sol(fixed(Token)) {
|
|
|
120
123
|
* @param n 标题层级
|
|
121
124
|
*/
|
|
122
125
|
setLevel(n) {
|
|
123
|
-
if (!Number.isInteger(n)) {
|
|
124
|
-
this.typeError('setLevel', 'Number');
|
|
125
|
-
}
|
|
126
126
|
const level = String(Math.min(Math.max(n, 1), 6));
|
|
127
127
|
this.setAttribute('name', level);
|
|
128
128
|
}
|
|
@@ -131,5 +131,5 @@ class HeadingToken extends sol(fixed(Token)) {
|
|
|
131
131
|
this.lastChild.replaceChildren();
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
exports.HeadingToken = HeadingToken;
|
|
135
|
+
index_1.default.classes['HeadingToken'] = __filename;
|
package/dist/src/hidden.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import Token = require('.');
|
|
1
|
+
import { Token } from '.';
|
|
3
2
|
declare const HiddenToken_base: ((abstract new (...args: any[]) => {
|
|
4
3
|
text(): string;
|
|
5
4
|
length: number;
|
|
@@ -9,12 +8,12 @@ declare const HiddenToken_base: ((abstract new (...args: any[]) => {
|
|
|
9
8
|
readonly hidden: true;
|
|
10
9
|
}) & typeof Token;
|
|
11
10
|
/** 不可见的节点 */
|
|
12
|
-
declare class HiddenToken extends HiddenToken_base {
|
|
11
|
+
export declare class HiddenToken extends HiddenToken_base {
|
|
13
12
|
/** @browser */
|
|
14
13
|
readonly type = "hidden";
|
|
15
14
|
/** @browser */
|
|
16
|
-
constructor(wikitext?: string, config?:
|
|
15
|
+
constructor(wikitext?: string, config?: import("../index").Config, accum?: Token[], acceptable?: Acceptable);
|
|
17
16
|
/** @override */
|
|
18
17
|
cloneNode(): this;
|
|
19
18
|
}
|
|
20
|
-
export
|
|
19
|
+
export {};
|
package/dist/src/hidden.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HiddenToken = void 0;
|
|
4
|
+
const hidden_1 = require("../mixin/hidden");
|
|
5
|
+
const index_1 = require("../index");
|
|
6
|
+
const _1 = require(".");
|
|
5
7
|
/** 不可见的节点 */
|
|
6
|
-
class HiddenToken extends hidden(Token) {
|
|
8
|
+
class HiddenToken extends (0, hidden_1.hidden)(_1.Token) {
|
|
7
9
|
/** @browser */
|
|
8
10
|
type = 'hidden';
|
|
9
11
|
/** @browser */
|
|
10
|
-
constructor(wikitext, config =
|
|
12
|
+
constructor(wikitext, config = index_1.default.getConfig(), accum = [], acceptable) {
|
|
11
13
|
super(wikitext, config, true, accum, acceptable);
|
|
12
14
|
}
|
|
13
15
|
/** @override */
|
|
14
16
|
cloneNode() {
|
|
15
17
|
const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAttribute('acceptable');
|
|
16
|
-
return
|
|
18
|
+
return index_1.default.run(() => {
|
|
17
19
|
const token = new HiddenToken(undefined, config, [], acceptable);
|
|
18
20
|
token.append(...cloned);
|
|
19
21
|
return token;
|
|
20
22
|
});
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
exports.HiddenToken = HiddenToken;
|
|
26
|
+
index_1.default.classes['HiddenToken'] = __filename;
|
package/dist/src/html.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import AttributesToken
|
|
4
|
-
import type { TokenAttributeGetter } from '../lib/node';
|
|
1
|
+
import { Token } from '.';
|
|
2
|
+
import type { LintError } from '../index';
|
|
3
|
+
import type { AttributesToken } from '../internal';
|
|
5
4
|
declare const HtmlToken_base: (abstract new (...args: any[]) => {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
/**
|
|
6
|
+
* HTML标签
|
|
7
|
+
* @classdesc `{childNodes: [AttributesToken]}`
|
|
8
|
+
*/
|
|
9
|
+
childNodes: import("../index").AstNodes[];
|
|
10
|
+
readonly "__#4@#attributesChild": AttributesToken;
|
|
8
11
|
readonly attributes: Record<string, string | true>;
|
|
9
12
|
className: string;
|
|
10
13
|
readonly classList: Set<string>;
|
|
@@ -23,8 +26,8 @@ declare const HtmlToken_base: (abstract new (...args: any[]) => {
|
|
|
23
26
|
insertAt(token: unknown, i?: number | undefined): unknown;
|
|
24
27
|
}) & ((abstract new (...args: any[]) => {
|
|
25
28
|
removeAt(): never;
|
|
26
|
-
insertAt(token: string, i?: number | undefined): import("../
|
|
27
|
-
insertAt<T extends import("../
|
|
29
|
+
insertAt(token: string, i?: number | undefined): import("../index").AstText;
|
|
30
|
+
insertAt<T extends import("../index").AstNodes>(token: T, i?: number | undefined): T;
|
|
28
31
|
length: number;
|
|
29
32
|
toString(selector?: string | undefined, separator?: string | undefined): string;
|
|
30
33
|
text(separator?: string | undefined): string;
|
|
@@ -35,7 +38,7 @@ declare const HtmlToken_base: (abstract new (...args: any[]) => {
|
|
|
35
38
|
* HTML标签
|
|
36
39
|
* @classdesc `{childNodes: [AttributesToken]}`
|
|
37
40
|
*/
|
|
38
|
-
declare abstract class HtmlToken extends HtmlToken_base {
|
|
41
|
+
export declare abstract class HtmlToken extends HtmlToken_base {
|
|
39
42
|
#private;
|
|
40
43
|
/** @browser */
|
|
41
44
|
readonly type = "html";
|
|
@@ -64,7 +67,7 @@ declare abstract class HtmlToken extends HtmlToken_base {
|
|
|
64
67
|
* @param closing 是否闭合
|
|
65
68
|
* @param selfClosing 是否自封闭
|
|
66
69
|
*/
|
|
67
|
-
constructor(name: string, attr: AttributesToken, closing: boolean, selfClosing: boolean, config?:
|
|
70
|
+
constructor(name: string, attr: AttributesToken, closing: boolean, selfClosing: boolean, config?: import("../index").Config, accum?: Token[]);
|
|
68
71
|
/**
|
|
69
72
|
* @override
|
|
70
73
|
* @browser
|
|
@@ -84,7 +87,7 @@ declare abstract class HtmlToken extends HtmlToken_base {
|
|
|
84
87
|
* @override
|
|
85
88
|
* @browser
|
|
86
89
|
*/
|
|
87
|
-
lint(start?: number):
|
|
90
|
+
lint(start?: number): LintError[];
|
|
88
91
|
/**
|
|
89
92
|
* 搜索匹配的标签
|
|
90
93
|
* @browser
|
|
@@ -107,4 +110,4 @@ declare abstract class HtmlToken extends HtmlToken_base {
|
|
|
107
110
|
*/
|
|
108
111
|
fix(): void;
|
|
109
112
|
}
|
|
110
|
-
export
|
|
113
|
+
export {};
|
package/dist/src/html.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HtmlToken = void 0;
|
|
2
4
|
const lint_1 = require("../util/lint");
|
|
3
5
|
const string_1 = require("../util/string");
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const fixed_1 = require("../mixin/fixed");
|
|
7
|
+
const attributesParent_1 = require("../mixin/attributesParent");
|
|
8
|
+
const index_1 = require("../index");
|
|
9
|
+
const _1 = require(".");
|
|
8
10
|
const magicWords = new Set(['if', 'ifeq', 'ifexpr', 'ifexist', 'iferror', 'switch']);
|
|
9
11
|
/**
|
|
10
12
|
* HTML标签
|
|
11
13
|
* @classdesc `{childNodes: [AttributesToken]}`
|
|
12
14
|
*/
|
|
13
|
-
class HtmlToken extends attributesParent(fixed(Token)) {
|
|
15
|
+
class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fixed)(_1.Token)) {
|
|
14
16
|
/** @browser */
|
|
15
17
|
type = 'html';
|
|
16
18
|
/** @browser */
|
|
@@ -67,7 +69,7 @@ class HtmlToken extends attributesParent(fixed(Token)) {
|
|
|
67
69
|
* @param closing 是否闭合
|
|
68
70
|
* @param selfClosing 是否自封闭
|
|
69
71
|
*/
|
|
70
|
-
constructor(name, attr, closing, selfClosing, config =
|
|
72
|
+
constructor(name, attr, closing, selfClosing, config = index_1.default.getConfig(), accum = []) {
|
|
71
73
|
super(undefined, config, true, accum);
|
|
72
74
|
this.insertAt(attr);
|
|
73
75
|
this.setAttribute('name', name.toLowerCase());
|
|
@@ -121,7 +123,7 @@ class HtmlToken extends attributesParent(fixed(Token)) {
|
|
|
121
123
|
wikitext ??= String(this.getRootNode());
|
|
122
124
|
refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
|
|
123
125
|
const excerpt = wikitext.slice(Math.max(0, start - 25), start + 25);
|
|
124
|
-
errors.push({ ...refError, message:
|
|
126
|
+
errors.push({ ...refError, message: index_1.default.msg('HTML tag in table attributes'), excerpt });
|
|
125
127
|
}
|
|
126
128
|
try {
|
|
127
129
|
this.findMatchingTag();
|
|
@@ -131,15 +133,15 @@ class HtmlToken extends attributesParent(fixed(Token)) {
|
|
|
131
133
|
const { message: errorMsg } = e;
|
|
132
134
|
wikitext ??= String(this.getRootNode());
|
|
133
135
|
refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
|
|
134
|
-
const [msg] = errorMsg.split(':'), error = { ...refError, message:
|
|
136
|
+
const [msg] = errorMsg.split(':'), error = { ...refError, message: index_1.default.msg(msg) };
|
|
135
137
|
if (msg === 'unclosed tag') {
|
|
136
138
|
error.severity = 'warning';
|
|
137
139
|
error.excerpt = wikitext.slice(start, start + 50);
|
|
138
140
|
}
|
|
139
141
|
else if (msg === 'unmatched closing tag') {
|
|
140
|
-
const end = start + String(this).length;
|
|
142
|
+
const end = start + String(this).length, ancestor = this.closest('magic-word');
|
|
141
143
|
error.excerpt = wikitext.slice(Math.max(0, end - 50), end);
|
|
142
|
-
if (magicWords.has(
|
|
144
|
+
if (ancestor && magicWords.has(ancestor.name)) {
|
|
143
145
|
error.severity = 'warning';
|
|
144
146
|
}
|
|
145
147
|
}
|
|
@@ -189,7 +191,8 @@ class HtmlToken extends attributesParent(fixed(Token)) {
|
|
|
189
191
|
/** @override */
|
|
190
192
|
cloneNode() {
|
|
191
193
|
const [attr] = this.cloneChildNodes(), config = this.getAttribute('config');
|
|
192
|
-
|
|
194
|
+
// @ts-expect-error abstract class
|
|
195
|
+
return index_1.default.run(() => new HtmlToken(this.#tag, attr, this.#closing, this.#selfClosing, config));
|
|
193
196
|
}
|
|
194
197
|
/** @private */
|
|
195
198
|
getAttribute(key) {
|
|
@@ -210,7 +213,7 @@ class HtmlToken extends attributesParent(fixed(Token)) {
|
|
|
210
213
|
/** 局部闭合 */
|
|
211
214
|
#localMatch() {
|
|
212
215
|
this.#selfClosing = false;
|
|
213
|
-
const root =
|
|
216
|
+
const root = index_1.default.parse(`</${this.name}>`, false, 3, this.getAttribute('config'));
|
|
214
217
|
this.after(root.firstChild);
|
|
215
218
|
}
|
|
216
219
|
/**
|
|
@@ -233,10 +236,10 @@ class HtmlToken extends attributesParent(fixed(Token)) {
|
|
|
233
236
|
this.#closing = true;
|
|
234
237
|
}
|
|
235
238
|
else {
|
|
236
|
-
|
|
239
|
+
index_1.default.warn('无法修复无效自封闭标签', (0, string_1.noWrap)(String(this)));
|
|
237
240
|
throw new Error(`无法修复无效自封闭标签:前文共有 ${imbalance} 个未匹配的闭合标签`);
|
|
238
241
|
}
|
|
239
242
|
}
|
|
240
243
|
}
|
|
241
|
-
|
|
242
|
-
|
|
244
|
+
exports.HtmlToken = HtmlToken;
|
|
245
|
+
index_1.default.classes['HtmlToken'] = __filename;
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import AtomToken
|
|
5
|
-
import AstText = require('../lib/text');
|
|
6
|
-
import type { TokenAttributeGetter, AstNodeTypes } from '../lib/node';
|
|
1
|
+
import { Token } from '.';
|
|
2
|
+
import type { LintError, Config } from '../index';
|
|
3
|
+
import type { Title } from '../lib/title';
|
|
4
|
+
import type { AstNodes, AstText, AtomToken, FileToken } from '../internal';
|
|
7
5
|
/** 图片参数 */
|
|
8
|
-
declare abstract class ImageParameterToken extends Token {
|
|
6
|
+
export declare abstract class ImageParameterToken extends Token {
|
|
9
7
|
#private;
|
|
10
8
|
/** @browser */
|
|
11
9
|
readonly type = "image-parameter";
|
|
12
10
|
name: string;
|
|
13
|
-
abstract get parentNode():
|
|
14
|
-
abstract get parentElement():
|
|
11
|
+
abstract get parentNode(): FileToken;
|
|
12
|
+
abstract get parentElement(): FileToken;
|
|
15
13
|
abstract get nextSibling(): this | undefined;
|
|
16
14
|
abstract get nextElementSibling(): this | undefined;
|
|
17
15
|
abstract get previousSibling(): AtomToken | this;
|
|
@@ -40,7 +38,7 @@ declare abstract class ImageParameterToken extends Token {
|
|
|
40
38
|
* @browser
|
|
41
39
|
* @param str 图片参数
|
|
42
40
|
*/
|
|
43
|
-
constructor(str: string, config?:
|
|
41
|
+
constructor(str: string, config?: Config, accum?: Token[]);
|
|
44
42
|
/**
|
|
45
43
|
* @override
|
|
46
44
|
* @browser
|
|
@@ -55,7 +53,7 @@ declare abstract class ImageParameterToken extends Token {
|
|
|
55
53
|
* @override
|
|
56
54
|
* @browser
|
|
57
55
|
*/
|
|
58
|
-
lint(start?: number):
|
|
56
|
+
lint(start?: number): LintError[];
|
|
59
57
|
/**
|
|
60
58
|
* @override
|
|
61
59
|
* @browser
|
|
@@ -71,14 +69,14 @@ declare abstract class ImageParameterToken extends Token {
|
|
|
71
69
|
*/
|
|
72
70
|
insertAt(token: string, i?: number): AstText;
|
|
73
71
|
/** @ignore */
|
|
74
|
-
insertAt<T extends
|
|
72
|
+
insertAt<T extends AstNodes>(token: T, i?: number): T;
|
|
75
73
|
/** 获取参数值 */
|
|
76
74
|
getValue(): string | true;
|
|
77
75
|
/**
|
|
78
76
|
* 设置参数值
|
|
79
77
|
* @param value 参数值
|
|
78
|
+
* @throws `Error` 无效参数
|
|
80
79
|
* @throws SyntaxError` 非法的参数值
|
|
81
80
|
*/
|
|
82
81
|
setValue(value: string | boolean): void;
|
|
83
82
|
}
|
|
84
|
-
export = ImageParameterToken;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImageParameterToken = void 0;
|
|
2
4
|
const string_1 = require("../util/string");
|
|
3
5
|
const lint_1 = require("../util/lint");
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
+
const index_1 = require("../index");
|
|
7
|
+
const _1 = require(".");
|
|
6
8
|
const params = new Set(['alt', 'link', 'lang', 'page', 'caption']);
|
|
7
9
|
/** @ignore */
|
|
8
|
-
|
|
9
|
-
function validate(key, val, config = Parser.getConfig(), halfParsed = false) {
|
|
10
|
+
function validate(key, val, config = index_1.default.getConfig(), halfParsed = false) {
|
|
10
11
|
const trimmedVal = val.trim();
|
|
11
12
|
let value = trimmedVal.replace(/\0\d+t\x7F/gu, '').trim();
|
|
12
13
|
switch (key) {
|
|
@@ -23,7 +24,7 @@ function validate(key, val, config = Parser.getConfig(), halfParsed = false) {
|
|
|
23
24
|
else if (value.startsWith('[[') && value.endsWith(']]')) {
|
|
24
25
|
value = value.slice(2, -2);
|
|
25
26
|
}
|
|
26
|
-
const title =
|
|
27
|
+
const title = index_1.default.normalizeTitle(value, 0, false, config, halfParsed, true, true);
|
|
27
28
|
return title.valid && title;
|
|
28
29
|
}
|
|
29
30
|
case 'lang':
|
|
@@ -33,11 +34,12 @@ function validate(key, val, config = Parser.getConfig(), halfParsed = false) {
|
|
|
33
34
|
case 'manualthumb':
|
|
34
35
|
return true;
|
|
35
36
|
default:
|
|
37
|
+
// @ts-expect-error isNaN
|
|
36
38
|
return !isNaN(value);
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
/** 图片参数 */
|
|
40
|
-
class ImageParameterToken extends Token {
|
|
42
|
+
class ImageParameterToken extends _1.Token {
|
|
41
43
|
/** @browser */
|
|
42
44
|
type = 'image-parameter';
|
|
43
45
|
/** @browser */
|
|
@@ -69,7 +71,7 @@ class ImageParameterToken extends Token {
|
|
|
69
71
|
const [width, height = ''] = size.split('x');
|
|
70
72
|
return { width, height };
|
|
71
73
|
}
|
|
72
|
-
const token =
|
|
74
|
+
const token = index_1.default.parse(size, false, 2, this.getAttribute('config')), i = token.childNodes.findIndex(child => child.type === 'text' && child.data.includes('x')), str = token.childNodes[i];
|
|
73
75
|
if (i === -1) {
|
|
74
76
|
return { width: size, height: '' };
|
|
75
77
|
}
|
|
@@ -102,7 +104,7 @@ class ImageParameterToken extends Token {
|
|
|
102
104
|
* @browser
|
|
103
105
|
* @param str 图片参数
|
|
104
106
|
*/
|
|
105
|
-
constructor(str, config =
|
|
107
|
+
constructor(str, config = index_1.default.getConfig(), accum = []) {
|
|
106
108
|
let mt;
|
|
107
109
|
const regexes = Object.entries(config.img).map(([syntax, param]) => [
|
|
108
110
|
syntax,
|
|
@@ -113,6 +115,7 @@ class ImageParameterToken extends Token {
|
|
|
113
115
|
return mt
|
|
114
116
|
&& (mt.length !== 4 || validate(key, mt[2], config, true) !== false);
|
|
115
117
|
});
|
|
118
|
+
// @ts-expect-error mt already assigned
|
|
116
119
|
if (param && mt) {
|
|
117
120
|
if (mt.length === 3) {
|
|
118
121
|
super(undefined, config, true, accum);
|
|
@@ -186,7 +189,8 @@ class ImageParameterToken extends Token {
|
|
|
186
189
|
/** @override */
|
|
187
190
|
cloneNode() {
|
|
188
191
|
const cloned = this.cloneChildNodes(), config = this.getAttribute('config');
|
|
189
|
-
return
|
|
192
|
+
return index_1.default.run(() => {
|
|
193
|
+
// @ts-expect-error abstract class
|
|
190
194
|
const token = new ImageParameterToken(this.#syntax.replace('$1', ''), config);
|
|
191
195
|
token.replaceChildren(...cloned);
|
|
192
196
|
return token;
|
|
@@ -206,7 +210,7 @@ class ImageParameterToken extends Token {
|
|
|
206
210
|
}
|
|
207
211
|
/** @ignore */
|
|
208
212
|
insertAt(token, i = this.length) {
|
|
209
|
-
if (!
|
|
213
|
+
if (!index_1.default.running && this.#isVoid()) {
|
|
210
214
|
throw new Error(`图片参数 ${this.name} 不接受自定义输入!`);
|
|
211
215
|
}
|
|
212
216
|
return super.insertAt(token, i);
|
|
@@ -218,6 +222,7 @@ class ImageParameterToken extends Token {
|
|
|
218
222
|
/**
|
|
219
223
|
* 设置参数值
|
|
220
224
|
* @param value 参数值
|
|
225
|
+
* @throws `Error` 无效参数
|
|
221
226
|
* @throws SyntaxError` 非法的参数值
|
|
222
227
|
*/
|
|
223
228
|
setValue(value) {
|
|
@@ -236,16 +241,16 @@ class ImageParameterToken extends Token {
|
|
|
236
241
|
else if (typeof value !== 'string') {
|
|
237
242
|
this.typeError('setValue', 'String');
|
|
238
243
|
}
|
|
239
|
-
const root =
|
|
244
|
+
const root = index_1.default.parse(`[[File:F|${this.#syntax ? this.#syntax.replace('$1', value) : value}]]`, this.getAttribute('include'), 6, this.getAttribute('config')), { length, firstChild: file } = root;
|
|
240
245
|
if (length !== 1 || file.type !== 'file' || file.length !== 2) {
|
|
241
246
|
throw new SyntaxError(`非法的 ${this.name} 参数:${(0, string_1.noWrap)(value)}`);
|
|
242
247
|
}
|
|
243
248
|
const { lastChild: imageParameter, name } = file;
|
|
244
|
-
if (name
|
|
245
|
-
|
|
249
|
+
if (name === 'File:F' && imageParameter.name === this.name) {
|
|
250
|
+
this.replaceChildren(...imageParameter.childNodes);
|
|
246
251
|
}
|
|
247
|
-
this.
|
|
252
|
+
throw new SyntaxError(`非法的 ${this.name} 参数:${(0, string_1.noWrap)(value)}`);
|
|
248
253
|
}
|
|
249
254
|
}
|
|
250
|
-
|
|
251
|
-
|
|
255
|
+
exports.ImageParameterToken = ImageParameterToken;
|
|
256
|
+
index_1.default.classes['ImageParameterToken'] = __filename;
|
package/dist/src/imagemap.d.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import AttributesToken = require('./attributes');
|
|
8
|
-
import ExtToken = require('./tagPair/ext');
|
|
9
|
-
import type { AstNodeTypes } from '../lib/node';
|
|
1
|
+
import { Token } from '.';
|
|
2
|
+
import { NoincludeToken } from './nowiki/noinclude';
|
|
3
|
+
import { GalleryImageToken } from './link/galleryImage';
|
|
4
|
+
import { ImagemapLinkToken } from './imagemapLink';
|
|
5
|
+
import type { LintError } from '../index';
|
|
6
|
+
import type { AstNodes, AstText, AttributesToken, ExtToken } from '../internal';
|
|
10
7
|
/**
|
|
11
8
|
* `<imagemap>`
|
|
12
9
|
* @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
|
|
13
10
|
*/
|
|
14
|
-
declare abstract class ImagemapToken extends Token {
|
|
11
|
+
export declare abstract class ImagemapToken extends Token {
|
|
15
12
|
/** @browser */
|
|
16
13
|
readonly type = "ext-inner";
|
|
17
14
|
childNodes: (GalleryImageToken | NoincludeToken | ImagemapLinkToken | AstText)[];
|
|
@@ -38,7 +35,7 @@ declare abstract class ImagemapToken extends Token {
|
|
|
38
35
|
* @param inner 标签内部wikitext
|
|
39
36
|
* @throws `SyntaxError` 没有合法图片
|
|
40
37
|
*/
|
|
41
|
-
constructor(inner?: string, config?:
|
|
38
|
+
constructor(inner?: string, config?: import("../index").Config, accum?: Token[]);
|
|
42
39
|
/**
|
|
43
40
|
* @override
|
|
44
41
|
* @browser
|
|
@@ -58,7 +55,7 @@ declare abstract class ImagemapToken extends Token {
|
|
|
58
55
|
* @override
|
|
59
56
|
* @browser
|
|
60
57
|
*/
|
|
61
|
-
lint(start?: number):
|
|
58
|
+
lint(start?: number): LintError[];
|
|
62
59
|
/**
|
|
63
60
|
* @override
|
|
64
61
|
* @param token 待插入的节点
|
|
@@ -68,14 +65,13 @@ declare abstract class ImagemapToken extends Token {
|
|
|
68
65
|
*/
|
|
69
66
|
insertAt(token: string, i?: number): AstText;
|
|
70
67
|
/** @ignore */
|
|
71
|
-
insertAt<T extends
|
|
68
|
+
insertAt<T extends AstNodes>(token: T, i?: number): T;
|
|
72
69
|
/**
|
|
73
70
|
* @override
|
|
74
71
|
* @param i 移除位置
|
|
75
72
|
* @throws `Error` 禁止移除图片
|
|
76
73
|
*/
|
|
77
|
-
removeAt(i: number):
|
|
74
|
+
removeAt(i: number): AstNodes;
|
|
78
75
|
/** @override */
|
|
79
76
|
cloneNode(): this;
|
|
80
77
|
}
|
|
81
|
-
export = ImagemapToken;
|
package/dist/src/imagemap.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImagemapToken = void 0;
|
|
2
4
|
const lint_1 = require("../util/lint");
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
5
|
+
const singleLine_1 = require("../mixin/singleLine");
|
|
6
|
+
const index_1 = require("../index");
|
|
7
|
+
const _1 = require(".");
|
|
8
|
+
const noinclude_1 = require("./nowiki/noinclude");
|
|
9
|
+
const galleryImage_1 = require("./link/galleryImage");
|
|
10
|
+
const imagemapLink_1 = require("./imagemapLink");
|
|
9
11
|
/**
|
|
10
12
|
* `<imagemap>`
|
|
11
13
|
* @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
|
|
12
14
|
*/
|
|
13
|
-
class ImagemapToken extends Token {
|
|
15
|
+
class ImagemapToken extends _1.Token {
|
|
14
16
|
/** @browser */
|
|
15
17
|
type = 'ext-inner';
|
|
16
18
|
/**
|
|
@@ -29,16 +31,14 @@ class ImagemapToken extends Token {
|
|
|
29
31
|
* @param inner 标签内部wikitext
|
|
30
32
|
* @throws `SyntaxError` 没有合法图片
|
|
31
33
|
*/
|
|
32
|
-
constructor(inner, config =
|
|
34
|
+
constructor(inner, config = index_1.default.getConfig(), accum = []) {
|
|
33
35
|
super(undefined, config, true, accum, {
|
|
34
36
|
GalleryImageToken: ':', ImagemapLinkToken: ':', SingleLineNoincludeToken: ':', AstText: ':',
|
|
35
37
|
});
|
|
36
38
|
if (!inner) {
|
|
37
39
|
return;
|
|
38
40
|
}
|
|
39
|
-
const lines = inner.split('\n'), protocols = new Set(config.protocol.split('|')), SingleLineNoincludeToken =
|
|
40
|
-
super.insertAt(new SingleLineNoincludeToken(line, config, accum));
|
|
41
|
-
};
|
|
41
|
+
const lines = inner.split('\n'), protocols = new Set(config.protocol.split('|')), SingleLineNoincludeToken = (0, singleLine_1.singleLine)(noinclude_1.NoincludeToken);
|
|
42
42
|
let first = true, error = false;
|
|
43
43
|
for (const line of lines) {
|
|
44
44
|
const trimmed = line.trim();
|
|
@@ -48,13 +48,14 @@ class ImagemapToken extends Token {
|
|
|
48
48
|
else if (first) {
|
|
49
49
|
const [file, ...options] = line.split('|'), title = this.normalizeTitle(file, 0, true);
|
|
50
50
|
if (title.valid && !title.interwiki && title.ns === 6) {
|
|
51
|
-
|
|
51
|
+
// @ts-expect-error abstract class
|
|
52
|
+
const token = new galleryImage_1.GalleryImageToken('imagemap', file, options.length > 0 ? options.join('|') : undefined, config, accum);
|
|
52
53
|
super.insertAt(token);
|
|
53
54
|
first = false;
|
|
54
55
|
continue;
|
|
55
56
|
}
|
|
56
57
|
else {
|
|
57
|
-
|
|
58
|
+
index_1.default.error('<imagemap>标签内必须先包含一张合法图片!', line);
|
|
58
59
|
error = true;
|
|
59
60
|
}
|
|
60
61
|
}
|
|
@@ -68,7 +69,8 @@ class ImagemapToken extends Token {
|
|
|
68
69
|
if (mtIn) {
|
|
69
70
|
const title = this.normalizeTitle(mtIn[1], 0, true, false, true);
|
|
70
71
|
if (title.valid) {
|
|
71
|
-
|
|
72
|
+
// @ts-expect-error abstract class
|
|
73
|
+
super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtIn.slice(1), substr.slice(substr.indexOf(']]') + 2), config, accum));
|
|
72
74
|
continue;
|
|
73
75
|
}
|
|
74
76
|
}
|
|
@@ -77,12 +79,14 @@ class ImagemapToken extends Token {
|
|
|
77
79
|
const mtEx = /^\[([^\]\s]+)(?:(\s+)(\S[^\]]*)?)?\][\w\s]*$/u
|
|
78
80
|
.exec(substr);
|
|
79
81
|
if (mtEx) {
|
|
80
|
-
|
|
82
|
+
// @ts-expect-error abstract class
|
|
83
|
+
super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtEx.slice(1), substr.slice(substr.indexOf(']') + 1), config, accum));
|
|
81
84
|
continue;
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
|
-
|
|
88
|
+
// @ts-expect-error abstract class
|
|
89
|
+
super.insertAt(new SingleLineNoincludeToken(line, config, accum));
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
92
|
/**
|
|
@@ -100,8 +104,8 @@ class ImagemapToken extends Token {
|
|
|
100
104
|
return super.text('\n').replace(/\n{2,}/gu, '\n');
|
|
101
105
|
}
|
|
102
106
|
/** @private */
|
|
103
|
-
getGaps() {
|
|
104
|
-
return 1;
|
|
107
|
+
getGaps(i) {
|
|
108
|
+
return i < this.length - 1 ? 1 : 0;
|
|
105
109
|
}
|
|
106
110
|
/**
|
|
107
111
|
* @override
|
|
@@ -153,12 +157,13 @@ class ImagemapToken extends Token {
|
|
|
153
157
|
/** @override */
|
|
154
158
|
cloneNode() {
|
|
155
159
|
const cloned = this.cloneChildNodes();
|
|
156
|
-
return
|
|
160
|
+
return index_1.default.run(() => {
|
|
161
|
+
// @ts-expect-error abstract class
|
|
157
162
|
const token = new ImagemapToken(undefined, this.getAttribute('config'));
|
|
158
163
|
token.append(...cloned);
|
|
159
164
|
return token;
|
|
160
165
|
});
|
|
161
166
|
}
|
|
162
167
|
}
|
|
163
|
-
|
|
164
|
-
|
|
168
|
+
exports.ImagemapToken = ImagemapToken;
|
|
169
|
+
index_1.default.classes['ImagemapToken'] = __filename;
|