wikiparser-node 1.32.0 → 1.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +7 -0
  2. package/bundle/bundle-es8.min.js +28 -28
  3. package/bundle/bundle-lsp.min.js +29 -29
  4. package/bundle/bundle.min.js +24 -24
  5. package/coverage/badge.svg +1 -1
  6. package/dist/addon/attribute.js +27 -7
  7. package/dist/addon/link.js +15 -16
  8. package/dist/addon/table.js +139 -103
  9. package/dist/addon/token.js +3 -1
  10. package/dist/base.d.mts +1 -1
  11. package/dist/base.d.ts +1 -1
  12. package/dist/base.js +1 -0
  13. package/dist/base.mjs +1 -0
  14. package/dist/bin/config.js +1 -1
  15. package/dist/index.js +10 -10
  16. package/dist/internal.d.ts +3 -0
  17. package/dist/lib/lintConfig.js +8 -0
  18. package/dist/lib/lsp.js +20 -3
  19. package/dist/lib/node.js +3 -11
  20. package/dist/lib/text.js +18 -18
  21. package/dist/lib/title.js +8 -10
  22. package/dist/render/magicWords.js +13 -6
  23. package/dist/src/attribute.d.ts +4 -6
  24. package/dist/src/attribute.js +15 -11
  25. package/dist/src/attributes.d.ts +2 -2
  26. package/dist/src/attributes.js +11 -6
  27. package/dist/src/converterFlags.js +5 -7
  28. package/dist/src/imageParameter.d.ts +7 -3
  29. package/dist/src/imageParameter.js +15 -5
  30. package/dist/src/index.d.ts +8 -0
  31. package/dist/src/index.js +34 -21
  32. package/dist/src/link/base.d.ts +1 -1
  33. package/dist/src/link/base.js +12 -5
  34. package/dist/src/link/categorytree.d.ts +25 -0
  35. package/dist/src/link/categorytree.js +126 -0
  36. package/dist/src/link/file.d.ts +3 -2
  37. package/dist/src/link/file.js +4 -3
  38. package/dist/src/link/galleryImage.js +6 -7
  39. package/dist/src/multiLine/gallery.d.ts +1 -4
  40. package/dist/src/multiLine/gallery.js +1 -11
  41. package/dist/src/multiLine/imagemap.d.ts +0 -1
  42. package/dist/src/multiLine/imagemap.js +98 -152
  43. package/dist/src/multiLine/index.d.ts +1 -0
  44. package/dist/src/multiLine/index.js +77 -22
  45. package/dist/src/multiLine/inputbox.d.ts +3 -3
  46. package/dist/src/multiLine/inputbox.js +3 -7
  47. package/dist/src/multiLine/paramTag.d.ts +3 -4
  48. package/dist/src/multiLine/paramTag.js +6 -48
  49. package/dist/src/nowiki/index.d.ts +1 -1
  50. package/dist/src/nowiki/index.js +59 -13
  51. package/dist/src/nowiki/list.d.ts +0 -1
  52. package/dist/src/nowiki/list.js +1 -0
  53. package/dist/src/nowiki/noinclude.d.ts +0 -1
  54. package/dist/src/nowiki/noinclude.js +1 -0
  55. package/dist/src/nowiki/quote.d.ts +0 -4
  56. package/dist/src/nowiki/quote.js +4 -0
  57. package/dist/src/paramLine.d.ts +3 -0
  58. package/dist/src/paramLine.js +45 -7
  59. package/dist/src/parameter.js +5 -7
  60. package/dist/src/table/base.d.ts +1 -2
  61. package/dist/src/table/base.js +7 -8
  62. package/dist/src/table/index.d.ts +2 -3
  63. package/dist/src/table/index.js +4 -41
  64. package/dist/src/table/td.d.ts +0 -1
  65. package/dist/src/table/td.js +1 -0
  66. package/dist/src/table/tr.d.ts +1 -1
  67. package/dist/src/tag/html.d.ts +0 -1
  68. package/dist/src/tag/html.js +1 -0
  69. package/dist/src/tag/tvar.d.ts +0 -1
  70. package/dist/src/tag/tvar.js +1 -0
  71. package/dist/src/tagPair/ext.js +19 -10
  72. package/dist/src/tagPair/index.d.ts +4 -2
  73. package/dist/src/tagPair/index.js +47 -7
  74. package/dist/src/tagPair/translate.d.ts +1 -1
  75. package/dist/src/tagPair/translate.js +3 -1
  76. package/dist/src/transclude.js +2 -2
  77. package/dist/util/debug.js +10 -3
  78. package/dist/util/diff.js +6 -17
  79. package/dist/util/html.js +1 -0
  80. package/dist/util/sharable.d.mts +1 -0
  81. package/dist/util/sharable.js +62 -1
  82. package/dist/util/sharable.mjs +62 -0
  83. package/extensions/dist/base.js +1 -1
  84. package/extensions/typings.d.ts +40 -0
  85. package/extensions/ui.css +1 -1
  86. package/i18n/en.json +2 -0
  87. package/i18n/zh-hans.json +2 -0
  88. package/i18n/zh-hant.json +2 -0
  89. package/logo.png +0 -0
  90. package/package.json +7 -6
