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
package/dist/lib/text.js CHANGED
@@ -1,9 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AstText = void 0;
4
- const Parser = require("../index");
4
+ const index_1 = require("../index");
5
5
  const node_1 = require("./node");
6
- const errorSyntax = /<\s*\/?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*\])|((?:^|\])[^[]*?)\]+|https?[:/]\/+/giu, errorSyntaxUrl = /<\s*\/?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*\])|((?:^|\])[^[]*?)\]+/giu, disallowedTags = [
6
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
7
+ /<\s*(?:\/\s*)?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])|((?:^|\])[^[]*?)\]+|https?[:/]\/+/giu;
8
+ const source = '<\\s*(?:\\/\\s*)?([a-z]\\w*)' // 疑似标签
9
+ + '|'
10
+ + '\\{+|\\}+' // `{`、`}`
11
+ + '|'
12
+ + '\\[{2,}|\\[(?![^[]*?\\])' // `[`
13
+ + '|'
14
+ + '((?:^|\\])[^[]*?)\\]+', // `]`
15
+ errorSyntax = new RegExp(`${source}|https?[:/]\\/+`, 'giu'), errorSyntaxUrl = new RegExp(source, 'giu'), regexes = {
16
+ '[': /[[\]]/u,
17
+ '{': /[{}]/u,
18
+ ']': /[[\]](?=[^[\]]*$)/u,
19
+ '}': /[{}](?=[^{}]*$)/u,
20
+ }, disallowedTags = [
7
21
  'html',
8
22
  'head',
9
23
  'style',
@@ -58,10 +72,10 @@ class AstText extends node_1.AstNode {
58
72
  lint(start = this.getAbsoluteIndex()) {
59
73
  const { data, parentNode, nextSibling, previousSibling } = this;
60
74
  const { NowikiToken } = require('../src/nowiki');
61
- const { type, name } = parentNode, nextType = nextSibling?.type, previousType = previousSibling?.type;
75
+ const { type, name } = parentNode, nowiki = name === 'nowiki' || name === 'pre';
62
76
  let errorRegex;
63
77
  if (type === 'ext-inner' && (name === 'pre' || parentNode instanceof NowikiToken)) {
64
- errorRegex = new RegExp(`<\\s*\\/?(${name})\\b`, 'giu');
78
+ errorRegex = new RegExp(`<\\s*(?:\\/\\s*)${nowiki ? '' : '?'}(${name})\\b`, 'giu');
65
79
  }
66
80
  else if (type === 'free-ext-link'
67
81
  || type === 'ext-link-url'
@@ -72,44 +86,73 @@ class AstText extends node_1.AstNode {
72
86
  else {
73
87
  errorRegex = errorSyntax;
74
88
  }
75
- const errors = [], { ext, html } = this.getRootNode().getAttribute('config');
76
- if (data.search(errorRegex) !== -1) {
77
- errorRegex.lastIndex = 0;
78
- const root = this.getRootNode(), { top, left } = root.posFromIndex(start), tags = new Set(['onlyinclude', 'noinclude', 'includeonly', ext, html, disallowedTags].flat(2));
79
- for (let mt = errorRegex.exec(data); mt; mt = errorRegex.exec(data)) {
80
- const [, tag, prefix] = mt;
81
- let { 0: error, index } = mt;
82
- if (prefix && prefix !== ']') {
83
- const { length } = prefix;
84
- index += length;
85
- error = error.slice(length);
89
+ if (data.search(errorRegex) === -1) {
90
+ return [];
91
+ }
92
+ errorRegex.lastIndex = 0;
93
+ const errors = [], nextType = nextSibling?.type, nextName = nextSibling?.name, previousType = previousSibling?.type, root = this.getRootNode(), { ext, html } = root.getAttribute('config'), { top, left } = root.posFromIndex(start), tags = new Set(['onlyinclude', 'noinclude', 'includeonly', ext, html, disallowedTags].flat(2));
94
+ for (let mt = errorRegex.exec(data); mt; mt = errorRegex.exec(data)) {
95
+ const [, tag, prefix] = mt;
96
+ let { 0: error, index } = mt;
97
+ if (prefix && prefix !== ']') {
98
+ const { length } = prefix;
99
+ index += length;
100
+ error = error.slice(length);
101
+ }
102
+ const { 0: char, length } = error;
103
+ if (char === '<' && !tags.has(tag.toLowerCase())
104
+ || char === '['
105
+ && type === 'ext-link-text'
106
+ && (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
107
+ || nextType === 'ext'
108
+ && nextName === 'nowiki'
109
+ && nextSibling.innerText?.includes(']'))) {
110
+ continue;
111
+ }
112
+ else if (char === ']' && (index || length > 1)) {
113
+ errorRegex.lastIndex--;
114
+ }
115
+ const startIndex = start + index, endIndex = startIndex + length, rootStr = String(root), nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], severity = length > 1 && (char !== '<' || !nowiki && /[\s/>]/u.test(nextChar ?? ''))
116
+ || char === '{' && (nextChar === char || previousChar === '-')
117
+ || char === '}' && (previousChar === char || nextChar === '-')
118
+ || char === '[' && (nextChar === char
119
+ || type === 'ext-link-text'
120
+ || !data.slice(index + 1).trim() && nextType === 'free-ext-link')
121
+ || char === ']' && (previousChar === char
122
+ || !data.slice(0, index).trim() && previousType === 'free-ext-link')
123
+ ? 'error'
124
+ : 'warning';
125
+ const leftBracket = char === '{' || char === '[', rightBracket = char === ']' || char === '}';
126
+ if (severity === 'warning' && (leftBracket || rightBracket)) {
127
+ const regex = regexes[char], remains = leftBracket ? data.slice(index + 1) : data.slice(0, index);
128
+ if (char === '{' && regex.exec(remains)?.[0] === '}'
129
+ || char === '}' && regex.exec(remains)?.[0] === '{') {
130
+ continue;
86
131
  }
87
- const startIndex = start + index, lines = data.slice(0, index).split('\n'), startLine = lines.length + top - 1, line = lines[lines.length - 1], startCol = lines.length === 1 ? left + line.length : line.length, { 0: char, length } = error, endIndex = startIndex + length, rootStr = String(root), nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], severity = length > 1 && (char !== '<' || /[\s/>]/u.test(nextChar ?? ''))
88
- || char === '{' && (nextChar === char || previousChar === '-')
89
- || char === '}' && (previousChar === char || nextChar === '-')
90
- || char === '[' && (nextChar === char
91
- || type === 'ext-link-text'
92
- || !data.slice(index + 1).trim() && nextType === 'free-ext-link')
93
- || char === ']' && (previousChar === char
94
- || !data.slice(0, index).trim() && previousType === 'free-ext-link')
95
- ? 'error'
96
- : 'warning';
97
- if (char !== '<' || tags.has(tag.toLowerCase())) {
98
- errors.push({
99
- message: Parser.msg('lonely "$1"', char === 'h' ? error : char),
100
- severity,
101
- startIndex,
102
- endIndex,
103
- startLine,
104
- endLine: startLine,
105
- startCol,
106
- endCol: startCol + length,
107
- });
132
+ else if (!remains.includes(char)) {
133
+ const sibling = leftBracket ? 'nextSibling' : 'previousSibling';
134
+ let cur = this[sibling];
135
+ while (cur && (cur.type !== 'text' || !regex.test(cur.data))) {
136
+ cur = cur[sibling];
137
+ }
138
+ if (cur && regex.exec(cur.data)[0] !== char) {
139
+ continue;
140
+ }
108
141
  }
109
142
  }
110
- return errors;
143
+ const lines = data.slice(0, index).split('\n'), startLine = lines.length + top - 1, line = lines[lines.length - 1], startCol = lines.length === 1 ? left + line.length : line.length;
144
+ errors.push({
145
+ message: index_1.default.msg('lonely "$1"', char === 'h' ? error : char),
146
+ severity,
147
+ startIndex,
148
+ endIndex,
149
+ startLine,
150
+ endLine: startLine,
151
+ startCol,
152
+ endCol: startCol + length,
153
+ });
111
154
  }
112
- return [];
155
+ return errors;
113
156
  }
114
157
  /**
115
158
  * 修改内容
@@ -1,4 +1,4 @@
1
- import * as Parser from '../index';
1
+ import Parser from '../index';
2
2
  /** MediaWiki页面标题对象 */
3
3
  export declare class Title {
4
4
  readonly valid: boolean;
package/dist/lib/title.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Title = void 0;
4
4
  const string_1 = require("../util/string");
5
- const Parser = require("../index");
5
+ const index_1 = require("../index");
6
6
  /** MediaWiki页面标题对象 */
7
7
  class Title {
8
8
  valid;
@@ -16,7 +16,7 @@ class Title {
16
16
  * @param decode 是否需要解码
17
17
  * @param selfLink 是否允许selfLink
18
18
  */
19
- constructor(title, defaultNs = 0, config = Parser.getConfig(), decode = false, selfLink = false) {
19
+ constructor(title, defaultNs = 0, config = index_1.default.getConfig(), decode = false, selfLink = false) {
20
20
  const { nsid, } = config;
21
21
  title = (0, string_1.decodeHtml)(title);
22
22
  if (decode && title.includes('%')) {
@@ -44,8 +44,19 @@ class Title {
44
44
  this.ns = ns;
45
45
  const i = title.indexOf('#');
46
46
  if (i !== -1) {
47
- // eslint-disable-next-line prefer-const
48
47
  let fragment = title.slice(i + 1).trimEnd();
48
+ if (fragment.includes('%')) {
49
+ try {
50
+ fragment = decodeURIComponent(fragment);
51
+ }
52
+ catch { }
53
+ }
54
+ else if (fragment.includes('.')) {
55
+ try {
56
+ fragment = decodeURIComponent(fragment.replace(/\./gu, '%'));
57
+ }
58
+ catch { }
59
+ }
49
60
  this.fragment = fragment;
50
61
  title = title.slice(0, i).trim();
51
62
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseBraces = void 0;
4
4
  const string_1 = require("../util/string");
5
- const Parser = require("../index");
5
+ const index_1 = require("../index");
6
6
  const heading_1 = require("../src/heading");
7
7
  const transclude_1 = require("../src/transclude");
8
8
  const arg_1 = require("../src/arg");
@@ -13,7 +13,7 @@ const arg_1 = require("../src/arg");
13
13
  * @param accum
14
14
  * @throws TranscludeToken.constructor()
15
15
  */
16
- const parseBraces = (wikitext, config = Parser.getConfig(), accum = []) => {
16
+ const parseBraces = (wikitext, config = index_1.default.getConfig(), accum = []) => {
17
17
  const source = `${config.excludes?.includes('heading') ? '' : '^(\0\\d+c\x7F)*={1,6}|'}\\[\\[|\\{{2,}|-\\{(?!\\{)`, { parserFunction: [, , , subst] } = config, stack = [], closes = { '=': '\n', '{': '\\}{2,}|\\|', '-': '\\}-', '[': '\\]\\]' }, marks = new Map([['!', '!'], ['!!', '+'], ['(!', '{'], ['!)', '}'], ['!-', '-'], ['=', '~']]);
18
18
  let regex = new RegExp(source, 'gmu'), mt = regex.exec(wikitext), moreBraces = wikitext.includes('}}'), lastIndex;
19
19
  while (mt
@@ -43,6 +43,7 @@ const parseBraces = (wikitext, config = Parser.getConfig(), accum = []) => {
43
43
  if (rmt) {
44
44
  wikitext = `${wikitext.slice(0, index)}\0${accum.length}h\x7F${wikitext.slice(curIndex)}`;
45
45
  lastIndex = index + 4 + String(accum.length).length;
46
+ // @ts-expect-error abstract class
46
47
  new heading_1.HeadingToken(rmt[1].length, rmt.slice(2), config, accum);
47
48
  }
48
49
  }
@@ -64,6 +65,7 @@ const parseBraces = (wikitext, config = Parser.getConfig(), accum = []) => {
64
65
  let skip = false, ch = 't';
65
66
  if (close.length === 3) {
66
67
  const argParts = parts.map(part => part.join('=')), str = argParts.length > 1 && (0, string_1.removeComment)(argParts[1]).trim();
68
+ // @ts-expect-error abstract class
67
69
  new arg_1.ArgToken(argParts, config, accum);
68
70
  if (str && str.endsWith(':') && subst.includes(str.slice(0, -1).toLowerCase())) {
69
71
  ch = 's';
@@ -71,6 +73,7 @@ const parseBraces = (wikitext, config = Parser.getConfig(), accum = []) => {
71
73
  }
72
74
  else {
73
75
  try {
76
+ // @ts-expect-error abstract class
74
77
  new transclude_1.TranscludeToken(parts[0][0], parts.slice(1), config, accum);
75
78
  const name = (0, string_1.removeComment)(parts[0][0]).trim();
76
79
  if (marks.has(name)) {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseCommentAndExt = void 0;
4
- const Parser = require("../index");
4
+ const index_1 = require("../index");
5
5
  const onlyinclude_1 = require("../src/onlyinclude");
6
6
  const noinclude_1 = require("../src/nowiki/noinclude");
7
7
  const include_1 = require("../src/tagPair/include");
@@ -14,7 +14,7 @@ const comment_1 = require("../src/nowiki/comment");
14
14
  * @param accum
15
15
  * @param includeOnly 是否嵌入
16
16
  */
17
- const parseCommentAndExt = (wikitext, config = Parser.getConfig(), accum = [], includeOnly = false) => {
17
+ const parseCommentAndExt = (wikitext, config = index_1.default.getConfig(), accum = [], includeOnly = false) => {
18
18
  const onlyincludeLeft = '<onlyinclude>', onlyincludeRight = '</onlyinclude>', { length } = onlyincludeLeft;
19
19
  /** 更新`<onlyinclude>`和`</onlyinclude>`的位置 */
20
20
  const update = () => {
@@ -30,6 +30,7 @@ const parseCommentAndExt = (wikitext, config = Parser.getConfig(), accum = [], i
30
30
  * @param text 未被包裹的内容
31
31
  */
32
32
  const noinclude = (text) => {
33
+ // @ts-expect-error abstract class
33
34
  new noinclude_1.NoincludeToken(text, config, accum);
34
35
  str += `\0${accum.length - 1}c\x7F`;
35
36
  };
@@ -65,16 +66,20 @@ const parseCommentAndExt = (wikitext, config = Parser.getConfig(), accum = [], i
65
66
  return wikitext.replace(regex, (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
66
67
  const str = `\0${accum.length}${name ? 'e' : 'c'}\x7F`;
67
68
  if (name) {
69
+ // @ts-expect-error abstract class
68
70
  new ext_1.ExtToken(name, attr, inner, closing, config, accum);
69
71
  }
70
72
  else if (substr.startsWith('<!--')) {
71
73
  const closed = substr.endsWith('-->');
74
+ // @ts-expect-error abstract class
72
75
  new comment_1.CommentToken(substr.slice(4, closed ? -3 : undefined), closed, config, accum);
73
76
  }
74
77
  else if (include) {
78
+ // @ts-expect-error abstract class
75
79
  new include_1.IncludeToken(include, includeAttr, includeInner, includeClosing, config, accum);
76
80
  }
77
81
  else {
82
+ // @ts-expect-error abstract class
78
83
  new noinclude_1.NoincludeToken(substr, config, accum);
79
84
  }
80
85
  return str;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseConverter = void 0;
4
- const Parser = require("../index");
4
+ const index_1 = require("../index");
5
5
  const converter_1 = require("../src/converter");
6
6
  /**
7
7
  * 解析语言变体转换
@@ -9,7 +9,7 @@ const converter_1 = require("../src/converter");
9
9
  * @param config
10
10
  * @param accum
11
11
  */
12
- const parseConverter = (text, config = Parser.getConfig(), accum = []) => {
12
+ const parseConverter = (text, config = index_1.default.getConfig(), accum = []) => {
13
13
  const regex1 = /-\{/gu, regex2 = /-\{|\}-/gu, stack = [];
14
14
  let regex = regex1, mt = regex.exec(text);
15
15
  while (mt) {
@@ -19,6 +19,7 @@ const parseConverter = (text, config = Parser.getConfig(), accum = []) => {
19
19
  /;(?=(?:[^;]*?=>)?\s*foo\s*:|(?:\s|\0\d+c\x7F)*$)/u;
20
20
  const top = stack.pop(), { length } = accum, str = text.slice(top.index + 2, index), i = str.indexOf('|'), [flags, raw] = i === -1 ? [[], str] : [str.slice(0, i).split(';'), str.slice(i + 1)], temp = raw.replace(/(&[#a-z\d]+);/giu, '$1\x01'), variants = `(?:${config.variants.join('|')})`, rules = temp.split(new RegExp(`;(?=(?:[^;]*?=>)?\\s*${variants}\\s*:|(?:\\s|\0\\d+c\x7F)*$)`, 'u'))
21
21
  .map(rule => rule.replace(/\x01/gu, ';'));
22
+ // @ts-expect-error abstract class
22
23
  new converter_1.ConverterToken(flags, rules, config, accum);
23
24
  text = `${text.slice(0, top.index)}\0${length}v\x7F${text.slice(index + 2)}`;
24
25
  if (stack.length === 0) {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseExternalLinks = void 0;
4
4
  const string_1 = require("../util/string");
5
- const Parser = require("../index");
5
+ const index_1 = require("../index");
6
6
  const extLink_1 = require("../src/extLink");
7
7
  /**
8
8
  * 解析外部链接
@@ -10,7 +10,7 @@ const extLink_1 = require("../src/extLink");
10
10
  * @param config
11
11
  * @param accum
12
12
  */
13
- const parseExternalLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
13
+ const parseExternalLinks = (wikitext, config = index_1.default.getConfig(), accum = []) => {
14
14
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
15
15
  /\[((?:\[[\da-f:.]+\]|[^[\]\t\n\p{Zs}])[^[\]\t\n\p{Zs}]*(?=[[\]\t\p{Zs}]|\0\d))(\p{Zs}*(?=\P{Zs}))([^\]\n]*)\]/giu;
16
16
  const regex = new RegExp(`\\[((?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\\d+m\x7F)${string_1.extUrlChar}(?=[[\\]<>"\\t\\p{Zs}]|\0\\d))`
@@ -22,6 +22,7 @@ const parseExternalLinks = (wikitext, config = Parser.getConfig(), accum = []) =
22
22
  space = '';
23
23
  text = `${url.slice(mt.index)}${space}${text}`;
24
24
  }
25
+ // @ts-expect-error abstract class
25
26
  new extLink_1.ExtLinkToken(url, space, text, config, accum);
26
27
  return `\0${length}w\x7F`;
27
28
  });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseHrAndDoubleUnderscore = void 0;
4
- const Parser = require("../index");
4
+ const index_1 = require("../index");
5
5
  const hr_1 = require("../src/nowiki/hr");
6
6
  const doubleUnderscore_1 = require("../src/nowiki/doubleUnderscore");
7
7
  const heading_1 = require("../src/heading");
@@ -11,23 +11,26 @@ const heading_1 = require("../src/heading");
11
11
  * @param config
12
12
  * @param accum
13
13
  */
14
- const parseHrAndDoubleUnderscore = ({ firstChild: { data }, type, name }, config = Parser.getConfig(), accum = []) => {
14
+ const parseHrAndDoubleUnderscore = ({ firstChild: { data }, type, name }, config = index_1.default.getConfig(), accum = []) => {
15
15
  const { doubleUnderscore } = config, insensitive = new Set(doubleUnderscore[0]), sensitive = new Set(doubleUnderscore[1]);
16
16
  if (type !== 'root' && (type !== 'ext-inner' || name !== 'poem')) {
17
17
  data = `\0${data}`;
18
18
  }
19
19
  data = data.replace(/^((?:\0\d+c\x7F)*)(-{4,})/gmu, (_, lead, m) => {
20
+ // @ts-expect-error abstract class
20
21
  new hr_1.HrToken(m, config, accum);
21
22
  return `${lead}\0${accum.length - 1}r\x7F`;
22
23
  }).replace(new RegExp(`__(${doubleUnderscore.flat().join('|')})__`, 'giu'), (m, p1) => {
23
24
  const caseSensitive = sensitive.has(p1);
24
25
  if (caseSensitive || insensitive.has(p1.toLowerCase())) {
26
+ // @ts-expect-error abstract class
25
27
  new doubleUnderscore_1.DoubleUnderscoreToken(p1, caseSensitive, config, accum);
26
28
  return `\0${accum.length - 1}u\x7F`;
27
29
  }
28
30
  return m;
29
31
  }).replace(/^((?:\0\d+c\x7F)*)(={1,6})(.+)\2((?:[^\S\n]|\0\d+c\x7F)*)$/gmu, (_, lead, equals, heading, trail) => {
30
32
  const text = `${lead}\0${accum.length}h\x7F`;
33
+ // @ts-expect-error abstract class
31
34
  new heading_1.HeadingToken(equals.length, [heading, trail], config, accum);
32
35
  return text;
33
36
  });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseHtml = void 0;
4
- const Parser = require("../index");
4
+ const index_1 = require("../index");
5
5
  const attributes_1 = require("../src/attributes");
6
6
  const html_1 = require("../src/html");
7
7
  /**
@@ -10,7 +10,7 @@ const html_1 = require("../src/html");
10
10
  * @param config
11
11
  * @param accum
12
12
  */
13
- const parseHtml = (wikitext, config = Parser.getConfig(), accum = []) => {
13
+ const parseHtml = (wikitext, config = index_1.default.getConfig(), accum = []) => {
14
14
  const regex = /^(\/?)([a-z][^\s/>]*)((?:\s|\/(?!>))[^>]*?)?(\/?>)([^<]*)$/iu, elements = new Set(config.html.flat()), bits = wikitext.split('<');
15
15
  let text = bits.shift();
16
16
  for (const x of bits) {
@@ -19,7 +19,9 @@ const parseHtml = (wikitext, config = Parser.getConfig(), accum = []) => {
19
19
  text += `<${x}`;
20
20
  continue;
21
21
  }
22
- const [, slash, , params = '', brace, rest] = mt, attr = new attributes_1.AttributesToken(params, 'html-attrs', name, config, accum), itemprop = attr.getAttr('itemprop');
22
+ const [, slash, , params = '', brace, rest] = mt,
23
+ // @ts-expect-error abstract class
24
+ attr = new attributes_1.AttributesToken(params, 'html-attrs', name, config, accum), itemprop = attr.getAttr('itemprop');
23
25
  if (name === 'meta' && (itemprop === undefined || attr.getAttr('content') === undefined)
24
26
  || name === 'link' && (itemprop === undefined || attr.getAttr('href') === undefined)) {
25
27
  text += `<${x}`;
@@ -27,6 +29,7 @@ const parseHtml = (wikitext, config = Parser.getConfig(), accum = []) => {
27
29
  continue;
28
30
  }
29
31
  text += `\0${accum.length}x\x7F${rest}`;
32
+ // @ts-expect-error abstract class
30
33
  new html_1.HtmlToken(t, attr, slash === '/', brace === '/>', config, accum);
31
34
  }
32
35
  return text;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseLinks = void 0;
4
- const Parser = require("../index");
5
- const index_1 = require("../src/link/index");
4
+ const index_1 = require("../index");
5
+ const index_2 = require("../src/link/index");
6
6
  const file_1 = require("../src/link/file");
7
7
  const category_1 = require("../src/link/category");
8
8
  /**
@@ -11,7 +11,7 @@ const category_1 = require("../src/link/category");
11
11
  * @param config
12
12
  * @param accum
13
13
  */
14
- const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
14
+ const parseLinks = (wikitext, config = index_1.default.getConfig(), accum = []) => {
15
15
  const { parseQuotes } = require('./quotes');
16
16
  const regex = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)(.*?[^\]]))?\]\](.*)$/su, regexImg = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(\||\0\d+!\x7F)(.*)$/su, regexExt = new RegExp(`^\\s*(?:${config.protocol}|//)`, 'iu'), bits = wikitext.split('[[');
17
17
  let s = bits.shift();
@@ -41,7 +41,7 @@ const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
41
41
  s += `[[${x}`;
42
42
  continue;
43
43
  }
44
- const title = Parser.normalizeTitle(link, 0, false, config, true, true, true), { ns, valid, } = title;
44
+ const title = index_1.default.normalizeTitle(link, 0, false, config, true, true, true), { ns, valid, } = title;
45
45
  if (!valid) {
46
46
  s += `[[${x}`;
47
47
  continue;
@@ -76,7 +76,7 @@ const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
76
76
  }
77
77
  text &&= parseQuotes(text, config, accum);
78
78
  s += `\0${accum.length}l\x7F${after}`;
79
- let SomeLinkToken = index_1.LinkToken;
79
+ let SomeLinkToken = index_2.LinkToken;
80
80
  if (!force) {
81
81
  if (ns === 6) {
82
82
  SomeLinkToken = file_1.FileToken;
@@ -85,6 +85,7 @@ const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
85
85
  SomeLinkToken = category_1.CategoryToken;
86
86
  }
87
87
  }
88
+ // @ts-expect-error abstract class
88
89
  new SomeLinkToken(link, text, config, accum, delimiter);
89
90
  }
90
91
  return s;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseList = void 0;
4
- const Parser = require("../index");
4
+ const index_1 = require("../index");
5
5
  const list_1 = require("../src/nowiki/list");
6
6
  const dd_1 = require("../src/nowiki/dd");
7
7
  /**
@@ -10,13 +10,14 @@ const dd_1 = require("../src/nowiki/dd");
10
10
  * @param config
11
11
  * @param accum
12
12
  */
13
- const parseList = (wikitext, config = Parser.getConfig(), accum = []) => {
13
+ const parseList = (wikitext, config = index_1.default.getConfig(), accum = []) => {
14
14
  const mt = /^((?:\0\d+c\x7F)*)([;:*#]+)/u.exec(wikitext);
15
15
  if (!mt) {
16
16
  return wikitext;
17
17
  }
18
18
  const [total, comment, prefix] = mt;
19
19
  let text = `${comment}\0${accum.length}d\x7F${wikitext.slice(total.length)}`, dt = prefix.split(';').length - 1;
20
+ // @ts-expect-error abstract class
20
21
  new list_1.ListToken(prefix, config, accum);
21
22
  if (!dt) {
22
23
  return text;
@@ -28,6 +29,7 @@ const parseList = (wikitext, config = Parser.getConfig(), accum = []) => {
28
29
  * @param index 起点
29
30
  */
30
31
  const dd = (syntax, index) => {
32
+ // @ts-expect-error abstract class
31
33
  new dd_1.DdToken(syntax, config, accum);
32
34
  return `${text.slice(0, index)}\0${accum.length - 1}d\x7F${text.slice(index + syntax.length)}`;
33
35
  };
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMagicLinks = void 0;
4
4
  const string_1 = require("../util/string");
5
- const Parser = require("../index");
5
+ const index_1 = require("../index");
6
6
  const magicLink_1 = require("../src/magicLink");
7
7
  /**
8
8
  * 解析自由外链
@@ -10,7 +10,7 @@ const magicLink_1 = require("../src/magicLink");
10
10
  * @param config
11
11
  * @param accum
12
12
  */
13
- const parseMagicLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
13
+ const parseMagicLinks = (wikitext, config = index_1.default.getConfig(), accum = []) => {
14
14
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
15
15
  /(^|[^\p{L}\d_])((?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])(?:[^[\]<>"\0\t\n\p{Zs}]|\0\d+c\x7F)*)/giu;
16
16
  const regex = new RegExp(`(^|[^\\p{L}\\d_])(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})`, 'giu');
@@ -33,6 +33,7 @@ const parseMagicLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
33
33
  if (trail.length >= p1.length) {
34
34
  return m;
35
35
  }
36
+ // @ts-expect-error abstract class
36
37
  new magicLink_1.MagicLinkToken(url, false, config, accum);
37
38
  return `${lead}\0${accum.length - 1}w\x7F${trail}`;
38
39
  });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseQuotes = void 0;
4
- const Parser = require("../index");
4
+ const index_1 = require("../index");
5
5
  const quote_1 = require("../src/nowiki/quote");
6
6
  /**
7
7
  * 解析单引号
@@ -9,14 +9,14 @@ const quote_1 = require("../src/nowiki/quote");
9
9
  * @param config
10
10
  * @param accum
11
11
  */
12
- const parseQuotes = (wikitext, config = Parser.getConfig(), accum = []) => {
12
+ const parseQuotes = (wikitext, config = index_1.default.getConfig(), accum = []) => {
13
13
  const arr = wikitext.split(/('{2,})/u), { length } = arr;
14
14
  if (length === 1) {
15
15
  return wikitext;
16
16
  }
17
17
  let nBold = 0, nItalic = 0, firstSingle, firstMulti, firstSpace;
18
18
  for (let i = 1; i < length; i += 2) {
19
- const { length: len } = arr[i];
19
+ const len = arr[i].length;
20
20
  switch (len) {
21
21
  case 2:
22
22
  nItalic++;
@@ -57,6 +57,7 @@ const parseQuotes = (wikitext, config = Parser.getConfig(), accum = []) => {
57
57
  }
58
58
  }
59
59
  for (let i = 1; i < length; i += 2) {
60
+ // @ts-expect-error abstract class
60
61
  new quote_1.QuoteToken(arr[i], config, accum);
61
62
  arr[i] = `\0${accum.length - 1}q\x7F`;
62
63
  }
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseTable = void 0;
4
- const Parser = require("../index");
5
- const index_1 = require("../src/index");
6
- const index_2 = require("../src/table/index");
4
+ const index_1 = require("../index");
5
+ const index_2 = require("../src/index");
6
+ const index_3 = require("../src/table/index");
7
7
  const tr_1 = require("../src/table/tr");
8
8
  const td_1 = require("../src/table/td");
9
9
  const dd_1 = require("../src/nowiki/dd");
@@ -11,14 +11,14 @@ const dd_1 = require("../src/nowiki/dd");
11
11
  * 判断是否为表格行或表格
12
12
  * @param token 表格节点
13
13
  */
14
- const isTr = (token) => token.lastChild.constructor !== index_1.Token;
14
+ const isTr = (token) => token.lastChild.constructor !== index_2.Token;
15
15
  /**
16
16
  * 解析表格,注意`tr`和`td`包含开头的换行
17
17
  * @param {Token & {firstChild: AstText}} root 根节点
18
18
  * @param config
19
19
  * @param accum
20
20
  */
21
- const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getConfig(), accum = []) => {
21
+ const parseTable = ({ firstChild: { data }, type, name }, config = index_1.default.getConfig(), accum = []) => {
22
22
  const stack = [], lines = data.split('\n');
23
23
  let out = type === 'root' || type === 'parameter-value' || type === 'ext-inner' && name === 'poem'
24
24
  ? ''
@@ -35,7 +35,7 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
35
35
  }
36
36
  const { lastChild } = topToken;
37
37
  if (isTr(topToken)) {
38
- const token = new index_1.Token(str, config, accum);
38
+ const token = new index_2.Token(str, config, accum);
39
39
  token.type = 'table-inter';
40
40
  token.setAttribute('stage', 3);
41
41
  topToken.insertAt(token);
@@ -56,10 +56,12 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
56
56
  }
57
57
  const [, indent, moreSpaces, tableSyntax, attr] = matchesStart;
58
58
  if (indent) {
59
+ // @ts-expect-error abstract class
59
60
  new dd_1.DdToken(indent, config, accum);
60
61
  }
61
62
  push(`\n${spaces}${indent && `\0${accum.length - 1}d\x7F`}${moreSpaces}\0${accum.length}b\x7F`, top);
62
- stack.push(...top ? [top] : [], new index_2.TableToken(tableSyntax, attr, config, accum));
63
+ // @ts-expect-error abstract class
64
+ stack.push(...top ? [top] : [], new index_3.TableToken(tableSyntax, attr, config, accum));
63
65
  continue;
64
66
  }
65
67
  else if (!top) {
@@ -87,6 +89,7 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
87
89
  if (top.type === 'tr') {
88
90
  top = stack.pop();
89
91
  }
92
+ // @ts-expect-error abstract class
90
93
  const tr = new tr_1.TrToken(`\n${spaces}${row}`, attr, config, accum);
91
94
  stack.push(top, tr);
92
95
  top.insertAt(tr);
@@ -100,6 +103,7 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
100
103
  * @param tr 当前表格行
101
104
  */
102
105
  const createTd = (tr) => {
106
+ // @ts-expect-error abstract class
103
107
  const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex, mt?.index), config, accum);
104
108
  tr.insertAt(td);
105
109
  return td;
package/dist/src/arg.d.ts CHANGED
@@ -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 { HiddenToken } from './hidden';
@@ -7,7 +7,7 @@ import type { LintError } from '../base';
7
7
  * `{{{}}}`包裹的参数
8
8
  * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
9
9
  */
10
- export declare class ArgToken extends Token {
10
+ export declare abstract class ArgToken extends Token {
11
11
  readonly type = "arg";
12
12
  readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token, ...HiddenToken[]];
13
13
  abstract get firstChild(): AtomToken;