wikilint 2.1.0 → 2.1.2

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 (41) hide show
  1. package/README.md +1 -0
  2. package/dist/base.d.ts +39 -0
  3. package/dist/index.d.ts +4 -26
  4. package/dist/lib/element.d.ts +2 -2
  5. package/dist/lib/element.js +1 -1
  6. package/dist/lib/node.d.ts +4 -2
  7. package/dist/lib/text.d.ts +2 -2
  8. package/dist/lib/text.js +1 -1
  9. package/dist/src/arg.d.ts +1 -1
  10. package/dist/src/atom.d.ts +1 -1
  11. package/dist/src/attribute.d.ts +1 -1
  12. package/dist/src/attributes.d.ts +1 -1
  13. package/dist/src/converterFlags.d.ts +1 -1
  14. package/dist/src/converterRule.js +7 -12
  15. package/dist/src/gallery.d.ts +1 -1
  16. package/dist/src/heading.d.ts +1 -2
  17. package/dist/src/heading.js +4 -3
  18. package/dist/src/html.d.ts +1 -1
  19. package/dist/src/imageParameter.d.ts +1 -1
  20. package/dist/src/imagemap.d.ts +1 -1
  21. package/dist/src/link/base.d.ts +2 -1
  22. package/dist/src/link/base.js +11 -3
  23. package/dist/src/link/file.d.ts +1 -1
  24. package/dist/src/link/galleryImage.d.ts +4 -1
  25. package/dist/src/link/galleryImage.js +14 -3
  26. package/dist/src/magicLink.d.ts +1 -1
  27. package/dist/src/nested.d.ts +1 -1
  28. package/dist/src/nowiki/comment.d.ts +1 -1
  29. package/dist/src/nowiki/index.d.ts +1 -1
  30. package/dist/src/nowiki/quote.d.ts +1 -1
  31. package/dist/src/nowiki/quote.js +2 -2
  32. package/dist/src/paramTag/index.d.ts +1 -1
  33. package/dist/src/parameter.d.ts +1 -1
  34. package/dist/src/table/index.d.ts +1 -1
  35. package/dist/src/table/td.d.ts +1 -1
  36. package/dist/src/table/td.js +2 -2
  37. package/dist/src/table/trBase.d.ts +1 -1
  38. package/dist/src/tagPair/ext.d.ts +1 -1
  39. package/dist/src/transclude.d.ts +1 -1
  40. package/dist/util/debug.js +1 -2
  41. package/package.json +2 -2
package/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![CI](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/node.js.yml/badge.svg)](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/node.js.yml)
4
4
 
5
5
  # wikilint
6
+
6
7
  This is a minimal version of [wikiparser-node](https://www.npmjs.com/package/wikiparser-node) customized for [eslint-plugin-wikitext](https://www.npmjs.com/package/eslint-plugin-wikitext).
7
8
 
8
9
  You can also directly lint Wikitext articles in the command line using this package:
package/dist/base.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ export interface Config {
2
+ ext: string[];
3
+ html: [string[], string[], string[]];
4
+ namespaces: Record<string, string>;
5
+ nsid: Record<string, number>;
6
+ parserFunction: [Record<string, string>, string[], string[], string[]];
7
+ doubleUnderscore: [string[], string[]];
8
+ protocol: string;
9
+ img: Record<string, string>;
10
+ variants: string[];
11
+ excludes?: string[];
12
+ }
13
+ export interface LintError {
14
+ message: string;
15
+ severity: 'error' | 'warning';
16
+ startIndex: number;
17
+ endIndex: number;
18
+ startLine: number;
19
+ startCol: number;
20
+ endLine: number;
21
+ endCol: number;
22
+ }
23
+ /** 类似Node */
24
+ export interface AstNode {
25
+ type: string;
26
+ childNodes: AstNode[];
27
+ /** Linter */
28
+ lint(): LintError[];
29
+ }
30
+ export interface Parser {
31
+ config: string | Config;
32
+ i18n: string | Record<string, string> | undefined;
33
+ /**
34
+ * 解析wikitext
35
+ * @param include 是否嵌入
36
+ * @param maxStage 最大解析层级
37
+ */
38
+ parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): AstNode;
39
+ }
package/dist/index.d.ts CHANGED
@@ -1,30 +1,7 @@
1
1
  import type { Title } from './lib/title';
