wikiparser-node 1.0.2-b → 1.0.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 (157) hide show
  1. package/README.en.md +57 -0
  2. package/README.md +5 -1
  3. package/config/.schema.json +160 -0
  4. package/config/llwiki.json +35 -1
  5. package/config/moegirl.json +44 -1
  6. package/config/zhwiki.json +466 -1
  7. package/dist/addon/table.d.ts +6 -0
  8. package/dist/addon/table.js +531 -0
  9. package/dist/bin/toc.js +18 -0
  10. package/dist/index.d.ts +60 -0
  11. package/dist/index.js +205 -0
  12. package/dist/internal.d.ts +44 -0
  13. package/dist/lib/element.d.ts +155 -0
  14. package/dist/lib/element.js +655 -0
  15. package/dist/lib/node.d.ts +143 -0
  16. package/dist/lib/node.js +419 -0
  17. package/dist/lib/range.d.ts +115 -0
  18. package/dist/lib/range.js +353 -0
  19. package/dist/lib/ranges.d.ts +28 -0
  20. package/dist/lib/ranges.js +120 -0
  21. package/dist/lib/text.d.ts +63 -0
  22. package/dist/lib/text.js +217 -0
  23. package/dist/lib/title.d.ts +26 -0
  24. package/dist/lib/title.js +125 -0
  25. package/dist/mixin/attributesParent.js +94 -0
  26. package/dist/mixin/fixed.js +32 -0
  27. package/dist/mixin/flagsParent.js +70 -0
  28. package/dist/mixin/hidden.js +22 -0
  29. package/dist/mixin/magicLinkParent.js +41 -0
  30. package/dist/mixin/singleLine.js +25 -0
  31. package/dist/mixin/sol.js +43 -0
  32. package/dist/mixin/syntax.js +56 -0
  33. package/dist/parser/braces.js +123 -0
  34. package/dist/parser/commentAndExt.js +65 -0
  35. package/dist/parser/converter.js +40 -0
  36. package/dist/parser/externalLinks.js +28 -0
  37. package/dist/parser/hrAndDoubleUnderscore.js +38 -0
  38. package/dist/parser/html.js +36 -0
  39. package/dist/parser/links.js +94 -0
  40. package/dist/parser/list.js +59 -0
  41. package/dist/parser/magicLinks.js +40 -0
  42. package/dist/parser/quotes.js +67 -0
  43. package/dist/parser/selector.js +163 -0
  44. package/dist/parser/table.js +110 -0
  45. package/dist/src/arg.d.ts +58 -0
  46. package/dist/src/arg.js +190 -0
  47. package/dist/src/atom.d.ts +12 -0
  48. package/dist/src/atom.js +27 -0
  49. package/dist/src/attribute.d.ts +86 -0
  50. package/dist/src/attribute.js +392 -0
  51. package/dist/src/attributes.d.ts +106 -0
  52. package/dist/src/attributes.js +339 -0
  53. package/dist/src/converter.d.ts +51 -0
  54. package/dist/src/converter.js +79 -0
  55. package/dist/src/converterFlags.d.ts +87 -0
  56. package/dist/src/converterFlags.js +223 -0
  57. package/dist/src/converterRule.d.ts +81 -0
  58. package/dist/src/converterRule.js +221 -0
  59. package/dist/src/extLink.d.ts +53 -0
  60. package/dist/src/extLink.js +121 -0
  61. package/dist/src/gallery.d.ts +55 -0
  62. package/dist/src/gallery.js +129 -0
  63. package/dist/src/heading.d.ts +76 -0
  64. package/dist/src/heading.js +127 -0
  65. package/dist/src/hidden.d.ts +21 -0
  66. package/dist/src/hidden.js +23 -0
  67. package/dist/src/html.d.ts +99 -0
  68. package/dist/src/html.js +230 -0
  69. package/dist/src/imageParameter.d.ts +66 -0
  70. package/dist/src/imageParameter.js +246 -0
  71. package/dist/src/imagemap.d.ts +57 -0
  72. package/dist/src/imagemap.js +148 -0
  73. package/dist/src/imagemapLink.d.ts +57 -0
  74. package/dist/src/imagemapLink.js +40 -0
  75. package/dist/src/index.d.ts +145 -0
  76. package/dist/src/index.js +766 -0
  77. package/dist/src/link/base.d.ts +52 -0
  78. package/dist/src/link/base.js +198 -0
  79. package/dist/src/link/category.d.ts +13 -0
  80. package/dist/src/link/category.js +29 -0
  81. package/dist/src/link/file.d.ts +96 -0
  82. package/dist/src/link/file.js +253 -0
  83. package/dist/src/link/galleryImage.d.ts +41 -0
  84. package/dist/src/link/galleryImage.js +98 -0
  85. package/dist/src/link/index.d.ts +53 -0
  86. package/dist/src/link/index.js +123 -0
  87. package/dist/src/magicLink.d.ts +58 -0
  88. package/dist/src/magicLink.js +122 -0
  89. package/dist/src/nested.d.ts +44 -0
  90. package/dist/src/nested.js +87 -0
  91. package/dist/src/nowiki/base.d.ts +46 -0
  92. package/dist/src/nowiki/base.js +42 -0
  93. package/dist/src/nowiki/comment.d.ts +39 -0
  94. package/dist/src/nowiki/comment.js +67 -0
  95. package/dist/src/nowiki/dd.d.ts +8 -0
  96. package/dist/src/nowiki/dd.js +25 -0
  97. package/dist/src/nowiki/doubleUnderscore.d.ts +43 -0
  98. package/dist/src/nowiki/doubleUnderscore.js +51 -0
  99. package/dist/src/nowiki/hr.d.ts +29 -0
  100. package/dist/src/nowiki/hr.js +14 -0
  101. package/dist/src/nowiki/index.d.ts +16 -0
  102. package/dist/src/nowiki/index.js +21 -0
  103. package/dist/src/nowiki/list.d.ts +29 -0
  104. package/dist/src/nowiki/list.js +47 -0
  105. package/dist/src/nowiki/listBase.d.ts +18 -0
  106. package/dist/src/nowiki/listBase.js +12 -0
  107. package/dist/src/nowiki/noinclude.d.ts +25 -0
  108. package/dist/src/nowiki/noinclude.js +25 -0
  109. package/dist/src/nowiki/quote.d.ts +22 -0
  110. package/dist/src/nowiki/quote.js +50 -0
  111. package/dist/src/onlyinclude.d.ts +16 -0
  112. package/dist/src/onlyinclude.js +57 -0
  113. package/dist/src/paramTag/index.d.ts +37 -0
  114. package/dist/src/paramTag/index.js +68 -0
  115. package/dist/src/paramTag/inputbox.d.ts +8 -0
  116. package/dist/src/paramTag/inputbox.js +23 -0
  117. package/dist/src/parameter.d.ts +82 -0
  118. package/dist/src/parameter.js +202 -0
  119. package/dist/src/pre.d.ts +28 -0
  120. package/dist/src/pre.js +51 -0
  121. package/dist/src/syntax.d.ts +25 -0
  122. package/dist/src/syntax.js +30 -0
  123. package/dist/src/table/base.d.ts +52 -0
  124. package/dist/src/table/base.js +78 -0
  125. package/dist/src/table/index.d.ts +229 -0
  126. package/dist/src/table/index.js +364 -0
  127. package/dist/src/table/td.d.ts +102 -0
  128. package/dist/src/table/td.js +261 -0
  129. package/dist/src/table/tr.d.ts +32 -0
  130. package/dist/src/table/tr.js +56 -0
  131. package/dist/src/table/trBase.d.ts +54 -0
  132. package/dist/src/table/trBase.js +151 -0
  133. package/dist/src/tagPair/ext.d.ts +55 -0
  134. package/dist/src/tagPair/ext.js +142 -0
  135. package/dist/src/tagPair/include.d.ts +52 -0
  136. package/dist/src/tagPair/include.js +58 -0
  137. package/dist/src/tagPair/index.d.ts +47 -0
  138. package/dist/src/tagPair/index.js +93 -0
  139. package/dist/src/transclude.d.ts +167 -0
  140. package/dist/src/transclude.js +694 -0
  141. package/dist/util/constants.js +108 -0
  142. package/dist/util/debug.js +63 -0
  143. package/dist/util/diff.js +72 -0
  144. package/dist/util/lint.js +48 -0
  145. package/dist/util/string.js +63 -0
  146. package/errors/README +1 -0
  147. package/i18n/zh-hans.json +2 -0
  148. package/i18n/zh-hant.json +2 -0
  149. package/package.json +12 -24
  150. package/printed/README +1 -0
  151. package/bundle/bundle.min.js +0 -37
  152. package/extensions/dist/base.js +0 -70
  153. package/extensions/dist/editor.js +0 -172
  154. package/extensions/dist/highlight.js +0 -39
  155. package/extensions/dist/lint.js +0 -48
  156. package/extensions/editor.css +0 -63
  157. package/extensions/ui.css +0 -119
