wikiparser-node 1.16.6 → 1.17.0
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/bundle/bundle.es7.js +26 -26
- package/bundle/bundle.lsp.js +26 -26
- package/bundle/bundle.min.js +26 -26
- package/dist/addon/token.js +13 -23
- package/dist/src/arg.d.ts +2 -3
- package/dist/src/arg.js +7 -7
- package/dist/src/attributes.d.ts +2 -3
- package/dist/src/attributes.js +1 -1
- package/dist/src/converter.d.ts +2 -2
- package/dist/src/converter.js +3 -4
- package/dist/src/converterFlags.d.ts +2 -3
- package/dist/src/converterFlags.js +3 -4
- package/dist/src/heading.d.ts +2 -3
- package/dist/src/heading.js +1 -1
- package/dist/src/html.d.ts +0 -3
- package/dist/src/html.js +86 -92
- package/dist/src/imageParameter.d.ts +2 -3
- package/dist/src/imageParameter.js +1 -1
- package/dist/src/imagemapLink.d.ts +2 -2
- package/dist/src/imagemapLink.js +5 -6
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.js +20 -0
- package/dist/src/nested.d.ts +2 -3
- package/dist/src/nested.js +1 -1
- package/dist/src/nowiki/doubleUnderscore.d.ts +2 -2
- package/dist/src/nowiki/doubleUnderscore.js +1 -2
- package/dist/src/redirect.d.ts +2 -3
- package/dist/src/redirect.js +4 -5
- package/dist/src/table/td.d.ts +2 -2
- package/dist/src/table/td.js +1 -1
- package/dist/src/transclude.d.ts +2 -3
- package/dist/src/transclude.js +5 -5
- package/extensions/dist/base.js +1 -1
- package/extensions/dist/lint.js +1 -0
- package/extensions/es7/base.js +1 -1
- package/extensions/es7/lint.js +1 -0
- package/extensions/typings.d.ts +3 -1
- package/package.json +1 -1
package/dist/addon/token.js
CHANGED
|
@@ -338,40 +338,30 @@ index_2.Token.prototype.findEnclosingHtml = /** @implements */ function (tag) {
|
|
|
338
338
|
tag &&= tag.toLowerCase();
|
|
339
339
|
const { html } = this.getAttribute('config'), normalTags = new Set(html[0]), voidTags = new Set(html[2]);
|
|
340
340
|
/* istanbul ignore next */
|
|
341
|
-
if (
|
|
341
|
+
if (voidTags.has(tag)) {
|
|
342
342
|
throw new RangeError(`Void tag: ${tag}`);
|
|
343
343
|
}
|
|
344
|
-
else if (tag
|
|
344
|
+
else if (tag && !normalTags.has(tag) && !html[1].includes(tag)) {
|
|
345
345
|
throw new RangeError(`Invalid tag name: ${tag}`);
|
|
346
346
|
}
|
|
347
347
|
const { parentNode } = this;
|
|
348
348
|
if (!parentNode) {
|
|
349
349
|
return undefined;
|
|
350
350
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
* @param node 节点
|
|
354
|
-
* @param name 标签名
|
|
355
|
-
* @param closing 是否为闭合标签
|
|
356
|
-
*/
|
|
357
|
-
const checkHtml = (node, name, closing) => node.is('html')
|
|
358
|
-
&& (!name && !voidTags.has(node.name) || node.name === name)
|
|
359
|
-
&& (normalTags.has(node.name) || !node.selfClosing)
|
|
360
|
-
&& node.closing === closing;
|
|
361
|
-
const { childNodes, length } = parentNode, index = childNodes.indexOf(this);
|
|
362
|
-
let i = index - 1, j = length;
|
|
351
|
+
const { childNodes } = parentNode, index = childNodes.indexOf(this);
|
|
352
|
+
let i = index - 1, j;
|
|
363
353
|
for (; i >= 0; i--) {
|
|
364
|
-
const open = childNodes[i];
|
|
365
|
-
if (
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
354
|
+
const open = childNodes[i], { name, closing, selfClosing } = open;
|
|
355
|
+
if (open.is('html') && !closing
|
|
356
|
+
&& (tag ? name === tag : !voidTags.has(name))
|
|
357
|
+
&& (normalTags.has(name) || !selfClosing)) {
|
|
358
|
+
const close = open.findMatchingTag();
|
|
359
|
+
if (close) {
|
|
360
|
+
j = childNodes.indexOf(close);
|
|
361
|
+
if (j > index) {
|
|
369
362
|
break;
|
|
370
363
|
}
|
|
371
364
|
}
|
|
372
|
-
if (j < length) {
|
|
373
|
-
break;
|
|
374
|
-
}
|
|
375
365
|
}
|
|
376
366
|
}
|
|
377
367
|
if (i === -1) {
|
|
@@ -379,7 +369,7 @@ index_2.Token.prototype.findEnclosingHtml = /** @implements */ function (tag) {
|
|
|
379
369
|
}
|
|
380
370
|
const range = this.createRange();
|
|
381
371
|
range.setStart(parentNode, i);
|
|
382
|
-
range.setEnd(parentNode, j + 1);
|
|
372
|
+
range.setEnd(parentNode, j + 1); // eslint-disable-line @typescript-eslint/no-unnecessary-type-assertion
|
|
383
373
|
return range;
|
|
384
374
|
};
|
|
385
375
|
constants_1.classes['ExtendedToken'] = __filename;
|
package/dist/src/arg.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import Parser from '../index';
|
|
2
1
|
import { Token } from './index';
|
|
3
2
|
import { AtomToken } from './atom';
|
|
4
3
|
import { HiddenToken } from './hidden';
|
|
5
|
-
import type { LintError, AST } from '../base';
|
|
4
|
+
import type { Config, LintError, AST } from '../base';
|
|
6
5
|
/**
|
|
7
6
|
* argument wrapped in `{{{}}}`
|
|
8
7
|
*
|
|
@@ -23,7 +22,7 @@ export declare abstract class ArgToken extends Token {
|
|
|
23
22
|
get default(): string | false;
|
|
24
23
|
set default(value: string | false);
|
|
25
24
|
/** @param parts 以'|'分隔的各部分 */
|
|
26
|
-
constructor(parts: readonly string[], config
|
|
25
|
+
constructor(parts: readonly string[], config: Config, accum?: Token[]);
|
|
27
26
|
cloneNode(): this;
|
|
28
27
|
/**
|
|
29
28
|
* Remove redundant parts
|
package/dist/src/arg.js
CHANGED
|
@@ -4,13 +4,13 @@ exports.ArgToken = void 0;
|
|
|
4
4
|
const string_1 = require("../util/string");
|
|
5
5
|
const lint_1 = require("../util/lint");
|
|
6
6
|
const rect_1 = require("../lib/rect");
|
|
7
|
-
const index_1 = require("
|
|
8
|
-
const index_2 = require("./index");
|
|
7
|
+
const index_1 = require("./index");
|
|
9
8
|
const atom_1 = require("./atom");
|
|
10
9
|
const hidden_1 = require("./hidden");
|
|
11
10
|
/* NOT FOR BROWSER */
|
|
12
11
|
const constants_1 = require("../util/constants");
|
|
13
12
|
const debug_1 = require("../util/debug");
|
|
13
|
+
const index_2 = require("../index");
|
|
14
14
|
/* NOT FOR BROWSER END */
|
|
15
15
|
/**
|
|
16
16
|
* argument wrapped in `{{{}}}`
|
|
@@ -18,7 +18,7 @@ const debug_1 = require("../util/debug");
|
|
|
18
18
|
* `{{{}}}`包裹的参数
|
|
19
19
|
* @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken[]]}`
|
|
20
20
|
*/
|
|
21
|
-
class ArgToken extends
|
|
21
|
+
class ArgToken extends index_1.Token {
|
|
22
22
|
/* NOT FOR BROWSER END */
|
|
23
23
|
get type() {
|
|
24
24
|
return 'arg';
|
|
@@ -33,7 +33,7 @@ class ArgToken extends index_2.Token {
|
|
|
33
33
|
}
|
|
34
34
|
/* NOT FOR BROWSER END */
|
|
35
35
|
/** @param parts 以'|'分隔的各部分 */
|
|
36
|
-
constructor(parts, config
|
|
36
|
+
constructor(parts, config, accum = []) {
|
|
37
37
|
super(undefined, config, accum, {
|
|
38
38
|
AtomToken: 0, Token: 1, HiddenToken: '2:',
|
|
39
39
|
});
|
|
@@ -49,7 +49,7 @@ class ArgToken extends index_2.Token {
|
|
|
49
49
|
super.insertAt(token);
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
52
|
-
const token = new
|
|
52
|
+
const token = new index_1.Token(part, config, accum);
|
|
53
53
|
token.type = 'arg-default';
|
|
54
54
|
token.setAttribute('stage', 2);
|
|
55
55
|
super.insertAt(token);
|
|
@@ -193,7 +193,7 @@ class ArgToken extends index_2.Token {
|
|
|
193
193
|
* @param name new argument name / 新参数名
|
|
194
194
|
*/
|
|
195
195
|
setName(name) {
|
|
196
|
-
const { childNodes } =
|
|
196
|
+
const { childNodes } = index_2.default
|
|
197
197
|
.parse(name, this.getAttribute('include'), 2, this.getAttribute('config'));
|
|
198
198
|
this.firstChild.replaceChildren(...childNodes);
|
|
199
199
|
}
|
|
@@ -208,7 +208,7 @@ class ArgToken extends index_2.Token {
|
|
|
208
208
|
this.removeAt(1);
|
|
209
209
|
return;
|
|
210
210
|
}
|
|
211
|
-
const root =
|
|
211
|
+
const root = index_2.default
|
|
212
212
|
.parse(value, this.getAttribute('include'), undefined, this.getAttribute('config')), { childNodes: [, oldDefault] } = this;
|
|
213
213
|
if (oldDefault) {
|
|
214
214
|
oldDefault.replaceChildren(...root.childNodes);
|
package/dist/src/attributes.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import Parser from '../index';
|
|
2
1
|
import { Token } from './index';
|
|
3
2
|
import { AtomToken } from './atom';
|
|
4
3
|
import { AttributeToken } from './attribute';
|
|
5
|
-
import type { LintError } from '../base';
|
|
4
|
+
import type { Config, LintError } from '../base';
|
|
6
5
|
import type { ExtToken, HtmlToken, SyntaxToken } from '../internal';
|
|
7
6
|
import type { AttributeTypes } from './attribute';
|
|
8
7
|
import type { TableTokens } from './table/index';
|
|
@@ -47,7 +46,7 @@ export declare abstract class AttributesToken extends Token {
|
|
|
47
46
|
* @param type 标签类型
|
|
48
47
|
* @param name 标签名
|
|
49
48
|
*/
|
|
50
|
-
constructor(attr: string | undefined, type: AttributesTypes, name: string, config
|
|
49
|
+
constructor(attr: string | undefined, type: AttributesTypes, name: string, config: Config, accum?: Token[]);
|
|
51
50
|
/**
|
|
52
51
|
* Get all AttributeTokens with the specified attribute name
|
|
53
52
|
*
|
package/dist/src/attributes.js
CHANGED
|
@@ -107,7 +107,7 @@ class AttributesToken extends index_2.Token {
|
|
|
107
107
|
* @param type 标签类型
|
|
108
108
|
* @param name 标签名
|
|
109
109
|
*/
|
|
110
|
-
constructor(attr, type, name, config
|
|
110
|
+
constructor(attr, type, name, config, accum = []) {
|
|
111
111
|
super(undefined, config, accum, {
|
|
112
112
|
AtomToken: ':', AttributeToken: ':',
|
|
113
113
|
});
|
package/dist/src/converter.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import Parser from '../index';
|
|
2
1
|
import { Token } from './index';
|
|
3
2
|
import { ConverterFlagsToken } from './converterFlags';
|
|
4
3
|
import { ConverterRuleToken } from './converterRule';
|
|
4
|
+
import type { Config } from '../base';
|
|
5
5
|
import type { FlagsParentBase } from '../mixin/flagsParent';
|
|
6
6
|
export interface ConverterToken extends FlagsParentBase {
|
|
7
7
|
}
|
|
@@ -25,6 +25,6 @@ export declare abstract class ConverterToken extends Token {
|
|
|
25
25
|
* @param flags 转换类型标记
|
|
26
26
|
* @param rules 转换规则
|
|
27
27
|
*/
|
|
28
|
-
constructor(flags: readonly string[], rules: readonly [string, ...string[]], config
|
|
28
|
+
constructor(flags: readonly string[], rules: readonly [string, ...string[]], config: Config, accum?: Token[]);
|
|
29
29
|
cloneNode(): this;
|
|
30
30
|
}
|
package/dist/src/converter.js
CHANGED
|
@@ -36,8 +36,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
37
|
exports.ConverterToken = void 0;
|
|
38
38
|
const string_1 = require("../util/string");
|
|
39
|
-
const index_1 = require("
|
|
40
|
-
const index_2 = require("./index");
|
|
39
|
+
const index_1 = require("./index");
|
|
41
40
|
const converterFlags_1 = require("./converterFlags");
|
|
42
41
|
const converterRule_1 = require("./converterRule");
|
|
43
42
|
/* NOT FOR BROWSER */
|
|
@@ -57,7 +56,7 @@ let ConverterToken = (() => {
|
|
|
57
56
|
let _classDescriptor;
|
|
58
57
|
let _classExtraInitializers = [];
|
|
59
58
|
let _classThis;
|
|
60
|
-
let _classSuper =
|
|
59
|
+
let _classSuper = index_1.Token;
|
|
61
60
|
var ConverterToken = class extends _classSuper {
|
|
62
61
|
static { _classThis = this; }
|
|
63
62
|
static {
|
|
@@ -81,7 +80,7 @@ let ConverterToken = (() => {
|
|
|
81
80
|
* @param flags 转换类型标记
|
|
82
81
|
* @param rules 转换规则
|
|
83
82
|
*/
|
|
84
|
-
constructor(flags, rules, config
|
|
83
|
+
constructor(flags, rules, config, accum = []) {
|
|
85
84
|
super(undefined, config, accum);
|
|
86
85
|
// @ts-expect-error abstract class
|
|
87
86
|
this.append(new converterFlags_1.ConverterFlagsToken(flags, config, accum));
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import Parser from '../index';
|
|
2
1
|
import { Token } from './index';
|
|
3
2
|
import { AtomToken } from './atom';
|
|
4
|
-
import type { LintError } from '../base';
|
|
3
|
+
import type { Config, LintError } from '../base';
|
|
5
4
|
import type { ConverterToken, ConverterRuleToken } from '../internal';
|
|
6
5
|
/**
|
|
7
6
|
* flags for language conversion
|
|
@@ -28,7 +27,7 @@ export declare abstract class ConverterFlagsToken extends Token {
|
|
|
28
27
|
get flags(): Set<string>;
|
|
29
28
|
set flags(value: Set<string>);
|
|
30
29
|
/** @param flags 转换类型标记 */
|
|
31
|
-
constructor(flags: readonly string[], config
|
|
30
|
+
constructor(flags: readonly string[], config: Config, accum?: Token[]);
|
|
32
31
|
/**
|
|
33
32
|
* Get unknown language conversion flags
|
|
34
33
|
*
|
|
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ConverterFlagsToken = void 0;
|
|
4
4
|
const lint_1 = require("../util/lint");
|
|
5
5
|
const rect_1 = require("../lib/rect");
|
|
6
|
-
const index_1 = require("
|
|
7
|
-
const index_2 = require("./index");
|
|
6
|
+
const index_1 = require("./index");
|
|
8
7
|
const atom_1 = require("./atom");
|
|
9
8
|
/* NOT FOR BROWSER */
|
|
10
9
|
const debug_1 = require("../util/debug");
|
|
@@ -17,7 +16,7 @@ const definedFlags = new Set(['A', 'T', 'R', 'D', '-', 'H', 'N']);
|
|
|
17
16
|
* 转换flags
|
|
18
17
|
* @classdesc `{childNodes: AtomToken[]}`
|
|
19
18
|
*/
|
|
20
|
-
class ConverterFlagsToken extends
|
|
19
|
+
class ConverterFlagsToken extends index_1.Token {
|
|
21
20
|
#flags;
|
|
22
21
|
/* NOT FOR BROWSER END */
|
|
23
22
|
get type() {
|
|
@@ -36,7 +35,7 @@ class ConverterFlagsToken extends index_2.Token {
|
|
|
36
35
|
}
|
|
37
36
|
/* NOT FOR BROWSER END */
|
|
38
37
|
/** @param flags 转换类型标记 */
|
|
39
|
-
constructor(flags, config
|
|
38
|
+
constructor(flags, config, accum = []) {
|
|
40
39
|
super(undefined, config, accum, {
|
|
41
40
|
AtomToken: ':',
|
|
42
41
|
});
|
package/dist/src/heading.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import Parser from '../index';
|
|
2
1
|
import { Token } from './index';
|
|
3
2
|
import { SyntaxToken } from './syntax';
|
|
4
|
-
import type { LintError, AST } from '../base';
|
|
3
|
+
import type { Config, LintError, AST } from '../base';
|
|
5
4
|
import type { AstText } from '../internal';
|
|
6
5
|
/**
|
|
7
6
|
* section heading
|
|
@@ -32,7 +31,7 @@ export declare abstract class HeadingToken extends Token {
|
|
|
32
31
|
* @param level 标题层级
|
|
33
32
|
* @param input 标题文字
|
|
34
33
|
*/
|
|
35
|
-
constructor(level: number, input: readonly [string?, string?], config
|
|
34
|
+
constructor(level: number, input: readonly [string?, string?], config: Config, accum?: Token[]);
|
|
36
35
|
cloneNode(): this;
|
|
37
36
|
/**
|
|
38
37
|
* Set the level of heading
|
package/dist/src/heading.js
CHANGED
|
@@ -103,7 +103,7 @@ let HeadingToken = (() => {
|
|
|
103
103
|
* @param level 标题层级
|
|
104
104
|
* @param input 标题文字
|
|
105
105
|
*/
|
|
106
|
-
constructor(level, input, config
|
|
106
|
+
constructor(level, input, config, accum = []) {
|
|
107
107
|
super(undefined, config, accum);
|
|
108
108
|
this.#level = level;
|
|
109
109
|
const token = new index_2.Token(input[0], config, accum);
|
package/dist/src/html.d.ts
CHANGED
|
@@ -39,9 +39,6 @@ export declare abstract class HtmlToken extends Token {
|
|
|
39
39
|
* Find the matching tag
|
|
40
40
|
*
|
|
41
41
|
* 搜索匹配的标签
|
|
42
|
-
* @throws `SyntaxError` 同时闭合和自封闭的标签
|
|
43
|
-
* @throws `SyntaxError` 无效自封闭标签
|
|
44
|
-
* @throws `SyntaxError` 未匹配的标签
|
|
45
42
|
*/
|
|
46
43
|
findMatchingTag(): this | undefined;
|
|
47
44
|
cloneNode(): this;
|
package/dist/src/html.js
CHANGED
|
@@ -36,12 +36,11 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
37
|
exports.HtmlToken = void 0;
|
|
38
38
|
const lint_1 = require("../util/lint");
|
|
39
|
-
const
|
|
39
|
+
const debug_1 = require("../util/debug");
|
|
40
40
|
const rect_1 = require("../lib/rect");
|
|
41
41
|
const attributesParent_1 = require("../mixin/attributesParent");
|
|
42
42
|
const index_1 = require("./index");
|
|
43
43
|
/* NOT FOR BROWSER */
|
|
44
|
-
const debug_1 = require("../util/debug");
|
|
45
44
|
const constants_1 = require("../util/constants");
|
|
46
45
|
const fixed_1 = require("../mixin/fixed");
|
|
47
46
|
const index_2 = require("../index");
|
|
@@ -96,6 +95,7 @@ let HtmlToken = (() => {
|
|
|
96
95
|
#closing;
|
|
97
96
|
#selfClosing;
|
|
98
97
|
#tag;
|
|
98
|
+
#match;
|
|
99
99
|
/* NOT FOR BROWSER END */
|
|
100
100
|
get type() {
|
|
101
101
|
return 'html';
|
|
@@ -178,8 +178,8 @@ let HtmlToken = (() => {
|
|
|
178
178
|
}
|
|
179
179
|
/** @private */
|
|
180
180
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
181
|
-
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
|
|
182
|
-
if (
|
|
181
|
+
const errors = super.lint(start, re), { name, parentNode, closing, selfClosing } = this, rect = new rect_1.BoundingRect(this, start);
|
|
182
|
+
if (name === 'h1' && !closing) {
|
|
183
183
|
const e = (0, lint_1.generateForSelf)(this, rect, 'h1', '<h1>');
|
|
184
184
|
e.suggestions = [{ desc: 'h2', range: [start + 2, start + 3], text: '2' }];
|
|
185
185
|
errors.push(e);
|
|
@@ -189,110 +189,104 @@ let HtmlToken = (() => {
|
|
|
189
189
|
e.fix = { desc: 'remove', range: [start, e.endIndex], text: '' };
|
|
190
190
|
errors.push(e);
|
|
191
191
|
}
|
|
192
|
-
|
|
193
|
-
this.findMatchingTag();
|
|
194
|
-
}
|
|
195
|
-
catch (e) {
|
|
196
|
-
if (e instanceof SyntaxError) {
|
|
197
|
-
const { message } = e;
|
|
198
|
-
const msg = message.split(':', 1)[0].toLowerCase(), error = (0, lint_1.generateForSelf)(this, rect, 'unmatched-tag', msg), noSelfClosing = {
|
|
199
|
-
desc: 'no self-closing',
|
|
200
|
-
range: [error.endIndex - 2, error.endIndex - 1],
|
|
201
|
-
text: '',
|
|
202
|
-
};
|
|
203
|
-
switch (msg) {
|
|
204
|
-
case 'unclosed tag': {
|
|
205
|
-
const childNodes = this.parentNode?.childNodes;
|
|
206
|
-
if (formattingTags.has(this.name)
|
|
207
|
-
&& childNodes?.slice(0, childNodes.indexOf(this))
|
|
208
|
-
.some(({ type, name }) => type === 'html' && name === this.name)) {
|
|
209
|
-
error.suggestions = [{ desc: 'close', range: [start + 1, start + 1], text: '/' }];
|
|
210
|
-
}
|
|
211
|
-
else if (!this.closest('heading-title')) {
|
|
212
|
-
error.severity = 'warning';
|
|
213
|
-
}
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
case 'unmatched closing tag': {
|
|
217
|
-
const ancestor = this.closest('magic-word');
|
|
218
|
-
if (ancestor && magicWords.has(ancestor.name)) {
|
|
219
|
-
error.severity = 'warning';
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
error.suggestions = [{ desc: 'remove', range: [start, error.endIndex], text: '' }];
|
|
223
|
-
}
|
|
224
|
-
break;
|
|
225
|
-
}
|
|
226
|
-
case 'tag that is both closing and self-closing': {
|
|
227
|
-
const { html: [normalTags, , voidTags] } = this.getAttribute('config'), open = { desc: 'open', range: [start + 1, start + 2], text: '' };
|
|
228
|
-
if (voidTags.includes(this.name)) {
|
|
229
|
-
error.fix = open;
|
|
230
|
-
}
|
|
231
|
-
else if (normalTags.includes(this.name)) {
|
|
232
|
-
error.fix = noSelfClosing;
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
error.suggestions = [open, noSelfClosing];
|
|
236
|
-
}
|
|
237
|
-
break;
|
|
238
|
-
}
|
|
239
|
-
case 'invalid self-closing tag':
|
|
240
|
-
error.suggestions = [
|
|
241
|
-
noSelfClosing,
|
|
242
|
-
{ desc: 'close', range: [error.endIndex - 2, error.endIndex], text: `></${this.name}>` },
|
|
243
|
-
];
|
|
244
|
-
// no default
|
|
245
|
-
}
|
|
246
|
-
errors.push(error);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
if (obsoleteTags.has(this.name)) {
|
|
192
|
+
if (obsoleteTags.has(name)) {
|
|
250
193
|
errors.push((0, lint_1.generateForSelf)(this, rect, 'obsolete-tag', 'obsolete HTML tag', 'warning'));
|
|
251
194
|
}
|
|
252
|
-
if ((
|
|
195
|
+
if ((name === 'b' || name === 'strong') && this.closest('heading-title')) {
|
|
253
196
|
errors.push((0, lint_1.generateForSelf)(this, rect, 'bold-header', 'bold in section header', 'warning'));
|
|
254
197
|
}
|
|
198
|
+
const { html: [, flexibleTags, voidTags] } = this.getAttribute('config'), isVoid = voidTags.includes(name), isFlexible = flexibleTags.includes(name), isNormal = !isVoid && !isFlexible;
|
|
199
|
+
if (closing && (selfClosing || isVoid) || selfClosing && isNormal) {
|
|
200
|
+
const error = (0, lint_1.generateForSelf)(this, rect, 'unmatched-tag', closing ? 'tag that is both closing and self-closing' : 'invalid self-closing tag'), open = { desc: 'open', range: [start + 1, start + 2], text: '' }, noSelfClosing = {
|
|
201
|
+
desc: 'no self-closing',
|
|
202
|
+
range: [error.endIndex - 2, error.endIndex - 1],
|
|
203
|
+
text: '',
|
|
204
|
+
};
|
|
205
|
+
if (isFlexible) {
|
|
206
|
+
error.suggestions = [open, noSelfClosing];
|
|
207
|
+
}
|
|
208
|
+
else if (closing) {
|
|
209
|
+
error.fix = isVoid ? open : noSelfClosing;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
error.suggestions = [
|
|
213
|
+
noSelfClosing,
|
|
214
|
+
{ desc: 'close', range: [error.endIndex - 2, error.endIndex], text: `></${name}>` },
|
|
215
|
+
];
|
|
216
|
+
}
|
|
217
|
+
errors.push(error);
|
|
218
|
+
}
|
|
219
|
+
else if (!this.findMatchingTag()) {
|
|
220
|
+
const error = (0, lint_1.generateForSelf)(this, rect, 'unmatched-tag', closing ? 'unmatched closing tag' : 'unclosed tag');
|
|
221
|
+
if (closing) {
|
|
222
|
+
const ancestor = this.closest('magic-word');
|
|
223
|
+
if (ancestor && magicWords.has(ancestor.name)) {
|
|
224
|
+
error.severity = 'warning';
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
error.suggestions = [{ desc: 'remove', range: [start, error.endIndex], text: '' }];
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
const childNodes = parentNode?.childNodes;
|
|
232
|
+
if (formattingTags.has(name)
|
|
233
|
+
&& childNodes?.slice(0, childNodes.indexOf(this))
|
|
234
|
+
.some(({ type, name: n }) => type === 'html' && n === name)) {
|
|
235
|
+
error.suggestions = [{ desc: 'close', range: [start + 1, start + 1], text: '/' }];
|
|
236
|
+
}
|
|
237
|
+
else if (!this.closest('heading-title')) {
|
|
238
|
+
error.severity = 'warning';
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
errors.push(error);
|
|
242
|
+
}
|
|
255
243
|
return errors;
|
|
256
244
|
}
|
|
257
245
|
/**
|
|
258
246
|
* Find the matching tag
|
|
259
247
|
*
|
|
260
248
|
* 搜索匹配的标签
|
|
261
|
-
* @throws `SyntaxError` 同时闭合和自封闭的标签
|
|
262
|
-
* @throws `SyntaxError` 无效自封闭标签
|
|
263
|
-
* @throws `SyntaxError` 未匹配的标签
|
|
264
249
|
*/
|
|
265
250
|
findMatchingTag() {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
else if (voidTags.includes(tagName) || this.#selfClosing && flexibleTags.includes(tagName)) { // 自封闭标签
|
|
271
|
-
return this;
|
|
272
|
-
}
|
|
273
|
-
else if (this.#selfClosing && normalTags.includes(tagName)) {
|
|
274
|
-
throw new SyntaxError(`Invalid self-closing tag: ${string}`);
|
|
275
|
-
}
|
|
276
|
-
else if (!parentNode) {
|
|
277
|
-
return undefined;
|
|
278
|
-
}
|
|
279
|
-
const { childNodes } = parentNode, i = childNodes.indexOf(this), siblings = closing ? childNodes.slice(0, i).reverse() : childNodes.slice(i + 1);
|
|
280
|
-
let imbalance = closing ? -1 : 1;
|
|
281
|
-
for (const token of siblings) {
|
|
282
|
-
if (!token.is('html') || token.name !== tagName) {
|
|
283
|
-
continue;
|
|
251
|
+
return (0, lint_1.cache)(this.#match, () => {
|
|
252
|
+
const { name, parentNode, closing, selfClosing } = this, { html: [, flexibleTags, voidTags] } = this.getAttribute('config'), isVoid = voidTags.includes(name), isFlexible = flexibleTags.includes(name);
|
|
253
|
+
if (isVoid || isFlexible && selfClosing) { // 自封闭标签
|
|
254
|
+
return this;
|
|
284
255
|
}
|
|
285
|
-
else if (
|
|
286
|
-
|
|
256
|
+
else if (!parentNode) {
|
|
257
|
+
return undefined;
|
|
287
258
|
}
|
|
288
|
-
|
|
289
|
-
|
|
259
|
+
const { childNodes } = parentNode, i = childNodes.indexOf(this), siblings = closing ? childNodes.slice(0, i).reverse() : childNodes.slice(i + 1), stack = [this], { rev } = debug_1.Shadow;
|
|
260
|
+
for (const token of siblings) {
|
|
261
|
+
if (!token.is('html') || token.name !== name || isFlexible && token.#selfClosing) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
else if (token.#closing === closing) {
|
|
265
|
+
stack.push(token);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
const top = stack.pop();
|
|
269
|
+
if (top === this) {
|
|
270
|
+
return token;
|
|
271
|
+
}
|
|
272
|
+
if (index_2.default.viewOnly) {
|
|
273
|
+
top.#match = [rev, token];
|
|
274
|
+
token.#match = [rev, top];
|
|
275
|
+
}
|
|
276
|
+
}
|
|
290
277
|
}
|
|
291
|
-
if (
|
|
292
|
-
|
|
278
|
+
if (index_2.default.viewOnly) {
|
|
279
|
+
for (const token of stack) {
|
|
280
|
+
token.#match = [rev, undefined];
|
|
281
|
+
}
|
|
293
282
|
}
|
|
294
|
-
|
|
295
|
-
|
|
283
|
+
return undefined;
|
|
284
|
+
}, value => {
|
|
285
|
+
this.#match = value;
|
|
286
|
+
if (value[1] && value[1] !== this) {
|
|
287
|
+
value[1].#match = [debug_1.Shadow.rev, this];
|
|
288
|
+
}
|
|
289
|
+
});
|
|
296
290
|
}
|
|
297
291
|
/** @private */
|
|
298
292
|
print() {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import Parser from '../index';
|
|
2
1
|
import { Token } from './index';
|
|
3
|
-
import type { LintError } from '../base';
|
|
2
|
+
import type { LintError, Config } from '../base';
|
|
4
3
|
import type { Title } from '../lib/title';
|
|
5
4
|
import type { AtomToken, FileToken, AstNodes, AstText } from '../internal';
|
|
6
5
|
export declare const galleryParams: Set<string>;
|
|
@@ -41,7 +40,7 @@ export declare abstract class ImageParameterToken extends Token {
|
|
|
41
40
|
get height(): string | undefined;
|
|
42
41
|
set height(height: string | undefined);
|
|
43
42
|
/** @param str 图片参数 */
|
|
44
|
-
constructor(str: string, extension: string | undefined, config
|
|
43
|
+
constructor(str: string, extension: string | undefined, config: Config, accum?: Token[]);
|
|
45
44
|
/**
|
|
46
45
|
* Get the parameter value
|
|
47
46
|
*
|
|
@@ -119,7 +119,7 @@ class ImageParameterToken extends index_2.Token {
|
|
|
119
119
|
}
|
|
120
120
|
/* NOT FOR BROWSER END */
|
|
121
121
|
/** @param str 图片参数 */
|
|
122
|
-
constructor(str, extension, config
|
|
122
|
+
constructor(str, extension, config, accum) {
|
|
123
123
|
let mt;
|
|
124
124
|
const regexes = Object.entries(config.img).map(([syntax, param]) => {
|
|
125
125
|
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import Parser from '../index';
|
|
2
1
|
import { Token } from './index';
|
|
3
2
|
import { NoincludeToken } from './nowiki/noinclude';
|
|
4
3
|
import { LinkToken } from './link/index';
|
|
5
4
|
import { ExtLinkToken } from './extLink';
|
|
5
|
+
import type { Config } from '../base';
|
|
6
6
|
import type { AstText, ImagemapToken, GalleryImageToken } from '../internal';
|
|
7
7
|
import type { Title } from '../lib/title';
|
|
8
8
|
/**
|
|
@@ -33,5 +33,5 @@ export declare abstract class ImagemapLinkToken extends Token {
|
|
|
33
33
|
* @param linkStuff 内外链接
|
|
34
34
|
* @param post 链接后的文本
|
|
35
35
|
*/
|
|
36
|
-
constructor(pre: string, linkStuff: readonly [string, string | undefined, string | undefined] | readonly [string, string | undefined], post: string, config
|
|
36
|
+
constructor(pre: string, linkStuff: readonly [string, string | undefined, string | undefined] | readonly [string, string | undefined], post: string, config: Config, accum?: Token[]);
|
|
37
37
|
}
|
package/dist/src/imagemapLink.js
CHANGED
|
@@ -35,10 +35,9 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
35
35
|
};
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
37
|
exports.ImagemapLinkToken = void 0;
|
|
38
|
-
const index_1 = require("
|
|
39
|
-
const index_2 = require("./index");
|
|
38
|
+
const index_1 = require("./index");
|
|
40
39
|
const noinclude_1 = require("./nowiki/noinclude");
|
|
41
|
-
const
|
|
40
|
+
const index_2 = require("./link/index");
|
|
42
41
|
const extLink_1 = require("./extLink");
|
|
43
42
|
/* NOT FOR BROWSER */
|
|
44
43
|
const constants_1 = require("../util/constants");
|
|
@@ -56,7 +55,7 @@ let ImagemapLinkToken = (() => {
|
|
|
56
55
|
let _classDescriptor;
|
|
57
56
|
let _classExtraInitializers = [];
|
|
58
57
|
let _classThis;
|
|
59
|
-
let _classSuper =
|
|
58
|
+
let _classSuper = index_1.Token;
|
|
60
59
|
var ImagemapLinkToken = class extends _classSuper {
|
|
61
60
|
static { _classThis = this; }
|
|
62
61
|
static {
|
|
@@ -84,11 +83,11 @@ let ImagemapLinkToken = (() => {
|
|
|
84
83
|
* @param linkStuff 内外链接
|
|
85
84
|
* @param post 链接后的文本
|
|
86
85
|
*/
|
|
87
|
-
constructor(pre, linkStuff, post, config
|
|
86
|
+
constructor(pre, linkStuff, post, config, accum = []) {
|
|
88
87
|
super(undefined, config, accum);
|
|
89
88
|
this.append(pre, linkStuff.length === 2
|
|
90
89
|
// @ts-expect-error abstract class
|
|
91
|
-
? new
|
|
90
|
+
? new index_2.LinkToken(...linkStuff, config, accum)
|
|
92
91
|
// @ts-expect-error abstract class
|
|
93
92
|
: new extLink_1.ExtLinkToken(...linkStuff, config, accum),
|
|
94
93
|
// @ts-expect-error abstract class
|