wikilint 2.4.1 → 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 (95) hide show
  1. package/dist/index.js +3 -1
  2. package/dist/lib/element.d.ts +0 -5
  3. package/dist/lib/element.js +2 -27
  4. package/dist/lib/text.js +74 -40
  5. package/dist/lib/title.d.ts +1 -1
  6. package/dist/lib/title.js +14 -3
  7. package/dist/parser/braces.js +2 -2
  8. package/dist/parser/commentAndExt.js +2 -2
  9. package/dist/parser/converter.js +2 -2
  10. package/dist/parser/externalLinks.js +2 -2
  11. package/dist/parser/hrAndDoubleUnderscore.js +2 -2
  12. package/dist/parser/html.js +2 -2
  13. package/dist/parser/links.js +5 -5
  14. package/dist/parser/list.js +2 -2
  15. package/dist/parser/magicLinks.js +2 -2
  16. package/dist/parser/quotes.js +3 -3
  17. package/dist/parser/table.js +7 -7
  18. package/dist/src/arg.d.ts +1 -1
  19. package/dist/src/arg.js +7 -7
  20. package/dist/src/atom.d.ts +1 -1
  21. package/dist/src/atom.js +4 -4
  22. package/dist/src/attribute.d.ts +1 -1
  23. package/dist/src/attribute.js +41 -12
  24. package/dist/src/attributes.d.ts +1 -1
  25. package/dist/src/attributes.js +5 -5
  26. package/dist/src/converter.d.ts +1 -1
  27. package/dist/src/converter.js +6 -6
  28. package/dist/src/converterFlags.d.ts +1 -1
  29. package/dist/src/converterFlags.js +7 -7
  30. package/dist/src/converterRule.d.ts +1 -1
  31. package/dist/src/converterRule.js +7 -7
  32. package/dist/src/extLink.d.ts +1 -1
  33. package/dist/src/extLink.js +8 -8
  34. package/dist/src/gallery.d.ts +1 -1
  35. package/dist/src/gallery.js +7 -7
  36. package/dist/src/heading.d.ts +1 -1
  37. package/dist/src/heading.js +10 -10
  38. package/dist/src/html.d.ts +1 -1
  39. package/dist/src/html.js +10 -10
  40. package/dist/src/imageParameter.d.ts +1 -1
  41. package/dist/src/imageParameter.js +8 -10
  42. package/dist/src/imagemap.d.ts +1 -1
  43. package/dist/src/imagemap.js +6 -6
  44. package/dist/src/imagemapLink.d.ts +1 -1
  45. package/dist/src/imagemapLink.js +6 -6
  46. package/dist/src/index.d.ts +1 -1
  47. package/dist/src/index.js +3 -3
  48. package/dist/src/link/base.d.ts +1 -1
  49. package/dist/src/link/base.js +10 -11
  50. package/dist/src/link/file.d.ts +1 -1
  51. package/dist/src/link/file.js +3 -3
  52. package/dist/src/link/galleryImage.d.ts +1 -1
  53. package/dist/src/link/galleryImage.js +4 -4
  54. package/dist/src/magicLink.d.ts +1 -1
  55. package/dist/src/magicLink.js +6 -6
  56. package/dist/src/nested.d.ts +1 -1
  57. package/dist/src/nested.js +5 -5
  58. package/dist/src/nowiki/base.d.ts +1 -1
  59. package/dist/src/nowiki/base.js +4 -4
  60. package/dist/src/nowiki/comment.d.ts +1 -1
  61. package/dist/src/nowiki/comment.js +4 -4
  62. package/dist/src/nowiki/doubleUnderscore.d.ts +1 -1
  63. package/dist/src/nowiki/doubleUnderscore.js +3 -3
  64. package/dist/src/nowiki/index.js +2 -2
  65. package/dist/src/nowiki/quote.js +3 -3
  66. package/dist/src/onlyinclude.js +1 -1
  67. package/dist/src/paramTag/index.d.ts +1 -1
  68. package/dist/src/paramTag/index.js +7 -7
  69. package/dist/src/paramTag/inputbox.d.ts +1 -1
  70. package/dist/src/paramTag/inputbox.js +4 -4
  71. package/dist/src/parameter.d.ts +1 -1
  72. package/dist/src/parameter.js +9 -13
  73. package/dist/src/pre.d.ts +1 -1
  74. package/dist/src/pre.js +4 -4
  75. package/dist/src/syntax.d.ts +1 -1
  76. package/dist/src/syntax.js +4 -4
  77. package/dist/src/table/base.d.ts +1 -1
  78. package/dist/src/table/base.js +4 -4
  79. package/dist/src/table/index.d.ts +1 -1
  80. package/dist/src/table/index.js +3 -3
  81. package/dist/src/table/td.d.ts +1 -1
  82. package/dist/src/table/td.js +6 -6
  83. package/dist/src/table/tr.d.ts +1 -1
  84. package/dist/src/table/tr.js +2 -2
  85. package/dist/src/tagPair/ext.d.ts +1 -1
  86. package/dist/src/tagPair/ext.js +6 -6
  87. package/dist/src/tagPair/include.d.ts +1 -1
  88. package/dist/src/tagPair/include.js +5 -5
  89. package/dist/src/tagPair/index.d.ts +1 -1
  90. package/dist/src/tagPair/index.js +7 -7
  91. package/dist/src/transclude.d.ts +1 -1
  92. package/dist/src/transclude.js +7 -7
  93. package/dist/util/diff.js +11 -1
  94. package/dist/util/lint.js +2 -2
  95. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -68,7 +68,9 @@ const Parser = {
68
68
  return root;
69
69
  },
