wikilint 2.29.2 → 2.31.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 (82) hide show
  1. package/bin/cli.js +1 -1
  2. package/dist/base.d.mts +4 -4
  3. package/dist/base.d.ts +4 -4
  4. package/dist/base.js +2 -1
  5. package/dist/base.mjs +3 -2
  6. package/dist/bin/cli.js +1 -1
  7. package/dist/bin/config.js +1 -1
  8. package/dist/index.js +14 -14
  9. package/dist/internal.d.ts +1 -0
  10. package/dist/lib/document.js +2 -2
  11. package/dist/lib/element.d.ts +1 -1
  12. package/dist/lib/element.js +8 -6
  13. package/dist/lib/lintConfig.js +12 -1
  14. package/dist/lib/lsp.d.ts +0 -1
  15. package/dist/lib/lsp.js +2 -5
  16. package/dist/lib/node.js +6 -8
  17. package/dist/lib/text.js +52 -9
  18. package/dist/lib/title.js +1 -1
  19. package/dist/mixin/attributesParent.js +2 -4
  20. package/dist/mixin/elementLike.js +2 -4
  21. package/dist/mixin/gapped.js +0 -2
  22. package/dist/mixin/hidden.js +1 -3
  23. package/dist/mixin/noEscape.js +1 -3
  24. package/dist/mixin/nodeLike.js +2 -4
  25. package/dist/mixin/padded.js +5 -9
  26. package/dist/parser/commentAndExt.js +1 -1
  27. package/dist/parser/hrAndDoubleUnderscore.js +9 -8
  28. package/dist/parser/quotes.js +6 -6
  29. package/dist/parser/table.js +1 -2
  30. package/dist/src/arg.js +8 -3
  31. package/dist/src/attribute.js +9 -9
  32. package/dist/src/attributes.d.ts +1 -0
  33. package/dist/src/attributes.js +10 -3
  34. package/dist/src/commented.js +0 -1
  35. package/dist/src/converterFlags.js +3 -3
  36. package/dist/src/converterRule.js +89 -38
  37. package/dist/src/extLink.js +2 -2
  38. package/dist/src/heading.js +1 -1
  39. package/dist/src/hidden.js +2 -1
  40. package/dist/src/imageParameter.js +189 -140
  41. package/dist/src/index.js +5 -7
  42. package/dist/src/link/base.js +1 -2
  43. package/dist/src/link/file.js +7 -7
  44. package/dist/src/link/galleryImage.js +2 -2
  45. package/dist/src/link/index.js +3 -3
  46. package/dist/src/link/redirectTarget.js +1 -1
  47. package/dist/src/magicLink.js +3 -3
  48. package/dist/src/multiLine/gallery.js +1 -1
  49. package/dist/src/multiLine/imagemap.js +1 -1
  50. package/dist/src/multiLine/paramTag.js +1 -1
  51. package/dist/src/nested.js +1 -1
  52. package/dist/src/nowiki/comment.js +1 -1
  53. package/dist/src/nowiki/index.js +3 -3
  54. package/dist/src/nowiki/list.d.ts +2 -0
  55. package/dist/src/nowiki/list.js +28 -0
  56. package/dist/src/nowiki/noinclude.d.ts +2 -0
  57. package/dist/src/nowiki/noinclude.js +26 -1
  58. package/dist/src/nowiki/quote.d.ts +2 -2
  59. package/dist/src/nowiki/quote.js +4 -4
  60. package/dist/src/parameter.js +1 -1
  61. package/dist/src/pre.js +1 -1
  62. package/dist/src/redirect.js +1 -1
  63. package/dist/src/syntax.js +1 -1
  64. package/dist/src/table/base.js +2 -3
  65. package/dist/src/table/index.js +4 -4
  66. package/dist/src/table/td.js +5 -5
  67. package/dist/src/table/trBase.js +2 -4
  68. package/dist/src/tag/html.js +3 -4
  69. package/dist/src/tag/index.js +7 -16
  70. package/dist/src/tag/tvar.js +2 -1
  71. package/dist/src/tagPair/ext.js +2 -2
  72. package/dist/src/tagPair/include.js +1 -1
  73. package/dist/src/tagPair/translate.d.ts +1 -0
  74. package/dist/src/transclude.d.ts +6 -0
  75. package/dist/src/transclude.js +24 -12
  76. package/dist/util/constants.js +4 -2
  77. package/dist/util/html.js +1 -3
  78. package/dist/util/string.js +1 -1
  79. package/i18n/en.json +3 -0
  80. package/i18n/zh-hans.json +3 -0
  81. package/i18n/zh-hant.json +3 -0
  82. package/package.json +28 -24
package/bin/cli.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
- require('../dist/bin/cli.js'); // eslint-disable-line n/no-missing-require
3
+ require('../dist/bin/cli.js');
package/dist/base.d.mts CHANGED
@@ -16,7 +16,7 @@ export interface Config {
16
16
  readonly articlePath?: string;
17
17
  }
18
18
  export type ConfigData = Omit<Config, 'excludes'>;
