wikiparser-node 1.21.2 → 1.22.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 (97) hide show
  1. package/README.md +9 -5
  2. package/bundle/bundle-es8.min.js +25 -25
  3. package/bundle/bundle-lsp.min.js +26 -26
  4. package/bundle/bundle.min.js +25 -25
  5. package/config/default.json +15 -11
  6. package/config/enwiki.json +1 -1
  7. package/config/jawiki.json +1 -1
  8. package/config/minimum.json +2 -3
  9. package/config/moegirl.json +152 -15
  10. package/config/zhwiki.json +1 -1
  11. package/dist/addon/token.js +3 -0
  12. package/dist/base.d.mts +16 -9
  13. package/dist/base.d.ts +16 -9
  14. package/dist/bin/config.js +23 -11
  15. package/dist/index.d.ts +33 -4
  16. package/dist/index.js +37 -2
  17. package/dist/lib/element.d.ts +4 -4
  18. package/dist/lib/element.js +6 -5
  19. package/dist/lib/lintConfig.d.ts +13 -0
  20. package/dist/lib/lintConfig.js +278 -0
  21. package/dist/lib/lsp.d.ts +7 -7
  22. package/dist/lib/lsp.js +18 -20
  23. package/dist/lib/node.d.ts +1 -1
  24. package/dist/lib/node.js +646 -606
  25. package/dist/lib/range.d.ts +2 -2
  26. package/dist/lib/range.js +2 -2
  27. package/dist/lib/text.js +76 -62
  28. package/dist/lib/title.d.ts +11 -4
  29. package/dist/lib/title.js +16 -6
  30. package/dist/mixin/attributesParent.d.ts +6 -6
  31. package/dist/mixin/attributesParent.js +4 -4
  32. package/dist/mixin/cached.d.ts +5 -0
  33. package/dist/mixin/cached.js +22 -0
  34. package/dist/mixin/clone.d.ts +5 -0
  35. package/dist/mixin/clone.js +23 -0
  36. package/dist/mixin/hidden.js +68 -18
  37. package/dist/mixin/sol.js +1 -1
  38. package/dist/parser/commentAndExt.js +6 -4
  39. package/dist/parser/converter.js +1 -1
  40. package/dist/parser/html.js +3 -3
  41. package/dist/parser/table.js +2 -2
  42. package/dist/src/arg.js +24 -17
  43. package/dist/src/atom.js +76 -31
  44. package/dist/src/attribute.js +79 -39
  45. package/dist/src/attributes.d.ts +7 -7
  46. package/dist/src/attributes.js +417 -366
  47. package/dist/src/commented.js +81 -35
  48. package/dist/src/converter.js +13 -7
  49. package/dist/src/converterFlags.js +33 -22
  50. package/dist/src/converterRule.js +263 -216
  51. package/dist/src/extLink.js +21 -16
  52. package/dist/src/gallery.js +44 -27
  53. package/dist/src/heading.js +48 -43
  54. package/dist/src/hidden.js +14 -9
  55. package/dist/src/html.js +92 -60
  56. package/dist/src/imageParameter.js +13 -6
  57. package/dist/src/imagemap.js +32 -25
  58. package/dist/src/index.d.ts +2 -2
  59. package/dist/src/index.js +61 -50
  60. package/dist/src/link/base.d.ts +1 -1
  61. package/dist/src/link/base.js +35 -23
  62. package/dist/src/link/file.js +409 -354
  63. package/dist/src/link/galleryImage.js +9 -5
  64. package/dist/src/link/index.d.ts +1 -1
  65. package/dist/src/link/index.js +8 -4
  66. package/dist/src/link/redirectTarget.js +7 -3
  67. package/dist/src/magicLink.js +39 -26
  68. package/dist/src/nested.js +122 -74
  69. package/dist/src/nowiki/base.js +5 -2
  70. package/dist/src/nowiki/comment.js +5 -1
  71. package/dist/src/nowiki/index.js +4 -4
  72. package/dist/src/nowiki/quote.js +32 -46
  73. package/dist/src/onlyinclude.js +17 -9
  74. package/dist/src/paramTag/index.js +21 -14
  75. package/dist/src/parameter.js +26 -20
  76. package/dist/src/pre.js +91 -45
  77. package/dist/src/syntax.js +14 -10
  78. package/dist/src/table/index.js +554 -501
  79. package/dist/src/table/td.d.ts +1 -1
  80. package/dist/src/table/td.js +91 -82
  81. package/dist/src/table/trBase.js +183 -130
  82. package/dist/src/tagPair/ext.js +38 -23
  83. package/dist/src/tagPair/include.js +5 -5
  84. package/dist/src/tagPair/index.js +2 -3
  85. package/dist/src/tagPair/translate.js +150 -103
  86. package/dist/src/transclude.d.ts +15 -1
  87. package/dist/src/transclude.js +56 -21
  88. package/dist/util/html.js +46 -41
  89. package/dist/util/lint.js +7 -9
  90. package/dist/util/sharable.js +1 -1
  91. package/dist/util/sharable.mjs +2 -2
  92. package/dist/util/string.js +13 -7
  93. package/extensions/dist/base.js +9 -2
  94. package/extensions/typings.d.ts +2 -1
  95. package/i18n/zh-hans.json +1 -1
  96. package/i18n/zh-hant.json +1 -1
  97. package/package.json +20 -15
