wikiparser-node 1.21.1 → 1.21.3

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 (96) hide show
  1. package/README.md +12 -6
  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/coverage/badge.svg +1 -1
  6. package/dist/addon/table.js +5 -5
  7. package/dist/addon/token.js +116 -7
  8. package/dist/base.d.mts +6 -1
  9. package/dist/base.d.ts +6 -1
  10. package/dist/bin/config.js +3 -3
  11. package/dist/index.d.ts +9 -2
  12. package/dist/index.js +10 -1
  13. package/dist/lib/element.d.ts +1 -0
  14. package/dist/lib/element.js +3 -1
  15. package/dist/lib/lintConfig.d.ts +13 -0
  16. package/dist/lib/lintConfig.js +161 -0
  17. package/dist/lib/lsp.d.ts +2 -0
  18. package/dist/lib/lsp.js +11 -8
  19. package/dist/lib/node.d.ts +20 -3
  20. package/dist/lib/node.js +647 -585
  21. package/dist/lib/text.d.ts +2 -0
  22. package/dist/lib/text.js +21 -12
  23. package/dist/lib/title.d.ts +3 -1
  24. package/dist/lib/title.js +3 -1
  25. package/dist/mixin/attributesParent.d.ts +6 -6
  26. package/dist/mixin/attributesParent.js +4 -4
  27. package/dist/mixin/cached.d.ts +5 -0
  28. package/dist/mixin/cached.js +22 -0
  29. package/dist/mixin/clone.d.ts +5 -0
  30. package/dist/mixin/clone.js +23 -0
  31. package/dist/mixin/hidden.js +68 -18
  32. package/dist/mixin/sol.js +2 -2
  33. package/dist/parser/commentAndExt.js +1 -1
  34. package/dist/parser/html.js +3 -3
  35. package/dist/parser/list.js +6 -3
  36. package/dist/parser/table.js +4 -4
  37. package/dist/src/arg.js +14 -8
  38. package/dist/src/atom.js +76 -31
  39. package/dist/src/attribute.d.ts +1 -0
  40. package/dist/src/attribute.js +51 -20
  41. package/dist/src/attributes.d.ts +7 -7
  42. package/dist/src/attributes.js +415 -366
  43. package/dist/src/commented.js +81 -35
  44. package/dist/src/converter.js +14 -8
  45. package/dist/src/converterFlags.js +33 -22
  46. package/dist/src/converterRule.js +263 -216
  47. package/dist/src/extLink.js +23 -18
  48. package/dist/src/gallery.d.ts +12 -2
  49. package/dist/src/gallery.js +30 -10
  50. package/dist/src/heading.d.ts +6 -1
  51. package/dist/src/heading.js +73 -59
  52. package/dist/src/hidden.js +14 -9
  53. package/dist/src/html.js +29 -10
  54. package/dist/src/imageParameter.d.ts +1 -0
  55. package/dist/src/imageParameter.js +15 -7
  56. package/dist/src/imagemap.js +35 -28
  57. package/dist/src/index.d.ts +3 -0
  58. package/dist/src/index.js +66 -49
  59. package/dist/src/link/base.js +17 -12
  60. package/dist/src/link/file.d.ts +9 -1
  61. package/dist/src/link/file.js +401 -346
  62. package/dist/src/link/galleryImage.js +12 -6
  63. package/dist/src/link/index.js +7 -3
  64. package/dist/src/link/redirectTarget.d.ts +6 -1
  65. package/dist/src/link/redirectTarget.js +14 -5
  66. package/dist/src/magicLink.d.ts +6 -1
  67. package/dist/src/magicLink.js +30 -16
  68. package/dist/src/nested.js +122 -74
  69. package/dist/src/nowiki/base.js +5 -2
  70. package/dist/src/nowiki/comment.js +6 -2
  71. package/dist/src/nowiki/index.js +4 -4
  72. package/dist/src/nowiki/listBase.d.ts +6 -1
  73. package/dist/src/nowiki/listBase.js +7 -2
  74. package/dist/src/nowiki/quote.d.ts +6 -1
  75. package/dist/src/nowiki/quote.js +22 -10
  76. package/dist/src/onlyinclude.js +17 -9
  77. package/dist/src/paramTag/index.js +21 -14
  78. package/dist/src/parameter.js +26 -20
  79. package/dist/src/pre.js +91 -45
  80. package/dist/src/redirect.js +1 -1
  81. package/dist/src/syntax.js +14 -10
  82. package/dist/src/table/index.js +550 -502
  83. package/dist/src/table/td.js +66 -59
  84. package/dist/src/table/trBase.js +179 -129
  85. package/dist/src/tagPair/ext.js +32 -20
  86. package/dist/src/tagPair/include.js +5 -5
  87. package/dist/src/tagPair/translate.js +150 -103
  88. package/dist/src/transclude.d.ts +21 -8
  89. package/dist/src/transclude.js +56 -34
  90. package/dist/util/html.js +45 -43
  91. package/dist/util/lint.js +10 -7
  92. package/dist/util/string.js +13 -7
  93. package/extensions/dist/base.js +2 -2
  94. package/i18n/zh-hans.json +1 -1
  95. package/i18n/zh-hant.json +1 -1
  96. package/package.json +15 -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
  };
