wikiparser-node 1.8.0-b → 1.8.0

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