@@ -1,4 +1,11 @@
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
+ };
2
9
  var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
10
  function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
11
  var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
@@ -26,13 +33,6 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
26
33
  if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
34
  done = true;
28
35
  };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
@@ -49,7 +49,7 @@ const galleryImage_1 = require("./link/galleryImage");
49
49
  const imagemapLink_1 = require("./imagemapLink");
50
50
  /* NOT FOR BROWSER */
51
51
  const constants_1 = require("../util/constants");
52
- const html_1 = require("../util/html");
52
+ const clone_1 = require("../mixin/clone");
53
53
  const singleLine_1 = require("../mixin/singleLine");
54
54
  /**
55
55
  * `<imagemap>`
@@ -61,10 +61,14 @@ let ImagemapToken = (() => {
61
61
  let _classExtraInitializers = [];
62
62
  let _classThis;
63
63
  let _classSuper = index_2.Token;
64
+ let _instanceExtraInitializers = [];
65
+ let _cloneNode_decorators;
64
66
  var ImagemapToken = class extends _classSuper {
65
67
  static { _classThis = this; }
66
68
  static {
67
69
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
70
+ _cloneNode_decorators = [clone_1.clone];
71
+ __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);
68
72
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
69
73
  ImagemapToken = _classThis = _classDescriptor.value;
70
74
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
@@ -83,6 +87,7 @@ let ImagemapToken = (() => {
83
87
  super(undefined, config, accum, {
84
88
  GalleryImageToken: ':', ImagemapLinkToken: ':', NoincludeToken: ':', AstText: ':',
85
89
  });
90
+ __runInitializers(this, _instanceExtraInitializers);
86
91
  if (!inner) {
87
92
  return;
88
93
  }
@@ -143,22 +148,24 @@ let ImagemapToken = (() => {
143
148
  }
144
149
  /** @private */