@@ -47,6 +47,8 @@ const noinclude_1 = require("./nowiki/noinclude");
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
+ const cached_1 = require("../mixin/cached");
50
52
  /**
51
53
  * gallery tag
52
54
  *
@@ -59,10 +61,17 @@ let GalleryToken = (() => {
59
61
  let _classExtraInitializers = [];
60
62
  let _classThis;
61
63
  let _classSuper = index_2.Token;
64
+ let _instanceExtraInitializers = [];
65
+ let _cloneNode_decorators;
66
+ let _toHtmlInternal_decorators;
62
67
  var GalleryToken = class extends _classSuper {
63
68
  static { _classThis = this; }
64
69
  static {
65
70
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
71
+ _cloneNode_decorators = [clone_1.clone];
72
+ _toHtmlInternal_decorators = [(0, cached_1.cached)()];
73
+ __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);
74
+ __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);
66
75
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
67
76
  GalleryToken = _classThis = _classDescriptor.value;
68
77
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
@@ -73,11 +82,21 @@ let GalleryToken = (() => {
73
82
  return 'ext-inner';
74
83
  }
75
84
  /* PRINT ONLY */
76
- /** image widths / 图片宽度 */
85
+ /**
86
+ * image widths
87
+ *
88
+ * 图片宽度
89
+ * @since v1.12.5
90
+ */
77
91
  get widths() {
78
92
  return this.#getSize('widths');
79
93
  }
80
- /** image heights / 图片高度 */
94
+ /**
95
+ * image heights
96
+ *
97
+ * 图片高度
98
+ * @since v1.12.5
99
+ */
81
100
  get heights() {
82
101
  return this.#getSize('heights');
83
102
  }