2
2
  import type { Token } from './internal';
3
- export interface Config {
4
- ext: string[];
5
- html: [string[], string[], string[]];
6
- namespaces: Record<string, string>;
7
- nsid: Record<string, number>;
8
- parserFunction: [Record<string, string>, string[], string[], string[]];
9
- doubleUnderscore: [string[], string[]];
10
- protocol: string;
11
- img: Record<string, string>;
12
- variants: string[];
13
- excludes?: string[];
14
- }
15
- export interface LintError {
16
- message: string;
17
- severity: 'error' | 'warning';
18
- startIndex: number;
19
- endIndex: number;
20
- startLine: number;
21
- startCol: number;
22
- endLine: number;
23
- endCol: number;
24
- }
25
- declare interface Parser {
26
- config: string | Config;
27
- i18n: string | Record<string, string> | undefined;
3
+ import type { Config, LintError, Parser as ParserBase } from './base';
4
+ declare interface Parser extends ParserBase {
28
5
  /**
29
6
  * 规范化页面标题
30
7
  * @param title 标题(含或不含命名空间前缀)
@@ -36,7 +13,7 @@ declare interface Parser {
36
13
  */
37
14
  normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): Title;
38
15
  /**
39
- * 解析wikitext
16
+ * @override
40
17
  * @param include 是否嵌入
41
18
  * @param maxStage 最大解析层级
42
19
  */
@@ -44,4 +21,5 @@ declare interface Parser {
44
21
  }
45
22
  declare const Parser: Parser;
46
23
  export = Parser;
24
+ export type { Config, LintError };
47
25
  export type * from './internal';
@@ -1,5 +1,5 @@
1
1
  import { AstNode } from './node';
2
- import type { LintError } from '../index';
2
+ import type { LintError } from '../base';
3
3
  import type { AstNodes, Token } from '../internal';
4
4
  /** 类似HTMLElement */
5
5
  export declare abstract class AstElement extends AstNode {
@@ -49,7 +49,7 @@ export declare abstract class AstElement extends AstNode {
49
49
  */
50
50
  setText(str: string, i?: number): string;
51
51
  /**
52
- * Linter
52
+ * @override
53
53
  * @param start
54
54
  */
55
55
  lint(start?: number): LintError[];
@@ -121,7 +121,7 @@ class AstElement extends node_1.AstNode {
121
121
  return this.childNodes.map(child => child.toString()).join(separator);
122
122
  }
123
123
  /**
124
- * Linter
124
+ * @override
125
125
  * @param start
126
126
  */
127
127
  lint(start = this.getAbsoluteIndex()) {
@@ -1,6 +1,7 @@
1
+ import type { LintError, AstNode as AstNodeBase } from '../base';
1
2
  import type { AstText, Token } from '../internal';
2
3
  export type AstNodes = AstText | Token;
3
- export type TokenTypes = 'root' | 'plain' | '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' | 'list' | 'dd' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-noconvert' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'imagemap-link';
4
+ export type TokenTypes = 'root' | 'plain' | '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' | 'list' | 'dd' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'imagemap-link';
4
5
  export interface Dimension {
5
6
  height: number;
6
7
  width: number;
@@ -14,11 +15,12 @@ export interface CaretPosition {
14
15
  offset: number;
15
16
  }
16
17
  /** 类似Node */
17
- export declare abstract class AstNode {
18
+ export declare abstract class AstNode implements AstNodeBase {
18
19
  #private;
19
20
  type: TokenTypes | 'text';
20
21
  data?: string | undefined;
21
22
  readonly childNodes: AstNodes[];
23
+ abstract lint(): LintError[];
22
24
  /** 首位子节点 */
23
25
  get firstChild(): AstNodes | undefined;
24
26
  /** 末位子节点 */
@@ -1,5 +1,5 @@
1
1
  import { AstNode } from './node';
2
- import type { LintError } from '../index';
2
+ import type { LintError } from '../base';
3
3
  /** 文本节点 */
4
4
  export declare class AstText extends AstNode {
5
5
  #private;
@@ -11,7 +11,7 @@ export declare class AstText extends AstNode {
11
11
  /** 可见部分 */
12
12
  text(): string;
13
13
  /**
14
- * Linter
14
+ * @override
15
15
  * @param start
16
16
  */
17
17
  lint(start?: number): LintError[];
package/dist/lib/text.js CHANGED
@@ -48,7 +48,7 @@ class AstText extends node_1.AstNode {
48
48
  return this.data;
49
49
  }
50
50
  /**
51
- * Linter
51
+ * @override
52
52
  * @param start
53
53
  */
54
54
  lint(start = this.getAbsoluteIndex()) {
package/dist/src/arg.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { AtomToken } from './atom';
4
4
  import { HiddenToken } from './hidden';
5
- import type { LintError } from '../index';
5
+ import type { LintError } from '../base';
6
6
  /**
7
7
  * `{{{}}}`包裹的参数
8
8
  * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
@@ -1,6 +1,6 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
- declare type AtomTypes = 'arg-name' | 'attr-key' | 'attr-value' | 'ext-attr-dirty' | 'html-attr-dirty' | 'table-attr-dirty' | 'converter-flag' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'converter-rule-noconvert' | 'invoke-function' | 'invoke-module' | 'template-name' | 'link-target' | 'param-line';
3
+ declare type AtomTypes = 'arg-name' | 'attr-key' | 'attr-value' | 'ext-attr-dirty' | 'html-attr-dirty' | 'table-attr-dirty' | 'converter-flag' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'invoke-function' | 'invoke-module' | 'template-name' | 'link-target' | 'param-line';
4
4
  /** 不会被继续解析的plain Token */
5
5
  export declare class AtomToken extends Token {
6
6
  type: AtomTypes;
@@ -1,7 +1,7 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { AtomToken } from './atom';
4
- import type { LintError } from '../index';
4
+ import type { LintError } from '../base';
5
5
  import type { AttributesToken } from '../internal';
6
6
  export type AttributeTypes = 'ext-attr' | 'html-attr' | 'table-attr';
7
7
  /**
@@ -2,7 +2,7 @@ import * as Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { AtomToken } from './atom';
4
4
  import { AttributeToken } from './attribute';
5
- import type { LintError } from '../index';
5
+ import type { LintError } from '../base';
6
6
  import type { ExtToken, HtmlToken, TdToken, TrToken, TableToken } from '../internal';
7
7
  declare type AttributesTypes = 'ext-attrs' | 'html-attrs' | 'table-attrs';
8
8
  /**
@@ -1,7 +1,7 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { AtomToken } from './atom';
4
- import type { LintError } from '../index';
4
+ import type { LintError } from '../base';
5
5
  import type { ConverterToken, ConverterRuleToken } from '../internal';
6
6
  /**
7
7
  * 转换flags
@@ -16,21 +16,16 @@ class ConverterRuleToken extends index_1.Token {
16
16
  */
17
17
  constructor(rule, hasColon = true, config = Parser.getConfig(), accum = []) {
18
18
  super(undefined, config, accum);
19
- if (hasColon) {
20
- const i = rule.indexOf(':'), j = rule.slice(0, i).indexOf('=>'), v = j === -1 ? rule.slice(0, i) : rule.slice(j + 2, i);
21
- if (config.variants.includes(v.trim())) {
22
- super.insertAt(new atom_1.AtomToken(v, 'converter-rule-variant', config, accum));
23
- super.insertAt(new atom_1.AtomToken(rule.slice(i + 1), 'converter-rule-to', config, accum));
24
- if (j !== -1) {
25
- super.insertAt(new atom_1.AtomToken(rule.slice(0, j), 'converter-rule-from', config, accum), 0);
26
- }
27
- }
28
- else {
29
- super.insertAt(new atom_1.AtomToken(rule, 'converter-rule-noconvert', config, accum));
19
+ const i = rule.indexOf(':'), j = rule.slice(0, i).indexOf('=>'), v = j === -1 ? rule.slice(0, i) : rule.slice(j + 2, i);
20
+ if (hasColon && config.variants.includes(v.trim())) {
21
+ super.insertAt(new atom_1.AtomToken(v, 'converter-rule-variant', config, accum));
22
+ super.insertAt(new atom_1.AtomToken(rule.slice(i + 1), 'converter-rule-to', config, accum));
23
+ if (j !== -1) {
24
+ super.insertAt(new atom_1.AtomToken(rule.slice(0, j), 'converter-rule-from', config, accum), 0);
30
25
  }
31
26
  }
32
27
  else {
33
- super.insertAt(new atom_1.AtomToken(rule, 'converter-rule-noconvert', config, accum));
28
+ super.insertAt(new atom_1.AtomToken(rule, 'converter-rule-to', config, accum));
34
29
  }
35
30
  }
36
31
  /** @private */
@@ -2,7 +2,7 @@ import * as Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { GalleryImageToken } from './link/galleryImage';
4
4
  import { HiddenToken } from './hidden';
5
- import type { LintError } from '../index';
5
+ import type { LintError } from '../base';
6
6
  import type { AstText, AttributesToken, ExtToken } from '../internal';
7
7
  /**
8
8
  * gallery标签
@@ -1,7 +1,7 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { SyntaxToken } from './syntax';
4
- import type { LintError } from '../index';
4
+ import type { LintError } from '../base';
5
5
  /**
6
6
  * 章节标题
7
7
  * @classdesc `{childNodes: [Token, SyntaxToken]}`
@@ -9,7 +9,6 @@ import type { LintError } from '../index';
9
9
  export declare class HeadingToken extends Token {
10
10
  #private;
11
11
  readonly type = "heading";
12
- name: string;
13
12
  childNodes: [Token, SyntaxToken];
14
13
  abstract get firstChild(): Token;
15
14
  abstract get lastChild(): SyntaxToken;
@@ -11,13 +11,14 @@ const syntax_1 = require("./syntax");
11
11
  */
12
12
  class HeadingToken extends index_1.Token {
13
13
  type = 'heading';
14
+ #level;
14
15
  /** 标题格式的等号 */
15
16
  get #equals() {
16
17
  return '='.repeat(this.level);
17
18
  }
18
19
  /** 标题层级 */
19
20
  get level() {
20
- return Number(this.name);
21
+ return this.#level;
21
22
  }
22
23
  /**
23
24
  * @param level 标题层级
@@ -25,7 +26,7 @@ class HeadingToken extends index_1.Token {
25
26
  */
26
27
  constructor(level, input, config = Parser.getConfig(), accum = []) {
27
28
  super(undefined, config, accum);
28
- this.setAttribute('name', String(level));
29
+ this.#level = level;
29
30
  const token = new index_1.Token(input[0], config, accum);
30
31
  token.type = 'heading-title';
31
32
  token.setAttribute('stage', 2);
@@ -56,7 +57,7 @@ class HeadingToken extends index_1.Token {
56
57
  lint(start = this.getAbsoluteIndex()) {
57
58
  const errors = super.lint(start), innerStr = String(this.firstChild);
58
59
  let refError;
59
- if (this.name === '1') {
60
+ if (this.level === 1) {
60
61
  refError = (0, lint_1.generateForSelf)(this, { start }, '<h1>');
61
62
  errors.push(refError);
62
63
  }
@@ -1,6 +1,6 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
- import type { LintError } from '../index';
3
+ import type { LintError } from '../base';
4
4
  import type { AttributesToken } from '../internal';
5
5
  /**
6
6
  * HTML标签
@@ -1,6 +1,6 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
- import type { LintError } from '../index';
3
+ import type { LintError } from '../base';
4
4
  import type { Title } from '../lib/title';
5
5
  import type { AtomToken, FileToken } from '../internal';
6
6
  export declare const galleryParams: Set<string>;
@@ -3,7 +3,7 @@ import { Token } from './index';
3
3
  import { NoincludeToken } from './nowiki/noinclude';
4
4
  import { GalleryImageToken } from './link/galleryImage';
5
5
  import { ImagemapLinkToken } from './imagemapLink';
6
- import type { LintError } from '../index';
6
+ import type { LintError } from '../base';
7
7
  import type { AstText, AttributesToken, ExtToken } from '../internal';
8
8
  /**
9
9
  * `<imagemap>`
@@ -1,7 +1,8 @@
1
1
  import * as Parser from '../../index';
2
2
  import { Token } from '../index';
3
3
  import { AtomToken } from '../atom';
4
- import type { LintError } from '../../index';
4
+ import type { LintError } from '../../base';
5
+ import type { Title } from '../../lib/title';
5
6
  /**
6
7
  * 内链
7
8
  * @classdesc `{childNodes: [AtomToken, ...Token]}`
@@ -13,6 +13,7 @@ const atom_1 = require("../atom");
13
13
  class LinkBaseToken extends index_1.Token {
14
14
  #bracket = true;
15
15
  #delimiter;
16
+ #title;
16
17
  /**
17
18
  * @param link 链接标题
18
19
  * @param linkText 链接显示文字
@@ -31,6 +32,7 @@ class LinkBaseToken extends index_1.Token {
31
32
  }
32
33
  /** @private */
33
34
  afterBuild() {
35
+ this.#title = this.getTitle();
34
36
  if (this.#delimiter.includes('\0')) {
35
37
  this.#delimiter = this.buildFromStr(this.#delimiter, 'string');
36
38
  }
@@ -40,6 +42,9 @@ class LinkBaseToken extends index_1.Token {
40
42
  if (key === 'bracket') {
41
43
  this.#bracket = Boolean(value);
42
44
  }
45
+ else if (key === 'title') {
46
+ this.#title = value;
47
+ }
43
48
  else {
44
49
  super.setAttribute(key, value);
45
50
  }
@@ -58,6 +63,9 @@ class LinkBaseToken extends index_1.Token {
58
63
  }
59
64
  /** @private */
60
65
  getAttribute(key) {
66
+ if (key === 'title') {
67
+ return this.#title;
68
+ }
61
69
  return key === 'padding' ? 2 : super.getAttribute(key);
62
70
  }
63
71
  /** @private */
@@ -66,7 +74,7 @@ class LinkBaseToken extends index_1.Token {
66
74
  }
67
75
  /** @override */
68
76
  lint(start = this.getAbsoluteIndex()) {
69
- const errors = super.lint(start), { childNodes: [target, linkText], type: linkType } = this, { encoded, fragment } = this.#getTitle();
77
+ const errors = super.lint(start), { childNodes: [target, linkText], type: linkType } = this, { encoded, fragment } = this.#title;
70
78
  let rect;
71
79
  if (linkType === 'link' && target.childNodes.some(({ type }) => type === 'template')) {
72
80
  rect = { start, ...this.getRootNode().posFromIndex(start) };
@@ -86,8 +94,8 @@ class LinkBaseToken extends index_1.Token {
86
94
  }
87
95
  return errors;
88
96
  }
89
- /** 生成Title对象 */
90
- #getTitle() {
97
+ /** @private */
98
+ getTitle() {
91
99
  return this.normalizeTitle(this.firstChild.text(), 0, false, true, true);
92
100
  }
93
101
  }
@@ -1,7 +1,7 @@
1
1
  import * as Parser from '../../index';
2
2
  import { LinkBaseToken } from './base';
3
3
  import { ImageParameterToken } from '../imageParameter';
4
- import type { LintError } from '../../index';
4
+ import type { LintError } from '../../base';
5
5
  import type { Token, AtomToken } from '../../internal';
6
6
  /**
7
7
  * 图片
@@ -1,7 +1,8 @@
1
1
  import * as Parser from '../../index';
2
2
  import { Token } from '../index';
3
3
  import { FileToken } from './file';
4
- import type { LintError } from '../../index';
4
+ import type { Title } from '../../lib/title';
5
+ import type { LintError } from '../../base';
5
6
  /** 图库图片 */
6
7
  export declare class GalleryImageToken extends FileToken {
7
8
  #private;
@@ -12,6 +13,8 @@ export declare class GalleryImageToken extends FileToken {
12
13
  * @param text 图片参数
13
14
  */
14
15
  constructor(type: 'gallery' | 'imagemap', link: string, text?: string, config?: Parser.Config, accum?: Token[]);
16
+ /** private */
17
+ getTitle(): Title;
15
18
  /** @override */
16
19
  lint(start?: number): LintError[];
17
20
  }
@@ -28,8 +28,8 @@ class GalleryImageToken extends file_1.FileToken {
28
28
  this.setAttribute('bracket', false);
29
29
  this.type = `${type}-image`;
30
30
  }
31
- /** 生成Title对象 */
32
- #getTitle() {
31
+ /** private */
32
+ getTitle() {
33
33
  const imagemap = this.type === 'imagemap-image';
34
34
  return this.normalizeTitle(String(this.firstChild), imagemap ? 0 : 6, true, !imagemap);
35
35
  }
@@ -39,11 +39,22 @@ class GalleryImageToken extends file_1.FileToken {
39
39
  }
40
40
  /** @override */
41
41
  lint(start = this.getAbsoluteIndex()) {
42
- const errors = super.lint(start), { ns, } = this.#getTitle();
42
+ const errors = super.lint(start), { ns, } = this.getAttribute('title');
43
43
  if (ns !== 6) {
44
44
  errors.push((0, lint_1.generateForSelf)(this, { start }, 'invalid gallery image'));
45
45
  }
46
46
  return errors;
47
47
  }
48
+ /**
49
+ * 设置`#title`
50
+ * @param title Title对象
51
+ */
52
+ #setName(title) {
53
+ this.setAttribute('title', title);
54
+ }
55
+ /** @private */
56
+ afterBuild() {
57
+ this.#setName(this.getTitle());
58
+ }
48
59
  }
49
60
  exports.GalleryImageToken = GalleryImageToken;
@@ -1,6 +1,6 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
- import type { LintError } from '../index';
3
+ import type { LintError } from '../base';
4
4
  import type { AstText, CommentToken, IncludeToken, NoincludeToken } from '../internal';
5
5
  /**
6
6
  * 自由外链
@@ -3,7 +3,7 @@ import { Token } from './index';
3
3
  import { ExtToken } from './tagPair/ext';
4
4
  import { NoincludeToken } from './nowiki/noinclude';
5
5
  import { CommentToken } from './nowiki/comment';
6
- import type { LintError } from '../index';
6
+ import type { LintError } from '../base';
7
7
  import type { AttributesToken } from './attributes';
8
8
  /**
9
9
  * 嵌套式的扩展标签
@@ -1,6 +1,6 @@
1
1
  import * as Parser from '../../index';
2
2
  import { NowikiBaseToken } from './base';
3
- import type { LintError } from '../../index';
3
+ import type { LintError } from '../../base';
4
4
  import type { Token } from '../index';
5
5
  declare const CommentToken_base: ((abstract new (...args: any[]) => {
6
6
  text(): string;
@@ -1,5 +1,5 @@
1
1
  import { NowikiBaseToken } from './base';
2
- import type { LintError } from '../../index';
2
+ import type { LintError } from '../../base';
3
3
  import type { AttributesToken, ExtToken } from '../../internal';
4
4
  /** 扩展标签内的纯文字Token */
5
5
  export declare class NowikiToken extends NowikiBaseToken {
@@ -1,5 +1,5 @@
1
1
  import { NowikiBaseToken } from './base';
2
- import type { LintError } from '../../index';
2
+ import type { LintError } from '../../base';
3
3
  /** `''`和`'''` */
4
4
  export declare class QuoteToken extends NowikiBaseToken {
5
5
  readonly type = "quote";
@@ -14,7 +14,7 @@ class QuoteToken extends base_1.NowikiBaseToken {
14
14
  let refError;
15
15
  if (previousSibling?.type === 'text' && previousSibling.data.endsWith(`'`)) {
16
16
  refError = (0, lint_1.generateForSelf)(this, { start }, message);
17
- const { startIndex: endIndex, startLine: endLine, startCol: endCol } = refError, [{ length }] = previousSibling.data.match(/(?<!')'+$/u), startIndex = start - length;
17
+ const { startIndex: endIndex, startLine: endLine, startCol: endCol } = refError, [{ length }] = /(?<!')'+$/u.exec(previousSibling.data), startIndex = start - length;
18
18
  errors.push({
19
19
  ...refError,
20
20
  startIndex,
@@ -26,7 +26,7 @@ class QuoteToken extends base_1.NowikiBaseToken {
26
26
  }
27
27
  if (nextSibling?.type === 'text' && nextSibling.data.startsWith(`'`)) {
28
28
  refError ??= (0, lint_1.generateForSelf)(this, { start }, message);
29
- const { endIndex: startIndex, endLine: startLine, endCol: startCol } = refError, [{ length }] = nextSibling.data.match(/^'+/u), endIndex = startIndex + length;
29
+ const { endIndex: startIndex, endLine: startLine, endCol: startCol } = refError, [{ length }] = /^'+/u.exec(nextSibling.data), endIndex = startIndex + length;
30
30
  errors.push({
31
31
  ...refError,
32
32
  startIndex,
@@ -1,7 +1,7 @@
1
1
  import * as Parser from '../../index';
2
2
  import { Token } from '../index';
3
3
  import { AtomToken } from '../atom';
4
- import type { LintError } from '../../index';
4
+ import type { LintError } from '../../base';
5
5
  import type { AttributesToken, ExtToken } from '../../internal';
6
6
  /**
7
7
  * `<dynamicpagelist>`
@@ -1,6 +1,6 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
- import type { LintError } from '../index';
3
+ import type { LintError } from '../base';
4
4
  import type { AtomToken, SyntaxToken, TranscludeToken } from '../internal';
5
5
  /**
6
6
  * 模板或魔术字参数
@@ -1,7 +1,7 @@
1
1
  import * as Parser from '../../index';
2
2
  import { TrBaseToken } from './trBase';
3
3
  import { SyntaxToken } from '../syntax';
4
- import type { LintError } from '../../index';
4
+ import type { LintError } from '../../base';
5
5
  import type { AttributesToken, TdToken, TrToken, Token } from '../../internal';
6
6
  /**
7
7
  * 表格
@@ -1,7 +1,7 @@
1
1
  import * as Parser from '../../index';
2
2
  import { Token } from '../index';
3
3
  import { TableBaseToken } from './base';
4
- import type { LintError } from '../../index';
4
+ import type { LintError } from '../../base';
5
5
  import type { SyntaxToken, AttributesToken, TrToken, TableToken } from '../../internal';
6
6
  export type TdSubtypes = 'td' | 'th' | 'caption';
7
7
  export type TdAttrs = Record<string, string | true> & {
@@ -22,9 +22,9 @@ class TdToken extends base_1.TableBaseToken {
22
22
  * @param inner 内部wikitext
23
23
  */
24
24
  constructor(syntax, inner, config = Parser.getConfig(), accum = []) {
25
- let innerSyntax = inner?.match(/\||\0\d+!\x7F/u), attr = innerSyntax ? inner.slice(0, innerSyntax.index) : '';
25
+ let innerSyntax = /\||\0\d+!\x7F/u.exec(inner ?? ''), attr = innerSyntax ? inner.slice(0, innerSyntax.index) : '';
26
26
  if (/\[\[|-\{/u.test(attr)) {
27
- innerSyntax = undefined;
27
+ innerSyntax = null;
28
28
  attr = '';
29
29
  }
30
30
  super(/^(?:\n[^\S\n]*(?:[|!]|\|\+|\{\{\s*!\s*\}\}\+?)|(?:\||\{\{\s*!\s*\}\}){2}|!!|\{\{\s*!!\s*\}\})$/u, syntax, attr, config, accum);
@@ -1,5 +1,5 @@
1
1
  import { TableBaseToken } from './base';
2
- import type { LintError } from '../../index';
2
+ import type { LintError } from '../../base';
3
3
  export interface TableCoords {
4
4
  row: number;
5
5
  column: number;
@@ -2,7 +2,7 @@ import * as Parser from '../../index';
2
2
  import { Token } from '../index';
3
3
  import { TagPairToken } from './index';
4
4
  import { AttributesToken } from '../attributes';
5
- import type { LintError } from '../../index';
5
+ import type { LintError } from '../../base';
6
6
  /**
7
7
  * 扩展标签
8
8
  * @classdesc `{childNodes: [AttributesToken, Token]}`
@@ -3,7 +3,7 @@ import { Token } from './index';
3
3
  import { ParameterToken } from './parameter';
4
4
  import { AtomToken } from './atom';
5
5
  import { SyntaxToken } from './syntax';
6
- import type { LintError } from '../index';
6
+ import type { LintError } from '../base';
7
7
  /**
8
8
  * 模板或魔术字
9
9
  * @classdesc `{childNodes: [AtomToken|SyntaxToken, ...AtomToken, ...ParameterToken]}`
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Shadow = void 0;
4
- // eslint-disable-next-line @typescript-eslint/no-redeclare
5
4
  exports.Shadow = {
6
- /** @implements */
5
+ /** @private */
7
6
  run(callback) {
8
7
  const result = callback();
9
8
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikilint",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "A Node.js linter for MediaWiki markup",
5
5
  "keywords": [
6
6
  "mediawiki",
@@ -30,7 +30,7 @@
30
30
  "url": "git+https://github.com/bhsd-harry/wikiparser-node.git"
31
31
  },
32
32
  "scripts": {
33
- "prepublishOnly": "npm run build; rm dist/internal.js; rm -r dist/test; rm dist/[bmpu]*/*.d.ts; grep -rl --include='*.d.ts' '@private' dist/ | xargs gsed -i '/@private/,+1d'",
33
+ "prepublishOnly": "npm run build; rm dist/internal.js dist/base.js dist/[bmpu]*/*.d.ts; rm -r dist/test; grep -rl --include='*.d.ts' '@private' dist/ | xargs gsed -i '/@private/,+1d'",
34
34
  "build": "rm -rf dist/; tsc; grep -rl --include='*.d.ts' '@private' dist/ | xargs gsed -i '/@private/,+1d'",
35
35
  "diff": "git diff --ignore-all-space --color-moved",
36
36
  "lint:ts": "tsc --noEmit && eslint --cache .",