wikiparser-node 1.21.2 → 1.21.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/README.md +3 -5
- package/bundle/bundle-es8.min.js +25 -25
- package/bundle/bundle-lsp.min.js +26 -26
- package/bundle/bundle.min.js +25 -25
- package/dist/base.d.mts +6 -1
- package/dist/base.d.ts +6 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +10 -1
- package/dist/lib/element.js +2 -1
- package/dist/lib/lintConfig.d.ts +13 -0
- package/dist/lib/lintConfig.js +161 -0
- package/dist/lib/lsp.js +6 -4
- package/dist/lib/node.js +646 -606
- package/dist/lib/text.js +4 -0
- package/dist/mixin/attributesParent.d.ts +6 -6
- package/dist/mixin/attributesParent.js +4 -4
- package/dist/mixin/cached.d.ts +5 -0
- package/dist/mixin/cached.js +22 -0
- package/dist/mixin/clone.d.ts +5 -0
- package/dist/mixin/clone.js +23 -0
- package/dist/mixin/hidden.js +68 -18
- package/dist/mixin/sol.js +1 -1
- package/dist/parser/commentAndExt.js +1 -1
- package/dist/parser/html.js +3 -3
- package/dist/parser/table.js +2 -2
- package/dist/src/arg.js +13 -7
- package/dist/src/atom.js +76 -31
- package/dist/src/attribute.js +49 -21
- package/dist/src/attributes.d.ts +7 -7
- package/dist/src/attributes.js +415 -366
- package/dist/src/commented.js +81 -35
- package/dist/src/converter.js +13 -7
- package/dist/src/converterFlags.js +33 -22
- package/dist/src/converterRule.js +263 -216
- package/dist/src/extLink.js +21 -16
- package/dist/src/gallery.js +18 -8
- package/dist/src/heading.js +66 -57
- package/dist/src/hidden.js +14 -9
- package/dist/src/html.js +28 -9
- package/dist/src/imageParameter.js +13 -6
- package/dist/src/imagemap.js +32 -25
- package/dist/src/index.js +53 -44
- package/dist/src/link/base.js +13 -8
- package/dist/src/link/file.js +401 -354
- package/dist/src/link/galleryImage.js +9 -5
- package/dist/src/link/index.js +7 -3
- package/dist/src/link/redirectTarget.js +7 -3
- package/dist/src/magicLink.js +23 -14
- package/dist/src/nested.js +122 -74
- package/dist/src/nowiki/base.js +5 -2
- package/dist/src/nowiki/comment.js +5 -1
- package/dist/src/nowiki/index.js +3 -3
- package/dist/src/nowiki/quote.js +13 -8
- package/dist/src/onlyinclude.js +17 -9
- package/dist/src/paramTag/index.js +21 -14
- package/dist/src/parameter.js +26 -20
- package/dist/src/pre.js +91 -45
- package/dist/src/syntax.js +14 -10
- package/dist/src/table/index.js +550 -503
- package/dist/src/table/td.js +65 -58
- package/dist/src/table/trBase.js +179 -129
- package/dist/src/tagPair/ext.js +32 -20
- package/dist/src/tagPair/include.js +5 -5
- package/dist/src/tagPair/translate.js +150 -103
- package/dist/src/transclude.js +13 -8
- package/dist/util/html.js +46 -41
- package/dist/util/lint.js +4 -4
- package/dist/util/string.js +13 -7
- package/extensions/dist/base.js +2 -2
- package/package.json +15 -15
package/dist/src/table/index.js
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
3
|
+
var useValue = arguments.length > 2;
|
|
4
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
5
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
6
|
+
}
|
|
7
|
+
return useValue ? value : void 0;
|
|
8
|
+
};
|
|
9
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
+
var _, done = false;
|
|
15
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
+
var context = {};
|
|
17
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
+
if (kind === "accessor") {
|
|
22
|
+
if (result === void 0) continue;
|
|
23
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
27
|
+
}
|
|
28
|
+
else if (_ = accept(result)) {
|
|
29
|
+
if (kind === "field") initializers.unshift(_);
|
|
30
|
+
else descriptor[key] = _;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
+
done = true;
|
|
35
|
+
};
|
|
2
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
38
|
};
|
|
@@ -14,6 +48,7 @@ const syntax_1 = require("../syntax");
|
|
|
14
48
|
const html_1 = require("../../util/html");
|
|
15
49
|
const constants_1 = require("../../util/constants");
|
|
16
50
|
const string_1 = require("../../util/string");
|
|
51
|
+
const cached_1 = require("../../mixin/cached");
|
|
17
52
|
const closingPattern = /^\n[^\S\n]*(?:\|\}|\{\{\s*!\s*\}\}\}|\{\{\s*!\)\s*\}\})$/u;
|
|
18
53
|
/**
|
|
19
54
|
* 生成一个指定长度的空数组
|
|
@@ -62,533 +97,545 @@ exports.Layout = Layout;
|
|
|
62
97
|
* 表格
|
|
63
98
|
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken[], ...TrToken[], ?SyntaxToken]}`
|
|
64
99
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
set closed(closed) {
|
|
76
|
-
if (closed && !this.closed) {
|
|
77
|
-
this.close(this.closest('parameter-value') ? '\n{{!}}}' : '\n|}');
|
|
100
|
+
let TableToken = (() => {
|
|
101
|
+
let _classSuper = trBase_1.TrBaseToken;
|
|
102
|
+
let _instanceExtraInitializers = [];
|
|
103
|
+
let _toHtmlInternal_decorators;
|
|
104
|
+
return class TableToken extends _classSuper {
|
|
105
|
+
static {
|
|
106
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
107
|
+
_toHtmlInternal_decorators = [(0, cached_1.cached)()];
|
|
108
|
+
__esDecorate(this, null, _toHtmlInternal_decorators, { kind: "method", name: "toHtmlInternal", static: false, private: false, access: { has: obj => "toHtmlInternal" in obj, get: obj => obj.toHtmlInternal }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
109
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
78
110
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
lint(start = this.getAbsoluteIndex(), re) {
|
|
92
|
-
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
|
|
93
|
-
if (!this.closed) {
|
|
94
|
-
errors.push((0, lint_1.generateForChild)(this.firstChild, rect, 'unclosed-table', index_1.default.msg('unclosed $1', 'table')));
|
|
95
|
-
}
|
|
96
|
-
const layout = this.getLayout(), { length } = layout;
|
|
97
|
-
if (length > 1) {
|
|
98
|
-
let low = 1, high = Infinity, j = 0;
|
|
99
|
-
for (; j < length; j++) {
|
|
100
|
-
const row = layout[j], max = row.length;
|
|
101
|
-
if (max < low) {
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
else if (max < high) {
|
|
105
|
-
high = max;
|
|
106
|
-
}
|
|
107
|
-
const min = row.indexOf(row[max - 1]) + 1;
|
|
108
|
-
if (min > high) {
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
else if (min > low) {
|
|
112
|
-
low = min;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (j < length) {
|
|
116
|
-
const e = (0, lint_1.generateForChild)(this.getNthRow(j), rect, 'table-layout', 'inconsistent table layout', 'warning');
|
|
117
|
-
e.startIndex++;
|
|
118
|
-
e.startLine++;
|
|
119
|
-
e.startCol = 0;
|
|
120
|
-
errors.push(e);
|
|
111
|
+
/* NOT FOR BROWSER END */
|
|
112
|
+
get type() {
|
|
113
|
+
return 'table';
|
|
114
|
+
}
|
|
115
|
+
/** whether the table is closed / 表格是否闭合 */
|
|
116
|
+
get closed() {
|
|
117
|
+
return this.lastChild.is('table-syntax');
|
|
118
|
+
}
|
|
119
|
+
/* NOT FOR BROWSER */
|
|
120
|
+
set closed(closed) {
|
|
121
|
+
if (closed && !this.closed) {
|
|
122
|
+
this.close(this.closest('parameter-value') ? '\n{{!}}}' : '\n|}');
|
|
121
123
|
}
|
|
122
124
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
*/
|
|
132
|
-
close(syntax = '\n|}', halfParsed) {
|
|
133
|
-
const config = this.getAttribute('config'), accum = this.getAttribute('accum'),
|
|
134
|
-
/* eslint-disable unicorn/no-negated-condition, @stylistic/operator-linebreak */
|
|
135
|
-
inner = !halfParsed ?
|
|
136
|
-
index_1.default.parse(syntax, this.getAttribute('include'), 2, config).childNodes :
|
|
137
|
-
[syntax];
|
|
138
|
-
/* eslint-enable unicorn/no-negated-condition, @stylistic/operator-linebreak */
|
|
139
|
-
if (this.lastChild.type !== 'table-syntax') {
|
|
140
|
-
debug_1.Shadow.run(() => {
|
|
141
|
-
const token = new syntax_1.SyntaxToken(undefined, closingPattern, 'table-syntax', config, accum, { 'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':' });
|
|
142
|
-
super.insertAt(token);
|
|
143
|
-
if (!halfParsed) {
|
|
144
|
-
token.afterBuild();
|
|
145
|
-
}
|
|
125
|
+
/* NOT FOR BROWSER END */
|
|
126
|
+
/**
|
|
127
|
+
* @param syntax 表格语法
|
|
128
|
+
* @param attr 表格属性
|
|
129
|
+
*/
|
|
130
|
+
constructor(syntax, attr, config, accum) {
|
|
131
|
+
super(/^(?:\{\||\{\{\{\s*!\s*\}\}|\{\{\s*\(!\s*\}\})$/u, syntax, 'table', attr, config, accum, {
|
|
132
|
+
Token: 2, SyntaxToken: [0, -1], AttributesToken: 1, TdToken: '2:', TrToken: '2:',
|
|
146
133
|
});
|
|
134
|
+
__runInitializers(this, _instanceExtraInitializers);
|
|
147
135
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
* 获取表格布局
|
|
154
|
-
* @param stop stop condition / 中止条件
|
|
155
|
-
* @param stop.row stop at the row / 中止行
|
|
156
|
-
* @param stop.column stop at the column / 中止列
|
|
157
|
-
* @param stop.x stop at the row / 中止行
|
|
158
|
-
* @param stop.y stop at the column / 中止列
|
|
159
|
-
*/
|
|
160
|
-
getLayout(stop) {
|
|
161
|
-
const rows = this.getAllRows(), { length } = rows, layout = Layout.from(emptyArray(length, () => []));
|
|
162
|
-
for (let i = 0; i < layout.length; i++) {
|
|
163
|
-
const rowLayout = layout[i];
|
|
164
|
-
/* NOT FOR BROWSER */
|
|
165
|
-
if (i > (stop?.row ?? stop?.y ?? NaN)) {
|
|
166
|
-
break;
|
|
136
|
+
/** @private */
|
|
137
|
+
lint(start = this.getAbsoluteIndex(), re) {
|
|
138
|
+
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
|
|
139
|
+
if (!this.closed) {
|
|
140
|
+
errors.push((0, lint_1.generateForChild)(this.firstChild, rect, 'unclosed-table', index_1.default.msg('unclosed $1', 'table')));
|
|
167
141
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
142
|
+
const layout = this.getLayout(), { length } = layout;
|
|
143
|
+
if (length > 1) {
|
|
144
|
+
let low = 1, high = Infinity, j = 0;
|
|
145
|
+
for (; j < length; j++) {
|
|
146
|
+
const row = layout[j], max = row.length;
|
|
147
|
+
if (max < low) {
|
|
148
|
+
break;
|
|
174
149
|
}
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
150
|
+
else if (max < high) {
|
|
151
|
+
high = max;
|
|
152
|
+
}
|
|
153
|
+
const min = row.indexOf(row[max - 1]) + 1;
|
|
154
|
+
if (min > high) {
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
else if (min > low) {
|
|
158
|
+
low = min;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (j < length) {
|
|
162
|
+
const e = (0, lint_1.generateForChild)(this.getNthRow(j), rect, 'table-layout', 'inconsistent table layout', 'warning');
|
|
163
|
+
e.startIndex++;
|
|
164
|
+
e.startLine++;
|
|
165
|
+
e.startCol = 0;
|
|
166
|
+
errors.push(e);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return errors;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Close the table syntax
|
|
173
|
+
*
|
|
174
|
+
* 闭合表格语法
|
|
175
|
+
* @param syntax syntax of the table end / 表格结尾语法
|
|
176
|
+
* @param halfParsed
|
|
177
|
+
*/
|
|
178
|
+
close(syntax = '\n|}', halfParsed) {
|
|
179
|
+
const config = this.getAttribute('config'), accum = this.getAttribute('accum'),
|
|
180
|
+
/* eslint-disable unicorn/no-negated-condition, @stylistic/operator-linebreak */
|
|
181
|
+
inner = !halfParsed ?
|
|
182
|
+
index_1.default.parse(syntax, this.getAttribute('include'), 2, config).childNodes :
|
|
183
|
+
[syntax];
|
|
184
|
+
/* eslint-enable unicorn/no-negated-condition, @stylistic/operator-linebreak */
|
|
185
|
+
if (!this.lastChild.is('table-syntax')) {
|
|
186
|
+
debug_1.Shadow.run(() => {
|
|
187
|
+
const token = new syntax_1.SyntaxToken(undefined, closingPattern, 'table-syntax', config, accum, { 'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':' });
|
|
188
|
+
super.insertAt(token);
|
|
189
|
+
if (!halfParsed) {
|
|
190
|
+
token.afterBuild();
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
this.lastChild.safeReplaceChildren(inner);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get the table layout
|
|
198
|
+
*
|
|
199
|
+
* 获取表格布局
|
|
200
|
+
* @param stop stop condition / 中止条件
|
|
201
|
+
* @param stop.row stop at the row / 中止行
|
|
202
|
+
* @param stop.column stop at the column / 中止列
|
|
203
|
+
* @param stop.x stop at the row / 中止行
|
|
204
|
+
* @param stop.y stop at the column / 中止列
|
|
205
|
+
*/
|
|
206
|
+
getLayout(stop) {
|
|
207
|
+
const rows = this.getAllRows(), { length } = rows, layout = Layout.from(emptyArray(length, () => []));
|
|
208
|
+
for (let i = 0; i < layout.length; i++) {
|
|
209
|
+
const rowLayout = layout[i];
|
|
210
|
+
/* NOT FOR BROWSER */
|
|
211
|
+
if (i > (stop?.row ?? stop?.y ?? NaN)) {
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
/* NOT FOR BROWSER END */
|
|
215
|
+
let j = 0, k = 0, last;
|
|
216
|
+
for (const cell of rows[i].childNodes.slice(2)) {
|
|
217
|
+
if (cell.is('td')) {
|
|
218
|
+
if (cell.isIndependent()) {
|
|
219
|
+
last = cell.subtype !== 'caption';
|
|
185
220
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
221
|
+
if (last) {
|
|
222
|
+
const coords = { row: i, column: j }, { rowspan, colspan } = cell;
|
|
223
|
+
j++;
|
|
224
|
+
while (rowLayout[k]) {
|
|
225
|
+
k++;
|
|
226
|
+
}
|
|
227
|
+
/* NOT FOR BROWSER */
|
|
228
|
+
if (i === stop?.row && j > stop.column) {
|
|
229
|
+
rowLayout[k] = coords;
|
|
230
|
+
return layout;
|
|
231
|
+
}
|
|
232
|
+
/* NOT FOR BROWSER END */
|
|
233
|
+
for (let y = i; y < Math.min(i + rowspan, length); y++) {
|
|
234
|
+
for (let x = k; x < k + colspan; x++) {
|
|
235
|
+
layout[y][x] = coords;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
k += colspan;
|
|
239
|
+
/* NOT FOR BROWSER */
|
|
240
|
+
if (i === stop?.y && k > (stop.x ?? NaN)) {
|
|
241
|
+
return layout;
|
|
190
242
|
}
|
|
191
|
-
}
|
|
192
|
-
k += colspan;
|
|
193
|
-
/* NOT FOR BROWSER */
|
|
194
|
-
if (i === stop?.y && k > (stop.x ?? NaN)) {
|
|
195
|
-
return layout;
|
|
196
243
|
}
|
|
197
244
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
245
|
+
else if ((0, exports.isRowEnd)(cell)) {
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
201
248
|
}
|
|
202
249
|
}
|
|
250
|
+
return layout;
|
|
203
251
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
.filter((child) => child.is('tr') && child.getRowCount() > 0),
|
|
216
|
-
];
|
|
217
|
-
}
|
|
218
|
-
getNthRow(n, force, insert) {
|
|
219
|
-
const isRow = super.getRowCount();
|
|
220
|
-
/* NOT FOR BROWSER */
|
|
221
|
-
const nRows = this.getRowCount();
|
|
222
|
-
n += n < 0 ? nRows : 0;
|
|
223
|
-
/* NOT FOR BROWSER END */
|
|
224
|
-
if (n === 0
|
|
225
|
-
&& (isRow
|
|
226
|
-
|| force && nRows === 0)) {
|
|
227
|
-
return this;
|
|
228
|
-
/* NOT FOR BROWSER */
|
|
252
|
+
/**
|
|
253
|
+
* Get all rows
|
|
254
|
+
*
|
|
255
|
+
* 获取所有行
|
|
256
|
+
*/
|
|
257
|
+
getAllRows() {
|
|
258
|
+
return [
|
|
259
|
+
...super.getRowCount() ? [this] : [],
|
|
260
|
+
...this.childNodes.slice(1)
|
|
261
|
+
.filter((child) => child.is('tr') && child.getRowCount() > 0),
|
|
262
|
+
];
|
|
229
263
|
}
|
|
230
|
-
|
|
231
|
-
|
|
264
|
+
getNthRow(n, force, insert) {
|
|
265
|
+
const isRow = super.getRowCount();
|
|
266
|
+
/* NOT FOR BROWSER */
|
|
267
|
+
const nRows = this.getRowCount();
|
|
268
|
+
n += n < 0 ? nRows : 0;
|
|
232
269
|
/* NOT FOR BROWSER END */
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if (
|
|
270
|
+
if (n === 0
|
|
271
|
+
&& (isRow
|
|
272
|
+
|| force && nRows === 0)) {
|
|
273
|
+
return this;
|
|
274
|
+
/* NOT FOR BROWSER */
|
|
275
|
+
}
|
|
276
|
+
else /* istanbul ignore if */ if (n < 0 || n > nRows || n === nRows && !insert) {
|
|
277
|
+
throw new RangeError(`The table does not have row ${n}!`);
|
|
278
|
+
/* NOT FOR BROWSER END */
|
|
279
|
+
}
|
|
280
|
+
else if (isRow) {
|
|
240
281
|
n--;
|
|
241
|
-
|
|
282
|
+
}
|
|
283
|
+
for (const child of this.childNodes.slice(2)) {
|
|
284
|
+
const { type } = child;
|
|
285
|
+
if (type === 'tr' && child.getRowCount()) {
|
|
286
|
+
n--;
|
|
287
|
+
if (n < 0) {
|
|
288
|
+
return child;
|
|
289
|
+
}
|
|
290
|
+
/* NOT FOR BROWSER */
|
|
291
|
+
}
|
|
292
|
+
else if (type === 'table-syntax') {
|
|
242
293
|
return child;
|
|
294
|
+
/* NOT FOR BROWSER END */
|
|
243
295
|
}
|
|
244
|
-
/* NOT FOR BROWSER */
|
|
245
296
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
297
|
+
return undefined;
|
|
298
|
+
}
|
|
299
|
+
/** @private */
|
|
300
|
+
json(_, start = this.getAbsoluteIndex()) {
|
|
301
|
+
const json = super.json(undefined, start);
|
|
302
|
+
json['closed'] = this.closed;
|
|
303
|
+
return json;
|
|
304
|
+
}
|
|
305
|
+
/* NOT FOR BROWSER */
|
|
306
|
+
/**
|
|
307
|
+
* @override
|
|
308
|
+
* @param token node to be inserted / 待插入的子节点
|
|
309
|
+
* @param i position to be inserted at / 插入位置
|
|
310
|
+
* @throws `SyntaxError` 表格的闭合部分非法
|
|
311
|
+
*/
|
|
312
|
+
insertAt(token, i = this.length) {
|
|
313
|
+
i += i < 0 ? this.length : 0;
|
|
314
|
+
const previous = this.childNodes[i - 1];
|
|
315
|
+
/* istanbul ignore else */
|
|
316
|
+
if (typeof token !== 'string' && token.is('td') && previous?.is('tr')) {
|
|
317
|
+
index_1.default.warn('The table cell is inserted into the current row instead.');
|
|
318
|
+
return previous.insertAt(token);
|
|
319
|
+
}
|
|
320
|
+
else if (i > 0 && token instanceof syntax_1.SyntaxToken && token.pattern !== closingPattern) {
|
|
321
|
+
throw new SyntaxError(`The closing part of the table is invalid: ${(0, string_1.noWrap)(token.toString())}`);
|
|
249
322
|
}
|
|
323
|
+
return super.insertAt(token, i);
|
|
250
324
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
json(_, start = this.getAbsoluteIndex()) {
|
|
255
|
-
const json = super.json(undefined, start);
|
|
256
|
-
json['closed'] = this.closed;
|
|
257
|
-
return json;
|
|
258
|
-
}
|
|
259
|
-
/* NOT FOR BROWSER */
|
|
260
|
-
/**
|
|
261
|
-
* @override
|
|
262
|
-
* @param token node to be inserted / 待插入的子节点
|
|
263
|
-
* @param i position to be inserted at / 插入位置
|
|
264
|
-
* @throws `SyntaxError` 表格的闭合部分非法
|
|
265
|
-
*/
|
|
266
|
-
insertAt(token, i = this.length) {
|
|
267
|
-
i += i < 0 ? this.length : 0;
|
|
268
|
-
const previous = this.childNodes[i - 1];
|
|
269
|
-
/* istanbul ignore else */
|
|
270
|
-
if (typeof token !== 'string' && token.is('td') && previous?.is('tr')) {
|
|
271
|
-
index_1.default.warn('The table cell is inserted into the current row instead.');
|
|
272
|
-
return previous.insertAt(token);
|
|
273
|
-
}
|
|
274
|
-
else if (i > 0 && token instanceof syntax_1.SyntaxToken && token.pattern !== closingPattern) {
|
|
275
|
-
throw new SyntaxError(`The closing part of the table is invalid: ${(0, string_1.noWrap)(token.toString())}`);
|
|
276
|
-
}
|
|
277
|
-
return super.insertAt(token, i);
|
|
278
|
-
}
|
|
279
|
-
getRowCount() {
|
|
280
|
-
return super.getRowCount()
|
|
281
|
-
+ this.childNodes.filter(child => child.is('tr') && child.getRowCount()).length;
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Get the next row
|
|
285
|
-
*
|
|
286
|
-
* 获取下一行
|
|
287
|
-
*/
|
|
288
|
-
getNextRow() {
|
|
289
|
-
return this.getNthRow(super.getRowCount() ? 1 : 0, false, false);
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Get the cell with the specified coordinates
|
|
293
|
-
*
|
|
294
|
-
* 获取指定坐标的单元格
|
|
295
|
-
* @param coords table coordinates / 表格坐标
|
|
296
|
-
*/
|
|
297
|
-
getNthCell(coords) {
|
|
298
|
-
let rawCoords = coords;
|
|
299
|
-
if (coords.row === undefined) {
|
|
300
|
-
rawCoords = this.toRawCoords(coords);
|
|
325
|
+
getRowCount() {
|
|
326
|
+
return super.getRowCount()
|
|
327
|
+
+ this.childNodes.filter(child => child.is('tr') && child.getRowCount()).length;
|
|
301
328
|
}
|
|
302
|
-
return rawCoords && this.getNthRow(rawCoords.row, false, false)?.getNthCol(rawCoords.column);
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Print the table layout
|
|
306
|
-
*
|
|
307
|
-
* 打印表格布局
|
|
308
|
-
*/
|
|
309
|
-
printLayout() {
|
|
310
|
-
require('../../addon/table');
|
|
311
|
-
this.printLayout();
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Convert to table coordinates after rendering
|
|
315
|
-
*
|
|
316
|
-
* 转换为渲染后的表格坐标
|
|
317
|
-
* @param {TableCoords} coord table coordinates in wikitext / wikitext中的表格坐标
|
|
318
|
-
*/
|
|
319
|
-
toRenderedCoords(coord) {
|
|
320
|
-
require('../../addon/table');
|
|
321
|
-
return this.toRenderedCoords(coord);
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Convert to table coordinates in wikitext
|
|
325
|
-
*
|
|
326
|
-
* 转换为wikitext中的表格坐标
|
|
327
|
-
* @param {TableRenderedCoords} coord table coordinates after rendering / 渲染后的表格坐标
|
|
328
|
-
*/
|
|
329
|
-
toRawCoords(coord) {
|
|
330
|
-
require('../../addon/table');
|
|
331
|
-
return this.toRawCoords(coord);
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Get the full row
|
|
335
|
-
*
|
|
336
|
-
* 获取完整行
|
|
337
|
-
* @param y row number / 行号
|
|
338
|
-
*/
|
|
339
|
-
getFullRow(y) {
|
|
340
|
-
require('../../addon/table');
|
|
341
|
-
return this.getFullRow(y);
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Get the full column
|
|
345
|
-
*
|
|
346
|
-
* 获取完整列
|
|
347
|
-
* @param x column number / 列号
|
|
348
|
-
*/
|
|
349
|
-
getFullCol(x) {
|
|
350
|
-
require('../../addon/table');
|
|
351
|
-
return this.getFullCol(x);
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* Format the row
|
|
355
|
-
*
|
|
356
|
-
* 设置行格式
|
|
357
|
-
* @param y row number / 行号
|
|
358
|
-
* @param attr table attribute / 表格属性
|
|
359
|
-
* @param multiRow whether to format multi-row cells / 是否对所有单元格设置,或是仅对行首单元格设置
|
|
360
|
-
*/
|
|
361
|
-
formatTableRow(y, attr, multiRow) {
|
|
362
|
-
require('../../addon/table');
|
|
363
|
-
this.formatTableRow(y, attr, multiRow);
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
* Format the column
|
|
367
|
-
*
|
|
368
|
-
* 设置列格式
|
|
369
|
-
* @param x column number / 列号
|
|
370
|
-
* @param attr table attribute / 表格属性
|
|
371
|
-
* @param multiCol whether to format multi-column cells / 是否对所有单元格设置,或是仅对行首单元格设置
|
|
372
|
-
*/
|
|
373
|
-
formatTableCol(x, attr, multiCol) {
|
|
374
|
-
require('../../addon/table');
|
|
375
|
-
this.formatTableCol(x, attr, multiCol);
|
|
376
|
-
}
|
|
377
|
-
/**
|
|
378
|
-
* Fill the table row
|
|
379
|
-
*
|
|
380
|
-
* 填补表格行
|
|
381
|
-
* @param y row number / 行号
|
|
382
|
-
* @param inner content to fill / 填充内容
|
|
383
|
-
* @param subtype type of the cell / 单元格类型
|
|
384
|
-
* @param attr table attribute / 表格属性
|
|
385
|
-
*/
|
|
386
|
-
fillTableRow(y, inner, subtype, attr) {
|
|
387
|
-
require('../../addon/table');
|
|
388
|
-
this.fillTableRow(y, inner, subtype, attr);
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* Fill the table
|
|
392
|
-
*
|
|
393
|
-
* 填补表格
|
|
394
|
-
* @param inner content to fill / 填充内容
|
|
395
|
-
* @param subtype type of the cell / 单元格类型
|
|
396
|
-
* @param attr table attribute / 表格属性
|
|
397
|
-
*/
|
|
398
|
-
fillTable(inner, subtype, attr) {
|
|
399
|
-
require('../../addon/table');
|
|
400
|
-
this.fillTable(inner, subtype, attr);
|
|
401
|
-
}
|
|
402
|
-
insertTableCell(inner, coords, subtype, attr) {
|
|
403
|
-
require('../../addon/table');
|
|
404
|
-
return this.insertTableCell(inner, coords, subtype, attr);
|
|
405
|
-
}
|
|
406
|
-
/** @private */
|
|
407
|
-
prependTableRow() {
|
|
408
|
-
require('../../addon/table');
|
|
409
|
-
return this.prependTableRow();
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Insert a table row
|
|
413
|
-
*
|
|
414
|
-
* 插入表格行
|
|
415
|
-
* @param y row number / 行号
|
|
416
|
-
* @param attr table row attribute / 表格行属性
|
|
417
|
-
* @param inner inner wikitext / 内部wikitext
|
|
418
|
-
* @param subtype type of the cell / 单元格类型
|
|
419
|
-
* @param innerAttr cell attribute / 单元格属性
|
|
420
|
-
*/
|
|
421
|
-
insertTableRow(y, attr, inner, subtype, innerAttr) {
|
|
422
|
-
require('../../addon/table');
|
|
423
|
-
return this.insertTableRow(y, attr, inner, subtype, innerAttr);
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* Insert a table column
|
|
427
|
-
*
|
|
428
|
-
* 插入表格列
|
|
429
|
-
* @param x column number / 列号
|
|
430
|
-
* @param inner inner wikitext / 内部wikitext
|
|
431
|
-
* @param subtype type of the cell / 单元格类型
|
|
432
|
-
* @param attr cell attribute / 单元格属性
|
|
433
|
-
* @throws `RangeError` 列号过大
|
|
434
|
-
*/
|
|
435
|
-
insertTableCol(x, inner, subtype, attr) {
|
|
436
|
-
require('../../addon/table');
|
|
437
|
-
this.insertTableCol(x, inner, subtype, attr);
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Remove a table row
|
|
441
|
-
*
|
|
442
|
-
* 移除表格行
|
|
443
|
-
* @param y row number / 行号
|
|
444
|
-
*/
|
|
445
|
-
removeTableRow(y) {
|
|
446
|
-
require('../../addon/table');
|
|
447
|
-
return this.removeTableRow(y);
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Remove a table column
|
|
451
|
-
*
|
|
452
|
-
* 移除表格列
|
|
453
|
-
* @param x column number / 列号
|
|
454
|
-
*/
|
|
455
|
-
removeTableCol(x) {
|
|
456
|
-
require('../../addon/table');
|
|
457
|
-
this.removeTableCol(x);
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* Marge cells
|
|
461
|
-
*
|
|
462
|
-
* 合并单元格
|
|
463
|
-
* @param xlim column range / 列范围
|
|
464
|
-
* @param ylim row range / 行范围
|
|
465
|
-
* @throws `RangeError` 待合并区域与外侧区域有重叠
|
|
466
|
-
*/
|
|
467
|
-
mergeCells(xlim, ylim) {
|
|
468
|
-
require('../../addon/table');
|
|
469
|
-
return this.mergeCells(xlim, ylim);
|
|
470
|
-
}
|
|
471
|
-
/** @private */
|
|
472
|
-
split(coords, dirs) {
|
|
473
|
-
require('../../addon/table');
|
|
474
|
-
this.split(coords, dirs);
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Split a cell into rows
|
|
478
|
-
*
|
|
479
|
-
* 分裂成多行
|
|
480
|
-
* @param coords coordinates of the cell / 单元格坐标
|
|
481
|
-
*/
|
|
482
|
-
splitIntoRows(coords) {
|
|
483
|
-
require('../../addon/table');
|
|
484
|
-
this.splitIntoRows(coords);
|
|
485
|
-
}
|
|
486
|
-
/**
|
|
487
|
-
* Split a cell into columns
|
|
488
|
-
*
|
|
489
|
-
* 分裂成多列
|
|
490
|
-
* @param coords coordinates of the cell / 单元格坐标
|
|
491
|
-
*/
|
|
492
|
-
splitIntoCols(coords) {
|
|
493
|
-
require('../../addon/table');
|
|
494
|
-
this.splitIntoCols(coords);
|
|
495
|
-
}
|
|
496
|
-
/**
|
|
497
|
-
* Split a cell into cells
|
|
498
|
-
*
|
|
499
|
-
* 分裂成单元格
|
|
500
|
-
* @param coords coordinates of the cell / 单元格坐标
|
|
501
|
-
*/
|
|
502
|
-
splitIntoCells(coords) {
|
|
503
|
-
require('../../addon/table');
|
|
504
|
-
this.splitIntoCells(coords);
|
|
505
|
-
}
|
|
506
|
-
/**
|
|
507
|
-
* Replicate a row and insert the result before the row
|
|
508
|
-
*
|
|
509
|
-
* 复制一行并插入该行之前
|
|
510
|
-
* @param row row number / 行号
|
|
511
|
-
*/
|
|
512
|
-
replicateTableRow(row) {
|
|
513
|
-
require('../../addon/table');
|
|
514
|
-
return this.replicateTableRow(row);
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Replicate a column and insert the result before the column
|
|
518
|
-
*
|
|
519
|
-
* 复制一列并插入该列之前
|
|
520
|
-
* @param x column number / 列号
|
|
521
|
-
*/
|
|
522
|
-
replicateTableCol(x) {
|
|
523
|
-
require('../../addon/table');
|
|
524
|
-
return this.replicateTableCol(x);
|
|
525
|
-
}
|
|
526
|
-
/** @private */
|
|
527
|
-
moveCol(x, reference, after) {
|
|
528
|
-
require('../../addon/table');
|
|
529
|
-
this.moveCol(x, reference, after);
|
|
530
|
-
}
|
|
531
|
-
/**
|
|
532
|
-
* Move a table row
|
|
533
|
-
*
|
|
534
|
-
* 移动表格行
|
|
535
|
-
* @param y row number / 行号
|
|
536
|
-
* @param before new position / 新位置
|
|
537
|
-
* @throws `RangeError` 无法移动
|
|
538
|
-
*/
|
|
539
|
-
moveTableRowBefore(y, before) {
|
|
540
|
-
require('../../addon/table');
|
|
541
|
-
return this.moveTableRowBefore(y, before);
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* Move a table row
|
|
545
|
-
*
|
|
546
|
-
* 移动表格行
|
|
547
|
-
* @param y row number / 行号
|
|
548
|
-
* @param after new position / 新位置
|
|
549
|
-
* @throws `RangeError` 无法移动
|
|
550
|
-
*/
|
|
551
|
-
moveTableRowAfter(y, after) {
|
|
552
|
-
require('../../addon/table');
|
|
553
|
-
return this.moveTableRowAfter(y, after);
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* Move a table column
|
|
557
|
-
*
|
|
558
|
-
* 移动表格列
|
|
559
|
-
* @param x column number / 列号
|
|
560
|
-
* @param before new position / 新位置
|
|
561
|
-
*/
|
|
562
|
-
moveTableColBefore(x, before) {
|
|
563
|
-
require('../../addon/table');
|
|
564
|
-
this.moveTableColBefore(x, before);
|
|
565
|
-
}
|
|
566
|
-
/**
|
|
567
|
-
* Move a table column
|
|
568
|
-
*
|
|
569
|
-
* 移动表格列
|
|
570
|
-
* @param x column number / 列号
|
|
571
|
-
* @param after new position / 新位置
|
|
572
|
-
*/
|
|
573
|
-
moveTableColAfter(x, after) {
|
|
574
|
-
require('../../addon/table');
|
|
575
|
-
this.moveTableColAfter(x, after);
|
|
576
|
-
}
|
|
577
|
-
/** @private */
|
|
578
|
-
toHtmlInternal(opt) {
|
|
579
329
|
/**
|
|
580
|
-
*
|
|
581
|
-
*
|
|
330
|
+
* Get the next row
|
|
331
|
+
*
|
|
332
|
+
* 获取下一行
|
|
582
333
|
*/
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
334
|
+
getNextRow() {
|
|
335
|
+
return this.getNthRow(super.getRowCount() ? 1 : 0, false, false);
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Get the cell with the specified coordinates
|
|
339
|
+
*
|
|
340
|
+
* 获取指定坐标的单元格
|
|
341
|
+
* @param coords table coordinates / 表格坐标
|
|
342
|
+
*/
|
|
343
|
+
getNthCell(coords) {
|
|
344
|
+
let rawCoords = coords;
|
|
345
|
+
if (coords.row === undefined) {
|
|
346
|
+
rawCoords = this.toRawCoords(coords);
|
|
347
|
+
}
|
|
348
|
+
return rawCoords && this.getNthRow(rawCoords.row, false, false)?.getNthCol(rawCoords.column);
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Print the table layout
|
|
352
|
+
*
|
|
353
|
+
* 打印表格布局
|
|
354
|
+
*/
|
|
355
|
+
printLayout() {
|
|
356
|
+
require('../../addon/table');
|
|
357
|
+
this.printLayout();
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Convert to table coordinates after rendering
|
|
361
|
+
*
|
|
362
|
+
* 转换为渲染后的表格坐标
|
|
363
|
+
* @param {TableCoords} coord table coordinates in wikitext / wikitext中的表格坐标
|
|
364
|
+
*/
|
|
365
|
+
toRenderedCoords(coord) {
|
|
366
|
+
require('../../addon/table');
|
|
367
|
+
return this.toRenderedCoords(coord);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Convert to table coordinates in wikitext
|
|
371
|
+
*
|
|
372
|
+
* 转换为wikitext中的表格坐标
|
|
373
|
+
* @param {TableRenderedCoords} coord table coordinates after rendering / 渲染后的表格坐标
|
|
374
|
+
*/
|
|
375
|
+
toRawCoords(coord) {
|
|
376
|
+
require('../../addon/table');
|
|
377
|
+
return this.toRawCoords(coord);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Get the full row
|
|
381
|
+
*
|
|
382
|
+
* 获取完整行
|
|
383
|
+
* @param y row number / 行号
|
|
384
|
+
*/
|
|
385
|
+
getFullRow(y) {
|
|
386
|
+
require('../../addon/table');
|
|
387
|
+
return this.getFullRow(y);
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Get the full column
|
|
391
|
+
*
|
|
392
|
+
* 获取完整列
|
|
393
|
+
* @param x column number / 列号
|
|
394
|
+
*/
|
|
395
|
+
getFullCol(x) {
|
|
396
|
+
require('../../addon/table');
|
|
397
|
+
return this.getFullCol(x);
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Format the row
|
|
401
|
+
*
|
|
402
|
+
* 设置行格式
|
|
403
|
+
* @param y row number / 行号
|
|
404
|
+
* @param attr table attribute / 表格属性
|
|
405
|
+
* @param multiRow whether to format multi-row cells / 是否对所有单元格设置,或是仅对行首单元格设置
|
|
406
|
+
*/
|
|
407
|
+
formatTableRow(y, attr, multiRow) {
|
|
408
|
+
require('../../addon/table');
|
|
409
|
+
this.formatTableRow(y, attr, multiRow);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Format the column
|
|
413
|
+
*
|
|
414
|
+
* 设置列格式
|
|
415
|
+
* @param x column number / 列号
|
|
416
|
+
* @param attr table attribute / 表格属性
|
|
417
|
+
* @param multiCol whether to format multi-column cells / 是否对所有单元格设置,或是仅对行首单元格设置
|
|
418
|
+
*/
|
|
419
|
+
formatTableCol(x, attr, multiCol) {
|
|
420
|
+
require('../../addon/table');
|
|
421
|
+
this.formatTableCol(x, attr, multiCol);
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Fill the table row
|
|
425
|
+
*
|
|
426
|
+
* 填补表格行
|
|
427
|
+
* @param y row number / 行号
|
|
428
|
+
* @param inner content to fill / 填充内容
|
|
429
|
+
* @param subtype type of the cell / 单元格类型
|
|
430
|
+
* @param attr table attribute / 表格属性
|
|
431
|
+
*/
|
|
432
|
+
fillTableRow(y, inner, subtype, attr) {
|
|
433
|
+
require('../../addon/table');
|
|
434
|
+
this.fillTableRow(y, inner, subtype, attr);
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Fill the table
|
|
438
|
+
*
|
|
439
|
+
* 填补表格
|
|
440
|
+
* @param inner content to fill / 填充内容
|
|
441
|
+
* @param subtype type of the cell / 单元格类型
|
|
442
|
+
* @param attr table attribute / 表格属性
|
|
443
|
+
*/
|
|
444
|
+
fillTable(inner, subtype, attr) {
|
|
445
|
+
require('../../addon/table');
|
|
446
|
+
this.fillTable(inner, subtype, attr);
|
|
447
|
+
}
|
|
448
|
+
insertTableCell(inner, coords, subtype, attr) {
|
|
449
|
+
require('../../addon/table');
|
|
450
|
+
return this.insertTableCell(inner, coords, subtype, attr);
|
|
451
|
+
}
|
|
452
|
+
/** @private */
|
|
453
|
+
prependTableRow() {
|
|
454
|
+
require('../../addon/table');
|
|
455
|
+
return this.prependTableRow();
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Insert a table row
|
|
459
|
+
*
|
|
460
|
+
* 插入表格行
|
|
461
|
+
* @param y row number / 行号
|
|
462
|
+
* @param attr table row attribute / 表格行属性
|
|
463
|
+
* @param inner inner wikitext / 内部wikitext
|
|
464
|
+
* @param subtype type of the cell / 单元格类型
|
|
465
|
+
* @param innerAttr cell attribute / 单元格属性
|
|
466
|
+
*/
|
|
467
|
+
insertTableRow(y, attr, inner, subtype, innerAttr) {
|
|
468
|
+
require('../../addon/table');
|
|
469
|
+
return this.insertTableRow(y, attr, inner, subtype, innerAttr);
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Insert a table column
|
|
473
|
+
*
|
|
474
|
+
* 插入表格列
|
|
475
|
+
* @param x column number / 列号
|
|
476
|
+
* @param inner inner wikitext / 内部wikitext
|
|
477
|
+
* @param subtype type of the cell / 单元格类型
|
|
478
|
+
* @param attr cell attribute / 单元格属性
|
|
479
|
+
* @throws `RangeError` 列号过大
|
|
480
|
+
*/
|
|
481
|
+
insertTableCol(x, inner, subtype, attr) {
|
|
482
|
+
require('../../addon/table');
|
|
483
|
+
this.insertTableCol(x, inner, subtype, attr);
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Remove a table row
|
|
487
|
+
*
|
|
488
|
+
* 移除表格行
|
|
489
|
+
* @param y row number / 行号
|
|
490
|
+
*/
|
|
491
|
+
removeTableRow(y) {
|
|
492
|
+
require('../../addon/table');
|
|
493
|
+
return this.removeTableRow(y);
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Remove a table column
|
|
497
|
+
*
|
|
498
|
+
* 移除表格列
|
|
499
|
+
* @param x column number / 列号
|
|
500
|
+
*/
|
|
501
|
+
removeTableCol(x) {
|
|
502
|
+
require('../../addon/table');
|
|
503
|
+
this.removeTableCol(x);
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Marge cells
|
|
507
|
+
*
|
|
508
|
+
* 合并单元格
|
|
509
|
+
* @param xlim column range / 列范围
|
|
510
|
+
* @param ylim row range / 行范围
|
|
511
|
+
* @throws `RangeError` 待合并区域与外侧区域有重叠
|
|
512
|
+
*/
|
|
513
|
+
mergeCells(xlim, ylim) {
|
|
514
|
+
require('../../addon/table');
|
|
515
|
+
return this.mergeCells(xlim, ylim);
|
|
516
|
+
}
|
|
517
|
+
/** @private */
|
|
518
|
+
split(coords, dirs) {
|
|
519
|
+
require('../../addon/table');
|
|
520
|
+
this.split(coords, dirs);
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Split a cell into rows
|
|
524
|
+
*
|
|
525
|
+
* 分裂成多行
|
|
526
|
+
* @param coords coordinates of the cell / 单元格坐标
|
|
527
|
+
*/
|
|
528
|
+
splitIntoRows(coords) {
|
|
529
|
+
require('../../addon/table');
|
|
530
|
+
this.splitIntoRows(coords);
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Split a cell into columns
|
|
534
|
+
*
|
|
535
|
+
* 分裂成多列
|
|
536
|
+
* @param coords coordinates of the cell / 单元格坐标
|
|
537
|
+
*/
|
|
538
|
+
splitIntoCols(coords) {
|
|
539
|
+
require('../../addon/table');
|
|
540
|
+
this.splitIntoCols(coords);
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Split a cell into cells
|
|
544
|
+
*
|
|
545
|
+
* 分裂成单元格
|
|
546
|
+
* @param coords coordinates of the cell / 单元格坐标
|
|
547
|
+
*/
|
|
548
|
+
splitIntoCells(coords) {
|
|
549
|
+
require('../../addon/table');
|
|
550
|
+
this.splitIntoCells(coords);
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Replicate a row and insert the result before the row
|
|
554
|
+
*
|
|
555
|
+
* 复制一行并插入该行之前
|
|
556
|
+
* @param row row number / 行号
|
|
557
|
+
*/
|
|
558
|
+
replicateTableRow(row) {
|
|
559
|
+
require('../../addon/table');
|
|
560
|
+
return this.replicateTableRow(row);
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Replicate a column and insert the result before the column
|
|
564
|
+
*
|
|
565
|
+
* 复制一列并插入该列之前
|
|
566
|
+
* @param x column number / 列号
|
|
567
|
+
*/
|
|
568
|
+
replicateTableCol(x) {
|
|
569
|
+
require('../../addon/table');
|
|
570
|
+
return this.replicateTableCol(x);
|
|
571
|
+
}
|
|
572
|
+
/** @private */
|
|
573
|
+
moveCol(x, reference, after) {
|
|
574
|
+
require('../../addon/table');
|
|
575
|
+
this.moveCol(x, reference, after);
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Move a table row
|
|
579
|
+
*
|
|
580
|
+
* 移动表格行
|
|
581
|
+
* @param y row number / 行号
|
|
582
|
+
* @param before new position / 新位置
|
|
583
|
+
* @throws `RangeError` 无法移动
|
|
584
|
+
*/
|
|
585
|
+
moveTableRowBefore(y, before) {
|
|
586
|
+
require('../../addon/table');
|
|
587
|
+
return this.moveTableRowBefore(y, before);
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Move a table row
|
|
591
|
+
*
|
|
592
|
+
* 移动表格行
|
|
593
|
+
* @param y row number / 行号
|
|
594
|
+
* @param after new position / 新位置
|
|
595
|
+
* @throws `RangeError` 无法移动
|
|
596
|
+
*/
|
|
597
|
+
moveTableRowAfter(y, after) {
|
|
598
|
+
require('../../addon/table');
|
|
599
|
+
return this.moveTableRowAfter(y, after);
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Move a table column
|
|
603
|
+
*
|
|
604
|
+
* 移动表格列
|
|
605
|
+
* @param x column number / 列号
|
|
606
|
+
* @param before new position / 新位置
|
|
607
|
+
*/
|
|
608
|
+
moveTableColBefore(x, before) {
|
|
609
|
+
require('../../addon/table');
|
|
610
|
+
this.moveTableColBefore(x, before);
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Move a table column
|
|
614
|
+
*
|
|
615
|
+
* 移动表格列
|
|
616
|
+
* @param x column number / 列号
|
|
617
|
+
* @param after new position / 新位置
|
|
618
|
+
*/
|
|
619
|
+
moveTableColAfter(x, after) {
|
|
620
|
+
require('../../addon/table');
|
|
621
|
+
this.moveTableColAfter(x, after);
|
|
622
|
+
}
|
|
623
|
+
/** @private */
|
|
624
|
+
toHtmlInternal(opt) {
|
|
625
|
+
/**
|
|
626
|
+
* 过滤需要移出表格的节点
|
|
627
|
+
* @param token 表格或表格行
|
|
628
|
+
*/
|
|
629
|
+
const filter = (token) => token.childNodes.filter((0, debug_1.isToken)('table-inter'));
|
|
630
|
+
const { childNodes } = this, tr = childNodes.filter((0, debug_1.isToken)('tr')), newOpt = {
|
|
631
|
+
...opt,
|
|
632
|
+
nowrap: true,
|
|
633
|
+
}, firstRow = super.toHtmlInternal(opt), newline = opt?.nowrap ? ' ' : '\n';
|
|
634
|
+
return `${[this, ...tr].flatMap(filter)
|
|
635
|
+
.map(token => token.toHtmlInternal(newOpt).trim())
|
|
636
|
+
.join(' ')}<table${childNodes[1].toHtmlInternal()}>${newline}<tbody>${firstRow + (tr.length > 0 && firstRow.endsWith('</tr>') ? newline : '')}${(0, html_1.html)(tr, newline, opt)}${tr.length === 0 && !firstRow ? '<tr><td></td></tr>' : ''}</tbody></table>`;
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
})();
|
|
593
640
|
exports.TableToken = TableToken;
|
|
594
641
|
constants_1.classes['TableToken'] = __filename;
|