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
@@ -271,6 +271,7 @@
271
271
  "dir",
272
272
  "interwikilink",
273
273
  "interlanguagelink",
274
+ "contentmodel",
274
275
  "int",
275
276
  "special",
276
277
  "speciale",
@@ -389,6 +390,7 @@
389
390
  "numberofadmins",
390
391
  "cascadingsources",
391
392
  "bcp47",
393
+ "contentmodel",
392
394
  "dir",
393
395
  "language",
394
396
  "numberofwikis",
@@ -695,6 +697,7 @@
695
697
  "#dir": "dir",
696
698
  "#interwikilink": "interwikilink",
697
699
  "#interlanguagelink": "interlanguagelink",
700
+ "#contentmodel": "contentmodel",
698
701
  "表示タイトル": "displaytitle",
699
702
  "DISPLAYTITLE": "displaytitle",
700
703
  "#timef": "timef",
@@ -183,6 +183,7 @@
183
183
  "#dir": "dir",
184
184
  "#interwikilink": "interwikilink",
185
185
  "#interlanguagelink": "interlanguagelink",
186
+ "#contentmodel": "contentmodel",
186
187
  "#timef": "timef",
187
188
  "#timefl": "timefl"
188
189
  },
@@ -368,16 +368,6 @@
368
368
  "formatdate",
369
369
  "displaytitle",
370
370
  "choose",
371
- "var",
372
- "varexists",
373
- "var_final",
374
- "vardefine",
375
- "vardefineecho",
376
- "while",
377
- "dowhile",
378
- "loop",
379
- "forargs",
380
- "fornumargs",
381
371
  "widget",
382
372
  "avatar",
383
373
  "categorytree",
@@ -552,16 +542,6 @@
552
542
  "#格式化日期": "formatdate",
553
543
  "#日期格式化": "formatdate",
554
544
  "#choose": "choose",
555
- "#var": "var",
556
- "#varexists": "varexists",
557
- "#var_final": "var_final",
558
- "#vardefine": "vardefine",
559
- "#vardefineecho": "vardefineecho",
560
- "#while": "while",
561
- "#dowhile": "dowhile",
562
- "#loop": "loop",
563
- "#forargs": "forargs",
564
- "#fornumargs": "fornumargs",
565
545
  "#widget": "widget",
566
546
  "#微件": "widget",
567
547
  "#小部件": "widget",
@@ -383,6 +383,7 @@
383
383
  "dir",
384
384
  "interwikilink",
385
385
  "interlanguagelink",
386
+ "contentmodel",
386
387
  "int",
387
388
  "special",
388
389
  "speciale",
@@ -502,6 +503,7 @@
502
503
  "numberofadmins",
503
504
  "cascadingsources",
504
505
  "bcp47",
506
+ "contentmodel",
505
507
  "dir",
506
508
  "language",
507
509
  "numberofwikis",
@@ -790,6 +792,7 @@
790
792
  "#dir": "dir",
791
793
  "#interwikilink": "interwikilink",
792
794
  "#interlanguagelink": "interlanguagelink",
795
+ "#contentmodel": "contentmodel",
793
796
  "DISPLAYTITLE": "displaytitle",
794
797
  "显示标题": "displaytitle",
795
798
  "顯示標題": "displaytitle",
@@ -7,6 +7,7 @@
7
7
  "\\alpha",
8
8
  "\\Alpha",
9
9
  "\\amalg",
10
+ "\\and",
10
11
  "\\And",
11
12
  "\\angle",
12
13
  "\\approx",
@@ -28,13 +29,16 @@
28
29
  "\\backslash",
29
30
  "\\bar",
30
31
  "\\barwedge",
32
+ "\\Bbb",
31
33
  "\\Bbbk",
32
34
  "\\bcancel",
33
35
  "\\because",
36
+ "\\begin",
34
37
  "\\beta",
35
38
  "\\Beta",
36
39
  "\\beth",
37
40
  "\\between",
41
+ "\\bf",
38
42
  "\\big",
39
43
  "\\Big",
40
44
  "\\bigcap",
@@ -68,6 +72,7 @@
68
72
  "\\blacktriangleleft",
69
73
  "\\blacktriangleright",
70
74
  "\\bmod",
75
+ "\\bold",
71
76
  "\\boldsymbol",
72
77
  "\\bot",
73
78
  "\\bowtie",
@@ -81,6 +86,8 @@
81
86
  "\\bullet",
82
87
  "\\bumpeq",
83
88
  "\\Bumpeq",
