wikiparser-node 1.1.5 → 1.1.6
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/dist/addon/table.js +9 -4
- package/dist/base.d.ts +23 -22
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -3
- package/dist/internal.d.ts +2 -2
- package/dist/lib/element.d.ts +10 -10
- package/dist/lib/element.js +3 -5
- package/dist/lib/node.d.ts +8 -8
- package/dist/lib/node.js +9 -9
- package/dist/lib/range.d.ts +2 -2
- package/dist/lib/range.js +1 -2
- package/dist/lib/ranges.d.ts +3 -3
- package/dist/lib/text.d.ts +2 -2
- package/dist/lib/title.d.ts +1 -1
- package/dist/parser/selector.js +1 -1
- package/dist/parser/table.js +6 -4
- package/dist/src/arg.d.ts +3 -3
- package/dist/src/attribute.d.ts +5 -5
- package/dist/src/attribute.js +1 -1
- package/dist/src/attributes.d.ts +5 -4
- package/dist/src/attributes.js +11 -5
- package/dist/src/converter.d.ts +3 -3
- package/dist/src/converterFlags.d.ts +3 -3
- package/dist/src/converterRule.d.ts +1 -1
- package/dist/src/extLink.d.ts +2 -2
- package/dist/src/gallery.d.ts +3 -3
- package/dist/src/gallery.js +1 -1
- package/dist/src/heading.d.ts +4 -4
- package/dist/src/hidden.d.ts +1 -1
- package/dist/src/html.d.ts +10 -11
- package/dist/src/html.js +3 -4
- package/dist/src/imageParameter.d.ts +1 -1
- package/dist/src/imageParameter.js +2 -4
- package/dist/src/imagemap.d.ts +3 -3
- package/dist/src/imagemap.js +2 -2
- package/dist/src/imagemapLink.d.ts +4 -4
- package/dist/src/index.d.ts +9 -8
- package/dist/src/index.js +11 -11
- package/dist/src/link/base.d.ts +2 -2
- package/dist/src/link/file.d.ts +7 -7
- package/dist/src/link/galleryImage.d.ts +1 -1
- package/dist/src/link/galleryImage.js +2 -2
- package/dist/src/link/index.d.ts +1 -1
- package/dist/src/magicLink.d.ts +2 -2
- package/dist/src/nested.d.ts +3 -3
- package/dist/src/nested.js +1 -1
- package/dist/src/nowiki/base.d.ts +2 -2
- package/dist/src/nowiki/comment.d.ts +1 -1
- package/dist/src/nowiki/doubleUnderscore.d.ts +3 -3
- package/dist/src/nowiki/doubleUnderscore.js +0 -1
- package/dist/src/nowiki/hr.d.ts +2 -2
- package/dist/src/nowiki/index.d.ts +1 -1
- package/dist/src/nowiki/list.d.ts +1 -1
- package/dist/src/nowiki/listBase.d.ts +1 -1
- package/dist/src/nowiki/noinclude.d.ts +1 -1
- package/dist/src/nowiki/quote.d.ts +1 -1
- package/dist/src/paramTag/index.d.ts +2 -2
- package/dist/src/parameter.d.ts +3 -3
- package/dist/src/pre.d.ts +2 -2
- package/dist/src/syntax.d.ts +1 -2
- package/dist/src/table/base.d.ts +3 -3
- package/dist/src/table/index.d.ts +9 -9
- package/dist/src/table/index.js +2 -1
- package/dist/src/table/td.d.ts +7 -6
- package/dist/src/table/tr.d.ts +1 -1
- package/dist/src/table/trBase.d.ts +5 -5
- package/dist/src/table/trBase.js +12 -4
- package/dist/src/tagPair/ext.d.ts +7 -4
- package/dist/src/tagPair/include.d.ts +2 -2
- package/dist/src/tagPair/index.d.ts +3 -3
- package/dist/src/transclude.d.ts +10 -10
- package/dist/src/transclude.js +10 -10
- package/dist/util/constants.js +1 -0
- package/package.json +4 -4
package/dist/addon/table.js
CHANGED
|
@@ -10,6 +10,11 @@ const tr_1 = require("../src/table/tr");
|
|
|
10
10
|
const table_1 = require("../src/table");
|
|
11
11
|
const td_1 = require("../src/table/td");
|
|
12
12
|
const trBase_1 = require("../src/table/trBase");
|
|
13
|
+
/**
|
|
14
|
+
* 检查坐标形式
|
|
15
|
+
* @param coords 坐标
|
|
16
|
+
*/
|
|
17
|
+
const isTableCoords = (coords) => coords.x === undefined;
|
|
13
18
|
/**
|
|
14
19
|
* 比较两个表格坐标
|
|
15
20
|
* @param coords1 坐标1
|
|
@@ -319,7 +324,7 @@ table_1.TableToken.prototype.removeTableRow =
|
|
|
319
324
|
}
|
|
320
325
|
}
|
|
321
326
|
}
|
|
322
|
-
const
|
|
327
|
+
const row = rows[y], rowToken = row.type === 'tr' ? row : this.prependTableRow();
|
|
323
328
|
rowToken.remove();
|
|
324
329
|
return rowToken;
|
|
325
330
|
};
|
|
@@ -371,7 +376,7 @@ table_1.TableToken.prototype.split =
|
|
|
371
376
|
return;
|
|
372
377
|
}
|
|
373
378
|
let { x, y } = coords;
|
|
374
|
-
const rawCoords =
|
|
379
|
+
const rawCoords = isTableCoords(coords) ? coords : this.toRawCoords(coords);
|
|
375
380
|
if (rawCoords.start === false || x === undefined) {
|
|
376
381
|
({ x, y } = this.toRenderedCoords(rawCoords));
|
|
377
382
|
}
|
|
@@ -452,7 +457,7 @@ table_1.TableToken.prototype.moveTableRowBefore =
|
|
|
452
457
|
function (y, before) {
|
|
453
458
|
const layout = this.getLayout(),
|
|
454
459
|
/** @ignore */
|
|
455
|
-
occupied = (i) => layout[i].map(({ row }, j) => row === i ? j : undefined).filter(j => j !== undefined);
|
|
460
|
+
occupied = (i) => layout[i].map(({ row }, j) => row === i ? j : undefined).filter((j) => j !== undefined);
|
|
456
461
|
try {
|
|
457
462
|
assert.deepEqual(occupied(y), occupied(before));
|
|
458
463
|
}
|
|
@@ -480,7 +485,7 @@ table_1.TableToken.prototype.moveTableRowAfter =
|
|
|
480
485
|
function (y, after) {
|
|
481
486
|
const layout = this.getLayout(), afterToken = this.getNthRow(after), cells = afterToken.childNodes.filter(child => child.type === 'td' && child.subtype !== 'caption'),
|
|
482
487
|
/** @ignore */
|
|
483
|
-
occupied = (i, oneRow = false) => layout[i].map(({ row, column }, j) => row === i && (!oneRow || cells[column].rowspan === 1) ? j : undefined).filter(j => j !== undefined);
|
|
488
|
+
occupied = (i, oneRow = false) => layout[i].map(({ row, column }, j) => row === i && (!oneRow || cells[column].rowspan === 1) ? j : undefined).filter((j) => j !== undefined);
|
|
484
489
|
try {
|
|
485
490
|
assert.deepEqual(occupied(y), occupied(after, true));
|
|
486
491
|
}
|
package/dist/base.d.ts
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
export interface Config {
|
|
2
2
|
ext: string[];
|
|
3
|
-
html: [string[], string[], string[]];
|
|
4
|
-
namespaces: Record<string, string>;
|
|
5
|
-
nsid: Record<string, number>;
|
|
6
|
-
parserFunction: [Record<string, string>, string[], string[], string[]];
|
|
7
|
-
doubleUnderscore: [string[], string[]];
|
|
8
|
-
protocol: string;
|
|
9
|
-
img: Record<string, string>;
|
|
10
|
-
variants: string[];
|
|
11
|
-
interwiki: string[];
|
|
12
|
-
excludes?: string[];
|
|
13
|
-
conversionTable?: [string, string][];
|
|
14
|
-
redirects?: [string, string][];
|
|
3
|
+
readonly html: [string[], string[], string[]];
|
|
4
|
+
readonly namespaces: Record<string, string>;
|
|
5
|
+
readonly nsid: Record<string, number>;
|
|
6
|
+
readonly parserFunction: [Record<string, string>, string[], string[], string[]];
|
|
7
|
+
readonly doubleUnderscore: [string[], string[]];
|
|
8
|
+
readonly protocol: string;
|
|
9
|
+
readonly img: Record<string, string>;
|
|
10
|
+
readonly variants: string[];
|
|
11
|
+
readonly interwiki: string[];
|
|
12
|
+
readonly excludes?: string[];
|
|
13
|
+
readonly conversionTable?: [string, string][];
|
|
14
|
+
readonly redirects?: [string, string][];
|
|
15
15
|
}
|
|
16
|
+
export type Severity = 'error' | 'warning';
|
|
16
17
|
export interface LintError {
|
|
17
|
-
message: string;
|
|
18
|
-
severity:
|
|
19
|
-
startIndex: number;
|
|
20
|
-
endIndex: number;
|
|
21
|
-
startLine: number;
|
|
22
|
-
startCol: number;
|
|
23
|
-
endLine: number;
|
|
24
|
-
endCol: number;
|
|
25
|
-
excerpt: string;
|
|
18
|
+
readonly message: string;
|
|
19
|
+
readonly severity: Severity;
|
|
20
|
+
readonly startIndex: number;
|
|
21
|
+
readonly endIndex: number;
|
|
22
|
+
readonly startLine: number;
|
|
23
|
+
readonly startCol: number;
|
|
24
|
+
readonly endLine: number;
|
|
25
|
+
readonly endCol: number;
|
|
26
|
+
readonly excerpt: string;
|
|
26
27
|
}
|
|
27
28
|
/** 类似Node */
|
|
28
29
|
export interface AstNode {
|
|
29
30
|
type: string;
|
|
30
|
-
childNodes: AstNode[];
|
|
31
|
+
readonly childNodes: AstNode[];
|
|
31
32
|
/** Linter */
|
|
32
33
|
lint(): LintError[];
|
|
33
34
|
/** 以HTML格式打印 */
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Title } from './lib/title';
|
|
|
3
3
|
import type { Token } from './internal';
|
|
4
4
|
import type { Config, LintError, Parser as ParserBase } from './base';
|
|
5
5
|
declare interface Parser extends ParserBase {
|
|
6
|
-
Shadow: typeof Shadow;
|
|
6
|
+
readonly Shadow: typeof Shadow;
|
|
7
7
|
conversionTable: Map<string, string>;
|
|
8
8
|
redirects: Map<string, string>;
|
|
9
9
|
warning: boolean;
|
package/dist/index.js
CHANGED
|
@@ -51,7 +51,7 @@ const Parser = {
|
|
|
51
51
|
this.i18n = rootRequire(this.i18n, 'i18n/');
|
|
52
52
|
return this.msg(msg, arg);
|
|
53
53
|
}
|
|
54
|
-
return (this.i18n?.[msg] ?? msg).replace('$1', arg);
|
|
54
|
+
return msg && (this.i18n?.[msg] ?? msg).replace('$1', this.msg(arg));
|
|
55
55
|
},
|
|
56
56
|
/** @implements */
|
|
57
57
|
normalizeTitle(title, defaultNs = 0, include = false, config = Parser.getConfig(), halfParsed = false, decode = false, selfLink = false) {
|
|
@@ -154,9 +154,8 @@ const Parser = {
|
|
|
154
154
|
await promise;
|
|
155
155
|
for (const [name, filePath] of entries) {
|
|
156
156
|
if (name in global) {
|
|
157
|
-
// @ts-expect-error noImplicitAny
|
|
158
157
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
159
|
-
global[name]
|
|
158
|
+
Object.assign(global, { [name]: require(filePath)[name] });
|
|
160
159
|
}
|
|
161
160
|
}
|
|
162
161
|
this.info('已重新加载Parser');
|
package/dist/internal.d.ts
CHANGED
|
@@ -18,12 +18,12 @@ export type * from './src/heading';
|
|
|
18
18
|
export type * from './src/html';
|
|
19
19
|
export type { TdToken } from './src/table/td';
|
|
20
20
|
export type * from './src/table/tr';
|
|
21
|
-
export type
|
|
21
|
+
export type { TableToken } from './src/table/index';
|
|
22
22
|
export type * from './src/nowiki/hr';
|
|
23
23
|
export type * from './src/nowiki/doubleUnderscore';
|
|
24
24
|
export type * from './src/link/index';
|
|
25
25
|
export type * from './src/link/category';
|
|
26
|
-
export type
|
|
26
|
+
export type { ImageParameterToken } from './src/imageParameter';
|
|
27
27
|
export type * from './src/link/file';
|
|
28
28
|
export type * from './src/link/galleryImage';
|
|
29
29
|
export type * from './src/nowiki/quote';
|
package/dist/lib/element.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { AstNode } from './node';
|
|
2
2
|
import type { LintError } from '../base';
|
|
3
|
-
import type { AstNodes, AstText, Token } from '../internal';
|
|
3
|
+
import type { AstNodes, AstText, Token, HtmlToken, ExtToken } from '../internal';
|
|
4
4
|
/** 类似HTMLElement */
|
|
5
5
|
export declare abstract class AstElement extends AstNode {
|
|
6
6
|
#private;
|
|
7
|
-
name?: string;
|
|
8
|
-
data: undefined;
|
|
7
|
+
readonly name?: string;
|
|
8
|
+
readonly data: undefined;
|
|
9
9
|
/** 子节点总数 */
|
|
10
10
|
get length(): number;
|
|
11
11
|
/** 全部非文本子节点 */
|
|
12
|
-
get children(): Token[];
|
|
12
|
+
get children(): readonly Token[];
|
|
13
13
|
/** 首位非文本子节点 */
|
|
14
14
|
get firstElementChild(): Token | undefined;
|
|
15
15
|
/** 末位非文本子节点 */
|
|
@@ -54,7 +54,7 @@ export declare abstract class AstElement extends AstNode {
|
|
|
54
54
|
* 最近的祖先节点
|
|
55
55
|
* @param selector 选择器
|
|
56
56
|
*/
|
|
57
|
-
closest(selector: string):
|
|
57
|
+
closest<T extends Token>(selector: string): T | undefined;
|
|
58
58
|
/**
|
|
59
59
|
* 在末尾批量插入子节点
|
|
60
60
|
* @param elements 插入节点
|
|
@@ -98,12 +98,12 @@ export declare abstract class AstElement extends AstNode {
|
|
|
98
98
|
* 符合选择器的第一个后代节点
|
|
99
99
|
* @param selector 选择器
|
|
100
100
|
*/
|
|
101
|
-
querySelector(selector: string):
|
|
101
|
+
querySelector<T extends Token>(selector: string): T | undefined;
|
|
102
102
|
/**
|
|
103
103
|
* 类型选择器
|
|
104
104
|
* @param types
|
|
105
105
|
*/
|
|
106
|
-
getElementByTypes(types: string):
|
|
106
|
+
getElementByTypes<T extends Token>(types: string): T | undefined;
|
|
107
107
|
/**
|
|
108
108
|
* id选择器
|
|
109
109
|
* @param id id名
|
|
@@ -113,17 +113,17 @@ export declare abstract class AstElement extends AstNode {
|
|
|
113
113
|
* 符合选择器的所有后代节点
|
|
114
114
|
* @param selector 选择器
|
|
115
115
|
*/
|
|
116
|
-
querySelectorAll(selector: string):
|
|
116
|
+
querySelectorAll<T extends Token>(selector: string): readonly T[];
|
|
117
117
|
/**
|
|
118
118
|
* 类选择器
|
|
119
119
|
* @param className 类名之一
|
|
120
120
|
*/
|
|
121
|
-
getElementsByClassName(className: string): Token[];
|
|
121
|
+
getElementsByClassName(className: string): readonly Token[];
|
|
122
122
|
/**
|
|
123
123
|
* 标签名选择器
|
|
124
124
|
* @param tag 标签名
|
|
125
125
|
*/
|
|
126
|
-
getElementsByTagName(tag: string):
|
|
126
|
+
getElementsByTagName(tag: string): readonly (HtmlToken | ExtToken)[];
|
|
127
127
|
/**
|
|
128
128
|
* 获取某一行的wikitext
|
|
129
129
|
* @param n 行号
|
package/dist/lib/element.js
CHANGED
|
@@ -60,11 +60,11 @@ class AstElement extends node_1.AstNode {
|
|
|
60
60
|
/* NOT FOR BROWSER */
|
|
61
61
|
/** 全部非文本子节点 */
|
|
62
62
|
get children() {
|
|
63
|
-
return this.childNodes.filter((
|
|
63
|
+
return this.childNodes.filter((child) => child.type !== 'text');
|
|
64
64
|
}
|
|
65
65
|
/** 首位非文本子节点 */
|
|
66
66
|
get firstElementChild() {
|
|
67
|
-
return this.childNodes.find((
|
|
67
|
+
return this.childNodes.find((child) => child.type !== 'text');
|
|
68
68
|
}
|
|
69
69
|
/** 末位非文本子节点 */
|
|
70
70
|
get lastElementChild() {
|
|
@@ -188,7 +188,7 @@ class AstElement extends node_1.AstNode {
|
|
|
188
188
|
}
|
|
189
189
|
else {
|
|
190
190
|
const types = new Set(selector.split(',').map(str => str.trim()));
|
|
191
|
-
condition = /** @implements */ (
|
|
191
|
+
condition = /** @implements */ (token) => types.has(token.type);
|
|
192
192
|
}
|
|
193
193
|
while (parentNode) {
|
|
194
194
|
if (condition(parentNode)) {
|
|
@@ -329,9 +329,7 @@ class AstElement extends node_1.AstNode {
|
|
|
329
329
|
}
|
|
330
330
|
if (equal === '~=') {
|
|
331
331
|
const thisVals = typeof thisVal === 'string' ? thisVal.split(/\s/u) : thisVal;
|
|
332
|
-
// @ts-expect-error noImplicitAny
|
|
333
332
|
return Boolean(thisVals?.[Symbol.iterator])
|
|
334
|
-
// @ts-expect-error spread unknown
|
|
335
333
|
&& [...thisVals].some(w => typeof w === 'string' && toCase(w, i) === v);
|
|
336
334
|
}
|
|
337
335
|
else if (typeof thisVal !== 'string') {
|
package/dist/lib/node.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { LintError, AstNode as AstNodeBase } from '../base';
|
|
2
2
|
import type { AstText, Token } from '../internal';
|
|
3
|
+
import type { TokenTypes } from '../util/constants';
|
|
3
4
|
export type AstNodes = AstText | Token;
|
|
4
|
-
export type TokenTypes = 'root' | 'plain' | 'onlyinclude' | 'noinclude' | 'include' | 'comment' | 'ext' | 'ext-attrs' | 'ext-attr-dirty' | 'ext-attr' | 'attr-key' | 'attr-value' | 'ext-inner' | 'arg' | 'arg-name' | 'arg-default' | 'hidden' | 'magic-word' | 'magic-word-name' | 'invoke-function' | 'invoke-module' | 'template' | 'template-name' | 'parameter' | 'parameter-key' | 'parameter-value' | 'heading' | 'heading-title' | 'heading-trail' | 'html' | 'html-attrs' | 'html-attr-dirty' | 'html-attr' | 'table' | 'tr' | 'td' | 'table-syntax' | 'table-attrs' | 'table-attr-dirty' | 'table-attr' | 'table-inter' | 'td-inner' | 'hr' | 'double-underscore' | 'link' | 'link-target' | 'link-text' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'image-parameter' | 'quote' | 'ext-link' | 'ext-link-text' | 'ext-link-url' | 'free-ext-link' | 'list' | 'dd' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'imagemap-link';
|
|
5
5
|
export interface Dimension {
|
|
6
|
-
height: number;
|
|
7
|
-
width: number;
|
|
6
|
+
readonly height: number;
|
|
7
|
+
readonly width: number;
|
|
8
8
|
}
|
|
9
9
|
export interface Position {
|
|
10
|
-
top: number;
|
|
11
|
-
left: number;
|
|
10
|
+
readonly top: number;
|
|
11
|
+
readonly left: number;
|
|
12
12
|
}
|
|
13
13
|
export interface CaretPosition {
|
|
14
|
-
offsetNode: AstNodes;
|
|
15
|
-
offset: number;
|
|
14
|
+
readonly offsetNode: AstNodes;
|
|
15
|
+
readonly offset: number;
|
|
16
16
|
}
|
|
17
17
|
/** 类似Node */
|
|
18
18
|
export declare abstract class AstNode implements AstNodeBase {
|
|
@@ -120,7 +120,7 @@ export declare abstract class AstNode implements AstNodeBase {
|
|
|
120
120
|
* 列举事件监听
|
|
121
121
|
* @param type 事件类型
|
|
122
122
|
*/
|
|
123
|
-
listEventListeners(type: string): Function[];
|
|
123
|
+
listEventListeners(type: string): readonly Function[];
|
|
124
124
|
/**
|
|
125
125
|
* 触发事件
|
|
126
126
|
* @param e 事件对象
|
package/dist/lib/node.js
CHANGED
|
@@ -57,12 +57,12 @@ class AstNode {
|
|
|
57
57
|
/** 后一个非文本兄弟节点 */
|
|
58
58
|
get nextElementSibling() {
|
|
59
59
|
const childNodes = this.parentNode?.childNodes, i = childNodes?.indexOf(this);
|
|
60
|
-
return childNodes?.slice(i + 1).find((
|
|
60
|
+
return childNodes?.slice(i + 1).find((child) => child.type !== 'text');
|
|
61
61
|
}
|
|
62
62
|
/** 前一个非文本兄弟节点 */
|
|
63
63
|
get previousElementSibling() {
|
|
64
64
|
const childNodes = this.parentNode?.childNodes, i = childNodes?.indexOf(this);
|
|
65
|
-
return childNodes?.slice(0, i).findLast((
|
|
65
|
+
return childNodes?.slice(0, i).findLast((child) => child.type !== 'text');
|
|
66
66
|
}
|
|
67
67
|
/** 是否具有根节点 */
|
|
68
68
|
get isConnected() {
|
|
@@ -110,7 +110,6 @@ class AstNode {
|
|
|
110
110
|
return new Set(this.#optional);
|
|
111
111
|
}
|
|
112
112
|
return key in this
|
|
113
|
-
// @ts-expect-error noImplicitAny
|
|
114
113
|
? String(this[key])
|
|
115
114
|
: undefined;
|
|
116
115
|
}
|
|
@@ -124,16 +123,14 @@ class AstNode {
|
|
|
124
123
|
if (this.#optional.has(key)) {
|
|
125
124
|
descriptor.enumerable = Boolean(value);
|
|
126
125
|
}
|
|
127
|
-
|
|
128
|
-
const oldValue = this[key], frozen = oldValue !== null && typeof oldValue === 'object' && Object.isFrozen(oldValue);
|
|
126
|
+
const oldValue = this[key], frozen = typeof oldValue === 'object' && Object.isFrozen(oldValue);
|
|
129
127
|
Object.defineProperty(this, key, { ...descriptor, value });
|
|
130
128
|
if (frozen && typeof value === 'object') {
|
|
131
129
|
Object.freeze(value);
|
|
132
130
|
}
|
|
133
131
|
}
|
|
134
132
|
else {
|
|
135
|
-
// @
|
|
136
|
-
this[key] = value;
|
|
133
|
+
this[key] = value; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
137
134
|
}
|
|
138
135
|
}
|
|
139
136
|
/** 获取根节点 */
|
|
@@ -210,8 +207,11 @@ class AstNode {
|
|
|
210
207
|
/** @private */
|
|
211
208
|
seal(key) {
|
|
212
209
|
this.#optional.add(key);
|
|
213
|
-
|
|
214
|
-
|
|
210
|
+
Object.defineProperty(this, key, {
|
|
211
|
+
writable: false,
|
|
212
|
+
enumerable: Boolean(this[key]),
|
|
213
|
+
configurable: true,
|
|
214
|
+
});
|
|
215
215
|
}
|
|
216
216
|
/**
|
|
217
217
|
* 是否是全同节点
|
package/dist/lib/range.d.ts
CHANGED
|
@@ -98,7 +98,7 @@ export declare class AstRange {
|
|
|
98
98
|
*/
|
|
99
99
|
insertNode(newNode: AstNodes | string): void;
|
|
100
100
|
/** 获取范围内的全部节点 */
|
|
101
|
-
extractContents(): AstNodes[];
|
|
101
|
+
extractContents(): readonly AstNodes[];
|
|
102
102
|
/** 在满足条件时拷贝范围内的全部节点 */
|
|
103
|
-
cloneContents(): AstNodes[];
|
|
103
|
+
cloneContents(): readonly AstNodes[];
|
|
104
104
|
}
|
package/dist/lib/range.js
CHANGED
|
@@ -352,8 +352,7 @@ class AstRange {
|
|
|
352
352
|
return [];
|
|
353
353
|
}
|
|
354
354
|
commonAncestorContainer.splitText(endOffset);
|
|
355
|
-
commonAncestorContainer.splitText(startOffset);
|
|
356
|
-
const { nextSibling } = commonAncestorContainer;
|
|
355
|
+
const nextSibling = commonAncestorContainer.splitText(startOffset);
|
|
357
356
|
this.#startContainer = nextSibling;
|
|
358
357
|
this.#startOffset = 0;
|
|
359
358
|
this.#endContainer = nextSibling;
|
package/dist/lib/ranges.d.ts
CHANGED
|
@@ -12,15 +12,15 @@ export declare class Range {
|
|
|
12
12
|
* 将Range转换为针对特定数组的下标集
|
|
13
13
|
* @param arr 参考数组`[0, 1, 2, ...]`
|
|
14
14
|
*/
|
|
15
|
-
applyTo(arr: number[]): number[];
|
|
15
|
+
applyTo(arr: readonly number[]): readonly number[];
|
|
16
16
|
}
|
|
17
17
|
/** @extends {Array<number|Range>} */
|
|
18
18
|
export declare class Ranges extends Array<number | Range> {
|
|
19
19
|
/** @param a 表达式数组 */
|
|
20
|
-
constructor(a?: number | string | Range | (number | string | Range)[]);
|
|
20
|
+
constructor(a?: number | string | Range | readonly (number | string | Range)[]);
|
|
21
21
|
/**
|
|
22
22
|
* 将Ranges转换为针对特定Array的下标集
|
|
23
23
|
* @param arr 参考数组
|
|
24
24
|
*/
|
|
25
|
-
applyTo(arr: number | unknown[]): number[];
|
|
25
|
+
applyTo(arr: number | readonly unknown[]): readonly number[];
|
|
26
26
|
}
|
package/dist/lib/text.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import type { LintError } from '../base';
|
|
|
4
4
|
export declare class AstText extends AstNode {
|
|
5
5
|
#private;
|
|
6
6
|
readonly type = "text";
|
|
7
|
-
name: undefined;
|
|
8
|
-
data: string;
|
|
7
|
+
readonly name: undefined;
|
|
8
|
+
readonly data: string;
|
|
9
9
|
/** 文本长度 */
|
|
10
10
|
get length(): number;
|
|
11
11
|
/** @param text 包含文本 */
|
package/dist/lib/title.d.ts
CHANGED
package/dist/parser/selector.js
CHANGED
|
@@ -151,7 +151,7 @@ const parseSelector = (selector) => {
|
|
|
151
151
|
}
|
|
152
152
|
if (regex === regularRegex) {
|
|
153
153
|
pushSimple(step, sanitized);
|
|
154
|
-
const pseudos = new Set(stack.flat(2).filter(e => typeof e === 'string' && e.startsWith(':')));
|
|
154
|
+
const pseudos = new Set(stack.flat(2).filter((e) => typeof e === 'string' && e.startsWith(':')));
|
|
155
155
|
if (pseudos.size > 0) {
|
|
156
156
|
Parser.warn('检测到伪选择器,请确认是否需要将":"转义成"\\:"。', pseudos);
|
|
157
157
|
}
|
package/dist/parser/table.js
CHANGED
|
@@ -8,6 +8,8 @@ const index_2 = require("../src/table/index");
|
|
|
8
8
|
const tr_1 = require("../src/table/tr");
|
|
9
9
|
const td_1 = require("../src/table/td");
|
|
10
10
|
const dd_1 = require("../src/nowiki/dd");
|
|
11
|
+
/** @ignore */
|
|
12
|
+
const isTr = (token) => token.lastChild.constructor !== index_1.Token;
|
|
11
13
|
/**
|
|
12
14
|
* 解析表格,注意`tr`和`td`包含开头的换行
|
|
13
15
|
* @param {Token & {firstChild: AstText}} root 根节点
|
|
@@ -30,15 +32,15 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
|
|
|
30
32
|
return;
|
|
31
33
|
}
|
|
32
34
|
const { lastChild } = top;
|
|
33
|
-
if (
|
|
34
|
-
lastChild.setText(String(lastChild) + str);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
35
|
+
if (isTr(top)) {
|
|
37
36
|
const token = new index_1.Token(str, config, accum);
|
|
38
37
|
token.type = 'table-inter';
|
|
39
38
|
token.setAttribute('stage', 3);
|
|
40
39
|
top.insertAt(token);
|
|
41
40
|
}
|
|
41
|
+
else {
|
|
42
|
+
lastChild.setText(String(lastChild) + str);
|
|
43
|
+
}
|
|
42
44
|
};
|
|
43
45
|
for (const outLine of lines) {
|
|
44
46
|
let top = stack.pop();
|
package/dist/src/arg.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ import type { LintError } from '../base';
|
|
|
10
10
|
export declare class ArgToken extends Token {
|
|
11
11
|
#private;
|
|
12
12
|
readonly type = "arg";
|
|
13
|
-
name: string;
|
|
14
|
-
childNodes: [AtomToken] | [AtomToken, Token, ...HiddenToken[]];
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly childNodes: [AtomToken] | [AtomToken, Token, ...HiddenToken[]];
|
|
15
15
|
abstract get children(): [AtomToken] | [AtomToken, Token, ...HiddenToken[]];
|
|
16
16
|
abstract get firstChild(): AtomToken;
|
|
17
17
|
abstract get firstElementChild(): AtomToken;
|
|
@@ -21,7 +21,7 @@ export declare class ArgToken extends Token {
|
|
|
21
21
|
get default(): string | false;
|
|
22
22
|
set default(value: string | false);
|
|
23
23
|
/** @param parts 以'|'分隔的各部分 */
|
|
24
|
-
constructor(parts: string[], config?: Parser.Config, accum?: Token[]);
|
|
24
|
+
constructor(parts: readonly string[], config?: Parser.Config, accum?: Token[]);
|
|
25
25
|
/** @override */
|
|
26
26
|
text(): string;
|
|
27
27
|
/** @override */
|
package/dist/src/attribute.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ declare const AttributeToken_base: ((abstract new (...args: any[]) => {
|
|
|
8
8
|
removeAt(): never;
|
|
9
9
|
insertAt(token: string, i?: number | undefined): Parser.AstText;
|
|
10
10
|
insertAt<T extends Parser.AstNodes>(token: T, i?: number | undefined): T;
|
|
11
|
-
length: number;
|
|
11
|
+
readonly length: number;
|
|
12
12
|
toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
|
|
13
13
|
text(separator?: string | undefined): string;
|
|
14
14
|
afterBuild(): void;
|
|
@@ -26,9 +26,9 @@ declare const AttributeToken_base: ((abstract new (...args: any[]) => {
|
|
|
26
26
|
export declare class AttributeToken extends AttributeToken_base {
|
|
27
27
|
#private;
|
|
28
28
|
type: AttributeTypes;
|
|
29
|
-
name: string;
|
|
30
|
-
tag: string;
|
|
31
|
-
childNodes: [AtomToken, Token];
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly tag: string;
|
|
31
|
+
readonly childNodes: [AtomToken, Token];
|
|
32
32
|
abstract get children(): [AtomToken, Token];
|
|
33
33
|
abstract get firstChild(): AtomToken;
|
|
34
34
|
abstract get firstElementChild(): AtomToken;
|
|
@@ -54,7 +54,7 @@ export declare class AttributeToken extends AttributeToken_base {
|
|
|
54
54
|
* @param value 属性值
|
|
55
55
|
* @param quotes 引号
|
|
56
56
|
*/
|
|
57
|
-
constructor(type: AttributeTypes, tag: string, key: string, equal?: string, value?: string, quotes?: [string?, string?], config?: Parser.Config, accum?: Token[]);
|
|
57
|
+
constructor(type: AttributeTypes, tag: string, key: string, equal?: string, value?: string, quotes?: readonly [string?, string?], config?: Parser.Config, accum?: Token[]);
|
|
58
58
|
/** @override */
|
|
59
59
|
text(): string;
|
|
60
60
|
/** @override */
|
package/dist/src/attribute.js
CHANGED
|
@@ -231,7 +231,7 @@ class AttributeToken extends (0, fixed_1.fixed)(index_1.Token) {
|
|
|
231
231
|
this.type = type;
|
|
232
232
|
this.append(keyToken, valueToken);
|
|
233
233
|
this.#equal = equal;
|
|
234
|
-
this.#quotes = quotes;
|
|
234
|
+
this.#quotes = [...quotes];
|
|
235
235
|
this.tag = tag;
|
|
236
236
|
this.seal('tag');
|
|
237
237
|
this.setAttribute('name', (0, string_1.removeComment)(key).trim().toLowerCase());
|
package/dist/src/attributes.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { AtomToken } from './atom';
|
|
|
4
4
|
import { AttributeToken } from './attribute';
|
|
5
5
|
import type { LintError } from '../base';
|
|
6
6
|
import type { ExtToken, HtmlToken, TdToken, TrToken, TableToken } from '../internal';
|
|
7
|
-
|
|
7
|
+
import type { AttributeTypes } from './attribute';
|
|
8
|
+
declare type AttributesTypes = `${AttributeTypes}s`;
|
|
8
9
|
/**
|
|
9
10
|
* 扩展和HTML标签属性
|
|
10
11
|
* @classdesc `{childNodes: ...AtomToken|AttributeToken}`
|
|
@@ -12,8 +13,8 @@ declare type AttributesTypes = 'ext-attrs' | 'html-attrs' | 'table-attrs';
|
|
|
12
13
|
export declare class AttributesToken extends Token {
|
|
13
14
|
#private;
|
|
14
15
|
type: AttributesTypes;
|
|
15
|
-
name: string;
|
|
16
|
-
childNodes: (AtomToken | AttributeToken)[];
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly childNodes: (AtomToken | AttributeToken)[];
|
|
17
18
|
abstract get children(): (AtomToken | AttributeToken)[];
|
|
18
19
|
abstract get firstChild(): AtomToken | AttributeToken | undefined;
|
|
19
20
|
abstract get firstElementChild(): AtomToken | AttributeToken | undefined;
|
|
@@ -46,7 +47,7 @@ export declare class AttributesToken extends Token {
|
|
|
46
47
|
* 所有指定属性名的AttributeToken
|
|
47
48
|
* @param key 属性名
|
|
48
49
|
*/
|
|
49
|
-
getAttrTokens(key?: string): AttributeToken[];
|
|
50
|
+
getAttrTokens(key?: string): readonly AttributeToken[];
|
|
50
51
|
/**
|
|
51
52
|
* 指定属性名的最后一个AttributeToken
|
|
52
53
|
* @param key 属性名
|
package/dist/src/attributes.js
CHANGED
|
@@ -11,6 +11,10 @@ const atom_1 = require("./atom");
|
|
|
11
11
|
const attribute_1 = require("./attribute");
|
|
12
12
|
/* NOT FOR BROWSER */
|
|
13
13
|
const stages = { 'ext-attrs': 0, 'html-attrs': 2, 'table-attrs': 3 };
|
|
14
|
+
/** @ignore */
|
|
15
|
+
const toAttributeType = (type) => type.slice(0, -1);
|
|
16
|
+
/** @ignore */
|
|
17
|
+
const toDirty = (type) => `${toAttributeType(type)}-dirty`;
|
|
14
18
|
/**
|
|
15
19
|
* 扩展和HTML标签属性
|
|
16
20
|
* @classdesc `{childNodes: ...AtomToken|AttributeToken}`
|
|
@@ -82,7 +86,9 @@ class AttributesToken extends index_1.Token {
|
|
|
82
86
|
let out = '', mt = regex.exec(attr), lastIndex = 0;
|
|
83
87
|
const insertDirty = /** 插入无效属性 */ () => {
|
|
84
88
|
if (out) {
|
|
85
|
-
super.insertAt(new atom_1.AtomToken(out,
|
|
89
|
+
super.insertAt(new atom_1.AtomToken(out, toDirty(type), config, accum, {
|
|
90
|
+
[`Stage-${stages[type]}`]: ':',
|
|
91
|
+
}));
|
|
86
92
|
out = '';
|
|
87
93
|
}
|
|
88
94
|
};
|
|
@@ -90,7 +96,7 @@ class AttributesToken extends index_1.Token {
|
|
|
90
96
|
const { index, 0: full, 1: key, 2: equal, 3: quoteStart, 4: quoted, 5: quoteEnd, 6: unquoted } = mt;
|
|
91
97
|
out += attr.slice(lastIndex, index);
|
|
92
98
|
if (/^(?:[\w:]|\0\d+[t!~{}+-]\x7F)(?:[\w:.-]|\0\d+[t!~{}+-]\x7F)*$/u.test((0, string_1.removeComment)(key).trim())) {
|
|
93
|
-
const value = quoted ?? unquoted, quotes = [quoteStart, quoteEnd], token = new attribute_1.AttributeToken(type
|
|
99
|
+
const value = quoted ?? unquoted, quotes = [quoteStart, quoteEnd], token = new attribute_1.AttributeToken(toAttributeType(type), name, key, equal, value, quotes, config, accum);
|
|
94
100
|
insertDirty();
|
|
95
101
|
super.insertAt(token);
|
|
96
102
|
}
|
|
@@ -116,7 +122,7 @@ class AttributesToken extends index_1.Token {
|
|
|
116
122
|
* @param key 属性名
|
|
117
123
|
*/
|
|
118
124
|
getAttrTokens(key) {
|
|
119
|
-
return this.childNodes.filter(child => child instanceof attribute_1.AttributeToken && (!key || child.name === key.toLowerCase().trim()));
|
|
125
|
+
return this.childNodes.filter((child) => child instanceof attribute_1.AttributeToken && (!key || child.name === key.toLowerCase().trim()));
|
|
120
126
|
}
|
|
121
127
|
/**
|
|
122
128
|
* 指定属性名的最后一个AttributeToken
|
|
@@ -229,7 +235,7 @@ class AttributesToken extends index_1.Token {
|
|
|
229
235
|
token.escape();
|
|
230
236
|
}
|
|
231
237
|
super.insertAt(token, i);
|
|
232
|
-
const { previousVisibleSibling, nextVisibleSibling } = token, type =
|
|
238
|
+
const { previousVisibleSibling, nextVisibleSibling } = token, type = toDirty(this.type), config = this.getAttribute('config'), acceptable = { [`Stage-${stages[this.type]}`]: ':' };
|
|
233
239
|
if (nextVisibleSibling && !/^\s/u.test(String(nextVisibleSibling))) {
|
|
234
240
|
super.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(' ', type, config, [], acceptable)), i + 1);
|
|
235
241
|
}
|
|
@@ -257,7 +263,7 @@ class AttributesToken extends index_1.Token {
|
|
|
257
263
|
else if (value === false) {
|
|
258
264
|
return;
|
|
259
265
|
}
|
|
260
|
-
const token = debug_1.Shadow.run(() => new attribute_1.AttributeToken(this.type
|
|
266
|
+
const token = debug_1.Shadow.run(() => new attribute_1.AttributeToken(toAttributeType(this.type), this.name, key, value === true ? '' : '=', value === true ? '' : value, ['"', '"'], this.getAttribute('config')));
|
|
261
267
|
this.insertAt(token);
|
|
262
268
|
}
|
|
263
269
|
/**
|
package/dist/src/converter.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ declare const ConverterToken_base: (abstract new (...args: any[]) => {
|
|
|
14
14
|
removeFlag(flag: string): void;
|
|
15
15
|
setFlag(flag: string): void;
|
|
16
16
|
toggleFlag(flag: string): void;
|
|
17
|
-
length: number;
|
|
17
|
+
readonly length: number;
|
|
18
18
|
toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
|
|
19
19
|
text(separator?: string | undefined): string;
|
|
20
20
|
insertAt(token: unknown, i?: number | undefined): unknown;
|
|
@@ -30,7 +30,7 @@ declare const ConverterToken_base: (abstract new (...args: any[]) => {
|
|
|
30
30
|
*/
|
|
31
31
|
export declare class ConverterToken extends ConverterToken_base {
|
|
32
32
|
readonly type = "converter";
|
|
33
|
-
childNodes: [ConverterFlagsToken, ...ConverterRuleToken[]];
|
|
33
|
+
readonly childNodes: [ConverterFlagsToken, ...ConverterRuleToken[]];
|
|
34
34
|
abstract get children(): [ConverterFlagsToken, ...ConverterRuleToken[]];
|
|
35
35
|
abstract get lastChild(): ConverterFlagsToken | ConverterRuleToken;
|
|
36
36
|
abstract get lastElementChild(): ConverterFlagsToken | ConverterRuleToken;
|
|
@@ -40,7 +40,7 @@ export declare class ConverterToken extends ConverterToken_base {
|
|
|
40
40
|
* @param flags 转换类型标记
|
|
41
41
|
* @param rules 转换规则
|
|
42
42
|
*/
|
|
43
|
-
constructor(flags: string[], rules: [string, ...string[]], config?: Parser.Config, accum?: Token[]);
|
|
43
|
+
constructor(flags: readonly string[], rules: readonly [string, ...string[]], config?: Parser.Config, accum?: Token[]);
|
|
44
44
|
/** @override */
|
|
45
45
|
text(): string;
|
|
46
46
|
/** @override */
|