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.
Files changed (70) hide show
  1. package/README.md +3 -5
  2. package/bundle/bundle-es8.min.js +25 -25
  3. package/bundle/bundle-lsp.min.js +26 -26
  4. package/bundle/bundle.min.js +25 -25
  5. package/dist/base.d.mts +6 -1
  6. package/dist/base.d.ts +6 -1
  7. package/dist/index.d.ts +2 -2
  8. package/dist/index.js +10 -1
  9. package/dist/lib/element.js +2 -1
  10. package/dist/lib/lintConfig.d.ts +13 -0
  11. package/dist/lib/lintConfig.js +161 -0
  12. package/dist/lib/lsp.js +6 -4
  13. package/dist/lib/node.js +646 -606
  14. package/dist/lib/text.js +4 -0
  15. package/dist/mixin/attributesParent.d.ts +6 -6
  16. package/dist/mixin/attributesParent.js +4 -4
  17. package/dist/mixin/cached.d.ts +5 -0
  18. package/dist/mixin/cached.js +22 -0
  19. package/dist/mixin/clone.d.ts +5 -0
  20. package/dist/mixin/clone.js +23 -0
  21. package/dist/mixin/hidden.js +68 -18
  22. package/dist/mixin/sol.js +1 -1
  23. package/dist/parser/commentAndExt.js +1 -1
  24. package/dist/parser/html.js +3 -3
  25. package/dist/parser/table.js +2 -2
  26. package/dist/src/arg.js +13 -7
  27. package/dist/src/atom.js +76 -31
  28. package/dist/src/attribute.js +49 -21
  29. package/dist/src/attributes.d.ts +7 -7
  30. package/dist/src/attributes.js +415 -366
  31. package/dist/src/commented.js +81 -35
  32. package/dist/src/converter.js +13 -7
  33. package/dist/src/converterFlags.js +33 -22
  34. package/dist/src/converterRule.js +263 -216
  35. package/dist/src/extLink.js +21 -16
  36. package/dist/src/gallery.js +18 -8
  37. package/dist/src/heading.js +66 -57
  38. package/dist/src/hidden.js +14 -9
  39. package/dist/src/html.js +28 -9
  40. package/dist/src/imageParameter.js +13 -6
  41. package/dist/src/imagemap.js +32 -25
  42. package/dist/src/index.js +53 -44
  43. package/dist/src/link/base.js +13 -8
  44. package/dist/src/link/file.js +401 -354
  45. package/dist/src/link/galleryImage.js +9 -5
  46. package/dist/src/link/index.js +7 -3
  47. package/dist/src/link/redirectTarget.js +7 -3
  48. package/dist/src/magicLink.js +23 -14
  49. package/dist/src/nested.js +122 -74
  50. package/dist/src/nowiki/base.js +5 -2
  51. package/dist/src/nowiki/comment.js +5 -1
  52. package/dist/src/nowiki/index.js +3 -3
  53. package/dist/src/nowiki/quote.js +13 -8
  54. package/dist/src/onlyinclude.js +17 -9
  55. package/dist/src/paramTag/index.js +21 -14
  56. package/dist/src/parameter.js +26 -20
  57. package/dist/src/pre.js +91 -45
  58. package/dist/src/syntax.js +14 -10
  59. package/dist/src/table/index.js +550 -503
  60. package/dist/src/table/td.js +65 -58
  61. package/dist/src/table/trBase.js +179 -129
  62. package/dist/src/tagPair/ext.js +32 -20
  63. package/dist/src/tagPair/include.js +5 -5
  64. package/dist/src/tagPair/translate.js +150 -103
  65. package/dist/src/transclude.js +13 -8
  66. package/dist/util/html.js +46 -41
  67. package/dist/util/lint.js +4 -4
  68. package/dist/util/string.js +13 -7
  69. package/extensions/dist/base.js +2 -2
  70. package/package.json +15 -15
