wikiparser-node 1.41.0 → 1.43.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 (64) hide show
  1. package/README.md +43 -18
  2. package/bundle/bundle-es8.min.js +27 -27
  3. package/bundle/bundle-lsp.min.js +28 -28
  4. package/bundle/bundle.min.js +19 -19
  5. package/dist/addon/attribute.js +5 -7
  6. package/dist/addon/link.js +3 -2
  7. package/dist/addon/transclude.js +17 -29
  8. package/dist/bin/config.js +1 -1
  9. package/dist/extensions/typings.d.ts +1 -1
  10. package/dist/index.js +1 -2
  11. package/dist/lib/document.js +5 -5
  12. package/dist/lib/element.d.ts +3 -8
  13. package/dist/lib/element.js +2 -26
  14. package/dist/lib/lsp.d.ts +2 -0
  15. package/dist/lib/lsp.js +8 -20
  16. package/dist/lib/node.d.ts +2 -0
  17. package/dist/lib/node.js +0 -7
  18. package/dist/lib/range.d.ts +0 -7
  19. package/dist/lib/range.js +5 -14
  20. package/dist/lib/ranges.js +2 -2
  21. package/dist/lib/text.js +3 -5
  22. package/dist/map.d.ts +66 -0
  23. package/dist/map.js +2 -0
  24. package/dist/mixin/attributesParent.d.ts +4 -3
  25. package/dist/mixin/elementLike.d.ts +13 -0
  26. package/dist/mixin/elementLike.js +66 -53
  27. package/dist/parser/selector.js +3 -3
  28. package/dist/render/expand.js +4 -2
  29. package/dist/render/extension.js +139 -8
  30. package/dist/render/html.js +72 -3
  31. package/dist/render/magicWords.js +24 -131
  32. package/dist/src/arg.js +1 -2
  33. package/dist/src/atom.js +1 -1
  34. package/dist/src/attribute.d.ts +2 -2
  35. package/dist/src/attribute.js +17 -13
  36. package/dist/src/attributes.d.ts +3 -3
  37. package/dist/src/attributes.js +30 -14
  38. package/dist/src/converterRule.js +3 -5
  39. package/dist/src/extLink.js +5 -4
  40. package/dist/src/heading.js +12 -5
  41. package/dist/src/imageParameter.js +1 -2
  42. package/dist/src/index.js +4 -5
  43. package/dist/src/link/base.js +3 -5
  44. package/dist/src/link/file.js +7 -8
  45. package/dist/src/link/galleryImage.js +1 -3
  46. package/dist/src/magicLink.js +7 -7
  47. package/dist/src/multiLine/gallery.js +2 -3
  48. package/dist/src/nowiki/doubleUnderscore.d.ts +1 -0
  49. package/dist/src/nowiki/doubleUnderscore.js +4 -1
  50. package/dist/src/nowiki/quote.js +1 -3
  51. package/dist/src/onlyinclude.js +1 -2
  52. package/dist/src/parameter.js +6 -4
  53. package/dist/src/table/index.js +1 -2
  54. package/dist/src/table/td.d.ts +2 -2
  55. package/dist/src/table/td.js +5 -7
  56. package/dist/src/tag/html.js +29 -12
  57. package/dist/src/tagPair/ext.js +4 -1
  58. package/dist/src/tagPair/translate.d.ts +1 -1
  59. package/dist/src/tagPair/translate.js +1 -1
  60. package/dist/src/transclude.js +4 -2
  61. package/dist/util/debug.js +5 -7
  62. package/dist/util/html.js +3 -11
  63. package/extensions/dist/base.js +1 -1
  64. package/package.json +57 -21