@@ -0,0 +1,531 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Layout = void 0;
4
+ const assert = require("assert/strict");
5
+ const debug_1 = require("../util/debug");
6
+ const constants_1 = require("../util/constants");
7
+ const src_1 = require("../src");
8
+ const tr_1 = require("../src/table/tr");
9
+ const table_1 = require("../src/table");
10
+ const td_1 = require("../src/table/td");
11
+ const trBase_1 = require("../src/table/trBase");
12
+ /**
13
+ * 比较两个表格坐标
14
+ * @param coords1 坐标1
15
+ * @param coords2 坐标2
16
+ */
17
+ const cmpCoords = (coords1, coords2) => {
18
+ const diff = coords1.row - coords2.row;
19
+ return diff === 0 ? coords1.column - coords2.column : diff;
20
+ };
21
+ /**
22
+ * 是否是行尾
23
+ * @param {Token} cell 表格单元格
24
+ */
25
+ const isRowEnd = ({ type }) => type === 'tr' || type === 'table-syntax';
26
+ /**
27
+ * 是否是合并单元格的第一列
28
+ * @param rowLayout 行布局
29
+ * @param i 单元格序号
30
+ * @param oneCol 是否仅有一列
31
+ */
32
+ const isStartCol = (rowLayout, i, oneCol = false) => {
33
+ const coords = rowLayout[i];
34
+ return rowLayout[i - 1] !== coords && (!oneCol || rowLayout[i + 1] !== coords);
35
+ };
36
+ /**
37
+ * 设置表格格式
38
+ * @param cells 单元格
39
+ * @param attr 属性
40
+ * @param multi 是否对所有单元格设置,或是仅对行首单元格设置
41
+ */
42
+ const format = (cells, attr = {}, multi = false) => {
43
+ for (const [token, start] of cells) {
44
+ if (multi || start) {
45
+ if (typeof attr === 'string') {
46
+ token.setSyntax(attr);
47
+ }
48
+ else {
49
+ for (const [k, v] of Object.entries(attr)) {
50
+ token.setAttr(k, v);
51
+ }
52
+ }
53
+ }
54
+ }
55
+ };
56
+ /**
57
+ * 填补缺失单元格
58
+ * @param y 行号
59
+ * @param rowToken 表格行
60
+ * @param layout 表格布局
61
+ * @param maxCol 最大列数
62
+ * @param token 待填充的单元格
63
+ */
64
+ const fill = (y, rowToken, layout, maxCol, token) => {
65
+ const rowLayout = layout[y], lastIndex = rowToken.childNodes.findLastIndex(child => child instanceof td_1.TdToken && child.subtype !== 'caption'), pos = lastIndex + 1 || undefined;
66
+ debug_1.Shadow.run(() => {
67
+ for (let i = 0; i < maxCol; i++) {
68
+ if (!rowLayout[i]) {
69
+ rowToken.insertAt(token.cloneNode(), pos);
70
+ }
71
+ }
72
+ });
73
+ };
74
+ /** @extends {Array<TableCoords[]>} */
75
+ class Layout extends Array {
76
+ /** 打印表格布局 */
77
+ print() {
78
+ const hBorders = new Array(this.length + 1).fill(undefined).map((_, i) => {
79
+ const prev = this[i - 1] ?? [], next = this[i] ?? [];
80
+ return new Array(Math.max(prev.length, next.length)).fill(undefined)
81
+ .map((__, j) => prev[j] !== next[j]);
82
+ }), vBorders = this.map(cur => new Array(cur.length + 1).fill(undefined).map((_, j) => cur[j - 1] !== cur[j]));
83
+ let out = '';
84
+ for (let i = 0; i <= this.length; i++) {
85
+ const hBorder = hBorders[i].map(Number), vBorderTop = (vBorders[i - 1] ?? []).map(Number), vBorderBottom = (vBorders[i] ?? []).map(Number),
86
+ // eslint-disable-next-line no-sparse-arrays
87
+ border = [' ', , , '┌', , '┐', '─', '┬', , '│', '└', '├', '┘', '┤', '┴', '┼'];
88
+ for (let j = 0; j <= hBorder.length; j++) {
89
+ const bit = (vBorderTop[j] << 3) + (vBorderBottom[j] << 0)
90
+ + (hBorder[j - 1] << 2) + (hBorder[j] << 1);
91
+ out += `${border[bit]}${hBorder[j] ? '─' : ' '}`;
92
+ }
93
+ out += '\n';
94
+ }
95
+ console.log(out.slice(0, -1));
96
+ }
97
+ }
98
+ exports.Layout = Layout;
99
+ Object.assign(table_1.TableToken.prototype, {
100
+ /** @implements */
101
+ getNthCell(coords) {
102
+ const rawCoords = coords.row === undefined ? this.toRawCoords(coords) : coords;
103
+ return rawCoords && this.getNthRow(rawCoords.row, false, false)?.getNthCol(rawCoords.column);
104
+ },
105
+ /** @implements */
106
+ getLayout(stop) {
107
+ const rows = this.getAllRows(), { length } = rows, layout = new Layout(...new Array(length).fill(undefined).map(() => []));
108
+ for (let i = 0; i < length; i++) {
109
+ if (i > (stop?.row ?? stop?.y ?? NaN)) {
110
+ break;
111
+ }
112
+ const rowLayout = layout[i];
113
+ let j = 0, k = 0, last;
114
+ for (const cell of rows[i].childNodes.slice(2)) {
115
+ if (cell instanceof td_1.TdToken) {
116
+ if (cell.isIndependent()) {
117
+ last = cell.subtype !== 'caption';
118
+ }
119
+ if (last) {
120
+ const coords = { row: i, column: j }, { rowspan, colspan } = cell;
121
+ j++;
122
+ while (rowLayout[k]) {
123
+ k++;
124
+ }
125
+ if (i === stop?.row && j > (stop.column ?? NaN)) {
126
+ layout[i][k] = coords;
127
+ return layout;
128
+ }
129
+ for (let y = i; y < Math.min(i + rowspan, length); y++) {
130
+ for (let x = k; x < k + colspan; x++) {
131
+ layout[y][x] = coords;
132
+ }
133
+ }
134
+ k += colspan;
135
+ if (i === stop?.y && k > (stop.x ?? NaN)) {
136
+ return layout;
137
+ }
138
+ }
139
+ }
140
+ else if (isRowEnd(cell)) {
141
+ break;
142
+ }
143
+ }
144
+ }
145
+ return layout;
146
+ },
147
+ /** @implements */
148
+ printLayout() {
149
+ this.getLayout().print();
150
+ },
151
+ /** @implements */
152
+ toRenderedCoords({ row, column }) {
153
+ const rowLayout = this.getLayout({ row, column })[row], x = rowLayout?.findIndex(coords => cmpCoords(coords, { row, column }) === 0);
154
+ return rowLayout && (x === -1 ? undefined : { y: row, x: x });
155
+ },
156
+ /** @implements */
157
+ toRawCoords({ x, y }) {
158
+ const rowLayout = this.getLayout({ x, y })[y], coords = rowLayout?.[x];
159
+ if (coords) {
160
+ return { ...coords, start: coords.row === y && rowLayout[x - 1] !== coords };
161
+ }
162
+ else if (rowLayout || y > 0) {
163
+ return x === rowLayout?.length
164
+ ? { row: y, column: (rowLayout.findLast(({ row }) => row === y)?.column ?? -1) + 1, start: true }
165
+ : undefined;
166
+ }
167
+ return { row: 0, column: 0, start: true };
168
+ },
169
+ /** @implements */
170
+ getFullRow(y) {
171
+ const rows = this.getAllRows();
172
+ return new Map(this.getLayout({ y })[y]?.map(({ row, column }) => [rows[row].getNthCol(column), row === y]));
173
+ },
174
+ /** @implements */
175
+ getFullCol(x) {
176
+ const layout = this.getLayout(), colLayout = layout.map(row => row[x]).filter(Boolean), rows = this.getAllRows();
177
+ return new Map(colLayout.map(coords => [rows[coords.row].getNthCol(coords.column), layout[coords.row][x - 1] !== coords]));
178
+ },
179
+ /** @implements */
180
+ formatTableRow(y, attr = {}, multiRow = false) {
181
+ format(this.getFullRow(y), attr, multiRow);
182
+ },
183
+ /** @implements */
184
+ formatTableCol(x, attr = {}, multiCol = false) {
185
+ format(this.getFullCol(x), attr, multiCol);
186
+ },
187
+ /** @implements */
188
+ fillTableRow(y, inner, subtype = 'td', attr = {}) {
189
+ const rowToken = this.getNthRow(y), layout = this.getLayout({ y }), maxCol = Math.max(...layout.map(({ length }) => length)), token = (0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
190
+ fill(y, rowToken, layout, maxCol, token);
191
+ },
192
+ /** @implements */
193
+ fillTable(inner, subtype = 'td', attr = {}) {
194
+ const rowTokens = this.getAllRows(), layout = this.getLayout(), maxCol = Math.max(...layout.map(({ length }) => length)), token = (0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
195
+ for (let y = 0; y < rowTokens.length; y++) {
196
+ fill(y, rowTokens[y], layout, maxCol, token);
197
+ }
198
+ },
199
+ /** @implements */
200
+ insertTableCell(inner, coords, subtype = 'td', attr = {}) {
201
+ let rawCoords;
202
+ if (coords.column === undefined) {
203
+ const { x, y } = coords;
204
+ rawCoords = this.toRawCoords(coords);
205
+ if (!rawCoords?.start) {
206
+ throw new RangeError(`指定的坐标不是单元格起始点:(${x}, ${y})`);
207
+ }
208
+ }
209
+ else {
210
+ rawCoords = coords;
211
+ }
212
+ const rowToken = this.getNthRow(rawCoords.row, true);
213
+ return rowToken === this
214
+ ? trBase_1.TrBaseToken.prototype.insertTableCell.call(this, inner, rawCoords, subtype, attr)
215
+ : rowToken.insertTableCell(inner, rawCoords, subtype, attr);
216
+ },
217
+ /** @implements */
218
+ prependTableRow() {
219
+ const row = debug_1.Shadow.run(() => new tr_1.TrToken('\n|-', undefined, this.getAttribute('config'))), { childNodes } = this, [, , plain] = childNodes, start = plain?.constructor === src_1.Token ? 3 : 2, tdChildren = childNodes.slice(start), index = tdChildren.findIndex(({ type }) => type !== 'td');
220
+ this.insertAt(row, index === -1 ? -1 : index + start);
221
+ debug_1.Shadow.run(() => {
222
+ for (const cell of tdChildren.slice(0, index === -1 ? undefined : index)) {
223
+ if (cell.subtype !== 'caption') {
224
+ row.insertAt(cell);
225
+ }
226
+ }
227
+ });
228
+ return row;
229
+ },
230
+ /** @implements */
231
+ insertTableRow(y, attr = {}, inner, subtype = 'td', innerAttr = {}) {
232
+ let reference = this.getNthRow(y, false, true);
233
+ const token = debug_1.Shadow.run(() => new tr_1.TrToken('\n|-', undefined, this.getAttribute('config')));
234
+ for (const [k, v] of Object.entries(attr)) {
235
+ token.setAttr(k, v);
236
+ }
237
+ if (reference?.type === 'table') { // `row === 0`且表格自身是有效行
238
+ reference = this.prependTableRow();
239
+ }
240
+ this.insertBefore(token, reference);
241
+ if (inner !== undefined) {
242
+ const td = token.insertTableCell(inner, { row: 0, column: 0 }, subtype, innerAttr), set = new WeakSet(), layout = this.getLayout({ y }), maxCol = Math.max(...layout.map(({ length }) => length)), rowLayout = layout[y];
243
+ debug_1.Shadow.run(() => {
244
+ for (let i = 0; i < maxCol; i++) {
245
+ const coords = rowLayout[i];
246
+ if (!coords) {
247
+ token.insertAt(td.cloneNode());
248
+ }
249
+ else if (!set.has(coords)) {
250
+ set.add(coords);
251
+ if (coords.row < y) {
252
+ this.getNthCell(coords).rowspan++;
253
+ }
254
+ }
255
+ }
256
+ });
257
+ }
258
+ return token;
259
+ },
260
+ /** @implements */
261
+ insertTableCol(x, inner, subtype = 'td', attr = {}) {
262
+ const layout = this.getLayout(), rowLength = layout.map(({ length }) => length), minCol = Math.min(...rowLength);
263
+ if (x > minCol) {
264
+ throw new RangeError(`表格第 ${rowLength.indexOf(minCol)} 行仅有 ${minCol} 列!`);
265
+ }
266
+ const token = (0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
267
+ for (let i = 0; i < layout.length; i++) {
268
+ const coords = layout[i][x], prevCoords = x === 0 ? true : layout[i][x - 1];
269
+ if (!prevCoords) {
270
+ continue;
271
+ }
272
+ else if (prevCoords !== coords) {
273
+ const rowToken = this.getNthRow(i);
274
+ rowToken.insertBefore(token.cloneNode(), rowToken.getNthCol(coords.column, true));
275
+ }
276
+ else if (coords.row === i) {
277
+ this.getNthCell(coords).colspan++;
278
+ }
279
+ }
280
+ },
281
+ /** @implements */
282
+ removeTableRow(y) {
283
+ const rows = this.getAllRows(), layout = this.getLayout(), rowLayout = layout[y], set = new WeakSet();
284
+ for (let x = rowLayout.length - 1; x >= 0; x--) {
285
+ const coords = rowLayout[x];
286
+ if (set.has(coords)) {
287
+ continue;
288
+ }
289
+ set.add(coords);
290
+ const token = rows[coords.row].getNthCol(coords.column);
291
+ let { rowspan } = token;
292
+ if (rowspan > 1) {
293
+ token.rowspan = --rowspan;
294
+ if (coords.row === y) {
295
+ const { colspan, subtype } = token, attr = token.getAttrs();
296
+ for (let i = y + 1; rowspan && i < rows.length; i++, rowspan--) {
297
+ const { column } = layout[i].slice(x + colspan).find(({ row }) => row === i) ?? {};
298
+ if (column !== undefined) {
299
+ rows[i].insertTableCell('', { row: 0, column }, subtype, { ...attr, rowspan });
300
+ break;
301
+ }
302
+ }
303
+ }
304
+ }
305
+ }
306
+ const rowToken = rows[y].type === 'table' ? this.prependTableRow() : rows[y];
307
+ rowToken.remove();
308
+ return rowToken;
309
+ },
310
+ /** @implements */
311
+ removeTableCol(x) {
312
+ for (const [token, start] of this.getFullCol(x)) {
313
+ const { colspan, lastChild } = token;
314
+ if (colspan > 1) {
315
+ token.colspan = colspan - 1;
316
+ if (start) {
317
+ lastChild.replaceChildren();
318
+ }
319
+ }
320
+ else {
321
+ token.remove();
322
+ }
323
+ }
324
+ },
325
+ /** @implements */
326
+ mergeCells(xlim, ylim) {
327
+ const layout = this.getLayout(), maxCol = Math.max(...layout.map(({ length }) => length)), posXlim = xlim.map(x => x < 0 ? x + maxCol : x), posYlim = ylim.map(y => y < 0 ? y + layout.length : y), [xmin, xmax] = posXlim.sort(), [ymin, ymax] = posYlim.sort(), set = new Set(layout.slice(ymin, ymax).flatMap(rowLayout => rowLayout.slice(xmin, xmax)));
328
+ if ([...layout[ymin - 1] ?? [], ...layout[ymax] ?? []].some(coords => set.has(coords))
329
+ || layout.some(rowLayout => set.has(rowLayout[xmin - 1]) || set.has(rowLayout[xmax]))) {
330
+ throw new RangeError('待合并区域与外侧区域有重叠!');
331
+ }
332
+ const corner = layout[ymin][xmin], rows = this.getAllRows(), cornerCell = rows[corner.row].getNthCol(corner.column);
333
+ cornerCell.rowspan = ymax - ymin;
334
+ cornerCell.colspan = xmax - xmin;
335
+ set.delete(corner);
336
+ for (const token of [...set].map(({ row, column }) => rows[row].getNthCol(column))) {
337
+ token.remove();
338
+ }
339
+ return cornerCell;
340
+ },
341
+ /** @implements */
342
+ split(coords, dirs) {
343
+ const cell = this.getNthCell(coords), attr = cell.getAttrs(), { subtype } = cell;
344
+ attr.rowspan ||= 1;
345
+ attr.colspan ||= 1;
346
+ for (const dir of dirs) {
347
+ if (attr[dir] === 1) {
348
+ dirs.delete(dir);
349
+ }
350
+ }
351
+ if (dirs.size === 0) {
352
+ return;
353
+ }
354
+ let { x, y } = coords;
355
+ const rawCoords = x === undefined ? coords : this.toRawCoords(coords);
356
+ if (rawCoords.start === false || x === undefined) {
357
+ ({ x, y } = this.toRenderedCoords(rawCoords));
358
+ }
359
+ const splitting = { rowspan: 1, colspan: 1 };
360
+ for (const dir of dirs) {
361
+ cell.setAttr(dir, 1);
362
+ splitting[dir] = attr[dir];
363
+ delete attr[dir];
364
+ }
365
+ for (let j = y; j < y + splitting.rowspan; j++) {
366
+ for (let i = x; i < x + splitting.colspan; i++) {
367
+ if (i > x || j > y) {
368
+ try {
369
+ this.insertTableCell('', { x: i, y: j }, subtype, attr);
370
+ }
371
+ catch (e) {
372
+ if (e instanceof RangeError && e.message.startsWith('指定的坐标不是单元格起始点:')) {
373
+ break;
374
+ }
375
+ throw e;
376
+ }
377
+ }
378
+ }
379
+ }
380
+ },
381
+ /** @implements */
382
+ splitIntoRows(coords) {
383
+ this.split(coords, new Set(['rowspan']));
384
+ },
385
+ /** @implements */
386
+ splitIntoCols(coords) {
387
+ this.split(coords, new Set(['colspan']));
388
+ },
389
+ /** @implements */
390
+ splitIntoCells(coords) {
391
+ this.split(coords, new Set(['rowspan', 'colspan']));
392
+ },
393
+ /** @implements */
394
+ replicateTableRow(row) {
395
+ let rowToken = this.getNthRow(row);
396
+ if (rowToken.type === 'table') {
397
+ rowToken = this.prependTableRow();
398
+ }
399
+ const replicated = this.insertBefore(rowToken.cloneNode(), rowToken);
400
+ for (const [token, start] of this.getFullRow(row)) {
401
+ if (start) {
402
+ token.rowspan = 1;
403
+ }
404
+ else {
405
+ token.rowspan++;
406
+ }
407
+ }
408
+ return replicated;
409
+ },
410
+ /** @implements */
411
+ replicateTableCol(x) {
412
+ const replicated = [];
413
+ for (const [token, start] of this.getFullCol(x)) {
414
+ if (start) {
415
+ const newToken = token.cloneNode();
416
+ newToken.colspan = 1;
417
+ token.before(newToken);
418
+ replicated.push(newToken);
419
+ }
420
+ else {
421
+ token.colspan++;
422
+ }
423
+ }
424
+ return replicated;
425
+ },
426
+ /** @implements */
427
+ moveTableRowBefore(y, before) {
428
+ const layout = this.getLayout(),
429
+ /** @ignore */
430
+ occupied = (i) => layout[i].map(({ row }, j) => row === i ? j : undefined).filter(j => j !== undefined);
431
+ try {
432
+ assert.deepEqual(occupied(y), occupied(before));
433
+ }
434
+ catch (e) {
435
+ if (e instanceof assert.AssertionError) {
436
+ throw new RangeError(`第 ${y} 行与第 ${before} 行的构造不同,无法移动!`);
437
+ }
438
+ throw e;
439
+ }
440
+ const rowToken = this.removeTableRow(y);
441
+ for (const coords of layout[before]) {
442
+ if (coords.row < before) {
443
+ this.getNthCell(coords).rowspan++;
444
+ }
445
+ }
446
+ let beforeToken = this.getNthRow(before);
447
+ if (beforeToken.type === 'table') {
448
+ beforeToken = this.prependTableRow();
449
+ }
450
+ this.insertBefore(rowToken, beforeToken);
451
+ return rowToken;
452
+ },
453
+ /** @implements */
454
+ moveTableRowAfter(y, after) {
455
+ const layout = this.getLayout(), afterToken = this.getNthRow(after), cells = afterToken.childNodes.filter(child => child instanceof td_1.TdToken && child.subtype !== 'caption'),
456
+ /** @ignore */
457
+ occupied = (i, oneRow = false) => layout[i].map(({ row, column }, j) => row === i && (!oneRow || cells[column].rowspan === 1) ? j : undefined).filter(j => j !== undefined);
458
+ try {
459
+ assert.deepEqual(occupied(y), occupied(after, true));
460
+ }
461
+ catch (e) {
462
+ if (e instanceof assert.AssertionError) {
463
+ throw new RangeError(`第 ${y} 行与第 ${after} 行的构造不同,无法移动!`);
464
+ }
465
+ throw e;
466
+ }
467
+ const rowToken = this.removeTableRow(y);
468
+ for (const coords of layout[after]) {
469
+ if (coords.row < after) {
470
+ this.getNthCell(coords).rowspan++;
471
+ }
472
+ else {
473
+ const cell = cells[coords.column], { rowspan } = cell;
474
+ if (rowspan > 1) {
475
+ cell.rowspan = rowspan + 1;
476
+ }
477
+ }
478
+ }
479
+ if (afterToken === this) {
480
+ const index = this.childNodes.slice(2).findIndex(isRowEnd);
481
+ this.insertAt(rowToken, index + 2);
482
+ }
483
+ else {
484
+ this.insertBefore(rowToken, afterToken);
485
+ }
486
+ return rowToken;
487
+ },
488
+ /** @implements */
489
+ moveCol(x, reference, after = false) {
490
+ const layout = this.getLayout();
491
+ if (layout.some(rowLayout => isStartCol(rowLayout, x) !== isStartCol(rowLayout, reference, after))) {
492
+ throw new RangeError(`第 ${x} 列与第 ${reference} 列的构造不同,无法移动!`);
493
+ }
494
+ const setX = new WeakSet(), setRef = new WeakSet(), rows = this.getAllRows();
495
+ for (let i = 0; i < layout.length; i++) {
496
+ const rowLayout = layout[i], coords = rowLayout[x], refCoords = rowLayout[reference], start = isStartCol(rowLayout, x);
497
+ if (refCoords && !start && !setRef.has(refCoords)) {
498
+ setRef.add(refCoords);
499
+ rows[refCoords.row].getNthCol(refCoords.column).colspan++;
500
+ }
501
+ if (coords && !setX.has(coords)) {
502
+ setX.add(coords);
503
+ const rowToken = rows[i];
504
+ let token = rowToken.getNthCol(coords.column);
505
+ const { colspan } = token;
506
+ if (colspan > 1) {
507
+ token.colspan = colspan - 1;
508
+ if (start) {
509
+ const original = token;
510
+ token = token.cloneNode();
511
+ original.lastChild.replaceChildren();
512
+ token.colspan = 1;
513
+ }
514
+ }
515
+ if (start) {
516
+ const col = rowLayout.slice(reference + Number(after)).find(({ row }) => row === i)?.column;
517
+ rowToken.insertBefore(token, col === undefined ? rowToken.childNodes.slice(2).find(isRowEnd) : rowToken.getNthCol(col));
518
+ }
519
+ }
520
+ }
521
+ },
522
+ /** @implements */
523
+ moveTableColBefore(x, before) {
524
+ this.moveCol(x, before);
525
+ },
526
+ /** @implements */
527
+ moveTableColAfter(x, after) {
528
+ this.moveCol(x, after, true);
529
+ },
530
+ });
531
+ constants_1.classes['ExtendTableToken'] = __filename;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { argv: [, , filename] } = process;
6
+ if (!filename) {
7
+ throw new RangeError('请指定文档文件!');
8
+ }
9
+ const fullpath = path.join(__dirname, '..', '..', 'wiki', `${filename}.md`), isEnglish = filename.endsWith('.en');
10
+ if (!fs.existsSync(fullpath)) {
11
+ throw new RangeError(`文档 ${filename}.md 不存在!`);
12
+ }
13
+ const content = fs.readFileSync(fullpath, 'utf8');
14
+ if (/^- \[[^\]]+\]\(#[^)]+\)$/mu.test(content)) {
15
+ throw new Error(`文档 ${filename}.md 中已包含目录!`);
16
+ }
17
+ const toc = content.split('\n').filter(line => line.startsWith('#')).map(line => line.replace(/^(#+)\s+(\S.*)$/u, (_, { length }, title) => `${'\t'.repeat(length - 1)}- [${title}](#${title.toLowerCase().replaceAll(' ', '-').replaceAll('.', '')})`)).join('\n');
18
+ fs.writeFileSync(fullpath, `<details>\n\t<summary>${isEnglish ? 'Table of Contents' : '目录'}</summary>\n\n${toc}\n</details>\n\n# Other Languages\n\n- [${isEnglish ? '简体中文' : 'English'}](./${isEnglish ? filename.slice(0, -3) : `${filename}.en`})\n\n${content}`);
@@ -0,0 +1,60 @@
1
+ import type { Title } from './lib/title';
2
+ import type { Token } from './internal';
3
+ export interface Config {
4
+ ext: string[];
5
+ html: [string[], string[], string[]];
6
+ namespaces: Record<string, string>;
7
+ nsid: Record<string, number>;
8
+ parserFunction: [Record<string, string>, string[], string[], string[]];
9
+ doubleUnderscore: [string[], string[]];
10
+ protocol: string;
11
+ img: Record<string, string>;
12
+ variants: string[];
13
+ interwiki: string[];
14
+ excludes?: string[];
15
+ conversionTable?: [string, string][];
16
+ redirects?: [string, string][];
17
+ }
18
+ export interface LintError {
19
+ message: string;
20
+ severity: 'error' | 'warning';
21
+ startIndex: number;
22
+ endIndex: number;
23
+ startLine: number;
24
+ startCol: number;
25
+ endLine: number;
26
+ endCol: number;
27
+ excerpt: string;
28
+ }
29
+ declare interface Parser {
30
+ config: string | Config;
31
+ i18n: string | Record<string, string> | undefined;
32
+ conversionTable: Map<string, string>;
33
+ redirects: Map<string, string>;
34
+ warning: boolean;
35
+ debugging: boolean;
36
+ /**
37
+ * 规范化页面标题
38
+ * @param title 标题(含或不含命名空间前缀)
39
+ * @param defaultNs 命名空间
40
+ * @param include 是否嵌入
41
+ * @param halfParsed 是否是半解析状态
42
+ * @param decode 是否需要解码
43
+ * @param selfLink 是否允许selfLink
44
+ */
45
+ normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): Title;
46
+ /**
47
+ * 解析wikitext
48
+ * @param include 是否嵌入
49
+ * @param maxStage 最大解析层级
50
+ */
51
+ parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): Token;
52
+ /**
53
+ * 是否是跨维基链接
54
+ * @param title 链接标题
55
+ */
56
+ isInterwiki(title: string, config?: Config): [string, string] | null;
57
+ }
58
+ declare const Parser: Parser;
59
+ export = Parser;
60
+ export type * from './internal';