wikiparser-node 1.17.0 → 1.18.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 (93) hide show
  1. package/README.md +20 -0
  2. package/bin/config.js +3 -0
  3. package/bundle/{bundle.es7.js → bundle-es7.min.js} +19 -19
  4. package/bundle/bundle-lsp.min.js +38 -0
  5. package/bundle/bundle.min.js +19 -19
  6. package/config/.schema.json +7 -3
  7. package/config/default.json +86 -23
  8. package/config/enwiki.json +20 -13
  9. package/config/llwiki.json +99 -7
  10. package/config/minimum.json +6 -3
  11. package/config/moegirl.json +12 -12
  12. package/config/zhwiki.json +52 -21
  13. package/data/.schema.json +7 -0
  14. package/data/ext/mapframe.json +4 -0
  15. package/data/ext/maplink.json +4 -0
  16. package/data/ext/score.json +1033 -0
  17. package/data/ext/templatedata.json +184 -0
  18. package/dist/addon/table.js +16 -10
  19. package/dist/addon/token.js +13 -9
  20. package/dist/addon/transclude.js +6 -3
  21. package/dist/base.d.mts +4 -2
  22. package/dist/base.d.ts +4 -2
  23. package/dist/base.js +2 -0
  24. package/dist/base.mjs +3 -1
  25. package/dist/bin/config.js +112 -0
  26. package/dist/index.d.ts +2 -2
  27. package/dist/index.js +33 -21
  28. package/dist/lib/document.d.ts +54 -0
  29. package/dist/lib/document.js +126 -0
  30. package/dist/lib/element.js +6 -3
  31. package/dist/lib/lsp.d.ts +7 -7
  32. package/dist/lib/lsp.js +314 -47
  33. package/dist/lib/node.js +19 -9
  34. package/dist/lib/text.js +4 -1
  35. package/dist/lib/title.js +9 -6
  36. package/dist/mixin/attributesParent.d.ts +8 -0
  37. package/dist/mixin/attributesParent.js +4 -0
  38. package/dist/parser/links.js +4 -1
  39. package/dist/parser/redirect.js +4 -1
  40. package/dist/src/arg.js +10 -3
  41. package/dist/src/attribute.d.ts +12 -1
  42. package/dist/src/attribute.js +69 -1
  43. package/dist/src/attributes.d.ts +8 -0
  44. package/dist/src/attributes.js +14 -1
  45. package/dist/src/converter.d.ts +62 -3
  46. package/dist/src/converter.js +162 -129
  47. package/dist/src/converterFlags.js +2 -2
  48. package/dist/src/converterRule.js +4 -1
  49. package/dist/src/extLink.d.ts +19 -3
  50. package/dist/src/extLink.js +177 -194
  51. package/dist/src/gallery.js +7 -3
  52. package/dist/src/heading.js +9 -4
  53. package/dist/src/html.js +4 -1
  54. package/dist/src/imageParameter.js +9 -3
  55. package/dist/src/imagemap.js +4 -1
  56. package/dist/src/index.js +34 -4
  57. package/dist/src/link/base.js +8 -2
  58. package/dist/src/link/file.js +11 -2
  59. package/dist/src/link/galleryImage.d.ts +1 -0
  60. package/dist/src/link/galleryImage.js +15 -1
  61. package/dist/src/magicLink.js +4 -1
  62. package/dist/src/nested.js +4 -1
  63. package/dist/src/nowiki/comment.js +4 -1
  64. package/dist/src/nowiki/index.js +4 -1
  65. package/dist/src/nowiki/quote.js +4 -1
  66. package/dist/src/onlyinclude.js +4 -1
  67. package/dist/src/paramTag/index.js +5 -1
  68. package/dist/src/paramTag/inputbox.js +4 -1
  69. package/dist/src/parameter.js +4 -1
  70. package/dist/src/pre.js +4 -1
  71. package/dist/src/redirect.js +3 -1
  72. package/dist/src/table/base.js +4 -1
  73. package/dist/src/table/index.js +10 -3
  74. package/dist/src/table/td.js +4 -1
  75. package/dist/src/tagPair/ext.js +17 -5
  76. package/dist/src/tagPair/include.js +4 -1
  77. package/dist/src/tagPair/index.js +4 -1
  78. package/dist/src/transclude.js +16 -7
  79. package/dist/util/debug.js +1 -13
  80. package/dist/util/diff.js +20 -6
  81. package/dist/util/lint.js +4 -1
  82. package/dist/util/string.js +5 -2
  83. package/extensions/dist/base.js +30 -18
  84. package/extensions/dist/lsp.js +30 -22
  85. package/extensions/es7/base.js +30 -18
  86. package/extensions/typings.d.ts +6 -2
  87. package/package.json +27 -16
  88. package/bundle/bundle.lsp.js +0 -38
  89. package/dist/mixin/flagsParent.d.ts +0 -69
  90. package/dist/mixin/flagsParent.js +0 -64
  91. package/dist/mixin/magicLinkParent.d.ts +0 -25
  92. package/dist/mixin/magicLinkParent.js +0 -43
  93. package/dist/util/sharable.d.ts +0 -1
