wikilint 2.25.0 → 2.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +16 -15
  2. package/config/default.json +3 -0
  3. package/config/enwiki.json +3 -0
  4. package/config/jawiki.json +3 -0
  5. package/config/minimum.json +1 -0
  6. package/config/moegirl.json +0 -20
  7. package/config/zhwiki.json +3 -0
  8. package/data/ext/math.json +41 -0
  9. package/dist/base.d.mts +17 -4
  10. package/dist/base.d.ts +17 -4
  11. package/dist/bin/cli.js +114 -51
  12. package/dist/bin/config.js +8 -2
  13. package/dist/index.d.ts +5 -3
  14. package/dist/index.js +68 -47
  15. package/dist/lib/element.js +11 -9
  16. package/dist/lib/lintConfig.d.ts +18 -7
  17. package/dist/lib/lintConfig.js +55 -12
  18. package/dist/lib/lsp.js +16 -8
  19. package/dist/lib/text.js +176 -171
  20. package/dist/mixin/hidden.js +1 -1
  21. package/dist/mixin/noEscape.js +9 -7
  22. package/dist/parser/links.js +10 -4
  23. package/dist/src/arg.d.ts +0 -2
  24. package/dist/src/arg.js +34 -34
  25. package/dist/src/attribute.js +58 -36
  26. package/dist/src/attributes.js +62 -51
  27. package/dist/src/commented.js +2 -1
  28. package/dist/src/converterFlags.js +22 -18
  29. package/dist/src/extLink.js +6 -4
  30. package/dist/src/gallery.js +40 -36
  31. package/dist/src/heading.js +71 -59
  32. package/dist/src/html.js +81 -70
  33. package/dist/src/imageParameter.js +21 -15
  34. package/dist/src/imagemap.js +22 -18
  35. package/dist/src/index.js +107 -97
  36. package/dist/src/link/base.js +38 -28
  37. package/dist/src/link/file.js +86 -73
  38. package/dist/src/link/galleryImage.js +10 -6
  39. package/dist/src/link/index.js +10 -6
  40. package/dist/src/link/redirectTarget.js +12 -8
  41. package/dist/src/magicLink.js +25 -20
  42. package/dist/src/nested.js +31 -27
  43. package/dist/src/nowiki/comment.js +13 -9
  44. package/dist/src/nowiki/index.js +11 -7
  45. package/dist/src/nowiki/quote.js +29 -23
  46. package/dist/src/paramTag/index.js +26 -22
  47. package/dist/src/parameter.js +20 -16
  48. package/dist/src/pre.js +1 -1
  49. package/dist/src/redirect.js +5 -3
  50. package/dist/src/syntax.js +1 -1
  51. package/dist/src/table/index.js +31 -29
  52. package/dist/src/table/td.js +20 -16
  53. package/dist/src/table/trBase.js +13 -11
  54. package/dist/src/tagPair/ext.js +13 -10
  55. package/dist/src/tagPair/include.js +17 -11
  56. package/dist/src/transclude.js +45 -37
  57. package/dist/util/constants.js +2 -1
  58. package/dist/util/lint.js +2 -1
  59. package/package.json +4 -4
package/dist/lib/text.js CHANGED
@@ -9,9 +9,9 @@ const lint_1 = require("../util/lint");
9
9
  const debug_1 = require("../util/debug");
10
10
  const index_1 = __importDefault(require("../index"));
11
11
  const node_1 = require("./node");
