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
package/dist/src/index.js CHANGED
@@ -181,6 +181,7 @@ let Token = (() => {
181
181
  'converter-rule-to',
182
182
  'converter-rule-from',
183
183
  ];
184
+ /* istanbul ignore if */
184
185
  if (!plainTypes.includes(value)) {
185
186
  throw new RangeError(`"${value}" is not a valid type for ${this.constructor.name}!`);
186
187
  }
@@ -222,7 +223,7 @@ let Token = (() => {
222
223
  if (n < this.#stage || this.length !== 1 || !this.isPlain()) {
223
224
  return this;
224
225
  }
225
- else if (this.#stage >= constants_1.MAX_STAGE) {
226
+ else /* istanbul ignore if */ if (this.#stage >= constants_1.MAX_STAGE) {
226
227
  /* NOt FOR BROWSER */
227
228
  if (this.type === 'root') {
228
229
  index_1.default.error('Fully parsed!');
@@ -285,9 +286,12 @@ let Token = (() => {
285
286
  if (i % 2 === 0) {
286
287
  return s && new text_1.AstText(s);
287
288
  }
288
- else if (isNaN(s.slice(-1))) {
289
- return this.#accum[Number(s.slice(0, -1))];
289
+ const n = Number(s.slice(0, -1));
290
+ if (isNaN(s.slice(-1))
291
+ && Number.isInteger(n) && n >= 0 && n < this.#accum.length) {
292
+ return this.#accum[n];
290
293
  }
294
+ /* istanbul ignore next */
291
295
  throw new Error(`Failed to build! Unrecognized token: ${s}`);
292
296
  }).filter(node => node !== '');
293
297
  if (type === constants_1.BuildMethod.String) {
@@ -336,7 +340,7 @@ let Token = (() => {
336
340
  #parseRedirect() {
337
341
  const { parseRedirect } = require('../parser/redirect');
338
342
  const wikitext = this.firstChild.toString(), parsed = parseRedirect(wikitext, this.#config, this.#accum);
339
- if (parsed) {
343
+ if (parsed !== false) {
340
344
  this.setText(parsed);
341
345
  }
342
346
  return Boolean(parsed);
@@ -392,9 +396,6 @@ let Token = (() => {
392
396
  * @param tidy 是否整理
393
397
  */
394
398
  #parseQuotes(tidy) {
395
- if (this.#config.excludes.includes('quote')) {
396
- return;
397
- }
398
399
  const { parseQuotes } = require('../parser/quotes');
399
400
  const lines = this.firstChild.toString().split('\n');
400
401
  for (let i = 0; i < lines.length; i++) {
@@ -404,17 +405,11 @@ let Token = (() => {
404
405
  }
405
406
  /** 解析外部链接 */
406
407
  #parseExternalLinks() {
407
- if (this.#config.excludes.includes('extLink')) {
408
- return;
409
- }
410
408
  const { parseExternalLinks } = require('../parser/externalLinks');
411
409
  this.setText(parseExternalLinks(this.firstChild.toString(), this.#config, this.#accum));
412
410
  }
413
411
  /** 解析自由外链 */
414
412
  #parseMagicLinks() {
415
- if (this.#config.excludes.includes('magicLink')) {
416
- return;
417
- }
418
413
  const { parseMagicLinks } = require('../parser/magicLinks');
419
414
  this.setText(parseMagicLinks(this.firstChild.toString(), this.#config, this.#accum));
420
415
  }
@@ -453,6 +448,7 @@ let Token = (() => {
453
448
  return this.#accum;
454
449
  case 'built':
455
450
  return this.#built;
451
+ /* istanbul ignore next */
456
452
  case 'stage':
457
453
  return this.#stage;
458
454
  /* PRINT ONLY */
@@ -490,12 +486,12 @@ let Token = (() => {
490
486
  }
491
487
  }
492
488
  insertAt(child, i = this.length) {
493
- const token = typeof child === 'string' ? new text_1.AstText(child) : child;
489
+ const token = typeof child === 'string' ? new text_1.AstText(child) : child, { length } = this;
490
+ i += i < 0 ? length : 0;
494
491
  /* NOT FOR BROWSER */
495
492
  const acceptable = this.getAcceptable();
496
493
  if (!debug_1.Shadow.running && acceptable) {
497
- const { length, childNodes } = this, nodesAfter = childNodes.slice(i), insertedName = token.constructor.name;
498
- i += i < 0 ? length : 0;
494
+ const nodesAfter = this.childNodes.slice(i), insertedName = token.constructor.name;
499
495
  if (!acceptable[insertedName]?.has(i, length + 1)) {
500
496
  this.constructorError(`cannot insert a ${insertedName} at position ${i}`);
501
497
  }
@@ -510,7 +506,7 @@ let Token = (() => {
510
506
  constructor, } = token;
511
507
  /* NOT FOR BROWSER */
512
508
  const e = new Event('insert', { bubbles: true });
513
- this.dispatchEvent(e, { type: 'insert', position: i < 0 ? i + this.length - 1 : i });
509
+ this.dispatchEvent(e, { type: 'insert', position: i });
514
510
  if (type !== 'list-range' && constructor === Token && this.isPlain()) {
515
511
  index_1.default.warn('You are inserting a plain token as a child of another plain token. '
516
512
  + 'Consider calling Token.flatten method afterwards.');
@@ -521,7 +517,14 @@ let Token = (() => {
521
517
  }
522
518
  return token;
523
519
  }
524
- /** @private */
520
+ // eslint-disable-next-line jsdoc/require-param
521
+ /**
522
+ * Normalize page title
523
+ *
524
+ * 规范化页面标题
525
+ * @param title title (with or without the namespace prefix) / 标题(含或不含命名空间前缀)
526
+ * @param defaultNs default namespace number / 命名空间
527
+ */
525
528
  normalizeTitle(title, defaultNs = 0, opt) {
526
529
  return index_1.default.normalizeTitle(title, defaultNs, this.getAttribute('include'), this.#config, { page: this.pageName, ...opt });
527
530
  }
@@ -582,8 +585,12 @@ let Token = (() => {
582
585
  let mt = regex.exec(wikitext);
583
586
  while (mt) {
584
587
  const { 1: type, index } = mt, detail = mt[2]?.trim();
588
+ let line;
589
+ if (type === 'disable-line' || type === 'disable-next-line') {
590
+ line = this.posFromIndex(index).top + (type === 'disable-line' ? 0 : 1);
591
+ }
585
592
  ignores.push({
586
- line: this.posFromIndex(index).top + (type === 'disable-line' ? 0 : 1),
593
+ line,
587
594
  from: type === 'disable' ? regex.lastIndex : undefined,
588
595
  to: type === 'enable' ? regex.lastIndex : undefined,
589
596
  rules: detail ? new Set(detail.split(',').map(rule => rule.trim())) : undefined,
@@ -593,13 +600,13 @@ let Token = (() => {
593
600
  errors = errors.filter(({ rule, startLine, startIndex }) => {
594
601
  const nearest = { pos: 0 };
595
602
  for (const { line, from, to, rules } of ignores) {
596
- if (line > startLine + 1) {
603
+ if (line && line > startLine + 1) {
597
604
  break;
598
605
  }
599
606
  else if (rules && !rules.has(rule)) {
600
607
  continue;
601
608
  }
602
- else if (line === startLine && from === undefined && to === undefined) {
609
+ else if (line === startLine) {
603
610
  return false;
604
611
  }
605
612
  else if (from <= startIndex && from > nearest.pos) {
@@ -713,12 +720,14 @@ let Token = (() => {
713
720
  */
714
721
  safeReplaceWith(token) {
715
722
  const { parentNode } = this;
723
+ /* istanbul ignore next */
716
724
  if (!parentNode) {
717
725
  throw new Error('The node does not have a parent node!');
718
726
  }
719
727
  else if (token.constructor !== this.constructor) {
720
728
  this.typeError('safeReplaceWith', this.constructor.name);
721
729
  }
730
+ /* istanbul ignore next */
722
731
  try {
723
732
  strict_1.default.deepEqual(token.getAcceptable(), this.getAcceptable());
724
733
  }
@@ -737,6 +746,7 @@ let Token = (() => {
737
746
  const e = new Event('replace', { bubbles: true });
738
747
  token.dispatchEvent(e, { type: 'replace', position: i, oldToken: this });
739
748
  }
749
+ /* istanbul ignore next */
740
750
  /**
741
751
  * Create an HTML comment
742
752
  *
@@ -797,6 +807,7 @@ let Token = (() => {
797
807
  * 深拷贝节点
798
808
  */
799
809
  cloneNode() {
810
+ /* istanbul ignore if */
800
811
  if (this.constructor !== Token) {
801
812
  this.constructorError('does not specify a cloneNode method');
802
813
  }
@@ -813,6 +824,7 @@ let Token = (() => {
813
824
  return token;
814
825
  });
815
826
  }
827
+ /* istanbul ignore next */
816
828
  /**
817
829
  * Get all sections
818
830
  *
@@ -831,6 +843,7 @@ let Token = (() => {
831
843
  section(n) {
832
844
  return this.sections()?.[n];
833
845
  }
846
+ /* istanbul ignore next */
834
847
  /**
835
848
  * Get the enclosing HTML tags
836
849
  *
@@ -11,7 +11,7 @@ import type { Title } from '../../lib/title';
11
11
  export declare abstract class LinkBaseToken extends Token {
12
12
  #private;
13
13
  readonly name: string;
14
- abstract get type(): 'link' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'redirect-target';
14
+ abstract get type(): 'link' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'redirect-target' | 'ext-inner';
15
15
  readonly childNodes: readonly [AtomToken, ...Token[]];
16
16
  abstract get firstChild(): AtomToken;
17
17
  abstract get lastChild(): Token;
@@ -137,24 +137,31 @@ let LinkBaseToken = (() => {
137
137
  /* NOT FOR BROWSER */
138
138
  this.protectChildren(0);
139
139
  }
140
+ /** 更新name */
141
+ #setName() {
142
+ if (this.type !== 'ext-inner') {
143
+ this.setAttribute('name', this.#title.title);
144
+ }
145
+ }
140
146
  /** @private */
141
147
  afterBuild() {
142
148
  this.#title = this.getTitle();
143
149
  if (this.#delimiter.includes('\0')) {
144
150
  this.#delimiter = this.buildFromStr(this.#delimiter, constants_1.BuildMethod.String);
145
151
  }
146
- this.setAttribute('name', this.#title.title);
152
+ this.#setName();
147
153
  super.afterBuild();
148
154
  /* NOT FOR BROWSER */
149
155
  const /** @implements */ linkListener = (e, data) => {
150
156
  const { prevTarget } = e, { type } = this;
151
- if (prevTarget?.is('link-target')) {
152
- const name = prevTarget.text(), titleObj = this.getTitle(), { title, interwiki, ns, valid } = titleObj;
157
+ if (prevTarget?.is('link-target')
158
+ && !(this.is('ext-inner') && this.parentNode?.selfClosing)) {
159
+ const name = prevTarget.text(), titleObj = this.getTitle(), { interwiki, ns, valid } = titleObj;
153
160
  if (!valid) {
154
161
  (0, debug_1.undo)(e, data);
155
162
  throw new Error(`Invalid link target: ${name}`);
156
163
  }
157
- else if (type === 'category' && (interwiki || ns !== 14)
164
+ else if ((type === 'category' || type === 'ext-inner') && (interwiki || ns !== 14)
158
165
  || (type === 'file' || type === 'gallery-image' || type === 'imagemap-image')
159
166
  && (interwiki || ns !== 6)) {
160
167
  (0, debug_1.undo)(e, data);
@@ -171,7 +178,7 @@ let LinkBaseToken = (() => {
171
178
  }
172
179
  }
173
180
  this.#title = titleObj;
174
- this.setAttribute('name', title);
181
+ this.#setName();
175
182
  }
176
183
  };
177
184
  this.addEventListener(['remove', 'insert', 'replace', 'text'], linkListener);
@@ -0,0 +1,25 @@
1
+ import { LinkBaseToken } from './base';
2
+ import type { Config, LintError } from '../../base';
3
+ import type { Title } from '../../lib/title';
4
+ import type { Token, AtomToken, AttributesToken, ExtToken, AstNodes } from '../../internal';
5
+ /**
6
+ * `<categorytree>`
7
+ * @classdesc `{childNodes: [AtomToken]}`
8
+ */
9
+ export declare abstract class CategorytreeToken extends LinkBaseToken {
10
+ readonly childNodes: readonly [AtomToken];
11
+ abstract get lastChild(): AtomToken;
12
+ abstract get nextSibling(): undefined;
13
+ abstract get previousSibling(): AttributesToken | undefined;
14
+ abstract get parentNode(): ExtToken | undefined;
15
+ abstract get link(): Title;
16
+ abstract get children(): [AtomToken];
17
+ abstract get lastElementChild(): AtomToken;
18
+ abstract get previousElementSibling(): AttributesToken | undefined;
19
+ abstract get nextElementSibling(): undefined;
20
+ abstract get parentElement(): ExtToken | undefined;
21
+ abstract set link(link: string);
22
+ get type(): 'ext-inner';
23
+ /** @param link 链接标题 */
24
+ constructor(link: string, linkText?: undefined, config?: Config, accum?: Token[]);
25
+ }
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
3
+ var useValue = arguments.length > 2;
4
+ for (var i = 0; i < initializers.length; i++) {
5
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6
+ }
7
+ return useValue ? value : void 0;
8
+ };
9
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
10
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
11
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
12
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
13
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
14
+ var _, done = false;
15
+ for (var i = decorators.length - 1; i >= 0; i--) {
16
+ var context = {};
17
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
18
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
19
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
20
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
21
+ if (kind === "accessor") {
22
+ if (result === void 0) continue;
23
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
24
+ if (_ = accept(result.get)) descriptor.get = _;
25
+ if (_ = accept(result.set)) descriptor.set = _;
26
+ if (_ = accept(result.init)) initializers.unshift(_);
27
+ }
28
+ else if (_ = accept(result)) {
29
+ if (kind === "field") initializers.unshift(_);
30
+ else descriptor[key] = _;
31
+ }
32
+ }
33
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
34
+ done = true;
35
+ };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.CategorytreeToken = void 0;
41
+ const lint_1 = require("../../util/lint");
42
+ const padded_1 = require("../../mixin/padded");
43
+ const index_1 = __importDefault(require("../../index"));
44
+ const base_1 = require("./base");
45
+ /* NOT FOR BROWSER */
46
+ const constants_1 = require("../../util/constants");
47
+ const cached_1 = require("../../mixin/cached");
48
+ const fixed_1 = require("../../mixin/fixed");
49
+ /* NOT FOR BROWSER END */
50
+ /**
51
+ * `<categorytree>`
52
+ * @classdesc `{childNodes: [AtomToken]}`
53
+ */
54
+ let CategorytreeToken = (() => {
55
+ let _classDecorators = [fixed_1.fixedToken, (0, padded_1.padded)('')];
56
+ let _classDescriptor;
57
+ let _classExtraInitializers = [];
58
+ let _classThis;
59
+ let _classSuper = base_1.LinkBaseToken;
60
+ let _instanceExtraInitializers = [];
61
+ let _toHtmlInternal_decorators;
62
+ var CategorytreeToken = class extends _classSuper {
63
+ static { _classThis = this; }
64
+ static {
65
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
66
+ _toHtmlInternal_decorators = [(0, cached_1.cached)()];
67
+ __esDecorate(this, null, _toHtmlInternal_decorators, { kind: "method", name: "toHtmlInternal", static: false, private: false, access: { has: obj => "toHtmlInternal" in obj, get: obj => obj.toHtmlInternal }, metadata: _metadata }, null, _instanceExtraInitializers);
68
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
69
+ CategorytreeToken = _classThis = _classDescriptor.value;
70
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
71
+ __runInitializers(_classThis, _classExtraInitializers);
72
+ }
73
+ /* NOT FOR BROWSER END */
74
+ get type() {
75
+ return 'ext-inner';
76
+ }
77
+ /** @param link 链接标题 */
78
+ constructor(link, linkText, config, accum = []) {
79
+ super(link, linkText, config, accum);
80
+ __runInitializers(this, _instanceExtraInitializers);
81
+ this.setAttribute('bracket', false);
82
+ /* NOT FOR BROWSER */
83
+ // @ts-expect-error abstract getter override
84
+ this.firstChild.setAttribute('acceptable', { AstText: 0 });
85
+ }
86
+ /** @private */
87
+ getTitle() {
88
+ const target = this.firstChild.toString().trim(), opt = { halfParsed: true }, title = this.normalizeTitle(target, 14, opt);
89
+ return title.valid && title.ns === 14
90
+ && !title.interwiki
91
+ ? title
92
+ : this.normalizeTitle(`Category:${target}`, 0, opt);
93
+ }
94
+ /** @private */
95
+ lint(start = this.getAbsoluteIndex()) {
96
+ LINT: {
97
+ const rule = 'no-ignored', s = index_1.default.lintConfig.getSeverity(rule, 'categorytree');
98
+ if (s) {
99
+ const { link } = this;
100
+ if (!link.valid || link.ns !== 14
101
+ || link.interwiki) {
102
+ return [(0, lint_1.generateForSelf)(this, { start }, rule, 'invalid-category', s)];
103
+ }
104
+ }
105
+ return super.lint(start, false);
106
+ }
107
+ }
108
+ /* NOT FOR BROWSER */
109
+ /** @private */
110
+ toHtmlInternal() {
111
+ return '';
112
+ }
113
+ /** @private */
114
+ safeReplaceChildren(elements) {
115
+ if (elements.length === 0) {
116
+ this.firstChild.replaceChildren();
117
+ }
118
+ else {
119
+ super.safeReplaceChildren(elements);
120
+ }
121
+ }
122
+ };
123
+ return CategorytreeToken = _classThis;
124
+ })();
125
+ exports.CategorytreeToken = CategorytreeToken;
126
+ constants_1.classes['CategorytreeToken'] = __filename;
@@ -1,6 +1,6 @@
1
1
  import { LinkBaseToken } from './base';
2
2
  import { ImageParameterToken } from '../imageParameter';
3
- import type { Config, LintError, AST } from '../../base';
3
+ import type { TokenTypes, Config, LintError, AST } from '../../base';
4
4
  import type { Token, AtomToken } from '../../internal';
5
5
  import { Title } from '../../lib/title';
6
6
  /**
@@ -45,8 +45,9 @@ export declare abstract class FileToken extends LinkBaseToken {
45
45
  * @param link 文件名
46
46
  * @param text 图片参数
47
47
  * @param delimiter `|`
48
+ * @param type 节点类型
48
49
  */
49
- constructor(link: string, text?: string, config?: Config, accum?: Token[], delimiter?: string);
50
+ constructor(link: string, text?: string, config?: Config, accum?: Token[], delimiter?: string, type?: TokenTypes);
50
51
  /**
51
52
  * Get all image parameter tokens
52
53
  *
@@ -173,8 +173,9 @@ let FileToken = (() => {
173
173
  * @param link 文件名
174
174
  * @param text 图片参数
175
175
  * @param delimiter `|`
176
+ * @param type 节点类型
176
177
  */
177
- constructor(link, text, config, accum = [], delimiter = '|') {
178
+ constructor(link, text, config, accum = [], delimiter = '|', type) {
178
179
  super(link, undefined, config, accum, delimiter);
179
180
  __runInitializers(this, _instanceExtraInitializers);
180
181
  /* NOT FOR BROWSER */
@@ -184,7 +185,7 @@ let FileToken = (() => {
184
185
  /-\{|\}-|\|/gu; // eslint-disable-line @typescript-eslint/no-unused-expressions
185
186
  this.safeAppend(explode(text).map(
186
187
  // @ts-expect-error abstract class
187
- (part) => new imageParameter_1.ImageParameterToken(part, extension, config, accum)));
188
+ (part) => new imageParameter_1.ImageParameterToken(part, extension, type, config, accum)));
188
189
  }
189
190
  /** @private */
190
191
  lint(start = this.getAbsoluteIndex(), re) {
@@ -470,7 +471,7 @@ let FileToken = (() => {
470
471
  }
471
472
  const parameter = debug_1.Shadow.run(() =>
472
473
  // @ts-expect-error abstract class
473
- new imageParameter_1.ImageParameterToken(syntax.replace('$1', key === 'width' ? '1' : ''), this.extension, config));
474
+ new imageParameter_1.ImageParameterToken(syntax.replace('$1', key === 'width' ? '1' : ''), this.extension, this.type, config));
474
475
  if (free) {
475
476
  const { childNodes } = index_1.default.parseWithRef(value, this);
476
477
  parameter.safeReplaceChildren(childNodes);
@@ -99,9 +99,10 @@ let GalleryImageToken = (() => {
99
99
  }
100
100
  accum.splice(length, 1);
101
101
  }
102
- super(link, token?.firstChild.toString(), config, accum);
102
+ const privateType = `${type}-image`;
103
+ super(link, token?.firstChild.toString(), config, accum, undefined, privateType);
103
104
  this.setAttribute('bracket', false);
104
- this.privateType = `${type}-image`;
105
+ this.privateType = privateType;
105
106
  /* PRINT ONLY */
106
107
  this.seal('privateType', true);
107
108
  }
@@ -112,11 +113,9 @@ let GalleryImageToken = (() => {
112
113
  }
113
114
  /** 判定无效的图片 */
114
115
  #lint() {
115
- const { ns,
116
- /* NOT FOR BROWSER */
117
- interwiki, } = this.getAttribute('title');
118
- return ns !== 6
119
- || Boolean(interwiki);
116
+ const title = this.getAttribute('title');
117
+ return title.ns !== 6
118
+ || Boolean(title.interwiki);
120
119
  }
121
120
  /** @private */
122
121
  lint(start = this.getAbsoluteIndex(), re) {
@@ -4,9 +4,7 @@ import { CommentLineToken } from '../nowiki/commentLine';
4
4
  import type { Config, LintError, AST } from '../../base';
5
5
  import type { AstText, Token, AstNodes } from '../../internal';
6
6
  /**
7
- * gallery tag
8
- *
9
- * gallery标签
7
+ * `<gallery>`
10
8
  * @classdesc `{childNodes: (GalleryImageToken|CommentLineToken|AstText)[]}`
11
9
  */
12
10
  export declare abstract class GalleryToken extends MultiLineToken {
@@ -36,7 +34,6 @@ export declare abstract class GalleryToken extends MultiLineToken {
36
34
  get heights(): number;
37
35
  /** @param inner 标签内部wikitext */
38
36
  constructor(inner?: string, config?: Config, accum?: Token[]);
39
- cloneNode(): this;
40
37
  /**
41
38
  * Insert an image
42
39
  *
@@ -47,26 +47,20 @@ const commentLine_1 = require("../nowiki/commentLine");
47
47
  const debug_1 = require("../../util/debug");
48
48
  const constants_1 = require("../../util/constants");
49
49
  const html_1 = require("../../util/html");
50
- const clone_1 = require("../../mixin/clone");
51
50
  const cached_1 = require("../../mixin/cached");
52
51
  /* NOT FOR BROWSER END */
53
52
  /**
54
- * gallery tag
55
- *
56
- * gallery标签
53
+ * `<gallery>`
57
54
  * @classdesc `{childNodes: (GalleryImageToken|CommentLineToken|AstText)[]}`
58
55
  */
59
56
  let GalleryToken = (() => {
60
57
  let _classSuper = index_2.MultiLineToken;
61
58
  let _instanceExtraInitializers = [];
62
- let _cloneNode_decorators;
63
59
  let _toHtmlInternal_decorators;
64
60
  return class GalleryToken extends _classSuper {
65
61
  static {
66
62
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
67
- _cloneNode_decorators = [clone_1.clone];
68
63
  _toHtmlInternal_decorators = [(0, cached_1.cached)()];
69
- __esDecorate(this, null, _cloneNode_decorators, { kind: "method", name: "cloneNode", static: false, private: false, access: { has: obj => "cloneNode" in obj, get: obj => obj.cloneNode }, metadata: _metadata }, null, _instanceExtraInitializers);
70
64
  __esDecorate(this, null, _toHtmlInternal_decorators, { kind: "method", name: "toHtmlInternal", static: false, private: false, access: { has: obj => "toHtmlInternal" in obj, get: obj => obj.toHtmlInternal }, metadata: _metadata }, null, _instanceExtraInitializers);
71
65
  if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
72
66
  }
@@ -194,10 +188,6 @@ let GalleryToken = (() => {
194
188
  }
195
189
  /* PRINT ONLY END */
196
190
  /* NOT FOR BROWSER */
197
- cloneNode() {
198
- // @ts-expect-error abstract class
199
- return new GalleryToken(undefined, this.getAttribute('config'));
200
- }
201
191
  /**
202
192
  * Insert an image
203
193
  *
@@ -21,5 +21,4 @@ export declare abstract class ImagemapToken extends MultiLineToken {
21
21
  get image(): GalleryImageToken | undefined;
22
22
  /** @param inner 标签内部wikitext */
23
23
  constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
24
- cloneNode(): this;
25
24
  }