@@ -1 +1 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="98" height="20" role="img" aria-label="Coverage: 87%"><title>Coverage: 87%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="98" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="63" height="20" fill="#555"/><rect x="63" width="35" height="20" fill="#4c1"/><rect width="98" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="325" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="530">Coverage</text><text x="325" y="140" transform="scale(.1)" fill="#fff" textLength="530">Coverage</text><text aria-hidden="true" x="795" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">87%</text><text x="795" y="140" transform="scale(.1)" fill="#fff" textLength="250">87%</text></g></svg>
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="98" height="20" role="img" aria-label="Coverage: 88%"><title>Coverage: 88%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="98" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="63" height="20" fill="#555"/><rect x="63" width="35" height="20" fill="#4c1"/><rect width="98" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="325" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="530">Coverage</text><text x="325" y="140" transform="scale(.1)" fill="#fff" textLength="530">Coverage</text><text aria-hidden="true" x="795" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">88%</text><text x="795" y="140" transform="scale(.1)" fill="#fff" textLength="250">88%</text></g></svg>
@@ -24,6 +24,7 @@ attribute_1.AttributeToken.prototype.setValue =
24
24
  return;
25
25
  }
26
26
  const { type, lastChild } = this;
27
+ /* istanbul ignore next */
27
28
  if (type === 'ext-attr' && value.includes('>')) {
28
29
  throw new RangeError('Attributes of an extension tag cannot contain ">"!');
29
30
  }
@@ -32,6 +33,7 @@ attribute_1.AttributeToken.prototype.setValue =
32
33
  }
33
34
  const { childNodes } = index_1.default.parseWithRef(value, this, attribute_1.stages[type] + 1);
34
35
  lastChild.safeReplaceChildren(childNodes);
36
+ this.setAttribute('equal', this.isInside('parameter') ? '{{=}}' : '=');
35
37
  if (value.includes('"')) {
36
38
  this.setAttribute('quotes', [`'`, `'`]);
37
39
  }
@@ -46,6 +48,7 @@ attribute_1.AttributeToken.prototype.rename =
46
48
  /** @implements */
