wikiparser-node 1.25.1 → 1.26.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 (49) hide show
  1. package/bundle/bundle-es8.min.js +25 -25
  2. package/bundle/bundle-lsp.min.js +30 -30
  3. package/bundle/bundle.min.js +20 -20
  4. package/config/default.json +3 -0
  5. package/config/enwiki.json +3 -0
  6. package/config/jawiki.json +3 -0
  7. package/config/minimum.json +1 -0
  8. package/config/moegirl.json +0 -20
  9. package/config/zhwiki.json +3 -0
  10. package/data/ext/math.json +41 -0
  11. package/dist/base.d.mts +15 -3
  12. package/dist/base.d.ts +15 -3
  13. package/dist/bin/config.js +8 -2
  14. package/dist/index.d.ts +2 -1
  15. package/dist/index.js +2 -3
  16. package/dist/lib/element.js +1 -1
  17. package/dist/lib/lintConfig.d.ts +18 -7
  18. package/dist/lib/lintConfig.js +55 -15
  19. package/dist/lib/lsp.js +16 -8
  20. package/dist/lib/text.js +35 -33
  21. package/dist/src/arg.js +8 -6
  22. package/dist/src/attribute.js +23 -13
  23. package/dist/src/attributes.js +23 -15
  24. package/dist/src/converterFlags.js +9 -7
  25. package/dist/src/gallery.js +7 -5
  26. package/dist/src/heading.js +35 -25
  27. package/dist/src/html.js +38 -29
  28. package/dist/src/imageParameter.js +9 -5
  29. package/dist/src/imagemap.js +7 -5
  30. package/dist/src/index.js +50 -41
  31. package/dist/src/link/base.js +19 -11
  32. package/dist/src/link/file.js +24 -18
  33. package/dist/src/link/galleryImage.js +4 -2
  34. package/dist/src/link/index.js +4 -2
  35. package/dist/src/link/redirectTarget.js +4 -2
  36. package/dist/src/magicLink.js +13 -10
  37. package/dist/src/nested.js +7 -5
  38. package/dist/src/nowiki/comment.js +4 -2
  39. package/dist/src/nowiki/index.js +4 -2
  40. package/dist/src/nowiki/quote.js +10 -6
  41. package/dist/src/paramTag/index.js +4 -2
  42. package/dist/src/parameter.js +4 -2
  43. package/dist/src/table/td.js +9 -7
  44. package/dist/src/tagPair/ext.js +3 -3
  45. package/dist/src/tagPair/include.js +7 -3
  46. package/dist/src/transclude.js +13 -7
  47. package/extensions/dist/base.js +1 -1
  48. package/extensions/editor.css +2 -2
  49. package/package.json +5 -5