@@ -93,6 +112,7 @@ let GalleryToken = (() => {
93
112
  super(undefined, config, accum, {
94
113
  AstText: ':', GalleryImageToken: ':', NoincludeToken: ':',
95
114
  });
115
+ __runInitializers(this, _instanceExtraInitializers);
96
116
  for (const line of inner?.split('\n') ?? []) {
97
117
  const matches = /^([^|]+)(?:\|(.*))?/u.exec(line);
98
118
  if (!matches) {
@@ -173,7 +193,7 @@ let GalleryToken = (() => {
173
193
  /* NOT FOR BROWSER */
174
194
  cloneNode() {
175
195
  // @ts-expect-error abstract class
176
- return (0, html_1.cloneNode)(this, () => new GalleryToken(undefined, this.getAttribute('config')));
196
+ return new GalleryToken(undefined, this.getAttribute('config'));
177
197
  }
178
198
  /**
179
199
  * Insert an image
@@ -25,7 +25,12 @@ export declare abstract class HeadingToken extends Token {
25
25
  get innerText(): string;
26
26
  /** @throws `Error` 首尾包含`=` */
27
27
  set innerText(text: string);
28
- /** id attribute / id属性 */
28
+ /**
29
+ * id attribute
30
+ *
31
+ * id属性
32
+ * @since v1.12.4
33
+ */
29
34
  get id(): string;
30
35
  /**
31
36
  * @param level 标题层级
@@ -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
  };
@@ -47,9 +47,11 @@ const syntax_1 = require("./syntax");
47
47
  /* NOT FOR BROWSER */
48
48
  const constants_1 = require("../util/constants");
49
49
  const string_1 = require("../util/string");
50
+ const html_1 = require("../util/html");
50
51
  const fixed_1 = require("../mixin/fixed");
51
52
  const sol_1 = require("../mixin/sol");
52
53
  const noEscape_1 = require("../mixin/noEscape");
54
+ const cached_1 = require("../mixin/cached");
53
55
  /* NOT FOR BROWSER END */
54
56
  /**
55
57
  * section heading
@@ -63,16 +65,20 @@ let HeadingToken = (() => {
63
65
  let _classExtraInitializers = [];
64
66
  let _classThis;
65
67
  let _classSuper = index_2.Token;
68
+ let _instanceExtraInitializers = [];
69
+ let _toHtmlInternal_decorators;
66
70
  var HeadingToken = class extends _classSuper {
67
71
  static { _classThis = this; }
68
72
  static {
69
73
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
74
+ _toHtmlInternal_decorators = [(0, cached_1.cached)()];
75
+ __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);
70
76
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
71
77
  HeadingToken = _classThis = _classDescriptor.value;
72
78
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
73
79
  __runInitializers(_classThis, _classExtraInitializers);
74
80
  }
75
- #level;
81
+ #level = __runInitializers(this, _instanceExtraInitializers);
76
82
  /* NOT FOR BROWSER END */
77
83
  get type() {
78
84
  return 'heading';
@@ -98,7 +104,12 @@ let HeadingToken = (() => {
98
104
  .parse(text, this.getAttribute('include'), undefined, this.getAttribute('config'));
99
105
  this.firstChild.safeReplaceChildren(childNodes);
100
106
  }
101
- /** id attribute / id属性 */
107
+ /**
108
+ * id attribute
109
+ *
110
+ * id属性
111
+ * @since v1.12.4
112
+ */
102
113
  get id() {
103
114
  return this.#getId(true);
104
115
  }
@@ -147,60 +158,69 @@ let HeadingToken = (() => {
147
158
  lint(start = this.getAbsoluteIndex(), re) {
148
159
  const errors = super.lint(start, re), { firstChild, level } = this, innerStr = firstChild.toString(), unbalancedStart = innerStr.startsWith('='), unbalanced = unbalancedStart || innerStr.endsWith('='), quotes = firstChild.childNodes.filter((0, debug_1.isToken)('quote')), boldQuotes = quotes.filter(({ bold }) => bold), italicQuotes = quotes.filter(({ italic }) => italic), rect = new rect_1.BoundingRect(this, start), s = this.inHtmlAttrs();
149
160
  if (this.level === 1) {
150
- const e = (0, lint_1.generateForChild)(firstChild, rect, 'h1', '<h1>');
151
- if (!unbalanced) {
152
- e.suggestions = [{ desc: 'h2', range: [e.startIndex, e.endIndex], text: `=${innerStr}=` }];
161
+ const rule = 'h1', severity = index_1.default.lintConfig.getSeverity(rule);
162
+ if (severity) {
163
+ const e = (0, lint_1.generateForChild)(firstChild, rect, rule, '<h1>', severity);
164
+ if (!unbalanced) {
165
+ e.suggestions = [{ desc: 'h2', range: [e.startIndex, e.endIndex], text: `=${innerStr}=` }];
166
+ }
167
+ errors.push(e);
153
168
  }
154
- errors.push(e);
155
169
  }
156
170
  if (unbalanced) {
157
- const e = (0, lint_1.generateForChild)(firstChild, rect, 'unbalanced-header', index_1.default.msg('unbalanced $1 in a section header', '"="'));
158
- if (innerStr === '=') {
159
- //
160
- }
161
- else if (unbalancedStart) {
162
- const [extra] = /^=+/u.exec(innerStr), newLevel = level + extra.length;
163
- e.suggestions = [{ desc: `h${level}`, range: [e.startIndex, e.startIndex + extra.length], text: '' }];
164
- if (newLevel < 7) {
165
- e.suggestions.push({ desc: `h${newLevel}`, range: [e.endIndex, e.endIndex], text: extra });
171
+ const rule = 'unbalanced-header', severity = index_1.default.lintConfig.getSeverity(rule);
172
+ if (severity) {
173
+ const msg = index_1.default.msg('unbalanced $1 in a section header', '"="'), e = (0, lint_1.generateForChild)(firstChild, rect, rule, msg, severity);
174
+ if (innerStr === '=') {
175
+ //
166
176
  }
167
- }
168
- else {
169
- const extra = /[^=](=+)$/u.exec(innerStr)[1], newLevel = level + extra.length;
170
- e.suggestions = [{ desc: `h${level}`, range: [e.endIndex - extra.length, e.endIndex], text: '' }];
171
- if (newLevel < 7) {
172
- e.suggestions.push({ desc: `h${newLevel}`, range: [e.startIndex, e.startIndex], text: extra });
177
+ else if (unbalancedStart) {
178
+ const [extra] = /^=+/u.exec(innerStr), newLevel = level + extra.length;
179
+ e.suggestions = [{ desc: `h${level}`, range: [e.startIndex, e.startIndex + extra.length], text: '' }];
180
+ if (newLevel < 7) {
181
+ e.suggestions.push({ desc: `h${newLevel}`, range: [e.endIndex, e.endIndex], text: extra });
182
+ }
173
183
  }
184
+ else {
185
+ const extra = /[^=](=+)$/u.exec(innerStr)[1], newLevel = level + extra.length;
186
+ e.suggestions = [{ desc: `h${level}`, range: [e.endIndex - extra.length, e.endIndex], text: '' }];
187
+ if (newLevel < 7) {
188
+ e.suggestions.push({ desc: `h${newLevel}`, range: [e.startIndex, e.startIndex], text: extra });
189
+ }
190
+ }
191
+ errors.push(e);
174
192
  }
175
- errors.push(e);
176
193
  }
177
194
  if (s) {
178
- errors.push((0, lint_1.generateForSelf)(this, rect, 'parsing-order', 'section header in an HTML tag', s));
195
+ errors.push((0, lint_1.generateForSelf)(this, rect, 'parsing-order', 'section header in HTML tag attributes', s));
179
196
  }
180
- const rootStr = this.getRootNode().toString();
181
- if (boldQuotes.length % 2) {
182
- const e = (0, lint_1.generateForChild)(boldQuotes[boldQuotes.length - 1], {
183
- ...rect, // eslint-disable-line @typescript-eslint/no-misused-spread
184
- start: start + level,
185
- left: rect.left + level,
186
- }, 'format-leakage', index_1.default.msg('unbalanced $1 in a section header', 'bold apostrophes')), end = start + level + innerStr.length;
187
- if (rootStr.slice(e.endIndex, end).trim()) {
188
- e.suggestions = [{ desc: 'close', range: [end, end], text: `'''` }];
189
- }
190
- else {
191
- e.fix = { desc: 'remove', range: [e.startIndex, e.endIndex], text: '' };
192
- }
193
- errors.push(e);
194
- }
195
- if (italicQuotes.length % 2) {
196
- const e = (0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, 'format-leakage', index_1.default.msg('unbalanced $1 in a section header', 'italic apostrophes')), end = start + level + innerStr.length;
197
- if (rootStr.slice(e.endIndex, end).trim()) {
198
- e.suggestions = [{ desc: 'close', range: [end, end], text: `''` }];
197
+ const rule = 'format-leakage', severity = index_1.default.lintConfig.getSeverity(rule, 'apostrophe');
198
+ if (severity) {
199
+ const rootStr = this.getRootNode().toString();
200
+ if (boldQuotes.length % 2) {
201
+ const e = (0, lint_1.generateForChild)(boldQuotes[boldQuotes.length - 1], {
202
+ ...rect, // eslint-disable-line @typescript-eslint/no-misused-spread
203
+ start: start + level,
204
+ left: rect.left + level,
205
+ }, rule, index_1.default.msg('unbalanced $1 in a section header', 'bold apostrophes'), severity), end = start + level + innerStr.length;
206
+ if (rootStr.slice(e.endIndex, end).trim()) {
207
+ e.suggestions = [{ desc: 'close', range: [end, end], text: `'''` }];
208
+ }
209
+ else {
210
+ e.fix = { desc: 'remove', range: [e.startIndex, e.endIndex], text: '' };
211
+ }
212
+ errors.push(e);
199
213
  }
200
- else {
201
- e.fix = { desc: 'remove', range: [e.startIndex, e.endIndex], text: '' };
214
+ if (italicQuotes.length % 2) {
215
+ const e = (0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, rule, index_1.default.msg('unbalanced $1 in a section header', 'italic apostrophes'), severity), end = start + level + innerStr.length;
216
+ if (rootStr.slice(e.endIndex, end).trim()) {
217
+ e.suggestions = [{ desc: 'close', range: [end, end], text: `''` }];
218
+ }
219
+ else {
220
+ e.fix = { desc: 'remove', range: [e.startIndex, e.endIndex], text: '' };
221
+ }
222
+ errors.push(e);
202
223
  }
203
- errors.push(e);
204
224
  }
205
225
  return errors;
206
226
  }
@@ -248,13 +268,7 @@ let HeadingToken = (() => {
248
268
  * @param expand 是否展开模板
249
269
  */
250
270
  #getId(expand) {
251
- const token = expand ? this.firstChild.expand() : this.firstChild;
252
- let id = (0, string_1.decodeHtml)((0, string_1.sanitizeAlt)(token.toHtmlInternal({ nocc: true })))
253
- .replace(/[\s_]+/gu, '_');
254
- if (id.endsWith('_')) {
255
- id = id.slice(0, -1);
256
- }
257
- return id;
271
+ return (0, html_1.getId)(this.firstChild[expand ? 'expand' : 'cloneNode']());
258
272
  }
259
273
  /** @private */
260
274
  toHtmlInternal() {
@@ -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,20 +33,13 @@ 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
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.HiddenToken = void 0;
38
38
  const hidden_1 = require("../mixin/hidden");
39
39
  const index_1 = require("./index");
40
40
  /* NOT FOR BROWSER */
41
41
  const constants_1 = require("../util/constants");
42
- const html_1 = require("../util/html");
42
+ const clone_1 = require("../mixin/clone");
43
43
  /* NOT FOR BROWSER END */
44
44
  /**
45
45
  * invisible token
@@ -52,10 +52,14 @@ let HiddenToken = (() => {
52
52
  let _classExtraInitializers = [];
53
53
  let _classThis;
54
54
  let _classSuper = index_1.Token;
55
+ let _instanceExtraInitializers = [];
56
+ let _cloneNode_decorators;
55
57
  var HiddenToken = class extends _classSuper {
56
58
  static { _classThis = this; }
57
59
  static {
58
60
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
61
+ _cloneNode_decorators = [clone_1.clone];
62
+ __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);
59
63
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
60
64
  HiddenToken = _classThis = _classDescriptor.value;
61
65
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
@@ -76,9 +80,10 @@ let HiddenToken = (() => {
76
80
  super(wikitext, config, accum, {
77
81
  'Stage-2': ':', '!HeadingToken': '',
78
82
  });
83
+ __runInitializers(this, _instanceExtraInitializers);
79
84
  }
80
85
  cloneNode() {
81
- return (0, html_1.cloneNode)(this, () => new HiddenToken(undefined, this.getAttribute('config'), []));
86
+ return new HiddenToken(undefined, this.getAttribute('config'));
82
87
  }
83
88
  };
84
89
  return HiddenToken = _classThis;
package/dist/src/html.js CHANGED
@@ -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
  };
@@ -48,7 +48,9 @@ const index_2 = __importDefault(require("../index"));
48
48
  /* PRINT ONLY END */
49
49
  /* NOT FOR BROWSER */
50
50
  const constants_1 = require("../util/constants");
51
+ const html_1 = require("../util/html");
51
52
  const fixed_1 = require("../mixin/fixed");
53
+ const cached_1 = require("../mixin/cached");
52
54
  const magicWords = new Set(['if', 'ifeq', 'ifexpr', 'ifexist', 'iferror', 'switch']), formattingTags = new Set([
53
55
  'b',
54
56
  'big',
@@ -88,16 +90,20 @@ let HtmlToken = (() => {
88
90
  let _classExtraInitializers = [];
89
91
  let _classThis;
90
92
  let _classSuper = index_1.Token;
93
+ let _instanceExtraInitializers = [];
94
+ let _toHtmlInternal_decorators;
91
95
  var HtmlToken = class extends _classSuper {
92
96
  static { _classThis = this; }
93
97
  static {
94
98
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
99
+ _toHtmlInternal_decorators = [(0, cached_1.cached)()];
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);
95
101
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
96
102
  HtmlToken = _classThis = _classDescriptor.value;
97
103
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
98
104
  __runInitializers(_classThis, _classExtraInitializers);
99
105
  }
100
- #closing;
106
+ #closing = __runInitializers(this, _instanceExtraInitializers);
101
107
  #selfClosing;
102
108
  #tag;
103
109
  #match;
@@ -352,7 +358,7 @@ let HtmlToken = (() => {
352
358
  return;
353
359
  }
354
360
  const { childNodes } = parentNode, i = childNodes.indexOf(this), prevSiblings = childNodes.slice(0, i)
355
- .filter((child) => child.type === 'html' && child.name === tagName), imbalance = prevSiblings.reduce((acc, { closing }) => acc + (closing ? 1 : -1), 0);
361
+ .filter((child) => child.is('html') && child.name === tagName), imbalance = prevSiblings.reduce((acc, { closing }) => acc + (closing ? 1 : -1), 0);
356
362
  if (imbalance < 0) {
357
363
  this.#selfClosing = false;
358
364
  this.#closing = true;
@@ -367,7 +373,20 @@ let HtmlToken = (() => {
367
373
  if (voidTags.includes(name)) {
368
374
  return closing && name !== 'br' ? '' : `<${tag}>`;
369
375
  }
370
- return `<${closing ? '/' : ''}${tag}>${this.#selfClosing && !closing && selfClosingTags.includes(name) ? `</${name}>` : ''}`;
376
+ const result = `<${closing ? '/' : ''}${tag}>${this.#selfClosing && !closing && selfClosingTags.includes(name) ? `</${name}>` : ''}`;
377
+ if (/^h\d$/u.test(name) && (this.closing || !this.id)) {
378
+ const matched = this.findMatchingTag();
379
+ if (matched) {
380
+ if (closing) {
381
+ return result + (matched.id ? '' : '</div>');
382
+ }
383
+ const range = this.createRange();
384
+ range.setStartAfter(this);
385
+ range.setEndBefore(matched);
386
+ return `<div class="mw-heading mw-heading${name.slice(-1)}">${result.slice(0, -1)} id="${(0, html_1.getId)(range.cloneContents())}">`;
387
+ }
388
+ }
389
+ return result;
371
390
  }
372
391
  };
373
392
  return HtmlToken = _classThis;
@@ -69,6 +69,7 @@ export declare abstract class ImageParameterToken extends Token {
69
69
  *
70
70
  * 获取网址
71
71
  * @param articlePath article path / 条目路径
72
+ * @since v1.11.0
72
73
  */
73
74
  getUrl(articlePath?: string): string | undefined;
74
75
  }
@@ -55,6 +55,7 @@ function validate(key, val, config, halfParsed, ext) {
55
55
  return Boolean(value) && !isNaN(value);
56
56
  }
57
57
  }
58
+ /* eslint-enable jsdoc/check-param-names */
58
59
  /**
59
60
  * image parameter
60
61
  *
@@ -165,7 +166,7 @@ class ImageParameterToken extends index_2.Token {
165
166
  }
166
167
  /** @private */
167
168
  afterBuild() {
168
- if (this.parentNode?.type === 'gallery-image' && !exports.galleryParams.has(this.name)) {
169
+ if (this.parentNode?.is('gallery-image') && !exports.galleryParams.has(this.name)) {
169
170
  this.setAttribute('name', 'invalid');
170
171
  }
171
172
  super.afterBuild();
@@ -197,14 +198,20 @@ class ImageParameterToken extends index_2.Token {
197
198
  lint(start = this.getAbsoluteIndex(), re) {
198
199
  const errors = super.lint(start, re), { link, name } = this;
199
200
  if (name === 'invalid') {
200
- const e = (0, lint_1.generateForSelf)(this, { start }, 'invalid-gallery', 'invalid image parameter');
201
- e.fix = { range: [start - 1, e.endIndex], text: '', desc: 'remove' };
202
- errors.push(e);
201
+ const rule = 'invalid-gallery', s = index_1.default.lintConfig.getSeverity(rule, 'parameter');
202
+ if (s) {
203
+ const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'invalid image parameter', s);
204
+ e.fix = { desc: 'remove', range: [start - 1, e.endIndex], text: '' };
205
+ errors.push(e);
206
+ }
203
207
  }
204
208
  else if (typeof link === 'object' && link.encoded) {
205
- const e = (0, lint_1.generateForSelf)(this, { start }, 'url-encoding', 'unnecessary URL encoding in an internal link');
206
- e.suggestions = [{ desc: 'decode', range: [start, e.endIndex], text: (0, string_1.rawurldecode)(this.text()) }];
207
- errors.push(e);
209
+ const rule = 'url-encoding', s = index_1.default.lintConfig.getSeverity(rule, 'file');
210
+ if (s) {
211
+ const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'unnecessary URL encoding in an internal link', s);
212
+ e.suggestions = [{ desc: 'decode', range: [start, e.endIndex], text: (0, string_1.rawurldecode)(this.text()) }];
213
+ errors.push(e);
214
+ }
208
215
  }
209
216
  return errors;
210
217
  }
@@ -273,6 +280,7 @@ class ImageParameterToken extends index_2.Token {
273
280
  *
274
281
  * 获取网址
275
282
  * @param articlePath article path / 条目路径
283
+ * @since v1.11.0
276
284
  */
277
285
  getUrl(articlePath) {
278
286
  let { link } = this;
@@ -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.type === '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
  }
@@ -169,10 +176,10 @@ let ImagemapToken = (() => {
169
176
  }
170
177
  insertAt(token, i) {
171
178
  const { image } = this;
172
- if (!image && (typeof token === 'string' || token.type === 'imagemap-link' || token.type === 'text')) {
179
+ if (!image && (typeof token === 'string' || token.is('imagemap-link') || token.type === 'text')) {
173
180
  throw new Error('Missing a valid image!');
174
181
  }
175
- else if (image && typeof token !== 'string' && token.type === 'imagemap-image') {
182
+ else if (image && typeof token !== 'string' && token.is('imagemap-image')) {
176
183
  throw new RangeError('Already have a valid image!');
177
184
  }
178
185
  return super.insertAt(token, i);
@@ -183,14 +190,14 @@ let ImagemapToken = (() => {
183
190
  * @throws `Error` 禁止移除图片
184
191
  */
185
192
  removeAt(i) {
186
- if (this.childNodes[i]?.type === 'imagemap-image') {
193
+ if (this.childNodes[i]?.is('imagemap-image')) {
187
194
  throw new Error('Do not remove the image in <imagemap>!');
188
195
  }
189
196
  return super.removeAt(i);
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;