47
49
  function (key) {
48
50
  const { type, name, tag, firstChild } = this;
51
+ /* istanbul ignore if */
49
52
  if (name === 'title' || name === 'alt' && tag === 'img') {
50
53
  throw new Error(`${name} attribute cannot be renamed!`);
51
54
  }
@@ -56,17 +59,19 @@ attribute_1.AttributeToken.prototype.css =
56
59
  /** @implements */
57
60
  function (key, value) {
58
61
  const { name, lastChild } = this;
62
+ /* istanbul ignore next */
59
63
  if (name !== 'style') {
60
64
  throw new Error('Not a style attribute!');
61
65
  }
62
- else if (lastChild.length !== 1 || lastChild.firstChild.type !== 'text') {
66
+ else if (lastChild.length > 1 || lastChild.length === 1 && lastChild.firstChild.type !== 'text') {
63
67
  throw new Error('Complex style attribute!');
64
68
  }
65
69
  const cssLSP = (0, document_1.loadCssLSP)();
70
+ /* istanbul ignore if */
66
71
  if (!cssLSP) {
67
72
  throw new Error('CSS language service is not available!');
68
73
  }
69
- const doc = new document_1.EmbeddedCSSDocument(this.getRootNode(), lastChild), styleSheet = doc.styleSheet, { children: [{ declarations }] } = styleSheet, declaration = declarations.children?.filter(({ property }) => property.getText() === key) ?? [];
74
+ const doc = new document_1.EmbeddedCSSDocument(this.getRootNode(), lastChild), styleSheet = doc.styleSheet, { children: [{ declarations: { children } }] } = styleSheet, declaration = children?.filter(({ property }) => property.getText() === key) ?? [];
70
75
  if (value === undefined) {
71
76
  return declaration.at(-1)?.value.getText();
72
77
  }
@@ -75,7 +80,7 @@ attribute_1.AttributeToken.prototype.css =
75
80
  }
76
81
  const style = styleSheet.getText().slice(0, -1);
77
82
  if (!value) {
78
- if (declaration.length === declarations.children?.length) {
83
+ if (declaration.length === children?.length) {
79
84
  this.setValue('');
80
85
  }
81
86
  else if (declaration.length > 0) {
@@ -90,6 +95,7 @@ attribute_1.AttributeToken.prototype.css =
90
95
  return undefined;
91
96
  }
92
97
  const hasQuote = value.includes('"'), [quot] = this.getAttribute('quotes');
98
+ /* istanbul ignore next */
93
99
  if (quot && value.includes(quot) || hasQuote && value.includes(`'`)) {
94
100
  const quote = quot || '"';
95
101
  throw new RangeError(`Please consider replacing \`${quote}\` with \`${quote === '"' ? `'` : '"'}\`!`);
@@ -99,19 +105,25 @@ attribute_1.AttributeToken.prototype.css =
99
105
  this.setValue(style.slice(doc.pre.length, offset) + value + style.slice(offset + length));
100
106
  }
101
107
  else {
102
- this.setValue(`${style.slice(doc.pre.length)}${/;\s*$/u.test(style) ? '' : '; '}${key}: ${value}`);
108
+ this.setValue(`${style.slice(doc.pre.length)}${!children?.length || /;\s*$/u.test(style) ? '' : '; '}${key}: ${value}`);
103
109
  }
104
110
  return undefined;
105
111
  };
106
112
  attributes_1.AttributesToken.prototype.sanitize =
107
113
  /** @implements */
108
114
  function () {
115
+ const type = (0, attributes_1.toAttributeType)(this.type);
109
116
  let dirty = false;
110
117
  for (let i = this.length - 1; i >= 0; i--) {
111
118
  const child = this.childNodes[i];
112
119
  if (child instanceof atom_1.AtomToken && child.text().trim()) {
113
120
  dirty = true;
114
- this.removeAt(i);
121
+ if (child.previousSibling?.is(type) && child.nextSibling?.is(type)) {
122
+ child.replaceChildren(' ');
123
+ }
124
+ else {
125
+ this.removeAt(i);
126
+ }
115
127
  }
116
128
  }
117
129
  if (!debug_1.Shadow.running && dirty) {
@@ -128,6 +140,7 @@ attributes_1.AttributesToken.prototype.setAttr =
128
140
  return;
129
141
  }
130
142
  const { type, name } = this;
143
+ /* istanbul ignore if */
131
144
  if (type === 'ext-attrs' && typeof value === 'string' && value.includes('>')) {
132
145
  throw new RangeError('Attributes of an extension tag cannot contain ">"!');
133
146
  }
@@ -140,7 +153,7 @@ attributes_1.AttributesToken.prototype.setAttr =
140
153
  return;
141
154
  }
142
155
  // @ts-expect-error abstract class
143
- const token = debug_1.Shadow.run(() => new attribute_1.AttributeToken((0, attributes_1.toAttributeType)(type), name, key, value === true ? '' : '=', value === true ? '' : value, ['"', '"'], this.getAttribute('config')));
156
+ const token = debug_1.Shadow.run(() => new attribute_1.AttributeToken((0, attributes_1.toAttributeType)(type), name, key, ['"', '"'], this.getAttribute('config'), value === true ? '' : '=', value === true ? '' : value));
144
157
  this.insertAt(token);
145
158
  };
146
159
  attributes_1.AttributesToken.prototype.toggleAttr =
@@ -148,6 +161,7 @@ attributes_1.AttributesToken.prototype.toggleAttr =
148
161
  function (key, force) {
149
162
  key = (0, string_1.trimLc)(key);
150
163
  const attr = this.getAttrToken(key);
164
+ /* istanbul ignore if */
151
165
  if (attr && attr.getValue() !== true) {
152
166
  throw new RangeError(`${key} attribute is not Boolean!`);
153
167
  }
@@ -161,6 +175,12 @@ attributes_1.AttributesToken.prototype.toggleAttr =
161
175
  attributes_1.AttributesToken.prototype.css =
162
176
  /** @implements */
163
177
  function (key, value) {
164
- return this.getAttrToken('style')?.css(key, value);
178
+ let attr = this.getAttrToken('style');
179
+ if (!attr) {
180
+ // @ts-expect-error abstract class
181
+ const token = debug_1.Shadow.run(() => new attribute_1.AttributeToken((0, attributes_1.toAttributeType)(this.type), this.name, 'style', [], this.getAttribute('config')));
182
+ attr = this.insertAt(token);
183
+ }
184
+ return attr.css(key, value);
165
185
  };
166
186
  constants_1.classes['ExtendedAttributeToken'] = __filename;
@@ -8,8 +8,9 @@ const constants_1 = require("../util/constants");
8
8
  const debug_1 = require("../util/debug");
9
9
  const string_1 = require("../util/string");
10
10
  const index_1 = __importDefault(require("../index"));
11
+ const index_2 = require("../src/index");
11
12
  const base_1 = require("../src/link/base");
12
- const index_2 = require("../src/link/index");
13
+ const index_3 = require("../src/link/index");
13
14
  const atom_1 = require("../src/atom");
14
15
  base_1.LinkBaseToken.prototype.setTarget =
15
16
  /** @implements */
@@ -30,24 +31,22 @@ base_1.LinkBaseToken.prototype.setFragment =
30
31
  base_1.LinkBaseToken.prototype.setLinkText =
31
32
  /** @implements */
32
33
  function (linkStr) {
33
- const { childNodes, lastChild, length } = this;
34
34
  if (linkStr === undefined) {
35
- childNodes[1]?.remove();
35
+ this.childNodes[1]?.remove();
36
36
  return;
37
37
  }
38
- const root = index_1.default.parseWithRef(linkStr, this);
39
- if (length === 1) {
40
- root.type = 'link-text';
41
- root.setAttribute('acceptable', {
42
- 'Stage-5': ':', QuoteToken: ':', ConverterToken: ':',
43
- });
44
- this.insertAt(root);
45
- }
46
- else {
47
- lastChild.safeReplaceChildren(root.childNodes);
38
+ else if (this.length === 1) {
39
+ this.insertAt(debug_1.Shadow.run(() => {
40
+ const inner = new index_2.Token(undefined, this.getAttribute('config'), [], {
41
+ 'Stage-5': ':', QuoteToken: ':', ConverterToken: ':',
42
+ });
43
+ inner.type = 'link-text';
44
+ return inner;
45
+ }));
48
46
  }
47
+ this.lastChild.safeReplaceChildren(index_1.default.parseWithRef(linkStr, this).childNodes);
49
48
  };
50
- index_2.LinkToken.prototype.setLangLink =
49
+ index_3.LinkToken.prototype.setLangLink =
51
50
  /** @implements */
52
51
  function (lang, link) {
53
52
  link = link.trim();
@@ -57,7 +56,7 @@ index_2.LinkToken.prototype.setLangLink =
57
56
  }
58
57
  this.setTarget(lang + (link.startsWith(':') ? '' : ':') + link);
59
58
  };
60
- index_2.LinkToken.prototype.asSelfLink =
59
+ index_3.LinkToken.prototype.asSelfLink =
61
60
  /** @implements */
62
61
  function (fragment) {
63
62
  fragment ??= this.fragment;
@@ -67,7 +66,7 @@ index_2.LinkToken.prototype.asSelfLink =
67
66
  }
68
67
  this.setTarget(`#${(0, string_1.encode)(fragment)}`);
69
68
  };
70
- index_2.LinkToken.prototype.pipeTrick =
69
+ index_3.LinkToken.prototype.pipeTrick =
71
70
  /** @implements */
72
71
  function () {
73
72
  const linkText = this.firstChild.text();
@@ -106,6 +106,136 @@ const getMaxCol = (layout) => {
106
106
  }
107
107
  return maxCol;
108
108
  };
109
+ /**
110
+ * 在表格开头插入一行
111
+ * @param table 表格
112
+ */
113
+ const prependTableRow = (table) => {
114
+ // @ts-expect-error abstract class
115
+ const row = debug_1.Shadow.run(() => new tr_1.TrToken('\n|-', undefined, table.getAttribute('config'))), { childNodes } = table, [, , plain] = childNodes, start = plain?.constructor === index_1.Token ? 3 : 2, tdChildren = childNodes.slice(start), index = tdChildren.findIndex(({ type }) => type !== 'td');
116
+ table.insertAt(row, index === -1 ? -1 : index + start);
117
+ debug_1.Shadow.run(() => {
118
+ for (const cell of tdChildren.slice(0, index === -1 ? undefined : index)) {
119
+ if (cell.subtype !== 'caption') {
120
+ row.insertAt(cell);
121
+ }
122
+ }
123
+ });
124
+ return row;
125
+ };
126
+ /**
127
+ * 分裂单元格
128
+ * @param table 表格
129
+ * @param coords 单元格坐标
130
+ * @param dirs 分裂方向
131
+ * @throws `RangeError` 指定坐标不是某个单元格的起始点
132
+ */
133
+ const split = (table, coords, dirs) => {
134
+ const cell = table.getNthCell(coords), attr = cell.getAttrs(), { subtype } = cell;
135
+ attr.rowspan ||= 1;
136
+ attr.colspan ||= 1;
137
+ for (const dir of dirs) {
138
+ if (attr[dir] === 1) {
139
+ dirs.delete(dir);
140
+ }
141
+ }
142
+ if (dirs.size === 0) {
143
+ return;
144
+ }
145
+ let { x, y } = coords;
146
+ const rawCoords = isTableCoords(coords) ? coords : table.toRawCoords(coords);
147
+ if (rawCoords.start === false || x === undefined) {
148
+ ({ x, y } = table.toRenderedCoords(rawCoords));
149
+ }
150
+ const splitting = { rowspan: 1, colspan: 1 };
151
+ for (const dir of dirs) {
152
+ cell.setAttr(dir, 1);
153
+ splitting[dir] = attr[dir];
154
+ delete attr[dir];
155
+ }
156
+ for (let j = y; j < y + splitting.rowspan; j++) {
157
+ for (let i = x; i < x + splitting.colspan; i++) {
158
+ if (i > x || j > y) {
159
+ try {
160
+ table.insertTableCell('', { x: i, y: j }, subtype, attr);
161
+ }
162
+ catch (e) {
163
+ if (e instanceof RangeError
164
+ && e.message.startsWith('The specified coordinates are not the starting point of a cell: ')) {
165
+ break;
166
+ }
167
+ throw e;
168
+ }
169
+ }
170
+ }
171
+ }
172
+ };
173
+ /**
174
+ * 移动表格列
175
+ * @param table 表格
176
+ * @param x 列号
177
+ * @param reference 参考列号
178
+ * @param after 是否插入到参考列之后
179
+ * @throws `RangeError` 两列结构不一致,无法移动
180
+ */
181
+ const moveCol = (table, x, reference, after) => {
182
+ const layout = table.getLayout();
183
+ if (layout.some(rowLayout => isStartCol(rowLayout, x) !== isStartCol(rowLayout, reference, after))) {
184
+ throw new RangeError(`The structure of column ${x} is different from that of column ${reference}, so it cannot be moved!`);
185
+ }
186
+ const setX = new WeakSet(), setRef = new WeakSet(), rows = table.getAllRows();
187
+ for (let i = 0; i < layout.length; i++) {
188
+ const rowLayout = layout[i], coords = rowLayout[x], refCoords = rowLayout[reference], start = isStartCol(rowLayout, x);
189
+ if (refCoords && !start && !setRef.has(refCoords)) {
190
+ setRef.add(refCoords);
191
+ rows[refCoords.row].getNthCol(refCoords.column).colspan++;
192
+ }
193
+ if (coords && !setX.has(coords)) {
194
+ setX.add(coords);
195
+ const rowToken = rows[i];
196
+ let token = rowToken.getNthCol(coords.column);
197
+ const { colspan } = token;
198
+ if (colspan > 1) {
199
+ token.colspan = colspan - 1;
200
+ if (start) {
201
+ const original = token;
202
+ token = token.cloneNode();
203
+ original.lastChild.replaceChildren();
204
+ token.colspan = 1;
205
+ }
206
+ }
207
+ if (start) {
208
+ const col = rowLayout.slice(reference + Number(after)).find(({ row }) => row === i)?.column;
209
+ rowToken.insertBefore(token, col === undefined
210
+ ? rowToken.childNodes.slice(2).find(debug_1.isRowEnd)
211
+ : rowToken.getNthCol(col));
212
+ }
213
+ }
214
+ }
215
+ };
216
+ index_2.Layout.prototype.print =
217
+ /** @implements */
218
+ function () {
219
+ const hBorders = (0, debug_1.emptyArray)(this.length + 1, i => {
220
+ const prev = this[i - 1] ?? [], next = this[i] ?? [];
221
+ return (0, debug_1.emptyArray)(Math.max(prev.length, next.length), j => prev[j] !== next[j]);
222
+ }), vBorders = this.map(cur => (0, debug_1.emptyArray)(cur.length + 1, j => cur[j - 1] !== cur[j]));
223
+ let out = '';
224
+ for (let i = 0; i <= this.length; i++) {
225
+ const hBorder = hBorders[i].map(Number), vBorderTop = (vBorders[i - 1] ?? []).map(Number), vBorderBottom = (vBorders[i] ?? []).map(Number),
226
+ // eslint-disable-next-line no-sparse-arrays
227
+ border = [' ', , , '┌', , '┐', '─', '┬', , '│', '└', '├', '┘', '┤', '┴', '┼'];
228
+ for (let j = 0; j <= hBorder.length; j++) {
229
+ /* eslint-disable no-bitwise */
230
+ const bit = (vBorderTop[j] << 3) + (vBorderBottom[j] << 0)
231
+ + (hBorder[j - 1] << 2) + (hBorder[j] << 1);
232
+ /* eslint-enable no-bitwise */
233
+ out += border[bit] + (hBorder[j] ? '─' : ' ');
234
+ }
235
+ out += '\n';
236
+ }
237
+ console.log(out.slice(0, -1));
238
+ };
109
239
  index_2.TableToken.prototype.getNthCell =
110
240
  /** @implements */
111
241
  function (coords) {
@@ -198,21 +328,6 @@ index_2.TableToken.prototype.insertTableCell =
198
328
  ? trBase_1.TrBaseToken.prototype.insertTableCell.call(this, inner, rawCoords, subtype, attr)
199
329
  : rowToken.insertTableCell(inner, rawCoords, subtype, attr);
200
330
  };
201
- index_2.TableToken.prototype.prependTableRow =
202
- /** @implements */
203
- function () {
204
- // @ts-expect-error abstract class
205
- const row = debug_1.Shadow.run(() => new tr_1.TrToken('\n|-', undefined, this.getAttribute('config'))), { childNodes } = this, [, , plain] = childNodes, start = plain?.constructor === index_1.Token ? 3 : 2, tdChildren = childNodes.slice(start), index = tdChildren.findIndex(({ type }) => type !== 'td');
206
- this.insertAt(row, index === -1 ? -1 : index + start);
207
- debug_1.Shadow.run(() => {
208
- for (const cell of tdChildren.slice(0, index === -1 ? undefined : index)) {
209
- if (cell.subtype !== 'caption') {
210
- row.insertAt(cell);
211
- }
212
- }
213
- });
214
- return row;
215
- };
216
331
  index_2.TableToken.prototype.insertTableRow =
217
332
  /** @implements */
218
333
  function (y, attr = {}, inner, subtype = 'td', innerAttr = {}) {
@@ -221,7 +336,7 @@ index_2.TableToken.prototype.insertTableRow =
221
336
  const token = debug_1.Shadow.run(() => new tr_1.TrToken('\n|-', undefined, this.getAttribute('config')));
222
337
  token.setAttr(attr);
223
338
  if (reference?.is('table')) { // `row === 0`且表格自身是有效行
224
- reference = this.prependTableRow();
339
+ reference = prependTableRow(this);
225
340
  }
226
341
  this.insertBefore(token, reference);
227
342
  if (inner !== undefined) {
@@ -298,7 +413,7 @@ index_2.TableToken.prototype.removeTableRow =
298
413
  }
299
414
  }
300
415
  }
301
- const row = rows[y], rowToken = row.is('tr') ? row : this.prependTableRow();
416
+ const row = rows[y], rowToken = row.is('tr') ? row : prependTableRow(this);
302
417
  rowToken.remove();
303
418
  return rowToken;
304
419
  };
@@ -335,69 +450,27 @@ index_2.TableToken.prototype.mergeCells =
335
450
  }
