wikiparser-node 1.31.0 → 1.32.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 +1 -0
  2. package/bundle/bundle-es8.min.js +29 -30
  3. package/bundle/bundle-lsp.min.js +29 -29
  4. package/bundle/bundle.min.js +23 -23
  5. package/dist/addon/attribute.js +166 -0
  6. package/dist/addon/link.js +92 -0
  7. package/dist/addon/table.js +12 -3
  8. package/dist/addon/token.js +5 -303
  9. package/dist/addon/transclude.js +9 -6
  10. package/dist/base.d.mts +9 -1
  11. package/dist/base.d.ts +9 -1
  12. package/dist/bin/config.js +1 -1
  13. package/dist/index.d.ts +24 -5
  14. package/dist/index.js +69 -89
  15. package/dist/internal.d.ts +4 -0
  16. package/dist/lib/document.d.ts +9 -7
  17. package/dist/lib/document.js +91 -66
  18. package/dist/lib/element.d.ts +7 -7
  19. package/dist/lib/element.js +48 -50
  20. package/dist/lib/lintConfig.js +1 -1
  21. package/dist/lib/lsp.js +120 -56
  22. package/dist/lib/node.js +20 -14
  23. package/dist/lib/text.js +2 -2
  24. package/dist/lib/title.d.ts +11 -0
  25. package/dist/lib/title.js +37 -13
  26. package/dist/mixin/elementLike.js +2 -3
  27. package/dist/mixin/syntax.js +13 -7
  28. package/dist/parser/commentAndExt.js +3 -3
  29. package/dist/parser/selector.js +16 -41
  30. package/dist/render/expand.js +216 -0
  31. package/dist/render/extension.js +141 -0
  32. package/dist/render/html.js +91 -0
  33. package/dist/{addon → render}/magicWords.js +35 -1
  34. package/dist/render/syntaxhighlight.js +415 -0
  35. package/dist/src/arg.js +1 -1
  36. package/dist/src/attribute.d.ts +5 -0
  37. package/dist/src/attribute.js +58 -103
  38. package/dist/src/attributes.d.ts +5 -0
  39. package/dist/src/attributes.js +15 -50
  40. package/dist/src/converter.js +4 -2
  41. package/dist/src/converterFlags.js +8 -6
  42. package/dist/src/converterRule.js +19 -15
  43. package/dist/src/extLink.js +1 -1
  44. package/dist/src/heading.d.ts +1 -1
  45. package/dist/src/heading.js +5 -3
  46. package/dist/src/imageParameter.d.ts +0 -1
  47. package/dist/src/imageParameter.js +33 -24
  48. package/dist/src/index.d.ts +5 -5
  49. package/dist/src/index.js +33 -21
  50. package/dist/src/link/base.js +16 -34
  51. package/dist/src/link/category.d.ts +7 -0
  52. package/dist/src/link/category.js +101 -37
  53. package/dist/src/link/file.js +19 -6
  54. package/dist/src/link/galleryImage.js +1 -2
  55. package/dist/src/link/index.d.ts +1 -1
  56. package/dist/src/link/index.js +10 -31
  57. package/dist/src/multiLine/index.js +1 -1
  58. package/dist/src/nowiki/comment.js +1 -1
  59. package/dist/src/nowiki/doubleUnderscore.js +4 -2
  60. package/dist/src/nowiki/index.js +34 -31
  61. package/dist/src/nowiki/listBase.d.ts +2 -1
  62. package/dist/src/nowiki/listBase.js +22 -8
  63. package/dist/src/nowiki/quote.d.ts +1 -1
  64. package/dist/src/nowiki/quote.js +1 -1
  65. package/dist/src/onlyinclude.js +1 -1
  66. package/dist/src/parameter.js +1 -1
  67. package/dist/src/redirect.js +1 -1
  68. package/dist/src/table/base.js +4 -2
  69. package/dist/src/table/index.d.ts +0 -5
  70. package/dist/src/table/index.js +6 -15
  71. package/dist/src/table/td.js +9 -5
  72. package/dist/src/tag/index.js +1 -1
  73. package/dist/src/tagPair/ext.js +14 -38
  74. package/dist/src/tagPair/index.js +6 -4
  75. package/dist/src/tagPair/translate.js +2 -2
  76. package/dist/src/transclude.d.ts +0 -6
  77. package/dist/src/transclude.js +16 -33
  78. package/dist/util/constants.js +5 -1
  79. package/dist/util/debug.js +72 -5
  80. package/dist/util/diff.js +17 -15
  81. package/dist/util/html.js +4 -3
  82. package/dist/util/selector.js +37 -0
  83. package/dist/util/sharable.d.mts +4 -1
  84. package/dist/util/sharable.js +7 -7
  85. package/dist/util/sharable.mjs +7 -7
  86. package/dist/util/string.js +31 -12
  87. package/extensions/dist/base.js +1 -1
  88. package/i18n/zh-hans.json +29 -29
  89. package/i18n/zh-hant.json +30 -30
  90. package/package.json +16 -13