@@ -0,0 +1,184 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "definitions": {
4
+ "interfaceText": {
5
+ "oneOf": [
6
+ {
7
+ "type": "string"
8
+ },
9
+ {
10
+ "type": "object",
11
+ "minProperties": 1,
12
+ "additionalProperties": {
13
+ "type": "string"
14
+ }
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ "type": "object",
20
+ "properties": {
21
+ "description": {
22
+ "markdownDescription": "A brief description of the template. **It must be in plain text.** Once filled, it can be displayed as caption when editing a single template and perhaps in search results when users pick one of many. The default is `null`.",
23
+ "oneOf": [
24
+ {
25
+ "$ref": "#/definitions/interfaceText"
26
+ },
27
+ {
28
+ "type": "null"
29
+ }
30
+ ]
31
+ },
32
+ "params": {
33
+ "markdownDescription": "An object that maps each parameter name of the template to a corresponding [Param object](https://www.mediawiki.org/wiki/Extension:TemplateData#Param_object) describing the properties of that parameter.",
34
+ "type": "object",
35
+ "additionalProperties": {
36
+ "type": "object",
37
+ "properties": {
38
+ "label": {
39
+ "markdownDescription": "A (very) brief name for the parameter. Try to keep under 20-ish characters.",
40
+ "$ref": "#/definitions/interfaceText"
41
+ },
42
+ "description": {
43
+ "markdownDescription": "A brief description of the parameter, for users to know which to pick from an option list.",
44
+ "$ref": "#/definitions/interfaceText"
45
+ },
46
+ "required": {
47
+ "markdownDescription": "Whether the parameter is required for the template to work (true if this parameter **must** be specified).",
48
+ "type": "boolean"
49
+ },
50
+ "suggested": {
51
+ "markdownDescription": "Whether the parameter is suggested for the template to be useful (true if this parameter **should** be specified).",
52
+ "type": "boolean"
53
+ },
54
+ "deprecated": {
55
+ "markdownDescription": "Whether the parameter is deprecated. The value can be a string of instructions giving the user guidance what instead can be done, or be simply `true`.",
56
+ "oneOf": [
57
+ {
58
+ "type": "string"
59
+ },
60
+ {
61
+ "type": "boolean"
62
+ }
63
+ ]
64
+ },
65
+ "aliases": {
66
+ "markdownDescription": "List of aliases. An alias is an alternative name for the parameter that may be used instead of (not in addition to) the primary name. Aliases are not documented in a separate Parameter object. If they need more information, they should be in their own property marked \"deprecated\".",
67
+ "type": "array",
68
+ "items": {
69
+ "type": "string"
70
+ }
71
+ },
72
+ "default": {
73
+ "markdownDescription": "A fixed default value used by the template if no value is assigned to the parameter, or a description thereof.",
74
+ "$ref": "#/definitions/interfaceText"
75
+ },
76
+ "autovalue": {
77
+ "markdownDescription": "A dynamically-generated default value in wikitext, such as today's date or the editing user's name; this will often involve wikitext substitution, such as `{{subst:CURRENTYEAR}}`.",
78
+ "type": "string"
79
+ },
80
+ "example": {
81
+ "markdownDescription": "An example text for the parameter, to help users fill in the proper value.",
82
+ "$ref": "#/definitions/interfaceText"
83
+ },
84
+ "type": {
85
+ "markdownDescription": "The type of the parameter, for (soft) type hinting.",
86
+ "type": "string",
87
+ "enum": [
88
+ "unknown",
89
+ "number",
90
+ "string",
91
+ "line",
92
+ "boolean",
93
+ "date",
94
+ "url",
95
+ "wiki-page-name",
96
+ "wiki-file-name",
97
+ "wiki-template-name",
98
+ "wiki-user-name",
99
+ "content",
100
+ "unbalanced-wikitext"
101
+ ]
102
+ },
103
+ "inherits": {
104
+ "markdownDescription": "The name key of another parameter (must be a valid key in the `params` object). The current [Parameter Object](https://www.mediawiki.org/wiki/Extension:TemplateData#Param_object) will inherit properties from the specified [Parameter Object](https://www.mediawiki.org/wiki/Extension:TemplateData#Param_object), with local properties overriding the inherited ones.",
105
+ "type": "string"
106
+ },
107
+ "suggestedValues": {
108
+ "markdownDescription": "An optional parameter property. Creates a list of parameter values to help users select the desired value. For the suggested values to be displayed as a combo box in VisualEditor, the parameter’s type must be set to one of the following: content, line, string, number, unknown or unbalanced wikitext.",
109
+ "type": "array",
110
+ "items": {
111
+ "type": "string"
112
+ }
113
+ }
114
+ },
115
+ "additionalProperties": false
116
+ }
117
+ },
118
+ "paramOrder": {
119
+ "markdownDescription": "The logical order in which parameters should be displayed. The array contains each parameter key exactly once. Each string must be a valid key in the `params` object.",
120
+ "type": "array",
121
+ "items": {
122
+ "type": "string"
123
+ }
124
+ },
125
+ "sets": {
126
+ "markdownDescription": "An array containing set specifications. A set is a group of parameters that should be used together. The default is []. Note that the `sets` functionality is still in development.",
127
+ "type": "array",
128
+ "items": {
129
+ "type": "object",
130
+ "properties": {
131
+ "label": {
132
+ "markdownDescription": "A (very) brief name for the parameter. Try to keep under 20-ish characters.",
133
+ "$ref": "#/definitions/interfaceText"
134
+ },
135
+ "params": {
136
+ "markdownDescription": "One or more names of parameters to include in the set (each must be a valid key in the `params` object). A parameter may be in multiple sets. Not every parameter must be in a set.",
137
+ "type": "array",
138
+ "items": {
139
+ "type": "string"
140
+ }
141
+ }
142
+ },
143
+ "additionalProperties": false
144
+ }
145
+ },
146
+ "format": {
147
+ "markdownDescription": "How the template's wikitext representation SHOULD be laid out. The default is `inline`. See [custom formats](https://www.mediawiki.org/wiki/Special:MyLanguage/Help:TemplateData#Custom_formats) for other custom formats.",
148
+ "type": "string"
149
+ },
150
+ "maps": {
151
+ "markdownDescription": "An object that links a simplified name of a third party consumer of the template data (i.e. [Citoid](https://www.mediawiki.org/wiki/Citoid), [Special:MyLanguage/Wikidata](https://www.mediawiki.org/wiki/Special:MyLanguage/Wikidata), etc.) to a map object that in turn links a name of a consumer parameter to one or more corresponding names of template parameters.",
152
+ "type": "object",
153
+ "additionalProperties": {
154
+ "type": "object",
155
+ "additionalProperties": {
156
+ "oneOf": [
157
+ {
158
+ "type": "string"
159
+ },
160
+ {
161
+ "type": "array",
162
+ "items": {
163
+ "type": "string"
164
+ }
165
+ },
166
+ {
167
+ "type": "array",
168
+ "items": {
169
+ "type": "array",
170
+ "items": {
171
+ "type": "string"
172
+ }
173
+ }
174
+ }
175
+ ]
176
+ }
177
+ }
178
+ }
179
+ },
180
+ "required": [
181
+ "params"
182
+ ],
183
+ "additionalProperties": false
184
+ }
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  /* eslint @stylistic/operator-linebreak: [2, "before", {overrides: {"=": "after"}}] */
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
3
6
  Object.defineProperty(exports, "__esModule", { value: true });
4
- const assert = require("assert/strict");
7
+ const strict_1 = __importDefault(require("assert/strict"));
5
8
  const debug_1 = require("../util/debug");
6
9
  const constants_1 = require("../util/constants");
7
10
  const index_1 = require("../src/index");
@@ -106,7 +109,10 @@ index_2.TableToken.prototype.toRawCoords =
106
109
  function ({ x, y }) {
107
110
  const rowLayout = this.getLayout({ x, y })[y], coords = rowLayout?.[x];
108
111
  if (coords) {
109
- return { ...coords, start: coords.row === y && rowLayout[x - 1] !== coords };
112
+ return {
113
+ ...coords,
114
+ start: coords.row === y && rowLayout[x - 1] !== coords,
115
+ };
110
116
  }
111
117
  else if (rowLayout || y > 0) {
112
118
  return x === rowLayout?.length
@@ -223,8 +229,8 @@ index_2.TableToken.prototype.insertTableCol =
223
229
  throw new RangeError(`Row ${rowLength.indexOf(minCol)} has only ${minCol} column(s)!`);
224
230
  }
225
231
  const token = (0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
226
- for (const [i, rowLayout] of layout.entries()) {
227
- const coords = rowLayout[x], prevCoords = x === 0 ? true : rowLayout[x - 1];
232
+ for (let i = 0; i < layout.length; i++) {
233
+ const rowLayout = layout[i], coords = rowLayout[x], prevCoords = x === 0 ? true : rowLayout[x - 1];
228
234
  if (!prevCoords) {
229
235
  continue;
230
236
  }
@@ -398,10 +404,10 @@ index_2.TableToken.prototype.moveTableRowBefore =
398
404
  function (y, before) {
399
405
  const layout = this.getLayout();
400
406
  try {
401
- assert.deepEqual(occupied(layout, y), occupied(layout, before));
407
+ strict_1.default.deepEqual(occupied(layout, y), occupied(layout, before));
402
408
  }
403
409
  catch (e) {
404
- if (e instanceof assert.AssertionError) {
410
+ if (e instanceof strict_1.default.AssertionError) {
405
411
  throw new RangeError(`The structure of row ${y} is different from that of row ${before}, so it cannot be moved!`);
406
412
  }
407
413
  throw e;
@@ -424,10 +430,10 @@ index_2.TableToken.prototype.moveTableRowAfter =
424
430
  function (y, after) {
425
431
  const layout = this.getLayout(), afterToken = this.getNthRow(after), cells = afterToken.childNodes.filter(child => child.type === 'td' && child.subtype !== 'caption');
426
432
  try {
427
- assert.deepEqual(occupied(layout, y), occupied(layout, after, true, cells));
433
+ strict_1.default.deepEqual(occupied(layout, y), occupied(layout, after, true, cells));
428
434
  }
429
435
  catch (e) {
430
- if (e instanceof assert.AssertionError) {
436
+ if (e instanceof strict_1.default.AssertionError) {
431
437
  throw new RangeError(`The structure of row ${y} is different from that of row ${after}, so it cannot be moved!`);
432
438
  }
433
439
  throw e;
@@ -461,8 +467,8 @@ index_2.TableToken.prototype.moveCol =
461
467
  throw new RangeError(`The structure of column ${x} is different from that of column ${reference}, so it cannot be moved!`);
462
468
  }
463
469
  const setX = new WeakSet(), setRef = new WeakSet(), rows = this.getAllRows();
464
- for (const [i, rowLayout] of layout.entries()) {
465
- const coords = rowLayout[x], refCoords = rowLayout[reference], start = isStartCol(rowLayout, x);
470
+ for (let i = 0; i < layout.length; i++) {
471
+ const rowLayout = layout[i], coords = rowLayout[x], refCoords = rowLayout[reference], start = isStartCol(rowLayout, x);
466
472
  if (refCoords && !start && !setRef.has(refCoords)) {
467
473
  setRef.add(refCoords);
468
474
  rows[refCoords.row].getNthCol(refCoords.column).colspan++;
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const fs = require("fs");
4
- const path = require("path");
6
+ const fs_1 = __importDefault(require("fs"));
7
+ const path_1 = __importDefault(require("path"));
5
8
  const constants_1 = require("../util/constants");
6
9
  const debug_1 = require("../util/debug");
7
10
  const string_1 = require("../util/string");
8
- const index_1 = require("../index");
11
+ const index_1 = __importDefault(require("../index"));
9
12
  const index_2 = require("../src/index");
10
13
  const comment_1 = require("../src/nowiki/comment");
11
14
  const include_1 = require("../src/tagPair/include");
@@ -96,17 +99,17 @@ const expand = (wikitext, config, include, context, accum = [], stack = []) => {
96
99
  if (index_1.default.templateDir === undefined) {
97
100
  return m;
98
101
  }
99
- else if (!path.isAbsolute(index_1.default.templateDir)) {
100
- index_1.default.templateDir = path.join(__dirname, '..', '..', index_1.default.templateDir);
102
+ else if (!path_1.default.isAbsolute(index_1.default.templateDir)) {
103
+ index_1.default.templateDir = path_1.default.join(__dirname, '..', '..', index_1.default.templateDir);
101
104
  }
102
105
  const titles = [title, title.replaceAll('_', ' ')]
103
106
  .flatMap(tt => [tt, tt.replaceAll(':', '꞉')]), file = ['.wiki', '.txt', '']
104
- .flatMap(ext => titles.map(tt => path.join(index_1.default.templateDir, tt + ext)))
105
- .find(fs.existsSync);
107
+ .flatMap(ext => titles.map(tt => path_1.default.join(index_1.default.templateDir, tt + ext)))
108
+ .find(fs_1.default.existsSync);
106
109
  if (!file) {
107
110
  return m;
108
111
  }
109
- index_1.default.templates.set(title, fs.readFileSync(file, 'utf8'));
112
+ index_1.default.templates.set(title, fs_1.default.readFileSync(file, 'utf8'));
110
113
  }
111
114
  else if (stack.includes(title)) {
112
115
  return `${prev}<span class="error">Template loop detected: [[${title}]]</span>`;
@@ -314,7 +317,8 @@ index_2.Token.prototype.sections = /** @implements */ function () {
314
317
  range.setStart(this, i);
315
318
  return range;
316
319
  });
317
- for (const [i, [index, level]] of headings.entries()) {
320
+ for (let i = 0; i < headings.length; i++) {
321
+ const [index, level] = headings[i];
318
322
  for (let j = level; j < 6; j++) {
319
323
  const last = lastHeading[j];
320
324
  if (last >= 0) {
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  /* eslint @stylistic/operator-linebreak: [2, "before", {overrides: {"=": "after"}}] */
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
3
6
  Object.defineProperty(exports, "__esModule", { value: true });
4
7
  const constants_1 = require("../util/constants");
5
8
  const debug_1 = require("../util/debug");
6
9
  const string_1 = require("../util/string");
7
- const index_1 = require("../index");
10
+ const index_1 = __importDefault(require("../index"));
8
11
  const index_2 = require("../src/index");
9
12
  const transclude_1 = require("../src/transclude");
10
13
  const parameter_1 = require("../src/parameter");
@@ -142,8 +145,8 @@ transclude_1.TranscludeToken.prototype.fixDuplication =
142
145
  return cmp;
143
146
  });
144
147
  if (ordered) {
145
- for (const [i, arg] of series.entries()) {
146
- const name = `${str}${i + 1}`;
148
+ for (let i = 0; i < series.length; i++) {
149
+ const arg = series[i], name = `${str}${i + 1}`;
147
150
  if (arg.name !== name) {
148
151
  if (arg.name === key) {
149
152
  remaining--;
package/dist/base.d.mts CHANGED
@@ -44,7 +44,7 @@ export declare const stages: {
44
44
  converter: number;
45
45
  };
46
46
  export type Stage = keyof typeof stages;
47
- export declare const rules: readonly ["bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "lonely-apos", "lonely-bracket", "lonely-http", "nested-link", "no-arg", "no-duplicate", "no-ignored", "obsolete-attr", "obsolete-tag", "parsing-order", "pipe-like", "table-layout", "tag-like", "unbalanced-header", "unclosed-comment", "unclosed-quote", "unclosed-table", "unescaped", "unknown-page", "unmatched-tag", "unterminated-url", "url-encoding", "var-anchor", "void-ext"];
47
+ export declare const rules: readonly ["bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "lonely-apos", "lonely-bracket", "lonely-http", "nested-link", "no-arg", "no-duplicate", "no-ignored", "obsolete-attr", "obsolete-tag", "parsing-order", "pipe-like", "table-layout", "tag-like", "unbalanced-header", "unclosed-comment", "unclosed-quote", "unclosed-table", "unescaped", "unknown-page", "unmatched-tag", "unterminated-url", "url-encoding", "var-anchor", "void-ext", "invalid-css"];
48
48
  export declare namespace LintError {
49
49
  type Severity = 'error' | 'warning';
50
50
  type Rule = typeof rules[number];
@@ -66,6 +66,7 @@ export interface LintError {
66
66
  endCol: number;
67
67
  fix?: LintError.Fix;
68
68
  suggestions?: LintError.Fix[];
69
+ code?: string;
69
70
  }
70
71
  export type AST = Record<string, string | number | boolean> & {
71
72
  range: [number, number];
@@ -139,9 +140,10 @@ export interface SignatureData {
139
140
  parserFunctions: SignatureInfo[];
140
141
  }
141
142
  export type CompletionItem = Omit<CompletionItemBase, 'kind'> & {
142
- kind: keyof typeof CompletionItemKind;
143
+ kind?: CompletionItemKind | keyof typeof CompletionItemKind;
143
144
  };
144
145
  export interface LanguageService {
146
+ include: boolean;
145
147
  /**
146
148
  * Destroy the instance
147
149
  *
package/dist/base.d.ts CHANGED
@@ -44,7 +44,7 @@ export declare const stages: {
44
44
  converter: number;
45
45
  };
46
46
  export type Stage = keyof typeof stages;
47
- export declare const rules: readonly ["bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "lonely-apos", "lonely-bracket", "lonely-http", "nested-link", "no-arg", "no-duplicate", "no-ignored", "obsolete-attr", "obsolete-tag", "parsing-order", "pipe-like", "table-layout", "tag-like", "unbalanced-header", "unclosed-comment", "unclosed-quote", "unclosed-table", "unescaped", "unknown-page", "unmatched-tag", "unterminated-url", "url-encoding", "var-anchor", "void-ext"];
47
+ export declare const rules: readonly ["bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "lonely-apos", "lonely-bracket", "lonely-http", "nested-link", "no-arg", "no-duplicate", "no-ignored", "obsolete-attr", "obsolete-tag", "parsing-order", "pipe-like", "table-layout", "tag-like", "unbalanced-header", "unclosed-comment", "unclosed-quote", "unclosed-table", "unescaped", "unknown-page", "unmatched-tag", "unterminated-url", "url-encoding", "var-anchor", "void-ext", "invalid-css"];
48
48
  export declare namespace LintError {
49
49
  type Severity = 'error' | 'warning';
50
50
  type Rule = typeof rules[number];
@@ -66,6 +66,7 @@ export interface LintError {
66
66
  endCol: number;
67
67
  fix?: LintError.Fix;
68
68
  suggestions?: LintError.Fix[];
69
+ code?: string;
69
70
  }
70
71
  export type AST = Record<string, string | number | boolean> & {
71
72
  range: [number, number];
@@ -139,9 +140,10 @@ export interface SignatureData {
139
140
  parserFunctions: SignatureInfo[];
140
141
  }
141
142
  export type CompletionItem = Omit<CompletionItemBase, 'kind'> & {
142
- kind: keyof typeof CompletionItemKind;
143
+ kind?: CompletionItemKind | keyof typeof CompletionItemKind;
143
144
  };
144
145
  export interface LanguageService {
146
+ include: boolean;
145
147
  /**
146
148
  * Destroy the instance
147
149
  *
package/dist/base.js CHANGED
@@ -67,6 +67,8 @@ exports.rules = (() => {
67
67
  'url-encoding',
68
68
  'var-anchor',
69
69
  'void-ext',
70
+ /* NOT FOR BROWSER ONLY */
71
+ 'invalid-css',
70
72
  ];
71
73
  Object.freeze(arr);
72
74
  return arr;
package/dist/base.mjs CHANGED
@@ -63,7 +63,9 @@ const rules = /* @__PURE__ */ (() => {
63
63
  "unterminated-url",
64
64
  "url-encoding",
65
65
  "var-anchor",
66
- "void-ext"
66
+ "void-ext",
67
+ /* NOT FOR BROWSER ONLY */
68
+ "invalid-css"
67
69
  ];
68
70
  Object.freeze(arr);
69
71
  return arr;
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ /* eslint-disable n/no-process-exit */
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const assert_1 = __importDefault(require("assert"));
10
+ const cm_1 = require("@bhsd/common/dist/cm");
11
+ const { argv } = process, [, , site, , force, old] = argv;
12
+ let [, , , url] = argv;
13
+ if (!site || !url) {
14
+ console.error('Usage: npx getParserConfig <site> <script path> [force]');
15
+ process.exit(1);
16
+ }
17
+ else if (/(?:\.php|\/)$/u.test(url)) {
18
+ url = url.slice(0, url.lastIndexOf('/'));
19
+ }
20
+ let mwConfig;
21
+ const mw = {
22
+ loader: {
23
+ /** @ignore */
24
+ impl(callback) {
25
+ Object.entries(callback()[1].files).find(([k]) => k.endsWith('.data.js'))[1]();
26
+ },
27
+ /** @ignore */
28
+ implement(_, callback) {
29
+ callback();
30
+ },
31
+ },
32
+ config: {
33
+ /** @ignore */
34
+ set({ extCodeMirrorConfig }) {
35
+ mwConfig = extCodeMirrorConfig;
36
+ },
37
+ },
38
+ };
39
+ /**
40
+ * Converts an array to an object.
41
+ * @param config parser configuration
42
+ * @param config.articlePath article path
43
+ */
44
+ const arrToObj = ({ articlePath, ...obj }) => {
45
+ for (const [k, v] of Object.entries(obj)) {
46
+ if (Array.isArray(v) && v.every(x => typeof x === 'string')) {
47
+ Object.assign(obj, { [k]: Object.fromEntries(v.map(x => [x, true])) });
48
+ }
49
+ }
50
+ return obj;
51
+ };
52
+ /**
53
+ * Gets the aliases of magic words.
54
+ * @param magicwords magic words
55
+ * @param targets magic word names
56
+ */
57
+ const getAliases = (magicwords, targets) => magicwords
58
+ .filter(({ name }) => targets.has(name))
59
+ .flatMap(({ aliases }) => aliases.map(s => s.replace(/:$/u, '').toLowerCase()));
60
+ /**
61
+ * Filters out gadget-related namespaces.
62
+ * @param id namespace ID
63
+ */
64
+ const filterGadget = (id) => {
65
+ const n = Number(id);
66
+ return n < 2300 || n > 2303; // Gadget, Gadget talk, Gadget definition, Gadget definition talk
67
+ };
68
+ (async () => {
69
+ const m = await (await fetch(`${url}/load.php?modules=ext.CodeMirror${old ? '.data' : ''}`)).text(), params = {
70
+ action: 'query',
71
+ meta: 'siteinfo',
72
+ siprop: `general|magicwords|namespaces|namespacealiases${old ? '|variables' : ''}`,
73
+ format: 'json',
74
+ formatversion: '2',
75
+ }, { query: { general: { variants }, magicwords, namespaces, namespacealiases, variables } } = await (await fetch(`${url}/api.php?${new URLSearchParams(params).toString()}`)).json();
76
+ eval(m); // eslint-disable-line no-eval
77
+ const dir = path_1.default.join('..', '..', 'config'), ns = Object.entries(namespaces).filter(([id]) => filterGadget(id))
78
+ .flatMap(([id, { name, canonical = '' }]) => [
79
+ [id, name],
80
+ ...name === canonical ? [] : [[id, canonical]],
81
+ ]), config = {
82
+ ...(0, cm_1.getParserConfig)(require(path_1.default.join(dir, 'minimum')), mwConfig),
83
+ ...(0, cm_1.getKeywords)(magicwords),
84
+ variants: (0, cm_1.getVariants)(variants),
85
+ namespaces: Object.fromEntries(ns),
86
+ nsid: Object.fromEntries([
87
+ ...ns.map(([id, canonical]) => [canonical.toLowerCase(), Number(id)]),
88
+ ...namespacealiases.filter(({ id }) => filterGadget(id)).map(({ id, alias }) => [alias.toLowerCase(), id]),
89
+ ]),
90
+ ...old && { variable: [...variables, '='] },
91
+ articlePath: '/wiki/$1',
92
+ };
93
+ config.doubleUnderscore[0] = [];
94
+ config.doubleUnderscore[1] = [];
95
+ Object.assign(config.parserFunction[0], (0, cm_1.getConfig)(magicwords, ({ name }) => name === 'msgnw'));
96
+ if ('#choose' in config.parserFunction[0]) {
97
+ delete config.parserFunction[0]['choose'];
98
+ const i = config.variable.indexOf('choose');
99
+ if (i !== -1) {
100
+ config.variable.splice(i, 1);
101
+ }
102
+ }
103
+ config.parserFunction[2] = getAliases(magicwords, new Set(['msg', 'raw']));
104
+ config.parserFunction[3] = getAliases(magicwords, new Set(['subst', 'safesubst']));
105
+ const file = path_1.default.join(__dirname, dir, `${site}.json`), exists = fs_1.default.existsSync(file);
106
+ if (exists) {
107
+ assert_1.default.deepStrictEqual(arrToObj(require(file)), arrToObj(config));
108
+ }
109
+ if (force || !exists) {
110
+ fs_1.default.writeFileSync(file, `${JSON.stringify(config, null, '\t')}\n`);
111
+ }
112
+ })();
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Config, LintError, TokenTypes, Parser as ParserBase, Stage, AST } from './base';
2
2
  import type { Title } from './lib/title';
3
- import type { LanguageService } from './lib/lsp';
3
+ import type { LanguageService, QuickFixData } from './lib/lsp';
4
4
  import type { Token } from './internal';
5
5
  declare interface Parser extends ParserBase {
6
6
  rules: readonly LintError.Rule[];
@@ -39,6 +39,6 @@ declare const Parser: Parser;
39
39
  // @ts-expect-error mixed export styles
40
40
  export = Parser;
41
41
  export default Parser;
42
- export type { Config, LintError, TokenTypes, LanguageService, AST, };
42
+ export type { Config, LintError, TokenTypes, LanguageService, QuickFixData, AST, };
43
43
  export type * from './internal';
44
44
  declare global { type Acceptable = unknown; }