wikiparser-node 1.4.2 → 1.4.3
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 +5 -1
- package/dist/base.d.ts +6 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +3 -3
- package/dist/lib/element.d.ts +3 -2
- package/dist/lib/element.js +20 -13
- package/dist/lib/node.js +13 -10
- package/dist/lib/text.js +3 -3
- package/dist/lib/title.js +4 -12
- package/dist/mixin/attributesParent.d.ts +32 -2
- package/dist/mixin/attributesParent.js +14 -25
- package/dist/mixin/fixed.d.ts +2 -1
- package/dist/mixin/fixed.js +3 -1
- package/dist/mixin/flagsParent.d.ts +28 -17
- package/dist/mixin/flagsParent.js +12 -25
- package/dist/mixin/magicLinkParent.d.ts +14 -8
- package/dist/mixin/magicLinkParent.js +7 -8
- package/dist/mixin/singleLine.d.ts +2 -1
- package/dist/mixin/singleLine.js +3 -2
- package/dist/mixin/sol.d.ts +2 -4
- package/dist/mixin/sol.js +8 -6
- package/dist/mixin/syntax.d.ts +5 -2
- package/dist/mixin/syntax.js +14 -18
- package/dist/parser/links.js +1 -3
- package/dist/src/arg.d.ts +4 -4
- package/dist/src/arg.js +4 -4
- package/dist/src/attribute.d.ts +9 -7
- package/dist/src/attribute.js +271 -218
- package/dist/src/attributes.d.ts +3 -3
- package/dist/src/attributes.js +0 -1
- package/dist/src/converter.d.ts +7 -2
- package/dist/src/converter.js +113 -64
- package/dist/src/converterFlags.d.ts +5 -5
- package/dist/src/converterFlags.js +0 -1
- package/dist/src/converterRule.d.ts +5 -5
- package/dist/src/converterRule.js +0 -1
- package/dist/src/extLink.d.ts +7 -2
- package/dist/src/extLink.js +159 -110
- package/dist/src/gallery.d.ts +5 -5
- package/dist/src/gallery.js +0 -1
- package/dist/src/heading.d.ts +8 -8
- package/dist/src/heading.js +172 -125
- package/dist/src/html.d.ts +8 -5
- package/dist/src/html.js +263 -214
- package/dist/src/imageParameter.d.ts +2 -2
- package/dist/src/imageParameter.js +1 -0
- package/dist/src/imagemap.d.ts +5 -5
- package/dist/src/imagemap.js +4 -10
- package/dist/src/imagemapLink.d.ts +7 -4
- package/dist/src/imagemapLink.js +75 -26
- package/dist/src/index.js +3 -4
- package/dist/src/link/base.d.ts +2 -2
- package/dist/src/link/base.js +1 -4
- package/dist/src/link/file.d.ts +1 -1
- package/dist/src/link/file.js +0 -1
- package/dist/src/link/galleryImage.d.ts +2 -1
- package/dist/src/link/galleryImage.js +136 -88
- package/dist/src/link/index.js +0 -1
- package/dist/src/magicLink.d.ts +11 -3
- package/dist/src/magicLink.js +170 -120
- package/dist/src/nested.d.ts +5 -5
- package/dist/src/nested.js +1 -0
- package/dist/src/nowiki/base.d.ts +6 -2
- package/dist/src/nowiki/base.js +79 -28
- package/dist/src/nowiki/comment.d.ts +0 -2
- package/dist/src/nowiki/comment.js +0 -9
- package/dist/src/nowiki/doubleUnderscore.js +88 -38
- package/dist/src/nowiki/hr.d.ts +1 -4
- package/dist/src/nowiki/hr.js +53 -4
- package/dist/src/nowiki/index.d.ts +2 -2
- package/dist/src/nowiki/index.js +1 -0
- package/dist/src/nowiki/list.d.ts +1 -4
- package/dist/src/nowiki/list.js +88 -39
- package/dist/src/nowiki/listBase.d.ts +1 -1
- package/dist/src/nowiki/listBase.js +52 -2
- package/dist/src/nowiki/quote.d.ts +3 -3
- package/dist/src/nowiki/quote.js +102 -54
- package/dist/src/paramTag/index.d.ts +5 -5
- package/dist/src/paramTag/index.js +2 -1
- package/dist/src/parameter.d.ts +11 -8
- package/dist/src/parameter.js +225 -176
- package/dist/src/pre.d.ts +5 -5
- package/dist/src/pre.js +1 -0
- package/dist/src/syntax.d.ts +6 -0
- package/dist/src/syntax.js +74 -23
- package/dist/src/table/base.d.ts +6 -3
- package/dist/src/table/base.js +100 -49
- package/dist/src/table/index.d.ts +6 -3
- package/dist/src/table/index.js +5 -9
- package/dist/src/table/td.d.ts +9 -5
- package/dist/src/table/td.js +270 -217
- package/dist/src/table/tr.d.ts +4 -4
- package/dist/src/table/tr.js +1 -0
- package/dist/src/tagPair/ext.d.ts +6 -3
- package/dist/src/tagPair/ext.js +168 -118
- package/dist/src/tagPair/include.d.ts +2 -4
- package/dist/src/tagPair/include.js +0 -8
- package/dist/src/tagPair/index.d.ts +1 -1
- package/dist/src/tagPair/index.js +115 -66
- package/dist/src/transclude.d.ts +3 -3
- package/dist/src/transclude.js +4 -9
- package/dist/util/debug.js +0 -2
- package/package.json +3 -3
package/dist/src/table/base.js
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
2
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
37
|
exports.TableBaseToken = void 0;
|
|
4
38
|
const debug_1 = require("../../util/debug");
|
|
@@ -24,58 +58,75 @@ const escapeTable = (syntax) => {
|
|
|
24
58
|
* 表格行,含开头的换行,不含结尾的换行
|
|
25
59
|
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ...Token]}`
|
|
26
60
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
61
|
+
let TableBaseToken = (() => {
|
|
62
|
+
let _classDecorators = [(0, attributesParent_1.attributesParent)(1)];
|
|
63
|
+
let _classDescriptor;
|
|
64
|
+
let _classExtraInitializers = [];
|
|
65
|
+
let _classThis;
|
|
66
|
+
let _classSuper = index_2.Token;
|
|
67
|
+
var TableBaseToken = class extends _classSuper {
|
|
68
|
+
static { _classThis = this; }
|
|
69
|
+
static {
|
|
70
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
71
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
72
|
+
TableBaseToken = _classThis = _classDescriptor.value;
|
|
73
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
74
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
75
|
+
}
|
|
76
|
+
/* NOT FOR BROWSER END */
|
|
77
|
+
/**
|
|
78
|
+
* @param pattern 表格语法正则
|
|
79
|
+
* @param syntax 表格语法
|
|
80
|
+
* @param attr 表格属性
|
|
81
|
+
*/
|
|
82
|
+
constructor(pattern, syntax, attr, config = index_1.default.getConfig(), accum = [], acceptable = {}) {
|
|
83
|
+
super(undefined, config, accum, acceptable);
|
|
84
|
+
this.append(new syntax_1.SyntaxToken(syntax, pattern, 'table-syntax', config, accum, {
|
|
85
|
+
'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':',
|
|
86
|
+
}),
|
|
87
|
+
// @ts-expect-error abstract class
|
|
88
|
+
new attributes_1.AttributesToken(attr, 'table-attrs', this.type, config, accum));
|
|
89
|
+
/* NOT FOR BROWSER */
|
|
90
|
+
this.protectChildren(0, 1);
|
|
91
|
+
}
|
|
40
92
|
/* NOT FOR BROWSER */
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
else if (child instanceof TableBaseToken) {
|
|
67
|
-
child.escape();
|
|
93
|
+
/** @override */
|
|
94
|
+
cloneNode() {
|
|
95
|
+
const [syntax, attr, ...cloned] = this.cloneChildNodes();
|
|
96
|
+
return debug_1.Shadow.run(() => {
|
|
97
|
+
const { constructor } = this, token = new constructor(undefined, undefined, this.getAttribute('config'));
|
|
98
|
+
token.firstChild.safeReplaceWith(syntax);
|
|
99
|
+
token.childNodes[1].safeReplaceWith(attr);
|
|
100
|
+
if (token.type === 'td') { // TdToken
|
|
101
|
+
token.childNodes[2].safeReplaceWith(cloned[0]);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
token.append(...cloned);
|
|
105
|
+
}
|
|
106
|
+
return token;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/** 转义表格语法 */
|
|
110
|
+
escape() {
|
|
111
|
+
for (const child of this.childNodes) {
|
|
112
|
+
if (child instanceof syntax_1.SyntaxToken) {
|
|
113
|
+
escapeTable(child);
|
|
114
|
+
}
|
|
115
|
+
else if (child instanceof TableBaseToken) {
|
|
116
|
+
child.escape();
|
|
117
|
+
}
|
|
68
118
|
}
|
|
69
119
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
120
|
+
/** @private */
|
|
121
|
+
setSyntax(syntax, esc = false) {
|
|
122
|
+
const { firstChild } = this;
|
|
123
|
+
firstChild.replaceChildren(syntax);
|
|
124
|
+
if (esc) {
|
|
125
|
+
escapeTable(firstChild);
|
|
126
|
+
}
|
|
77
127
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
128
|
+
};
|
|
129
|
+
return TableBaseToken = _classThis;
|
|
130
|
+
})();
|
|
80
131
|
exports.TableBaseToken = TableBaseToken;
|
|
81
132
|
constants_1.classes['TableBaseToken'] = __filename;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import Parser from '../../index';
|
|
2
2
|
import { TrBaseToken } from './trBase';
|
|
3
3
|
import { SyntaxToken } from '../syntax';
|
|
4
|
-
import type { LintError } from '../../base';
|
|
4
|
+
import type { LintError, AST } from '../../base';
|
|
5
|
+
import type { SyntaxBase } from '../../mixin/syntax';
|
|
5
6
|
import type { AttributesToken, TdToken, TrToken, Token } from '../../internal';
|
|
6
7
|
import type { TableCoords } from './trBase';
|
|
7
8
|
import type { TdAttrs, TdSubtypes, TdSpanAttrs } from './td';
|
|
@@ -12,6 +13,8 @@ export interface TableRenderedCoords {
|
|
|
12
13
|
readonly x: number;
|
|
13
14
|
readonly y: number;
|
|
14
15
|
}
|
|
16
|
+
export interface TableToken extends SyntaxBase {
|
|
17
|
+
}
|
|
15
18
|
/**
|
|
16
19
|
* 表格
|
|
17
20
|
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken, ...TrToken, ?SyntaxToken]}`
|
|
@@ -19,8 +22,8 @@ export interface TableRenderedCoords {
|
|
|
19
22
|
export declare abstract class TableToken extends TrBaseToken {
|
|
20
23
|
readonly type = "table";
|
|
21
24
|
readonly childNodes: readonly [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[], SyntaxToken] | readonly [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[]];
|
|
22
|
-
abstract get children(): [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[], SyntaxToken] | [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[]];
|
|
23
25
|
abstract get lastChild(): AttributesToken | TdToken | TrToken | SyntaxToken;
|
|
26
|
+
abstract get children(): [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[], SyntaxToken] | [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[]];
|
|
24
27
|
abstract get lastElementChild(): AttributesToken | TdToken | TrToken | SyntaxToken;
|
|
25
28
|
/** 表格是否闭合 */
|
|
26
29
|
get closed(): boolean;
|
|
@@ -39,7 +42,7 @@ export declare abstract class TableToken extends TrBaseToken {
|
|
|
39
42
|
*/
|
|
40
43
|
close(syntax?: string, halfParsed?: boolean): void;
|
|
41
44
|
/** @override */
|
|
42
|
-
json():
|
|
45
|
+
json(): AST;
|
|
43
46
|
/**
|
|
44
47
|
* @override
|
|
45
48
|
* @param token 待插入的子节点
|
package/dist/src/table/index.js
CHANGED
|
@@ -16,6 +16,7 @@ const closingPattern = /^\n[^\S\n]*(?:\|\}|\{\{\s*!\s*\}\}\}|\{\{\s*!\)\s*\}\})$
|
|
|
16
16
|
*/
|
|
17
17
|
class TableToken extends trBase_1.TrBaseToken {
|
|
18
18
|
type = 'table';
|
|
19
|
+
/* NOT FOR BROWSER END */
|
|
19
20
|
/** 表格是否闭合 */
|
|
20
21
|
get closed() {
|
|
21
22
|
return this.lastChild.type === 'table-syntax';
|
|
@@ -51,26 +52,21 @@ class TableToken extends trBase_1.TrBaseToken {
|
|
|
51
52
|
*/
|
|
52
53
|
close(syntax = '\n|}', halfParsed = false) {
|
|
53
54
|
const config = this.getAttribute('config'), accum = this.getAttribute('accum'), inner = halfParsed ? [syntax] : index_1.default.parse(syntax, this.getAttribute('include'), 2, config).childNodes;
|
|
54
|
-
/* NOT FOR BROWSER */
|
|
55
55
|
if (this.lastChild.type !== 'table-syntax') {
|
|
56
|
-
/* NOT FOR BROWSER END */
|
|
57
56
|
const token = debug_1.Shadow.run(() => super.insertAt(new syntax_1.SyntaxToken(undefined, closingPattern, 'table-syntax', config, accum, {
|
|
58
57
|
'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':',
|
|
59
58
|
})));
|
|
60
|
-
/* NOT FOR BROWSER */
|
|
61
59
|
if (!halfParsed) {
|
|
62
60
|
token.afterBuild();
|
|
63
61
|
}
|
|
64
|
-
/* NOT FOR BROWSER END */
|
|
65
62
|
}
|
|
66
63
|
this.lastChild.replaceChildren(...inner);
|
|
67
64
|
}
|
|
68
65
|
/** @override */
|
|
69
66
|
json() {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
};
|
|
67
|
+
const json = super.json();
|
|
68
|
+
json['closed'] = this.closed;
|
|
69
|
+
return json;
|
|
74
70
|
}
|
|
75
71
|
/* NOT FOR BROWSER */
|
|
76
72
|
/**
|
|
@@ -86,7 +82,7 @@ class TableToken extends trBase_1.TrBaseToken {
|
|
|
86
82
|
index_1.default.warn('改为将单元格插入当前行。');
|
|
87
83
|
return previous.insertAt(token);
|
|
88
84
|
}
|
|
89
|
-
else if (i > 0 && token instanceof syntax_1.SyntaxToken && token.
|
|
85
|
+
else if (i > 0 && token instanceof syntax_1.SyntaxToken && token.pattern !== closingPattern) {
|
|
90
86
|
throw new SyntaxError(`表格的闭合部分不符合语法:${(0, string_1.noWrap)(String(token))}`);
|
|
91
87
|
}
|
|
92
88
|
return super.insertAt(token, i);
|
package/dist/src/table/td.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Parser from '../../index';
|
|
2
2
|
import { Token } from '../index';
|
|
3
3
|
import { TableBaseToken } from './base';
|
|
4
|
-
import type { LintError } from '../../base';
|
|
4
|
+
import type { LintError, AST } from '../../base';
|
|
5
5
|
import type { SyntaxToken, AttributesToken, TrToken, TableToken } from '../../internal';
|
|
6
6
|
export type TdSubtypes = 'td' | 'th' | 'caption';
|
|
7
7
|
export interface TdSpanAttrs {
|
|
@@ -11,16 +11,20 @@ export interface TdSpanAttrs {
|
|
|
11
11
|
declare type TdAttrGetter<T extends string> = T extends keyof TdSpanAttrs ? number : string | true | undefined;
|
|
12
12
|
declare type TdAttrSetter<T extends string> = T extends keyof TdSpanAttrs ? number : string | boolean;
|
|
13
13
|
export type TdAttrs = Record<string, string | true> & TdSpanAttrs;
|
|
14
|
+
/**
|
|
15
|
+
* `<td>`、`<th>`和`<caption>`
|
|
16
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, Token]}`
|
|
17
|
+
*/
|
|
14
18
|
export declare abstract class TdToken extends TableBaseToken {
|
|
15
19
|
#private;
|
|
16
20
|
readonly type = "td";
|
|
17
21
|
readonly childNodes: readonly [SyntaxToken, AttributesToken, Token];
|
|
18
|
-
abstract get children(): [SyntaxToken, AttributesToken, Token];
|
|
19
22
|
abstract get parentNode(): TrToken | TableToken | undefined;
|
|
20
|
-
abstract get parentElement(): TrToken | TableToken | undefined;
|
|
21
23
|
abstract get nextSibling(): this | TrToken | SyntaxToken | undefined;
|
|
22
|
-
abstract get nextElementSibling(): this | TrToken | SyntaxToken | undefined;
|
|
23
24
|
abstract get previousSibling(): Token | undefined;
|
|
25
|
+
abstract get children(): [SyntaxToken, AttributesToken, Token];
|
|
26
|
+
abstract get parentElement(): TrToken | TableToken | undefined;
|
|
27
|
+
abstract get nextElementSibling(): this | TrToken | SyntaxToken | undefined;
|
|
24
28
|
/** 单元格类型 */
|
|
25
29
|
get subtype(): TdSubtypes;
|
|
26
30
|
set subtype(subtype: TdSubtypes);
|
|
@@ -45,7 +49,7 @@ export declare abstract class TdToken extends TableBaseToken {
|
|
|
45
49
|
/** @override */
|
|
46
50
|
print(): string;
|
|
47
51
|
/** @override */
|
|
48
|
-
json():
|
|
52
|
+
json(): AST;
|
|
49
53
|
/** 是否位于行首 */
|
|
50
54
|
isIndependent(): boolean;
|
|
51
55
|
/** @override */
|