wikiparser-node 1.35.0 → 1.35.1

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 (71) hide show
  1. package/README.md +29 -28
  2. package/bundle/bundle-es8.min.js +29 -29
  3. package/bundle/bundle-lsp.min.js +34 -34
  4. package/bundle/bundle.min.js +24 -24
  5. package/config/default.json +3 -0
  6. package/config/enwiki.json +3 -0
  7. package/config/jawiki.json +3 -0
  8. package/config/minimum.json +1 -0
  9. package/config/zhwiki.json +3 -0
  10. package/coverage/badge.svg +1 -1
  11. package/data/signatures.json +13 -0
  12. package/dist/addon/attribute.js +13 -12
  13. package/dist/addon/link.js +3 -3
  14. package/dist/addon/token.js +4 -4
  15. package/dist/addon/transclude.js +8 -8
  16. package/dist/base.d.mts +3 -1
  17. package/dist/base.d.ts +3 -1
  18. package/dist/bin/config.js +3 -3
  19. package/dist/index.js +21 -13
  20. package/dist/lib/document.js +14 -12
  21. package/dist/lib/element.d.ts +2 -1
  22. package/dist/lib/element.js +17 -13
  23. package/dist/lib/lintConfig.js +7 -6
  24. package/dist/lib/lsp.js +10 -8
  25. package/dist/lib/node.js +8 -6
  26. package/dist/lib/range.js +17 -13
  27. package/dist/lib/ranges.js +25 -26
  28. package/dist/lib/text.js +14 -13
  29. package/dist/lib/title.js +7 -6
  30. package/dist/parser/braces.js +5 -7
  31. package/dist/parser/hrAndDoubleUnderscore.js +2 -2
  32. package/dist/parser/list.js +1 -1
  33. package/dist/parser/magicLinks.js +2 -1
  34. package/dist/parser/selector.js +15 -15
  35. package/dist/src/arg.js +4 -4
  36. package/dist/src/atom.js +1 -1
  37. package/dist/src/attribute.js +5 -4
  38. package/dist/src/attributes.js +10 -7
  39. package/dist/src/converter.js +4 -4
  40. package/dist/src/converterRule.js +2 -2
  41. package/dist/src/heading.js +2 -2
  42. package/dist/src/imageParameter.js +12 -3
  43. package/dist/src/index.js +15 -10
  44. package/dist/src/link/base.js +10 -7
  45. package/dist/src/link/category.js +3 -3
  46. package/dist/src/link/file.js +6 -5
  47. package/dist/src/link/index.js +5 -3
  48. package/dist/src/multiLine/gallery.js +2 -2
  49. package/dist/src/nowiki/comment.js +4 -3
  50. package/dist/src/nowiki/doubleUnderscore.js +1 -1
  51. package/dist/src/nowiki/listBase.js +2 -2
  52. package/dist/src/nowiki/noinclude.js +1 -1
  53. package/dist/src/nowiki/quote.js +3 -3
  54. package/dist/src/onlyinclude.js +1 -1
  55. package/dist/src/parameter.js +2 -2
  56. package/dist/src/table/index.js +9 -8
  57. package/dist/src/table/td.js +5 -5
  58. package/dist/src/table/trBase.js +4 -4
  59. package/dist/src/tag/html.js +9 -9
  60. package/dist/src/tag/index.js +6 -5
  61. package/dist/src/tag/tvar.js +4 -3
  62. package/dist/src/tagPair/index.js +6 -4
  63. package/dist/src/transclude.js +3 -3
  64. package/dist/util/debug.js +3 -2
  65. package/dist/util/diff.js +11 -6
  66. package/dist/util/selector.js +1 -1
  67. package/dist/util/string.js +2 -2
  68. package/extensions/dist/base.js +12 -4
  69. package/extensions/dist/codejar.js +1 -1
  70. package/package.json +27 -27
  71. package/logo.png +0 -0
