wikilint 2.43.0 → 2.45.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 (94) hide show
  1. package/config/default.json +32 -2
  2. package/config/enwiki.json +1 -1
  3. package/config/jawiki.json +1 -1
  4. package/config/minimum.json +1 -1
  5. package/config/moegirl.json +39 -1
  6. package/config/zhwiki.json +1 -1
  7. package/data/ext/templatedata.json +13 -5
  8. package/data/signatures.json +38 -32
  9. package/dist/base.d.mts +5 -5
  10. package/dist/base.d.ts +5 -5
  11. package/dist/base.js +1 -0
  12. package/dist/base.mjs +1 -0
  13. package/dist/bin/config.js +6 -5
  14. package/dist/index.js +9 -6
  15. package/dist/internal.d.ts +6 -1
  16. package/dist/lib/document.d.ts +17 -14
  17. package/dist/lib/element.js +5 -5
  18. package/dist/lib/lintConfig.js +11 -1
  19. package/dist/lib/lsp.d.ts +1 -2
  20. package/dist/lib/lsp.js +18 -42
  21. package/dist/lib/node.js +2 -2
  22. package/dist/lib/text.js +2 -2
  23. package/dist/lib/title.d.ts +4 -1
  24. package/dist/lib/title.js +5 -1
  25. package/dist/map.d.ts +4 -1
  26. package/dist/mixin/attributesParent.js +1 -1
  27. package/dist/mixin/elementLike.js +29 -31
  28. package/dist/mixin/hidden.js +0 -1
  29. package/dist/mixin/paramLineParent.d.ts +26 -0
  30. package/dist/mixin/paramLineParent.js +51 -0
  31. package/dist/parser/converter.js +1 -1
  32. package/dist/src/arg.js +17 -35
  33. package/dist/src/atom.d.ts +1 -1
  34. package/dist/src/atom.js +2 -0
  35. package/dist/src/attribute.js +10 -5
  36. package/dist/src/attributes.d.ts +1 -0
  37. package/dist/src/attributes.js +41 -15
  38. package/dist/src/commented.d.ts +1 -0
  39. package/dist/src/commented.js +1 -3
  40. package/dist/src/converterFlags.js +17 -8
  41. package/dist/src/converterRule.js +3 -3
  42. package/dist/src/funcTag.d.ts +23 -0
  43. package/dist/src/funcTag.js +85 -0
  44. package/dist/src/heading.js +8 -3
  45. package/dist/src/hidden.d.ts +3 -2
  46. package/dist/src/hidden.js +29 -5
  47. package/dist/src/imageParameter.d.ts +4 -3
  48. package/dist/src/imageParameter.js +29 -9
  49. package/dist/src/index.js +2 -2
  50. package/dist/src/link/base.js +14 -2
  51. package/dist/src/link/categorytree.d.ts +2 -0
  52. package/dist/src/link/categorytree.js +8 -5
  53. package/dist/src/link/file.d.ts +5 -4
  54. package/dist/src/link/file.js +19 -13
  55. package/dist/src/multiLine/charinsert.d.ts +16 -0
  56. package/dist/src/multiLine/charinsert.js +84 -0
  57. package/dist/src/multiLine/gallery.js +4 -4
  58. package/dist/src/multiLine/imagemap.d.ts +1 -1
  59. package/dist/src/multiLine/imagemap.js +7 -7
  60. package/dist/src/multiLine/index.d.ts +3 -0
  61. package/dist/src/multiLine/index.js +79 -18
  62. package/dist/src/multiLine/inputbox.d.ts +1 -0
  63. package/dist/src/multiLine/paramTag.d.ts +3 -0
  64. package/dist/src/multiLine/paramTag.js +60 -13
  65. package/dist/src/nested.js +7 -7
  66. package/dist/src/nowiki/index.d.ts +1 -0
  67. package/dist/src/nowiki/index.js +39 -28
  68. package/dist/src/nowiki/quote.js +6 -5
  69. package/dist/src/paramLine.d.ts +17 -3
  70. package/dist/src/paramLine.js +123 -31
  71. package/dist/src/parameter.d.ts +6 -0
  72. package/dist/src/parameter.js +15 -1
  73. package/dist/src/singleLine/charinsertLine.d.ts +21 -0
  74. package/dist/src/singleLine/charinsertLine.js +69 -0
  75. package/dist/src/{imagemapLink.d.ts → singleLine/imagemapLink.d.ts} +8 -7
  76. package/dist/src/singleLine/imagemapLink.js +95 -0
  77. package/dist/src/singleLine/index.d.ts +10 -0
  78. package/dist/src/singleLine/index.js +16 -0
  79. package/dist/src/tag/html.js +26 -8
  80. package/dist/src/tag/index.js +18 -17
  81. package/dist/src/tagPair/ext.d.ts +1 -0
  82. package/dist/src/tagPair/ext.js +59 -5
  83. package/dist/src/tagPair/index.js +1 -10
  84. package/dist/src/transclude.js +13 -13
  85. package/dist/util/sharable.js +22 -0
  86. package/dist/util/sharable.mjs +22 -0
  87. package/dist/util/string.js +33 -2
  88. package/dist/vendor/search.js +34 -0
  89. package/i18n/en.json +11 -0
  90. package/i18n/zh-hans.json +11 -0
  91. package/i18n/zh-hant.json +11 -0
  92. package/package.json +16 -25
  93. package/dist/src/imagemapLink.js +0 -34
  94. package/dist/util/search.js +0 -16
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.paramLineParent = void 0;
7
+ const debug_1 = require("../util/debug");
8
+ const lint_1 = require("../util/lint");
9
+ const rect_1 = require("../lib/rect");
10
+ const index_1 = __importDefault(require("../index"));
11
+ /**
12
+ * 子节点为ParamLineToken的类
13
+ * @ignore
14
+ */
15
+ const paramLineParent = (constructor) => {
16
+ LINT: {
17
+ class ParamLineParent extends constructor {
18
+ getKeys() {
19
+ return new Set(this.childNodes.map(({ key }) => key).filter((key) => key !== undefined));
20
+ }
21
+ getParams(key) {
22
+ return this.childNodes.filter(({ key: k }) => k === key);
23
+ }
24
+ getDuplicatedParams() {
25
+ return [...this.getKeys()].map((key) => [key, this.getParams(key)])
26
+ .filter(([, { length }]) => length > 1);
27
+ }
28
+ lint(start = this.getAbsoluteIndex()) {
29
+ const errors = super.lint(start), { name, firstChild } = this, rule = 'no-duplicate', { lintConfig } = index_1.default, s = lintConfig.getSeverity(rule, name);
30
+ if (s) {
31
+ const msg = index_1.default.msg('duplicate-ext-parameter', name), rect = new rect_1.BoundingRect(this, start), { computeEditInfo } = lintConfig;
32
+ for (const [, params] of this.getDuplicatedParams()) {
33
+ const duplication = Array.from({ length: params.length });
34
+ for (let i = params.length - 1; i >= 0; i--) {
35
+ const param = params[i], e = (0, lint_1.generateForChild)(param, rect, rule, msg, s);
36
+ if (computeEditInfo) {
37
+ e.suggestions = [(0, lint_1.fixByRemove)(e, param === firstChild ? 0 : -1)];
38
+ }
39
+ duplication[i] = e;
40
+ }
41
+ Array.prototype.push.apply(errors, duplication);
42
+ }
43
+ }
44
+ return errors;
45
+ }
46
+ }
47
+ (0, debug_1.mixin)(ParamLineParent, constructor);
48
+ return ParamLineParent;
49
+ }
50
+ };
51
+ exports.paramLineParent = paramLineParent;
@@ -9,7 +9,7 @@ const converter_1 = require("../src/converter");
9
9
  * @param accum