@@ -37,7 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.ImageParameterToken = exports.extensions = exports.galleryParams = void 0;
40
+ exports.ImageParameterToken = void 0;
41
41
  const common_1 = require("@bhsd/common");
42
42
  const string_1 = require("../util/string");
43
43
  const lint_1 = require("../util/lint");
@@ -56,7 +56,6 @@ const getUrlRegex = (0, common_1.getRegex)(protocol => new RegExp(String.raw `^(
56
56
  /^(\s*(?!\s))(.*)px(\s*)$/u;
57
57
  /* eslint-enable @typescript-eslint/no-unused-expressions */
58
58
  const getSyntaxRegex = (0, common_1.getRegex)(syntax => new RegExp(String.raw `^(\s*(?!\s))${syntax.replace('$1', '(.*)')}${syntax.endsWith('$1') ? '(?=$|\n)' : ''}(\s*)$`, 'u'));
59
- exports.galleryParams = new Set(['alt', 'link', 'lang', 'page', 'caption']), exports.extensions = new Set(['tiff', 'tif', 'png', 'gif', 'jpg', 'jpeg', 'webp', 'xcf', 'pdf', 'svg', 'djvu']);
60
59
  /**
61
60
  * 获取网址
62
61
  * @param link 外链
@@ -70,33 +69,34 @@ const getUrl = (link) => {
70
69
  }
71
70
  return new URL(link).href;
72
71
  };
73
- function validate(key, val, config, halfParsed, ext) {
72
+ function validate(key, val, config, extOrType, halfParsed) {
74
73
  val = (0, string_1.removeComment)(val).trim();
75
74
  let value = val.replace(key === 'link' ? /\0\d+[tq]\x7F/gu : /\0\d+t\x7F/gu, '').trim();
76
75
  switch (key) {
77
76
  case 'width':
78
77
  return !value && Boolean(val) || /^(?:\d+x?|\d*x\d+)(?:\s*px)?$/u.test(value);
79
78
  case 'link': {
79
+ const isGalleryImage = extOrType === 'gallery-image';
80
80
  if (!value) {
81
81
  return val;
82
82
  }
83
83
  else if (getUrlLikeRegex(config.protocol).test(value)) {
84
- return getUrlRegex(config.protocol).test(value) && val;
84
+ return getUrlRegex(config.protocol).test(value) ? val : isGalleryImage;
85
85
  }
86
86
  else if (value.startsWith('[[') && value.endsWith(']]')) {
87
87
  value = value.slice(2, -2);
88
88
  }
89
89
  const title = index_1.default.normalizeTitle(value, 0, false, config, { halfParsed, decode: true, selfLink: true, page: '' });
90
- return title.valid && title;
90
+ return title.valid ? title : isGalleryImage;
91
91
  }
92
92
  case 'lang':
93
- return (ext === 'svg' || ext === 'svgz') && !/[^a-z\d-]/u.test(value);
93
+ return (extOrType === 'svg' || extOrType === 'svgz') && !/[^a-z\d-]/u.test(value);
94
94
  case 'alt':
95
95
  case 'class':
96
96
  case 'manualthumb':
97
97
  return true;
98
98
  case 'page':
99
- return (ext === 'djvu' || ext === 'djv' || ext === 'pdf') && Number(value) > 0;
99
+ return (extOrType === 'djvu' || extOrType === 'djv' || extOrType === 'pdf') && Number(value) > 0;
100
100
  default:
101
101
  return Boolean(value) && !isNaN(value);
102
102
  }
@@ -149,10 +149,12 @@ let ImageParameterToken = (() => {
149
149
  return debug_1.Shadow.run(() => {
150
150
  const token = new index_2.Token(value, this.getAttribute('config'));
151
151
  token.parseOnce(0, this.getAttribute('include')).parseOnce();
152
- return /^\0\d+m\x7F/u.test(token.firstChild.toString())
153
- ? value
154
- : validate('link', value, this.getAttribute('config'));
155
- });
152
+ if (/^\0\d+m\x7F/u.test(token.firstChild.toString())) {
153
+ return value;
154
+ }
155
+ const link = validate('link', value, this.getAttribute('config'), this.parentNode?.type);
156
+ return link === true ? undefined : link;
157
+ }, index_1.default);
156
158
  }
157
159
  }
158
160
  /* NOT FOR BROWSER */
@@ -181,13 +183,18 @@ let ImageParameterToken = (() => {
181
183
  const [width, height = ''] = size.split('x');
182
184
  return { width, height };
183
185
  }
184
- const token = index_1.default.parseWithRef(size, this, 2, false), i = token.childNodes.findIndex(({ type, data }) => type === 'text' && data.includes('x'));
185
- if (i === -1) {
186
- return { width: size, height: '' };
187
- }
188
- const str = token.childNodes[i];
189
- str.splitText(str.data.indexOf('x')).splitText(1);
190
- return { width: (0, string_1.text)(token.childNodes.slice(0, i + 1)), height: (0, string_1.text)(token.childNodes.slice(i + 2)) };
186
+ return debug_1.Shadow.internal(() => {
187
+ const token = index_1.default.parseWithRef(size, this, 2, false), i = token.childNodes.findIndex(({ type, data }) => type === 'text' && data.includes('x'));
188
+ if (i === -1) {
189
+ return { width: size, height: '' };
190
+ }
191
+ const str = token.childNodes[i];
192
+ str.splitText(str.data.indexOf('x')).splitText(1);
193
+ return {
194
+ width: (0, string_1.text)(token.childNodes.slice(0, i + 1)),
195
+ height: (0, string_1.text)(token.childNodes.slice(i + 2)),
196
+ };
197
+ }, index_1.default);
191
198
  }
192
199
  return undefined;
193
200
  }
@@ -224,7 +231,7 @@ let ImageParameterToken = (() => {
224
231
  mt = regex.exec(str);
225
232
  return mt
226
233
  && (mt.length !== 4
227
- || validate(key, mt[2], config, true, extension) !== false);
234
+ || validate(key, mt[2], config, extension, true) !== false);
228
235
  });
229
236
  // @ts-expect-error mt already assigned
230
237
  if (param && mt) {
@@ -257,7 +264,7 @@ let ImageParameterToken = (() => {
257
264
  }
258
265
  /** @private */
259
266
  afterBuild() {
260
- if (this.parentNode?.is('gallery-image') && !exports.galleryParams.has(this.name)) {
267
+ if (this.parentNode?.is('gallery-image') && !constants_1.galleryParams.has(this.name)) {
261
268
  this.setAttribute('name', 'invalid');
262
269
  }
263
270
  super.afterBuild();
@@ -328,7 +335,7 @@ let ImageParameterToken = (() => {
328
335
  const { valid, ns, extension,
329
336
  /* NOT FOR BROWSER */
330
337
  interwiki, } = this.thumb;
331
- if (!valid || ns !== 6 || !exports.extensions.has(extension)
338
+ if (!valid || ns !== 6 || !constants_1.extensions.has(extension)
332
339
  || interwiki) {
333
340
  errors.push((0, lint_1.generateForSelf)(this, { start }, rule, 'invalid-thumb', s));
334
341
  }
@@ -351,10 +358,12 @@ let ImageParameterToken = (() => {
351
358
  }
352
359
  /** @private */
353
360
  print() {
354
- if (this.#syntax) {
355
- return `<span class="wpb-image-parameter${this.name === 'invalid' ? ' wpb-invalid' : ''}">${this.#syntax.replace('$1', `<span class="wpb-image-caption">${(0, string_1.print)(this.childNodes)}</span>`)}</span>`;
361
+ PRINT: {
362
+ if (this.#syntax) {
363
+ return `<span class="wpb-image-parameter${this.name === 'invalid' ? ' wpb-invalid' : ''}">${this.#syntax.replace('$1', `<span class="wpb-image-caption">${(0, string_1.print)(this.childNodes)}</span>`)}</span>`;
364
+ }
365
+ return super.print({ class: 'image-caption' });
356
366
  }
357
- return super.print({ class: 'image-caption' });
358
367
  }
359
368
  /* NOT FOR BROWSER */
360
369
  cloneNode() {
@@ -5,8 +5,8 @@ import type { LintError, TokenTypes } from '../base';
5
5
  import type { Title, TitleOptions } from '../lib/title';
6
6
  import type { AstNodes, IncludeToken, HtmlToken, ExtToken, CommentToken } from '../internal';
7
7
  import { Ranges } from '../lib/ranges';
8
- import { AstRange } from '../lib/range';
9
8
  import type { Range } from '../lib/ranges';
9
+ import type { AstRange as AstRangeBase } from '../lib/range';
10
10
  declare type ExtendedLintError = LintError[] & {
11
11
  output?: string;
12
12
  };
@@ -77,7 +77,7 @@ export declare class Token extends AstElement {
77
77
  *
78
78
  * 创建AstRange对象
79
79
  */
80
- createRange(): AstRange;
80
+ createRange(): AstRangeBase;
81
81
  /**
82
82
  * Check if a title is an interwiki link
83
83
  *
@@ -96,21 +96,21 @@ export declare class Token extends AstElement {
96
96
  *
97
97
  * 获取全部章节
98
98
  */
99
- sections(): AstRange[] | undefined;
99
+ sections(): AstRangeBase[] | undefined;
100
100
  /**
101
101
  * Get a section
102
102
  *
103
103
  * 获取指定章节
104
104
  * @param n rank of the section / 章节序号
105
105
  */
106
- section(n: number): AstRange | undefined;
106
+ section(n: number): AstRangeBase | undefined;
107
107
  /**
108
108
  * Get the enclosing HTML tags
109
109
  *
110
110
  * 获取指定的外层HTML标签
111
111
  * @param tag HTML tag name / HTML标签名
112
112
  */
113
- findEnclosingHtml(tag?: string): AstRange | undefined;
113
+ findEnclosingHtml(tag?: string): AstRangeBase | undefined;
114
114
  /**
115
115
  * Get all categories
116
116
  *
package/dist/src/index.js CHANGED
@@ -93,7 +93,6 @@ const text_1 = require("../lib/text");
93
93
  const strict_1 = __importDefault(require("assert/strict"));
94
94
  const html_1 = require("../util/html");
95
95
  const ranges_1 = require("../lib/ranges");
96
- const range_1 = require("../lib/range");
97
96
  const readOnly_1 = require("../mixin/readOnly");
98
97
  const cached_1 = require("../mixin/cached");
99
98
  const lintSelectors = ['category', 'html-attr#id,ext-attr#id,table-attr#id'];
@@ -220,7 +219,7 @@ let Token = (() => {
220
219
  }
221
220
  /** @private */
222
221
  parseOnce(n = this.#stage, include = false, tidy) {
223
- if (n < this.#stage || this.length === 0 || !this.isPlain()) {
222
+ if (n < this.#stage || this.length !== 1 || !this.isPlain()) {
224
223
  return this;
225
224
  }
226
225
  else if (this.#stage >= constants_1.MAX_STAGE) {
@@ -284,13 +283,13 @@ let Token = (() => {
284
283
  buildFromStr(str, type) {
285
284
  const nodes = str.split(/[\0\x7F]/u).map((s, i) => {
286
285
  if (i % 2 === 0) {
287
- return new text_1.AstText(s);
286
+ return s && new text_1.AstText(s);
288
287
  }
289
288
  else if (isNaN(s.slice(-1))) {
290
289
  return this.#accum[Number(s.slice(0, -1))];
291
290
  }
292
291
  throw new Error(`Failed to build! Unrecognized token: ${s}`);
293
- });
292
+ }).filter(node => node !== '');
294
293
  if (type === constants_1.BuildMethod.String) {
295
294
  return nodes.map(String).join('');
296
295
  }
@@ -305,7 +304,6 @@ let Token = (() => {
305
304
  const { length, firstChild } = this, str = firstChild?.toString();
306
305
  if (length === 1 && firstChild.type === 'text' && str.includes('\0')) {
307
306
  (0, debug_1.setChildNodes)(this, 0, 1, this.buildFromStr(str));
308
- this.normalize();
309
307
  if (this.type === 'root') {
310
308
  for (const token of this.#accum) {
311
309
  token?.build(); // eslint-disable-line @typescript-eslint/no-unnecessary-condition
@@ -459,7 +457,7 @@ let Token = (() => {
459
457
  return this.#stage;
460
458
  /* PRINT ONLY */
461
459
  case 'invalid':
462
- return (this.type === 'table-inter' && (0, lint_1.isFostered)(this) === 2);
460
+ PRINT: return (this.type === 'table-inter' && (0, lint_1.isFostered)(this) === 2);
463
461
  /* PRINT ONLY END */
464
462
  /* NOT FOR BROWSER */
465
463
  case 'protectedChildren':
@@ -618,7 +616,7 @@ let Token = (() => {
618
616
  }
619
617
  if (needFix && errors.some(({ fix }) => fix)) {
620
618
  // 倒序修复,跳过嵌套的修复
621
- const fixable = errors.map(({ fix }) => fix).filter(Boolean).sort(({ range: [aFrom, aTo] }, { range: [bFrom, bTo] }) => aTo === bTo ? bFrom - aFrom : bTo - aTo);
619
+ const fixable = errors.map(({ fix }) => fix).filter(fix => fix !== undefined).sort(({ range: [aFrom, aTo] }, { range: [bFrom, bTo] }) => aTo === bTo ? bFrom - aFrom : bTo - aTo);
622
620
  let i = Infinity, output = wikitext;
623
621
  for (const { range: [from, to], text: t } of fixable) {
624
622
  if (to <= i) {
@@ -676,11 +674,7 @@ let Token = (() => {
676
674
  if (elements.length === 0) {
677
675
  return;
678
676
  }
679
- const { childNodes, lastChild } = this, first = elements[0], last = elements.at(-1), parent = first.parentNode, nodes = parent.getChildNodes();
680
- nodes.splice(nodes.indexOf(first), elements.length);
681
- parent.setAttribute('childNodes', nodes);
682
- first.previousSibling?.setAttribute('nextSibling', last.nextSibling);
683
- last.nextSibling?.setAttribute('previousSibling', first.previousSibling);
677
+ const { childNodes, lastChild } = this, first = elements[0], last = elements.at(-1);
684
678
  for (const element of elements) {
685
679
  element.setAttribute('parentNode', this);
686
680
  }
@@ -781,7 +775,8 @@ let Token = (() => {
781
775
  * 创建AstRange对象
782
776
  */
783
777
  createRange() {
784
- return new range_1.AstRange();
778
+ const { AstRange } = require('../lib/range');
779
+ return new AstRange();
785
780
  }
786
781
  /**
787
782
  * Check if a title is an interwiki link
@@ -790,7 +785,7 @@ let Token = (() => {
790
785
  * @param title title / 标题
791
786
  */
792
787
  isInterwiki(title) {
793
- return index_1.default.isInterwiki(title, this.#config);
788
+ return (0, string_1.isInterwiki)(title, this.#config);
794
789
  }
795
790
  /** @private */
796
791
  cloneChildNodes() {
@@ -809,6 +804,7 @@ let Token = (() => {
809
804
  return debug_1.Shadow.run(() => {
810
805
  const token = new Token(undefined, this.#config, [], this.getAcceptable());
811
806
  token.type = this.type;
807
+ token.pageName = this.pageName;
812
808
  token.setAttribute('stage', this.#stage);
813
809
  token.setAttribute('include', Boolean(this.#include));
814
810
  token.setAttribute('name', this.name);
@@ -860,8 +856,8 @@ let Token = (() => {
860
856
  * @since v1.10.0
861
857
  */
862
858
  expand() {
863
- require('../addon/token');
864
- return this.expand();
859
+ const { expandToken } = require('../render/expand');
860
+ return debug_1.Shadow.run(() => expandToken(this).parse());
865
861
  }
866
862
  /**
867
863
  * Parse some magic words
@@ -869,8 +865,8 @@ let Token = (() => {
869
865
  * 解析部分魔术字
870
866
  */
871
867
  solveConst() {
872
- require('../addon/token');
873
- return this.solveConst();
868
+ const { expandToken } = require('../render/expand');
869
+ return debug_1.Shadow.run(() => expandToken(this, false).parse());
874
870
  }
875
871
  /**
876
872
  * Merge plain child tokens of a plain token
@@ -881,7 +877,7 @@ let Token = (() => {
881
877
  if (this.isPlain()) {
882
878
  for (const child of this.childNodes) {
883
879
  if (child.type !== 'text' && child.isPlain()) {
884
- child.insertAdjacent(child.childNodes, 1);
880
+ child.insertAdjacent([...child.childNodes], 1);
885
881
  child.remove();
886
882
  }
887
883
  }
@@ -894,8 +890,24 @@ let Token = (() => {
894
890
  * @since v1.10.0
895
891
  */
896
892
  toHtml() {
897
- require('../addon/token');
898
- return this.toHtml();
893
+ const { viewOnly, internal } = index_1.default;
894
+ let output;
895
+ index_1.default.internal = true;
896
+ if (this.type === 'root') {
897
+ const { expandToken } = require('../render/expand'), { toHtml } = require('../render/html');
898
+ index_1.default.viewOnly = true;
899
+ const expanded = debug_1.Shadow.run(() => expandToken(this).parse(undefined, false, true)), e = new Event('expand');
900
+ this.dispatchEvent(e, { type: 'expand', token: expanded });
901
+ index_1.default.viewOnly = false;
902
+ output = toHtml(expanded);
903
+ }
904
+ else {
905
+ index_1.default.viewOnly = false;
906
+ output = this.cloneNode().toHtmlInternal();
907
+ }
908
+ index_1.default.viewOnly = viewOnly;
909
+ index_1.default.internal = internal;
910
+ return output;
899
911
  }
900
912
  /**
901
913
  * 构建列表
@@ -40,6 +40,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.LinkBaseToken = void 0;
41
41
  const lint_1 = require("../../util/lint");
42
42
  const constants_1 = require("../../util/constants");
43
+ const debug_1 = require("../../util/debug");
43
44
  const rect_1 = require("../../lib/rect");
44
45
  const padded_1 = require("../../mixin/padded");
45
46
  const noEscape_1 = require("../../mixin/noEscape");
@@ -47,15 +48,9 @@ const index_1 = __importDefault(require("../../index"));
47
48
  const index_2 = require("../index");
48
49
  const atom_1 = require("../atom");
49
50
  /* NOT FOR BROWSER */
50
- const debug_1 = require("../../util/debug");
51
51
  const string_1 = require("../../util/string");
52
52
  const cached_1 = require("../../mixin/cached");
53
53
  /* NOT FOR BROWSER END */
54
- /**
55
- * 是否为普通内链
56
- * @param type 节点类型
57
- */
58
- const isLink = (type) => type === 'redirect-target' || type === 'link';
59
54
  /**
60
55
  * internal link
61
56
  *
@@ -108,7 +103,7 @@ let LinkBaseToken = (() => {
108
103
  }
109
104
  /** @throws `RangeError` 非法的跨维基前缀 */
110
105
  set interwiki(interwiki) {
111
- if (isLink(this.type)) {
106
+ if ((0, debug_1.isLink)(this.type)) {
112
107
  const { prefix, main, fragment } = this.#title, link = `${interwiki}:${prefix}${main}${fragment === undefined ? '' : `#${fragment}`}`;
113
108
  /* istanbul ignore if */
114
109
  if (interwiki && !this.isInterwiki(link)) {
@@ -243,7 +238,7 @@ let LinkBaseToken = (() => {
243
238
  }
244
239
  rule = 'no-ignored';
245
240
  s = lintConfig.getSeverity(rule, 'fragment');
246
- if (s && fragment !== undefined && !isLink(type)) {
241
+ if (s && fragment !== undefined && !(0, debug_1.isLink)(type)) {
247
242
  const e = (0, lint_1.generateForChild)(target, rect, rule, 'useless-fragment', s);
248
243
  if (computeEditInfo || fix) {
249
244
  const j = target.childNodes.findIndex(c => c.type === 'text' && c.data.includes('#')), textNode = target.childNodes[j];
@@ -262,7 +257,7 @@ let LinkBaseToken = (() => {
262
257
  }
263
258
  /** @private */
264
259
  print() {
265
- return super.print(this.#bracket ? { pre: '[[', post: ']]', sep: this.#delimiter } : { sep: this.#delimiter });
260
+ PRINT: return super.print(this.#bracket ? { pre: '[[', post: ']]', sep: this.#delimiter } : { sep: this.#delimiter });
266
261
  }
267
262
  /** @private */
268
263
  json(_, start = this.getAbsoluteIndex()) {
@@ -284,6 +279,7 @@ let LinkBaseToken = (() => {
284
279
  return token;
285
280
  });
286
281
  }
282
+ /* istanbul ignore next */
287
283
  /**
288
284
  * Set the link target
289
285
  *
@@ -291,10 +287,10 @@ let LinkBaseToken = (() => {
291
287
  * @param link link target / 链接目标
292
288
  */
293
289
  setTarget(link) {
294
- const { childNodes } = index_1.default.parseWithRef(link, this, 2), token = debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'link-target', this.getAttribute('config'), [], { 'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '' }));
295
- token.concat(childNodes); // eslint-disable-line unicorn/prefer-spread
296
- this.firstChild.safeReplaceWith(token);
290
+ require('../../addon/link');
291
+ this.setTarget(link);
297
292
  }
293
+ /* istanbul ignore next */
298
294
  /**
299
295
  * Set the fragment
300
296
  *
@@ -302,11 +298,8 @@ let LinkBaseToken = (() => {
302
298
  * @param fragment URI fragment / 片段标识符
303
299
  */
304
300
  setFragment(fragment) {
305
- const { type, name } = this;
306
- if (fragment === undefined || isLink(type)) {
307
- fragment &&= (0, string_1.encode)(fragment);
308
- this.setTarget(name + (fragment === undefined ? '' : `#${fragment}`));
309
- }
301
+ require('../../addon/link');
302
+ this.setFragment(fragment);
310
303
  }
311
304
  /**
312
305
  * Set the link text
@@ -315,26 +308,14 @@ let LinkBaseToken = (() => {
315
308
  * @param linkStr link text / 链接显示文字
316
309
  */
317
310
  setLinkText(linkStr) {
318
- const { childNodes, lastChild, length } = this;
319
- if (linkStr === undefined) {
320
- childNodes[1]?.remove();
321
- return;
322
- }
323
- const root = index_1.default.parseWithRef(linkStr, this);
324
- if (length === 1) {
325
- root.type = 'link-text';
326
- root.setAttribute('acceptable', {
327
- 'Stage-5': ':', QuoteToken: ':', ConverterToken: ':',
328
- });
329
- this.insertAt(root);
330
- }
331
- else {
332
- lastChild.safeReplaceChildren(root.childNodes);
333
- }
311
+ require('../../addon/link');
312
+ this.setLinkText(linkStr);
334
313
  }
335
314
  /** @private */
336
315
  toHtmlInternal(opt) {
337
- if (this.is('link') || this.is('redirect-target')) {
316
+ if (this.is('link')
317
+ || this.is('redirect-target')
318
+ || this.is('category')) {
338
319
  const { link, length, lastChild, type, pageName } = this;
339
320
  let attr;
340
321
  if (type === 'link' && link.title === pageName && !link.fragment) {
@@ -351,6 +332,7 @@ let LinkBaseToken = (() => {
351
332
  })
352
333
  : (0, string_1.sanitize)(this.innerText)}</a>`;
353
334
  }
335
+ /* istanbul ignore next */
354
336
  return '';
355
337
  }
356
338
  };
@@ -17,6 +17,13 @@ export declare abstract class CategoryToken extends LinkBaseToken {
17
17
  /** sort key / 分类排序关键字 */
18
18
  get sortkey(): string | undefined;
19
19
  set sortkey(text: string | undefined);
20
+ /**
21
+ * link text
22
+ *
23
+ * 链接显示文字
24
+ * @since v1.32.0
25
+ */
26
+ get innerText(): string;
20
27
  /**
21
28
  * Set the sort key
22
29
  *
@@ -1,4 +1,38 @@
1
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
+ };
2
36
  Object.defineProperty(exports, "__esModule", { value: true });
3
37
  exports.CategoryToken = void 0;
4
38
  const base_1 = require("./base");
@@ -7,6 +41,7 @@ const string_1 = require("../../util/string");
7
41
  /* PRINT ONLY END */
8
42
  /* NOT FOR BROWSER */
9
43
  const constants_1 = require("../../util/constants");
44
+ const cached_1 = require("../../mixin/cached");
10
45
  /* NOT FOR BROWSER END */
11
46
  /**
12
47
  * category
@@ -14,45 +49,74 @@ const constants_1 = require("../../util/constants");
14
49
  * 分类
15
50
  * @classdesc `{childNodes: [AtomToken, ?Token]}`
16
51
  */
17
- class CategoryToken extends base_1.LinkBaseToken {
18
- /* NOT FOR BROWSER END */
19
- get type() {
20
- return 'category';
21
- }
22
- /* PRINT ONLY */
23
- /** sort key / 分类排序关键字 */
24
- get sortkey() {
25
- LSP: {
26
- const { childNodes: [, child] } = this;
27
- return child && (0, string_1.decodeHtml)(child.text());
52
+ let CategoryToken = (() => {
53
+ let _classSuper = base_1.LinkBaseToken;
54
+ let _instanceExtraInitializers = [];
55
+ let _toHtmlInternal_decorators;
56
+ return class CategoryToken extends _classSuper {
57
+ static {
58
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
59
+ _toHtmlInternal_decorators = [(0, cached_1.cached)()];
60
+ __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);
61
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
28
62
  }
29
- }
30
- /* PRINT ONLY END */
31
- /* NOT FOR BROWSER */
32
- set sortkey(text) {
33
- this.setSortkey(text);
34
- }
35
- /* NOT FOR BROWSER END */
36
- /** @private */
37
- json(_, start = this.getAbsoluteIndex()) {
38
- LSP: {
39
- const json = super.json(undefined, start), { sortkey } = this;
40
- if (sortkey) {
41
- json['sortkey'] = sortkey;
63
+ /* NOT FOR BROWSER END */
64
+ get type() {
65
+ return 'category';
66
+ }
67
+ /* PRINT ONLY */
68
+ /** sort key / 分类排序关键字 */
69
+ get sortkey() {
70
+ LSP: {
71
+ const { childNodes: [, child] } = this;
72
+ return child && (0, string_1.decodeHtml)(child.text());
42
73
  }
43
- return json;
44
74
  }
45
- }
46
- /* NOT FOR BROWSER */
47
- /**
48
- * Set the sort key
49
- *
50
- * 设置排序关键字
51
- * @param text sort key / 排序关键字
52
- */
53
- setSortkey(text) {
54
- this.setLinkText(text);
55
- }
56
- }
75
+ /* PRINT ONLY END */
76
+ /* NOT FOR BROWSER */
77
+ set sortkey(text) {
78
+ this.setSortkey(text);
79
+ }
80
+ /**
81
+ * link text
82
+ *
83
+ * 链接显示文字
84
+ * @since v1.32.0
85
+ */
86
+ get innerText() {
87
+ return this.link.main;
88
+ }
89
+ /* NOT FOR BROWSER END */
90
+ /** @private */
91
+ json(_, start = this.getAbsoluteIndex()) {
92
+ LSP: {
93
+ const json = super.json(undefined, start), { sortkey } = this;
94
+ if (sortkey) {
95
+ json['sortkey'] = sortkey;
96
+ }
97
+ return json;
98
+ }
99
+ }
100
+ /* NOT FOR BROWSER */
101
+ /**
102
+ * Set the sort key
103
+ *
104
+ * 设置排序关键字
105
+ * @param text sort key / 排序关键字
106
+ */
107
+ setSortkey(text) {
108
+ this.setLinkText(text);
109
+ }
110
+ /** @private */
111
+ toHtmlInternal() {
112
+ constants_1.states.get(this.getRootNode())?.categories.add(super.toHtmlInternal());
113
+ return '';
114
+ }
115
+ constructor() {
116
+ super(...arguments);
117
+ __runInitializers(this, _instanceExtraInitializers);
118
+ }
119
+ };
120
+ })();
57
121
  exports.CategoryToken = CategoryToken;
58
122
  constants_1.classes['CategoryToken'] = __filename;