@@ -360,7 +360,7 @@ let FileToken = (() => {
360
360
  #getTypedArgs(keys, type) {
361
361
  const args = this.getAllArgs().filter(({ name }) => keys.has(name));
362
362
  if (args.length > 1) {
363
- index_1.default.warn(`The image ${this.name} has ${args.length} ${type} parameters. Only the last ${args[0].name} will take effect!`);
363
+ index_1.default.warn(`The image ${JSON.stringify(this.name)} has ${args.length} ${type} parameters. Only the last ${args[0].name} will take effect!`);
364
364
  }
365
365
  return args;
366
366
  }
@@ -485,8 +485,7 @@ let FileToken = (() => {
485
485
  // @ts-expect-error abstract class
486
486
  new imageParameter_1.ImageParameterToken(syntax.replace('$1', key === 'width' ? '1' : ''), this.extension, this.type, config));
487
487
  if (free) {
488
- const { childNodes } = index_1.default.parseWithRef(value, this);
489
- parameter.safeReplaceChildren(childNodes);
488
+ parameter.safeReplaceChildren(index_1.default.parseWithRef(value, this).childNodes);
490
489
  }
491
490
  this.insertAt(parameter);
492
491
  }
@@ -501,13 +500,13 @@ let FileToken = (() => {
501
500
  /* c8 ignore stop */
502
501
  /** @private */
503
502
  toHtmlInternal(opt) {
504
- 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({
503
+ const { link, width, height, type } = this, file = this.getAttribute('title'), fr = this.getFrame(), manual = fr instanceof title_1.Title, framed = fr === 'framed', visibleCaption = manual || framed || fr === 'thumbnail' || type === 'gallery-image', caption = this.getArg('caption')?.toHtmlInternal({
505
504
  ...opt,
506
505
  nowrap: true,
507
506
  }) ?? '', titleFromCaption = visibleCaption && type !== 'gallery-image' ? '' : (0, string_1.sanitizeAlt)(caption), hasLink = manual || link !== file, title = titleFromCaption || (hasLink && typeof link !== 'string' ? link.getTitleAttr() : ''), titleAttr = title && ` title="${title}"`, alt = (0, string_1.sanitizeAlt)(this.getArg('alt')?.toHtmlInternal({
508
507
  ...opt,
509
508
  nowrap: true,
510
- })) ?? titleFromCaption, horiz = this.getHorizAlign() ?? '', vert = this.getVertAlign() ?? '', className = `${horiz ? `mw-halign-${horiz}` : vert && `mw-valign-${vert}`}${this.getValue('border') ? ' mw-image-border' : ''} ${(0, string_1.sanitizeAlt)(this.getValue('class')) ?? ''}`.trim(), classAttr = className && ` class="${className}"`, hasWidth = isInteger(width), hasHeight = isInteger(height);
509
+ })) ?? titleFromCaption, horiz = this.getHorizAlign() ?? '', vert = this.getVertAlign() ?? '', hasWidth = isInteger(width), hasHeight = isInteger(height), className = `${manual || framed || hasWidth || hasHeight ? '' : 'mw-default-size '}${horiz ? `mw-halign-${horiz}` : vert && `mw-valign-${vert}`}${this.getValue('border') ? ' mw-image-border' : ''} ${(0, string_1.sanitizeAlt)(this.getValue('class')) ?? ''}`.trim(), classAttr = className && ` class="${className}"`;
511
510
  let src;
512
511
  try {
513
512
  src = manual ? fr.getFileUrl() : file.getFileUrl(hasWidth && Number(width), hasHeight && Number(height));
@@ -523,10 +522,10 @@ let FileToken = (() => {
523
522
  if (link === file) {
524
523
  const lang = this.getValue('lang'), page = this.getValue('page');
525
524
  if (lang) {
526
- href += `?lang=${lang}`;
525
+ href += `?lang=${(0, string_1.sanitizeId)(lang)}`;
527
526
  }
528
527
  else if (page) {
529
- href += `?page=${page}`;
528
+ href += `?page=${(0, string_1.sanitizeId)(page)}`;
530
529
  }
531
530
  }
532
531
  }
@@ -540,7 +539,7 @@ let FileToken = (() => {
540
539
  ? `<figure${classAttr} typeof="mw:File${fr ? `/${manual ? 'Thumb' : frame.get(fr)}` : ''}">${a}<figcaption>${caption}</figcaption></figure>`
541
540
  : `<span${classAttr}>${a}</span>`;
542
541
  }
543
- const parent = this.parentNode, mode = parent?.parentNode?.getAttr('mode'), nolines = typeof mode === 'string' && mode.toLowerCase() === 'nolines', padding = nolines ? 0 : 30;
542
+ const parent = this.parentNode, nolines = parent?.parentNode?.getAttr('mode')?.toLowerCase() === 'nolines', padding = nolines ? 0 : 30;
544
543
  return `\t<li class="gallerybox" style="width: ${Number(width) + padding + 5}px">\n\t\t<div class="thumb" style="width: ${Number(width) + padding}px${nolines ? '' : `; height: ${Number(height) + padding}px`}"><span>${a}</span></div>\n\t\t<div class="gallerytext">${parent?.parentNode?.hasAttr('showfilename')
545
544
  ? `<a href="${file.getUrl()}" class="galleryfilename galleryfilename-truncate" title="${file.title}">${file.main}</a>\n`
546
545
  : ''}${caption}</div>\n\t</li>`;
@@ -144,9 +144,7 @@ let GalleryImageToken = (() => {
144
144
  * @param i position to be inserted at / 插入位置
145
145
  */
146
146
  insertAt(child, i) {
147
- if (this.type === 'gallery-image'
148
- && child.is('image-parameter')
149
- && !constants_1.galleryParams.has(child.name)) {
147
+ if (this.type === 'gallery-image' && child.is('image-parameter') && !constants_1.galleryParams.has(child.name)) {
150
148
  child.setAttribute('name', 'invalid');
151
149
  }
152
150
  return super.insertAt(child, i);
@@ -246,7 +246,7 @@ let MagicLinkToken = (() => {
246
246
  .getUrl(articlePath)
247
247
  : new URL(link.startsWith('RFC')
248
248
  ? `https://datatracker.ietf.org/doc/html/rfc${link.slice(4)}`
249
- : `https://pubmed.ncbi.nlm.nih.gov/${link.slice(5)}`);
249
+ : `https://www.ncbi.nlm.nih.gov/pubmed/${link.slice(5)}?dopt=Abstract`);
250
250
  }
251
251
  }
252
252
  /* PRINT ONLY */
@@ -281,8 +281,7 @@ let MagicLinkToken = (() => {
281
281
  * @param url URL containing the protocol / 含协议的网址
282
282
  */
283
283
  setTarget(url) {
284
- const { childNodes } = index_1.default.parseWithRef(url, this, 2);
285
- this.safeReplaceChildren(childNodes);
284
+ this.safeReplaceChildren(index_1.default.parseWithRef(url, this, 2).childNodes);
286
285
  }
287
286
  /**
288
287
  * Check if it is a parameter of a template or magic word
@@ -300,10 +299,11 @@ let MagicLinkToken = (() => {
300
299
  url = this.getUrl();
301
300
  }
302
301
  catch { }
303
- const attrs = type === 'free-ext-link' || type === 'ext-link-url'
304
- ? ` rel="nofollow" class="external${type === 'free-ext-link' ? ' free' : ''}"${typeof url === 'object' ? ` href="${url.href}"` : ''}`
305
- : (protocol === 'ISBN' ? '' : ' class="external" rel="nofollow"')
306
- + (url === undefined ? '' : ` href="${typeof url === 'string' ? url : url.href}"`);
302
+ const isISBN = protocol === 'ISBN', attrs = type === 'free-ext-link' || type === 'ext-link-url'
303
+ ? ` rel="nofollow" class="external free"${typeof url === 'object' ? ` href="${url.href}"` : ''}`
304
+ : (isISBN ? '' : ` class="external mw-magiclink-${protocol.toLowerCase()}" rel="nofollow"`)
305
+ + (url === undefined ? '' : ` href="${typeof url === 'string' ? url : url.href}"`)
306
+ + (isISBN ? ' class="internal mw-magiclink-isbn"' : '');
307
307
  return `<a${attrs}>${innerText}</a>`;
308
308
  }
309
309
  };
@@ -176,7 +176,7 @@ let GalleryToken = (() => {
176
176
  */
177
177
  #getSize(key) {
178
178
  LSP: {
179
- const widths = this.parentNode?.getAttr(key), mt = typeof widths === 'string' && /^(\d+)\s*(?:px)?$/u.exec(widths)?.[1];
179
+ const widths = this.parentNode?.getAttr(key), mt = widths && /^(\d+)\s*(?:px)?$/u.exec(widths)?.[1];
180
180
  return mt && Number(mt) || 120;
181
181
  }
182
182
  }
@@ -208,8 +208,7 @@ let GalleryToken = (() => {
208
208
  throw new SyntaxError(`Invalid file name: ${file}`);
209
209
  }
210
210
  insertAt(token, i = this.length) {
211
- if (!debug_1.Shadow.running
212
- && (typeof token === 'string' ? token.trim() : !token.is('gallery-image'))) {
211
+ if (!debug_1.Shadow.running && (typeof token === 'string' ? token.trim() : !token.is('gallery-image'))) {
213
212
  throw new RangeError('Please do not insert invisible content into <gallery>!');
214
213
  }
215
214
  return super.insertAt(token, i);
@@ -20,4 +20,5 @@ export declare abstract class DoubleUnderscoreToken extends NowikiBaseToken {
20
20
  */
21
21
  constructor(word: string, sensitive: boolean, fullWidth: boolean, config: Config, accum?: Token[]);
22
22
  cloneNode(): this;
23
+ toHtmlInternal(): string;
23
24
  }
@@ -49,7 +49,7 @@ const syntax_1 = require("../../mixin/syntax");
49
49
  * 状态开关
50
50
  */
51
51
  let DoubleUnderscoreToken = (() => {
52
- let _classDecorators = [(0, syntax_1.syntax)(), (0, hidden_1.hiddenToken)(), (0, padded_1.padded)('__')];
52
+ let _classDecorators = [(0, syntax_1.syntax)(), (0, hidden_1.hiddenToken)(true, false), (0, padded_1.padded)('__')];
53
53
  let _classDescriptor;
54
54
  let _classExtraInitializers = [];
55
55
  let _classThis;
@@ -101,6 +101,9 @@ let DoubleUnderscoreToken = (() => {
101
101
  // @ts-expect-error abstract class
102
102
  return debug_1.Shadow.run(() => new DoubleUnderscoreToken(this.innerText, this.#sensitive, this.#fullWidth, this.getAttribute('config')));
103
103
  }
104
+ toHtmlInternal() {
105
+ return this.tocData ?? '';
106
+ }
104
107
  };
105
108
  return DoubleUnderscoreToken = _classThis;
106
109
  })();
@@ -113,9 +113,7 @@ let QuoteToken = (() => {
113
113
  /** @private */
114
114
  text() {
115
115
  const { parentNode, innerText } = this;
116
- return parentNode?.is('image-parameter') && parentNode.name !== 'caption'
117
- ? ''
118
- : innerText;
116
+ return parentNode?.is('image-parameter') && parentNode.name !== 'caption' ? '' : innerText;
119
117
  }
120
118
  /** @private */
121
119
  lint(start = this.getAbsoluteIndex()) {
@@ -85,8 +85,7 @@ let OnlyincludeToken = (() => {
85
85
  if (text.includes('</onlyinclude>')) {
86
86
  throw new RangeError('"</onlyinclude>" is not allowed in the text!');
87
87
  }
88
- const { childNodes } = index_2.default.parseWithRef(text, this, undefined, true);
89
- this.safeReplaceChildren(childNodes);
88
+ this.safeReplaceChildren(index_2.default.parseWithRef(text, this, undefined, true).childNodes);
90
89
  }
91
90
  /* NOT FOR BROWSER END */
92
91
  /** @private */
@@ -236,8 +236,11 @@ let ParameterToken = (() => {
236
236
  * 获取参数值
237
237
  */
238
238
  getValue() {
239
- const value = (0, string_1.removeCommentLine)(this.lastChild.text());
240
- return this.anon && this.parentNode?.isTemplate() !== false ? value : value.trim();
239
+ const { parentNode, lastChild, anon, name } = this, value = (0, string_1.removeCommentLine)(lastChild.text());
240
+ return anon && parentNode?.isTemplate() !== false
241
+ || name === '2' && parentNode?.type === 'magic-word' && parentNode.name === 'tag'
242
+ ? value
243
+ : value.trim();
241
244
  }
242
245
  /**
243
246
  * Set the parameter value
@@ -246,9 +249,8 @@ let ParameterToken = (() => {
246
249
  * @param value parameter value / 参数值
247
250
  */
248
251
  setValue(value) {
249
- const { childNodes } = index_1.default.parseWithRef(value, this);
250
252
  this.lastChild
251
- .safeReplaceChildren(childNodes);
253
+ .safeReplaceChildren(index_1.default.parseWithRef(value, this).childNodes);
252
254
  }
253
255
  /**
254
256
  * Rename the parameter
@@ -168,8 +168,7 @@ let TableToken = (() => {
168
168
  }
169
169
  /* NOT FOR BROWSER */
170
170
  if (!halfParsed) {
171
- const { childNodes } = index_1.default.parseWithRef(syntax, this, 2);
172
- this.lastChild.safeReplaceChildren(childNodes);
171
+ this.lastChild.safeReplaceChildren(index_1.default.parseWithRef(syntax, this, 2).childNodes);
173
172
  }
174
173
  }
175
174
  /**
@@ -8,9 +8,9 @@ export interface TdSpanAttrs {
8
8
  rowspan?: number;
9
9
  colspan?: number;
10
10
  }
11
- declare type TdAttrGetter<T extends string> = T extends keyof TdSpanAttrs ? number : string | true | undefined;
11
+ declare type TdAttrGetter<T extends string> = T extends keyof TdSpanAttrs ? number : string | undefined;
12
12
  declare type TdAttrSetter<T extends string> = T extends keyof TdSpanAttrs ? number : string | boolean;
13
- export type TdAttrs = Record<string, string | true> & TdSpanAttrs;
13
+ export type TdAttrs = Record<string, string> & TdSpanAttrs;
14
14
  /**
15
15
  * `<td>`, `<th>` or `<caption>`
16
16
  *
@@ -158,8 +158,7 @@ let TdToken = (() => {
158
158
  return this.lastChild.text().trim();
159
159
  }
160
160
  set innerText(text) {
161
- const { childNodes } = index_1.default.parseWithRef(text, this, undefined, true);
162
- this.lastChild.safeReplaceChildren(childNodes);
161
+ this.lastChild.safeReplaceChildren(index_1.default.parseWithRef(text, this, undefined, true).childNodes);
163
162
  }
164
163
  /* NOT FOR BROWSER END */
165
164
  /**
@@ -258,7 +257,7 @@ let TdToken = (() => {
258
257
  key = (0, string_1.trimLc)(key);
259
258
  /* NOT FOR BROWSER END */
260
259
  const value = super.getAttr(key);
261
- return (key === 'rowspan' || key === 'colspan' ? parseInt(value) || 1 : value);
260
+ return (key === 'rowspan' || key === 'colspan' ? parseInt(value || '') || 1 : value);
262
261
  }
263
262
  }
264
263
  /** @private */
@@ -369,7 +368,7 @@ let TdToken = (() => {
369
368
  if (notEOL) {
370
369
  html = html.replace(/(?<=[\S\n])[^\S\n]*$/u, '');
371
370
  }
372
- return `${lf}<${subtype}${attr.toHtmlInternal()}>${subtype === 'caption' ? (0, string_1.newline)(html) : html + (notEOL ? '' : lf)}</${subtype}>`;
371
+ return `${lf}<${subtype}${attr.toHtmlInternal()}>${subtype === 'caption' ? (0, string_1.newline)(html) : html}${notEOL ? '' : lf}</${subtype}>`;
373
372
  }
374
373
  };
375
374
  return TdToken = _classThis;
@@ -384,11 +383,10 @@ exports.TdToken = TdToken;
384
383
  * @param attr 单元格属性
385
384
  */
386
385
  const createTd = (inner, ref, subtype = 'td', attr = {}) => {
387
- const innerToken = typeof inner === 'string' ? index_1.default.parseWithRef(inner, ref) : inner,
388
386
  // @ts-expect-error abstract class
389
- token = debug_1.Shadow.run(() => new TdToken('\n|', undefined, ref.getAttribute('config')));
387
+ const token = debug_1.Shadow.run(() => new TdToken('\n|', undefined, ref.getAttribute('config')));
390
388
  token.setSyntax(subtype);
391
- token.lastChild.safeReplaceWith(innerToken);
389
+ token.lastChild.safeReplaceWith(typeof inner === 'string' ? index_1.default.parseWithRef(inner, ref) : inner);
392
390
  token.setAttr(attr);
393
391
  return token;
394
392
  };
@@ -88,12 +88,15 @@ let HtmlToken = (() => {
88
88
  let _classThis;
89
89
  let _classSuper = index_2.TagToken;
90
90
  let _instanceExtraInitializers = [];
91
+ let _getTocLine_decorators;
91
92
  let _toHtmlInternal_decorators;
92
93
  var HtmlToken = class extends _classSuper {
93
94
  static { _classThis = this; }
94
95
  static {
95
96
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
97
+ _getTocLine_decorators = [(0, cached_1.cached)()];
96
98
  _toHtmlInternal_decorators = [(0, cached_1.cached)()];
99
+ __esDecorate(this, null, _getTocLine_decorators, { kind: "method", name: "getTocLine", static: false, private: false, access: { has: obj => "getTocLine" in obj, get: obj => obj.getTocLine }, metadata: _metadata }, null, _instanceExtraInitializers);
97
100
  __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);
98
101
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
99
102
  HtmlToken = _classThis = _classDescriptor.value;
@@ -319,25 +322,39 @@ let HtmlToken = (() => {
319
322
  }
320
323
  }
321
324
  /** @private */
325
+ getTocLine() {
326
+ if (this.closing || !/^h\d$/u.test(this.name)) {
327
+ return undefined;
328
+ }
329
+ const matched = this.findMatchingTag();
330
+ if (!matched) {
331
+ return undefined;
332
+ }
333
+ const range = this.createRange();
334
+ range.setStartAfter(this);
335
+ range.setEndBefore(matched);
336
+ const content = (0, html_1.html)(range.cloneContents(), '', { nocc: true });
337
+ return [(0, html_1.getId)(content), content];
338
+ }
339
+ /** @private */
322
340
  toHtmlInternal() {
323
- const { closing, name } = this, [, selfClosingTags, voidTags] = this.getAttribute('config').html, tag = name + (closing ? '' : super.toHtmlInternal());
341
+ const { closing, name, selfClosing } = this, [, selfClosingTags, voidTags] = this.getAttribute('config').html, tag = name + (closing ? '' : super.toHtmlInternal());
324
342
  if (voidTags.includes(name)) {
325
343
  return closing && name !== 'br' ? '' : `<${tag}>`;
326
344
  }
327
- const result = `<${closing ? '/' : ''}${tag}>${this.#selfClosing && !closing && selfClosingTags.includes(name) ? `</${name}>` : ''}`;
328
- if (/^h\d$/u.test(name) && (this.closing || !this.id)) {
329
- const matched = this.findMatchingTag();
330
- if (matched) {
331
- if (closing) {
332
- return result + (matched.id ? '' : '</div>');
345
+ const result = `<${closing ? '/' : ''}${tag}>${selfClosing && !closing && selfClosingTags.includes(name) ? `</${name}>` : ''}`;
346
+ if (/^h\d$/u.test(name)) {
347
+ if (closing) {
348
+ return result + (this.findMatchingTag()?.id === '' ? '</div>' : '');
349
+ }
350
+ else if (!this.id) {
351
+ const id = this.getTocLine()?.[0];
352
+ if (id !== undefined) {
353
+ return `<div class="mw-heading mw-heading${name.slice(-1)}">${result.slice(0, -1)} id="${id}">`;
333
354
  }
334
- const range = this.createRange();
335
- range.setStartAfter(this);
336
- range.setEndBefore(matched);
337
- return `<div class="mw-heading mw-heading${name.slice(-1)}">${result.slice(0, -1)} id="${(0, html_1.getId)(range.cloneContents())}">`;
338
355
  }
339
356
  }
340
- return result;
357
+ return (this.tocData ?? '') + result;
341
358
  }
342
359
  /** @private */
343
360
  getRange() {
@@ -103,6 +103,7 @@ let ExtToken = (() => {
103
103
  innerToken = new PreToken(inner, newConfig, accum);
104
104
  break;
105
105
  }
106
+ newConfig.excludes.push('list');
106
107
  // fall through
107
108
  case 'indicator':
108
109
  case 'poem':
@@ -125,7 +126,9 @@ let ExtToken = (() => {
125
126
  case 'tab':
126
127
  newConfig.ext = newConfig.ext.filter(e => e !== 'tabs');
127
128
  break;
128
- // No default
129
+ case 'ref':
130
+ newConfig.ext = newConfig.ext.filter(e => e !== 'references');
131
+ // no default
129
132
  }
130
133
  innerToken = new index_2.Token(inner, newConfig, accum);
131
134
  break;
@@ -26,7 +26,7 @@ export declare abstract class TranslateToken extends TagPairToken implements Omi
26
26
  */
27
27
  constructor(attr?: string, inner?: string, config?: Config, accum?: Token[]);
28
28
  /** @implements */
29
- getAttr(key: string): true | undefined;
29
+ getAttr(key: string): '' | undefined;
30
30
  /** @implements */
31
31
  hasAttr(key: string): boolean;
32
32
  /** @implements */
@@ -125,7 +125,7 @@ let TranslateToken = (() => {
125
125
  }
126
126
  /** @implements */
127
127
  getAttr(key) {
128
- return (0, string_1.trimLc)(key) === 'nowrap' && this.#isNowrap() || undefined;
128
+ return (0, string_1.trimLc)(key) === 'nowrap' && this.#isNowrap() ? '' : undefined;
129
129
  }
130
130
  /** @implements */
131
131
  hasAttr(key) {
@@ -525,7 +525,7 @@ let TranscludeToken = (() => {
525
525
  * @throws `Error` 不是可接受的魔术字
526
526
  */
527
527
  getPossibleValues() {
528
- const { type, name, childNodes } = this;
528
+ const { type, name, childNodes, length: l } = this;
529
529
  if (type === 'template') {
530
530
  throw new Error('TranscludeToken.getPossibleValues method is only for specific magic words!');
531
531
  }
@@ -534,12 +534,14 @@ let TranscludeToken = (() => {
534
534
  case 'if':
535
535
  case 'ifexist':
536
536
  case 'ifexpr':
537
- case 'iferror':
538
537
  start = 2;
539
538
  break;
540
539
  case 'ifeq':
541
540
  start = 3;
542
541
  break;
542
+ case 'iferror':
543
+ start = l > 3 ? 2 : 1;
544
+ break;
543
545
  case 'switch': {
544
546
  const parameters = childNodes.slice(2), last = parameters[parameters.length - 1];
545
547
  queue = [
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCanonicalName = exports.undo = exports.mixin = exports.emptyArray = exports.getMagicWordInfo = exports.setChildNodes = exports.isLink = exports.isRowEnd = exports.isToken = exports.Shadow = void 0;
3
+ exports.getCanonicalName = exports.undo = exports.mixin = exports.emptyArray = exports.getMagicWordInfo = exports.setChildNodes = exports.isLink = exports.isRowEnd = exports.Shadow = void 0;
4
+ exports.isToken = isToken;
4
5
  exports.Shadow = {
5
6
  running: false,
6
7
  /** @private */
@@ -50,12 +51,9 @@ exports.Shadow = {
50
51
  },
51
52
  rev: 0,
52
53
  };
53
- /**
54
- * 是否是某一特定类型的节点
55
- * @param type 节点类型
56
- */
57
- const isToken = (type) => (node) => node.type === type;
58
- exports.isToken = isToken;
54
+ function isToken(type) {
55
+ return (node) => node.type === type;
56
+ }
59
57
  /**
60
58
  * 是否是行尾
61
59
  * @param token 节点
package/dist/util/html.js CHANGED
@@ -95,9 +95,9 @@ const html = (childNodes, separator, opt = {}) => {
95
95
  if ((child.length > 0 || /\s$/u.test(innerText))
96
96
  && previousSibling.is('list')
97
97
  && !/[;#*]/u.test(innerText)
98
- && child.closest('ext-inner#poem,list-range')?.type === 'ext-inner') {
98
+ && child.closest('ext#poem,list-range')?.type === 'ext') {
99
99
  lastPrefix = '';
100
- result = `<span style="display: inline-block; margin-inline-start: ${previousSibling.indent}em;">${result}</span>`;
100
+ result = `<span class="mw-poem-indented" style="display: inline-block; margin-inline-start: ${previousSibling.indent}em;">${result}</span>`;
101
101
  }
102
102
  else {
103
103
  result = result.trim();
@@ -145,15 +145,7 @@ exports.html = html;
145
145
  * @param tokens inner tokens of a section heading
146
146
  */
147
147
  const getId = (tokens) => {
148
- let content;
149
- if (typeof tokens === 'string') {
150
- content = tokens;
151
- }
152
- else {
153
- const opt = { nocc: true };
154
- content = Array.isArray(tokens) ? (0, exports.html)(tokens, '', opt) : tokens.toHtmlInternal(opt);
155
- }
156
- const id = (0, string_1.decodeHtml)((0, string_1.sanitizeAlt)(content.replaceAll('_', ' ')))
148
+ const content = typeof tokens === 'string' ? tokens : tokens.toHtmlInternal({ nocc: true }), id = (0, string_1.decodeHtml)((0, string_1.sanitizeAlt)(content.replaceAll('_', ' ')))
157
149
  .replace(/[\s_]+/gu, '_');
158
150
  return id.endsWith('_') ? id.slice(0, -1) : id;
159
151
  };
@@ -1,6 +1,6 @@
1
1
  (() => {
2
2
  var _a;
3
- const version = '1.41.0', src = (_a = document.currentScript) === null || _a === void 0 ? void 0 : _a.src, file = /\/extensions\/dist\/base\.(?:min\.)?js$/u, CDN = src && file.test(src)
3
+ const version = '1.43.0', src = (_a = document.currentScript) === null || _a === void 0 ? void 0 : _a.src, file = /\/extensions\/dist\/base\.(?:min\.)?js$/u, CDN = src && file.test(src)
4
4
  ? src.replace(file, '')
5
5
  : `https://fastly.jsdelivr.net/npm/wikiparser-node@${version}`;
6
6
  const workerJS = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikiparser-node",
3
- "version": "1.41.0",
3
+ "version": "1.43.0",
4
4
  "description": "A Node.js parser for MediaWiki markup with AST",
5
5
  "keywords": [
6
6
  "mediawiki",
@@ -82,47 +82,83 @@
82
82
  ]
83
83
  },
84
84
  "dependencies": {
85
- "@bhsd/cm-util": "^2.0.1",
85
+ "@bhsd/cm-util": "^2.1.0",
86
86
  "@bhsd/common": "^2.2.1",
87
87
  "@bhsd/nodejs": "^1.0.1",
88
88
  "@bhsd/stylelint-util": "^1.0.3",
89
89
  "binary-search": "^1.3.6",
90
+ "entities": "^8.0.0",
90
91
  "vscode-languageserver-types": "^3.17.5"
91
92
  },
92
- "optionalDependencies": {
93
- "color-name": "~2.0.2",
94
- "entities": "^8.0.0",
95
- "mathoid-texvcjs": "^0.6.0",
96
- "prism-wiki": "^2.1.1",
97
- "prismjs": "^1.30.0",
98
- "stylelint": "^17.12.0",
99
- "vscode-css-languageservice": "^6.3.10",
100
- "vscode-html-languageservice": "^5.6.2",
101
- "vscode-json-languageservice": "^5.7.2"
93
+ "peerDependencies": {
94
+ "color-name": ">=2.0.0",
95
+ "mathoid-texvcjs": ">=0.4.0",
96
+ "mediawiki-expr": "*",
97
+ "prism-wiki": ">=1.0.0",
98
+ "prismjs": "^1.0.0",
99
+ "stylelint": ">=16.0.0",
100
+ "vscode-css-languageservice": ">=3.0.0",
101
+ "vscode-html-languageservice": ">=3.1.0",
102
+ "vscode-json-languageservice": ">=3.2.0"
103
+ },
104
+ "peerDependenciesMeta": {
105
+ "color-name": {
106
+ "optional": true
107
+ },
108
+ "mathoid-texvcjs": {
109
+ "optional": true
110
+ },
111
+ "mediawiki-expr": {
112
+ "optional": true
113
+ },
114
+ "prism-wiki": {
115
+ "optional": true
116
+ },
117
+ "prismjs": {
118
+ "optional": true
119
+ },
120
+ "stylelint": {
121
+ "optional": true
122
+ },
123
+ "vscode-css-languageservice": {
124
+ "optional": true
125
+ },
126
+ "vscode-html-languageservice": {
127
+ "optional": true
128
+ },
129
+ "vscode-json-languageservice": {
130
+ "optional": true
131
+ }
102
132
  },
103
133
  "devDependencies": {
104
- "@bhsd/code-standard": "^2.5.1",
105
- "@bhsd/test-util": "^1.3.1",
134
+ "@bhsd/code-standard": "^2.6.2",
135
+ "@bhsd/test-util": "^1.5.0",
106
136
  "@codemirror/lint": "^6.9.6",
107
- "@eslint/markdown": "^8.0.1",
137
+ "@eslint/markdown": "^8.0.2",
108
138
  "@types/color-name": "^2.0.0",
109
139
  "@types/color-rgba": "^2.1.3",
110
- "@types/mocha": "^10.0.10",
111
- "@types/node": "^25.9.0",
112
140
  "@types/prismjs": "^1.26.6",
113
- "@typescript-eslint/parser": "^8.59.4",
114
141
  "c8": "^11.0.0",
115
142
  "codejar-async": "^4.3.1",
143
+ "color-name": "~2.0.2",
116
144
  "color-rgba": "^3.0.0",
117
145
  "diff2html-cli": "^5.2.15",
118
146
  "esbuild": "^0.28.0",
119
- "eslint": "^10.4.0",
147
+ "eslint": "^10.4.1",
120
148
  "markdownlint-cli2": "^0.22.1",
121
- "mocha": "^11.7.5",
149
+ "mathoid-texvcjs": "^0.6.0",
150
+ "mediawiki-expr": "^0.0.2",
151
+ "mocha": "^11.7.6",
122
152
  "monaco-editor": "~0.53.0",
123
- "tsx": "^4.22.2",
153
+ "prism-wiki": "^2.2.0",
154
+ "prismjs": "^1.30.0",
155
+ "stylelint": "^17.12.0",
156
+ "tsx": "^4.22.3",
124
157
  "typescript": "^6.0.3",
125
158
  "v8r": "^6.1.0",
159
+ "vscode-css-languageservice": "^6.3.10",
160
+ "vscode-html-languageservice": "^5.6.2",
161
+ "vscode-json-languageservice": "^5.7.2",
126
162
  "vscode-languageserver-textdocument": "^1.0.12"
127
163
  },
128
164
  "engines": {