19
- export type TokenTypes = 'root' | 'plain' | 'redirect' | 'redirect-syntax' | 'redirect-target' | 'translate' | 'translate-attr' | 'translate-inner' | 'tvar' | 'tvar-name' | 'onlyinclude' | 'noinclude' | 'include' | 'comment' | 'ext' | 'ext-attrs' | 'ext-attr-dirty' | 'ext-attr' | 'attr-key' | 'attr-value' | 'ext-inner' | 'arg' | 'arg-name' | 'arg-default' | 'hidden' | 'magic-word' | 'magic-word-name' | 'invoke-function' | 'invoke-module' | 'template' | 'template-name' | 'parameter' | 'parameter-key' | 'parameter-value' | 'heading' | 'heading-title' | 'heading-trail' | 'html' | 'html-attrs' | 'html-attr-dirty' | 'html-attr' | 'table' | 'tr' | 'td' | 'table-syntax' | 'table-attrs' | 'table-attr-dirty' | 'table-attr' | 'table-inter' | 'td-inner' | 'hr' | 'double-underscore' | 'link' | 'link-target' | 'link-text' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'image-parameter' | 'quote' | 'ext-link' | 'ext-link-text' | 'ext-link-url' | 'free-ext-link' | 'magic-link' | 'list' | 'dd' | 'list-range' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'imagemap-link';
19
+ export type TokenTypes = 'root' | 'plain' | 'redirect' | 'redirect-syntax' | 'redirect-target' | 'translate' | 'translate-attr' | 'translate-inner' | 'tvar' | 'tvar-name' | 'onlyinclude' | 'noinclude' | 'include' | 'comment' | 'ext' | 'ext-attrs' | 'ext-attr-dirty' | 'ext-attr' | 'attr-key' | 'attr-value' | 'ext-inner' | 'arg' | 'arg-name' | 'arg-default' | 'hidden' | 'magic-word' | 'magic-word-name' | 'invoke-function' | 'invoke-module' | 'template' | 'template-name' | 'parameter' | 'parameter-key' | 'parameter-value' | 'heading' | 'heading-title' | 'heading-trail' | 'html' | 'html-attrs' | 'html-attr-dirty' | 'html-attr' | 'table' | 'tr' | 'td' | 'table-syntax' | 'table-attrs' | 'table-attr-dirty' | 'table-attr' | 'table-inter' | 'td-inner' | 'hr' | 'double-underscore' | 'link' | 'link-target' | 'link-text' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'image-parameter' | 'quote' | 'ext-link' | 'ext-link-text' | 'ext-link-url' | 'free-ext-link' | 'magic-link' | 'list' | 'dd' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'imagemap-link';
20
20
  export declare const stages: {
21
21
  redirect: number;
22
22
  onlyinclude: number;
@@ -42,10 +42,9 @@ export declare const stages: {
42
42
  list: number;
43
43
  dd: number;
44
44
  converter: number;
45
- 'list-range': number;
46
45
  };
47
46
  export type Stage = keyof typeof stages;
48
- export declare const rules: readonly ["bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "invalid-url", "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", "invalid-math"];
47
+ export declare const rules: readonly ["arg-in-ext", "bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "invalid-url", "lonely-apos", "lonely-bracket", "lonely-http", "nested-link", "no-arg", "no-duplicate", "no-ignored", "obsolete-attr", "obsolete-tag", "parsing-order", "pipe-like", "syntax-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", "invalid-math"];
49
48
  export declare namespace LintError {
50
49
  type Severity = 'error' | 'warning';
51
50
  type Rule = typeof rules[number];
@@ -285,7 +284,8 @@ export interface LintConfiguration extends FullLintConfig {
285
284
  getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
286
285
  }
287
286
  export interface Parser {
288
- config: ConfigData | string;
287
+ config: string | // eslint-disable-line @stylistic/operator-linebreak
288
+ ConfigData;
289
289
  i18n: Record<string, string> | string | undefined;
290
290
  /** @since v1.22.0 */
291
291
  lintConfig: LintConfig;
package/dist/base.d.ts CHANGED
@@ -16,7 +16,7 @@ export interface Config {
16
16
  readonly articlePath?: string;
17
17
  }
18
18
  export type ConfigData = Omit<Config, 'excludes'>;
19
- export type TokenTypes = 'root' | 'plain' | 'redirect' | 'redirect-syntax' | 'redirect-target' | 'translate' | 'translate-attr' | 'translate-inner' | 'tvar' | 'tvar-name' | 'onlyinclude' | 'noinclude' | 'include' | 'comment' | 'ext' | 'ext-attrs' | 'ext-attr-dirty' | 'ext-attr' | 'attr-key' | 'attr-value' | 'ext-inner' | 'arg' | 'arg-name' | 'arg-default' | 'hidden' | 'magic-word' | 'magic-word-name' | 'invoke-function' | 'invoke-module' | 'template' | 'template-name' | 'parameter' | 'parameter-key' | 'parameter-value' | 'heading' | 'heading-title' | 'heading-trail' | 'html' | 'html-attrs' | 'html-attr-dirty' | 'html-attr' | 'table' | 'tr' | 'td' | 'table-syntax' | 'table-attrs' | 'table-attr-dirty' | 'table-attr' | 'table-inter' | 'td-inner' | 'hr' | 'double-underscore' | 'link' | 'link-target' | 'link-text' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'image-parameter' | 'quote' | 'ext-link' | 'ext-link-text' | 'ext-link-url' | 'free-ext-link' | 'magic-link' | 'list' | 'dd' | 'list-range' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'imagemap-link';
19
+ export type TokenTypes = 'root' | 'plain' | 'redirect' | 'redirect-syntax' | 'redirect-target' | 'translate' | 'translate-attr' | 'translate-inner' | 'tvar' | 'tvar-name' | 'onlyinclude' | 'noinclude' | 'include' | 'comment' | 'ext' | 'ext-attrs' | 'ext-attr-dirty' | 'ext-attr' | 'attr-key' | 'attr-value' | 'ext-inner' | 'arg' | 'arg-name' | 'arg-default' | 'hidden' | 'magic-word' | 'magic-word-name' | 'invoke-function' | 'invoke-module' | 'template' | 'template-name' | 'parameter' | 'parameter-key' | 'parameter-value' | 'heading' | 'heading-title' | 'heading-trail' | 'html' | 'html-attrs' | 'html-attr-dirty' | 'html-attr' | 'table' | 'tr' | 'td' | 'table-syntax' | 'table-attrs' | 'table-attr-dirty' | 'table-attr' | 'table-inter' | 'td-inner' | 'hr' | 'double-underscore' | 'link' | 'link-target' | 'link-text' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'image-parameter' | 'quote' | 'ext-link' | 'ext-link-text' | 'ext-link-url' | 'free-ext-link' | 'magic-link' | 'list' | 'dd' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'imagemap-link';
20
20
  export declare const stages: {
21
21
  redirect: number;
22
22
  onlyinclude: number;
@@ -42,10 +42,9 @@ export declare const stages: {
42
42
  list: number;
43
43
  dd: number;
44
44
  converter: number;
45
- 'list-range': number;
46
45
  };
47
46
  export type Stage = keyof typeof stages;
48
- export declare const rules: readonly ["bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "invalid-url", "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", "invalid-math"];
47
+ export declare const rules: readonly ["arg-in-ext", "bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "invalid-url", "lonely-apos", "lonely-bracket", "lonely-http", "nested-link", "no-arg", "no-duplicate", "no-ignored", "obsolete-attr", "obsolete-tag", "parsing-order", "pipe-like", "syntax-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", "invalid-math"];
49
48
  export declare namespace LintError {
50
49
  type Severity = 'error' | 'warning';
51
50
  type Rule = typeof rules[number];
@@ -285,7 +284,8 @@ export interface LintConfiguration extends FullLintConfig {
285
284
  getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
286
285
  }
287
286
  export interface Parser {
288
- config: ConfigData | string;
287
+ config: string | // eslint-disable-line @stylistic/operator-linebreak
288
+ ConfigData;
289
289
  i18n: Record<string, string> | string | undefined;
290
290
  /** @since v1.22.0 */
291
291
  lintConfig: LintConfig;
package/dist/base.js CHANGED
@@ -27,13 +27,13 @@ exports.stages = (() => {
27
27
  list: 10,
28
28
  dd: 10,
29
29
  converter: 11,
30
- 'list-range': 11,
31
30
  };
32
31
  Object.setPrototypeOf(obj, null);
33
32
  return obj;
34
33
  })();
35
34
  exports.rules = (() => {
36
35
  const arr = [
36
+ 'arg-in-ext',
37
37
  'bold-header',
38
38
  'format-leakage',
39
39
  'fostered-content',
@@ -56,6 +56,7 @@ exports.rules = (() => {
56
56
  'obsolete-tag',
57
57
  'parsing-order',
58
58
  'pipe-like',
59
+ 'syntax-like',
59
60
  'table-layout',
60
61
  'tag-like',
61
62
  'unbalanced-header',
package/dist/base.mjs CHANGED
@@ -23,14 +23,14 @@ const stages = /* @__PURE__ */ (() => {
23
23
  "magic-link": 9,
24
24
  list: 10,
25
25
  dd: 10,
26
- converter: 11,
27
- "list-range": 11
26
+ converter: 11
28
27
  };
29
28
  Object.setPrototypeOf(obj, null);
30
29
  return obj;
31
30
  })();
32
31
  const rules = /* @__PURE__ */ (() => {
33
32
  const arr = [
33
+ "arg-in-ext",
34
34
  "bold-header",
35
35
  "format-leakage",
36
36
  "fostered-content",
@@ -53,6 +53,7 @@ const rules = /* @__PURE__ */ (() => {
53
53
  "obsolete-tag",
54
54
  "parsing-order",
55
55
  "pipe-like",
56
+ "syntax-like",
56
57
  "table-layout",
57
58
  "tag-like",
58
59
  "unbalanced-header",
package/dist/bin/cli.js CHANGED
@@ -282,7 +282,7 @@ if (caching) {
282
282
  try {
283
283
  cache = JSON.parse(fs_1.default.readFileSync(cacheFile, 'utf8'));
284
284
  /* eslint-disable @typescript-eslint/no-unnecessary-condition */
285
- (0, assert_1.default)(typeof cache === 'object' && cache !== null
285
+ assert_1.default.ok(typeof cache === 'object' && cache !== null
286
286
  && typeof cache.include === 'object' && cache.include !== null
287
287
  && typeof cache.noinclude === 'object' && cache.noinclude !== null);
288
288
  /* eslint-enable @typescript-eslint/no-unnecessary-condition */
@@ -77,7 +77,7 @@ const mw = {
77
77
  },
78
78
  },
79
79
  };
80
- const pkg = "wikilint", version = "2.29.2";
80
+ const pkg = "wikilint", version = "2.31.0";
81
81
  let mwConfig;
82
82
  /**
83
83
  * Get the parser configuration for a Wikimedia Foundation project.
package/dist/index.js CHANGED
@@ -27,34 +27,34 @@ const rootRequire = (file, dir) => require(path_1.default.isAbsolute(file)
27
27
  /* NOT FOR BROWSER ONLY END */
28
28
  let viewOnly = true;
29
29
  let lintConfig = (() => {
30
- LINT: return new lintConfig_1.LintConfiguration(); // eslint-disable-line no-unused-labels
30
+ LINT: return new lintConfig_1.LintConfiguration();
31
31
  })(), i18n;
32
32
  const Parser = {
33
33
  config: 'default',
34
34
  /** @implements */
35
35
  get rules() {
36
- LINT: return base_1.rules; // eslint-disable-line no-unused-labels
36
+ LINT: return base_1.rules;
37
37
  },
38
38
  /** @implements */
39
39
  get i18n() {
40
- LINT: return { ...constants_1.enMsg, ...i18n }; // eslint-disable-line no-unused-labels
40
+ LINT: return { ...constants_1.enMsg, ...i18n };
41
41
  },
42
42
  set i18n(data) {
43
43
  /* NOT FOR BROWSER ONLY */
44
- if (typeof data === 'string') { // eslint-disable-line unicorn/prefer-ternary
44
+ if (typeof data === 'string') {
45
45
  i18n = rootRequire(data, 'i18n');
46
46
  }
47
47
  else {
48
48
  /* NOT FOR BROWSER ONLY END */
49
- LINT: i18n = data; // eslint-disable-line no-unused-labels
49
+ LINT: i18n = data;
50
50
  }
51
51
  },
52
52
  /** @implements */
53
53
  get lintConfig() {
54
- LINT: return lintConfig; // eslint-disable-line no-unused-labels
54
+ LINT: return lintConfig;
55
55
  },
56
56
  set lintConfig(config) {
57
- LINT: lintConfig = new lintConfig_1.LintConfiguration(config); // eslint-disable-line no-unused-labels
57
+ LINT: lintConfig = new lintConfig_1.LintConfiguration(config);
58
58
  },
59
59
  /** @implements */
60
60
  get viewOnly() {
@@ -117,7 +117,7 @@ const Parser = {
117
117
  },
118
118
  /** @implements */
119
119
  msg(msg, arg = '') {
120
- LINT: return msg // eslint-disable-line no-unused-labels
120
+ LINT: return msg
121
121
  && (this.i18n[msg] ?? msg).replace('$1', this.msg(arg));
122
122
  },
123
123
  /** @implements */
@@ -134,7 +134,7 @@ const Parser = {
134
134
  root.type = 'root';
135
135
  root.pageName = opt?.page;
136
136
  root.parseOnce(0, include).parseOnce();
137
- const t = new Title(root.toString(), defaultNs, config, opt);
137
+ const t = new Title(root.firstChild.toString(), defaultNs, config, opt);
138
138
  root.build();
139
139
  for (const key of ['main', 'fragment']) {
140
140
  const str = t[key];
@@ -172,7 +172,7 @@ const Parser = {
172
172
  maxStage ??= constants_1.MAX_STAGE;
173
173
  config ??= this.getConfig();
174
174
  let types;
175
- LINT: { // eslint-disable-line no-unused-labels
175
+ LINT: {
176
176
  if (typeof maxStage !== 'number') {
177
177
  types = Array.isArray(maxStage) ? maxStage : [maxStage];
178
178
  maxStage = Math.max(...types.map(t => base_1.stages[t] || constants_1.MAX_STAGE));
@@ -190,7 +190,7 @@ const Parser = {
190
190
  catch (e) /* istanbul ignore next */ {
191
191
  if (e instanceof Error) {
192
192
  const file = path_1.default.join(__dirname, '..', 'errors', new Date().toISOString()), stage = token.getAttribute('stage');
193
- for (const k in config) {
193
+ for (const k of Object.keys(config)) {
194
194
  if (k.startsWith('regex') || config[k] instanceof Set) {
195
195
  delete config[k];
196
196
  }
@@ -211,7 +211,7 @@ const Parser = {
211
211
  },
212
212
  /** @implements */
213
213
  async partialParse(wikitext, watch, include, config = Parser.getConfig()) {
214
- LSP: { // eslint-disable-line no-unused-labels
214
+ LSP: {
215
215
  const { Token } = require('./src/index');
216
216
  const set = typeof setImmediate === 'function' ? setImmediate : /* istanbul ignore next */ setTimeout, { running } = debug_1.Shadow;
217
217
  debug_1.Shadow.running = true;
@@ -252,7 +252,7 @@ const Parser = {
252
252
  },
253
253
  /** @implements */
254
254
  createLanguageService(uri = {}) {
255
- LSP: { // eslint-disable-line no-unused-labels
255
+ LSP: {
256
256
  const mod = require('./lib/lsp');
257
257
  const { LanguageService, tasks } = mod;
258
258
  return tasks.get(uri) ?? new LanguageService(uri);
@@ -285,7 +285,7 @@ const def = {
285
285
  /* NOT FOR BROWSER ONLY */
286
286
  'fetchConfig',
287
287
  ]);
288
- for (const key in Parser) {
288
+ for (const key of Object.keys(Parser)) {
289
289
  if (!enumerable.has(key)) {
290
290
  def[key] = { enumerable: false };
291
291
  }
@@ -46,3 +46,4 @@ export type { ImagemapLinkToken } from './src/imagemapLink';
46
46
  export type { ImagemapToken } from './src/multiLine/imagemap';
47
47
  export type { CommentedToken } from './src/commented';
48
48
  export type { TranslateToken } from './src/tagPair/translate';
49
+ export type { TvarToken } from './src/tag/tvar';
@@ -7,7 +7,7 @@ exports.EmbeddedCSSDocument = exports.EmbeddedJSONDocument = exports.stylelint =
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const common_1 = require("@bhsd/common");
9
9
  exports.texvcjs = (() => {
10
- NPM: { // eslint-disable-line no-unused-labels
10
+ NPM: {
11
11
  try {
12
12
  return require('mathoid-texvcjs');
13
13
  }
@@ -72,7 +72,7 @@ exports.htmlData = (() => {
72
72
  }
73
73
  })();
74
74
  exports.stylelint = (async () => {
75
- NPM: { // eslint-disable-line no-unused-labels
75
+ NPM: {
76
76
  try {
77
77
  return (await import('stylelint')).default;
78
78
  }
@@ -1,5 +1,5 @@
1
1
  import { AstNode } from './node';
2
- import type { LintError } from '../base';
2
+ import type { TokenTypes, LintError } from '../base';
3
3
  import type { ElementLike } from '../mixin/elementLike';
4
4
  import type { AstNodes, Token } from '../internal';
5
5
  export interface CaretPosition {
@@ -102,7 +102,6 @@ let AstElement = (() => {
102
102
  * @param i position of the child node / 移除位置
103
103
  */
104
104
  removeAt(i) {
105
- // eslint-disable-next-line no-unused-labels
106
105
  LSP: return (0, debug_1.setChildNodes)(this, i, 1)[0];
107
106
  }
108
107
  /**
@@ -133,6 +132,10 @@ let AstElement = (() => {
133
132
  }
134
133
  return undefined;
135
134
  }
135
+ /** @private */
136
+ isInside(type) {
137
+ return this.closest(`${type},ext`)?.type === type;
138
+ }
136
139
  /**
137
140
  * Insert a batch of child nodes at the end
138
141
  *
@@ -150,7 +153,7 @@ let AstElement = (() => {
150
153
  }
151
154
  /** @private */
152
155
  safeReplaceChildren(elements) {
153
- LSP: { // eslint-disable-line no-unused-labels
156
+ LSP: {
154
157
  for (let i = this.length - 1; i >= 0; i--) {
155
158
  this.removeAt(i);
156
159
  }
@@ -182,7 +185,7 @@ let AstElement = (() => {
182
185
  * @param index character index / 位置
183
186
  */
184
187
  caretPositionFromIndex(index) {
185
- LSP: { // eslint-disable-line no-unused-labels
188
+ LSP: {
186
189
  if (index === undefined) {
187
190
  return undefined;
188
191
  }
@@ -225,7 +228,7 @@ let AstElement = (() => {
225
228
  * @param index character index / 位置
226
229
  */
227
230
  elementFromIndex(index) {
228
- LSP: { // eslint-disable-line no-unused-labels
231
+ LSP: {
229
232
  const node = this.caretPositionFromIndex(index)?.offsetNode;
230
233
  return node?.type === 'text' ? node.parentNode : node;
231
234
  }
@@ -238,12 +241,11 @@ let AstElement = (() => {
238
241
  * @param y line number / 行数
239
242
  */
240
243
  elementFromPoint(x, y) {
241
- // eslint-disable-next-line no-unused-labels
242
244
  LSP: return this.elementFromIndex(this.indexFromPos(y, x));
243
245
  }
244
246
  /** @private */
245
247
  lint(start = this.getAbsoluteIndex(), re) {
246
- LINT: { // eslint-disable-line no-unused-labels
248
+ LINT: {
247
249
  const errors = [];
248
250
  for (let i = 0, cur = start + this.getAttribute('padding'); i < this.length; i++) {
249
251
  const child = this.childNodes[i];
@@ -12,6 +12,7 @@ const dict = new Map([
12
12
  ['error', 'error'],
13
13
  ]);
14
14
  const defaultLintRuleConfig = {
15
+ 'arg-in-ext': 1,
15
16
  'bold-header': [
16
17
  1,
17
18
  {
@@ -153,6 +154,13 @@ const defaultLintRuleConfig = {
153
154
  // td: 1,
154
155
  },
155
156
  ],
157
+ 'syntax-like': [
158
+ 2,
159
+ {
160
+ // heading: 2,
161
+ // redirect: 2,
162
+ },
163
+ ],
156
164
  'table-layout': 1,
157
165
  'tag-like': [
158
166
  2,
@@ -261,11 +269,14 @@ const set = (obj, key, value) => {
261
269
  /* istanbul ignore next */
262
270
  throw new RangeError(`Invalid lint config for ${key}: ${JSON.stringify(value)}`);
263
271
  };
272
+ const clone = typeof structuredClone === 'function'
273
+ ? structuredClone
274
+ : /* istanbul ignore next */ (obj) => JSON.parse(JSON.stringify(obj));
264
275
  /** 语法规则设置 */
265
276
  class LintRuleConfiguration {
266
277
  /** @param config 语法规则设置 */
267
278
  constructor(config) {
268
- Object.assign(this, structuredClone(defaultLintRuleConfig));
279
+ Object.assign(this, clone(defaultLintRuleConfig));
269
280
  if (!config) {
270
281
  return;
271
282
  }
package/dist/lib/lsp.d.ts CHANGED
@@ -157,7 +157,6 @@ export declare class LanguageService implements LanguageServiceBase {
157
157
  * @param wiki Wikipedia URL / 维基百科网址
158
158
  * @param user URI for wiki userpage or email address of the user / 维基用户页面地址或用户的电子邮件地址
159
159
  * @since v1.18.1
160
- * @throws `RangeError` 不是有效的维基百科网址
161
160
  */
162
161
  setTargetWikipedia(wiki: string, user: string): Promise<void>;
163
162
  }
package/dist/lib/lsp.js CHANGED
@@ -498,7 +498,6 @@ class LanguageService {
498
498
  * 颜色选择器
499
499
  * @param color color information / 颜色信息
500
500
  */
501
- // eslint-disable-next-line @typescript-eslint/class-methods-use-this
502
501
  provideColorPresentations(color) {
503
502
  const { color: { red, green, blue, alpha }, range } = color, rgb = [red, green, blue], newText = alpha < 1
504
503
  ? `rgba(${rgb.map(c => Math.round(c * 255)).join()},${alpha})`
@@ -789,7 +788,7 @@ class LanguageService {
789
788
  /* eslint-disable @stylistic/operator-linebreak */
790
789
  cssDiagnostics = await document_1.stylelint ?
791
790
  await (async () => {
792
- NPM: { // eslint-disable-line no-unused-labels
791
+ NPM: {
793
792
  const tokens = this.findStyleTokens();
794
793
  if (tokens.length === 0) {
795
794
  return [];
@@ -999,7 +998,7 @@ class LanguageService {
999
998
  let name;
1000
999
  if (token.is('magic-word')) {
1001
1000
  ({ name } = token);
1002
- token = token.childNodes[1].lastChild; // eslint-disable-line no-param-reassign
1001
+ token = token.childNodes[1].lastChild;
1003
1002
  }
1004
1003
  else if (token.is('image-parameter')) {
1005
1004
  ({ name } = token);
@@ -1417,7 +1416,6 @@ class LanguageService {
1417
1416
  * 提供快速修复建议
1418
1417
  * @param diagnostics grammar diagnostics / 语法诊断信息
1419
1418
  */
1420
- // eslint-disable-next-line @typescript-eslint/class-methods-use-this
1421
1419
  provideCodeAction(diagnostics) {
1422
1420
  const actionable = diagnostics.filter((diagnostic) => diagnostic.data), fixable = actionable.filter(({ source, data }) => source === 'WikiLint' && data.some(({ fix }) => fix)), fixableRules = [...new Set(fixable.map(({ code }) => code))];
1423
1421
  return [
@@ -1498,7 +1496,6 @@ class LanguageService {
1498
1496
  * @param wiki Wikipedia URL / 维基百科网址
1499
1497
  * @param user URI for wiki userpage or email address of the user / 维基用户页面地址或用户的电子邮件地址
1500
1498
  * @since v1.18.1
1501
- * @throws `RangeError` 不是有效的维基百科网址
1502
1499
  */
1503
1500
  async setTargetWikipedia(wiki, user) {
1504
1501
  const [site, host] = index_1.default.getWMFSite(wiki);
package/dist/lib/node.js CHANGED
@@ -112,7 +112,7 @@ let AstNode = (() => {
112
112
  this.#previousSibling = value;
113
113
  break;
114
114
  case 'aIndex':
115
- LINT: { // eslint-disable-line no-unused-labels
115
+ LINT: {
116
116
  this.#aIndex = [debug_1.Shadow.rev, value];
117
117
  }
118
118
  break;
@@ -141,7 +141,7 @@ let AstNode = (() => {
141
141
  * @param left column number / 列号
142
142
  */
143
143
  indexFromPos(top, left) {
144
- LSP: { // eslint-disable-line no-unused-labels
144
+ LSP: {
145
145
  if (top < 0 || left < 0) {
146
146
  return undefined;
147
147
  }
@@ -160,7 +160,7 @@ let AstNode = (() => {
160
160
  * @param index character index / 字符位置
161
161
  */
162
162
  posFromIndex(index) {
163
- LINT: { // eslint-disable-line no-unused-labels
163
+ LINT: {
164
164
  const { length } = String(this);
165
165
  index += index < 0 ? length : 0;
166
166
  if (index >= 0 && index <= length) {
@@ -172,7 +172,7 @@ let AstNode = (() => {
172
172
  }
173
173
  /** @private */
174
174
  getDimension() {
175
- LINT: { // eslint-disable-line no-unused-labels
175
+ LINT: {
176
176
  const lines = this.getLines(), last = lines[lines.length - 1];
177
177
  return { height: lines.length, width: last[2] - last[1] };
178
178
  }
@@ -213,8 +213,7 @@ let AstNode = (() => {
213
213
  */
214
214
  getAbsoluteIndex() {
215
215
  // 也用于Prism-Wiki
216
- return (0, lint_1.cache)(// eslint-disable-line no-unused-labels
217
- this.#aIndex, () => {
216
+ return (0, lint_1.cache)(this.#aIndex, () => {
218
217
  const { parentNode } = this;
219
218
  return parentNode ? parentNode.getAbsoluteIndex() + this.getRelativeIndex() : 0;
220
219
  }, value => {
@@ -227,7 +226,6 @@ let AstNode = (() => {
227
226
  * 获取当前节点的行列位置和大小
228
227
  */
229
228
  getBoundingClientRect() {
230
- // eslint-disable-next-line no-unused-labels
231
229
  LSP: return {
232
230
  ...this.getDimension(),
233
231
  ...this.getRootNode().posFromIndex(this.getAbsoluteIndex()),
@@ -250,7 +248,7 @@ let AstNode = (() => {
250
248
  * @since v1.16.3
251
249
  */
252
250
  getLines() {
253
- LINT: { // eslint-disable-line no-unused-labels
251
+ LINT: {
254
252
  const results = [];
255
253
  let start = 0;
256
254
  for (const line of String(this).split('\n')) {
package/dist/lib/text.js CHANGED
@@ -9,7 +9,7 @@ const lint_1 = require("../util/lint");
9
9
  const debug_1 = require("../util/debug");
10
10
  const index_1 = __importDefault(require("../index"));
11
11
  const node_1 = require("./node");
12
- const sp = /* #__PURE__ */ (() => String.raw `[${string_1.zs}\t]*`)(), anySp = /* #__PURE__ */ (() => String.raw `[^\S\n]*`)(), source = /* #__PURE__ */ (() => String.raw `<${anySp}(?:/${anySp})?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])|((?:^|\])[^[]*?)\]+`)();
12
+ const sp = /* #__PURE__ */ (() => String.raw `[${string_1.zs}\t]*`)(), source = /* #__PURE__ */ (() => String.raw `<(?:/[^\S\n]*)?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])|((?:^|\])[^[]*?)\]+|\n={2,}`)();
13
13
  const errorSyntax = /* #__PURE__ */ (() => new RegExp(String.raw `${source}|https?[:/]/+|(?:rfc|pmid)(?=[-::]?${sp}\d)|isbn(?=[-::]?${sp}(?:\d(?:${sp}|-)){6})`, 'giu'))();
14
14
  const errorSyntaxUrl = /* #__PURE__ */ new RegExp(source, 'giu'), noLinkTypes = new Set(['attr-value', 'ext-link-text', 'link-text']), regexes = {
15
15
  '[': /[[\]]/u,
@@ -77,7 +77,7 @@ class AstText extends node_1.AstNode {
77
77
  }
78
78
  /** @private */
79
79
  lint(start = this.getAbsoluteIndex(), errorRegex) {
80
- LINT: { // eslint-disable-line no-unused-labels
80
+ LINT: {
81
81
  if (errorRegex === false) {
82
82
  return [];
83
83
  }
@@ -121,6 +121,10 @@ class AstText extends node_1.AstNode {
121
121
  index += length;
122
122
  error = error.slice(length);
123
123
  }
124
+ else if (error.startsWith('\n==')) {
125
+ index++;
126
+ error = error.slice(1);
127
+ }
124
128
  error = error.toLowerCase();
125
129
  const [char] = error, magicLink = char === 'r' || char === 'p' || char === 'i', lbrace = char === '{', rbrace = char === '}', lbrack = char === '[', rbrack = char === ']';
126
130
  let { length } = error;
@@ -134,7 +138,7 @@ class AstText extends node_1.AstNode {
134
138
  errorRegex.lastIndex--;
135
139
  }
136
140
  // Rule & Severity
137
- let startIndex = start + index, endIndex = startIndex + length, rule, severity;
141
+ let startIndex = start + index, endIndex = startIndex + length, rule, severity, endLine, endCol;
138
142
  const nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], leftBracket = lbrace || lbrack, lConverter = lbrace && previousChar === '-' && variants.length > 0, rConverter = rbrace && nextChar === '-' && variants.length > 0, brokenExtLink = lbrack && nextType === 'free-ext-link' && !data.slice(index + 1).trim()
139
143
  || rbrack && previousType === 'free-ext-link'
140
144
  && !data.slice(0, index).includes(']');
@@ -157,6 +161,10 @@ class AstText extends node_1.AstNode {
157
161
  }
158
162
  severity = lintConfig.getSeverity(rule, key);
159
163
  }
164
+ else if (char === '=') {
165
+ rule = 'syntax-like';
166
+ severity = lintConfig.getSeverity(rule, 'heading');
167
+ }
160
168
  else if (lConverter || rConverter) {
161
169
  rule = 'lonely-bracket';
162
170
  severity = lintConfig.getSeverity(rule, 'converter');
@@ -210,16 +218,51 @@ class AstText extends node_1.AstNode {
210
218
  continue;
211
219
  }
212
220
  // LintError
213
- const pos = this.posFromIndex(index), { line: startLine, character: startCol } = (0, lint_1.getEndPos)(top, left, pos.top + 1, pos.left), e = {
221
+ const pos = this.posFromIndex(index), { line: startLine, character: startCol } = (0, lint_1.getEndPos)(top, left, pos.top + 1, pos.left);
222
+ if (char === '=') {
223
+ const lineEnd = data.indexOf('\n', index);
224
+ let sibling = nextSibling, line;
225
+ if (lineEnd === -1) {
226
+ let end = 0;
227
+ while (sibling) {
228
+ if (sibling.type === 'text') {
229
+ end = sibling.data.indexOf('\n');
230
+ if (end !== -1) {
231
+ break;
232
+ }
233
+ }
234
+ sibling = sibling.nextSibling;
235
+ }
236
+ if (!sibling) {
237
+ continue;
238
+ }
239
+ line = sibling.data.slice(0, end);
240
+ }
241
+ else {
242
+ line = data.slice(index + length, lineEnd);
243
+ }
244
+ if (!/(?:^|[^=])=+\s*(?:\S\s*)?$/u.test(line)) {
245
+ continue;
246
+ }
247
+ if (lineEnd === -1) {
248
+ endIndex = sibling.getAbsoluteIndex() + line.length;
249
+ ({ top: endLine, left: endCol } = root.posFromIndex(endIndex));
250
+ }
251
+ else {
252
+ endIndex += line.length;
253
+ length += line.length;
254
+ }
255
+ }
256
+ const e = {
214
257
  rule,
215
- message: index_1.default.msg('lonely', magicLink || char === 'h' || lConverter || rConverter ? error : char),
258
+ message: index_1.default.msg(char === '=' ? 'header-like' : 'lonely', magicLink || char === 'h' || lConverter || rConverter ? error : char),
216
259
  severity,
217
260
  startIndex,
218
261
  endIndex,
219
262
  startLine,
220
- endLine: startLine,
263
+ endLine: endLine ?? startLine,
221
264
  startCol,
222
- endCol: startCol + length,
265
+ endCol: endCol ?? startCol + length,
223
266
  };
224
267
  // Suggestions
225
268
  if (lintConfig.computeEditInfo) {
@@ -278,7 +321,7 @@ class AstText extends node_1.AstNode {
278
321
  * @throws `Error` 没有父节点
279
322
  */
280
323
  splitText(offset) {
281
- LSP: { // eslint-disable-line no-unused-labels
324
+ LSP: {
282
325
  const { parentNode, data } = this;
283
326
  /* istanbul ignore if */
284
327
  if (!parentNode) {
@@ -298,7 +341,7 @@ class AstText extends node_1.AstNode {
298
341
  * @throws `Error` 没有父节点
299
342
  */
300
343
  escape() {
301
- LSP: { // eslint-disable-line no-unused-labels
344
+ LSP: {
302
345
  const { parentNode } = this;
303
346
  /* istanbul ignore if */
304
347
  if (!parentNode) {
package/dist/lib/title.js CHANGED
@@ -169,7 +169,7 @@ class Title {
169
169
  * @since v1.10.0
170
170
  */
171
171
  getUrl(articlePath) {
172
- LSP: { // eslint-disable-line no-unused-labels
172
+ LSP: {
173
173
  if (typeof articlePath === 'string') {
174
174
  this.#path = articlePath;
175
175
  /* istanbul ignore if */