336
451
  return cornerCell;
337
452
  };
338
- index_2.TableToken.prototype.split =
339
- /** @implements */
340
- function (coords, dirs) {
341
- const cell = this.getNthCell(coords), attr = cell.getAttrs(), { subtype } = cell;
342
- attr.rowspan ||= 1;
343
- attr.colspan ||= 1;
344
- for (const dir of dirs) {
345
- if (attr[dir] === 1) {
346
- dirs.delete(dir);
347
- }
348
- }
349
- if (dirs.size === 0) {
350
- return;
351
- }
352
- let { x, y } = coords;
353
- const rawCoords = isTableCoords(coords) ? coords : this.toRawCoords(coords);
354
- if (rawCoords.start === false || x === undefined) {
355
- ({ x, y } = this.toRenderedCoords(rawCoords));
356
- }
357
- const splitting = { rowspan: 1, colspan: 1 };
358
- for (const dir of dirs) {
359
- cell.setAttr(dir, 1);
360
- splitting[dir] = attr[dir];
361
- delete attr[dir];
362
- }
363
- for (let j = y; j < y + splitting.rowspan; j++) {
364
- for (let i = x; i < x + splitting.colspan; i++) {
365
- if (i > x || j > y) {
366
- try {
367
- this.insertTableCell('', { x: i, y: j }, subtype, attr);
368
- }
369
- catch (e) {
370
- if (e instanceof RangeError
371
- && e.message.startsWith('The specified coordinates are not the starting point of a cell: ')) {
372
- break;
373
- }
374
- throw e;
375
- }
376
- }
377
- }
378
- }
379
- };
380
453
  index_2.TableToken.prototype.splitIntoRows =
