wikiparser-node 1.13.1-b → 1.13.1

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 (174) hide show
  1. package/config/.schema.json +203 -0
  2. package/config/default.json +32 -31
  3. package/config/enwiki.json +829 -15
  4. package/config/llwiki.json +56 -21
  5. package/config/moegirl.json +65 -21
  6. package/config/zhwiki.json +498 -32
  7. package/dist/addon/table.js +494 -0
  8. package/dist/addon/token.js +392 -0
  9. package/dist/addon/transclude.js +184 -0
  10. package/dist/base.d.ts +110 -0
  11. package/dist/base.js +67 -0
  12. package/dist/index.d.ts +33 -0
  13. package/dist/index.js +279 -0
  14. package/dist/internal.d.ts +47 -0
  15. package/dist/lib/element.d.ts +125 -0
  16. package/dist/lib/element.js +364 -0
  17. package/dist/lib/node.d.ts +173 -0
  18. package/dist/lib/node.js +478 -0
  19. package/dist/lib/range.d.ts +105 -0
  20. package/dist/lib/range.js +406 -0
  21. package/dist/lib/ranges.d.ts +28 -0
  22. package/dist/lib/ranges.js +126 -0
  23. package/dist/lib/rect.d.ts +18 -0
  24. package/dist/lib/rect.js +36 -0
  25. package/dist/lib/text.d.ts +58 -0
  26. package/dist/lib/text.js +414 -0
  27. package/dist/lib/title.d.ts +49 -0
  28. package/dist/lib/title.js +251 -0
  29. package/dist/mixin/attributesParent.d.ts +49 -0
  30. package/dist/mixin/attributesParent.js +80 -0
  31. package/dist/mixin/fixed.d.ts +5 -0
  32. package/dist/mixin/fixed.js +32 -0
  33. package/dist/mixin/flagsParent.d.ts +43 -0
  34. package/dist/mixin/flagsParent.js +64 -0
  35. package/dist/mixin/hidden.d.ts +7 -0
  36. package/dist/mixin/hidden.js +39 -0
  37. package/dist/mixin/magicLinkParent.d.ts +19 -0
  38. package/dist/mixin/magicLinkParent.js +43 -0
  39. package/dist/mixin/singleLine.d.ts +5 -0
  40. package/dist/mixin/singleLine.js +25 -0
  41. package/dist/mixin/sol.d.ts +6 -0
  42. package/dist/mixin/sol.js +45 -0
  43. package/dist/mixin/syntax.d.ts +8 -0
  44. package/dist/mixin/syntax.js +46 -0
  45. package/dist/parser/braces.js +152 -0
  46. package/dist/parser/commentAndExt.js +84 -0
  47. package/dist/parser/converter.js +41 -0
  48. package/dist/parser/externalLinks.js +39 -0
  49. package/dist/parser/hrAndDoubleUnderscore.js +44 -0
  50. package/dist/parser/html.js +40 -0
  51. package/dist/parser/links.js +103 -0
  52. package/dist/parser/list.js +116 -0
  53. package/dist/parser/magicLinks.js +55 -0
  54. package/dist/parser/quotes.js +69 -0
  55. package/dist/parser/redirect.js +28 -0
  56. package/dist/parser/selector.js +443 -0
  57. package/dist/parser/table.js +125 -0
  58. package/dist/src/arg.d.ts +49 -0
  59. package/dist/src/arg.js +220 -0
  60. package/dist/src/atom.d.ts +14 -0
  61. package/dist/src/atom.js +54 -0
  62. package/dist/src/attribute.d.ts +64 -0
  63. package/dist/src/attribute.js +482 -0
  64. package/dist/src/attributes.d.ts +103 -0
  65. package/dist/src/attributes.js +383 -0
  66. package/dist/src/converter.d.ts +28 -0
  67. package/dist/src/converter.js +153 -0
  68. package/dist/src/converterFlags.d.ts +80 -0
  69. package/dist/src/converterFlags.js +241 -0
  70. package/dist/src/converterRule.d.ts +71 -0
  71. package/dist/src/converterRule.js +218 -0
  72. package/dist/src/extLink.d.ts +36 -0
  73. package/dist/src/extLink.js +223 -0
  74. package/dist/src/gallery.d.ts +51 -0
  75. package/dist/src/gallery.js +166 -0
  76. package/dist/src/heading.d.ts +44 -0
  77. package/dist/src/heading.js +222 -0
  78. package/dist/src/hidden.d.ts +9 -0
  79. package/dist/src/hidden.js +82 -0
  80. package/dist/src/html.d.ts +61 -0
  81. package/dist/src/html.js +344 -0
  82. package/dist/src/imageParameter.d.ts +60 -0
  83. package/dist/src/imageParameter.js +262 -0
  84. package/dist/src/imagemap.d.ts +47 -0
  85. package/dist/src/imagemap.js +148 -0
  86. package/dist/src/imagemapLink.d.ts +35 -0
  87. package/dist/src/imagemapLink.js +99 -0
  88. package/dist/src/index.d.ts +136 -0
  89. package/dist/src/index.js +790 -0
  90. package/dist/src/link/base.d.ts +52 -0
  91. package/dist/src/link/base.js +258 -0
  92. package/dist/src/link/category.d.ts +22 -0
  93. package/dist/src/link/category.js +36 -0
  94. package/dist/src/link/file.d.ts +102 -0
  95. package/dist/src/link/file.js +345 -0
  96. package/dist/src/link/galleryImage.d.ts +29 -0
  97. package/dist/src/link/galleryImage.js +133 -0
  98. package/dist/src/link/index.d.ts +39 -0
  99. package/dist/src/link/index.js +100 -0
  100. package/dist/src/link/redirectTarget.d.ts +27 -0
  101. package/dist/src/link/redirectTarget.js +71 -0
  102. package/dist/src/magicLink.d.ts +57 -0
  103. package/dist/src/magicLink.js +261 -0
  104. package/dist/src/nested.d.ts +40 -0
  105. package/dist/src/nested.js +108 -0
  106. package/dist/src/nowiki/base.d.ts +28 -0
  107. package/dist/src/nowiki/base.js +90 -0
  108. package/dist/src/nowiki/comment.d.ts +14 -0
  109. package/dist/src/nowiki/comment.js +123 -0
  110. package/dist/src/nowiki/dd.d.ts +8 -0
  111. package/dist/src/nowiki/dd.js +74 -0
  112. package/dist/src/nowiki/doubleUnderscore.d.ts +15 -0
  113. package/dist/src/nowiki/doubleUnderscore.js +101 -0
  114. package/dist/src/nowiki/hr.d.ts +5 -0
  115. package/dist/src/nowiki/hr.js +72 -0
  116. package/dist/src/nowiki/index.d.ts +14 -0
  117. package/dist/src/nowiki/index.js +30 -0
  118. package/dist/src/nowiki/list.d.ts +5 -0
  119. package/dist/src/nowiki/list.js +67 -0
  120. package/dist/src/nowiki/listBase.d.ts +23 -0
  121. package/dist/src/nowiki/listBase.js +100 -0
  122. package/dist/src/nowiki/noinclude.d.ts +6 -0
  123. package/dist/src/nowiki/noinclude.js +77 -0
  124. package/dist/src/nowiki/quote.d.ts +14 -0
  125. package/dist/src/nowiki/quote.js +149 -0
  126. package/dist/src/onlyinclude.d.ts +13 -0
  127. package/dist/src/onlyinclude.js +60 -0
  128. package/dist/src/paramTag/index.d.ts +28 -0
  129. package/dist/src/paramTag/index.js +80 -0
  130. package/dist/src/paramTag/inputbox.d.ts +8 -0
  131. package/dist/src/paramTag/inputbox.js +38 -0
  132. package/dist/src/parameter.d.ts +60 -0
  133. package/dist/src/parameter.js +267 -0
  134. package/dist/src/pre.d.ts +28 -0
  135. package/dist/src/pre.js +70 -0
  136. package/dist/src/redirect.d.ts +30 -0
  137. package/dist/src/redirect.js +128 -0
  138. package/dist/src/syntax.d.ts +15 -0
  139. package/dist/src/syntax.js +87 -0
  140. package/dist/src/table/base.d.ts +28 -0
  141. package/dist/src/table/base.js +81 -0
  142. package/dist/src/table/index.d.ts +230 -0
  143. package/dist/src/table/index.js +506 -0
  144. package/dist/src/table/td.d.ts +72 -0
  145. package/dist/src/table/td.js +375 -0
  146. package/dist/src/table/tr.d.ts +30 -0
  147. package/dist/src/table/tr.js +61 -0
  148. package/dist/src/table/trBase.d.ts +49 -0
  149. package/dist/src/table/trBase.js +165 -0
  150. package/dist/src/tagPair/ext.d.ts +29 -0
  151. package/dist/src/tagPair/ext.js +229 -0
  152. package/dist/src/tagPair/include.d.ts +33 -0
  153. package/dist/src/tagPair/include.js +145 -0
  154. package/dist/src/tagPair/index.d.ts +23 -0
  155. package/dist/src/tagPair/index.js +130 -0
  156. package/dist/src/transclude.d.ts +159 -0
  157. package/dist/src/transclude.js +598 -0
  158. package/dist/util/constants.js +26 -0
  159. package/dist/util/debug.js +95 -0
  160. package/dist/util/diff.js +83 -0
  161. package/dist/util/html.js +146 -0
  162. package/dist/util/lint.js +32 -0
  163. package/dist/util/string.js +107 -0
  164. package/errors/README +3 -0
  165. package/package.json +21 -28
  166. package/printed/README +3 -0
  167. package/bundle/bundle.min.js +0 -37
  168. package/extensions/dist/base.js +0 -163
  169. package/extensions/dist/codejar.js +0 -53
  170. package/extensions/dist/editor.js +0 -159
  171. package/extensions/dist/highlight.js +0 -30
  172. package/extensions/dist/lint.js +0 -72
  173. package/extensions/editor.css +0 -59
  174. package/extensions/ui.css +0 -162