@@ -20,11 +20,12 @@ const parseMagicLinks = (wikitext, config, accum) => {
20
20
  /(^|[^\p{L}\p{N}_])(?:(?:ftp:\/\/|http:\/\/)((?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])[^[\]<>"\0\t\n\p{Zs}]*)|(?:rfc|pmid)[\p{Zs}\t]+\d+\b|isbn[\p{Zs}\t]+(?:97[89][\p{Zs}\t-]?)?(?:\d[\p{Zs}\t-]?){9}[\dx]\b)/giu;
21
21
  config.regexMagicLinks = new RegExp(String.raw `(^|[^\p{L}\p{N}_])(?:(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})|${magicLinkPattern})`, 'giu');
22
22
  }
23
- catch /* istanbul ignore next */ {
23
+ catch /* c8 ignore start */ {
24
24
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
25
25
  /(^|\W)(?:(?:ftp:\/\/|http:\/\/)((?:\[[\da-f:.]+\]|[^[\]<>"\s])[^[\]<>"\0\s]*)|(?:rfc|pmid)\s+\d+\b|isbn\s+(?:97[89][\s-]?)?(?:\d[\s-]?){9}[\dx]\b)/giu;
26
26
  config.regexMagicLinks = new RegExp(String.raw `(^|\W)(?:(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})|${magicLinkPattern})`, 'giu');
27
27
  }
28
+ /* c8 ignore stop */
28
29
  }
29
30
  return wikitext.replace(config.regexMagicLinks, (m, lead, p1) => {
30
31
  let url = lead ? m.slice(lead.length) : m;
@@ -153,7 +153,7 @@ const matches = (token, step, scope, has) => {
153
153
  case ':optional':
154
154
  return isProtected(token) === false;
155
155
  case ':scope':
156
- /* istanbul ignore if */
156
+ /* c8 ignore next 3 */
157
157
  if (!scope) {
158
158
  throw new SyntaxError('The :scope pseudo-selector must be used with an element node.');
159
159
  }
@@ -171,13 +171,13 @@ const matches = (token, step, scope, has) => {
171
171
  if (!equal) {
172
172
  return thisVal !== undefined && thisVal !== false;
173
173
  }
174
- /* istanbul ignore else */
175
174
  if (equal === '~=') {
176
175
  const thisVals = typeof thisVal === 'string' ? thisVal.split(/\s/u) : thisVal;
177
176
  return Boolean(thisVals?.[Symbol.iterator])
178
177
  && [...thisVals].some(w => typeof w === 'string' && toCase(w, i) === v);
179
178
  }
180
- else if (!(primitives.has(typeof thisVal) || thisVal instanceof title_1.Title)) {
179
+ /* c8 ignore next 3 */
180
+ if (!(primitives.has(typeof thisVal) || thisVal instanceof title_1.Title)) {
181
181
  throw new RangeError(`The complex attribute ${key} cannot be used in a selector!`);
182
182
  }
183
183
  const stringVal = toCase(String(thisVal), i);
@@ -213,7 +213,7 @@ const matches = (token, step, scope, has) => {
213
213
  case 'contains':
214
214
  return token.text().includes(s);
215
215
  case 'has': {
216
- /* istanbul ignore if */
216
+ /* c8 ignore next 3 */
217
217
  if (has) {
218
218
  throw new SyntaxError('The :has() pseudo-selector cannot be nested.');
219
219
  }
@@ -241,18 +241,19 @@ const matches = (token, step, scope, has) => {
241
241
  }
242
242
  case 'regex': {
243
243
  const mt = /^([^,]+),\s*\/(.+)\/([a-z]*)$/u.exec(s);
244
- /* istanbul ignore if */
244
+ /* c8 ignore next 3 */
245
245
  if (!mt) {
246
246
  throw new SyntaxError(`Wrong usage of the regex pseudo-selector. Use ":regex('attr, /re/i')" format.`);
247
247
  }
248
248
  try {
249
249
  return new RegExp(mt[2], mt[3]).test(String(getAttr(token, mt[1].trim())));
250
250
  }
251
- catch /* istanbul ignore next */ {
251
+ catch /* c8 ignore start */ {
252
252
  throw new SyntaxError(`Invalid regular expression: /${mt[2]}/${mt[3]}`);
253
253
  }
254
+ /* c8 ignore stop */
254
255
  }
255
- /* istanbul ignore next */
256
+ /* c8 ignore next 2 */
256
257
  default:
257
258
  throw new SyntaxError(`Undefined pseudo-selector: ${pseudo}`);
258
259
  }
@@ -337,24 +338,23 @@ const checkToken = (selector, scope, has) => (token) => {
337
338
  for (let i = 0; i < pieces.length; i++) {
338
339
  const piece = pieces[i];
339
340
  if (!/^[:#]/u.test(piece)) {
340
- /* istanbul ignore if */
341
+ /* c8 ignore next 3 */
341
342
  if (step.length > 0) {
342
343
  throw new SyntaxError(`Invalid selector!\n${selector}\nType selectors must come first.`);
343
344
  }
344
- else {
345
- step.push(piece);
346
- }
345
+ step.push(piece);
347
346
  }
348
347
  else if (piece.startsWith(':')) {
349
348
  if (simplePseudos.has(piece.slice(1))) {
350
349
  step.push(piece);
351
350
  }
352
- else /* istanbul ignore else */ if (pieces[i - 1]?.startsWith('#')) {
351
+ else if (pieces[i - 1]?.startsWith('#')) {
353
352
  pieces[i - 1] += piece;
354
353
  pieces.splice(i, 1);
355
354
  i--;
356
355
  }
357
356
  else {
357
+ /* c8 ignore next 2 */
358
358
  throw new SyntaxError(`Undefined pseudo selector!\n${desanitize(piece)}`);
359
359
  }
360
360
  }
@@ -366,7 +366,7 @@ const checkToken = (selector, scope, has) => (token) => {
366
366
  * @throws `SyntaxError` 非法的选择器
367
367
  */
368
368
  const needUniversal = () => {
369
- /* istanbul ignore next */
369
+ /* c8 ignore next 3 */
370
370
  if (step.length === 0 && (condition.length > 1 || !has)) {
371
371
  throw new SyntaxError(`Invalid selector!\n${selector}\nYou may need the universal selector '*'.`);
372
372
  }
@@ -408,7 +408,7 @@ const checkToken = (selector, scope, has) => (token) => {
408
408
  }
409
409
  else if (syntax === '(') { // 情形5:伪选择器开启
410
410
  const i = sanitized.lastIndexOf(':', index), pseudo = sanitized.slice(i + 1, index);
411
- /* istanbul ignore if */
411
+ /* c8 ignore next 3 */
412
412
  if (i === -1 || !complexPseudos.has(pseudo)) {
413
413
  throw new SyntaxError(`Undefined pseudo selector!\n${desanitize(sanitized)}`);
414
414
  }
@@ -433,7 +433,7 @@ const checkToken = (selector, scope, has) => (token) => {
433
433
  needUniversal();
434
434
  return stack.some(copy => matchesArray(token, copy, scope, has));
435
435
  }
436
- /* istanbul ignore next */
436
+ /* c8 ignore next */
437
437
  throw new SyntaxError(`Unclosed '${regex === attributeRegex ? '[' : '('}' in the selector!\n${desanitize(sanitized)}`);
438
438
  };
439
439
  exports.checkToken = checkToken;
package/dist/src/arg.js CHANGED
@@ -148,7 +148,7 @@ let ArgToken = (() => {
148
148
  /** @private */
149
149
  lint(start = this.getAbsoluteIndex(), re) {
150
150
  LINT: {
151
- const { childNodes: [argName, argDefault, ...rest] } = this;
151
+ const [argName, argDefault, ...rest] = this.childNodes;
152
152
  argName.setAttribute('aIndex', start + 3);
153
153
  const errors = argName.lint(start + 3, re);
154
154
  if (argDefault) {
@@ -196,9 +196,9 @@ let ArgToken = (() => {
196
196
  PRINT: return super.print({ pre: '{{{', post: '}}}', sep: '|' });
197
197
  }
198
198
  /** @private */
199
- json(_, start = this.getAbsoluteIndex()) {
199
+ json(_, depth, start = this.getAbsoluteIndex()) {
200
200
  LSP: {
201
- const json = super.json(undefined, start);
201
+ const json = super.json(undefined, depth, start);
202
202
  json['default'] = this.default;
203
203
  return json;
204
204
  }
@@ -279,7 +279,7 @@ let ArgToken = (() => {
279
279
  this.removeAt(1);
280
280
  return;
281
281
  }
282
- const { childNodes: [, oldDefault] } = this, root = index_1.default.parseWithRef(value, this);
282
+ const [, oldDefault] = this.childNodes, root = index_1.default.parseWithRef(value, this);
283
283
  if (oldDefault) {
284
284
  oldDefault.safeReplaceChildren(root.childNodes);
285
285
  }
package/dist/src/atom.js CHANGED
@@ -77,7 +77,7 @@ let AtomToken = (() => {
77
77
  }
78
78
  set type(value) {
79
79
  /* NOT FOR BROWSER */
80
- /* istanbul ignore if */
80
+ /* c8 ignore next 3 */
81
81
  if (!atomTypes.includes(value)) {
82
82
  throw new RangeError(`"${value}" is not a valid type for AtomToken!`);
83
83
  }
@@ -389,9 +389,9 @@ let AttributeToken = (() => {
389
389
  }
390
390
  }
391
391
  /** @private */
392
- json(_, start = this.getAbsoluteIndex()) {
392
+ json(_, depth, start = this.getAbsoluteIndex()) {
393
393
  LSP: {
394
- const json = super.json(undefined, start);
394
+ const json = super.json(undefined, depth, start);
395
395
  json['tag'] = this.tag;
396
396
  return json;
397
397
  }
@@ -443,7 +443,7 @@ let AttributeToken = (() => {
443
443
  require('../addon/attribute');
444
444
  this.setValue(value);
445
445
  }
446
- /* istanbul ignore next */
446
+ /* c8 ignore start */
447
447
  /**
448
448
  * Rename the attribute
449
449
  *
@@ -455,6 +455,7 @@ let AttributeToken = (() => {
455
455
  require('../addon/attribute');
456
456
  this.rename(key);
457
457
  }
458
+ /* c8 ignore stop */
458
459
  /** @private */
459
460
  asHtmlAttr() {
460
461
  this.#type = 'html-attr';
@@ -475,7 +476,7 @@ let AttributeToken = (() => {
475
476
  : (0, string_1.sanitizeAttr)(value, name === 'id');
476
477
  return `${name}="${sanitized}"`;
477
478
  }
478
- /* istanbul ignore next */
479
+ /* c8 ignore start */
479
480
  /**
480
481
  * Get or set the value of a style property
481
482
  *
@@ -68,9 +68,10 @@ const wordRegex = /* #__PURE__ */ (() => {
68
68
  // eslint-disable-next-line prefer-regex-literals
69
69
  return new RegExp(String.raw `[\p{L}\p{N}]`, 'u');
70
70
  }
71
- catch /* istanbul ignore next */ {
71
+ catch /* c8 ignore start */ {
72
72
  return /[^\W_]/u;
73
73
  }
74
+ /* c8 ignore stop */
74
75
  })();
75
76
  /**
76
77
  * attributes of extension and HTML tags
@@ -338,7 +339,7 @@ let AttributesToken = (() => {
338
339
  }
339
340
  /* PRINT ONLY END */
340
341
  /* NOT FOR BROWSER */
341
- /* istanbul ignore next */
342
+ /* c8 ignore start */
342
343
  /**
343
344
  * Sanitize invalid attributes
344
345
  *
@@ -348,6 +349,7 @@ let AttributesToken = (() => {
348
349
  require('../addon/attribute');
349
350
  this.sanitize();
350
351
  }
352
+ /* c8 ignore stop */
351
353
  cloneNode() {
352
354
  // @ts-expect-error abstract class
353
355
  return new AttributesToken(undefined, this.type, this.name, this.getAttribute('config'));
@@ -360,18 +362,18 @@ let AttributesToken = (() => {
360
362
  */
361
363
  insertAt(token, i = this.length) {
362
364
  if (!(token instanceof attribute_1.AttributeToken)) {
363
- /* istanbul ignore if */
365
+ /* c8 ignore next 3 */
364
366
  if (!debug_1.Shadow.running && token.toString().trim()) {
365
367
  this.constructorError('can only insert AttributeToken');
366
368
  }
367
369
  return super.insertAt(token, i);
368
370
  }
369
371
  const { type, name, length } = this;
370
- /* istanbul ignore if */
372
+ /* c8 ignore next 3 */
371
373
  if (token.type !== type.slice(0, -1) || token.tag !== name) {
372
374
  throw new RangeError(`The AttributeToken to be inserted can only be used for <${token.tag}> tag!`);
373
375
  }
374
- else if (i === length) {
376
+ if (i === length) {
375
377
  const { lastChild } = this;
376
378
  if (lastChild instanceof attribute_1.AttributeToken) {
377
379
  lastChild.close();
@@ -424,7 +426,7 @@ let AttributesToken = (() => {
424
426
  attr.remove();
425
427
  }
426
428
  }
427
- /* istanbul ignore next */
429
+ /* c8 ignore start */
428
430
  /**
429
431
  * Toggle the specified attribute
430
432
  *
@@ -437,6 +439,7 @@ let AttributesToken = (() => {
437
439
  require('../addon/attribute');
438
440
  this.toggleAttr(key, force);
439
441
  }
442
+ /* c8 ignore stop */
440
443
  /**
441
444
  * 生成引导空格
442
445
  * @param str 属性字符串
@@ -466,7 +469,7 @@ let AttributesToken = (() => {
466
469
  const map = new Map(this.childNodes.filter(child => child instanceof attribute_1.AttributeToken).map(child => [child.name, child])), output = map.size === 0 ? '' : (0, html_1.html)([...map.values()], ' ', { removeBlank: true });
467
470
  return output && ` ${output}`;
468
471
  }
469
- /* istanbul ignore next */
472
+ /* c8 ignore start */
470
473
  /**
471
474
  * Get the value of a style property
472
475
  *
@@ -119,12 +119,12 @@ let ConverterToken = (() => {
119
119
  }
120
120
  /** @private */
121
121
  toString(skip) {
122
- const { childNodes: [flags, ...rules] } = this;
122
+ const [flags, ...rules] = this.childNodes;
123
123
  return `-{${flags.toString(skip)}${flags.length > 0 ? '|' : ''}${rules.map(rule => rule.toString(skip)).join(';')}}-`;
124
124
  }
125
125
  /** @private */
126
126
  text() {
127
- const { childNodes: [flags, ...rules] } = this;
127
+ const [flags, ...rules] = this.childNodes;
128
128
  return `-{${flags.text()}|${(0, string_1.text)(rules, ';')}}-`;
129
129
  }
130
130
  /** @private */
@@ -134,7 +134,7 @@ let ConverterToken = (() => {
134
134
  /** @private */
135
135
  print() {
136
136
  PRINT: {
137
- const { childNodes: [flags, ...rules] } = this;
137
+ const [flags, ...rules] = this.childNodes;
138
138
  return `<span class="wpb-converter">-{${flags.print()}${flags.length > 0 ? '|' : ''}${(0, string_1.print)(rules, { sep: ';' })}}-</span>`;
139
139
  }
140
140
  }
@@ -152,7 +152,7 @@ let ConverterToken = (() => {
152
152
  }
153
153
  /** @private */
154
154
  toHtmlInternal(opt) {
155
- const flags = this.getEffectiveFlags(), nocc = opt?.nocc, { childNodes: [, ...rules] } = this;
155
+ const flags = this.getEffectiveFlags(), nocc = opt?.nocc, [, ...rules] = this.childNodes;
156
156
  if (nocc || flags.has('R') || this.getVariantFlags().size > 0) {
157
157
  return (nocc ? '-{' : '') + (0, html_1.html)(rules, ';', opt) + (nocc ? '}-' : '');
158
158
  }
@@ -192,9 +192,9 @@ let ConverterRuleToken = (() => {
192
192
  }
193
193
  }
194
194
  /** @private */
195
- json(_, start = this.getAbsoluteIndex()) {
195
+ json(_, depth, start = this.getAbsoluteIndex()) {
196
196
  LSP: {
197
- const json = super.json(undefined, start);
197
+ const json = super.json(undefined, depth, start);
198
198
  json['variant'] = this.variant;
199
199
  return json;
200
200
  }
@@ -248,9 +248,9 @@ let HeadingToken = (() => {
248
248
  }
249
249
  }
250
250
  /** @private */
251
- json(_, start = this.getAbsoluteIndex()) {
251
+ json(_, depth, start = this.getAbsoluteIndex()) {
252
252
  LSP: {
253
- const json = super.json(undefined, start);
253
+ const json = super.json(undefined, depth, start);
254
254
  json['level'] = this.level;
255
255
  return json;
256
256
  }
@@ -147,12 +147,12 @@ let ImageParameterToken = (() => {
147
147
  }
148
148
  const value = super.text().trim();
149
149
  return debug_1.Shadow.run(() => {
150
- const token = new index_2.Token(value, this.getAttribute('config'));
150
+ const config = this.getAttribute('config'), token = new index_2.Token(value, config);
151
151
  token.parseOnce(0, this.getAttribute('include')).parseOnce();
152
152
  if (/^\0\d+m\x7F/u.test(token.firstChild.toString())) {
153
153
  return value;
154
154
  }
155
- const link = validate('link', value, this.getAttribute('config'), this.parentNode?.type);
155
+ const link = validate('link', value, config, this.parentNode?.type);
156
156
  return link === true ? undefined : link;
157
157
  }, index_1.default);
158
158
  }
@@ -314,7 +314,16 @@ let ImageParameterToken = (() => {
314
314
  if (link === undefined) {
315
315
  const rule = 'invalid-gallery', s = lintConfig.getSeverity(rule, 'link');
316
316
  if (s) {
317
- errors.push((0, lint_1.generateForSelf)(this, { start }, rule, 'invalid-gallery-link', s));
317
+ const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'invalid-gallery-link', s);
318
+ if (computeEditInfo) {
319
+ const rawLink = super.toString(), index = rawLink.indexOf('|'), before = rawLink.slice(0, index).trim();
320
+ if (index !== -1
321
+ && !/[<{]/u.test(before)
322
+ && typeof validate('link', before, this.getAttribute('config'), this.parentNode?.type) === 'string') {
323
+ e.suggestions = [(0, lint_1.fixBySpace)(start + this.getRelativeIndex(0) + index)];
324
+ }
325
+ }
326
+ errors.push(e);
318
327
  }
319
328
  }
320
329
  else if (typeof link === 'string') {
package/dist/src/index.js CHANGED
@@ -181,7 +181,7 @@ let Token = (() => {
181
181
  'converter-rule-to',
182
182
  'converter-rule-from',
183
183
  ];
184
- /* istanbul ignore if */
184
+ /* c8 ignore next 3 */
185
185
  if (!plainTypes.includes(value)) {
186
186
  throw new RangeError(`"${value}" is not a valid type for ${this.constructor.name}!`);
187
187
  }
@@ -223,7 +223,8 @@ let Token = (() => {
223
223
  if (n < this.#stage || this.length !== 1 || !this.isPlain()) {
224
224
  return this;
225
225
  }
226
- else /* istanbul ignore if */ if (this.#stage >= constants_1.MAX_STAGE) {
226
+ /* c8 ignore start */
227
+ if (this.#stage >= constants_1.MAX_STAGE) {
227
228
  /* NOt FOR BROWSER */
228
229
  if (this.type === 'root') {
229
230
  index_1.default.error('Fully parsed!');
@@ -231,6 +232,7 @@ let Token = (() => {
231
232
  /* NOT FOR BROWSER END */
232
233
  return this;
233
234
  }
235
+ /* c8 ignore stop */
234
236
  switch (n) {
235
237
  case 0:
236
238
  if (this.type === 'root') {
@@ -291,7 +293,7 @@ let Token = (() => {
291
293
  && Number.isInteger(n) && n >= 0 && n < this.#accum.length) {
292
294
  return this.#accum[n];
293
295
  }
294
- /* istanbul ignore next */
296
+ /* c8 ignore next */
295
297
  throw new Error(`Failed to build! Unrecognized token: ${s}`);
296
298
  }).filter(node => node !== '');
297
299
  if (type === constants_1.BuildMethod.String) {
@@ -448,7 +450,7 @@ let Token = (() => {
448
450
  return this.#accum;
449
451
  case 'built':
450
452
  return this.#built;
451
- /* istanbul ignore next */
453
+ /* c8 ignore next 2 */
452
454
  case 'stage':
453
455
  return this.#stage;
454
456
  /* PRINT ONLY */
@@ -720,14 +722,13 @@ let Token = (() => {
720
722
  */
721
723
  safeReplaceWith(token) {
722
724
  const { parentNode } = this;
723
- /* istanbul ignore next */
725
+ /* c8 ignore start */
724
726
  if (!parentNode) {
725
727
  throw new Error('The node does not have a parent node!');
726
728
  }
727
729
  else if (token.constructor !== this.constructor) {
728
730
  this.typeError('safeReplaceWith', this.constructor.name);
729
731
  }
730
- /* istanbul ignore next */
731
732
  try {
732
733
  strict_1.default.deepEqual(token.getAcceptable(), this.getAcceptable());
733
734
  }
@@ -737,6 +738,7 @@ let Token = (() => {
737
738
  }
738
739
  throw e;
739
740
  }
741
+ /* c8 ignore stop */
740
742
  const i = parentNode.childNodes.indexOf(this);
741
743
  super.removeAt.call(parentNode, i);
742
744
  super.insertAt.call(parentNode, token, i);
@@ -746,7 +748,7 @@ let Token = (() => {
746
748
  const e = new Event('replace', { bubbles: true });
747
749
  token.dispatchEvent(e, { type: 'replace', position: i, oldToken: this });
748
750
  }
749
- /* istanbul ignore next */
751
+ /* c8 ignore start */
750
752
  /**
751
753
  * Create an HTML comment
752
754
  *
@@ -757,6 +759,7 @@ let Token = (() => {
757
759
  require('../addon/token');
758
760
  return this.createComment(data);
759
761
  }
762
+ /* c8 ignore stop */
760
763
  /**
761
764
  * Create a tag
762
765
  *
@@ -807,7 +810,7 @@ let Token = (() => {
807
810
  * 深拷贝节点
808
811
  */
809
812
  cloneNode() {
810
- /* istanbul ignore if */
813
+ /* c8 ignore next 3 */
811
814
  if (this.constructor !== Token) {
812
815
  this.constructorError('does not specify a cloneNode method');
813
816
  }
@@ -824,7 +827,7 @@ let Token = (() => {
824
827
  return token;
825
828
  });
826
829
  }
827
- /* istanbul ignore next */
830
+ /* c8 ignore start */
828
831
  /**
829
832
  * Get all sections
830
833
  *
@@ -834,6 +837,7 @@ let Token = (() => {
834
837
  require('../addon/token');
835
838
  return this.sections();
836
839
  }
840
+ /* c8 ignore stop */
837
841
  /**
838
842
  * Get a section
839
843
  *
@@ -843,7 +847,7 @@ let Token = (() => {
843
847
  section(n) {
844
848
  return this.sections()?.[n];
845
849
  }
846
- /* istanbul ignore next */
850
+ /* c8 ignore start */
847
851
  /**
848
852
  * Get the enclosing HTML tags
849
853
  *
@@ -854,6 +858,7 @@ let Token = (() => {
854
858
  require('../addon/token');
855
859
  return this.findEnclosingHtml(tag);
856
860
  }
861
+ /* c8 ignore stop */
857
862
  /**
858
863
  * Get all categories
859
864
  *
@@ -105,7 +105,7 @@ let LinkBaseToken = (() => {
105
105
  set interwiki(interwiki) {
106
106
  if ((0, debug_1.isLink)(this.type)) {
107
107
  const { prefix, main, fragment } = this.#title, link = `${interwiki}:${prefix}${main}${fragment === undefined ? '' : `#${fragment}`}`;
108
- /* istanbul ignore if */
108
+ /* c8 ignore next 3 */
109
109
  if (interwiki && !this.isInterwiki(link)) {
110
110
  throw new RangeError(`${interwiki} is not a valid interwiki prefix!`);
111
111
  }
@@ -188,7 +188,8 @@ let LinkBaseToken = (() => {
188
188
  if (key === 'bracket') {
189
189
  this.#bracket = value;
190
190
  }
191
- else /* istanbul ignore if */ if (key === 'title') {
191
+ else if (key === 'title') {
192
+ /* c8 ignore next */
192
193
  this.#title = value;
193
194
  }
194
195
  else {
@@ -267,9 +268,9 @@ let LinkBaseToken = (() => {
267
268
  PRINT: return super.print(this.#bracket ? { pre: '[[', post: ']]', sep: this.#delimiter } : { sep: this.#delimiter });
268
269
  }
269
270
  /** @private */
270
- json(_, start = this.getAbsoluteIndex()) {
271
+ json(_, depth, start = this.getAbsoluteIndex()) {
271
272
  LSP: {
272
- const json = super.json(undefined, start), { type, fragment } = this;
273
+ const json = super.json(undefined, depth, start), { type, fragment } = this;
273
274
  if (fragment !== undefined && (type === 'link' || type === 'redirect-target')) {
274
275
  json['fragment'] = fragment;
275
276
  }
@@ -286,7 +287,7 @@ let LinkBaseToken = (() => {
286
287
  return token;
287
288
  });
288
289
  }
289
- /* istanbul ignore next */
290
+ /* c8 ignore start */
290
291
  /**
291
292
  * Set the link target
292
293
  *
@@ -297,7 +298,8 @@ let LinkBaseToken = (() => {
297
298
  require('../../addon/link');
298
299
  this.setTarget(link);
299
300
  }
300
- /* istanbul ignore next */
301
+ /* c8 ignore stop */
302
+ /* c8 ignore start */
301
303
  /**
302
304
  * Set the fragment
303
305
  *
@@ -308,6 +310,7 @@ let LinkBaseToken = (() => {
308
310
  require('../../addon/link');
309
311
  this.setFragment(fragment);
310
312
  }
313
+ /* c8 ignore stop */
311
314
  /**
312
315
  * Set the link text
313
316
  *
@@ -339,7 +342,7 @@ let LinkBaseToken = (() => {
339
342
  })
340
343
  : (0, string_1.sanitize)(this.innerText)}</a>`;
341
344
  }
342
- /* istanbul ignore next */
345
+ /* c8 ignore next */
343
346
  return '';
344
347
  }
345
348
  };
@@ -68,7 +68,7 @@ let CategoryToken = (() => {
68
68
  /** sort key / 分类排序关键字 */
69
69
  get sortkey() {
70
70
  LSP: {
71
- const { childNodes: [, child] } = this;
71
+ const [, child] = this.childNodes;
72
72
  return child && (0, string_1.decodeHtml)(child.text());
73
73
  }
74
74
  }
@@ -88,9 +88,9 @@ let CategoryToken = (() => {
88
88
  }
89
89
  /* NOT FOR BROWSER END */
90
90
  /** @private */
91
- json(_, start = this.getAbsoluteIndex()) {
91
+ json(_, depth, start = this.getAbsoluteIndex()) {
92
92
  LSP: {
93
- const json = super.json(undefined, start), { sortkey } = this;
93
+ const json = super.json(undefined, depth, start), { sortkey } = this;
94
94
  if (sortkey) {
95
95
  json['sortkey'] = sortkey;
96
96
  }
@@ -330,9 +330,9 @@ let FileToken = (() => {
330
330
  LINT: return this.getArg(key)?.getValue();
331
331
  }
332
332
  /** @private */
333
- json(_, start = this.getAbsoluteIndex()) {
333
+ json(_, depth, start = this.getAbsoluteIndex()) {
334
334
  LSP: {
335
- const json = super.json(undefined, start), { extension } = this;
335
+ const json = super.json(undefined, depth, start), { extension } = this;
336
336
  if (extension) {
337
337
  json['extension'] = extension;
338
338
  }
@@ -460,12 +460,12 @@ let FileToken = (() => {
460
460
  return;
461
461
  }
462
462
  const config = this.getAttribute('config'), syntax = key === 'caption' ? '$1' : Object.entries(config.img).find(([, name]) => name === key)?.[0];
463
- /* istanbul ignore if */
463
+ /* c8 ignore next 3 */
464
464
  if (syntax === undefined) {
465
465
  throw new RangeError(`Unknown image parameter: ${key}`);
466
466
  }
467
467
  const free = syntax.includes('$1');
468
- /* istanbul ignore if */
468
+ /* c8 ignore next 3 */
469
469
  if (value === true && free) {
470
470
  this.typeError('setValue', 'String');
471
471
  }
@@ -478,7 +478,7 @@ let FileToken = (() => {
478
478
  }
479
479
  this.insertAt(parameter);
480
480
  }
481
- /* istanbul ignore next */
481
+ /* c8 ignore start */
482
482
  /**
483
483
  * @override
484
484
  * @throws `Error` 不适用于图片
@@ -486,6 +486,7 @@ let FileToken = (() => {
486
486
  setLinkText() {
487
487
  throw new Error('LinkBaseToken.setLinkText method is not applicable to images!');
488
488
  }
489
+ /* c8 ignore stop */
489
490
  /** @private */
490
491
  toHtmlInternal(opt) {
491
492
  const { link, width, height, type } = this, file = this.getAttribute('title'), fr = this.getFrame(), manual = fr instanceof title_1.Title, visibleCaption = manual || fr === 'thumbnail' || fr === 'framed' || type === 'gallery-image', caption = this.getArg('caption')?.toHtmlInternal({
@@ -58,7 +58,7 @@ class LinkToken extends base_1.LinkBaseToken {
58
58
  }
59
59
  }
60
60
  /* NOT FOR BROWSER */
61
- /* istanbul ignore next */
61
+ /* c8 ignore start */
62
62
  /**
63
63
  * Set the interlanguage link
64
64
  *
@@ -71,7 +71,8 @@ class LinkToken extends base_1.LinkBaseToken {
71
71
  require('../../addon/link');
72
72
  this.setLangLink(lang, link);
73
73
  }
74
- /* istanbul ignore next */
74
+ /* c8 ignore stop */
75
+ /* c8 ignore start */
75
76
  /**
76
77
  * Convert to a self link
77
78
  *
@@ -83,7 +84,8 @@ class LinkToken extends base_1.LinkBaseToken {
83
84
  require('../../addon/link');
84
85
  this.asSelfLink(fragment);
85
86
  }
86
- /* istanbul ignore next */
87
+ /* c8 ignore stop */
88
+ /* c8 ignore start */
87
89
  /**
88
90
  * Automatically generate the link text after the pipe
89
91
  *