381
454
  /** @implements */
382
455
  function (coords) {
383
- this.split(coords, new Set(['rowspan']));
456
+ split(this, coords, new Set(['rowspan']));
384
457
  };
385
458
  index_2.TableToken.prototype.splitIntoCols =
386
459
  /** @implements */
387
460
  function (coords) {
388
- this.split(coords, new Set(['colspan']));
461
+ split(this, coords, new Set(['colspan']));
389
462
  };
390
463
  index_2.TableToken.prototype.splitIntoCells =
391
464
  /** @implements */
392
465
  function (coords) {
393
- this.split(coords, new Set(['rowspan', 'colspan']));
466
+ split(this, coords, new Set(['rowspan', 'colspan']));
394
467
  };
395
468
  index_2.TableToken.prototype.replicateTableRow =
396
469
  /** @implements */
397
470
  function (row) {
398
471
  let rowToken = this.getNthRow(row);
399
472
  if (rowToken.is('table')) {
400
- rowToken = this.prependTableRow();
473
+ rowToken = prependTableRow(this);
401
474
  }
402
475
  const replicated = this.insertBefore(rowToken.cloneNode(), rowToken);
403
476
  for (const [token, start] of this.getFullRow(row)) {
@@ -448,7 +521,7 @@ index_2.TableToken.prototype.moveTableRowBefore =
448
521
  }
449
522
  let beforeToken = this.getNthRow(before);
450
523
  if (beforeToken.is('table')) {
451
- beforeToken = this.prependTableRow();
524
+ beforeToken = prependTableRow(this);
452
525
  }
453
526
  this.insertBefore(rowToken, beforeToken);
454
527
  return rowToken;
@@ -487,51 +560,14 @@ index_2.TableToken.prototype.moveTableRowAfter =
487
560
  }
