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