70
70
  };
71
- const def = {}, enumerable = new Set([
71
+ const def = {
72
+ default: { value: Parser },
73
+ }, enumerable = new Set([
72
74
  'normalizeTitle',
73
75
  'parse',
74
76
  ]);
@@ -31,11 +31,6 @@ export declare abstract class AstElement extends AstNode {
31
31
  * @param selector 选择器
32
32
  */
33
33
  closest<T = Token>(selector: string): T | undefined;
34
- /**
35
- * 符合选择器的所有后代节点
36
- * @param selector 选择器
37
- */
38
- querySelectorAll<T = Token>(selector: string): T[];
39
34
  /**
40
35
  * 在末尾批量插入子节点
41
36
  * @param elements 插入节点
@@ -77,31 +77,6 @@ class AstElement extends node_1.AstNode {
77
77
  }
78
78
  return undefined;
79
79
  }
80
- /**
81
- * 符合条件的所有后代节点
82
- * @param condition 条件
83
- */
84
- #getElementsBy(condition) {
85
- const descendants = [];
86
- for (const child of this.childNodes) {
87
- if (child.type === 'text') {
88
- continue;
89
- }
90
- else if (condition(child)) {
91
- descendants.push(child);
92
- }
93
- descendants.push(...child.#getElementsBy(condition));
94
- }
95
- return descendants;
96
- }
97
- /**
98
- * 符合选择器的所有后代节点
99
- * @param selector 选择器
100
- */
101
- querySelectorAll(selector) {
102
- const condition = this.#getCondition(selector);
103
- return this.#getElementsBy(condition);
104
- }
105
80
  /**
106
81
  * 在末尾批量插入子节点
107
82
  * @param elements 插入节点
@@ -134,8 +109,8 @@ class AstElement extends node_1.AstNode {
134
109
  return data;
135
110
  }
136
111
  /** @private */
137
- toString(omit, separator = '') {
138
- return this.childNodes.map(child => child.toString()).join(separator);
112
+ toString(separator = '') {
113
+ return this.childNodes.map(String).join(separator);
139
114
  }
140
115
  /**
141
116
  * @override
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*(?:\/\s*)?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*\])|((?:^|\])[^[]*?)\]+|https?[:/]\/+/giu, errorSyntaxUrl = /<\s*(?:\/\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,7 +72,7 @@ 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, nowiki = name === 'nowiki' || name === 'pre', nextType = nextSibling?.type, nextName = nextSibling?.name, 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
78
  errorRegex = new RegExp(`<\\s*(?:\\/\\s*)${nowiki ? '' : '?'}(${name})\\b`, 'giu');
@@ -72,53 +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);
86
- }
87
- const { 0: char, length } = error;
88
- if (char === '['
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 === '['
89
105
  && type === 'ext-link-text'
90
106
  && (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
91
107
  || nextType === 'ext'
92
108
  && nextName === 'nowiki'
93
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] === '{') {
94
130
  continue;
95
131
  }
96
- 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, endIndex = startIndex + length, rootStr = String(root), nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], severity = length > 1 && (char !== '<' || !nowiki && /[\s/>]/u.test(nextChar ?? ''))
97
- || char === '{' && (nextChar === char || previousChar === '-')
98
- || char === '}' && (previousChar === char || nextChar === '-')
99
- || char === '[' && (nextChar === char
100
- || type === 'ext-link-text'
101
- || !data.slice(index + 1).trim() && nextType === 'free-ext-link')
102
- || char === ']' && (previousChar === char
103
- || !data.slice(0, index).trim() && previousType === 'free-ext-link')
104
- ? 'error'
105
- : 'warning';
106
- if (char !== '<' || tags.has(tag.toLowerCase())) {
107
- errors.push({
108
- message: Parser.msg('lonely "$1"', char === 'h' ? error : char),
109
- severity,
110
- startIndex,
111
- endIndex,
112
- startLine,
113
- endLine: startLine,
114
- startCol,
115
- endCol: startCol + length,
116
- });
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
+ }
117
141
  }
118
142
  }
119
- 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
+ });
120
154
  }
121
- return [];
155
+ return errors;
122
156
  }
123
157
  /**
124
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
@@ -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 = () => {
@@ -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) {
@@ -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))`
@@ -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,7 +11,7 @@ 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}`;
@@ -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) {
@@ -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;
@@ -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,7 +10,7 @@ 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;
@@ -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');
@@ -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++;
@@ -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);
@@ -61,7 +61,7 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
61
61
  }
62
62
  push(`\n${spaces}${indent && `\0${accum.length - 1}d\x7F`}${moreSpaces}\0${accum.length}b\x7F`, top);
63
63
  // @ts-expect-error abstract class
64
- stack.push(...top ? [top] : [], new index_2.TableToken(tableSyntax, attr, config, accum));
64
+ stack.push(...top ? [top] : [], new index_3.TableToken(tableSyntax, attr, config, accum));
65
65
  continue;
66
66
  }
67
67
  else if (!top) {
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';
package/dist/src/arg.js CHANGED
@@ -3,22 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ArgToken = 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
  const atom_1 = require("./atom");
9
9
  const hidden_1 = require("./hidden");
10
10
  /**
11
11
  * `{{{}}}`包裹的参数
12
12
  * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
13
13
  */
14
- class ArgToken extends index_1.Token {
14
+ class ArgToken extends index_2.Token {
15
15
  type = 'arg';
16
16
  /** 预设值 */
17
17
  get default() {
18
18
  return this.childNodes[1]?.text() ?? false;
19
19
  }
20
20
  /** @param parts 以'|'分隔的各部分 */
21
- constructor(parts, config = Parser.getConfig(), accum = []) {
21
+ constructor(parts, config = index_1.default.getConfig(), accum = []) {
22
22
  super(undefined, config, accum, {});
23
23
  for (let i = 0; i < parts.length; i++) {
24
24
  if (i === 0) {
@@ -30,7 +30,7 @@ class ArgToken extends index_1.Token {
30
30
  super.insertAt(token);
31
31
  }
32
32
  else {
33
- const token = new index_1.Token(parts[i], config, accum);
33
+ const token = new index_2.Token(parts[i], config, accum);
34
34
  token.type = 'arg-default';
35
35
  token.setAttribute('stage', 2);
36
36
  super.insertAt(token);
@@ -38,8 +38,8 @@ class ArgToken extends index_1.Token {
38
38
  }
39
39
  }
40
40
  /** @private */
41
- toString(omit) {
42
- return `{{{${super.toString(omit, '|')}}}}`;
41
+ toString() {
42
+ return `{{{${super.toString('|')}}}}`;
43
43
  }
44
44
  /** @override */
45
45
  text() {
@@ -1,4 +1,4 @@
1
- import * as Parser from '../index';
1
+ import Parser from '../index';
2
2
  import { Token } from './index';
3
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 */
package/dist/src/atom.js CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AtomToken = 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
  /** 不会被继续解析的plain Token */
7
- class AtomToken extends index_1.Token {
7
+ class AtomToken extends index_2.Token {
8
8
  /** @class */
9
- constructor(wikitext, type, config = Parser.getConfig(), accum = [], acceptable) {
9
+ constructor(wikitext, type, config = index_1.default.getConfig(), accum = [], acceptable) {
10
10
  super(wikitext, config, accum, acceptable);
11
11
  this.type = type;
12
12
  }
@@ -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';