488
561
  return rowToken;
489
562
  };
490
- index_2.TableToken.prototype.moveCol =
491
- /** @implements */
492
- function (x, reference, after) {
493
- const layout = this.getLayout();
494
- if (layout.some(rowLayout => isStartCol(rowLayout, x) !== isStartCol(rowLayout, reference, after))) {
495
- throw new RangeError(`The structure of column ${x} is different from that of column ${reference}, so it cannot be moved!`);
496
- }
497
- const setX = new WeakSet(), setRef = new WeakSet(), rows = this.getAllRows();
498
- for (let i = 0; i < layout.length; i++) {
499
- const rowLayout = layout[i], coords = rowLayout[x], refCoords = rowLayout[reference], start = isStartCol(rowLayout, x);
500
- if (refCoords && !start && !setRef.has(refCoords)) {
501
- setRef.add(refCoords);
502
- rows[refCoords.row].getNthCol(refCoords.column).colspan++;
503
- }
504
- if (coords && !setX.has(coords)) {
505
- setX.add(coords);
506
- const rowToken = rows[i];
507
- let token = rowToken.getNthCol(coords.column);
508
- const { colspan } = token;
509
- if (colspan > 1) {
510
- token.colspan = colspan - 1;
511
- if (start) {
512
- const original = token;
513
- token = token.cloneNode();
514
- original.lastChild.replaceChildren();
515
- token.colspan = 1;
516
- }
517
- }
518
- if (start) {
519
- const col = rowLayout.slice(reference + Number(after)).find(({ row }) => row === i)?.column;
520
- rowToken.insertBefore(token, col === undefined
521
- ? rowToken.childNodes.slice(2).find(debug_1.isRowEnd)
522
- : rowToken.getNthCol(col));
523
- }
524
- }
525
- }
526
- };
527
563
  index_2.TableToken.prototype.moveTableColBefore =
