wikilint 2.4.0 → 2.4.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 (121) hide show
  1. package/config/default.json +18 -3
  2. package/config/enwiki.json +411 -0
  3. package/dist/index.js +6 -7
  4. package/dist/lib/element.d.ts +1 -0
  5. package/dist/lib/element.js +2 -2
  6. package/dist/lib/node.d.ts +1 -0
  7. package/dist/lib/text.d.ts +1 -0
  8. package/dist/lib/text.js +81 -38
  9. package/dist/lib/title.d.ts +1 -1
  10. package/dist/lib/title.js +14 -3
  11. package/dist/parser/braces.js +5 -2
  12. package/dist/parser/commentAndExt.js +7 -2
  13. package/dist/parser/converter.js +3 -2
  14. package/dist/parser/externalLinks.js +3 -2
  15. package/dist/parser/hrAndDoubleUnderscore.js +5 -2
  16. package/dist/parser/html.js +6 -3
  17. package/dist/parser/links.js +6 -5
  18. package/dist/parser/list.js +4 -2
  19. package/dist/parser/magicLinks.js +3 -2
  20. package/dist/parser/quotes.js +4 -3
  21. package/dist/parser/table.js +11 -7
  22. package/dist/src/arg.d.ts +2 -2
  23. package/dist/src/arg.js +7 -7
  24. package/dist/src/atom.d.ts +1 -1
  25. package/dist/src/atom.js +4 -4
  26. package/dist/src/attribute.d.ts +3 -2
  27. package/dist/src/attribute.js +41 -12
  28. package/dist/src/attributes.d.ts +2 -2
  29. package/dist/src/attributes.js +8 -6
  30. package/dist/src/converter.d.ts +2 -2
  31. package/dist/src/converter.js +14 -8
  32. package/dist/src/converterFlags.d.ts +3 -2
  33. package/dist/src/converterFlags.js +7 -7
  34. package/dist/src/converterRule.d.ts +2 -2
  35. package/dist/src/converterRule.js +7 -7
  36. package/dist/src/extLink.d.ts +6 -2
  37. package/dist/src/extLink.js +18 -8
  38. package/dist/src/gallery.d.ts +3 -2
  39. package/dist/src/gallery.js +10 -7
  40. package/dist/src/heading.d.ts +3 -2
  41. package/dist/src/heading.js +10 -10
  42. package/dist/src/hidden.d.ts +0 -2
  43. package/dist/src/html.d.ts +3 -2
  44. package/dist/src/html.js +10 -10
  45. package/dist/src/imageParameter.d.ts +3 -2
  46. package/dist/src/imageParameter.js +8 -10
  47. package/dist/src/imagemap.d.ts +2 -2
  48. package/dist/src/imagemap.js +10 -6
  49. package/dist/src/imagemapLink.d.ts +2 -2
  50. package/dist/src/imagemapLink.js +11 -7
  51. package/dist/src/index.d.ts +2 -1
  52. package/dist/src/index.js +15 -15
  53. package/dist/src/link/base.d.ts +2 -1
  54. package/dist/src/link/base.js +10 -11
  55. package/dist/src/link/category.d.ts +1 -1
  56. package/dist/src/link/category.js +0 -1
  57. package/dist/src/link/file.d.ts +3 -2
  58. package/dist/src/link/file.js +6 -5
  59. package/dist/src/link/galleryImage.d.ts +7 -4
  60. package/dist/src/link/galleryImage.js +4 -5
  61. package/dist/src/link/index.d.ts +1 -1
  62. package/dist/src/link/index.js +0 -1
  63. package/dist/src/magicLink.d.ts +2 -2
  64. package/dist/src/magicLink.js +6 -6
  65. package/dist/src/nested.d.ts +2 -2
  66. package/dist/src/nested.js +9 -6
  67. package/dist/src/nowiki/base.d.ts +1 -1
  68. package/dist/src/nowiki/base.js +4 -4
  69. package/dist/src/nowiki/comment.d.ts +2 -4
  70. package/dist/src/nowiki/comment.js +4 -5
  71. package/dist/src/nowiki/dd.d.ts +1 -1
  72. package/dist/src/nowiki/dd.js +0 -1
  73. package/dist/src/nowiki/doubleUnderscore.d.ts +2 -4
  74. package/dist/src/nowiki/doubleUnderscore.js +3 -4
  75. package/dist/src/nowiki/hr.d.ts +1 -1
  76. package/dist/src/nowiki/hr.js +0 -1
  77. package/dist/src/nowiki/index.d.ts +1 -1
  78. package/dist/src/nowiki/index.js +2 -3
  79. package/dist/src/nowiki/list.d.ts +1 -1
  80. package/dist/src/nowiki/list.js +0 -1
  81. package/dist/src/nowiki/listBase.d.ts +1 -1
  82. package/dist/src/nowiki/listBase.js +0 -1
  83. package/dist/src/nowiki/noinclude.d.ts +1 -3
  84. package/dist/src/nowiki/noinclude.js +0 -1
  85. package/dist/src/nowiki/quote.d.ts +1 -1
  86. package/dist/src/nowiki/quote.js +3 -4
  87. package/dist/src/onlyinclude.js +1 -1
  88. package/dist/src/paramTag/index.d.ts +2 -2
  89. package/dist/src/paramTag/index.js +7 -7
  90. package/dist/src/paramTag/inputbox.d.ts +2 -2
  91. package/dist/src/paramTag/inputbox.js +4 -5
  92. package/dist/src/parameter.d.ts +2 -2
  93. package/dist/src/parameter.js +9 -13
  94. package/dist/src/pre.d.ts +2 -2
  95. package/dist/src/pre.js +6 -4
  96. package/dist/src/syntax.d.ts +1 -1
  97. package/dist/src/syntax.js +4 -4
  98. package/dist/src/table/base.d.ts +1 -1
  99. package/dist/src/table/base.js +7 -5
  100. package/dist/src/table/index.d.ts +2 -2
  101. package/dist/src/table/index.js +3 -4
  102. package/dist/src/table/td.d.ts +3 -2
  103. package/dist/src/table/td.js +6 -7
  104. package/dist/src/table/tr.d.ts +2 -2
  105. package/dist/src/table/tr.js +2 -3
  106. package/dist/src/table/trBase.js +1 -0
  107. package/dist/src/tagPair/ext.d.ts +2 -2
  108. package/dist/src/tagPair/ext.js +24 -8
  109. package/dist/src/tagPair/include.d.ts +2 -4
  110. package/dist/src/tagPair/include.js +5 -5
  111. package/dist/src/tagPair/index.d.ts +4 -1
  112. package/dist/src/tagPair/index.js +12 -7
  113. package/dist/src/transclude.d.ts +3 -2
  114. package/dist/src/transclude.js +8 -7
  115. package/dist/util/diff.js +11 -1
  116. package/dist/util/lint.js +2 -2
  117. package/dist/util/string.js +3 -1
  118. package/i18n/zh-hans.json +4 -3
  119. package/i18n/zh-hant.json +5 -4
  120. package/package.json +14 -13
  121. package/dist/bin/declaration.js +0 -27
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HeadingToken = void 0;
4
4
  const lint_1 = require("../util/lint");