@@ -0,0 +1,506 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TableToken = exports.Layout = exports.isRowEnd = void 0;
4
+ const lint_1 = require("../../util/lint");
5
+ const debug_1 = require("../../util/debug");
6
+ const rect_1 = require("../../lib/rect");
7
+ const index_1 = require("../../index");
8
+ const trBase_1 = require("./trBase");
9
+ const syntax_1 = require("../syntax");
10
+ /* NOT FOR BROWSER */
11
+ const html_1 = require("../../util/html");
12
+ const constants_1 = require("../../util/constants");
13
+ const string_1 = require("../../util/string");
14
+ /* NOT FOR BROWSER END */
15
+ const closingPattern = /^\n[^\S\n]*(?:\|\}|\{\{\s*!\s*\}\}\}|\{\{\s*!\)\s*\}\})$/u;
16
+ /**
17
+ * 是否是行尾
18
+ * @param {Token} cell 表格单元格
19
+ */
20
+ const isRowEnd = ({ type }) => type === 'tr' || type === 'table-syntax';
21
+ exports.isRowEnd = isRowEnd;
22
+ /** @extends {Array<TableCoords[]>} */
23
+ class Layout extends Array {
24
+ /* NOT FOR BROWSER */
25
+ /** 打印表格布局 */
26
+ print() {
27
+ const hBorders = (0, debug_1.emptyArray)(this.length + 1, i => {
28
+ const prev = this[i - 1] ?? [], next = this[i] ?? [];
29
+ return (0, debug_1.emptyArray)(Math.max(prev.length, next.length), j => prev[j] !== next[j]);
30
+ }), vBorders = this.map(cur => (0, debug_1.emptyArray)(cur.length + 1, j => cur[j - 1] !== cur[j]));
31
+ let out = '';
32
+ for (let i = 0; i <= this.length; i++) {
33
+ const hBorder = hBorders[i].map(Number), vBorderTop = (vBorders[i - 1] ?? []).map(Number), vBorderBottom = (vBorders[i] ?? []).map(Number),
34
+ // eslint-disable-next-line no-sparse-arrays
35
+ border = [' ', , , '┌', , '┐', '─', '┬', , '│', '└', '├', '┘', '┤', '┴', '┼'];
36
+ for (let j = 0; j <= hBorder.length; j++) {
37
+ const bit = (vBorderTop[j] << 3) + (vBorderBottom[j] << 0)
38
+ + (hBorder[j - 1] << 2) + (hBorder[j] << 1);
39
+ out += border[bit] + (hBorder[j] ? '─' : ' ');
40
+ }
41
+ out += '\n';
42
+ }
43
+ console.log(out.slice(0, -1));
44
+ }
45
+ }
46
+ exports.Layout = Layout;
47
+ /**
48
+ * 表格
49
+ * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken, ...TrToken, ?SyntaxToken]}`
50
+ */
51
+ class TableToken extends trBase_1.TrBaseToken {
52
+ /* NOT FOR BROWSER END */
53
+ get type() {
54
+ return 'table';
55
+ }
56
+ /** 表格是否闭合 */
57
+ get closed() {
58
+ return this.lastChild.type === 'table-syntax';
59
+ }
60
+ /* NOT FOR BROWSER */
61
+ set closed(closed) {
62
+ if (closed && !this.closed) {
63
+ this.close(this.closest('parameter-value') ? '\n{{!}}}' : '\n|}');
64
+ }
65
+ }
66
+ /* NOT FOR BROWSER END */
67
+ /**
68
+ * @param syntax 表格语法
69
+ * @param attr 表格属性
70
+ */
71
+ constructor(syntax, attr, config, accum) {
72
+ super(/^(?:\{\||\{\{\{\s*!\s*\}\}|\{\{\s*\(!\s*\}\})$/u, syntax, 'table', attr, config, accum, {
73
+ Token: 2, SyntaxToken: [0, -1], AttributesToken: 1, TdToken: '2:', TrToken: '2:',
74
+ });
75
+ }
76
+ /** @private */
77
+ lint(start = this.getAbsoluteIndex(), re) {
78
+ const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
79
+ if (!this.closed) {
80
+ errors.push((0, lint_1.generateForChild)(this.firstChild, rect, 'unclosed-table', index_1.default.msg('unclosed $1', 'table')));
81
+ }
82
+ const layout = this.getLayout(), { length } = layout;
83
+ if (length > 1) {
84
+ let low = 1, high = Infinity, j = 0;
85
+ for (; j < length; j++) {
86
+ const row = layout[j], max = row.length;
87
+ if (max < low) {
88
+ break;
89
+ }
90
+ else if (max < high) {
91
+ high = max;
92
+ }
93
+ const min = row.indexOf(row[max - 1]) + 1;
94
+ if (min > high) {
95
+ break;
96
+ }
97
+ else if (min > low) {
98
+ low = min;
99
+ }
100
+ }
101
+ if (j < length) {
102
+ const e = (0, lint_1.generateForChild)(this.getNthRow(j), rect, 'table-layout', 'inconsistent table layout', 'warning');
103
+ e.startIndex++;
104
+ e.startLine++;
105
+ e.startCol = 0;
106
+ errors.push(e);
107
+ }
108
+ }
109
+ return errors;
110
+ }
111
+ /**
112
+ * 闭合表格语法
113
+ * @param syntax 表格结尾语法
114
+ * @param halfParsed
115
+ */
116
+ close(syntax = '\n|}', halfParsed) {
117
+ const config = this.getAttribute('config'), accum = this.getAttribute('accum'), inner = halfParsed ? [syntax] : index_1.default.parse(syntax, this.getAttribute('include'), 2, config).childNodes;
118
+ if (this.lastChild.type !== 'table-syntax') {
119
+ debug_1.Shadow.run(() => {
120
+ const token = new syntax_1.SyntaxToken(undefined, closingPattern, 'table-syntax', config, accum, {
121
+ 'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':',
122
+ });
123
+ super.insertAt(token);
124
+ if (!halfParsed) {
125
+ token.afterBuild();
126
+ }
127
+ });
128
+ }
129
+ this.lastChild.replaceChildren(...inner);
130
+ }
131
+ /**
132
+ * 获取表格布局
133
+ * @param stop 中止条件
134
+ * @param stop.row 中止行
135
+ * @param stop.column 中止列
136
+ * @param stop.x 中止行
137
+ * @param stop.y 中止列
138
+ */
139
+ getLayout(stop) {
140
+ const rows = this.getAllRows(), { length } = rows, layout = new Layout(...(0, debug_1.emptyArray)(length, () => []));
141
+ for (const [i, rowLayout] of layout.entries()) {
142
+ /* NOT FOR BROWSER */
143
+ if (i > (stop?.row ?? stop?.y ?? NaN)) {
144
+ break;
145
+ }
146
+ /* NOT FOR BROWSER END */
147
+ let j = 0, k = 0, last;
148
+ for (const cell of rows[i].childNodes.slice(2)) {
149
+ if (cell.type === 'td') {
150
+ if (cell.isIndependent()) {
151
+ last = cell.subtype !== 'caption';
152
+ }
153
+ if (last) {
154
+ const coords = { row: i, column: j }, { rowspan, colspan } = cell;
155
+ j++;
156
+ while (rowLayout[k]) {
157
+ k++;
158
+ }
159
+ /* NOT FOR BROWSER */
160
+ if (i === stop?.row && j > stop.column) {
161
+ rowLayout[k] = coords;
162
+ return layout;
163
+ }
164
+ /* NOT FOR BROWSER END */
165
+ for (let y = i; y < Math.min(i + rowspan, length); y++) {
166
+ for (let x = k; x < k + colspan; x++) {
167
+ layout[y][x] = coords;
168
+ }
169
+ }
170
+ k += colspan;
171
+ /* NOT FOR BROWSER */
172
+ if (i === stop?.y && k > (stop.x ?? NaN)) {
173
+ return layout;
174
+ }
175
+ }
176
+ }
177
+ else if ((0, exports.isRowEnd)(cell)) {
178
+ break;
179
+ }
180
+ }
181
+ }
182
+ return layout;
183
+ }
184
+ /** 获取所有行 */
185
+ getAllRows() {
186
+ return [
187
+ ...super.getRowCount() ? [this] : [],
188
+ ...this.childNodes.slice(1)
189
+ .filter((child) => child.type === 'tr' && child.getRowCount() > 0),
190
+ ];
191
+ }
192
+ /**
193
+ * 获取指定坐标的单元格
194
+ * @param coords 表格坐标
195
+ */
196
+ getNthCell(coords) {
197
+ let rawCoords = coords;
198
+ if (coords.row === undefined) {
199
+ rawCoords = this.toRawCoords(coords);
200
+ }
201
+ return rawCoords && this.getNthRow(rawCoords.row, false, false)?.getNthCol(rawCoords.column);
202
+ }
203
+ getNthRow(n, force, insert) {
204
+ const isRow = super.getRowCount();
205
+ /* NOT FOR BROWSER */
206
+ const nRows = this.getRowCount();
207
+ n += n < 0 ? nRows : 0;
208
+ /* NOT FOR BROWSER END */
209
+ if (n === 0
210
+ && (isRow
211
+ || force && nRows === 0)) {
212
+ return this;
213
+ /* NOT FOR BROWSER */
214
+ }
215
+ else if (n < 0 || n > nRows || n === nRows && !insert) {
216
+ throw new RangeError(`The table does not have row ${n}!`);
217
+ /* NOT FOR BROWSER END */
218
+ }
219
+ else if (isRow) {
220
+ n--;
221
+ }
222
+ for (const child of this.childNodes.slice(2)) {
223
+ if (child.type === 'tr' && child.getRowCount()) {
224
+ n--;
225
+ if (n < 0) {
226
+ return child;
227
+ }
228
+ /* NOT FOR BROWSER */
229
+ }
230
+ else if (child.type === 'table-syntax') {
231
+ return child;
232
+ /* NOT FOR BROWSER END */
233
+ }
234
+ }
235
+ return undefined;
236
+ }
237
+ /** @override */
238
+ json() {
239
+ const json = super.json();
240
+ json['closed'] = this.closed;
241
+ return json;
242
+ }
243
+ /* NOT FOR BROWSER */
244
+ /**
245
+ * @override
246
+ * @param token 待插入的子节点
247
+ * @param i 插入位置
248
+ * @throws `SyntaxError` 表格的闭合部分非法
249
+ */
250
+ insertAt(token, i = this.length) {
251
+ i += i < 0 ? this.length : 0;
252
+ const previous = this.childNodes[i - 1];
253
+ if (typeof token !== 'string' && token.type === 'td' && previous?.type === 'tr') {
254
+ index_1.default.warn('The table cell is inserted into the current row instead.');
255
+ return previous.insertAt(token);
256
+ }
257
+ else if (i > 0 && token instanceof syntax_1.SyntaxToken && token.pattern !== closingPattern) {
258
+ throw new SyntaxError(`The closing part of the table is invalid: ${(0, string_1.noWrap)(token.toString())}`);
259
+ }
260
+ return super.insertAt(token, i);
261
+ }
262
+ getRowCount() {
263
+ return super.getRowCount() + this.childNodes.filter(child => child.type === 'tr' && child.getRowCount()).length;
264
+ }
265
+ /** 获取下一行 */
266
+ getNextRow() {
267
+ return this.getNthRow(super.getRowCount() ? 1 : 0, false, false);
268
+ }
269
+ /** 打印表格布局 */
270
+ printLayout() {
271
+ require('../../addon/table');
272
+ this.printLayout();
273
+ }
274
+ /**
275
+ * 转换为渲染后的表格坐标
276
+ * @param {TableCoords} coord wikitext中的表格坐标
277
+ */
278
+ toRenderedCoords(coord) {
279
+ require('../../addon/table');
280
+ return this.toRenderedCoords(coord);
281
+ }
282
+ /**
283
+ * 转换为wikitext中的表格坐标
284
+ * @param {TableRenderedCoords} coord 渲染后的表格坐标
285
+ */
286
+ toRawCoords(coord) {
287
+ require('../../addon/table');
288
+ return this.toRawCoords(coord);
289
+ }
290
+ /**
291
+ * 获取完整行
292
+ * @param y 行号
293
+ */
294
+ getFullRow(y) {
295
+ require('../../addon/table');
296
+ return this.getFullRow(y);
297
+ }
298
+ /**
299
+ * 获取完整列
300
+ * @param x 列号
301
+ */
302
+ getFullCol(x) {
303
+ require('../../addon/table');
304
+ return this.getFullCol(x);
305
+ }
306
+ /**
307
+ * 设置行格式
308
+ * @param y 行号
309
+ * @param attr 表格属性
310
+ * @param multiRow 是否对所有单元格设置,或是仅对行首单元格设置
311
+ */
312
+ formatTableRow(y, attr, multiRow) {
313
+ require('../../addon/table');
314
+ this.formatTableRow(y, attr, multiRow);
315
+ }
316
+ /**
317
+ * 设置列格式
318
+ * @param x 列号
319
+ * @param attr 表格属性
320
+ * @param multiCol 是否对所有单元格设置,或是仅对行首单元格设置
321
+ */
322
+ formatTableCol(x, attr, multiCol) {
323
+ require('../../addon/table');
324
+ this.formatTableCol(x, attr, multiCol);
325
+ }
326
+ /**
327
+ * 填补表格行
328
+ * @param y 行号
329
+ * @param inner 填充内容
330
+ * @param subtype 单元格类型
331
+ * @param attr 表格属性
332
+ */
333
+ fillTableRow(y, inner, subtype, attr) {
334
+ require('../../addon/table');
335
+ this.fillTableRow(y, inner, subtype, attr);
336
+ }
337
+ /**
338
+ * 填补表格
339
+ * @param inner 填充内容
340
+ * @param subtype 单元格类型
341
+ * @param attr 表格属性
342
+ */
343
+ fillTable(inner, subtype, attr) {
344
+ require('../../addon/table');
345
+ this.fillTable(inner, subtype, attr);
346
+ }
347
+ insertTableCell(inner, coords, subtype, attr) {
348
+ require('../../addon/table');
349
+ return this.insertTableCell(inner, coords, subtype, attr);
350
+ }
351
+ /** @private */
352
+ prependTableRow() {
353
+ require('../../addon/table');
354
+ return this.prependTableRow();
355
+ }
356
+ /**
357
+ * 插入表格行
358
+ * @param y 行号
359
+ * @param attr 表格行属性
360
+ * @param inner 内部wikitext
361
+ * @param subtype 单元格类型
362
+ * @param innerAttr 单元格属性
363
+ */
364
+ insertTableRow(y, attr, inner, subtype, innerAttr) {
365
+ require('../../addon/table');
366
+ return this.insertTableRow(y, attr, inner, subtype, innerAttr);
367
+ }
368
+ /**
369
+ * 插入表格列
370
+ * @param x 列号
371
+ * @param inner 内部wikitext
372
+ * @param subtype 单元格类型
373
+ * @param attr 单元格属性
374
+ * @throws `RangeError` 列号过大
375
+ */
376
+ insertTableCol(x, inner, subtype, attr) {
377
+ require('../../addon/table');
378
+ this.insertTableCol(x, inner, subtype, attr);
379
+ }
380
+ /**
381
+ * 移除表格行
382
+ * @param y 行号
383
+ */
384
+ removeTableRow(y) {
385
+ require('../../addon/table');
386
+ return this.removeTableRow(y);
387
+ }
388
+ /**
389
+ * 移除表格列
390
+ * @param x 列号
391
+ */
392
+ removeTableCol(x) {
393
+ require('../../addon/table');
394
+ this.removeTableCol(x);
395
+ }
396
+ /**
397
+ * 合并单元格
398
+ * @param xlim 列范围
399
+ * @param ylim 行范围
400
+ * @throws `RangeError` 待合并区域与外侧区域有重叠
401
+ */
402
+ mergeCells(xlim, ylim) {
403
+ require('../../addon/table');
404
+ return this.mergeCells(xlim, ylim);
405
+ }
406
+ /** @private */
407
+ split(coords, dirs) {
408
+ require('../../addon/table');
409
+ this.split(coords, dirs);
410
+ }
411
+ /**
412
+ * 分裂成多行
413
+ * @param coords 单元格坐标
414
+ */
415
+ splitIntoRows(coords) {
416
+ require('../../addon/table');
417
+ this.splitIntoRows(coords);
418
+ }
419
+ /**
420
+ * 分裂成多列
421
+ * @param coords 单元格坐标
422
+ */
423
+ splitIntoCols(coords) {
424
+ require('../../addon/table');
425
+ this.splitIntoCols(coords);
426
+ }
427
+ /**
428
+ * 分裂成单元格
429
+ * @param coords 单元格坐标
430
+ */
431
+ splitIntoCells(coords) {
432
+ require('../../addon/table');
433
+ this.splitIntoCells(coords);
434
+ }
435
+ /**
436
+ * 复制一行并插入该行之前
437
+ * @param row 行号
438
+ */
439
+ replicateTableRow(row) {
440
+ require('../../addon/table');
441
+ return this.replicateTableRow(row);
442
+ }
443
+ /**
444
+ * 复制一列并插入该列之前
445
+ * @param x 列号
446
+ */
447
+ replicateTableCol(x) {
448
+ require('../../addon/table');
449
+ return this.replicateTableCol(x);
450
+ }
451
+ /** @private */
452
+ moveCol(x, reference, after) {
453
+ require('../../addon/table');
454
+ this.moveCol(x, reference, after);
455
+ }
456
+ /**
457
+ * 移动表格行
458
+ * @param y 行号
459
+ * @param before 新位置
460
+ * @throws `RangeError` 无法移动
461
+ */
462
+ moveTableRowBefore(y, before) {
463
+ require('../../addon/table');
464
+ return this.moveTableRowBefore(y, before);
465
+ }
466
+ /**
467
+ * 移动表格行
468
+ * @param y 行号
469
+ * @param after 新位置
470
+ * @throws `RangeError` 无法移动
471
+ */
472
+ moveTableRowAfter(y, after) {
473
+ require('../../addon/table');
474
+ return this.moveTableRowAfter(y, after);
475
+ }
476
+ /**
477
+ * 移动表格列
478
+ * @param x 列号
479
+ * @param before 新位置
480
+ */
481
+ moveTableColBefore(x, before) {
482
+ require('../../addon/table');
483
+ this.moveTableColBefore(x, before);
484
+ }
485
+ /**
486
+ * 移动表格列
487
+ * @param x 列号
488
+ * @param after 新位置
489
+ */
490
+ moveTableColAfter(x, after) {
491
+ require('../../addon/table');
492
+ this.moveTableColAfter(x, after);
493
+ }
494
+ /** @private */
495
+ toHtmlInternal(nowrap) {
496
+ /**
497
+ * 过滤需要移出表格的节点
498
+ * @param token 表格或表格行
499
+ */
500
+ const filter = (token) => token.childNodes.filter((0, debug_1.isToken)('table-inter'));
501
+ const { childNodes } = this, tr = childNodes.filter((0, debug_1.isToken)('tr')), inter = [this, ...tr].flatMap(filter).map(token => token.toHtmlInternal(true).trim()).join(' ');
502
+ return `${inter}<table${childNodes[1].toHtmlInternal()}>${nowrap ? ' ' : '\n'}<tbody>${super.toHtmlInternal(nowrap)}${(0, html_1.html)(tr, '', nowrap)}</tbody></table>`;
503
+ }
504
+ }
505
+ exports.TableToken = TableToken;
506
+ constants_1.classes['TableToken'] = __filename;
@@ -0,0 +1,72 @@
1
+ import Parser from '../../index';
2
+ import { Token } from '../index';
3
+ import { TableBaseToken } from './base';
4
+ import type { LintError, AST } from '../../base';
5
+ import type { SyntaxToken, AttributesToken, TrToken, TableToken } from '../../internal';
6
+ export type TdSubtypes = 'td' | 'th' | 'caption';
7
+ export interface TdSpanAttrs {
8
+ rowspan?: number;
9
+ colspan?: number;
10
+ }
11
+ declare type TdAttrGetter<T extends string> = T extends keyof TdSpanAttrs ? number : string | true | undefined;
12
+ declare type TdAttrSetter<T extends string> = T extends keyof TdSpanAttrs ? number : string | boolean;
13
+ export type TdAttrs = Record<string, string | true> & TdSpanAttrs;
14
+ /**
15
+ * `<td>`、`<th>`和`<caption>`
16
+ * @classdesc `{childNodes: [SyntaxToken, AttributesToken, Token]}`
17
+ */
18
+ export declare abstract class TdToken extends TableBaseToken {
19
+ #private;
20
+ readonly childNodes: readonly [SyntaxToken, AttributesToken, Token];
21
+ abstract get parentNode(): TrToken | TableToken | undefined;
22
+ abstract get nextSibling(): this | TrToken | SyntaxToken | undefined;
23
+ abstract get previousSibling(): Token | undefined;
24
+ abstract get children(): [SyntaxToken, AttributesToken, Token];
25
+ abstract get parentElement(): TrToken | TableToken | undefined;
26
+ abstract get nextElementSibling(): this | TrToken | SyntaxToken | undefined;
27
+ get type(): 'td';
28
+ /** rowspan */
29
+ get rowspan(): number;
30
+ /** colspan */
31
+ get colspan(): number;
32
+ /** 单元格类型 */
33
+ get subtype(): TdSubtypes;
34
+ set subtype(subtype: TdSubtypes);
35
+ set rowspan(rowspan: number);
36
+ set colspan(colspan: number);
37
+ /** 内部wikitext */
38
+ get innerText(): string;
39
+ set innerText(text: string);
40
+ /**
41
+ * @param syntax 单元格语法
42
+ * @param inner 内部wikitext
43
+ */
44
+ constructor(syntax: string, inner?: string, config?: Parser.Config, accum?: Token[]);
45
+ /** 是否位于行首 */
46
+ isIndependent(): boolean;
47
+ getAttr<T extends string>(key: T): TdAttrGetter<T>;
48
+ /** @override */
49
+ json(): AST;
50
+ cloneNode(): this;
51
+ /** 改为独占一行 */
52
+ independence(): void;
53
+ getAttrs(): TdAttrs;
54
+ /**
55
+ * @override
56
+ * @param key 属性键
57
+ * @param value 属性值
58
+ * @param prop 属性对象
59
+ */
60
+ setAttr<T extends string>(key: T, value: TdAttrSetter<T>): void;
61
+ setAttr(prop: Record<string, string | number | boolean>): void;
62
+ }
63
+ /**
64
+ * 创建新的单元格
65
+ * @param inner 内部wikitext
66
+ * @param subtype 单元格类型
67
+ * @param attr 单元格属性
68
+ * @param include 是否嵌入
69
+ * @param config
70
+ */
71
+ export declare const createTd: (inner: string | Token, subtype?: TdSubtypes, attr?: TdAttrs, include?: boolean, config?: Parser.Config) => TdToken;
72
+ export {};