89
+ "\\C",
90
+ "\\cal",
84
91
  "\\cancel",
85
92
  "\\cancelto",
86
93
  "\\cap",
@@ -178,6 +185,7 @@
178
185
  "\\emph",
179
186
  "\\empty",
180
187
  "\\emptyset",
188
+ "\\end",
181
189
  "\\epsilon",
182
190
  "\\Epsilon",
183
191
  "\\eqcirc",
@@ -226,17 +234,21 @@
226
234
  "\\gtrless",
227
235
  "\\gtrsim",
228
236
  "\\gvertneqq",
237
+ "\\H",
229
238
  "\\hAar",
230
239
  "\\harr",
240
+ "\\hArr",
231
241
  "\\Harr",
232
242
  "\\hat",
233
243
  "\\hbar",
244
+ "\\hbox",
234
245
  "\\hearts",
235
246
  "\\heartsuit",
236
247
  "\\hline",
237
248
  "\\hom",
238
249
  "\\hookleftarrow",
239
250
  "\\hookrightarrow",
251
+ "\\hphantom",
240
252
  "\\hslash",
241
253
  "\\iff",
242
254
  "\\iiiint",
@@ -252,10 +264,13 @@
252
264
  "\\infty",
253
265
  "\\injlim",
254
266
  "\\int",
267
+ "\\intbar",
268
+ "\\intBar",
255
269
  "\\intercal",
256
270
  "\\iota",
257
271
  "\\Iota",
258
272
  "\\isin",
273
+ "\\it",
259
274
  "\\jmath",
260
275
  "\\kappa",
261
276
  "\\Kappa",
@@ -275,6 +290,7 @@
275
290
  "\\lceil",
276
291
  "\\ldots",
277
292
  "\\le",
293
+ "\\left",
278
294
  "\\leftarrow",
279
295
  "\\Leftarrow",
280
296
  "\\leftarrowtail",
@@ -349,6 +365,7 @@
349
365
  "\\mathsf",
350
366
  "\\mathtt",
351
367
  "\\max",
368
+ "\\mbox",
352
369
  "\\measuredangle",
353
370
  "\\mho",
354
371
  "\\mid",
@@ -414,7 +431,10 @@
414
431
  "\\O",
415
432
  "\\odot",
416
433
  "\\officialeuro",
434
+ "\\oiiint",
435
+ "\\oiint",
417
436
  "\\oint",
437
+ "\\ointctrclockwise",
418
438
  "\\omega",
419
439
  "\\Omega",
420
440
  "\\omicron",
@@ -422,9 +442,11 @@
422
442
  "\\ominus",
423
443
  "\\operatorname",
424
444
  "\\oplus",
445
+ "\\or",
425
446
  "\\oslash",
426
447
  "\\otimes",
427
448
  "\\over",
449
+ "\\overarc",
428
450
  "\\overbrace",
429
451
  "\\overleftarrow",
430
452
  "\\overleftrightarrow",
@@ -432,9 +454,12 @@
432
454
  "\\overrightarrow",
433
455
  "\\overset",
434
456
  "\\P",
457
+ "\\pagecolor",
435
458
  "\\parallel",
459
+ "\\part",
436
460
  "\\partial",
437
461
  "\\perp",
462
+ "\\phantom",
438
463
  "\\phi",
439
464
  "\\Phi",
440
465
  "\\pi",
@@ -478,6 +503,7 @@
478
503
  "\\rfloor",
479
504
  "\\rho",
480
505
  "\\Rho",
506
+ "\\right",
481
507
  "\\rightarrow",
482
508
  "\\Rightarrow",
483
509
  "\\rightarrowtail",
@@ -489,6 +515,7 @@
489
515
  "\\rightsquigarrow",
490
516
  "\\rightthreetimes",
491
517
  "\\risingdotseq",
518
+ "\\rm",
492
519
  "\\Rrightarrow",
493
520
  "\\Rsh",
494
521
  "\\rtimes",
@@ -508,6 +535,7 @@
508
535
  "\\sharp",
509
536
  "\\shortmid",
510
537
  "\\shortparallel",
538
+ "\\sideset",
511
539
  "\\sigma",
512
540
  "\\Sigma",
513
541
  "\\sim",
@@ -565,6 +593,7 @@
565
593
  "\\tau",
566
594
  "\\Tau",
567
595
  "\\tbinom",
596
+ "\\text",
568
597
  "\\textbf",
569
598
  "\\textit",
570
599
  "\\textrm",