5
- const Parser = require("../index");
6
- const index_1 = require("./index");
5
+ const index_1 = require("../index");
6
+ const index_2 = require("./index");
7
7
  const syntax_1 = require("./syntax");
8
8
  /**
9
9
  * 章节标题
10
10
  * @classdesc `{childNodes: [Token, SyntaxToken]}`
11
11
  */
12
- class HeadingToken extends index_1.Token {
12
+ class HeadingToken extends index_2.Token {
13
13
  type = 'heading';
14
14
  #level;
15
15
  /** 标题格式的等号 */
@@ -24,19 +24,19 @@ class HeadingToken extends index_1.Token {
24
24
  * @param level 标题层级
25
25
  * @param input 标题文字
26
26
  */
27
- constructor(level, input, config = Parser.getConfig(), accum = []) {
27
+ constructor(level, input, config = index_1.default.getConfig(), accum = []) {
28
28
  super(undefined, config, accum);
29
29
  this.#level = level;
30
- const token = new index_1.Token(input[0], config, accum);
30
+ const token = new index_2.Token(input[0], config, accum);
31
31
  token.type = 'heading-title';
32
32
  token.setAttribute('stage', 2);
33
33
  const trail = new syntax_1.SyntaxToken(input[1], /^[^\S\n]*$/u, 'heading-trail', config, accum, {});
34
34
  this.append(token, trail);
35
35
  }
36
36
  /** @private */
37
- toString(omit) {
37
+ toString() {
38
38
  const equals = this.#equals;
39
- return `${equals}${this.firstChild.toString()}${equals}${this.lastChild.toString()}`;
39
+ return `${equals}${String(this.firstChild)}${equals}${String(this.lastChild)}`;
40
40
  }
41
41
  /** @override */
42
42
  text() {
@@ -63,7 +63,7 @@ class HeadingToken extends index_1.Token {
63
63
  }
64
64
  if (innerStr.startsWith('=') || innerStr.endsWith('=')) {
65
65
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
66
- errors.push((0, lint_1.generateForChild)(firstChild, rect, Parser.msg('unbalanced $1 in a section header', '"="')));
66
+ errors.push((0, lint_1.generateForChild)(firstChild, rect, index_1.default.msg('unbalanced $1 in a section header', '"="')));
67
67
  }
68
68
  if (this.closest('html-attrs, table-attrs')) {
69
69
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
@@ -71,11 +71,11 @@ class HeadingToken extends index_1.Token {
71
71
  }
72
72
  if (boldQuotes.length % 2) {
73
73
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
74
- errors.push((0, lint_1.generateForChild)(boldQuotes[boldQuotes.length - 1], { ...rect, start: start + level, left: rect.left + level }, Parser.msg('unbalanced $1 in a section header', 'bold apostrophes')));
74
+ errors.push((0, lint_1.generateForChild)(boldQuotes[boldQuotes.length - 1], { ...rect, start: start + level, left: rect.left + level }, index_1.default.msg('unbalanced $1 in a section header', 'bold apostrophes')));
75
75
  }
76
76
  if (italicQuotes.length % 2) {
77
77
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
78
- errors.push((0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, Parser.msg('unbalanced $1 in a section header', 'italic apostrophes')));
78
+ errors.push((0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, index_1.default.msg('unbalanced $1 in a section header', 'italic apostrophes')));
79
79
  }
80
80
  return errors;
81
81
  }
@@ -1,7 +1,5 @@
1
1
  import { Token } from './index';
2
2
  export declare class HiddenToken extends Token {
3
- text(): string;
4
- lint(): import("..").LintError[];
5
3
  readonly type = "hidden";
6
4
  }
7
5
  export {};
@@ -1,4 +1,4 @@
1
- import * as Parser from '../index';
1
+ import Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import type { LintError } from '../base';
4
4
  import type { AttributesToken } from '../internal';
@@ -6,7 +6,8 @@ import type { AttributesToken } from '../internal';
6
6
  * HTML标签
7
7
  * @classdesc `{childNodes: [AttributesToken]}`
8
8
  */
9
- export declare class HtmlToken extends Token {
9
+ export declare abstract class HtmlToken extends Token {
10
+ #private;
10
11
  readonly type = "html";
11
12
  readonly name: string;
12
13
  readonly childNodes: readonly [AttributesToken];
package/dist/src/html.js CHANGED
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HtmlToken = void 0;
4
4
  const lint_1 = require("../util/lint");
5
5
  const string_1 = require("../util/string");
6
- const Parser = require("../index");
7
- const index_1 = require("./index");
6
+ const index_1 = require("../index");
7
+ const index_2 = require("./index");
8
8
  const magicWords = new Set(['if', 'ifeq', 'ifexpr', 'ifexist', 'iferror', 'switch']), formattingTags = new Set([
9
9
  'b',
10
10
  'big',
@@ -36,7 +36,7 @@ const magicWords = new Set(['if', 'ifeq', 'ifexpr', 'ifexist', 'iferror', 'switc
36
36
  * HTML标签
37
37
  * @classdesc `{childNodes: [AttributesToken]}`
38
38
  */
39
- class HtmlToken extends index_1.Token {
39
+ class HtmlToken extends index_2.Token {
40
40
  type = 'html';
41
41
  #closing;
42
42
  #selfClosing;
@@ -51,7 +51,7 @@ class HtmlToken extends index_1.Token {
51
51
  * @param closing 是否闭合
52
52
  * @param selfClosing 是否自封闭
53
53
  */
54
- constructor(name, attr, closing, selfClosing, config = Parser.getConfig(), accum = []) {
54
+ constructor(name, attr, closing, selfClosing, config = index_1.default.getConfig(), accum = []) {
55
55
  super(undefined, config, accum);
56
56
  this.insertAt(attr);
57
57
  this.setAttribute('name', name.toLowerCase());
@@ -60,7 +60,7 @@ class HtmlToken extends index_1.Token {
60
60
  this.#tag = name;
61
61
  }
62
62
  /** @private */
63
- toString(omit) {
63
+ toString() {
64
64
  return `<${this.closing ? '/' : ''}${this.#tag}${super.toString()}${this.#selfClosing ? '/' : ''}>`;
65
65
  }
66
66
  /** @override */
@@ -89,7 +89,7 @@ class HtmlToken extends index_1.Token {
89
89
  refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
90
90
  errors.push({
91
91
  ...refError,
92
- message: Parser.msg('HTML tag in table attributes'),
92
+ message: index_1.default.msg('HTML tag in table attributes'),
93
93
  });
94
94
  }
95
95
  try {
@@ -97,9 +97,9 @@ class HtmlToken extends index_1.Token {
97
97
  }
98
98
  catch (e) {
99
99
  if (e instanceof SyntaxError) {
100
- const { message: errorMsg } = e;
100
+ const { message } = e;
101
101
  refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
102
- const [msg] = errorMsg.split(':'), error = { ...refError, message: Parser.msg(msg) };
102
+ const [msg] = message.split(':'), error = { ...refError, message: index_1.default.msg(msg) };
103
103
  if (msg === 'unclosed tag' && !this.closest('heading-title')) {
104
104
  if (formattingTags.has(this.name)) {
105
105
  const childNodes = this.parentNode?.childNodes, i = childNodes?.indexOf(this);
@@ -124,7 +124,7 @@ class HtmlToken extends index_1.Token {
124
124
  refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
125
125
  errors.push({
126
126
  ...refError,
127
- message: Parser.msg('obsolete HTML tag'),
127
+ message: index_1.default.msg('obsolete HTML tag'),
128
128
  severity: 'warning',
129
129
  });
130
130
  }
@@ -132,7 +132,7 @@ class HtmlToken extends index_1.Token {
132
132
  refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
133
133
  errors.push({
134
134
  ...refError,
135
- message: Parser.msg('bold in section header'),
135
+ message: index_1.default.msg('bold in section header'),
136
136
  severity: 'warning',
137
137
  });
138
138
  }
@@ -1,11 +1,12 @@
1
- import * as Parser from '../index';
1
+ import Parser from '../index';
2
2
  import { Token } from './index';
3
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>;
7
7
  /** 图片参数 */
8
- export declare class ImageParameterToken extends Token {
8
+ export declare abstract class ImageParameterToken extends Token {
9
+ #private;
9
10
  readonly type = "image-parameter";
10
11
  readonly name: string;
11
12
  abstract get parentNode(): FileToken | undefined;
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ImageParameterToken = exports.galleryParams = void 0;
4
4
  const string_1 = require("../util/string");
5
5
  const lint_1 = require("../util/lint");
6
- const Parser = require("../index");
7
- const index_1 = require("./index");
6
+ const index_1 = require("../index");
7
+ const index_2 = require("./index");
8
8
  exports.galleryParams = new Set(['alt', 'link', 'lang', 'page', 'caption']);
9
- function validate(key, val, config = Parser.getConfig(), halfParsed = false) {
9
+ function validate(key, val, config = index_1.default.getConfig(), halfParsed = false) {
10
10
  val = val.trim();
11
11
  let value = val.replace(/\0\d+t\x7F/gu, '').trim();
12
12
  switch (key) {
@@ -25,7 +25,7 @@ function validate(key, val, config = Parser.getConfig(), halfParsed = false) {
25
25
  else if (value.startsWith('[[') && value.endsWith(']]')) {
26
26
  value = value.slice(2, -2);
27
27
  }
28
- const title = Parser.normalizeTitle(value, 0, false, config, halfParsed, true, true);
28
+ const title = index_1.default.normalizeTitle(value, 0, false, config, halfParsed, true, true);
29
29
  return title.valid && title;
30
30
  }
31
31
  case 'lang':
@@ -39,7 +39,7 @@ function validate(key, val, config = Parser.getConfig(), halfParsed = false) {
39
39
  }
40
40
  }
41
41
  /** 图片参数 */
42
- class ImageParameterToken extends index_1.Token {
42
+ class ImageParameterToken extends index_2.Token {
43
43
  type = 'image-parameter';
44
44
  #syntax = '';
45
45
  /** 图片链接 */
@@ -47,7 +47,7 @@ class ImageParameterToken extends index_1.Token {
47
47
  return this.name === 'link' ? validate('link', super.text(), this.getAttribute('config')) : undefined;
48
48
  }
49
49
  /** @param str 图片参数 */
50
- constructor(str, config = Parser.getConfig(), accum = []) {
50
+ constructor(str, config = index_1.default.getConfig(), accum = []) {
51
51
  let mt;
52
52
  const regexes = Object.entries(config.img).map(([syntax, param]) => [
53
53
  syntax,
@@ -82,10 +82,8 @@ class ImageParameterToken extends index_1.Token {
82
82
  }
83
83
  }
84
84
  /** @private */
85
- toString(omit) {
86
- return this.#syntax
87
- ? this.#syntax.replace('$1', super.toString(omit))
88
- : super.toString(omit);
85
+ toString() {
86
+ return this.#syntax ? this.#syntax.replace('$1', super.toString()) : super.toString();
89
87
  }
90
88
  /** @override */
91
89
  text() {
@@ -1,4 +1,4 @@
1
- import * as Parser from '../index';
1
+ import Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { NoincludeToken } from './nowiki/noinclude';
4
4
  import { GalleryImageToken } from './link/galleryImage';
@@ -9,7 +9,7 @@ import type { AstText, AttributesToken, ExtToken } from '../internal';
9
9
  * `<imagemap>`
10
10
  * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
11
11
  */
12
- export declare class ImagemapToken extends Token {
12
+ export declare abstract class ImagemapToken extends Token {
13
13
  readonly type = "ext-inner";
14
14
  readonly name: 'imagemap';
15
15
  readonly childNodes: readonly (GalleryImageToken | NoincludeToken | ImagemapLinkToken | AstText)[];
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ImagemapToken = void 0;
4
4
  const lint_1 = require("../util/lint");
5
5
  const debug_1 = require("../util/debug");
6
- const Parser = require("../index");
7
- const index_1 = require("./index");
6
+ const index_1 = require("../index");
7
+ const index_2 = require("./index");
8
8
  const noinclude_1 = require("./nowiki/noinclude");
9
9
  const galleryImage_1 = require("./link/galleryImage");
10
10
  const imagemapLink_1 = require("./imagemapLink");
@@ -12,14 +12,14 @@ const imagemapLink_1 = require("./imagemapLink");
12
12
  * `<imagemap>`
13
13
  * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
14
14
  */
15
- class ImagemapToken extends index_1.Token {
15
+ class ImagemapToken extends index_2.Token {
16
16
  type = 'ext-inner';
17
17
  /** 图片 */
18
18
  get image() {
19
19
  return this.childNodes.find((0, debug_1.isToken)('imagemap-image'));
20
20
  }
21
21
  /** @param inner 标签内部wikitext */
22
- constructor(inner, config = Parser.getConfig(), accum = []) {
22
+ constructor(inner, config = index_1.default.getConfig(), accum = []) {
23
23
  super(undefined, config, accum, {});
24
24
  if (!inner) {
25
25
  return;
@@ -35,6 +35,7 @@ class ImagemapToken extends index_1.Token {
35
35
  const [file, ...options] = line.split('|'), title = this.normalizeTitle(file, 0, true);
36
36
  if (title.valid
37
37
  && title.ns === 6) {
38
+ // @ts-expect-error abstract class
38
39
  const token = new galleryImage_1.GalleryImageToken('imagemap', file, options.length > 0 ? options.join('|') : undefined, config, accum);
39
40
  super.insertAt(token);
40
41
  first = false;
@@ -53,6 +54,7 @@ class ImagemapToken extends index_1.Token {
53
54
  .exec(substr);
54
55
  if (mtIn) {
55
56
  if (this.normalizeTitle(mtIn[1], 0, true, false, true).valid) {
57
+ // @ts-expect-error abstract class
56
58
  super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtIn.slice(1), substr.slice(substr.indexOf(']]') + 2), config, accum));
57
59
  continue;
58
60
  }
@@ -62,17 +64,19 @@ class ImagemapToken extends index_1.Token {
62
64
  const mtEx = /^\[([^\]\s]+)(?:(\s+(?=\S))([^\]]*))?\][\w\s]*$/u
63
65
  .exec(substr);
64
66
  if (mtEx) {
67
+ // @ts-expect-error abstract class
65
68
  super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtEx.slice(1), substr.slice(substr.indexOf(']') + 1), config, accum));
66
69
  continue;
67
70
  }
68
71
  }
69
72
  }
73
+ // @ts-expect-error abstract class
70
74
  super.insertAt(new SingleLineNoincludeToken(line, config, accum));
71
75
  }
72
76
  }
73
77
  /** @private */
74
- toString(omit) {
75
- return super.toString(omit, '\n');
78
+ toString() {
79
+ return super.toString('\n');
76
80
  }
77
81
  /** @override */
78
82
  text() {
@@ -1,4 +1,4 @@
1
- import * as Parser from '../index';
1
+ import Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { NoincludeToken } from './nowiki/noinclude';
4
4
  import { LinkToken } from './link/index';
@@ -8,7 +8,7 @@ import type { AstText, ImagemapToken } from '../internal';
8
8
  * `<imagemap>`内的链接
9
9
  * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
10
10
  */
11
- export declare class ImagemapLinkToken extends Token {
11
+ export declare abstract class ImagemapLinkToken extends Token {
12
12
  readonly type = "imagemap-link";
13
13
  readonly childNodes: readonly [AstText, LinkToken | ExtLinkToken, NoincludeToken];
14
14
  abstract get firstChild(): AstText;
@@ -1,27 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ImagemapLinkToken = void 0;
4
- const Parser = require("../index");
5
- const index_1 = require("./index");
4
+ const index_1 = require("../index");
5
+ const index_2 = require("./index");
6
6
  const noinclude_1 = require("./nowiki/noinclude");
7
- const index_2 = require("./link/index");
7
+ const index_3 = require("./link/index");
8
8
  const extLink_1 = require("./extLink");
9
9
  /**
10
10
  * `<imagemap>`内的链接
11
11
  * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
12
12
  */
13
- class ImagemapLinkToken extends index_1.Token {
13
+ class ImagemapLinkToken extends index_2.Token {
14
14
  type = 'imagemap-link';
15
15
  /**
16
16
  * @param pre 链接前的文本
17
17
  * @param linkStuff 内外链接
18
18
  * @param post 链接后的文本
19
19
  */
20
- constructor(pre, linkStuff, post, config = Parser.getConfig(), accum = []) {
20
+ constructor(pre, linkStuff, post, config = index_1.default.getConfig(), accum = []) {
21
21
  super(undefined, config, accum);
22
22
  this.append(pre, linkStuff.length === 2
23
- ? new index_2.LinkToken(...linkStuff, config, accum)
24
- : new extLink_1.ExtLinkToken(...linkStuff, config, accum), new noinclude_1.NoincludeToken(post, config, accum));
23
+ // @ts-expect-error abstract class
24
+ ? new index_3.LinkToken(...linkStuff, config, accum)
25
+ // @ts-expect-error abstract class
26
+ : new extLink_1.ExtLinkToken(...linkStuff, config, accum),
27
+ // @ts-expect-error abstract class
28
+ new noinclude_1.NoincludeToken(post, config, accum));
25
29
  }
26
30
  }
27
31
  exports.ImagemapLinkToken = ImagemapLinkToken;
@@ -1,5 +1,5 @@
1
1
  import { BuildMethod } from '../util/constants';
2
- import * as Parser from '../index';
2
+ import Parser from '../index';
3
3
  import { AstElement } from '../lib/element';
4
4
  import { AstText } from '../lib/text';
5
5
  import type { Title } from '../lib/title';
@@ -10,6 +10,7 @@ import type { TokenTypes } from '../util/constants';
10
10
  * @classdesc `{childNodes: ...(AstText|Token)}`
11
11
  */
12
12
  export declare class Token extends AstElement {
13
+ #private;
13
14
  type: TokenTypes;
14
15
  /** @class */
15
16
  constructor(wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
package/dist/src/index.js CHANGED
@@ -15,33 +15,33 @@
15
15
  // 10. 段落和列表,参见BlockLevelPass::execute
16
16
  // 11. 转换,参见LanguageConverter::recursiveConvertTopLevel
17
17
  // \0\d+.\x7F标记Token:
18
- // e: ExtToken
19
- // a: AttributeToken
20
- // c: CommentToken、NoIncludeToken和IncludeToken
21
18
  // !: `{{!}}`专用
22
19
  // {: `{{(!}}`专用
23
20
  // }: `{{!)}}`专用
24
21
  // -: `{{!-}}`专用
25
22
  // +: `{{!!}}`专用
26
23
  // ~: `{{=}}`专用
27
- // s: `{{{|subst:}}}`
28
- // m: `{{fullurl:}}`、`{{canonicalurl:}}`或`{{filepath:}}`
29
- // t: ArgToken或TranscludeToken
30
- // h: HeadingToken
31
- // x: HtmlToken
24
+ // a: AttributeToken
32
25
  // b: TableToken
33
- // r: HrToken
34
- // u: DoubleUnderscoreToken
26
+ // c: CommentToken、NoIncludeToken和IncludeToken
27
+ // d: ListToken
28
+ // e: ExtToken
29
+ // h: HeadingToken
35
30
  // l: LinkToken
31
+ // m: `{{fullurl:}}`、`{{canonicalurl:}}`或`{{filepath:}}`
36
32
  // q: QuoteToken
37
- // w: ExtLinkToken
38
- // d: ListToken
33
+ // r: HrToken
34
+ // s: `{{{|subst:}}}`
35
+ // t: ArgToken或TranscludeToken
36
+ // u: DoubleUnderscoreToken
39
37
  // v: ConverterToken
38
+ // w: ExtLinkToken
39
+ // x: HtmlToken
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.Token = void 0;
42
42
  const string_1 = require("../util/string");
43
43
  const constants_1 = require("../util/constants");
44
- const Parser = require("../index");
44
+ const index_1 = require("../index");
45
45
  const element_1 = require("../lib/element");
46
46
  const text_1 = require("../lib/text");
47
47
  /**
@@ -57,7 +57,7 @@ class Token extends element_1.AstElement {
57
57
  #accum;
58
58
  #include;
59
59
  /** @class */
60
- constructor(wikitext, config = Parser.getConfig(), accum = [], acceptable) {
60
+ constructor(wikitext, config = index_1.default.getConfig(), accum = [], acceptable) {
61
61
  super();
62
62
  if (typeof wikitext === 'string') {
63
63
  this.insertAt(wikitext);
@@ -315,7 +315,7 @@ class Token extends element_1.AstElement {
315
315
  * @param selfLink 是否允许selfLink
316
316
  */
317
317
  normalizeTitle(title, defaultNs = 0, halfParsed = false, decode = false, selfLink = false) {
318
- return Parser.normalizeTitle(title, defaultNs, this.#include, this.#config, halfParsed, decode, selfLink);
318
+ return index_1.default.normalizeTitle(title, defaultNs, this.#include, this.#config, halfParsed, decode, selfLink);
319
319
  }
320
320
  }
321
321
  exports.Token = Token;
@@ -1,4 +1,4 @@
1
- import * as Parser from '../../index';
1
+ import Parser from '../../index';
2
2
  import { Token } from '../index';
3
3
  import { AtomToken } from '../atom';
4
4
  import type { LintError } from '../../base';
@@ -8,6 +8,7 @@ import type { Title } from '../../lib/title';
8
8
  * @classdesc `{childNodes: [AtomToken, ...Token]}`
9
9
  */
10
10
  export declare abstract class LinkBaseToken extends Token {
11
+ #private;
11
12
  type: 'link' | 'category' | 'file' | 'gallery-image' | 'imagemap-image';
12
13
  readonly childNodes: readonly [AtomToken, ...Token[]];
13
14
  abstract get firstChild(): AtomToken;
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LinkBaseToken = void 0;
4
4
  const lint_1 = require("../../util/lint");
5
5
  const constants_1 = require("../../util/constants");
6
- const Parser = require("../../index");
7
- const index_1 = require("../index");
6
+ const index_1 = require("../../index");
7
+ const index_2 = require("../index");
8
8
  const atom_1 = require("../atom");
9
9
  /**
10
10
  * 内链
11
11
  * @classdesc `{childNodes: [AtomToken, ...Token]}`
12
12
  */
13
- class LinkBaseToken extends index_1.Token {
13
+ class LinkBaseToken extends index_2.Token {
14
14
  #bracket = true;
15
15
  #delimiter;
16
16
  #title;
@@ -19,11 +19,11 @@ class LinkBaseToken extends index_1.Token {
19
19
  * @param linkText 链接显示文字
20
20
  * @param delimiter `|`
21
21
  */
22
- constructor(link, linkText, config = Parser.getConfig(), accum = [], delimiter = '|') {
22
+ constructor(link, linkText, config = index_1.default.getConfig(), accum = [], delimiter = '|') {
23
23
  super(undefined, config, accum, {});
24
24
  this.insertAt(new atom_1.AtomToken(link, 'link-target', config, accum, {}));
25
25
  if (linkText !== undefined) {
26
- const inner = new index_1.Token(linkText, config, accum, {});
26
+ const inner = new index_2.Token(linkText, config, accum, {});
27
27
  inner.type = 'link-text';
28
28
  inner.setAttribute('stage', constants_1.MAX_STAGE - 1);
29
29
  this.insertAt(inner);
@@ -50,11 +50,9 @@ class LinkBaseToken extends index_1.Token {
50
50
  }
51
51
  }
52
52
  /** @private */
53
- toString(omit) {
54
- const str = super.toString(omit, this.#delimiter);
55
- return this.#bracket
56
- ? `[[${str}]]`
57
- : str;
53
+ toString() {
54
+ const str = super.toString(this.#delimiter);
55
+ return this.#bracket ? `[[${str}]]` : str;
58
56
  }
59
57
  /** @override */
60
58
  text() {
@@ -84,7 +82,8 @@ class LinkBaseToken extends index_1.Token {
84
82
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
85
83
  errors.push((0, lint_1.generateForChild)(target, rect, 'unnecessary URL encoding in an internal link'));
86
84
  }
87
- if ((linkType === 'link' || linkType === 'category') && linkText?.childNodes.some(({ type, data }) => type === 'text' && data.includes('|'))) {
85
+ if ((linkType === 'link' || linkType === 'category')
86
+ && linkText?.childNodes.some(({ type, data }) => type === 'text' && data.includes('|'))) {
88
87
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
89
88
  errors.push((0, lint_1.generateForChild)(linkText, rect, 'additional "|" in the link text', 'warning'));
90
89
  }
@@ -1,5 +1,5 @@
1
1
  import { LinkBaseToken } from './base';
2
2
  /** 分类 */
3
- export declare class CategoryToken extends LinkBaseToken {
3
+ export declare abstract class CategoryToken extends LinkBaseToken {
4
4
  readonly type = "category";
5
5
  }
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CategoryToken = void 0;
4
4
  const base_1 = require("./base");
5
5
  /** 分类 */
6
- // @ts-expect-error not implementing all abstract methods
7
6
  class CategoryToken extends base_1.LinkBaseToken {
8
7
  type = 'category';
9
8
  }
@@ -1,4 +1,4 @@
1
- import * as Parser from '../../index';
1
+ import Parser from '../../index';
2
2
  import { LinkBaseToken } from './base';
3
3
  import { ImageParameterToken } from '../imageParameter';
4
4
  import type { LintError } from '../../base';
@@ -7,7 +7,8 @@ import type { Token, AtomToken } from '../../internal';
7
7
  * 图片
8
8
  * @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
9
9
  */
10
- export declare class FileToken extends LinkBaseToken {
10
+ export declare abstract class FileToken extends LinkBaseToken {
11
+ #private;
11
12
  readonly type: 'file' | 'gallery-image' | 'imagemap-image';
12
13
  readonly childNodes: readonly [AtomToken, ...ImageParameterToken[]];
13
14
  abstract get lastChild(): AtomToken | ImageParameterToken;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FileToken = void 0;
4
4
  const string_1 = require("../../util/string");
5
5
  const lint_1 = require("../../util/lint");
6
- const Parser = require("../../index");
6
+ const index_1 = require("../../index");
7
7
  const base_1 = require("./base");
8
8
  const imageParameter_1 = require("../imageParameter");
9
9
  const frame = new Set(['manualthumb', 'frameless', 'framed', 'thumbnail']), horizAlign = new Set(['left', 'right', 'center', 'none']), vertAlign = new Set(['baseline', 'sub', 'super', 'top', 'text-top', 'middle', 'bottom', 'text-bottom']);
@@ -38,7 +38,6 @@ const explode = (start, end, separator, str) => {
38
38
  * 图片
39
39
  * @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
40
40
  */
41
- // @ts-expect-error not implementing all abstract methods
42
41
  class FileToken extends base_1.LinkBaseToken {
43
42
  type = 'file';
44
43
  /**
@@ -46,9 +45,11 @@ class FileToken extends base_1.LinkBaseToken {
46
45
  * @param text 图片参数
47
46
  * @param delimiter `|`
48
47
  */
49
- constructor(link, text, config = Parser.getConfig(), accum = [], delimiter = '|') {
48
+ constructor(link, text, config = index_1.default.getConfig(), accum = [], delimiter = '|') {
50
49
  super(link, undefined, config, accum, delimiter);
51
- this.append(...explode('-{', '}-', '|', text).map(part => new imageParameter_1.ImageParameterToken(part, config, accum)));
50
+ this.append(...explode('-{', '}-', '|', text).map(
51
+ // @ts-expect-error abstract class
52
+ part => new imageParameter_1.ImageParameterToken(part, config, accum)));
52
53
  }
53
54
  /** @override */
54
55
  lint(start = this.getAbsoluteIndex()) {
@@ -71,7 +72,7 @@ class FileToken extends base_1.LinkBaseToken {
71
72
  * @param msg 消息键
72
73
  * @param p1 替换$1
73
74
  */
74
- const generate = (msg, p1) => (arg) => (0, lint_1.generateForChild)(arg, rect, Parser.msg(`${msg} image $1 parameter`, p1));
75
+ const generate = (msg, p1) => (arg) => (0, lint_1.generateForChild)(arg, rect, index_1.default.msg(`${msg} image $1 parameter`, p1));
75
76
  for (const key of keys) {
76
77
  let relevantArgs = args.filter(({ name }) => name === key);
77
78
  if (key === 'caption') {
@@ -1,17 +1,20 @@
1
- import * as Parser from '../../index';
1
+ import Parser from '../../index';
2
2
  import { Token } from '../index';
3
3
  import { FileToken } from './file';
4
4
  import type { Title } from '../../lib/title';
5
5
  import type { LintError } from '../../base';
6
+ declare type GalleryTypes = 'gallery' | 'imagemap';
6
7
  /** 图库图片 */
7
- export declare class GalleryImageToken extends FileToken {
8
- type: 'gallery-image' | 'imagemap-image';
8
+ export declare abstract class GalleryImageToken extends FileToken {
9
+ #private;
10
+ type: `${GalleryTypes}-image`;
9
11
  /**
10
12
  * @param type 图片类型
11
13
  * @param link 图片文件名
12
14
  * @param text 图片参数
13
15
  */
14
- constructor(type: 'gallery' | 'imagemap', link: string, text?: string, config?: Parser.Config, accum?: Token[]);
16
+ constructor(type: GalleryTypes, link: string, text?: string, config?: Parser.Config, accum?: Token[]);
15
17
  /** @override */
16
18
  lint(start?: number): LintError[];
17
19
  }
20
+ export {};
@@ -3,21 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GalleryImageToken = void 0;
4
4
  const lint_1 = require("../../util/lint");
5
5
  const constants_1 = require("../../util/constants");
6
- const Parser = require("../../index");
7
- const index_1 = require("../index");
6
+ const index_1 = require("../../index");
7
+ const index_2 = require("../index");
8
8
  const file_1 = require("./file");
9
9
  /** 图库图片 */
10
- // @ts-expect-error not implementing all abstract methods
11
10
  class GalleryImageToken extends file_1.FileToken {
12
11
  /**
13
12
  * @param type 图片类型
14
13
  * @param link 图片文件名
15
14
  * @param text 图片参数
16
15
  */
17
- constructor(type, link, text, config = Parser.getConfig(), accum = []) {
16
+ constructor(type, link, text, config = index_1.default.getConfig(), accum = []) {
18
17
  let token;
19
18
  if (text !== undefined) {
20
- token = new index_1.Token(text, config, accum);
19
+ token = new index_2.Token(text, config, accum);
21
20
  token.type = 'plain';
22
21
  for (let n = 1; n < constants_1.MAX_STAGE; n++) {
23
22
  token.parseOnce();