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
  };
@@ -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 });
@@ -103,6 +112,7 @@ let GalleryToken = (() => {
103
112
  super(undefined, config, accum, {
104
113
  AstText: ':', GalleryImageToken: ':', NoincludeToken: ':',
105
114
  });
115
+ __runInitializers(this, _instanceExtraInitializers);
106
116
  for (const line of inner?.split('\n') ?? []) {
107
117
  const matches = /^([^|]+)(?:\|(.*))?/u.exec(line);
108
118
  if (!matches) {
@@ -130,29 +140,36 @@ let GalleryToken = (() => {
130
140
  }
131
141
  /** @private */
132
142
  lint(start = this.getAbsoluteIndex(), re) {
133
- const { top, left } = this.getRootNode().posFromIndex(start), errors = [];
143
+ const { top, left } = this.getRootNode().posFromIndex(start), errors = [], rule = 'no-ignored', s = ['Image', 'NoImage', 'Comment'].map(k => index_1.default.lintConfig.getSeverity(rule, `gallery${k}`));
134
144
  for (let i = 0; i < this.length; i++) {
135
145
  const child = this.childNodes[i], str = child.toString(), { length } = str, trimmed = str.trim(), { type } = child, startLine = top + i, startCol = i ? 0 : left;
136
146
  child.setAttribute('aIndex', start);
137
147
  if (type === 'noinclude' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
138
- const endIndex = start + length;
139
- errors.push({
140
- rule: 'no-ignored',
141
- message: index_1.default.msg('invalid content in <$1>', 'gallery'),
142
- severity: trimmed.endsWith('-->') || /^(?:\||<!--)/u.test(trimmed)
143
- ? 'warning'
144
- : 'error',
145
- startIndex: start,
146
- endIndex,
147
- startLine,
148
- endLine: startLine,
149
- startCol,
150
- endCol: startCol + length,
151
- suggestions: [
152
- { desc: 'remove', range: [start, endIndex], text: '' },
153
- { desc: 'comment', range: [start, endIndex], text: `<!--${str}-->` },
154
- ],
155
- });
148
+ let [severity] = s;
149
+ if (trimmed.startsWith('|')) {
150
+ [, severity] = s;
151
+ }
152
+ else if (trimmed.startsWith('<!--') || trimmed.endsWith('-->')) {
153
+ [, , severity] = s;
154
+ }
155
+ if (severity) {
156
+ const endIndex = start + length;
157
+ errors.push({
158
+ rule,
159
+ message: index_1.default.msg('invalid content in <$1>', 'gallery'),
160
+ severity,
161
+ startIndex: start,
162
+ endIndex,
163
+ startLine,
164
+ endLine: startLine,
165
+ startCol,
166
+ endCol: startCol + length,
167
+ suggestions: [
168
+ { desc: 'remove', range: [start, endIndex], text: '' },
169
+ { desc: 'comment', range: [start, endIndex], text: `<!--${str}-->` },
170
+ ],
171
+ });
172
+ }
156
173
  }
157
174
  else if (type !== 'noinclude' && type !== 'text') {
158
175
  const childErrors = child.lint(start, re);
@@ -183,7 +200,7 @@ let GalleryToken = (() => {
183
200
  /* NOT FOR BROWSER */
184
201
  cloneNode() {
185
202
  // @ts-expect-error abstract class
186
- return (0, html_1.cloneNode)(this, () => new GalleryToken(undefined, this.getAttribute('config')));
203
+ return new GalleryToken(undefined, this.getAttribute('config'));
187
204
  }
188
205
  /**
189
206
  * Insert an image
@@ -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';
@@ -139,7 +145,7 @@ let HeadingToken = (() => {
139
145
  getAttribute(key) {
140
146
  /* PRINT ONLY */
141
147
  if (key === 'invalid') {
142
- return (this.inHtmlAttrs() === 'error');
148
+ return (this.inHtmlAttrs() === 2);
143
149
  }
144
150
  /* PRINT ONLY END */
145
151
  return key === 'padding' ? this.level : super.getAttribute(key);
@@ -150,16 +156,16 @@ let HeadingToken = (() => {
150
156
  }
151
157
  /** @private */
152
158
  lint(start = this.getAbsoluteIndex(), re) {
153
- 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();
154
- if (this.level === 1) {
155
- const e = (0, lint_1.generateForChild)(firstChild, rect, 'h1', '<h1>');
159
+ const errors = super.lint(start, re), { firstChild, level } = this, innerStr = firstChild.toString(), unbalancedStart = innerStr.startsWith('='), unbalanced = unbalancedStart || innerStr.endsWith('='), rect = new rect_1.BoundingRect(this, start), s = this.inHtmlAttrs(), rules = ['h1', 'unbalanced-header', 'format-leakage'], severities = rules.map(rule => index_1.default.lintConfig.getSeverity(rule, 'apostrophe'));
160
+ if (severities[0] && this.level === 1) {
161
+ const e = (0, lint_1.generateForChild)(firstChild, rect, rules[0], '<h1>', severities[0]);
156
162
  if (!unbalanced) {
157
163
  e.suggestions = [{ desc: 'h2', range: [e.startIndex, e.endIndex], text: `=${innerStr}=` }];
158
164
  }
159
165
  errors.push(e);
160
166
  }
161
- if (unbalanced) {
162
- const e = (0, lint_1.generateForChild)(firstChild, rect, 'unbalanced-header', index_1.default.msg('unbalanced $1 in a section header', '"="'));
167
+ if (severities[1] && unbalanced) {
168
+ const msg = index_1.default.msg('unbalanced $1 in a section header', '"="'), e = (0, lint_1.generateForChild)(firstChild, rect, rules[1], msg, severities[1]);
163
169
  if (innerStr === '=') {
164
170
  //
165
171
  }
@@ -180,32 +186,37 @@ let HeadingToken = (() => {
180
186
  errors.push(e);
181
187
  }
182
188
  if (s) {
183
- errors.push((0, lint_1.generateForSelf)(this, rect, 'parsing-order', 'section header in HTML tag attributes', s));
184
- }
185
- const rootStr = this.getRootNode().toString();
186
- if (boldQuotes.length % 2) {
187
- const e = (0, lint_1.generateForChild)(boldQuotes[boldQuotes.length - 1], {
188
- ...rect, // eslint-disable-line @typescript-eslint/no-misused-spread
189
- start: start + level,
190
- left: rect.left + level,
191
- }, 'format-leakage', index_1.default.msg('unbalanced $1 in a section header', 'bold apostrophes')), end = start + level + innerStr.length;
192
- if (rootStr.slice(e.endIndex, end).trim()) {
193
- e.suggestions = [{ desc: 'close', range: [end, end], text: `'''` }];
194
- }
195
- else {
196
- e.fix = { desc: 'remove', range: [e.startIndex, e.endIndex], text: '' };
189
+ const rule = 'parsing-order', severity = index_1.default.lintConfig.getSeverity(rule, s === 2 ? 'heading' : 'templateInTable');
190
+ if (severity) {
191
+ errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'section header in HTML tag attributes', severity));
197
192
  }
198
- errors.push(e);
199
193
  }
200
- if (italicQuotes.length % 2) {
201
- 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;
202
- if (rootStr.slice(e.endIndex, end).trim()) {
203
- e.suggestions = [{ desc: 'close', range: [end, end], text: `''` }];
194
+ if (severities[2]) {
195
+ const rootStr = this.getRootNode().toString(), quotes = firstChild.childNodes.filter((0, debug_1.isToken)('quote')), boldQuotes = quotes.filter(({ bold }) => bold), italicQuotes = quotes.filter(({ italic }) => italic);
196
+ if (boldQuotes.length % 2) {
197
+ const e = (0, lint_1.generateForChild)(boldQuotes[boldQuotes.length - 1], {
198
+ ...rect, // eslint-disable-line @typescript-eslint/no-misused-spread
199
+ start: start + level,
200
+ left: rect.left + level,
201
+ }, rules[2], index_1.default.msg('unbalanced $1 in a section header', 'bold apostrophes'), severities[2]), end = start + level + innerStr.length;
202
+ if (rootStr.slice(e.endIndex, end).trim()) {
203
+ e.suggestions = [{ desc: 'close', range: [end, end], text: `'''` }];
204
+ }
205
+ else {
206
+ e.fix = { desc: 'remove', range: [e.startIndex, e.endIndex], text: '' };
207
+ }
208
+ errors.push(e);
204
209
  }
205
- else {
206
- e.fix = { desc: 'remove', range: [e.startIndex, e.endIndex], text: '' };
210
+ if (italicQuotes.length % 2) {
211
+ const e = (0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, rules[2], index_1.default.msg('unbalanced $1 in a section header', 'italic apostrophes'), severities[2]), end = start + level + innerStr.length;
212
+ if (rootStr.slice(e.endIndex, end).trim()) {
213
+ e.suggestions = [{ desc: 'close', range: [end, end], text: `''` }];
214
+ }
215
+ else {
216
+ e.fix = { desc: 'remove', range: [e.startIndex, e.endIndex], text: '' };
217
+ }
218
+ errors.push(e);
207
219
  }
208
- errors.push(e);
209
220
  }
210
221
  return errors;
211
222
  }
@@ -253,13 +264,7 @@ let HeadingToken = (() => {
253
264
  * @param expand 是否展开模板
254
265
  */
255
266
  #getId(expand) {
256
- const token = expand ? this.firstChild.expand() : this.firstChild;
257
- let id = (0, string_1.decodeHtml)((0, string_1.sanitizeAlt)(token.toHtmlInternal({ nocc: true })))
258
- .replace(/[\s_]+/gu, '_');
259
- if (id.endsWith('_')) {
260
- id = id.slice(0, -1);
261
- }
262
- return id;
267
+ return (0, html_1.getId)(this.firstChild[expand ? 'expand' : 'cloneNode']());
263
268
  }
264
269
  /** @private */
265
270
  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
  };
@@ -42,13 +42,13 @@ const lint_1 = require("../util/lint");
42
42
  const debug_1 = require("../util/debug");
43
43
  const rect_1 = require("../lib/rect");
44
44
  const attributesParent_1 = require("../mixin/attributesParent");
45
- const index_1 = require("./index");
46
- /* PRINT ONLY */
47
- const index_2 = __importDefault(require("../index"));
48
- /* PRINT ONLY END */
45
+ const index_1 = __importDefault(require("../index"));
46
+ const index_2 = require("./index");
49
47
  /* NOT FOR BROWSER */
50
48
  const constants_1 = require("../util/constants");
49
+ const html_1 = require("../util/html");
51
50
  const fixed_1 = require("../mixin/fixed");
51
+ const cached_1 = require("../mixin/cached");
52
52
  const magicWords = new Set(['if', 'ifeq', 'ifexpr', 'ifexist', 'iferror', 'switch']), formattingTags = new Set([
53
53
  'b',
54
54
  'big',
@@ -87,17 +87,21 @@ let HtmlToken = (() => {
87
87
  let _classDescriptor;
88
88
  let _classExtraInitializers = [];
89
89
  let _classThis;
90
- let _classSuper = index_1.Token;
90
+ let _classSuper = index_2.Token;
91
+ let _instanceExtraInitializers = [];
92
+ let _toHtmlInternal_decorators;
91
93
  var HtmlToken = class extends _classSuper {
92
94
  static { _classThis = this; }
93
95
  static {
94
96
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
97
+ _toHtmlInternal_decorators = [(0, cached_1.cached)()];
98
+ __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
99
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
96
100
  HtmlToken = _classThis = _classDescriptor.value;
97
101
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
98
102
  __runInitializers(_classThis, _classExtraInitializers);
99
103
  }
100
- #closing;
104
+ #closing = __runInitializers(this, _instanceExtraInitializers);
101
105
  #selfClosing;
102
106
  #tag;
103
107
  #match;
@@ -179,7 +183,7 @@ let HtmlToken = (() => {
179
183
  getAttribute(key) {
180
184
  /* PRINT ONLY */
181
185
  if (key === 'invalid') {
182
- return (this.inTableAttrs() === 'error');
186
+ return (this.inTableAttrs() === 2);
183
187
  }
184
188
  /* PRINT ONLY END */
185
189
  return key === 'padding'
@@ -188,69 +192,84 @@ let HtmlToken = (() => {
188
192
  }
189
193
  /** @private */
190
194
  lint(start = this.getAbsoluteIndex(), re) {
191
- const errors = super.lint(start, re), { name, parentNode, closing, selfClosing } = this, rect = new rect_1.BoundingRect(this, start), s = this.inTableAttrs();
192
- if (name === 'h1' && !closing) {
193
- const e = (0, lint_1.generateForSelf)(this, rect, 'h1', '<h1>');
195
+ const errors = super.lint(start, re), { name, parentNode, closing, selfClosing } = this, rect = new rect_1.BoundingRect(this, start), severity = this.inTableAttrs();
196
+ let rule = 'h1', s = index_1.default.lintConfig.getSeverity(rule, 'html');
197
+ if (s && name === 'h1' && !closing) {
198
+ const e = (0, lint_1.generateForSelf)(this, rect, rule, '<h1>', s);
194
199
  e.suggestions = [{ desc: 'h2', range: [start + 2, start + 3], text: '2' }];
195
200
  errors.push(e);
196
201
  }
202
+ rule = 'parsing-order';
203
+ s = severity && index_1.default.lintConfig.getSeverity(rule, severity === 2 ? 'html' : 'templateInTable');
197
204
  if (s) {
198
- const e = (0, lint_1.generateForSelf)(this, rect, 'parsing-order', 'HTML tag in table attributes', s);
199
- if (s === 'error') {
205
+ const e = (0, lint_1.generateForSelf)(this, rect, rule, 'HTML tag in table attributes', s);
206
+ if (severity === 2) {
200
207
  e.fix = { desc: 'remove', range: [start, e.endIndex], text: '' };
201
208
  }
202
209
  errors.push(e);
203
210
  }
204
- if (obsoleteTags.has(name)) {
205
- errors.push((0, lint_1.generateForSelf)(this, rect, 'obsolete-tag', 'obsolete HTML tag', 'warning'));
211
+ rule = 'obsolete-tag';
212
+ s = index_1.default.lintConfig.getSeverity(rule, name);
213
+ if (s && obsoleteTags.has(name)) {
214
+ errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'obsolete HTML tag', s));
206
215
  }
207
- if ((name === 'b' || name === 'strong') && this.closest('heading-title')) {
208
- errors.push((0, lint_1.generateForSelf)(this, rect, 'bold-header', 'bold in section header', 'warning'));
216
+ rule = 'bold-header';
217
+ s = index_1.default.lintConfig.getSeverity(rule, name);
218
+ if (s && (name === 'b' || name === 'strong') && this.closest('heading-title')) {
219
+ errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'bold in section header', s));
209
220
  }
210
221
  const { html: [, flexibleTags, voidTags] } = this.getAttribute('config'), isVoid = voidTags.includes(name), isFlexible = flexibleTags.includes(name), isNormal = !isVoid && !isFlexible;
222
+ rule = 'unmatched-tag';
211
223
  if (closing && (selfClosing || isVoid) || selfClosing && isNormal) {
212
- const error = (0, lint_1.generateForSelf)(this, rect, 'unmatched-tag', closing ? 'tag that is both closing and self-closing' : 'invalid self-closing tag'), open = { desc: 'open', range: [start + 1, start + 2], text: '' }, noSelfClosing = {
213
- desc: 'no self-closing',
214
- range: [error.endIndex - 2, error.endIndex - 1],
215
- text: '',
216
- };
217
- if (isFlexible) {
218
- error.suggestions = [open, noSelfClosing];
219
- }
220
- else if (closing) {
221
- error.fix = isVoid ? open : noSelfClosing;
222
- }
223
- else {
224
- error.suggestions = [
225
- noSelfClosing,
226
- { desc: 'close', range: [error.endIndex - 2, error.endIndex], text: `></${name}>` },
227
- ];
228
- }
229
- errors.push(error);
230
- }
231
- else if (!this.findMatchingTag()) {
232
- const error = (0, lint_1.generateForSelf)(this, rect, 'unmatched-tag', closing ? 'unmatched closing tag' : 'unclosed tag');
233
- if (closing) {
234
- const ancestor = this.closest('magic-word');
235
- if (ancestor && magicWords.has(ancestor.name)) {
236
- error.severity = 'warning';
224
+ s = index_1.default.lintConfig.getSeverity(rule, closing ? 'both' : 'selfClosing');
225
+ if (s) {
226
+ const error = (0, lint_1.generateForSelf)(this, rect, rule, closing ? 'tag that is both closing and self-closing' : 'invalid self-closing tag', s), open = { desc: 'open', range: [start + 1, start + 2], text: '' }, noSelfClosing = {
227
+ desc: 'no self-closing',
228
+ range: [error.endIndex - 2, error.endIndex - 1],
229
+ text: '',
230
+ };
231
+ if (isFlexible) {
232
+ error.suggestions = [open, noSelfClosing];
233
+ }
234
+ else if (closing) {
235
+ error.fix = isVoid ? open : noSelfClosing;
237
236
  }
238
237
  else {
239
- error.suggestions = [{ desc: 'remove', range: [start, error.endIndex], text: '' }];
238
+ error.suggestions = [
239
+ noSelfClosing,
240
+ { desc: 'close', range: [error.endIndex - 2, error.endIndex], text: `></${name}>` },
241
+ ];
240
242
  }
243
+ errors.push(error);
244
+ }
245
+ }
246
+ else if (!this.findMatchingTag()) {
247
+ const error = (0, lint_1.generateForSelf)(this, rect, rule, closing ? 'unmatched closing tag' : 'unclosed tag'), ancestor = this.closest('magic-word');
248
+ if (ancestor && magicWords.has(ancestor.name)) {
249
+ s = index_1.default.lintConfig.getSeverity(rule, 'conditional');
250
+ }
251
+ else if (closing) {
252
+ s = index_1.default.lintConfig.getSeverity(rule, 'closing');
253
+ error.suggestions = [{ desc: 'remove', range: [start, error.endIndex], text: '' }];
241
254
  }
242
255
  else {
256
+ s = index_1.default.lintConfig.getSeverity(rule, 'opening');
243
257
  const childNodes = parentNode?.childNodes;
244
- if (formattingTags.has(name)
245
- && childNodes?.slice(0, childNodes.indexOf(this))
258
+ if (formattingTags.has(name)) {
259
+ if (childNodes?.slice(0, childNodes.indexOf(this))
246
260
  .some(({ type, name: n }) => type === 'html' && n === name)) {
247
- error.suggestions = [{ desc: 'close', range: [start + 1, start + 1], text: '/' }];
248
- }
249
- else if (!this.closest('heading-title')) {
250
- error.severity = 'warning';
261
+ error.suggestions = [{ desc: 'close', range: [start + 1, start + 1], text: '/' }];
262
+ }
263
+ if (this.closest('heading-title')) {
264
+ error.rule = 'format-leakage';
265
+ s = index_1.default.lintConfig.getSeverity('format-leakage', name);
266
+ }
251
267
  }
252
268
  }
253
- errors.push(error);
269
+ if (s) {
270
+ error.severity = s;
271
+ errors.push(error);
272
+ }
254
273
  }
255
274
  return errors;
256
275
  }
@@ -281,13 +300,13 @@ let HtmlToken = (() => {
281
300
  if (top === this) {
282
301
  return token;
283
302
  }
284
- if (index_2.default.viewOnly) {
303
+ if (index_1.default.viewOnly) {
285
304
  top.#match = [rev, token];
286
305
  token.#match = [rev, top];
287
306
  }
288
307
  }
289
308
  }
290
- if (index_2.default.viewOnly) {
309
+ if (index_1.default.viewOnly) {
291
310
  for (const token of stack) {
292
311
  token.#match = [rev, undefined];
293
312
  }
@@ -347,7 +366,7 @@ let HtmlToken = (() => {
347
366
  }
348
367
  else if (firstChild.text().trim()) {
349
368
  this.#selfClosing = false;
350
- this.after(index_2.default.parse(`</${this.name}>`, false, 3, this.getAttribute('config'))
369
+ this.after(index_1.default.parse(`</${this.name}>`, false, 3, this.getAttribute('config'))
351
370
  .firstChild);
352
371
  return;
353
372
  }
@@ -367,7 +386,20 @@ let HtmlToken = (() => {
367
386
  if (voidTags.includes(name)) {
368
387
  return closing && name !== 'br' ? '' : `<${tag}>`;
369
388
  }
370
- return `<${closing ? '/' : ''}${tag}>${this.#selfClosing && !closing && selfClosingTags.includes(name) ? `</${name}>` : ''}`;
389
+ const result = `<${closing ? '/' : ''}${tag}>${this.#selfClosing && !closing && selfClosingTags.includes(name) ? `</${name}>` : ''}`;
390
+ if (/^h\d$/u.test(name) && (this.closing || !this.id)) {
391
+ const matched = this.findMatchingTag();
392
+ if (matched) {
393
+ if (closing) {
394
+ return result + (matched.id ? '' : '</div>');
395
+ }
396
+ const range = this.createRange();
397
+ range.setStartAfter(this);
398
+ range.setEndBefore(matched);
399
+ return `<div class="mw-heading mw-heading${name.slice(-1)}">${result.slice(0, -1)} id="${(0, html_1.getId)(range.cloneContents())}">`;
400
+ }
401
+ }
402
+ return result;
371
403
  }
372
404
  };
373
405
  return HtmlToken = _classThis;
@@ -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
  *
@@ -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 = { desc: 'remove', range: [start - 1, e.endIndex], text: '' };
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
  }