@@ -611,27 +640,38 @@
611
640
  "\\upuparrows",
612
641
  "\\urcorner",
613
642
  "\\varcoppa",
643
+ "\\varDelta",
614
644
  "\\varepsilon",
645
+ "\\varGamma",
615
646
  "\\varinjlim",
616
647
  "\\varkappa",
648
+ "\\varLambda",
617
649
  "\\varliminf",
618
650
  "\\varlimsup",
619
651
  "\\varnothing",
652
+ "\\varointclockwise",
653
+ "\\varOmega",
620
654
  "\\varphi",
655
+ "\\varPhi",
621
656
  "\\varpi",
657
+ "\\varPi",
622
658
  "\\varprojlim",
623
659
  "\\varpropto",
624
660
  "\\varrho",
625
661
  "\\varsigma",
662
+ "\\varSigma",
626
663
  "\\varstigma",
627
664
  "\\varsubsetneq",
628
665
  "\\varsubsetneqq",
629
666
  "\\varsupsetneq",
630
667
  "\\varsupsetneqq",
631
668
  "\\vartheta",
669
+ "\\varTheta",
632
670
  "\\vartriangle",
633
671
  "\\vartriangleleft",
634
672
  "\\vartriangleright",
673
+ "\\varUpsilon",
674
+ "\\varXi",
635
675
  "\\vdash",
636
676
  "\\vDash",
637
677
  "\\Vdash",
@@ -642,6 +682,7 @@
642
682
  "\\vert",
643
683
  "\\Vert",
644
684
  "\\vline",
685
+ "\\vphantom",
645
686
  "\\Vvdash",
646
687
  "\\wedge",
647
688
  "\\weierp",
package/dist/base.d.mts CHANGED
@@ -295,9 +295,21 @@ export interface LanguageService {
295
295
  setTargetWikipedia(wiki: string, user: string): Promise<void>;
296
296
  }
297
297
  export type SeverityLevel = 0 | 1 | 2;