@@ -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
- class TableToken extends trBase_1.TrBaseToken {
66
- /* NOT FOR BROWSER END */
67
- get type() {
68
- return 'table';
69
- }
70
- /** whether the table is closed / 表格是否闭合 */
71
- get closed() {
72
- return this.lastChild.is('table-syntax');
73
- }
74
- /* NOT FOR BROWSER */
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
- /* NOT FOR BROWSER END */
81
- /**
82
- * @param syntax 表格语法
83
- * @param attr 表格属性
84
- */
85
- constructor(syntax, attr, config, accum) {
86
- super(/^(?:\{\||\{\{\{\s*!\s*\}\}|\{\{\s*\(!\s*\}\})$/u, syntax, 'table', attr, config, accum, {
87
- Token: 2, SyntaxToken: [0, -1], AttributesToken: 1, TdToken: '2:', TrToken: '2:',
88
- });
89
- }
90
- /** @private */
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
- return errors;
124
- }
125
- /**
126
- * Close the table syntax
127
- *
128
- * 闭合表格语法
129
- * @param syntax syntax of the table end / 表格结尾语法
130
- * @param halfParsed
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
- this.lastChild.safeReplaceChildren(inner);
149
- }
150
- /**
151
- * Get the table layout
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
- /* NOT FOR BROWSER END */
169
- let j = 0, k = 0, last;
170
- for (const cell of rows[i].childNodes.slice(2)) {
171
- if (cell.is('td')) {
172
- if (cell.isIndependent()) {
173
- last = cell.subtype !== 'caption';
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 (last) {
176
- const coords = { row: i, column: j }, { rowspan, colspan } = cell;
177
- j++;
178
- while (rowLayout[k]) {
179
- k++;
180
- }
181
- /* NOT FOR BROWSER */
182
- if (i === stop?.row && j > stop.column) {
183
- rowLayout[k] = coords;
184
- return layout;
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
- /* NOT FOR BROWSER END */
187
- for (let y = i; y < Math.min(i + rowspan, length); y++) {
188
- for (let x = k; x < k + colspan; x++) {
189
- layout[y][x] = coords;
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
- else if ((0, exports.isRowEnd)(cell)) {
200
- break;
245
+ else if ((0, exports.isRowEnd)(cell)) {
246
+ break;
247
+ }
201
248
  }
202
249
  }
250
+ return layout;
203
251
  }
204
- return layout;
205
- }
206
- /**
207
- * Get all rows
208
- *
209
- * 获取所有行
210
- */
211
- getAllRows() {
212
- return [
213
- ...super.getRowCount() ? [this] : [],
214
- ...this.childNodes.slice(1)
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
- else /* istanbul ignore if */ if (n < 0 || n > nRows || n === nRows && !insert) {
231
- throw new RangeError(`The table does not have row ${n}!`);
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
- else if (isRow) {
235
- n--;
236
- }
237
- for (const child of this.childNodes.slice(2)) {
238
- const { type } = child;
239
- if (type === 'tr' && child.getRowCount()) {
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
- if (n < 0) {
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
- else if (type === 'table-syntax') {
247
- return child;
248
- /* NOT FOR BROWSER END */
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
- return undefined;
252
- }
253
- /** @private */
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
- * @param token 表格或表格行
330
+ * Get the next row
331
+ *
332
+ * 获取下一行
582
333
  */
583
- const filter = (token) => token.childNodes.filter((0, debug_1.isToken)('table-inter'));
584
- const { childNodes } = this, tr = childNodes.filter((0, debug_1.isToken)('tr')), newOpt = {
585
- ...opt,
586
- nowrap: true,
587
- }, firstRow = super.toHtmlInternal(opt), newline = opt?.nowrap ? ' ' : '\n';
588
- return `${[this, ...tr].flatMap(filter)
589
- .map(token => token.toHtmlInternal(newOpt).trim())
590
- .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>`;
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;