145
150
  lint(start = this.getAbsoluteIndex(), re) {
146
- const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
147
- if (this.image) {
148
- errors.push(...this.childNodes.filter(child => {
149
- const str = child.toString().trim();
150
- return child.is('noinclude') && str && !str.startsWith('#');
151
- }).map(child => {
152
- const e = (0, lint_1.generateForChild)(child, rect, 'invalid-imagemap', 'invalid link in <imagemap>');
153
- e.suggestions = [
154
- { desc: 'remove', range: [e.startIndex - 1, e.endIndex], text: '' },
155
- { desc: 'comment', range: [e.startIndex, e.startIndex], text: '# ' },
156
- ];
157
- return e;
158
- }));
159
- }
160
- else {
161
- errors.push((0, lint_1.generateForSelf)(this, rect, 'invalid-imagemap', '<imagemap> without an image'));
151
+ const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start), { childNodes, image } = this, rule = 'invalid-imagemap', s = index_1.default.lintConfig.getSeverity(rule, image ? 'link' : 'image');
152
+ if (s) {
153
+ if (image) {
154
+ errors.push(...childNodes.filter(child => {
155
+ const str = child.toString().trim();
156
+ return child.is('noinclude') && str && !str.startsWith('#');
157
+ }).map(child => {
158
+ const e = (0, lint_1.generateForChild)(child, rect, rule, 'invalid link in <imagemap>', s);
159
+ e.suggestions = [
160
+ { desc: 'remove', range: [e.startIndex - 1, e.endIndex], text: '' },
161
+ { desc: 'comment', range: [e.startIndex, e.startIndex], text: '# ' },
162
+ ];
163
+ return e;
164
+ }));
165
+ }
166
+ else {
167
+ errors.push((0, lint_1.generateForSelf)(this, rect, rule, '<imagemap> without an image', s));
168
+ }
162
169
  }
163
170
  return errors;
164
171
  }
@@ -190,7 +197,7 @@ let ImagemapToken = (() => {
190
197
  }
191
198
  cloneNode() {
192
199
  // @ts-expect-error abstract class
193
- return (0, html_1.cloneNode)(this, () => new ImagemapToken(undefined, this.getAttribute('config')));
200
+ return new ImagemapToken(undefined, this.getAttribute('config'));
194
201
  }
195
202
  };
196
203
  return ImagemapToken = _classThis;