298
- export type LintConfigValue = SeverityLevel | [SeverityLevel, Record<string, unknown>];
299
- export type LintConfig = Partial<Record<LintError.Rule, LintConfigValue>>;
300
- export interface LintConfiguration extends LintConfig {
298
+ export type LintConfigValue = SeverityLevel | [SeverityLevel, Record<string, SeverityLevel>];
299
+ export type LintRuleConfig = Partial<Record<LintError.Rule, LintConfigValue>>;
300
+ export interface FullLintConfig {
301
+ rules: LintRuleConfig;
302
+ configurationComment?: string;
303
+ ignoreDisables?: boolean;
304
+ fix?: boolean;
305
+ computeEditInfo?: boolean;
306
+ }
307
+ export type LintConfig = LintRuleConfig | FullLintConfig;
308
+ export interface LintRuleConfiguration extends LintRuleConfig {
309
+ getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
310
+ }
311
+ export interface LintConfiguration extends FullLintConfig {
312
+ rules: LintRuleConfiguration;
301
313
  getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
302
314
  }
303
315
  export interface Parser {
package/dist/base.d.ts CHANGED
@@ -295,9 +295,21 @@ export interface LanguageService {
295
295
  setTargetWikipedia(wiki: string, user: string): Promise<void>;
296
296
  }
297
297
  export type SeverityLevel = 0 | 1 | 2;
298
- export type LintConfigValue = SeverityLevel | [SeverityLevel, Record<string, unknown>];
299
- export type LintConfig = Partial<Record<LintError.Rule, LintConfigValue>>;
300
- export interface LintConfiguration extends LintConfig {
298
+ export type LintConfigValue = SeverityLevel | [SeverityLevel, Record<string, SeverityLevel>];
299
+ export type LintRuleConfig = Partial<Record<LintError.Rule, LintConfigValue>>;
300
+ export interface FullLintConfig {
301
+ rules: LintRuleConfig;
302
+ configurationComment?: string;
303
+ ignoreDisables?: boolean;
304
+ fix?: boolean;
305
+ computeEditInfo?: boolean;
306
+ }
307
+ export type LintConfig = LintRuleConfig | FullLintConfig;
308
+ export interface LintRuleConfiguration extends LintRuleConfig {
309
+ getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
310
+ }
311
+ export interface LintConfiguration extends FullLintConfig {
312
+ rules: LintRuleConfiguration;
301
313
  getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
302
314
  }
303
315
  export interface Parser {
@@ -77,7 +77,7 @@ const mw = {
77
77
  },
78
78
  },
79
79
  };
80
- const pkg = "wikiparser-node", version = "1.25.1";
80
+ const pkg = "wikiparser-node", version = "1.26.0";
81
81
  let mwConfig;
82
82
  /**
83
83
  * Get the parser configuration for a Wikimedia Foundation project.
@@ -123,7 +123,13 @@ exports.default = async (site, url, user, force, internal) => {
123
123
  format: 'json',
124
124
  formatversion: '2',
125
125
  }, { query: { general: { articlepath, variants }, magicwords, namespaces, namespacealiases, functionhooks, }, } = await (await fetch(`${url}/api.php?${new URLSearchParams(params).toString()}`, headers)).json();
126
- eval(m); // eslint-disable-line no-eval
126
+ try {
127
+ eval(m); // eslint-disable-line no-eval
128
+ }
129
+ catch (e) {
130
+ console.log(m);
131
+ throw e;
132
+ }
127
133
  if (!mwConfig) {
128
134
  throw new RangeError('Extension:CodeMirror is not installed!');
129
135
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { Config, ConfigData, LintError, LintConfig, LintConfiguration, TokenTypes, Parser as ParserBase, Stage, AST } from './base';
1
+ import { LintConfiguration } from './lib/lintConfig';
2
+ import type { Config, ConfigData, LintError, LintConfig, TokenTypes, Parser as ParserBase, Stage, AST } from './base';
2
3
  import type { Title, TitleOptions } from './lib/title';
3
4
  import type { LanguageService, QuickFixData } from './lib/lsp';
4
5
  import type { Token, TranscludeToken, ExtToken } from './internal';
package/dist/index.js CHANGED
@@ -37,7 +37,7 @@ const getInterwikiRegex = (0, common_1.getRegex)(interwiki => new RegExp(String.
37
37
  let redirectMap = new redirectMap_1.RedirectMap();
38
38
  /* NOT FOR BROWSER END */
39
39
  let lintConfig = (() => {
40
- LINT: return (0, lintConfig_1.getLintConfig)(); // eslint-disable-line no-unused-labels
40
+ LINT: return new lintConfig_1.LintConfiguration(); // eslint-disable-line no-unused-labels
41
41
  })(), i18n;
42
42
  const Parser = {
43
43
  config: 'default',
@@ -64,7 +64,7 @@ const Parser = {
64
64
  LINT: return lintConfig; // eslint-disable-line no-unused-labels
65
65
  },
66
66
  set lintConfig(config) {
67
- LINT: lintConfig = (0, lintConfig_1.getLintConfig)(config); // eslint-disable-line no-unused-labels
67
+ LINT: lintConfig = new lintConfig_1.LintConfiguration(config); // eslint-disable-line no-unused-labels
68
68
  },
69
69
  /** @implements */
70
70
  get viewOnly() {
@@ -93,7 +93,6 @@ const Parser = {
93
93
  /* NOT FOR BROWSER END */
94
94
  /* NOT FOR BROWSER ONLY */
95
95
  configPaths: [],
96
- lintCSS: true,
97
96
  /* NOT FOR BROWSER ONLY END */
98
97
  /** @implements */
99
98
  getConfig(config) {
@@ -260,7 +260,7 @@ let AstElement = (() => {
260
260
  this.verifyChild(i);
261
261
  /* NOT FOR BROWSER END */
262
262
  const oldText = this.childNodes[i];
263
- if (oldText.type === 'text') { // eslint-disable-line @typescript-eslint/no-unnecessary-condition
263
+ if (oldText.type === 'text') {
264
264
  const { data } = oldText;
265
265
  oldText.replaceData(str);
266
266
  return data;
@@ -1,13 +1,24 @@
1
- import type { LintError, LintConfig, LintConfiguration as LintConfigurationBase } from '../base';
1
+ import type { LintError, LintRuleConfig, LintRuleConfiguration as LintRuleConfigurationBase, LintConfig, LintConfiguration as LintConfigurationBase } from '../base';
2
+ interface LintRuleConfiguration extends LintRuleConfigurationBase {
3
+ }
4
+ /** 语法规则设置 */
5
+ declare class LintRuleConfiguration implements LintRuleConfigurationBase {
6
+ /** @param config 语法规则设置 */
7
+ constructor(config?: LintRuleConfig);
8
+ /** @implements */
9
+ getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
10
+ }
11
+ export interface LintConfiguration extends LintConfigurationBase {
12
+ }
2
13
  /** 语法检查设置 */
3
14
  export declare class LintConfiguration implements LintConfigurationBase {
15
+ #private;
16
+ /** @implements */
17
+ get rules(): LintRuleConfiguration;
18
+ set rules(config: LintRuleConfig | undefined);
4
19
  /** @param config 语法检查设置 */
5
20
  constructor(config?: LintConfig);
6
21
  /** @implements */
7
- getSeverity(this: LintConfigurationBase, rule: LintError.Rule, key?: string): LintError.Severity | false;
22
+ getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
8
23
  }
9
- /**
10
- * 获取语法检查设置
11
- * @param config 语法检查设置
12
- */
13
- export declare const getLintConfig: (config?: LintConfig) => LintConfiguration;
24
+ export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLintConfig = exports.LintConfiguration = void 0;
3
+ exports.LintConfiguration = void 0;
4
4
  const base_1 = require("../base");
5
5
  /* NOT FOR BRWOSER */
6
6
  const constants_1 = require("../util/constants");
@@ -10,7 +10,7 @@ const severities = new Set([0, 1, 2]), dict = new Map([
10
10
  [1, 'warning'],
11
11
  [2, 'error'],
12
12
  ]);
13
- const defaultLintConfig = {
13
+ const defaultLintRuleConfig = {
14
14
  'bold-header': [
15
15
  1,
16
16
  {
@@ -214,6 +214,13 @@ const defaultLintConfig = {
214
214
  },
215
215
  ],
216
216
  };
217
+ Object.freeze(defaultLintRuleConfig);
218
+ const defaultLintConfig = {
219
+ configurationComment: 'lint',
220
+ ignoreDisables: false,
221
+ fix: true,
222
+ computeEditInfo: true,
223
+ };
217
224
  Object.freeze(defaultLintConfig);
218
225
  /**
219
226
  * 验证错误级别是否符合规范
@@ -238,17 +245,20 @@ const set = (obj, key, value) => {
238
245
  if (!base_1.rules.includes(key)) {
239
246
  throw new RangeError(`Unknown lint rule: ${key}`);
240
247
  }
248
+ else if (value === undefined) {
249
+ return false;
250
+ }
241
251
  else if (validateConfigValue(value)) {
242
252
  obj[key] = value;
243
253
  return true;
244
254
  }
245
255
  throw new RangeError(`Invalid lint config for ${key}: ${JSON.stringify(value)}`);
246
256
  };
247
- /** 语法检查设置 */
248
- class LintConfiguration {
249
- /** @param config 语法检查设置 */
257
+ /** 语法规则设置 */
258
+ class LintRuleConfiguration {
259
+ /** @param config 语法规则设置 */
250
260
  constructor(config) {
251
- Object.assign(this, structuredClone(defaultLintConfig));
261
+ Object.assign(this, structuredClone(defaultLintRuleConfig));
252
262
  if (!config) {
253
263
  return;
254
264
  }
@@ -258,9 +268,6 @@ class LintConfiguration {
258
268
  }
259
269
  /** @implements */
260
270
  getSeverity(rule, key) {
261
- if (!(rule in this)) {
262
- throw new RangeError(`Unknown rule: ${rule}`);
263
- }
264
271
  const value = this[rule];
265
272
  if (typeof value === 'number') {
266
273
  return dict.get(value);
@@ -268,11 +275,44 @@ class LintConfiguration {
268
275
  return key ? dict.get(value[1][key]) ?? dict.get(value[0]) : dict.get(value[0]);
269
276
  }
270
277
  }
278
+ /** 语法检查设置 */
279
+ class LintConfiguration {
280
+ #rules;
281
+ /** @implements */
282
+ get rules() {
283
+ return this.#rules;
284
+ }
285
+ set rules(config) {
286
+ this.#rules = new Proxy(new LintRuleConfiguration(config), {
287
+ set,
288
+ /** @ignore */
289
+ deleteProperty() {
290
+ return false;
291
+ },
292
+ });
293
+ }
294
+ /** @param config 语法检查设置 */
295
+ constructor(config) {
296
+ Object.assign(this, defaultLintConfig);
297
+ if (config
298
+ && !('rules' in config)
299
+ && Object.keys(config).some(key => base_1.rules.includes(key))) {
300
+ this.rules = config;
301
+ }
302
+ else {
303
+ const { rules: ruleConfig, ...other } = (config ?? {});
304
+ this.rules = ruleConfig;
305
+ for (const [key, value] of Object.entries(other)) {
306
+ if (value !== undefined && Object.prototype.hasOwnProperty.call(defaultLintConfig, key)) {
307
+ this[key] = value;
308
+ }
309
+ }
310
+ }
311
+ }
312
+ /** @implements */
313
+ getSeverity(rule, key) {
314
+ return this.#rules.getSeverity(rule, key);
315
+ }
316
+ }
271
317
  exports.LintConfiguration = LintConfiguration;
272
- /**
273
- * 获取语法检查设置
274
- * @param config 语法检查设置
275
- */
276
- const getLintConfig = (config) => new Proxy(new LintConfiguration(config), { set });
277
- exports.getLintConfig = getLintConfig;
278
318
  constants_1.classes['LintConfiguration'] = __filename;
package/dist/lib/lsp.js CHANGED
@@ -208,16 +208,20 @@ const getQuickFix = (root, fix, preferred = false) => ({
208
208
  * @param rule rule to be fixed
209
209
  */
210
210
  const getFixAll = (root, rule) => {
211
- const { lintConfig } = index_1.default;
211
+ const { lintConfig } = index_1.default, { rules: ruleConfig, fix, computeEditInfo } = lintConfig;
212
+ lintConfig.fix = true;
213
+ lintConfig.computeEditInfo = false;
212
214
  if (rule) {
213
- index_1.default.lintConfig = {};
215
+ lintConfig.rules = undefined;
214
216
  for (const key of base_1.rules) {
215
- index_1.default.lintConfig[key] = key === rule ? lintConfig[key] : 0;
217
+ lintConfig.rules[key] = key === rule ? ruleConfig[key] : 0;
216
218
  }
217
219
  }
218
220
  const { output } = root.lint();
221
+ lintConfig.fix = fix;
222
+ lintConfig.computeEditInfo = computeEditInfo;
219
223
  if (rule) {
220
- index_1.default.lintConfig = lintConfig;
224
+ lintConfig.rules = ruleConfig;
221
225
  }
222
226
  return output === undefined
223
227
  ? []
@@ -732,7 +736,7 @@ class LanguageService {
732
736
  }
733
737
  }
734
738
  else if (type === 'ext-inner' && mathTags.includes(cur.name)) {
735
- const word = /\\\w+$/u.exec(curLine.slice(0, character))?.[0];
739
+ const word = /(?<!\\)\\[a-z]+$/iu.exec(curLine.slice(0, character))?.[0];
736
740
  if (word) {
737
741
  const data = this.#mathData;
738
742
  return getCompletion(cur.name === 'math' && parentNode.hasAttr('chem')
@@ -759,7 +763,11 @@ class LanguageService {
759
763
  * @param warning whether to include warnings / 是否包含警告
760
764
  */
761
765
  async provideDiagnostics(text, warning = true) {
762
- const root = await this.#queue(text), errors = root.lint(), diagnostics = (warning ? errors : errors.filter(({ severity }) => severity === 'error')).map(({ startLine, startCol, endLine, endCol, severity, rule, message, fix, suggestions,
766
+ const root = await this.#queue(text), { lintConfig } = index_1.default, needFix = lintConfig.fix;
767
+ lintConfig.fix = false;
768
+ const errors = root.lint();
769
+ lintConfig.fix = needFix;
770
+ const diagnostics = (warning ? errors : errors.filter(({ severity }) => severity === 'error')).map(({ startLine, startCol, endLine, endCol, severity, rule, message, fix, suggestions,
763
771
  /* NOT FOR BROWSER ONLY */
764
772
  code, }) => ({
765
773
  range: {
@@ -893,7 +901,7 @@ class LanguageService {
893
901
  if (selfClosing) {
894
902
  return [];
895
903
  }
896
- const hasCe = name === 'math' && token.hasAttr('chem'), mathErrors = [...innerText.matchAll(/\\\w+/gu)]
904
+ const hasCe = name === 'math' && token.hasAttr('chem'), mathErrors = [...innerText.matchAll(/(?<!\\)\\[a-z]+/giu)]
897
905
  .filter(([macro]) => !(hasCe && macro === String.raw `\ce` || data.has(macro)))
898
906
  .map(({ 0: macro, index }) => {
899
907
  const aIndex = lastChild.getAbsoluteIndex() + index;
@@ -913,7 +921,7 @@ class LanguageService {
913
921
  if (e && typeof e === 'object' && 'id' in e && 'message' in e) {
914
922
  mathErrors.push({
915
923
  range: createNodeRange(lastChild),
916
- severity: 1,
924
+ severity: 2,
917
925
  source: 'MathJax',
918
926
  code: e.id,
919
927
  message: e.message,