wikiparser-node 1.1.5 → 1.1.6-b

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