@@ -51,7 +51,7 @@ export declare class Token extends AstElement {
51
51
  *
52
52
  * 创建标签
53
53
  * @param tagName tag name / 标签名
54
- * @param options 选项
54
+ * @param options options / 选项
55
55
  * @param options.selfClosing whether to be a self-closing tag / 是否自封闭
56
56
  * @param options.closing whether to be a closing tag / 是否是闭合标签
57
57
  * @throws `RangeError` 非法的标签名
@@ -77,7 +77,7 @@ export declare class Token extends AstElement {
77
77
  * Check if a title is an interwiki link
78
78
  *
79
79
  * 判断标题是否是跨维基链接
80
- * @param title 标题
80
+ * @param title title / 标题
81
81
  */
82
82
  isInterwiki(title: string): RegExpExecArray | null;
83
83
  /**
package/dist/src/index.js CHANGED
@@ -95,10 +95,12 @@ const html_1 = require("../util/html");
95
95
  const ranges_1 = require("../lib/ranges");
96
96
  const range_1 = require("../lib/range");
97
97
  const readOnly_1 = require("../mixin/readOnly");
98
+ const cached_1 = require("../mixin/cached");
98
99
  /* NOT FOR BROWSER END */
99
100
  /* NOT FOR BROWSER ONLY */
100
101
  const document_1 = require("../lib/document");
101
102
  const lsp_1 = require("../lib/lsp");
103
+ const lintSelectors = ['category', 'html-attr#id,ext-attr#id,table-attr#id'];
102
104
  /* NOT FOR BROWSER */
103
105
  /**
104
106
  * 可接受的Token类型
@@ -135,13 +137,16 @@ let Token = (() => {
135
137
  let _instanceExtraInitializers = [];
136
138
  let _lint_decorators;
137
139
  let _safeReplaceWith_decorators;
140
+ let _toHtmlInternal_decorators;
138
141
  return class Token extends _classSuper {
139
142
  static {
140
143
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
141
144
  _lint_decorators = [(0, readOnly_1.readOnly)(true)];
142
145
  _safeReplaceWith_decorators = [(0, readOnly_1.readOnly)()];
146
+ _toHtmlInternal_decorators = [(0, cached_1.cached)()];
143
147
  __esDecorate(this, null, _lint_decorators, { kind: "method", name: "lint", static: false, private: false, access: { has: obj => "lint" in obj, get: obj => obj.lint }, metadata: _metadata }, null, _instanceExtraInitializers);
144
148
  __esDecorate(this, null, _safeReplaceWith_decorators, { kind: "method", name: "safeReplaceWith", static: false, private: false, access: { has: obj => "safeReplaceWith" in obj, get: obj => obj.safeReplaceWith }, metadata: _metadata }, null, _instanceExtraInitializers);
149
+ __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);
145
150
  if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
146
151
  }
147
152
  #type = (__runInitializers(this, _instanceExtraInitializers), 'plain');
@@ -437,7 +442,7 @@ let Token = (() => {
437
442
  return this.#stage;
438
443
  /* PRINT ONLY */
439
444
  case 'invalid':
440
- return (this.type === 'table-inter' && (0, lint_1.isFostered)(this) === 'error');
445
+ return (this.type === 'table-inter' && (0, lint_1.isFostered)(this) === 2);
441
446
  /* PRINT ONLY END */
442
447
  /* NOT FOR BROWSER */
443
448
  case 'protectedChildren':
@@ -507,51 +512,53 @@ let Token = (() => {
507
512
  /** @private */
508
513
  inTableAttrs() {
509
514
  return this.closest('table-attrs,ext')?.type === 'table-attrs' && (this.closest('table-attrs,arg,magic-word,template')?.is('table-attrs')
510
- ? 'error'
511
- : 'warning');
515
+ ? 2
516
+ : 1);
512
517
  }
513
518
  /** @private */
514
519
  inHtmlAttrs() {
515
520
  return this.closest('html-attrs,ext')?.is('html-attrs')
516
- ? 'error'
521
+ ? 2
517
522
  : this.inTableAttrs();
518
523
  }
519
524
  /** @private */
520
525
  lint(start = this.getAbsoluteIndex(), re) {
521
526
  let errors = super.lint(start, re);
522
527
  if (this.type === 'root') {
523
- const record = new Map(), selector = 'category,html-attr#id,ext-attr#id,table-attr#id';
524
- for (const cat of this.querySelectorAll(selector)) {
525
- let key;
526
- if (cat.is('category')) {
527
- key = cat.name;
528
- }
529
- else {
530
- const value = cat.getValue();
531
- if (value && value !== true) {
532
- key = `#${value}`;
533
- }
534
- }
535
- if (key) {
536
- const thisCat = record.get(key);
537
- if (thisCat) {
538
- thisCat.add(cat);
528
+ const record = new Map(), r = 'no-duplicate', s = ['category', 'id'].map(key => index_1.default.lintConfig.getSeverity(r, key)), selector = lintSelectors.filter((_, i) => s[i]).join();
529
+ if (selector) {
530
+ for (const cat of this.querySelectorAll(selector)) {
531
+ let key;
532
+ if (cat.is('category')) {
533
+ key = cat.name;
539
534
  }
540
535
  else {
541
- record.set(key, new Set([cat]));
536
+ const value = cat.getValue();
537
+ if (value && value !== true) {
538
+ key = `#${value}`;
539
+ }
542
540
  }
543
- }
544
- }
545
- for (const [key, value] of record) {
546
- if (value.size > 1 && !key.startsWith('#mw-customcollapsible-')) {
547
- const isCat = !key.startsWith('#'), msg = `duplicated ${isCat ? 'category' : 'id'}`, severity = isCat ? 'error' : 'warning';
548
- errors.push(...[...value].map(cat => {
549
- const e = (0, lint_1.generateForSelf)(cat, { start: cat.getAbsoluteIndex() }, 'no-duplicate', msg, severity);
550
- if (isCat) {
551
- e.suggestions = [{ desc: 'remove', range: [e.startIndex, e.endIndex], text: '' }];
541
+ if (key) {
542
+ const thisCat = record.get(key);
543
+ if (thisCat) {
544
+ thisCat.add(cat);
552
545
  }
553
- return e;
554
- }));
546
+ else {
547
+ record.set(key, new Set([cat]));
548
+ }
549
+ }
550
+ }
551
+ for (const [key, value] of record) {
552
+ if (value.size > 1 && !key.startsWith('#mw-customcollapsible-')) {
553
+ const isCat = !key.startsWith('#'), msg = `duplicated ${isCat ? 'category' : 'id'}`, severity = s[isCat ? 0 : 1];
554
+ errors.push(...[...value].map(cat => {
555
+ const e = (0, lint_1.generateForSelf)(cat, { start: cat.getAbsoluteIndex() }, r, msg, severity);
556
+ if (isCat) {
557
+ e.suggestions = [{ desc: 'remove', range: [e.startIndex, e.endIndex], text: '' }];
558
+ }
559
+ return e;
560
+ }));
561
+ }
555
562
  }
556
563
  }
557
564
  const regex = /<!--\s*lint-(disable(?:(?:-next)?-line)?|enable)(\s[\sa-z,-]*)?-->/gu, wikitext = this.toString(), ignores = [];
@@ -562,7 +569,7 @@ let Token = (() => {
562
569
  line: this.posFromIndex(index).top + (type === 'disable-line' ? 0 : 1),
563
570
  from: type === 'disable' ? regex.lastIndex : undefined,
564
571
  to: type === 'enable' ? regex.lastIndex : undefined,
565
- rules: detail ? new Set(detail.split(',').map(r => r.trim())) : undefined,
572
+ rules: detail ? new Set(detail.split(',').map(rule => rule.trim())) : undefined,
566
573
  });
567
574
  mt = regex.exec(wikitext);
568
575
  }
@@ -605,21 +612,25 @@ let Token = (() => {
605
612
  /* NOT FOR BROWSER ONLY */
606
613
  }
607
614
  else if (index_1.default.lintCSS && (0, lsp_1.isAttr)(this, true)) {
608
- const root = this.getRootNode(), textDoc = new document_1.EmbeddedCSSDocument(root, this);
609
- errors.push(...document_1.cssLSP.doValidation(textDoc, textDoc.styleSheet)
610
- .filter(({ code }) => code !== 'css-ruleorselectorexpected')
611
- .map(({ range: { start: { line, character }, end }, message, severity, code }) => ({
612
- code: code,
613
- rule: 'invalid-css',
614
- message,
615
- severity: severity === 1 ? 'error' : 'warning',
616
- startLine: line,
617
- startCol: character,
618
- startIndex: root.indexFromPos(line, character),
619
- endLine: end.line,
620
- endCol: end.character,
621
- endIndex: root.indexFromPos(end.line, end.character),
622
- })));
615
+ const rule = 'invalid-css', s = index_1.default.lintConfig.getSeverity(rule), sWarn = index_1.default.lintConfig.getSeverity(rule, 'warn');
616
+ if (s) {
617
+ const root = this.getRootNode(), textDoc = new document_1.EmbeddedCSSDocument(root, this);
618
+ errors.push(...document_1.cssLSP.doValidation(textDoc, textDoc.styleSheet)
619
+ .filter(({ code, severity }) => code !== 'css-ruleorselectorexpected' && code !== 'emptyRules'
620
+ && (sWarn || severity === 1))
621
+ .map(({ range: { start: { line, character }, end }, message, severity, code }) => ({
622
+ code: code,
623
+ rule: 'invalid-css',
624
+ message,
625
+ severity: severity === 1 ? s : sWarn,
626
+ startLine: line,
627
+ startCol: character,
628
+ startIndex: root.indexFromPos(line, character),
629
+ endLine: end.line,
630
+ endCol: end.character,
631
+ endIndex: root.indexFromPos(end.line, end.character),
632
+ })));
633
+ }
623
634
  /* NOT FOR BROWSER ONLY END */
624
635
  }
625
636
  return errors;
@@ -747,7 +758,7 @@ let Token = (() => {
747
758
  *
748
759
  * 创建标签
749
760
  * @param tagName tag name / 标签名
750
- * @param options 选项
761
+ * @param options options / 选项
751
762
  * @param options.selfClosing whether to be a self-closing tag / 是否自封闭
752
763
  * @param options.closing whether to be a closing tag / 是否是闭合标签
753
764
  * @throws `RangeError` 非法的标签名
@@ -777,7 +788,7 @@ let Token = (() => {
777
788
  * Check if a title is an interwiki link
778
789
  *
779
790
  * 判断标题是否是跨维基链接
780
- * @param title 标题
791
+ * @param title title / 标题
781
792
  */
782
793
  isInterwiki(title) {
783
794
  return index_1.default.isInterwiki(title, this.#config);
@@ -46,7 +46,7 @@ export declare abstract class LinkBaseToken extends Token {
46
46
  * Set the fragment
47
47
  *
48
48
  * 设置片段标识符
49
- * @param fragment 片段标识符
49
+ * @param fragment URI fragment / 片段标识符
50
50
  */
51
51
  setFragment(fragment?: string): void;
52
52
  /**
@@ -1,4 +1,11 @@
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
+ };
2
9
  var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
10
  function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
11
  var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
@@ -26,13 +33,6 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
26
33
  if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
34
  done = true;
28
35
  };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
@@ -43,12 +43,13 @@ const constants_1 = require("../../util/constants");
43
43
  const string_1 = require("../../util/string");
44
44
  const rect_1 = require("../../lib/rect");
45
45
  const padded_1 = require("../../mixin/padded");
46
- const index_1 = require("../index");
46
+ const index_1 = __importDefault(require("../../index"));
47
+ const index_2 = require("../index");
47
48
  const atom_1 = require("../atom");
48
49
  /* NOT FOR BROWSER */
49
50
  const debug_1 = require("../../util/debug");
50
51
  const noEscape_1 = require("../../mixin/noEscape");
51
- const index_2 = __importDefault(require("../../index"));
52
+ const cached_1 = require("../../mixin/cached");
52
53
  /* NOT FOR BROWSER END */
53
54
  /**
54
55
  * 是否为普通内链
@@ -66,17 +67,21 @@ let LinkBaseToken = (() => {
66
67
  let _classDescriptor;
67
68
  let _classExtraInitializers = [];
68
69
  let _classThis;
69
- let _classSuper = index_1.Token;
70
+ let _classSuper = index_2.Token;
71
+ let _instanceExtraInitializers = [];
72
+ let _toHtmlInternal_decorators;
70
73
  var LinkBaseToken = class extends _classSuper {
71
74
  static { _classThis = this; }
72
75
  static {
73
76
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
77
+ _toHtmlInternal_decorators = [(0, cached_1.cached)()];
78
+ __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);
74
79
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
75
80
  LinkBaseToken = _classThis = _classDescriptor.value;
76
81
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
77
82
  __runInitializers(_classThis, _classExtraInitializers);
78
83
  }
79
- #bracket = true;
84
+ #bracket = (__runInitializers(this, _instanceExtraInitializers), true);
80
85
  #delimiter;
81
86
  #title;
82
87
  /* NOT FOR BROWSER END */
@@ -127,7 +132,7 @@ let LinkBaseToken = (() => {
127
132
  'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
128
133
  }));
129
134
  if (linkText !== undefined) {
130
- const inner = new index_1.Token(linkText, config, accum, {
135
+ const inner = new index_2.Token(linkText, config, accum, {
131
136
  'Stage-5': ':', QuoteToken: ':', ConverterToken: ':',
132
137
  });
133
138
  inner.type = 'link-text';
@@ -210,18 +215,23 @@ let LinkBaseToken = (() => {
210
215
  /** @private */
211
216
  lint(start = this.getAbsoluteIndex(), re) {
212
217
  const errors = super.lint(start, re), { childNodes: [target, linkText], type } = this, { encoded, fragment } = this.#title, rect = new rect_1.BoundingRect(this, start);
213
- if (target.childNodes.some(({ type: t }) => t === 'template')) {
214
- errors.push((0, lint_1.generateForChild)(target, rect, 'unknown-page', 'template in an internal link target', 'warning'));
218
+ let rule = 'unknown-page', s = index_1.default.lintConfig.getSeverity(rule);
219
+ if (s && target.childNodes.some(({ type: t }) => t === 'template')) {
220
+ errors.push((0, lint_1.generateForChild)(target, rect, rule, 'template in an internal link target', s));
215
221
  }
216
- if (encoded) {
217
- const e = (0, lint_1.generateForChild)(target, rect, 'url-encoding', 'unnecessary URL encoding in an internal link', 'warning');
222
+ rule = 'url-encoding';
223
+ s = index_1.default.lintConfig.getSeverity(rule);
224
+ if (s && encoded) {
225
+ const e = (0, lint_1.generateForChild)(target, rect, rule, 'unnecessary URL encoding in an internal link', s);
218
226
  e.fix = { desc: 'decode', range: [e.startIndex, e.endIndex], text: (0, string_1.rawurldecode)(target.text()) };
219
227
  errors.push(e);
220
228
  }
221
- if (type === 'link' || type === 'category') {
229
+ rule = 'pipe-like';
230
+ s = index_1.default.lintConfig.getSeverity(rule, 'link');
231
+ if (s && (type === 'link' || type === 'category')) {
222
232
  const j = linkText?.childNodes.findIndex(c => c.type === 'text' && c.data.includes('|')), textNode = linkText?.childNodes[j];
223
233
  if (textNode) {
224
- const e = (0, lint_1.generateForChild)(linkText, rect, 'pipe-like', 'additional "|" in the link text', 'warning'), i = e.startIndex + linkText.getRelativeIndex(j);
234
+ const e = (0, lint_1.generateForChild)(linkText, rect, rule, 'additional "|" in the link text', s), i = e.startIndex + linkText.getRelativeIndex(j);
225
235
  e.suggestions = [
226
236
  {
227
237
  desc: 'escape',
@@ -232,8 +242,10 @@ let LinkBaseToken = (() => {
232
242
  errors.push(e);
233
243
  }
234
244
  }
235
- if (fragment !== undefined && !isLink(type)) {
236
- const e = (0, lint_1.generateForChild)(target, rect, 'no-ignored', 'useless fragment', 'warning'), j = target.childNodes.findIndex(c => c.type === 'text' && c.data.includes('#')), textNode = target.childNodes[j];
245
+ rule = 'no-ignored';
246
+ s = index_1.default.lintConfig.getSeverity(rule, 'fragment');
247
+ if (s && fragment !== undefined && !isLink(type)) {
248
+ const e = (0, lint_1.generateForChild)(target, rect, rule, 'useless fragment', s), j = target.childNodes.findIndex(c => c.type === 'text' && c.data.includes('#')), textNode = target.childNodes[j];
237
249
  if (textNode) {
238
250
  e.fix = {
239
251
  desc: 'remove',
@@ -281,7 +293,7 @@ let LinkBaseToken = (() => {
281
293
  * @param link link target / 链接目标
282
294
  */
283
295
  setTarget(link) {
284
- const config = this.getAttribute('config'), { childNodes } = index_2.default.parse(link, this.getAttribute('include'), 2, config), token = debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'link-target', config, [], {
296
+ const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(link, this.getAttribute('include'), 2, config), token = debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'link-target', config, [], {
285
297
  'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
286
298
  }));
287
299
  token.safeAppend(childNodes);
@@ -291,7 +303,7 @@ let LinkBaseToken = (() => {
291
303
  * Set the fragment
292
304
  *
293
305
  * 设置片段标识符
294
- * @param fragment 片段标识符
306
+ * @param fragment URI fragment / 片段标识符
295
307
  */
296
308
  setFragment(fragment) {
297
309
  const { type, name } = this;
@@ -311,7 +323,7 @@ let LinkBaseToken = (() => {
311
323
  this.childNodes[1]?.remove();
312
324
  return;
313
325
  }
314
- const root = index_2.default
326
+ const root = index_1.default
315
327
  .parse(linkStr, this.getAttribute('include'), undefined, this.getAttribute('config'));
316
328
  if (this.length === 1) {
317
329
  root.type = 'link-text';