package/dist/lib/text.js CHANGED
@@ -221,9 +221,9 @@ let AstText = (() => {
221
221
  return [];
222
222
  }
223
223
  errorRegex.lastIndex = 0;
224
- const errors = [], nextType = nextSibling?.type, nextName = nextSibling?.name, previousType = previousSibling?.type, root = this.getRootNode(), rootStr = root.toString(), { ext, html, variants } = root.getAttribute('config'), { top, left } = root.posFromIndex(start), lintConfig = index_1.default.lintConfig['tag-like'], specified = typeof lintConfig === 'number'
224
+ const errors = [], nextType = nextSibling?.type, nextName = nextSibling?.name, previousType = previousSibling?.type, root = this.getRootNode(), rootStr = root.toString(), { ext, html, variants } = root.getAttribute('config'), { top, left } = root.posFromIndex(start), { lintConfig } = index_1.default, tagLike = lintConfig.rules['tag-like'], specified = typeof tagLike === 'number'
225
225
  ? new Set()
226
- : new Set(Object.keys(lintConfig[1]).filter(tag => tag !== 'invalid' && tag !== 'disallowed')), tags = new Set([
226
+ : new Set(Object.keys(tagLike[1]).filter(tag => tag !== 'invalid' && tag !== 'disallowed')), tags = new Set([
227
227
  'onlyinclude',
228
228
  'noinclude',
229
229
  'includeonly',
@@ -232,7 +232,7 @@ let AstText = (() => {
232
232
  ...html[1],
233
233
  ...html[2],
234
234
  ...specified,
235
- ...disallowedTags,
235
+ ...lintConfig.getSeverity('tag-like', 'disallowed') ? disallowedTags : [],
236
236
  ]);
237
237
  for (let mt = errorRegex.exec(data); mt; mt = errorRegex.exec(data)) {
238
238
  const [, tag, prefix] = mt;
@@ -263,7 +263,7 @@ let AstText = (() => {
263
263
  if (magicLink) {
264
264
  rule = 'lonely-http';
265
265
  error = error.toUpperCase();
266
- severity = index_1.default.lintConfig.getSeverity(rule, error);
266
+ severity = lintConfig.getSeverity(rule, error);
267
267
  }
268
268
  else if (char === '<') {
269
269
  rule = 'tag-like';
@@ -277,11 +277,11 @@ let AstText = (() => {
277
277
  else if (disallowedTags.has(tag) && !ext.includes(tag)) {
278
278
  key = 'disallowed';
279
279
  }
280
- severity = index_1.default.lintConfig.getSeverity(rule, key);
280
+ severity = lintConfig.getSeverity(rule, key);
281
281
  }
282
282
  else if (lConverter || rConverter) {
283
283
  rule = 'lonely-bracket';
284
- severity = index_1.default.lintConfig.getSeverity(rule, 'converter');
284
+ severity = lintConfig.getSeverity(rule, 'converter');
285
285
  if (lConverter && index > 0) {
286
286
  error = '-{';
287
287
  index--;
@@ -296,12 +296,12 @@ let AstText = (() => {
296
296
  }
297
297
  else if (brokenExtLink) {
298
298
  rule = 'lonely-bracket';
299
- severity = index_1.default.lintConfig.getSeverity(rule, 'extLink');
299
+ severity = lintConfig.getSeverity(rule, 'extLink');
300
300
  }
301
301
  else if (leftBracket || rbrace || rbrack) {
302
302
  rule = 'lonely-bracket';
303
303
  if (length > 1 || lbrace && nextChar === char || rbrace && previousChar === char) {
304
- severity = index_1.default.lintConfig.getSeverity(rule, 'double');
304
+ severity = lintConfig.getSeverity(rule, 'double');
305
305
  }
306
306
  else {
307
307
  if (!lbrack || type !== 'ext-link-text') {
@@ -321,12 +321,12 @@ let AstText = (() => {
321
321
  }
322
322
  }
323
323
  }
324
- severity = index_1.default.lintConfig.getSeverity(rule, 'single');
324
+ severity = lintConfig.getSeverity(rule, 'single');
325
325
  }
326
326
  }
327
327
  else {
328
328
  rule = 'lonely-http';
329
- severity = index_1.default.lintConfig.getSeverity(rule);
329
+ severity = lintConfig.getSeverity(rule);
330
330
  }
331
331
  if (!severity) {
332
332
  continue;
@@ -344,29 +344,31 @@ let AstText = (() => {
344
344
  endCol: startCol + length,
345
345
  };
346
346
  // Suggestions
347
- if (char === '<') {
348
- e.suggestions = [(0, lint_1.fixByEscape)(startIndex, '&lt;')];
349
- }
350
- else if (char === 'h' && type !== 'link-text' && wordRegex.test(previousChar || '')) {
351
- e.suggestions = [(0, lint_1.fixBySpace)(startIndex)];
352
- }
353
- else if (lbrack && type === 'ext-link-text') {
354
- const i = parentNode.getAbsoluteIndex() + parentNode.toString().length;
355
- e.suggestions = [(0, lint_1.fixByEscape)(i, '&#93;')];
356
- }
357
- else if (rbrack && brokenExtLink) {
358
- const i = start - previousSibling.toString().length;
359
- e.suggestions = [(0, lint_1.fixByInsert)(i, 'left-bracket', '[')];
360
- }
361
- else if (magicLink) {
362
- e.suggestions = [
363
- ...mt[0] === error
364
- ? []
365
- : [(0, lint_1.fixByUpper)(e, error)],
366
- ...nextChar === ':' || nextChar === ':'
367
- ? [(0, lint_1.fixBySpace)(endIndex, 1)]
368
- : [],
369
- ];
347
+ if (lintConfig.computeEditInfo) {
348
+ if (char === '<') {
349
+ e.suggestions = [(0, lint_1.fixByEscape)(startIndex, '&lt;')];
350
+ }
351
+ else if (char === 'h' && type !== 'link-text' && wordRegex.test(previousChar || '')) {
352
+ e.suggestions = [(0, lint_1.fixBySpace)(startIndex)];
353
+ }
354
+ else if (lbrack && type === 'ext-link-text') {
355
+ const i = parentNode.getAbsoluteIndex() + parentNode.toString().length;
356
+ e.suggestions = [(0, lint_1.fixByEscape)(i, '&#93;')];
357
+ }
358
+ else if (rbrack && brokenExtLink) {
359
+ const i = start - previousSibling.toString().length;
360
+ e.suggestions = [(0, lint_1.fixByInsert)(i, 'left-bracket', '[')];
361
+ }
362
+ else if (magicLink) {
363
+ e.suggestions = [
364
+ ...mt[0] === error
365
+ ? []
366
+ : [(0, lint_1.fixByUpper)(e, error)],
367
+ ...nextChar === ':' || nextChar === ':'
368
+ ? [(0, lint_1.fixBySpace)(endIndex, 1)]
369
+ : [],
370
+ ];
371
+ }
370
372
  }
371
373
  errors.push(e);
372
374
  }
package/dist/src/arg.js CHANGED
@@ -161,23 +161,25 @@ let ArgToken = (() => {
161
161
  errors.push(...childErrors);
162
162
  }
163
163
  }
164
- const rules = ['no-ignored', 'no-arg'], s = rules.map(rule => index_1.default.lintConfig.getSeverity(rule, 'arg'));
164
+ const rules = ['no-ignored', 'no-arg'], { lintConfig } = index_1.default, { computeEditInfo } = lintConfig, s = rules.map(rule => lintConfig.getSeverity(rule, 'arg'));
165
165
  if (s[0] && rest.length > 0) {
166
166
  const rect = new rect_1.BoundingRect(this, start);
167
167
  errors.push(...rest.map(child => {
168
168
  const e = (0, lint_1.generateForChild)(child, rect, rules[0], 'invisible-triple-braces', s[0]);
169
169
  e.startIndex--;
170
170
  e.startCol--;
171
- e.suggestions = [
172
- (0, lint_1.fixByRemove)(e),
173
- (0, lint_1.fixByEscape)(e.startIndex, '{{!}}'),
174
- ];
171
+ if (computeEditInfo) {
172
+ e.suggestions = [
173
+ (0, lint_1.fixByRemove)(e),
174
+ (0, lint_1.fixByEscape)(e.startIndex, '{{!}}'),
175
+ ];
176
+ }
175
177
  return e;
176
178
  }));
177
179
  }
178
180
  if (s[1] && !this.getAttribute('include')) {
179
181
  const e = (0, lint_1.generateForSelf)(this, { start }, rules[1], 'unexpected-argument', s[1]);
180
- if (argDefault) {
182
+ if (computeEditInfo && argDefault) {
181
183
  e.suggestions = [(0, lint_1.fixBy)(e, 'expand', argDefault.text())];
182
184
  }
183
185
  errors.push(e);
@@ -197,7 +197,11 @@ let AttributeToken = (() => {
197
197
  }
198
198
  #lint(start, rect) {
199
199
  const { firstChild, lastChild, type, name, tag, parentNode } = this, simple = !lastChild.childNodes.some(({ type: t }) => complexTypes.has(t)), value = this.getValue(), attrs = sharable_1.extAttrs[tag], attrs2 = sharable_1.htmlAttrs[tag], { length } = this.toString();
200
- let rule = 'illegal-attr';
200
+ let rule = 'illegal-attr', lintConfig, computeEditInfo;
201
+ LINT: { // eslint-disable-line no-unused-labels
202
+ ({ lintConfig } = index_1.default);
203
+ ({ computeEditInfo } = lintConfig);
204
+ }
201
205
  if (!attrs?.has(name)
202
206
  && !attrs2?.has(name)
203
207
  // 不是未定义的扩展标签或包含嵌入的HTML标签
@@ -213,10 +217,12 @@ let AttributeToken = (() => {
213
217
  }
214
218
  /* PRINT ONLY END */
215
219
  LINT: { // eslint-disable-line no-unused-labels
216
- const s = index_1.default.lintConfig.getSeverity(rule, 'unknown');
220
+ const s = lintConfig.getSeverity(rule, 'unknown');
217
221
  if (s) {
218
222
  const e = (0, lint_1.generateForChild)(firstChild, rect, rule, 'illegal-attribute-name', s);
219
- e.suggestions = [(0, lint_1.fixByRemove)(start, length)];
223
+ if (computeEditInfo) {
224
+ e.suggestions = [(0, lint_1.fixByRemove)(start, length)];
225
+ }
220
226
  return e;
221
227
  }
222
228
  }
@@ -229,7 +235,7 @@ let AttributeToken = (() => {
229
235
  /* PRINT ONLY END */
230
236
  LINT: { // eslint-disable-line no-unused-labels
231
237
  rule = 'insecure-style';
232
- const s = index_1.default.lintConfig.getSeverity(rule);
238
+ const s = lintConfig.getSeverity(rule);
233
239
  return s && (0, lint_1.generateForChild)(lastChild, rect, rule, 'insecure-style', s);
234
240
  }
235
241
  }
@@ -240,13 +246,15 @@ let AttributeToken = (() => {
240
246
  }
241
247
  /* PRINT ONLY END */
242
248
  LINT: { // eslint-disable-line no-unused-labels
243
- const s = index_1.default.lintConfig.getSeverity(rule, 'tabindex');
249
+ const s = lintConfig.getSeverity(rule, 'tabindex');
244
250
  if (s) {
245
251
  const e = (0, lint_1.generateForChild)(lastChild, rect, rule, 'nonzero-tabindex', s);
246
- e.suggestions = [
247
- (0, lint_1.fixByRemove)(start, length),
248
- (0, lint_1.fixBy)(e, '0 tabindex', '0'),
249
- ];
252
+ if (computeEditInfo) {
253
+ e.suggestions = [
254
+ (0, lint_1.fixByRemove)(start, length),
255
+ (0, lint_1.fixBy)(e, '0 tabindex', '0'),
256
+ ];
257
+ }
250
258
  return e;
251
259
  }
252
260
  }
@@ -260,7 +268,7 @@ let AttributeToken = (() => {
260
268
  }
261
269
  /* PRINT ONLY END */
262
270
  LINT: { // eslint-disable-line no-unused-labels
263
- const s = index_1.default.lintConfig.getSeverity(rule, 'value');
271
+ const s = lintConfig.getSeverity(rule, 'value');
264
272
  return s && (0, lint_1.generateForChild)(lastChild, rect, rule, 'illegal-attribute-value', s);
265
273
  }
266
274
  }
@@ -276,7 +284,7 @@ let AttributeToken = (() => {
276
284
  }
277
285
  /* PRINT ONLY END */
278
286
  LINT: { // eslint-disable-line no-unused-labels
279
- const s = index_1.default.lintConfig.getSeverity(rule, 'value');
287
+ const s = lintConfig.getSeverity(rule, 'value');
280
288
  return s && (0, lint_1.generateForChild)(lastChild, rect, rule, 'illegal-attribute-value', s);
281
289
  }
282
290
  }
@@ -285,12 +293,14 @@ let AttributeToken = (() => {
285
293
  /** @private */
286
294
  lint(start = this.getAbsoluteIndex(), re) {
287
295
  LINT: { // eslint-disable-line no-unused-labels
288
- const errors = super.lint(start, re), { balanced, firstChild, lastChild, name, tag } = this, rect = new rect_1.BoundingRect(this, start), rules = ['unclosed-quote', 'obsolete-attr'], s = rules.map(rule => index_1.default.lintConfig.getSeverity(rule, name));
296
+ const errors = super.lint(start, re), { balanced, firstChild, lastChild, name, tag } = this, rect = new rect_1.BoundingRect(this, start), rules = ['unclosed-quote', 'obsolete-attr'], { lintConfig } = index_1.default, s = rules.map(rule => lintConfig.getSeverity(rule, name));
289
297
  if (s[0] && !balanced) {
290
298
  const e = (0, lint_1.generateForChild)(lastChild, rect, rules[0], index_1.default.msg('unclosed', 'quotes'), s[0]);
291
299
  e.startIndex--;
292
300
  e.startCol--;
293
- e.suggestions = [(0, lint_1.fixByClose)(e.endIndex, this.#quotes[0])];
301
+ if (lintConfig.computeEditInfo) {
302
+ e.suggestions = [(0, lint_1.fixByClose)(e.endIndex, this.#quotes[0])];
303
+ }
294
304
  errors.push(e);
295
305
  }
296
306
  const e = this.#lint(start, rect);
@@ -250,14 +250,17 @@ let AttributesToken = (() => {
250
250
  /** @private */
251
251
  lint(start = this.getAbsoluteIndex(), re) {
252
252
  LINT: { // eslint-disable-line no-unused-labels
253
- const errors = super.lint(start, re), { parentNode, childNodes } = this, attrs = new Map(), duplicated = new Set(), rect = new rect_1.BoundingRect(this, start), rules = ['no-ignored', 'no-duplicate'], s = ['closingTag', 'invalidAttributes', 'nonWordAttributes']
254
- .map(k => index_1.default.lintConfig.getSeverity(rules[0], k));
253
+ const errors = super.lint(start, re), { parentNode, childNodes } = this, attrs = new Map(), duplicated = new Set(), rect = new rect_1.BoundingRect(this, start), rules = ['no-ignored', 'no-duplicate'], { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, s = ['closingTag', 'invalidAttributes', 'nonWordAttributes']
254
+ .map(k => lintConfig.getSeverity(rules[0], k));
255
255
  if (s[0] && this.#lint()) {
256
- const e = (0, lint_1.generateForSelf)(this, rect, rules[0], 'attributes-of-closing-tag', s[0]), index = parentNode.getAbsoluteIndex();
257
- e.suggestions = [
258
- (0, lint_1.fixByRemove)(e),
259
- (0, lint_1.fixByOpen)(index),
260
- ];
256
+ const e = (0, lint_1.generateForSelf)(this, rect, rules[0], 'attributes-of-closing-tag', s[0]);
257
+ if (computeEditInfo) {
258
+ const index = parentNode.getAbsoluteIndex();
259
+ e.suggestions = [
260
+ (0, lint_1.fixByRemove)(e),
261
+ (0, lint_1.fixByOpen)(index),
262
+ ];
263
+ }
261
264
  errors.push(e);
262
265
  }
263
266
  for (const attr of childNodes) {
@@ -275,12 +278,14 @@ let AttributesToken = (() => {
275
278
  const str = attr.text().trim(), severity = s[wordRegex.test(str) ? 1 : 2];
276
279
  if (str && severity) {
277
280
  const e = (0, lint_1.generateForChild)(attr, rect, rules[0], 'invalid-attribute', severity);
278
- e.suggestions = [(0, lint_1.fixByRemove)(e, 0, ' ')];
281
+ if (computeEditInfo) {
282
+ e.suggestions = [(0, lint_1.fixByRemove)(e, 0, ' ')];
283
+ }
279
284
  errors.push(e);
280
285
  }
281
286
  }
282
287
  }
283
- const severity = index_1.default.lintConfig.getSeverity(rules[1], 'attribute');
288
+ const severity = lintConfig.getSeverity(rules[1], 'attribute');
284
289
  if (severity && duplicated.size > 0) {
285
290
  for (const key of duplicated) {
286
291
  const pairs = attrs.get(key).map(attr => {
@@ -288,12 +293,15 @@ let AttributesToken = (() => {
288
293
  return [attr, value === true ? '' : value];
289
294
  });
290
295
  errors.push(...pairs.map(([attr, value], i) => {
291
- const e = (0, lint_1.generateForChild)(attr, rect, rules[1], index_1.default.msg('duplicate-attribute', key), severity), remove = (0, lint_1.fixByRemove)(e);
292
- if (!value || pairs.slice(0, i).some(([, v]) => v === value)) {
293
- e.fix = remove;
294
- }
295
- else {
296
- e.suggestions = [remove];
296
+ const e = (0, lint_1.generateForChild)(attr, rect, rules[1], index_1.default.msg('duplicate-attribute', key), severity);
297
+ if (computeEditInfo || fix) {
298
+ const remove = (0, lint_1.fixByRemove)(e);
299
+ if (!value || pairs.slice(0, i).some(([, v]) => v === value)) {
300
+ e.fix = remove;
301
+ }
302
+ else if (computeEditInfo) {
303
+ e.suggestions = [remove];
304
+ }
297
305
  }
298
306
  return e;
299
307
  }));
@@ -151,22 +151,24 @@ let ConverterFlagsToken = (() => {
151
151
  /** @private */
152
152
  lint(start = this.getAbsoluteIndex(), re) {
153
153
  LINT: { // eslint-disable-line no-unused-labels
154
- const variantFlags = this.getVariantFlags(), unknownFlags = this.getUnknownFlags(), validFlags = new Set(this.#flags.filter(flag => definedFlags.has(flag))), emptyFlagCount = this.#flags.filter(flag => !flag).length, knownFlagCount = this.#flags.length - unknownFlags.size - emptyFlagCount, errors = super.lint(start, re);
154
+ const variantFlags = this.getVariantFlags(), unknownFlags = this.getUnknownFlags(), validFlags = new Set(this.#flags.filter(flag => definedFlags.has(flag))), emptyFlagCount = this.#flags.filter(flag => !flag).length, knownFlagCount = this.#flags.length - unknownFlags.size - emptyFlagCount, { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, errors = super.lint(start, re);
155
155
  if (variantFlags.size === knownFlagCount || validFlags.size === knownFlagCount) {
156
156
  return errors;
157
157
  }
158
- const rule = 'no-ignored', s = index_1.default.lintConfig.getSeverity(rule, 'conversionFlag');
158
+ const rule = 'no-ignored', s = lintConfig.getSeverity(rule, 'conversionFlag');
159
159
  if (s) {
160
160
  const rect = new rect_1.BoundingRect(this, start);
161
161
  for (let i = 0; i < this.length; i++) {
162
162
  const child = this.childNodes[i], flag = child.text().trim();
163
163
  if (this.isInvalidFlag(flag, variantFlags, unknownFlags, validFlags)) {
164
164
  const e = (0, lint_1.generateForChild)(child, rect, rule, 'invalid-conversion-flag', s);
165
- if (variantFlags.size === 0 && definedFlags.has(flag.toUpperCase())) {
166
- e.fix = (0, lint_1.fixByUpper)(e, flag);
167
- }
168
- else {
169
- e.suggestions = [(0, lint_1.fixByRemove)(e, i && -1)];
165
+ if (computeEditInfo || fix) {
166
+ if (variantFlags.size === 0 && definedFlags.has(flag.toUpperCase())) {
167
+ e.fix = (0, lint_1.fixByUpper)(e, flag);
168
+ }
169
+ else if (computeEditInfo) {
170
+ e.suggestions = [(0, lint_1.fixByRemove)(e, i && -1)];
171
+ }
170
172
  }
171
173
  errors.push(e);
172
174
  }
@@ -142,7 +142,7 @@ let GalleryToken = (() => {
142
142
  /** @private */
143
143
  lint(start = this.getAbsoluteIndex(), re) {
144
144
  LINT: { // eslint-disable-line no-unused-labels
145
- 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}`));
145
+ const { top, left } = this.getRootNode().posFromIndex(start), errors = [], rule = 'no-ignored', { lintConfig } = index_1.default, s = ['Image', 'NoImage', 'Comment'].map(k => lintConfig.getSeverity(rule, `gallery${k}`));
146
146
  for (let i = 0; i < this.length; i++) {
147
147
  const child = this.childNodes[i], str = child.toString(), { length } = str, trimmed = str.trim(), { type } = child, startLine = top + i, startCol = i ? 0 : left;
148
148
  child.setAttribute('aIndex', start);
@@ -166,10 +166,12 @@ let GalleryToken = (() => {
166
166
  startCol,
167
167
  endCol: startCol + length,
168
168
  };
169
- e.suggestions = [
170
- (0, lint_1.fixByRemove)(e),
171
- (0, lint_1.fixByComment)(e, str),
172
- ];
169
+ if (lintConfig.computeEditInfo) {
170
+ e.suggestions = [
171
+ (0, lint_1.fixByRemove)(e),
172
+ (0, lint_1.fixByComment)(e, str),
173
+ ];
174
+ }
173
175
  errors.push(e);
174
176
  }
175
177
  }
@@ -157,17 +157,17 @@ let HeadingToken = (() => {
157
157
  /** @private */
158
158
  lint(start = this.getAbsoluteIndex(), re) {
159
159
  LINT: { // eslint-disable-line no-unused-labels
160
- 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
+ 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'], { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, severities = rules.map(rule => lintConfig.getSeverity(rule, 'apostrophe'));
161
161
  if (severities[0] && this.level === 1) {
162
162
  const e = (0, lint_1.generateForChild)(firstChild, rect, rules[0], '<h1>', severities[0]);
163
- if (!unbalanced) {
163
+ if (computeEditInfo && !unbalanced) {
164
164
  e.suggestions = [(0, lint_1.fixBy)(e, 'h2', `=${innerStr}=`)];
165
165
  }
166
166
  errors.push(e);
167
167
  }
168
168
  if (severities[1] && unbalanced) {
169
169
  const msg = index_1.default.msg('unbalanced-in-section-header', '"="'), e = (0, lint_1.generateForChild)(firstChild, rect, rules[1], msg, severities[1]);
170
- if (innerStr === '=') {
170
+ if (!computeEditInfo || innerStr === '=') {
171
171
  //
172
172
  }
173
173
  else if (unbalancedStart) {
@@ -187,7 +187,7 @@ let HeadingToken = (() => {
187
187
  errors.push(e);
188
188
  }
189
189
  if (s) {
190
- const rule = 'parsing-order', severity = index_1.default.lintConfig.getSeverity(rule, s === 2 ? 'heading' : 'templateInTable');
190
+ const rule = 'parsing-order', severity = lintConfig.getSeverity(rule, s === 2 ? 'heading' : 'templateInTable');
191
191
  if (severity) {
192
192
  errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'header-in-html', severity));
193
193
  }
@@ -199,31 +199,41 @@ let HeadingToken = (() => {
199
199
  ...rect, // eslint-disable-line @typescript-eslint/no-misused-spread
200
200
  start: start + level,
201
201
  left: rect.left + level,
202
- }, rules[2], index_1.default.msg('unbalanced-in-section-header', 'bold-apostrophes'), severities[2]), end = start + level + innerStr.length, remove = (0, lint_1.fixByRemove)(e);
203
- if (rootStr.slice(e.endIndex, end).trim()) {
204
- e.suggestions = [
205
- remove,
206
- (0, lint_1.fixByClose)(end, `'''`),
207
- ];
208
- }
209
- else if (boldQuotes.length === 1 && italicQuotes.length === 0) {
210
- e.fix = remove;
211
- }
212
- else {
213
- e.suggestions = [remove];
202
+ }, rules[2], index_1.default.msg('unbalanced-in-section-header', 'bold-apostrophes'), severities[2]);
203
+ if (computeEditInfo || fix) {
204
+ const end = start + level + innerStr.length, remove = (0, lint_1.fixByRemove)(e);
205
+ if (rootStr.slice(e.endIndex, end).trim()) {
206
+ if (computeEditInfo) {
207
+ e.suggestions = [
208
+ remove,
209
+ (0, lint_1.fixByClose)(end, `'''`),
210
+ ];
211
+ }
212
+ }
213
+ else if (boldQuotes.length === 1 && italicQuotes.length === 0) {
214
+ e.fix = remove;
215
+ }
216
+ else if (computeEditInfo) {
217
+ e.suggestions = [remove];
218
+ }
214
219
  }
215
220
  errors.push(e);
216
221
  }
217
222
  if (italicQuotes.length % 2) {
218
- const e = (0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, rules[2], index_1.default.msg('unbalanced-in-section-header', 'italic-apostrophes'), severities[2]), end = start + level + innerStr.length;
219
- if (rootStr.slice(e.endIndex, end).trim()) {
220
- e.suggestions = [(0, lint_1.fixByClose)(end, `''`)];
221
- }
222
- else if (italicQuotes.length === 1 && boldQuotes.length === 0) {
223
- e.fix = (0, lint_1.fixByRemove)(e);
224
- }
225
- else {
226
- e.suggestions = [(0, lint_1.fixByRemove)(e)];
223
+ const e = (0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, rules[2], index_1.default.msg('unbalanced-in-section-header', 'italic-apostrophes'), severities[2]);
224
+ if (computeEditInfo || fix) {
225
+ const end = start + level + innerStr.length;
226
+ if (rootStr.slice(e.endIndex, end).trim()) {
227
+ if (computeEditInfo) {
228
+ e.suggestions = [(0, lint_1.fixByClose)(end, `''`)];
229
+ }
230
+ }
231
+ else if (italicQuotes.length === 1 && boldQuotes.length === 0) {
232
+ e.fix = (0, lint_1.fixByRemove)(e);
233
+ }
234
+ else if (computeEditInfo) {
235
+ e.suggestions = [(0, lint_1.fixByRemove)(e)];
236
+ }
227
237
  }
228
238
  errors.push(e);
229
239
  }
package/dist/src/html.js CHANGED
@@ -193,56 +193,65 @@ let HtmlToken = (() => {
193
193
  /** @private */
194
194
  lint(start = this.getAbsoluteIndex(), re) {
195
195
  LINT: { // eslint-disable-line no-unused-labels
196
- const errors = super.lint(start, re), { name, parentNode, closing, selfClosing } = this, rect = new rect_1.BoundingRect(this, start), severity = this.inTableAttrs();
197
- let rule = 'h1', s = index_1.default.lintConfig.getSeverity(rule, 'html');
196
+ const errors = super.lint(start, re), { name, parentNode, closing, selfClosing } = this, rect = new rect_1.BoundingRect(this, start), { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, severity = this.inTableAttrs();
197
+ let rule = 'h1', s = lintConfig.getSeverity(rule, 'html');
198
198
  if (s && name === 'h1' && !closing) {
199
199
  const e = (0, lint_1.generateForSelf)(this, rect, rule, '<h1>', s);
200
- e.suggestions = [{ desc: 'h2', range: [start + 2, start + 3], text: '2' }];
200
+ if (computeEditInfo) {
201
+ e.suggestions = [{ desc: 'h2', range: [start + 2, start + 3], text: '2' }];
202
+ }
201
203
  errors.push(e);
202
204
  }
203
205
  rule = 'parsing-order';
204
- s = severity && index_1.default.lintConfig.getSeverity(rule, severity === 2 ? 'html' : 'templateInTable');
206
+ s = severity && lintConfig.getSeverity(rule, severity === 2 ? 'html' : 'templateInTable');
205
207
  if (s) {
206
208
  const e = (0, lint_1.generateForSelf)(this, rect, rule, 'html-in-table', s);
207
- if (severity === 2) {
209
+ if (computeEditInfo && severity === 2) {
208
210
  e.suggestions = [(0, lint_1.fixByRemove)(e)];
209
211
  }
210
212
  errors.push(e);
211
213
  }
212
214
  rule = 'obsolete-tag';
213
- s = index_1.default.lintConfig.getSeverity(rule, name);
215
+ s = lintConfig.getSeverity(rule, name);
214
216
  if (s && obsoleteTags.has(name)) {
215
217
  errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'obsolete-tag', s));
216
218
  }
217
219
  rule = 'bold-header';
218
- s = index_1.default.lintConfig.getSeverity(rule, name);
220
+ s = lintConfig.getSeverity(rule, name);
219
221
  if (s && (name === 'b' || name === 'strong')
220
222
  && this.closest('heading-title,ext')?.type === 'heading-title') {
221
223
  const e = (0, lint_1.generateForSelf)(this, rect, rule, 'bold-in-header', s);
222
- e.suggestions = [(0, lint_1.fixByRemove)(e)];
224
+ if (computeEditInfo) {
225
+ e.suggestions = [(0, lint_1.fixByRemove)(e)];
226
+ }
223
227
  errors.push(e);
224
228
  }
225
229
  const { html: [, flexibleTags, voidTags] } = this.getAttribute('config'), isVoid = voidTags.includes(name), isFlexible = flexibleTags.includes(name), isNormal = !isVoid && !isFlexible;
226
230
  rule = 'unmatched-tag';
227
231
  if (closing && (selfClosing || isVoid) || selfClosing && isNormal) {
228
- s = index_1.default.lintConfig.getSeverity(rule, closing ? 'both' : 'selfClosing');
232
+ s = lintConfig.getSeverity(rule, closing ? 'both' : 'selfClosing');
229
233
  if (s) {
230
- const e = (0, lint_1.generateForSelf)(this, rect, rule, closing ? 'closing-and-self-closing' : 'invalid-self-closing', s), open = (0, lint_1.fixByOpen)(start), noSelfClosing = {
231
- desc: index_1.default.msg('no-self-closing'),
232
- range: [e.endIndex - 2, e.endIndex - 1],
233
- text: '',
234
- };
235
- if (isFlexible) {
236
- e.suggestions = [open, noSelfClosing];
237
- }
238
- else if (closing) {
239
- e.fix = isVoid ? open : noSelfClosing;
240
- }
241
- else {
242
- e.suggestions = [
243
- noSelfClosing,
244
- (0, lint_1.fixByClose)(e.endIndex, `></${name}>`, -2),
245
- ];
234
+ const e = (0, lint_1.generateForSelf)(this, rect, rule, closing ? 'closing-and-self-closing' : 'invalid-self-closing', s);
235
+ if (computeEditInfo || fix) {
236
+ const open = (0, lint_1.fixByOpen)(start), noSelfClosing = {
237
+ desc: index_1.default.msg('no-self-closing'),
238
+ range: [e.endIndex - 2, e.endIndex - 1],
239
+ text: '',
240
+ };
241
+ if (isFlexible) {
242
+ if (computeEditInfo) {
243
+ e.suggestions = [open, noSelfClosing];
244
+ }
245
+ }
246
+ else if (closing) {
247
+ e.fix = isVoid ? open : noSelfClosing;
248
+ }
249
+ else if (computeEditInfo) {
250
+ e.suggestions = [
251
+ noSelfClosing,
252
+ (0, lint_1.fixByClose)(e.endIndex, `></${name}>`, -2),
253
+ ];
254
+ }
246
255
  }
247
256
  errors.push(e);
248
257
  }
@@ -250,14 +259,14 @@ let HtmlToken = (() => {
250
259
  else if (!this.findMatchingTag()) {
251
260
  const error = (0, lint_1.generateForSelf)(this, rect, rule, closing ? 'unmatched-closing' : 'unclosed-tag'), ancestor = this.closest('magic-word');
252
261
  if (ancestor && magicWords.has(ancestor.name)) {
253
- s = index_1.default.lintConfig.getSeverity(rule, 'conditional');
262
+ s = lintConfig.getSeverity(rule, 'conditional');
254
263
  }
255
264
  else if (closing) {
256
- s = index_1.default.lintConfig.getSeverity(rule, 'closing');
265
+ s = lintConfig.getSeverity(rule, 'closing');
257
266
  error.suggestions = [(0, lint_1.fixByRemove)(error)];
258
267
  }
259
268
  else {
260
- s = index_1.default.lintConfig.getSeverity(rule, 'opening');
269
+ s = lintConfig.getSeverity(rule, 'opening');
261
270
  const childNodes = parentNode?.childNodes;
262
271
  if (formattingTags.has(name)) {
263
272
  if (childNodes?.slice(0, childNodes.indexOf(this)).some(tag => tag.type === 'html' && tag.name === name && !tag.findMatchingTag())) {
@@ -265,7 +274,7 @@ let HtmlToken = (() => {
265
274
  }
266
275
  if (this.closest('heading-title')) {
267
276
  error.rule = 'format-leakage';
268
- s = index_1.default.lintConfig.getSeverity('format-leakage', name);
277
+ s = lintConfig.getSeverity('format-leakage', name);
269
278
  }
270
279
  }
271
280
  }