528
564
  /** @implements */
529
565
  function (x, before) {
530
- this.moveCol(x, before);
566
+ moveCol(this, x, before);
531
567
  };
532
568
  index_2.TableToken.prototype.moveTableColAfter =
533
569
  /** @implements */
534
570
  function (x, after) {
535
- this.moveCol(x, after, true);
571
+ moveCol(this, x, after, true);
536
572
  };
537
573
  constants_1.classes['ExtendedTableToken'] = __filename;
@@ -13,6 +13,7 @@ index_1.Token.prototype.createComment = /** @implements */ function (data = '')
13
13
  return debug_1.Shadow.run(() => new comment_1.CommentToken(data.replaceAll('-->', '--&gt;'), true, this.getAttribute('config')));
14
14
  };
15
15
  index_1.Token.prototype.createElement = /** @implements */ function (tagName, { selfClosing, closing } = {}) {
16
+ tagName = tagName.toLowerCase();
16
17
  const config = this.getAttribute('config'), include = this.getAttribute('include');
17
18
  if (tagName === (include ? 'noinclude' : 'includeonly')) {
18
19
  return debug_1.Shadow.run(
@@ -22,7 +23,7 @@ index_1.Token.prototype.createElement = /** @implements */ function (tagName, {
22
23
  else if (config.ext.includes(tagName)) {
23
24
  return debug_1.Shadow.run(
24
25
  // @ts-expect-error abstract class
25
- () => new ext_1.ExtToken(tagName, '', undefined, selfClosing ? undefined : '', config, include));
26
+ () => new ext_1.ExtToken(tagName, '', undefined, selfClosing ? undefined : tagName, config, include));
26
27
  }
27
28
  else if (config.html.some(tags => tags.includes(tagName))) {
28
29
  return debug_1.Shadow.run(() => {
@@ -37,6 +38,7 @@ index_1.Token.prototype.createElement = /** @implements */ function (tagName, {
37
38
  throw new RangeError(`Invalid tag name: ${tagName}`);
38
39
  };
39
40
  index_1.Token.prototype.sections = /** @implements */ function () {
41
+ /* istanbul ignore if */
40
42
  if (this.type !== 'root') {
41
43
  return undefined;
42
44
  }
package/dist/base.d.mts CHANGED
@@ -47,7 +47,7 @@ export declare const stages: {
47
47
  'list-range': number;
48
48
  };
49
49
  export type Stage = keyof typeof stages;
50
- export declare const rules: readonly ["arg-in-ext", "bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "invalid-url", "lonely-apos", "lonely-bracket", "lonely-http", "nested-link", "no-arg", "no-duplicate", "no-ignored", "obsolete-attr", "obsolete-tag", "parsing-order", "pipe-like", "syntax-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", "invalid-css", "invalid-math"];
50
+ export declare const rules: readonly ["arg-in-ext", "bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "invalid-json", "invalid-url", "lonely-apos", "lonely-bracket", "lonely-http", "nested-link", "no-arg", "no-duplicate", "no-ignored", "obsolete-attr", "obsolete-tag", "parsing-order", "pipe-like", "syntax-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", "invalid-css", "invalid-math"];
51
51
  export declare namespace LintError {
52
52
  type Severity = 'error' | 'warning';
53
53
  type Rule = typeof rules[number];
package/dist/base.d.ts CHANGED
@@ -47,7 +47,7 @@ export declare const stages: {
47
47
  'list-range': number;
48
48
  };
49
49
  export type Stage = keyof typeof stages;
50
- export declare const rules: readonly ["arg-in-ext", "bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "invalid-url", "lonely-apos", "lonely-bracket", "lonely-http", "nested-link", "no-arg", "no-duplicate", "no-ignored", "obsolete-attr", "obsolete-tag", "parsing-order", "pipe-like", "syntax-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", "invalid-css", "invalid-math"];
50
+ export declare const rules: readonly ["arg-in-ext", "bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "invalid-json", "invalid-url", "lonely-apos", "lonely-bracket", "lonely-http", "nested-link", "no-arg", "no-duplicate", "no-ignored", "obsolete-attr", "obsolete-tag", "parsing-order", "pipe-like", "syntax-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", "invalid-css", "invalid-math"];
51
51
  export declare namespace LintError {
52
52
  type Severity = 'error' | 'warning';
53
53
  type Rule = typeof rules[number];
package/dist/base.js CHANGED
@@ -46,6 +46,7 @@ exports.rules = (() => {
46
46
  'invalid-imagemap',
47
47
  'invalid-invoke',
48
48
  'invalid-isbn',
49
+ 'invalid-json',
49
50
  'invalid-url',
50
51
  'lonely-apos',
51
52
  'lonely-bracket',
package/dist/base.mjs CHANGED
@@ -43,6 +43,7 @@ const rules = /* @__PURE__ */ (() => {
43
43
  "invalid-imagemap",
44
44
  "invalid-invoke",
45
45
  "invalid-isbn",
46
+ "invalid-json",
46
47
  "invalid-url",
47
48
  "lonely-apos",
48
49
  "lonely-bracket",
@@ -77,7 +77,7 @@ const mw = {
77
77
  },
78
78
  },
79
79
  };
80
- const pkg = "wikiparser-node", version = "1.32.0";
80
+ const pkg = "wikiparser-node", version = "1.34.0";
81
81
  let mwConfig;
82
82
  /**
83
83
  * Get the parser configuration for a Wikimedia Foundation project.
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ const string_1 = require("./util/string");
10
10
  const lintConfig_1 = require("./lib/lintConfig");
11
11
  const title_1 = require("./lib/title");
12
12
  /* NOT FOR BROWSER */
13
+ const util_1 = __importDefault(require("util"));
13
14
  const redirectMap_1 = require("./lib/redirectMap");
14
15
  /* NOT FOR BROWSER END */
15
16
  /* NOT FOR BROWSER ONLY */
@@ -216,11 +217,9 @@ const Parser = {
216
217
  maxStage ??= constants_1.MAX_STAGE;
217
218
  config ??= this.getConfig();
218
219
  let types;
219
- LINT: {
220
- if (typeof maxStage !== 'number') {
221
- types = Array.isArray(maxStage) ? maxStage : [maxStage];
222
- maxStage = Math.max(...types.map(t => base_1.stages[t] || constants_1.MAX_STAGE));
223
- }
220
+ LINT: if (typeof maxStage !== 'number') {
221
+ types = Array.isArray(maxStage) ? maxStage : [maxStage];
222
+ maxStage = Math.max(...types.map(t => base_1.stages[t] || constants_1.MAX_STAGE));
224
223
  }
225
224
  const { Token } = require('./src/index');
226
225
  const root = debug_1.Shadow.run(() => {
@@ -376,14 +375,16 @@ const Parser = {
376
375
  warn(msg, ...args) {
377
376
  /* istanbul ignore if */
378
377
  if (this.warning) {
379
- console.warn((0, diff_1.loadChalk)()?.yellow(msg) ?? msg, ...args);
378
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
379
+ console.warn(util_1.default.styleText?.('yellow', msg) ?? msg, ...args);
380
380
  }
381
381
  },
382
382
  /** @implements */
383
383
  debug(msg, ...args) {
384
384
  /* istanbul ignore if */
385
385
  if (this.debugging) {
386
- console.debug((0, diff_1.loadChalk)()?.blue(msg) ?? msg, ...args);
386
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
387
+ console.debug(util_1.default.styleText?.('blue', msg) ?? msg, ...args);
387
388
  }
388
389
  },
389
390
  error: diff_1.error,
@@ -426,12 +427,11 @@ const Parser = {
426
427
  /* istanbul ignore next */
427
428
  /** @implements */
428
429
  reparse(date = '') {
429
- const main = fs_1.default.readdirSync(path_1.default.join(__dirname, '..', 'errors'))
430
- .find(name => name.startsWith(date) && name.endsWith('Z'));
430
+ const dir = path_1.default.join(__dirname, '..', 'errors'), main = fs_1.default.readdirSync(dir).find(name => name.startsWith(date) && name.endsWith('Z'));
431
431
  if (!main) {
432
432
  throw new RangeError(`找不到对应时间戳的错误记录:${date}`);
433
433
  }
434
- const file = path_1.default.join(__dirname, '..', 'errors', main), wikitext = fs_1.default.readFileSync(file, 'utf8');
434
+ const file = path_1.default.join(dir, main), wikitext = fs_1.default.readFileSync(file, 'utf8');
435
435
  const { stage, include, config, page } = require(`${file}.json`), { Token } = require('./src/index');
436
436
  debug_1.Shadow.run(() => {
437
437
  const halfParsed = stage < constants_1.MAX_STAGE, token = new Token(halfParsed ? wikitext : (0, string_1.tidy)(wikitext), config);