12
- const sp = String.raw `[${string_1.zs}\t]*`, anySp = String.raw `[^\S\n]*`, source = String.raw `<${anySp}(?:/${anySp})?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])|((?:^|\])[^[]*?)\]+|(?:rfc|pmid)(?=[-::]?${sp}\d)|isbn(?=[-::]?${sp}(?:\d(?:${sp}|-)){6})`;
13
- const errorSyntax = new RegExp(String.raw `${source}|https?[:/]/+`, 'giu');
14
- const errorSyntaxUrl = new RegExp(source, 'giu'), noLinkTypes = new Set(['attr-value', 'ext-link-text', 'link-text']), regexes = {
12
+ const sp = /* #__PURE__ */ (() => String.raw `[${string_1.zs}\t]*`)(), anySp = /* #__PURE__ */ (() => String.raw `[^\S\n]*`)(), source = /* #__PURE__ */ (() => String.raw `<${anySp}(?:/${anySp})?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])|((?:^|\])[^[]*?)\]+|(?:rfc|pmid)(?=[-::]?${sp}\d)|isbn(?=[-::]?${sp}(?:\d(?:${sp}|-)){6})`)();
13
+ const errorSyntax = /* #__PURE__ */ (() => new RegExp(String.raw `${source}|https?[:/]/+`, 'giu'))();
14
+ const errorSyntaxUrl = /* #__PURE__ */ new RegExp(source, 'giu'), noLinkTypes = new Set(['attr-value', 'ext-link-text', 'link-text']), regexes = {
15
15
  '[': /[[\]]/u,
16
16
  '{': /[{}]/u,
17
17
  ']': /[[\]](?=[^[\]]*$)/u,
@@ -43,14 +43,15 @@ const errorSyntaxUrl = new RegExp(source, 'giu'), noLinkTypes = new Set(['attr-v
43
43
  'select',
44
44
  'textarea',
45
45
  ]);
46
- let wordRegex;
47
- try {
48
- // eslint-disable-next-line prefer-regex-literals
49
- wordRegex = new RegExp(String.raw `[\p{L}\p{N}_]`, 'u');
50
- }
51
- catch /* istanbul ignore next */ {
52
- wordRegex = /\w/u;
53
- }
46
+ const wordRegex = /* #__PURE__ */ (() => {
47
+ try {
48
+ // eslint-disable-next-line prefer-regex-literals
49
+ return new RegExp(String.raw `[\p{L}\p{N}_]`, 'u');
50
+ }
51
+ catch /* istanbul ignore next */ {
52
+ return /\w/u;
53
+ }
54
+ })();
54
55
  /**
55
56
  * text node
56
57
  *
@@ -76,184 +77,188 @@ class AstText extends node_1.AstNode {
76
77
  }
77
78
  /** @private */
78
79
  lint(start = this.getAbsoluteIndex(), errorRegex) {
79
- if (errorRegex === false) {
80
- return [];
81
- }
82
- const { data, parentNode, nextSibling, previousSibling } = this;
83
- /* istanbul ignore if */
84
- if (!parentNode) {
85
- throw new Error('An isolated text node cannot be linted!');
86
- }
87
- const { type, name, parentNode: grandparent } = parentNode;
88
- if (type === 'attr-value') {
89
- const { name: grandName, tag } = grandparent;
90
- if (tag === 'ref' && (grandName === 'name' || grandName === 'follow')
91
- || grandName === 'group' && (tag === 'ref' || tag === 'references')
92
- || tag === 'choose' && (grandName === 'before' || grandName === 'after')) {
80
+ LINT: { // eslint-disable-line no-unused-labels
81
+ if (errorRegex === false) {
93
82
  return [];
94
83
  }
95
- }
96
- errorRegex ??= type === 'free-ext-link'
97
- || type === 'ext-link-url'
98
- || type === 'ext-link-text'
99
- || type === 'image-parameter' && name === 'link'
100
- || type === 'attr-value'
101
- ? errorSyntaxUrl
102
- : errorSyntax;
103
- if (data.search(errorRegex) === -1) {
104
- return [];
105
- }
106
- errorRegex.lastIndex = 0;
107
- const errors = [], nextType = nextSibling?.type, nextName = nextSibling?.name, previousType = previousSibling?.type, root = this.getRootNode(), rootStr = root.toString(), { ext, html, variants } = root.getAttribute('config'), { top, left } = root.posFromIndex(start), lintConfig = index_1.default.lintConfig['tag-like'], specified = typeof lintConfig === 'number'
108
- ? new Set()
109
- : new Set(Object.keys(lintConfig[1]).filter(tag => tag !== 'invalid' && tag !== 'disallowed')), tags = new Set([
110
- 'onlyinclude',
111
- 'noinclude',
112
- 'includeonly',
113
- ...ext,
114
- ...html[0],
115
- ...html[1],
116
- ...html[2],
117
- ...specified,
118
- ...disallowedTags,
119
- ]);
120
- for (let mt = errorRegex.exec(data); mt; mt = errorRegex.exec(data)) {
121
- const [, tag, prefix] = mt;
122
- let { index, 0: error } = mt;
123
- if (prefix && prefix !== ']') {
124
- const { length } = prefix;
125
- index += length;
126
- error = error.slice(length);
127
- }
128
- error = error.toLowerCase();
129
- const [char] = error, magicLink = char === 'r' || char === 'p' || char === 'i', lbrace = char === '{', rbrace = char === '}', lbrack = char === '[', rbrack = char === ']';
130
- let { length } = error;
131
- if (char === '<' && !tags.has(tag.toLowerCase())
132
- || lbrack && type === 'ext-link-text' && (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
133
- || nextSibling?.is('ext') && nextName === 'nowiki'
134
- && nextSibling.innerText?.includes(']'))
135
- || magicLink && (!parentNode.isPlain() || noLinkTypes.has(type))) {
136
- continue;
84
+ const { data, parentNode, nextSibling, previousSibling } = this;
85
+ /* istanbul ignore if */
86
+ if (!parentNode) {
87
+ throw new Error('An isolated text node cannot be linted!');
137
88
  }
138
- else if (rbrack && (index || length > 1)) {
139
- errorRegex.lastIndex--;
89
+ const { type, name, parentNode: grandparent } = parentNode;
90
+ if (type === 'attr-value') {
91
+ const { name: grandName, tag } = grandparent;
92
+ if (tag === 'ref' && (grandName === 'name' || grandName === 'follow')
93
+ || grandName === 'group' && (tag === 'ref' || tag === 'references')
94
+ || tag === 'choose' && (grandName === 'before' || grandName === 'after')) {
95
+ return [];
96
+ }
140
97
  }
141
- // Rule & Severity
142
- let startIndex = start + index, endIndex = startIndex + length, rule, severity;
143
- const nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], leftBracket = lbrace || lbrack, lConverter = lbrace && previousChar === '-' && variants.length > 0, rConverter = rbrace && nextChar === '-' && variants.length > 0, brokenExtLink = lbrack && nextType === 'free-ext-link' && !data.slice(index + 1).trim()
144
- || rbrack && previousType === 'free-ext-link'
145
- && !data.slice(0, index).includes(']');
146
- if (magicLink) {
147
- rule = 'lonely-http';
148
- error = error.toUpperCase();
149
- severity = index_1.default.lintConfig.getSeverity(rule, error);
98
+ errorRegex ??= type === 'free-ext-link'
99
+ || type === 'ext-link-url'
100
+ || type === 'ext-link-text'
101
+ || type === 'image-parameter' && name === 'link'
102
+ || type === 'attr-value'
103
+ ? errorSyntaxUrl
104
+ : errorSyntax;
105
+ if (data.search(errorRegex) === -1) {
106
+ return [];
150
107
  }
151
- else if (char === '<') {
152
- rule = 'tag-like';
153
- let key;
154
- if (/^<\/?\s/u.test(error) || !/[\s/>]/u.test(nextChar ?? '')) {
155
- key = 'invalid';
108
+ errorRegex.lastIndex = 0;
109
+ const errors = [], nextType = nextSibling?.type, nextName = nextSibling?.name, previousType = previousSibling?.type, root = this.getRootNode(), rootStr = root.toString(), { ext, html, variants } = root.getAttribute('config'), { top, left } = root.posFromIndex(start), { lintConfig } = index_1.default, tagLike = lintConfig.rules['tag-like'], specified = typeof tagLike === 'number'
110
+ ? new Set()
111
+ : new Set(Object.keys(tagLike[1]).filter(tag => tag !== 'invalid' && tag !== 'disallowed')), tags = new Set([
112
+ 'onlyinclude',
113
+ 'noinclude',
114
+ 'includeonly',
115
+ ...ext,
116
+ ...html[0],
117
+ ...html[1],
118
+ ...html[2],
119
+ ...specified,
120
+ ...lintConfig.getSeverity('tag-like', 'disallowed') ? disallowedTags : [],
121
+ ]);
122
+ for (let mt = errorRegex.exec(data); mt; mt = errorRegex.exec(data)) {
123
+ const [, tag, prefix] = mt;
124
+ let { index, 0: error } = mt;
125
+ if (prefix && prefix !== ']') {
126
+ const { length } = prefix;
127
+ index += length;
128
+ error = error.slice(length);
156
129
  }
157
- else if (specified.has(tag)) {
158
- key = tag;
130
+ error = error.toLowerCase();
131
+ const [char] = error, magicLink = char === 'r' || char === 'p' || char === 'i', lbrace = char === '{', rbrace = char === '}', lbrack = char === '[', rbrack = char === ']';
132
+ let { length } = error;
133
+ if (char === '<' && !tags.has(tag.toLowerCase())
134
+ || lbrack && type === 'ext-link-text' && (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
135
+ || nextSibling?.is('ext') && nextName === 'nowiki'
136
+ && nextSibling.innerText?.includes(']'))
137
+ || magicLink && (!parentNode.isPlain() || noLinkTypes.has(type))) {
138
+ continue;
159
139
  }
160
- else if (disallowedTags.has(tag) && !ext.includes(tag)) {
161
- key = 'disallowed';
140
+ else if (rbrack && (index || length > 1)) {
141
+ errorRegex.lastIndex--;
162
142
  }
163
- severity = index_1.default.lintConfig.getSeverity(rule, key);
164
- }
165
- else if (lConverter || rConverter) {
166
- rule = 'lonely-bracket';
167
- severity = index_1.default.lintConfig.getSeverity(rule, 'converter');
168
- if (lConverter && index > 0) {
169
- error = '-{';
170
- index--;
171
- startIndex--;
172
- length = 2;
143
+ // Rule & Severity
144
+ let startIndex = start + index, endIndex = startIndex + length, rule, severity;
145
+ const nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], leftBracket = lbrace || lbrack, lConverter = lbrace && previousChar === '-' && variants.length > 0, rConverter = rbrace && nextChar === '-' && variants.length > 0, brokenExtLink = lbrack && nextType === 'free-ext-link' && !data.slice(index + 1).trim()
146
+ || rbrack && previousType === 'free-ext-link'
147
+ && !data.slice(0, index).includes(']');
148
+ if (magicLink) {
149
+ rule = 'lonely-http';
150
+ error = error.toUpperCase();
151
+ severity = lintConfig.getSeverity(rule, error);
173
152
  }
174
- else if (rConverter && index < data.length - 1) {
175
- error = '}-';
176
- endIndex++;
177
- length = 2;
153
+ else if (char === '<') {
154
+ rule = 'tag-like';
155
+ let key;
156
+ if (/^<\/?\s/u.test(error) || !/[\s/>]/u.test(nextChar ?? '')) {
157
+ key = 'invalid';
158
+ }
159
+ else if (specified.has(tag)) {
160
+ key = tag;
161
+ }
162
+ else if (disallowedTags.has(tag) && !ext.includes(tag)) {
163
+ key = 'disallowed';
164
+ }
165
+ severity = lintConfig.getSeverity(rule, key);
178
166
  }
179
- }
180
- else if (brokenExtLink) {
181
- rule = 'lonely-bracket';
182
- severity = index_1.default.lintConfig.getSeverity(rule, 'extLink');
183
- }
184
- else if (leftBracket || rbrace || rbrack) {
185
- rule = 'lonely-bracket';
186
- if (length > 1 || lbrace && nextChar === char || rbrace && previousChar === char) {
187
- severity = index_1.default.lintConfig.getSeverity(rule, 'double');
167
+ else if (lConverter || rConverter) {
168
+ rule = 'lonely-bracket';
169
+ severity = lintConfig.getSeverity(rule, 'converter');
170
+ if (lConverter && index > 0) {
171
+ error = '-{';
172
+ index--;
173
+ startIndex--;
174
+ length = 2;
175
+ }
176
+ else if (rConverter && index < data.length - 1) {
177
+ error = '}-';
178
+ endIndex++;
179
+ length = 2;
180
+ }
188
181
  }
189
- else {
190
- if (!lbrack || type !== 'ext-link-text') {
191
- const regex = regexes[char], remains = leftBracket ? data.slice(index + 1) : data.slice(0, index);
192
- if (lbrace && regex.exec(remains)?.[0] === '}'
193
- || rbrace && regex.exec(remains)?.[0] === '{') {
194
- continue;
195
- }
196
- else if (!remains.includes(char)) {
197
- const sibling = leftBracket ? 'nextSibling' : 'previousSibling';
198
- let cur = this[sibling];
199
- while (cur && (cur.type !== 'text' || !regex.test(cur.data))) {
200
- cur = cur[sibling];
201
- }
202
- if (cur && regex.exec(cur.data)[0] !== char) {
182
+ else if (brokenExtLink) {
183
+ rule = 'lonely-bracket';
184
+ severity = lintConfig.getSeverity(rule, 'extLink');
185
+ }
186
+ else if (leftBracket || rbrace || rbrack) {
187
+ rule = 'lonely-bracket';
188
+ if (length > 1 || lbrace && nextChar === char || rbrace && previousChar === char) {
189
+ severity = lintConfig.getSeverity(rule, 'double');
190
+ }
191
+ else {
192
+ if (!lbrack || type !== 'ext-link-text') {
193
+ const regex = regexes[char], remains = leftBracket ? data.slice(index + 1) : data.slice(0, index);
194
+ if (lbrace && regex.exec(remains)?.[0] === '}'
195
+ || rbrace && regex.exec(remains)?.[0] === '{') {
203
196
  continue;
204
197
  }
198
+ else if (!remains.includes(char)) {
199
+ const sibling = leftBracket ? 'nextSibling' : 'previousSibling';
200
+ let cur = this[sibling];
201
+ while (cur && (cur.type !== 'text' || !regex.test(cur.data))) {
202
+ cur = cur[sibling];
203
+ }
204
+ if (cur && regex.exec(cur.data)[0] !== char) {
205
+ continue;
206
+ }
207
+ }
205
208
  }
209
+ severity = lintConfig.getSeverity(rule, 'single');
206
210
  }
207
- severity = index_1.default.lintConfig.getSeverity(rule, 'single');
208
211
  }
212
+ else {
213
+ rule = 'lonely-http';
214
+ severity = lintConfig.getSeverity(rule);
215
+ }
216
+ if (!severity) {
217
+ continue;
218
+ }
219
+ // LintError
220
+ const pos = this.posFromIndex(index), { line: startLine, character: startCol } = (0, lint_1.getEndPos)(top, left, pos.top + 1, pos.left), e = {
221
+ rule,
222
+ message: index_1.default.msg('lonely', magicLink || char === 'h' || lConverter || rConverter ? error : char),
223
+ severity,
224
+ startIndex,
225
+ endIndex,
226
+ startLine,
227
+ endLine: startLine,
228
+ startCol,
229
+ endCol: startCol + length,
230
+ };
231
+ // Suggestions
232
+ if (lintConfig.computeEditInfo) {
233
+ if (char === '<') {
234
+ e.suggestions = [(0, lint_1.fixByEscape)(startIndex, '&lt;')];
235
+ }
236
+ else if (char === 'h' && type !== 'link-text' && wordRegex.test(previousChar || '')) {
237
+ e.suggestions = [(0, lint_1.fixBySpace)(startIndex)];
238
+ }
239
+ else if (lbrack && type === 'ext-link-text') {
240
+ const i = parentNode.getAbsoluteIndex() + parentNode.toString().length;
241
+ e.suggestions = [(0, lint_1.fixByEscape)(i, '&#93;')];
242
+ }
243
+ else if (rbrack && brokenExtLink) {
244
+ const i = start - previousSibling.toString().length;
245
+ e.suggestions = [(0, lint_1.fixByInsert)(i, 'left-bracket', '[')];
246
+ }
247
+ else if (magicLink) {
248
+ e.suggestions = [
249
+ ...mt[0] === error
250
+ ? []
251
+ : [(0, lint_1.fixByUpper)(e, error)],
252
+ ...nextChar === ':' || nextChar === ':'
253
+ ? [(0, lint_1.fixBySpace)(endIndex, 1)]
254
+ : [],
255
+ ];
256
+ }
257
+ }
258
+ errors.push(e);
209
259
  }
210
- else {
211
- rule = 'lonely-http';
212
- severity = index_1.default.lintConfig.getSeverity(rule);
213
- }
214
- if (!severity) {
215
- continue;
216
- }
217
- // LintError
218
- const pos = this.posFromIndex(index), { line: startLine, character: startCol } = (0, lint_1.getEndPos)(top, left, pos.top + 1, pos.left), e = {
219
- rule,
220
- message: index_1.default.msg('lonely', magicLink || char === 'h' || lConverter || rConverter ? error : char),
221
- severity,
222
- startIndex,
223
- endIndex,
224
- startLine,
225
- endLine: startLine,
226
- startCol,
227
- endCol: startCol + length,
228
- };
229
- // Suggestions
230
- if (char === '<') {
231
- e.suggestions = [(0, lint_1.fixByEscape)(startIndex, '&lt;')];
232
- }
233
- else if (char === 'h' && type !== 'link-text' && wordRegex.test(previousChar || '')) {
234
- e.suggestions = [(0, lint_1.fixBySpace)(startIndex)];
235
- }
236
- else if (lbrack && type === 'ext-link-text') {
237
- const i = parentNode.getAbsoluteIndex() + parentNode.toString().length;
238
- e.suggestions = [(0, lint_1.fixByEscape)(i, '&#93;')];
239
- }
240
- else if (rbrack && brokenExtLink) {
241
- const i = start - previousSibling.toString().length;
242
- e.suggestions = [(0, lint_1.fixByInsert)(i, 'left-bracket', '[')];
243
- }
244
- else if (magicLink) {
245
- e.suggestions = [
246
- ...mt[0] === error
247
- ? []
248
- : [(0, lint_1.fixByUpper)(e, error)],
249
- ...nextChar === ':' || nextChar === ':'
250
- ? [(0, lint_1.fixBySpace)(endIndex, 1)]
251
- : [],
252
- ];
253
- }
254
- errors.push(e);
260
+ return errors;
255
261
  }
256
- return errors;
257
262
  }
258
263
  /**
259
264
  * 修改内容
@@ -16,7 +16,7 @@ const hiddenToken = (linter = true, html = true) => (constructor) => {
16
16
  }
17
17
  lint(start) {
18
18
  // @ts-expect-error private argument
19
- return linter ? [] : super.lint(start);
19
+ LINT: return linter ? [] : super.lint(start); // eslint-disable-line no-unused-labels
20
20
  }
21
21
  }
22
22
  /* eslint-enable jsdoc/require-jsdoc */
@@ -7,14 +7,16 @@ const debug_1 = require("../util/debug");
7
7
  * @ignore
8
8
  */
9
9
  const noEscape = (constructor) => {
10
- /* eslint-disable jsdoc/require-jsdoc */
11
- class NoEscapeToken extends constructor {
12
- escape() {
13
- //
10
+ LSP: { // eslint-disable-line no-unused-labels
11
+ /* eslint-disable jsdoc/require-jsdoc */
12
+ class NoEscapeToken extends constructor {
13
+ escape() {
14
+ //
15
+ }
14
16
  }
17
+ /* eslint-enable jsdoc/require-jsdoc */
18
+ (0, debug_1.mixin)(NoEscapeToken, constructor);
19
+ return NoEscapeToken;
15
20
  }
16
- /* eslint-enable jsdoc/require-jsdoc */
17
- (0, debug_1.mixin)(NoEscapeToken, constructor);
18
- return NoEscapeToken;
19
21
  };
20
22
  exports.noEscape = noEscape;
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.parseLinks = void 0;
7
+ const string_1 = require("../util/string");
7
8
  const index_1 = __importDefault(require("../index"));
8
9
  const quotes_1 = require("./quotes");
9
10
  const externalLinks_1 = require("./externalLinks");
@@ -20,9 +21,9 @@ const regexImg = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(\||\0\d+!\x7F)([\s\S]*)$/u;
20
21
  */
21
22
  const parseLinks = (wikitext, config, accum, tidy) => {
22
23
  config.regexLinks ??= new RegExp(String.raw `^\s*(?:${config.protocol}|//)`, 'iu');
23
- const regex = true // eslint-disable-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
24
+ const regex = config.inExt
24
25
  ? /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)([\s\S]*?[^\]]))?\]\]([\s\S]*)$/u
25
- : /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)([\s\S]*?[^\]])?)?\]\]([\s\S]*)$/u, bits = wikitext.split('[[');
26
+ : /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])*)(?:(\||\0\d+!\x7F)([\s\S]*?[^\]])?)?\]\]([\s\S]*)$/u, bits = wikitext.split('[[');
26
27
  let s = bits.shift();
27
28
  for (let i = 0; i < bits.length; i++) {
28
29
  let mightBeImg = false, link, delimiter, text, after;
@@ -45,12 +46,14 @@ const parseLinks = (wikitext, config, accum, tidy) => {
45
46
  s += `[[${x}`;
46
47
  continue;
47
48
  }
48
- const force = link.trim().startsWith(':');
49
+ // eslint-disable-next-line prefer-const
50
+ let trimmed = (0, string_1.removeComment)(link).trim();
51
+ const force = trimmed.startsWith(':');
49
52
  if (force && mightBeImg) {
50
53
  s += `[[${x}`;
51
54
  continue;
52
55
  }
53
- const { ns, valid, } = index_1.default.normalizeTitle(link, 0, false, config, { halfParsed: true, temporary: true, decode: true, selfLink: true });
56
+ const { ns, valid, } = index_1.default.normalizeTitle(trimmed, 0, false, config, { halfParsed: true, temporary: true, decode: true, selfLink: true });
54
57
  if (!valid) {
55
58
  s += `[[${x}`;
56
59
  continue;
@@ -94,6 +97,9 @@ const parseLinks = (wikitext, config, accum, tidy) => {
94
97
  SomeLinkToken = category_1.CategoryToken;
95
98
  }
96
99
  }
100
+ if (text === undefined && delimiter) {
101
+ text = '';
102
+ }
97
103
  s += `\0${accum.length}l\x7F${after}`;
98
104
  // @ts-expect-error abstract class
99
105
  new SomeLinkToken(link, text, config, accum, delimiter);
package/dist/src/arg.d.ts CHANGED
@@ -15,8 +15,6 @@ export declare abstract class ArgToken extends Token {
15
15
  abstract get firstChild(): AtomToken;
16
16
  abstract get lastChild(): Token;
17
17
  get type(): 'arg';
18
- /** default value / 预设值 */
19
- get default(): string | false;
20
18
  /** @param parts 以'|'分隔的各部分 */
21
19
  constructor(parts: readonly string[], config: Config, accum?: Token[]);
22
20
  }
package/dist/src/arg.js CHANGED
@@ -72,10 +72,6 @@ let ArgToken = (() => {
72
72
  get type() {
73
73
  return 'arg';
74
74
  }
75
- /** default value / 预设值 */
76
- get default() {
77
- return this.childNodes[1]?.text() ?? false;
78
- }
79
75
  /** @param parts 以'|'分隔的各部分 */
80
76
  constructor(parts, config, accum = []) {
81
77
  super(undefined, config, accum, {});
@@ -118,39 +114,43 @@ let ArgToken = (() => {
118
114
  }
119
115
  /** @private */
120
116
  lint(start = this.getAbsoluteIndex(), re) {
121
- const { childNodes: [argName, argDefault, ...rest] } = this;
122
- argName.setAttribute('aIndex', start + 3);
123
- const errors = argName.lint(start + 3, re);
124
- if (argDefault) {
125
- const index = start + 4 + argName.toString().length;
126
- argDefault.setAttribute('aIndex', index);
127
- const childErrors = argDefault.lint(index, re);
128
- if (childErrors.length > 0) {
129
- errors.push(...childErrors);
130
- }
131
- }
132
- const rules = ['no-ignored', 'no-arg'], s = rules.map(rule => index_1.default.lintConfig.getSeverity(rule, 'arg'));
133
- if (s[0] && rest.length > 0) {
134
- const rect = new rect_1.BoundingRect(this, start);
135
- errors.push(...rest.map(child => {
136
- const e = (0, lint_1.generateForChild)(child, rect, rules[0], 'invisible-triple-braces', s[0]);
137
- e.startIndex--;
138
- e.startCol--;
139
- e.suggestions = [
140
- (0, lint_1.fixByRemove)(e),
141
- (0, lint_1.fixByEscape)(e.startIndex, '{{!}}'),
142
- ];
143
- return e;
144
- }));
145
- }
146
- if (s[1] && !this.getAttribute('include')) {
147
- const e = (0, lint_1.generateForSelf)(this, { start }, rules[1], 'unexpected-argument', s[1]);
117
+ LINT: { // eslint-disable-line no-unused-labels
118
+ const { childNodes: [argName, argDefault, ...rest] } = this;
119
+ argName.setAttribute('aIndex', start + 3);
120
+ const errors = argName.lint(start + 3, re);
148
121
  if (argDefault) {
149
- e.suggestions = [(0, lint_1.fixBy)(e, 'expand', argDefault.text())];
122
+ const index = start + 4 + argName.toString().length;
123
+ argDefault.setAttribute('aIndex', index);
124
+ const childErrors = argDefault.lint(index, re);
125
+ if (childErrors.length > 0) {
126
+ errors.push(...childErrors);
127
+ }
128
+ }
129
+ const rules = ['no-ignored', 'no-arg'], { lintConfig } = index_1.default, { computeEditInfo } = lintConfig, s = rules.map(rule => lintConfig.getSeverity(rule, 'arg'));
130
+ if (s[0] && rest.length > 0) {
131
+ const rect = new rect_1.BoundingRect(this, start);
132
+ errors.push(...rest.map(child => {
133
+ const e = (0, lint_1.generateForChild)(child, rect, rules[0], 'invisible-triple-braces', s[0]);
134
+ e.startIndex--;
135
+ e.startCol--;
136
+ if (computeEditInfo) {
137
+ e.suggestions = [
138
+ (0, lint_1.fixByRemove)(e),
139
+ (0, lint_1.fixByEscape)(e.startIndex, '{{!}}'),
140
+ ];
141
+ }
142
+ return e;
143
+ }));
144
+ }
145
+ if (s[1] && !this.getAttribute('include')) {
146
+ const e = (0, lint_1.generateForSelf)(this, { start }, rules[1], 'unexpected-argument', s[1]);
147
+ if (computeEditInfo && argDefault) {
148
+ e.suggestions = [(0, lint_1.fixBy)(e, 'expand', argDefault.text())];
149
+ }
150
+ errors.push(e);
150
151
  }
151
- errors.push(e);
152
+ return errors;
152
153
  }
153
- return errors;
154
154
  }
155
155
  };
156
156
  return ArgToken = _classThis;