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/td.js
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
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
|
+
};
|
|
3
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
37
|
exports.createTd = exports.TdToken = void 0;
|
|
5
38
|
const lint_1 = require("../../util/lint");
|
|
@@ -13,254 +46,274 @@ const base_1 = require("./base");
|
|
|
13
46
|
* `<td>`、`<th>`和`<caption>`
|
|
14
47
|
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, Token]}`
|
|
15
48
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
set rowspan(rowspan) {
|
|
32
|
-
this.setAttr('rowspan', rowspan);
|
|
33
|
-
}
|
|
34
|
-
/** colspan */
|
|
35
|
-
get colspan() {
|
|
36
|
-
return this.getAttr('colspan');
|
|
37
|
-
}
|
|
38
|
-
set colspan(colspan) {
|
|
39
|
-
this.setAttr('colspan', colspan);
|
|
40
|
-
}
|
|
41
|
-
/** 内部wikitext */
|
|
42
|
-
get innerText() {
|
|
43
|
-
return this.lastChild.text();
|
|
44
|
-
}
|
|
45
|
-
set innerText(text) {
|
|
46
|
-
this.lastChild.replaceChildren(...index_1.default.parse(text, true, undefined, this.getAttribute('config')).childNodes);
|
|
47
|
-
}
|
|
48
|
-
/* NOT FOR BROWSER END */
|
|
49
|
-
/**
|
|
50
|
-
* @param syntax 单元格语法
|
|
51
|
-
* @param inner 内部wikitext
|
|
52
|
-
*/
|
|
53
|
-
constructor(syntax, inner, config = index_1.default.getConfig(), accum = []) {
|
|
54
|
-
let innerSyntax = /\||\0\d+!\x7F/u.exec(inner ?? ''), attr = innerSyntax ? inner.slice(0, innerSyntax.index) : '';
|
|
55
|
-
if (/\[\[|-\{/u.test(attr)) {
|
|
56
|
-
innerSyntax = null;
|
|
57
|
-
attr = '';
|
|
49
|
+
let TdToken = (() => {
|
|
50
|
+
var _a;
|
|
51
|
+
let _classDecorators = [fixed_1.fixedToken];
|
|
52
|
+
let _classDescriptor;
|
|
53
|
+
let _classExtraInitializers = [];
|
|
54
|
+
let _classThis;
|
|
55
|
+
let _classSuper = base_1.TableBaseToken;
|
|
56
|
+
var TdToken = class extends _classSuper {
|
|
57
|
+
static { _classThis = this; }
|
|
58
|
+
static {
|
|
59
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
60
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
61
|
+
TdToken = _classThis = _classDescriptor.value;
|
|
62
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
63
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
58
64
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
type = 'td';
|
|
66
|
+
#innerSyntax = '';
|
|
67
|
+
/* NOT FOR BROWSER END */
|
|
68
|
+
/** 单元格类型 */
|
|
69
|
+
get subtype() {
|
|
70
|
+
return this.#getSyntax().subtype;
|
|
62
71
|
}
|
|
63
|
-
const innerToken = new index_2.Token(inner?.slice((innerSyntax?.index ?? NaN) + this.#innerSyntax.length), config, accum);
|
|
64
|
-
innerToken.type = 'td-inner';
|
|
65
|
-
innerToken.setAttribute('stage', 4);
|
|
66
|
-
this.insertAt(innerToken);
|
|
67
|
-
}
|
|
68
|
-
/** 表格语法信息 */
|
|
69
|
-
#getSyntax() {
|
|
70
|
-
const syntax = this.firstChild.text(),
|
|
71
72
|
/* NOT FOR BROWSER */
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
char = syntax.slice(-1);
|
|
75
|
-
let subtype = 'td';
|
|
76
|
-
if (char === '!') {
|
|
77
|
-
subtype = 'th';
|
|
73
|
+
set subtype(subtype) {
|
|
74
|
+
this.setSyntax(subtype);
|
|
78
75
|
}
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
/** rowspan */
|
|
77
|
+
get rowspan() {
|
|
78
|
+
return this.getAttr('rowspan');
|
|
81
79
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return { subtype, escape: esc, correction: false };
|
|
80
|
+
set rowspan(rowspan) {
|
|
81
|
+
this.setAttr('rowspan', rowspan);
|
|
85
82
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return
|
|
83
|
+
/** colspan */
|
|
84
|
+
get colspan() {
|
|
85
|
+
return this.getAttr('colspan');
|
|
89
86
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
result.correction = str.includes('\n') && debug_1.Shadow.run(() => {
|
|
93
|
-
const config = this.getAttribute('config'), include = this.getAttribute('include');
|
|
94
|
-
return String(new index_2.Token(str, config).parseOnce(0, include).parseOnce()).includes('\n');
|
|
95
|
-
});
|
|
96
|
-
if (subtype === 'th' && result.subtype !== 'th') {
|
|
97
|
-
result.subtype = 'th';
|
|
98
|
-
result.correction = true;
|
|
87
|
+
set colspan(colspan) {
|
|
88
|
+
this.setAttr('colspan', colspan);
|
|
99
89
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
this.#innerSyntax = this.buildFromStr(this.#innerSyntax, constants_1.BuildMethod.String);
|
|
90
|
+
/** 内部wikitext */
|
|
91
|
+
get innerText() {
|
|
92
|
+
return this.lastChild.text();
|
|
93
|
+
}
|
|
94
|
+
set innerText(text) {
|
|
95
|
+
this.lastChild.replaceChildren(...index_1.default.parse(text, true, undefined, this.getAttribute('config')).childNodes);
|
|
107
96
|
}
|
|
108
|
-
}
|
|
109
|
-
/** @private */
|
|
110
|
-
toString() {
|
|
111
|
-
/* NOT FOR BROWSER */
|
|
112
|
-
this.#correct();
|
|
113
|
-
/* NOT FOR BROWSER END */
|
|
114
|
-
const { childNodes: [syntax, attr, inner] } = this;
|
|
115
|
-
return `${String(syntax)}${String(attr)}${this.#innerSyntax}${String(inner)}`;
|
|
116
|
-
}
|
|
117
|
-
/** @override */
|
|
118
|
-
text() {
|
|
119
|
-
/* NOT FOR BROWSER */
|
|
120
|
-
this.#correct();
|
|
121
97
|
/* NOT FOR BROWSER END */
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
98
|
+
/**
|
|
99
|
+
* @param syntax 单元格语法
|
|
100
|
+
* @param inner 内部wikitext
|
|
101
|
+
*/
|
|
102
|
+
constructor(syntax, inner, config = index_1.default.getConfig(), accum = []) {
|
|
103
|
+
let innerSyntax = /\||\0\d+!\x7F/u.exec(inner ?? ''), attr = innerSyntax ? inner.slice(0, innerSyntax.index) : '';
|
|
104
|
+
if (/\[\[|-\{/u.test(attr)) {
|
|
105
|
+
innerSyntax = null;
|
|
106
|
+
attr = '';
|
|
107
|
+
}
|
|
108
|
+
super(/^(?:\n[^\S\n]*(?:[|!]|\|\+|\{\{\s*!\s*\}\}\+?)|(?:\||\{\{\s*!\s*\}\}){2}|!!|\{\{\s*!!\s*\}\})$/u, syntax, attr, config, accum, { SyntaxToken: 0, AttributesToken: 1, Token: 2 });
|
|
109
|
+
if (innerSyntax) {
|
|
110
|
+
[this.#innerSyntax] = innerSyntax;
|
|
111
|
+
}
|
|
112
|
+
const innerToken = new index_2.Token(inner?.slice((innerSyntax?.index ?? NaN) + this.#innerSyntax.length), config, accum);
|
|
113
|
+
innerToken.type = 'td-inner';
|
|
114
|
+
innerToken.setAttribute('stage', 4);
|
|
115
|
+
this.insertAt(innerToken);
|
|
116
|
+
}
|
|
117
|
+
/** 表格语法信息 */
|
|
118
|
+
#getSyntax() {
|
|
119
|
+
const syntax = this.firstChild.text(),
|
|
120
|
+
/* NOT FOR BROWSER */
|
|
121
|
+
esc = syntax.includes('{{'),
|
|
122
|
+
/* NOT FOR BROWSER END */
|
|
123
|
+
char = syntax.slice(-1);
|
|
124
|
+
let subtype = 'td';
|
|
125
|
+
if (char === '!') {
|
|
126
|
+
subtype = 'th';
|
|
127
|
+
}
|
|
128
|
+
else if (char === '+') {
|
|
129
|
+
subtype = 'caption';
|
|
130
|
+
}
|
|
131
|
+
if (this.isIndependent()) {
|
|
132
|
+
return {
|
|
133
|
+
subtype,
|
|
134
|
+
/* NOT FOR BROWSER */
|
|
135
|
+
escape: esc,
|
|
136
|
+
correction: false,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/* NOT FOR BROWSER */
|
|
140
|
+
const { previousSibling } = this;
|
|
141
|
+
if (!(previousSibling instanceof TdToken)) {
|
|
142
|
+
return { subtype, escape: esc, correction: true };
|
|
143
|
+
}
|
|
144
|
+
const result = previousSibling.#getSyntax(), str = String(previousSibling.lastChild);
|
|
145
|
+
result.escape ||= esc;
|
|
146
|
+
result.correction = str.includes('\n') && debug_1.Shadow.run(() => {
|
|
147
|
+
const config = this.getAttribute('config'), include = this.getAttribute('include');
|
|
148
|
+
return String(new index_2.Token(str, config).parseOnce(0, include).parseOnce()).includes('\n');
|
|
149
|
+
});
|
|
150
|
+
if (subtype === 'th' && result.subtype !== 'th') {
|
|
151
|
+
result.subtype = 'th';
|
|
152
|
+
result.correction = true;
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
/** @private */
|
|
157
|
+
afterBuild() {
|
|
158
|
+
if (this.#innerSyntax.includes('\0')) {
|
|
159
|
+
this.#innerSyntax = this.buildFromStr(this.#innerSyntax, constants_1.BuildMethod.String);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** @private */
|
|
163
|
+
toString() {
|
|
128
164
|
/* NOT FOR BROWSER */
|
|
129
165
|
this.#correct();
|
|
130
166
|
/* NOT FOR BROWSER END */
|
|
131
|
-
|
|
167
|
+
const { childNodes: [syntax, attr, inner] } = this;
|
|
168
|
+
return `${String(syntax)}${String(attr)}${this.#innerSyntax}${String(inner)}`;
|
|
132
169
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
170
|
+
/** @override */
|
|
171
|
+
text() {
|
|
172
|
+
/* NOT FOR BROWSER */
|
|
173
|
+
this.#correct();
|
|
174
|
+
/* NOT FOR BROWSER END */
|
|
175
|
+
const { childNodes: [syntax, attr, inner] } = this;
|
|
176
|
+
return `${syntax.text()}${attr.text()}${this.#innerSyntax}${inner.text()}`;
|
|
177
|
+
}
|
|
178
|
+
/** @private */
|
|
179
|
+
getGaps(i) {
|
|
180
|
+
if (i === 1) {
|
|
181
|
+
/* NOT FOR BROWSER */
|
|
182
|
+
this.#correct();
|
|
183
|
+
/* NOT FOR BROWSER END */
|
|
184
|
+
return this.#innerSyntax.length;
|
|
185
|
+
}
|
|
186
|
+
return 0;
|
|
187
|
+
}
|
|
188
|
+
/** @override */
|
|
189
|
+
lint(start = this.getAbsoluteIndex()) {
|
|
190
|
+
const errors = super.lint(start);
|
|
191
|
+
start += this.getRelativeIndex(this.length - 1);
|
|
192
|
+
for (const child of this.lastChild.childNodes) {
|
|
193
|
+
if (child.type === 'text') {
|
|
194
|
+
const { data } = child;
|
|
195
|
+
if (data.includes('|')) {
|
|
196
|
+
errors.push((0, lint_1.generateForChild)(child, { start }, 'additional "|" in a table cell', data.includes('||') ? 'error' : 'warning'));
|
|
197
|
+
}
|
|
144
198
|
}
|
|
145
199
|
}
|
|
200
|
+
return errors;
|
|
146
201
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const { childNodes: [syntax, attr, inner] } = this;
|
|
152
|
-
return `<span class="wpb-td">${syntax.print()}${attr.print()}${this.#innerSyntax}${inner.print()}</span>`;
|
|
153
|
-
}
|
|
154
|
-
/** @override */
|
|
155
|
-
json() {
|
|
156
|
-
return {
|
|
157
|
-
...super.json(),
|
|
158
|
-
subtype: this.subtype,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
/* NOT FOR BROWSER */
|
|
162
|
-
/** 是否位于行首 */
|
|
163
|
-
isIndependent() {
|
|
164
|
-
return this.firstChild.text().startsWith('\n');
|
|
165
|
-
}
|
|
166
|
-
/** @override */
|
|
167
|
-
cloneNode() {
|
|
168
|
-
const token = super.cloneNode();
|
|
169
|
-
token.setAttribute('innerSyntax', this.#innerSyntax);
|
|
170
|
-
return token;
|
|
171
|
-
}
|
|
172
|
-
/** @private */
|
|
173
|
-
getAttribute(key) {
|
|
174
|
-
return key === 'innerSyntax' ? this.#innerSyntax : super.getAttribute(key);
|
|
175
|
-
}
|
|
176
|
-
/** @private */
|
|
177
|
-
setAttribute(key, value) {
|
|
178
|
-
if (key === 'innerSyntax') {
|
|
179
|
-
this.#innerSyntax = value ?? '';
|
|
202
|
+
/** @override */
|
|
203
|
+
print() {
|
|
204
|
+
const { childNodes: [syntax, attr, inner] } = this;
|
|
205
|
+
return `<span class="wpb-td">${syntax.print()}${attr.print()}${this.#innerSyntax}${inner.print()}</span>`;
|
|
180
206
|
}
|
|
181
|
-
|
|
182
|
-
|
|
207
|
+
/** @override */
|
|
208
|
+
json() {
|
|
209
|
+
const json = super.json();
|
|
210
|
+
json['subtype'] = this.subtype;
|
|
211
|
+
return json;
|
|
183
212
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
* @param esc 是否需要转义
|
|
189
|
-
*/
|
|
190
|
-
setSyntax(syntax, esc = false) {
|
|
191
|
-
const aliases = { td: '\n|', th: '\n!', caption: '\n|+' };
|
|
192
|
-
super.setSyntax(aliases[syntax] ?? syntax, esc);
|
|
193
|
-
}
|
|
194
|
-
/** 修复\<td\>语法 */
|
|
195
|
-
#correct() {
|
|
196
|
-
if (String(this.childNodes[1])) {
|
|
197
|
-
this.#innerSyntax ||= '|';
|
|
213
|
+
/* NOT FOR BROWSER */
|
|
214
|
+
/** 是否位于行首 */
|
|
215
|
+
isIndependent() {
|
|
216
|
+
return this.firstChild.text().startsWith('\n');
|
|
198
217
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
218
|
+
/** @override */
|
|
219
|
+
cloneNode() {
|
|
220
|
+
const token = super.cloneNode();
|
|
221
|
+
token.setAttribute('innerSyntax', this.#innerSyntax);
|
|
222
|
+
return token;
|
|
202
223
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (!this.isIndependent()) {
|
|
207
|
-
const { subtype, escape } = this.#getSyntax();
|
|
208
|
-
this.setSyntax(subtype, escape);
|
|
224
|
+
/** @private */
|
|
225
|
+
getAttribute(key) {
|
|
226
|
+
return key === 'innerSyntax' ? this.#innerSyntax : super.getAttribute(key);
|
|
209
227
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return (key === 'rowspan' || key === 'colspan' ? Number(value) || 1 : value);
|
|
219
|
-
}
|
|
220
|
-
/** @override */
|
|
221
|
-
getAttrs() {
|
|
222
|
-
const attr = super.getAttrs();
|
|
223
|
-
if ('rowspan' in attr) {
|
|
224
|
-
attr.rowspan = Number(attr.rowspan);
|
|
228
|
+
/** @private */
|
|
229
|
+
setAttribute(key, value) {
|
|
230
|
+
if (key === 'innerSyntax') {
|
|
231
|
+
this.#innerSyntax = value ?? '';
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
super.setAttribute(key, value);
|
|
235
|
+
}
|
|
225
236
|
}
|
|
226
|
-
|
|
227
|
-
|
|
237
|
+
/**
|
|
238
|
+
* @override
|
|
239
|
+
* @param syntax 表格语法
|
|
240
|
+
* @param esc 是否需要转义
|
|
241
|
+
*/
|
|
242
|
+
setSyntax(syntax, esc = false) {
|
|
243
|
+
const aliases = { td: '\n|', th: '\n!', caption: '\n|+' };
|
|
244
|
+
super.setSyntax(aliases[syntax] ?? syntax, esc);
|
|
228
245
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
246
|
+
/** 修复\<td\>语法 */
|
|
247
|
+
#correct() {
|
|
248
|
+
if (String(this.childNodes[1])) {
|
|
249
|
+
this.#innerSyntax ||= '|';
|
|
250
|
+
}
|
|
251
|
+
const { subtype, escape, correction } = this.#getSyntax();
|
|
252
|
+
if (correction) {
|
|
253
|
+
this.setSyntax(subtype, escape);
|
|
235
254
|
}
|
|
236
|
-
return;
|
|
237
255
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
256
|
+
/** 改为独占一行 */
|
|
257
|
+
independence() {
|
|
258
|
+
if (!this.isIndependent()) {
|
|
259
|
+
const { subtype, escape } = this.#getSyntax();
|
|
260
|
+
this.setSyntax(subtype, escape);
|
|
261
|
+
}
|
|
242
262
|
}
|
|
243
|
-
|
|
244
|
-
|
|
263
|
+
/**
|
|
264
|
+
* @override
|
|
265
|
+
* @param key 属性键
|
|
266
|
+
*/
|
|
267
|
+
getAttr(key) {
|
|
268
|
+
const value = super.getAttr(key);
|
|
269
|
+
key = key.toLowerCase().trim();
|
|
270
|
+
return (key === 'rowspan' || key === 'colspan' ? Number(value) || 1 : value);
|
|
245
271
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
272
|
+
/** @override */
|
|
273
|
+
getAttrs() {
|
|
274
|
+
const attr = super.getAttrs();
|
|
275
|
+
if ('rowspan' in attr) {
|
|
276
|
+
attr.rowspan = Number(attr.rowspan);
|
|
277
|
+
}
|
|
278
|
+
if ('colspan' in attr) {
|
|
279
|
+
attr.colspan = Number(attr.colspan);
|
|
280
|
+
}
|
|
281
|
+
return attr;
|
|
249
282
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
283
|
+
setAttr(keyOrProp, value) {
|
|
284
|
+
if (typeof keyOrProp !== 'string') {
|
|
285
|
+
for (const [key, val] of Object.entries(keyOrProp)) {
|
|
286
|
+
this.setAttr(key, val);
|
|
287
|
+
}
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const key = keyOrProp.toLowerCase().trim();
|
|
291
|
+
let v;
|
|
292
|
+
if (typeof value === 'number' && (key === 'rowspan' || key === 'colspan')) {
|
|
293
|
+
v = value === 1 ? false : String(value);
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
v = value;
|
|
297
|
+
}
|
|
298
|
+
super.setAttr(key, v);
|
|
299
|
+
if (!String(this.childNodes[1])) {
|
|
300
|
+
this.#innerSyntax = '';
|
|
301
|
+
}
|
|
256
302
|
}
|
|
257
|
-
|
|
258
|
-
|
|
303
|
+
/** @override */
|
|
304
|
+
escape() {
|
|
305
|
+
super.escape();
|
|
306
|
+
if (String(this.childNodes[1])) {
|
|
307
|
+
this.#innerSyntax ||= '{{!}}';
|
|
308
|
+
}
|
|
309
|
+
if (this.#innerSyntax === '|') {
|
|
310
|
+
this.#innerSyntax = '{{!}}';
|
|
311
|
+
}
|
|
259
312
|
}
|
|
260
|
-
}
|
|
261
|
-
|
|
313
|
+
};
|
|
314
|
+
return TdToken = _classThis;
|
|
315
|
+
})();
|
|
262
316
|
exports.TdToken = TdToken;
|
|
263
|
-
_a = TdToken;
|
|
264
317
|
/* NOT FOR BROWSER */
|
|
265
318
|
/**
|
|
266
319
|
* 创建新的单元格
|
package/dist/src/table/tr.d.ts
CHANGED
|
@@ -9,14 +9,14 @@ export declare abstract class TrToken extends TrBaseToken {
|
|
|
9
9
|
#private;
|
|
10
10
|
readonly type = "tr";
|
|
11
11
|
readonly childNodes: readonly [SyntaxToken, AttributesToken, ...TdToken[]];
|
|
12
|
-
abstract get children(): [SyntaxToken, AttributesToken, ...TdToken[]];
|
|
13
12
|
abstract get lastChild(): AttributesToken | TdToken;
|
|
14
|
-
abstract get lastElementChild(): AttributesToken | TdToken;
|
|
15
13
|
abstract get parentNode(): TableToken | undefined;
|
|
16
|
-
abstract get parentElement(): TableToken | undefined;
|
|
17
14
|
abstract get nextSibling(): this | SyntaxToken | undefined;
|
|
18
|
-
abstract get nextElementSibling(): this | SyntaxToken | undefined;
|
|
19
15
|
abstract get previousSibling(): Token;
|
|
16
|
+
abstract get children(): [SyntaxToken, AttributesToken, ...TdToken[]];
|
|
17
|
+
abstract get lastElementChild(): AttributesToken | TdToken;
|
|
18
|
+
abstract get parentElement(): TableToken | undefined;
|
|
19
|
+
abstract get nextElementSibling(): this | SyntaxToken | undefined;
|
|
20
20
|
abstract get previousElementSibling(): Token;
|
|
21
21
|
/**
|
|
22
22
|
* @param syntax 表格语法
|
package/dist/src/table/tr.js
CHANGED
|
@@ -6,14 +6,18 @@ import type { LintError } from '../../base';
|
|
|
6
6
|
import type { AttributesParentBase } from '../../mixin/attributesParent';
|
|
7
7
|
export interface ExtToken extends AttributesParentBase {
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* 扩展标签
|
|
11
|
+
* @classdesc `{childNodes: [AttributesToken, Token]}`
|
|
12
|
+
*/
|
|
9
13
|
export declare abstract class ExtToken extends TagPairToken {
|
|
10
14
|
readonly type = "ext";
|
|
11
15
|
closed: true;
|
|
12
16
|
readonly childNodes: readonly [AttributesToken, Token];
|
|
13
|
-
abstract get children(): [AttributesToken, Token];
|
|
14
17
|
abstract get firstChild(): AttributesToken;
|
|
15
|
-
abstract get firstElementChild(): AttributesToken;
|
|
16
18
|
abstract get lastChild(): Token;
|
|
19
|
+
abstract get children(): [AttributesToken, Token];
|
|
20
|
+
abstract get firstElementChild(): AttributesToken;
|
|
17
21
|
/**
|
|
18
22
|
* @param name 标签名
|
|
19
23
|
* @param attr 标签属性
|
|
@@ -26,4 +30,3 @@ export declare abstract class ExtToken extends TagPairToken {
|
|
|
26
30
|
/** @override */
|
|
27
31
|
cloneNode(): this;
|
|
28
32
|
}
|
|
29
|
-
export {};
|