10
10
  */
11
11
  const parseConverter = (text, config, accum) => {
12
- config.regexConverter ??= new RegExp(String.raw `;(?=(?:[^;]*?=>)?\s*(?:${config.variants.join('|')})\s*:|(?:\s|\0\d+[cn]\x7F)*$)`, 'iu');
12
+ config.regexConverter ??= new RegExp(String.raw `;(?=(?:[^;]*?=>)?\s*(?:${config.variants.join('|')})\s*:|(?:\s|\0\d+[cn]\x7F)*$)`, 'u');
13
13
  const regex1 = /-\{/gu, regex2 = /-\{|\}-/gu, stack = [];
14
14
  let regex = regex1, mt = regex.exec(text);
15
15
  while (mt) {
package/dist/src/arg.js CHANGED
@@ -38,7 +38,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.ArgToken = void 0;
41
- const string_1 = require("../util/string");
42
41
  const lint_1 = require("../util/lint");
43
42
  const rect_1 = require("../lib/rect");
44
43
  const padded_1 = require("../mixin/padded");
@@ -99,11 +98,17 @@ let ArgToken = (() => {
99
98
  }
100
99
  /** @private */
101
100
  text() {
102
- return `{{{${(0, string_1.text)(this.childNodes.slice(0, 2), '|')}}}}`;
101
+ // eslint-disable-next-line @typescript-eslint/no-useless-default-assignment
102
+ const { length, childNodes, name = this.#getName() } = this;
103
+ return length === 1 ? `{{{${name}}}}` : `{{{${name}|${childNodes[1].text()}}}}`;
104
+ }
105
+ /** 获取name */
106
+ #getName() {
107
+ return this.firstChild.text().trim();
103
108
  }
104
109
  /** 更新name */
105
110
  #setName() {
106
- LSP: this.setAttribute('name', this.firstChild.text().trim());
111
+ LSP: this.setAttribute('name', this.#getName());
107
112
  }
108
113
  /** @private */
109
114
  afterBuild() {
@@ -113,44 +118,21 @@ let ArgToken = (() => {
113
118
  /** @private */
114
119
  lint(start = this.getAbsoluteIndex(), re) {
115
120
  LINT: {
116
- const [argName, argDefault, ...rest] = this.childNodes;
117
- argName.setAttribute('aIndex', start + 3);
118
- const errors = argName.lint(start + 3, re);
119
- if (argDefault) {
120
- const index = start + 4 + argName.toString().length;
121
- argDefault.setAttribute('aIndex', index);
122
- const childErrors = argDefault.lint(index, re);
123
- if (childErrors.length > 0) {
124
- Array.prototype.push.apply(errors, childErrors);
125
- }
126
- }
127
- const rules = ['no-ignored', 'no-arg'], { lintConfig } = index_1.default, { computeEditInfo } = lintConfig, rect = new rect_1.BoundingRect(this, start), s = rules.map(rule => lintConfig.getSeverity(rule, 'arg'));
128
- if (s[0] && rest.length > 0) {
129
- Array.prototype.push.apply(errors, rest.map(child => {
130
- const e = (0, lint_1.generateForChild)(child, rect, rules[0], 'invisible-triple-braces', s[0]);
131
- e.startIndex--;
132
- e.startCol--;
133
- if (computeEditInfo) {
134
- e.suggestions = [
135
- (0, lint_1.fixByRemove)(e),
136
- (0, lint_1.fixByEscape)(e.startIndex, '{{!}}'),
137
- ];
138
- }
139
- return e;
140
- }));
141
- }
142
- if (s[1] && !this.getAttribute('include')) {
143
- const e = (0, lint_1.generateForSelf)(this, rect, rules[1], 'unexpected-argument', s[1]);
144
- if (computeEditInfo && argDefault) {
121
+ const errors = super.lint(start, re), { lintConfig } = index_1.default, rect = new rect_1.BoundingRect(this, start);
122
+ let rule = 'no-arg', s = lintConfig.getSeverity(rule);
123
+ if (s && !this.getAttribute('include')) {
124
+ const e = (0, lint_1.generateForSelf)(this, rect, rule, 'unexpected-argument', s), [, argDefault] = this.childNodes;
125
+ if (lintConfig.computeEditInfo && argDefault) {
145
126
  e.suggestions = [(0, lint_1.fixBy)(e, 'expand', argDefault.text())];
146
127
  }
147
128
  errors.push(e);
148
129
  }
149
130
  const ext = this.closest('ext');
150
131
  if (ext) {
151
- const rule = 'arg-in-ext', severity = lintConfig.getSeverity(rule, ext.name);
152
- if (severity) {
153
- errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'argument-in-ext', severity));
132
+ rule = 'arg-in-ext';
133
+ s = lintConfig.getSeverity(rule, ext.name);
134
+ if (s) {
135
+ errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'argument-in-ext', s));
154
136
  }
155
137
  }
156
138
  return errors;
@@ -1,6 +1,6 @@
1
1
  import { Token } from './index';
2
2
  import type { Config } from '../base';
3
- declare const atomTypes: readonly ["arg-name", "attr-key", "attr-value", "ext-attr-dirty", "html-attr-dirty", "table-attr-dirty", "converter-flag", "converter-rule-variant", "invoke-function", "invoke-module", "template-name", "link-target"];
3
+ declare const atomTypes: readonly ["arg-name", "attr-key", "attr-value", "ext-attr-dirty", "html-attr-dirty", "table-attr-dirty", "converter-flag", "converter-rule-variant", "invoke-function", "invoke-module", "template-name", "link-target", "param-line-key", "param-line-value"];
4
4
  declare type AtomTypes = typeof atomTypes[number];
5
5
  /**
6
6
  * plain Token that will not be parsed further
package/dist/src/atom.js CHANGED
@@ -16,6 +16,8 @@ const atomTypes = [
16
16
  'invoke-module',
17
17
  'template-name',
18
18
  'link-target',
19
+ 'param-line-key',
20
+ 'param-line-value',
19
21
  ];
20
22
  /**
21
23
  * plain Token that will not be parsed further
@@ -14,7 +14,7 @@ const index_2 = require("./index");
14
14
  const atom_1 = require("./atom");
15
15
  /* NOT FOR BROWSER ONLY */
16
16
  const document_1 = require("../lib/document");
17
- const insecureStyle = /expression|(?:accelerator|-o-link(?:-source)?|-o-replace)\s*:|(?:url|src|image(?:-set)?)\s*\(|attr\s*\([^)]+[\s,]url/u, evil = /(?:^|\s|\*\/)(?:java|vb)script(?:\W|$)/iu, complexTypes = new Set(['ext', 'arg', 'magic-word', 'template']), urlAttrs = new Set([
17
+ const insecureStyle = /expression|(?:accelerator|-o-link(?:-source)?|-o-replace)\s*:|(?:url|src|image(?:-set)?)\s*\(|attr\s*\([^)]+[\s,]url/u, evil = /(?:^|\s|\*\/)(?:java|vb)script(?:\W|$)/iu, complexTypes = new Set(['ext', 'arg', 'magic-word', 'template']), itemAttrs = new Set(['itemtype', 'itemid', 'itemref']), urlAttrs = new Set([
18
18
  'about',
19
19
  'property',
20
20
  'resource',
@@ -88,9 +88,13 @@ class AttributeToken extends index_2.Token {
88
88
  this.#tag = tag;
89
89
  this.setAttribute('name', (0, string_1.trimLc)((0, string_1.removeComment)(key)));
90
90
  }
91
+ /** 获取name */
92
+ #getName() {
93
+ return (0, string_1.trimLc)(this.firstChild.text());
94
+ }
91
95
  /** 更新name */
92
96
  #setName() {
93
- this.setAttribute('name', (0, string_1.trimLc)(this.firstChild.text()));
97
+ this.setAttribute('name', this.#getName());
94
98
  }
95
99
  /** @private */
96
100
  afterBuild() {
@@ -110,7 +114,9 @@ class AttributeToken extends index_2.Token {
110
114
  }
111
115
  /** @private */
112
116
  text() {
113
- return this.#equal ? `${super.text(`${this.#equal.trim()}"`)}"` : this.firstChild.text();
117
+ // eslint-disable-next-line @typescript-eslint/no-useless-default-assignment
118
+ const { lastChild, name = this.#getName() } = this;
119
+ return this.#equal ? `${name}${this.#equal.trim()}"${lastChild.text()}"` : name;
114
120
  }
115
121
  /** @private */
116
122
  getGaps() {
@@ -138,8 +144,7 @@ class AttributeToken extends index_2.Token {
138
144
  // 或非通用HTML属性
139
145
  || !/^(?:xmlns:[\w:.-]+|data-(?!ooui|mw|parsoid)[^:_]*)$/u.test(name)
140
146
  && (tag === 'meta' || tag === 'link' || !sharable_1.commonHtmlAttrs.has(name)))
141
- || (name === 'itemtype' || name === 'itemid' || name === 'itemref')
142
- && !parentNode?.hasAttr('itemscope')) {
147
+ || itemAttrs.has(name) && !parentNode?.hasAttr('itemscope')) {
143
148
  LINT: {
144
149
  const s = lintConfig.getSeverity(rule, 'unknown');
145
150
  if (s) {
@@ -1,3 +1,4 @@
1
+ import { BoundingRect } from '../lib/rect';
1
2
  import { Token } from './index';
2
3
  import { AtomToken } from './atom';
3
4
  import { AttributeToken } from './attribute';
@@ -124,10 +124,8 @@ class AttributesToken extends index_2.Token {
124
124
  * @param key attribute name / 属性名
125
125
  */
126
126
  getAttrToken(key) {
127
- LINT: {
128
- const tokens = this.getAttrTokens(key);
129
- return tokens[tokens.length - 1];
130
- }
127
+ const tokens = this.getAttrTokens(key);
128
+ return tokens[tokens.length - 1];
131
129
  }
132
130
  /**
133
131
  * Get the attribute
@@ -136,7 +134,7 @@ class AttributesToken extends index_2.Token {
136
134
  * @param key attribute name / 属性键
137
135
  */
138
136
  getAttr(key) {
139
- LINT: return this.getAttrToken(key)?.getValue();
137
+ return this.getAttrToken(key)?.getValue();
140
138
  }
141
139
  /** 是否位于闭合标签内 */
142
140
  #lint() {
@@ -144,9 +142,24 @@ class AttributesToken extends index_2.Token {
144
142
  return parentNode?.type === 'html' && parentNode.closing && this.text().trim() !== '';
145
143
  }
146
144
  /** @private */
145
+ lintRef(rect, severity) {
146
+ LINT: {
147
+ const followAttr = this.getAttrToken('follow'), follow = followAttr?.getValue(), name = this.getAttr('name'), rule = 'invalid-ref';
148
+ if (follow && !/\D/u.test(follow)) {
149
+ const msg = 'int-name';
150
+ return rect ? (0, lint_1.generateForChild)(followAttr, rect, rule, msg, severity) : msg;
151
+ }
152
+ else if (follow && (this.hasAttr('details') || name && /\D/u.test(name))) {
153
+ const msg = 'ref-follow';
154
+ return rect ? (0, lint_1.generateForSelf)(this, rect, rule, msg, severity) : msg;
155
+ }
156
+ return '';
157
+ }
158
+ }
159
+ /** @private */
147
160
  lint(start = this.getAbsoluteIndex(), re) {
148
161
  LINT: {
149
- const errors = super.lint(start, re), { parentNode, childNodes, type, name: tag } = this, attrs = new Map(), duplicated = new Set(), rect = new rect_1.BoundingRect(this, start), rules = ['no-ignored', 'required-attr', 'no-duplicate'], { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, s = ['closingTag', 'invalidAttributes', 'nonWordAttributes']
162
+ const errors = super.lint(start, re), { parentNode, childNodes, type, name: tag } = this, attrs = new Map(), duplicated = new Set(), rect = new rect_1.BoundingRect(this, start), rules = ['no-ignored', 'required-attr', 'invalid-ref', 'no-duplicate'], { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, s = ['closingTag', 'invalidAttributes', 'nonWordAttributes']
150
163
  .map(k => lintConfig.getSeverity(rules[0], k));
151
164
  if (s[0] && this.#lint()) {
152
165
  const e = (0, lint_1.generateForSelf)(this, rect, rules[0], 'attributes-of-closing-tag', s[0]);
@@ -192,23 +205,36 @@ class AttributesToken extends index_2.Token {
192
205
  }
193
206
  }
194
207
  }
195
- const severity = lintConfig.getSeverity(rules[2], 'attribute');
208
+ if (tag === 'ref') {
209
+ const severity = lintConfig.getSeverity(rules[2]);
210
+ if (severity) {
211
+ const e = this.lintRef(rect, severity);
212
+ if (e) {
213
+ errors.push(e);
214
+ }
215
+ }
216
+ }
217
+ const severity = lintConfig.getSeverity(rules[3], 'attribute');
196
218
  if (severity && duplicated.size > 0) {
197
219
  for (const key of duplicated) {
198
- const pairs = attrs.get(key).map(attr => [attr, attr.getValue()]);
199
- Array.prototype.push.apply(errors, pairs.map(([attr, value], i) => {
200
- const e = (0, lint_1.generateForChild)(attr, rect, rules[2], index_1.default.msg('duplicate-attribute', key), severity);
220
+ const pairs = attrs.get(key).map(attr => [attr, attr.getValue()]), duplication = Array.from({ length: pairs.length }), values = new Set();
221
+ for (let i = pairs.length - 1; i >= 0; i--) {
222
+ const [attr, value] = pairs[i], e = (0, lint_1.generateForChild)(attr, rect, rules[3], index_1.default.msg('duplicate-attribute', key), severity);
201
223
  if (computeEditInfo || fix) {
202
224
  const remove = (0, lint_1.fixByRemove)(e);
203
- if (!value || pairs.slice(0, i).some(([, v]) => v === value)) {
225
+ if (!value || values.has(value)) {
204
226
  e.fix = remove;
205
227
  }
206
- else if (computeEditInfo) {
207
- e.suggestions = [remove];
228
+ else {
229
+ values.add(value);
230
+ if (computeEditInfo) {
231
+ e.suggestions = [remove];
232
+ }
208
233
  }
209
234
  }
210
- return e;
211
- }));
235
+ duplication[i] = e;
236
+ }
237
+ Array.prototype.push.apply(errors, duplication);
212
238
  }
213
239
  }
214
240
  return errors;
@@ -7,6 +7,7 @@ import type { AstText, AttributesToken, ExtToken } from '../internal';
7
7
  * @classdesc `{childNodes: (AstText|CommentToken)[]}`
8
8
  */
9
9
  export declare abstract class CommentedToken extends Token {
10
+ readonly name: 'hiero';
10
11
  readonly childNodes: readonly (CommentToken | AstText)[];
11
12
  abstract get firstChild(): CommentToken | AstText | undefined;
12
13
  abstract get lastChild(): CommentToken | AstText | undefined;
@@ -13,9 +13,7 @@ class CommentedToken extends index_1.Token {
13
13
  }
14
14
  /** @class */
15
15
  constructor(wikitext, config, accum = []) {
16
- super(undefined, config, accum, {
17
- AstText: ':', CommentToken: ':',
18
- });
16
+ super(undefined, config, accum, {});
19
17
  if (wikitext) {
20
18
  let i = wikitext.indexOf('<!--'), j = i !== -1 && wikitext.indexOf('-->', i + 4), lastIndex = 0;
21
19
  while (j !== false && j !== -1) {
@@ -39,6 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.ConverterFlagsToken = void 0;
41
41
  const lint_1 = require("../util/lint");
42
+ const string_1 = require("../util/string");
42
43
  const rect_1 = require("../lib/rect");
43
44
  const gapped_1 = require("../mixin/gapped");
44
45
  const noEscape_1 = require("../mixin/noEscape");
@@ -76,9 +77,13 @@ let ConverterFlagsToken = (() => {
76
77
  super(undefined, config, accum, {});
77
78
  this.safeAppend(flags.map(flag => new atom_1.AtomToken(flag, 'converter-flag', config, accum)));
78
79
  }
80
+ /** 获取全部转换类型标记 */
81
+ #getFlags() {
82
+ return this.childNodes.map(child => child.text().trim());
83
+ }
79
84
  /** @private */
80
85
  afterBuild() {
81
- this.#flags = this.childNodes.map(child => child.text().trim());
86
+ this.#flags = this.#getFlags();
82
87
  super.afterBuild();
83
88
  }
84
89
  /** @private */
@@ -87,7 +92,7 @@ let ConverterFlagsToken = (() => {
87
92
  }
88
93
  /** @private */
89
94
  text() {
90
- return super.text(';');
95
+ return (this.#flags ?? this.#getFlags()).join(';');
91
96
  }
92
97
  /**
93
98
  * Get unknown language conversion flags
@@ -97,20 +102,24 @@ let ConverterFlagsToken = (() => {
97
102
  getUnknownFlags() {
98
103
  return new Set(this.#flags.filter(flag => /\{{3}[^{}]+\}{3}/u.test(flag)));
99
104
  }
105
+ /** 从解析设置中获取语言变体 */
106
+ #getVariants() {
107
+ return new Set((0, string_1.toLowerCase)(this.getAttribute('config').variants));
108
+ }
100
109
  /**
101
110
  * Get language coversion flags that specify a language variant
102
111
  *
103
112
  * 获取指定语言变体的转换标记
104
113
  */
105
114
  getVariantFlags() {
106
- const variants = new Set(this.getAttribute('config').variants);
107
- return new Set(this.#flags.filter(flag => variants.has(flag)));
115
+ const variants = this.#getVariants();
116
+ return new Set((0, string_1.toLowerCase)(this.#flags).filter(flag => variants.has(flag)));
108
117
  }
109
118
  /** @private */
110
119
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
111
120
  isInvalidFlag(flag, variant, unknown) {
112
121
  return Boolean(flag)
113
- && !variant.has(flag)
122
+ && !variant.has(flag.toLowerCase())
114
123
  && !unknown.has(flag)
115
124
  && (variant.size > 0 || !definedFlags.has(flag));
116
125
  }
@@ -124,9 +133,9 @@ let ConverterFlagsToken = (() => {
124
133
  }
125
134
  const rule = 'no-ignored', s = lintConfig.getSeverity(rule, 'conversionFlag');
126
135
  if (s) {
127
- const rect = new rect_1.BoundingRect(this, start);
128
- for (let i = 0; i < this.length; i++) {
129
- const child = this.childNodes[i], flag = child.text().trim();
136
+ const rect = new rect_1.BoundingRect(this, start), { childNodes, length } = this;
137
+ for (let i = 0; i < length; i++) {
138
+ const child = childNodes[i], flag = child.text().trim();
130
139
  if (this.isInvalidFlag(flag, variantFlags, unknownFlags)) {
131
140
  const e = (0, lint_1.generateForChild)(child, rect, rule, 'invalid-conversion-flag', s);
132
141
  if (computeEditInfo || fix) {
@@ -87,7 +87,7 @@ let ConverterRuleToken = (() => {
87
87
  constructor(rule, hasColon = true, config = index_1.default.getConfig(), accum = []) {
88
88
  super(undefined, config, accum, {});
89
89
  const i = rule.indexOf(':'), j = rule.slice(0, i).indexOf('=>'), v = j === -1 ? rule.slice(0, i) : rule.slice(j + 2, i);
90
- if (hasColon && config.variants.includes(v.trim().toLowerCase())) {
90
+ if (hasColon && config.variants.includes(v.trim())) {
91
91
  super.insertAt(new atom_1.AtomToken(v, 'converter-rule-variant', config, accum));
92
92
  super.insertAt(getRuleFromTo(rule.slice(i + 1), 'to', config, accum));
93
93
  if (j !== -1) {
@@ -109,8 +109,8 @@ let ConverterRuleToken = (() => {
109
109
  text() {
110
110
  const { childNodes, firstChild, lastChild } = this;
111
111
  return childNodes.length === 3
112
- ? `${firstChild.text()}=>${childNodes[1].text()}:${lastChild.text()}`
113
- : super.text(':');
112
+ ? `${firstChild.text().trim()}=>${childNodes[1].text().trim()}:${lastChild.text().trim()}`
113
+ : childNodes.map(child => child.text().trim()).join(':');
114
114
  }
115
115
  /** @private */
116
116
  getGaps(i) {
@@ -0,0 +1,23 @@
1
+ import { Token } from './index';
2
+ import { ParamLineToken } from './paramLine';
3
+ import type { Config } from '../base';
4
+ import type { AttributesToken, ExtToken } from '../internal';
5
+ import type { ParamLineParentBase } from '../mixin/paramLineParent';
6
+ export interface FuncTagToken extends ParamLineParentBase {
7
+ }
8
+ /**
9
+ * `<seo>`
10
+ * @classdesc `{childNodes: ParamLineToken[]}`
11
+ */
12
+ export declare abstract class FuncTagToken extends Token {
13
+ readonly name: 'seo';
14
+ readonly childNodes: readonly ParamLineToken[];
15
+ abstract get firstChild(): ParamLineToken | undefined;
16
+ abstract get lastChild(): ParamLineToken | undefined;
17
+ abstract get nextSibling(): undefined;
18
+ abstract get previousSibling(): AttributesToken | undefined;
19
+ abstract get parentNode(): ExtToken | undefined;
20
+ get type(): 'ext-inner';
21
+ /** @class */
22
+ constructor(wikitext: string | undefined, config: Config, accum: Token[]);
23
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.FuncTagToken = void 0;
38
+ const paramLineParent_1 = require("../mixin/paramLineParent");
39
+ const index_1 = require("./index");
40
+ const paramLine_1 = require("./paramLine");
41
+ const gapped_1 = require("../mixin/gapped");
42
+ /**
43
+ * `<seo>`
44
+ * @classdesc `{childNodes: ParamLineToken[]}`
45
+ */
46
+ let FuncTagToken = (() => {
47
+ let _classDecorators = [(0, gapped_1.gapped)(), paramLineParent_1.paramLineParent];
48
+ let _classDescriptor;
49
+ let _classExtraInitializers = [];
50
+ let _classThis;
51
+ let _classSuper = index_1.Token;
52
+ var FuncTagToken = class extends _classSuper {
53
+ static { _classThis = this; }
54
+ static {
55
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
56
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
57
+ FuncTagToken = _classThis = _classDescriptor.value;
58
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
59
+ __runInitializers(_classThis, _classExtraInitializers);
60
+ }
61
+ get type() {
62
+ return 'ext-inner';
63
+ }
64
+ /** @class */
65
+ constructor(wikitext, config, accum) {
66
+ super(undefined, config, accum, {});
67
+ if (wikitext) {
68
+ for (const parameter of wikitext.split('|')) {
69
+ // @ts-expect-error abstract class
70
+ this.insertAt(new paramLine_1.ParamLineToken('seo', parameter, config, accum));
71
+ }
72
+ }
73
+ }
74
+ /** @private */
75
+ toString(skip) {
76
+ return super.toString(skip, '|');
77
+ }
78
+ /** @private */
79
+ text() {
80
+ return this.childNodes.map(child => child.text()).filter(Boolean).join('|');
81
+ }
82
+ };
83
+ return FuncTagToken = _classThis;
84
+ })();
85
+ exports.FuncTagToken = FuncTagToken;
@@ -100,7 +100,7 @@ let HeadingToken = (() => {
100
100
  /** @private */
101
101
  text() {
102
102
  const equals = this.#getEquals();
103
- return equals + this.firstChild.text() + equals;
103
+ return equals + this.firstChild.text().trim() + equals;
104
104
  }
105
105
  /** @private */
106
106
  getAttribute(key) {
@@ -110,10 +110,15 @@ let HeadingToken = (() => {
110
110
  getGaps() {
111
111
  return this.level;
112
112
  }
113
+ /** 是否包含未成对的`=` */
114
+ #lint() {
115
+ const innerStr = this.firstChild.toString(), unbalancedStart = innerStr.startsWith('=');
116
+ return unbalancedStart ? 1 : innerStr.endsWith('=');
117
+ }
113
118
  /** @private */
114
119
  lint(start = this.getAbsoluteIndex(), re) {
115
120
  LINT: {
116
- const errors = super.lint(start, re), { firstChild, level } = this, innerStr = firstChild.toString(), unbalancedStart = innerStr.startsWith('='), unbalanced = unbalancedStart || innerStr.endsWith('='), rect = new rect_1.BoundingRect(this, start), s = this.inHtmlAttrs(), rules = ['h1', 'unbalanced-header', 'format-leakage'], { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, severities = rules.map(rule => lintConfig.getSeverity(rule, 'apostrophe'));
121
+ const errors = super.lint(start, re), { firstChild, level } = this, innerStr = firstChild.toString(), unbalanced = this.#lint(), rect = new rect_1.BoundingRect(this, start), s = this.inHtmlAttrs(), rules = ['h1', 'unbalanced-header', 'format-leakage'], { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, severities = rules.map(rule => lintConfig.getSeverity(rule, 'apostrophe'));
117
122
  if (severities[0] && this.level === 1) {
118
123
  const e = (0, lint_1.generateForChild)(firstChild, rect, rules[0], '<h1>', severities[0]);
119
124
  if (computeEditInfo && !unbalanced) {
@@ -126,7 +131,7 @@ let HeadingToken = (() => {
126
131
  if (!computeEditInfo || innerStr === '=') {
127
132
  //
128
133
  }
129
- else if (unbalancedStart) {
134
+ else if (unbalanced === 1) {
130
135
  const extra = (0, common_1.numLeadingSpaces)(innerStr, /[^=]|$/u), newLevel = level + extra;
131
136
  e.suggestions = [{ desc: `h${level}`, range: [e.startIndex, e.startIndex + extra], text: '' }];
132
137
  if (newLevel < 7) {
@@ -1,8 +1,9 @@
1
1
  import { Token } from './index';
2
+ import type { LintError } from '../base';
2
3
  /**
3
- * invisible token
4
+ * invisible token in triple braces
4
5
  *
5
- * 不可见的节点
6
+ * 三重括号内不可见的节点
6
7
  */
7
8
  export declare class HiddenToken extends Token {
8
9
  get type(): 'hidden';
@@ -33,22 +33,27 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
33
33
  }
34
34
  return useValue ? value : void 0;
35
35
  };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
36
39
  Object.defineProperty(exports, "__esModule", { value: true });
37
40
  exports.HiddenToken = void 0;
41
+ const lint_1 = require("../util/lint");
38
42
  const hidden_1 = require("../mixin/hidden");
39
43
  const noEscape_1 = require("../mixin/noEscape");
40
- const index_1 = require("./index");
44
+ const index_1 = __importDefault(require("../index"));
45
+ const index_2 = require("./index");
41
46
  /**
42
- * invisible token
47
+ * invisible token in triple braces
43
48
  *
44
- * 不可见的节点
49
+ * 三重括号内不可见的节点
45
50
  */
46
51
  let HiddenToken = (() => {
47
- let _classDecorators = [(0, hidden_1.hiddenToken)(), noEscape_1.noEscape];
52
+ let _classDecorators = [(0, hidden_1.hiddenToken)(false), noEscape_1.noEscape];
48
53
  let _classDescriptor;
49
54
  let _classExtraInitializers = [];
50
55
  let _classThis;
51
- let _classSuper = index_1.Token;
56
+ let _classSuper = index_2.Token;
52
57
  var HiddenToken = class extends _classSuper {
53
58
  static { _classThis = this; }
54
59
  static {
@@ -61,6 +66,25 @@ let HiddenToken = (() => {
61
66
  get type() {
62
67
  return 'hidden';
63
68
  }
69
+ /** @private */
70
+ lint(start = this.getAbsoluteIndex()) {
71
+ LINT: {
72
+ const rule = 'no-ignored', { lintConfig } = index_1.default, s = lintConfig.getSeverity(rule, 'arg');
73
+ if (s) {
74
+ const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'invisible-triple-braces', s);
75
+ e.startIndex--;
76
+ e.startCol--;
77
+ if (lintConfig.computeEditInfo) {
78
+ e.suggestions = [
79
+ (0, lint_1.fixByRemove)(e),
80
+ (0, lint_1.fixByEscape)(e.startIndex, '{{!}}'),
81
+ ];
82
+ }
83
+ return [e];
84
+ }
85
+ return [];
86
+ }
87
+ }
64
88
  };
65
89
  return HiddenToken = _classThis;
66
90
  })();