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
@@ -1,25 +1,72 @@
1
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
+ };
2
36
  Object.defineProperty(exports, "__esModule", { value: true });
3
37
  exports.ParamTagToken = void 0;
4
- const commentAndExt_1 = require("../../parser/commentAndExt");
38
+ const paramLineParent_1 = require("../../mixin/paramLineParent");
5
39
  const index_1 = require("./index");
6
40
  const paramLine_1 = require("../paramLine");
7
41
  /**
8
42
  * `<dynamicpagelist>`
9
43
  * @classdesc `{childNodes: ParamLineToken[]}`
10
44
  */
11
- class ParamTagToken extends index_1.MultiLineToken {
12
- /** @param name 扩展标签名 */
13
- constructor(name, include, wikitext, config, accum = [], acceptable) {
14
- super(undefined, config, accum, {});
15
- if (wikitext) {
16
- this.safeAppend(wikitext.split('\n')
17
- .map(line => acceptable ? line : (0, commentAndExt_1.parseCommentAndExt)(line, config, accum, include))
45
+ let ParamTagToken = (() => {
46
+ let _classDecorators = [paramLineParent_1.paramLineParent];
47
+ let _classDescriptor;
48
+ let _classExtraInitializers = [];
49
+ let _classThis;
50
+ let _classSuper = index_1.MultiLineToken;
51
+ var ParamTagToken = class extends _classSuper {
52
+ static { _classThis = this; }
53
+ static {
54
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
55
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
56
+ ParamTagToken = _classThis = _classDescriptor.value;
57
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
58
+ __runInitializers(_classThis, _classExtraInitializers);
59
+ }
60
+ /** @param name 扩展标签名 */
61
+ constructor(name, include, wikitext, config, accum = [], acceptable) {
62
+ super(undefined, config, accum, {});
63
+ if (wikitext) {
64
+ this.safeAppend(
18
65
  // @ts-expect-error abstract class
19
- .map((line) => new paramLine_1.ParamLineToken(name, line, config, accum, {})));
66
+ wikitext.split('\n').map((line) => new paramLine_1.ParamLineToken(name, line, config, accum)));
67
+ }
20
68
  }
21
- accum.splice(accum.indexOf(this), 1);
22
- accum.push(this);
23
- }
24
- }
69
+ };
70
+ return ParamTagToken = _classThis;
71
+ })();
25
72
  exports.ParamTagToken = ParamTagToken;
@@ -60,17 +60,17 @@ class NestedToken extends index_2.Token {
60
60
  /** @private */
61
61
  lint(start = this.getAbsoluteIndex(), re) {
62
62
  LINT: {
63
- const errors = super.lint(start, re), rule = 'no-ignored', { lintConfig } = index_1.default, s = lintConfig.getSeverity(rule, this.name);
63
+ const errors = super.lint(start, re), rule = 'no-ignored', { lintConfig } = index_1.default, { computeEditInfo } = lintConfig, { name, childNodes } = this, s = lintConfig.getSeverity(rule, name);
64
64
  if (!s) {
65
65
  return errors;
66
66
  }
67
- const rect = new rect_1.BoundingRect(this, start), regex = typeof this.#regex === 'boolean' ? lintRegex[this.#regex ? 1 : 0] : /^<!--[\s\S]*-->$/u;
67
+ const rect = new rect_1.BoundingRect(this, start), msg = index_1.default.msg('invalid-content', name), regex = typeof this.#regex === 'boolean' ? lintRegex[this.#regex ? 1 : 0] : /^<!--[\s\S]*-->$/u;
68
68
  return [
69
69
  ...errors,
70
- ...this.childNodes.filter(child => {
71
- const { type, name } = child;
70
+ ...childNodes.filter(child => {
71
+ const { type, name: n } = child;
72
72
  if (type === 'ext') {
73
- return !this.#tags.includes(name);
73
+ return !this.#tags.includes(n);
74
74
  }
75
75
  else if (childTypes.has(type)) {
76
76
  return false;
@@ -78,8 +78,8 @@ class NestedToken extends index_2.Token {
78
78
  const str = child.toString().trim();
79
79
  return str && !regex.test(str);
80
80
  }).map(child => {
81
- const e = (0, lint_1.generateForChild)(child, rect, rule, index_1.default.msg('invalid-content', this.name), s);
82
- if (lintConfig.computeEditInfo) {
81
+ const e = (0, lint_1.generateForChild)(child, rect, rule, msg, s);
82
+ if (computeEditInfo) {
83
83
  e.suggestions = [
84
84
  (0, lint_1.fixByRemove)(e),
85
85
  (0, lint_1.fixByComment)(e, child.toString()),
@@ -1,6 +1,7 @@
1
1
  import { NowikiBaseToken } from './base';
2
2
  import type { LintError } from '../../base';
3
3
  import type { AttributesToken, ExtToken } from '../../internal';
4
+ import type { TexvcReport } from '../../lib/document';
4
5
  /**
5
6
  * text-only token inside an extension tag
6
7
  *
@@ -44,9 +44,7 @@ class NowikiToken extends base_1.NowikiBaseToken {
44
44
  /** @private */
45
45
  lint(start = this.getAbsoluteIndex()) {
46
46
  LINT: {
47
- const { name, innerText,
48
- /* NOT FOR BROWSER ONLY */
49
- previousSibling, } = this, { lintConfig } = index_1.default;
47
+ const { name, innerText } = this, { lintConfig } = index_1.default;
50
48
  let rule = 'void-ext', s = lintConfig.getSeverity(rule, name);
51
49
  if (s && this.#lint()) {
52
50
  const e = (0, lint_1.generateForSelf)(this, { start }, rule, index_1.default.msg('nothing-in', name), s);
@@ -82,31 +80,9 @@ class NowikiToken extends base_1.NowikiBaseToken {
82
80
  rule = 'invalid-math';
83
81
  s = lintConfig.getSeverity(rule);
84
82
  if (s && constants_2.mathTags.has(name)) {
85
- const texvcjs = (0, document_1.loadTexvcjs)();
86
- if (texvcjs) {
87
- const isChem = name !== 'math', display = previousSibling?.getAttr('display') ?? 'block';
88
- let tex = innerText, n = 0;
89
- if (isChem) {
90
- tex = String.raw `\ce{${tex}}`;
91
- n = 4;
92
- }
93
- switch (display) {
94
- case 'block':
95
- tex = String.raw `{\displaystyle ${tex}}`;
96
- n += 15;
97
- break;
98
- case 'inline':
99
- tex = String.raw `{\textstyle ${tex}}`;
100
- n += 12;
101
- break;
102
- case 'linebreak':
103
- tex = String.raw `\[ ${tex} \]`;
104
- n += 3;
105
- // no default
106
- }
107
- const result = texvcjs.check(tex, {
108
- usemhchem: isChem || Boolean(previousSibling?.hasAttr('chem')),
109
- });
83
+ const report = this.texvcCheck();
84
+ if (report) {
85
+ const [result, n] = report;
110
86
  if (result.status === '+') {
111
87
  return [];
112
88
  }
@@ -125,5 +101,40 @@ class NowikiToken extends base_1.NowikiBaseToken {
125
101
  return super.lint(start, getLintRegex(name));
126
102
  }
127
103
  }
104
+ /* NOT FOR BROWSER ONLY */
105
+ /** @private */
106
+ texvcCheck() {
107
+ const texvcjs = (0, document_1.loadTexvcjs)();
108
+ if (!texvcjs) {
109
+ return undefined;
110
+ }
111
+ let tex = this.innerText, n = 0;
112
+ if (this.name !== 'math') {
113
+ tex = String.raw `\ce{${tex}}`;
114
+ n = 4;
115
+ }
116
+ switch (this.previousSibling?.getAttr('display') ?? 'block') {
117
+ case 'block':
118
+ tex = String.raw `{\displaystyle ${tex}}`;
119
+ n += 15;
120
+ break;
121
+ case 'inline':
122
+ tex = String.raw `{\textstyle ${tex}}`;
123
+ n += 12;
124
+ break;
125
+ case 'linebreak':
126
+ tex = String.raw `\[ ${tex} \]`;
127
+ n += 3;
128
+ // no default
129
+ }
130
+ return [
131
+ texvcjs.check(tex, {
132
+ usemathrm: true,
133
+ usemhchem: this.name !== 'math' || Boolean(this.previousSibling?.hasAttr('chem')),
134
+ }),
135
+ n,
136
+ tex,
137
+ ];
138
+ }
128
139
  }
129
140
  exports.NowikiToken = NowikiToken;
@@ -44,11 +44,6 @@ class QuoteToken extends base_1.NowikiBaseToken {
44
44
  this.#closing = closing;
45
45
  }
46
46
  /** @private */
47
- text() {
48
- const { parentNode, innerText } = this;
49
- return parentNode?.is('image-parameter') && parentNode.name !== 'caption' ? '' : innerText;
50
- }
51
- /** @private */
52
47
  lint(start = this.getAbsoluteIndex()) {
53
48
  LINT: {
54
49
  const { previousSibling, bold, closing } = this, previousData = previousSibling?.type === 'text' ? previousSibling.data : undefined, errors = [], rect = new rect_1.BoundingRect(this, start), rules = ['lonely-apos', 'bold-header'], { lintConfig } = index_1.default, { computeEditInfo } = lintConfig, severities = [undefined, 'word'].map(key => lintConfig.getSeverity(rules[0], key)), s = lintConfig.getSeverity(rules[1]);
@@ -82,5 +77,11 @@ class QuoteToken extends base_1.NowikiBaseToken {
82
77
  return errors;
83
78
  }
84
79
  }
80
+ /* NOT FOR BROWSER ONLY */
81
+ /** @private */
82
+ text() {
83
+ const { parentNode, innerText } = this;
84
+ return parentNode?.is('image-parameter') && parentNode.name !== 'caption' ? '' : innerText;
85
+ }
85
86
  }
86
87
  exports.QuoteToken = QuoteToken;
@@ -1,16 +1,30 @@
1
1
  import { Token } from './index';
2
+ import { AtomToken } from './atom';
2
3
  import type { Config, LintError } from '../base';
3
- import type { ParamTagToken } from '../internal';
4
+ import type { ParamTagToken, FuncTagToken } from '../internal';
4
5
  /**
5
6
  * parameter of certain extension tags
6
7
  *
7
8
  * 某些扩展标签的参数
9
+ * @classdesc `{childNodes: [AtomToken] | [AtomToken, AtomToken]}`
8
10
  */
9
11
  export declare abstract class ParamLineToken extends Token {
10
- abstract get parentNode(): ParamTagToken | undefined;
12
+ readonly name: string;
13
+ readonly childNodes: readonly [AtomToken] | readonly [AtomToken, AtomToken];
14
+ abstract get firstChild(): AtomToken;
15
+ abstract get lastChild(): AtomToken;
16
+ abstract get parentNode(): ParamTagToken | FuncTagToken | undefined;
11
17
  abstract get nextSibling(): this | undefined;
12
18
  abstract get previousSibling(): this | undefined;
13
19
  get type(): 'param-line';
20
+ /** A reasonable parameter name / 合理的参数名 */
21
+ get key(): string | undefined;
14
22
  /** @param name 扩展标签名 */
15
- constructor(name: string, wikitext: string | undefined, config: Config, accum: Token[], acceptable: WikiParserAcceptable);
23
+ constructor(name: string, wikitext: string, config: Config, accum: Token[], acceptable?: WikiParserAcceptable);
24
+ /**
25
+ * Get a reasonable parameter name
26
+ *
27
+ * 获取合理的参数名
28
+ */
29
+ getKey(): string | undefined;
16
30
  }
@@ -1,4 +1,38 @@
1
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
+ };
2
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
38
  };
@@ -6,51 +40,109 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
40
  exports.ParamLineToken = void 0;
7
41
  const lint_1 = require("../util/lint");
8
42
  const sharable_1 = require("../util/sharable");
43
+ const gapped_1 = require("../mixin/gapped");
9
44
  const index_1 = __importDefault(require("../index"));
10
45
  const index_2 = require("./index");
46
+ const atom_1 = require("./atom");
47
+ const skipTypes = new Set(['comment', 'include', 'noinclude']);
11
48
  /**
12
49
  * parameter of certain extension tags
13
50
  *
14
51
  * 某些扩展标签的参数
52
+ * @classdesc `{childNodes: [AtomToken] | [AtomToken, AtomToken]}`
15
53
  */
16
- class ParamLineToken extends index_2.Token {
17
- get type() {
18
- return 'param-line';
19
- }
20
- /** @param name 扩展标签名 */
21
- constructor(name, wikitext, config, accum, acceptable) {
22
- super(wikitext, config, accum, acceptable);
23
- this.setAttribute('name', name);
24
- }
25
- /** @private */
26
- lint(start = this.getAbsoluteIndex()) {
27
- LINT: {
28
- const rule = 'no-ignored', { lintConfig } = index_1.default, { name, childNodes } = this, s = lintConfig.getSeverity(rule, name);
29
- if (!s) {
30
- return [];
54
+ let ParamLineToken = (() => {
55
+ let _classDecorators = [(0, gapped_1.gapped)()];
56
+ let _classDescriptor;
57
+ let _classExtraInitializers = [];
58
+ let _classThis;
59
+ let _classSuper = index_2.Token;
60
+ var ParamLineToken = class extends _classSuper {
61
+ static { _classThis = this; }
62
+ static {
63
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
64
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
65
+ ParamLineToken = _classThis = _classDescriptor.value;
66
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
67
+ __runInitializers(_classThis, _classExtraInitializers);
68
+ }
69
+ get type() {
70
+ return 'param-line';
71
+ }
72
+ /** A reasonable parameter name / 合理的参数名 */
73
+ get key() {
74
+ LINT: return this.getKey();
75
+ }
76
+ /** @param name 扩展标签名 */
77
+ constructor(name, wikitext, config, accum, acceptable = {}) {
78
+ super(undefined, config, accum, {});
79
+ this.setAttribute('name', name);
80
+ const equal = wikitext.indexOf('=');
81
+ if (equal === -1) {
82
+ this.insertAt(new atom_1.AtomToken(wikitext, 'param-line-key', config, accum, acceptable));
31
83
  }
32
- const msg = index_1.default.msg('invalid-parameter', name);
33
- if (childNodes.some(({ type }) => type === 'ext')) {
34
- return [(0, lint_1.generateForSelf)(this, { start }, rule, msg, s)];
84
+ else {
85
+ this.append(new atom_1.AtomToken(wikitext.slice(0, equal), 'param-line-key', config, accum, acceptable), new atom_1.AtomToken(wikitext.slice(equal + 1), 'param-line-value', config, accum, acceptable));
35
86
  }
36
- const children = childNodes
37
- .filter(({ type }) => type !== 'comment' && type !== 'include' && type !== 'noinclude'), isInputbox = name === 'inputbox', i = isInputbox ? children.findIndex(({ type }) => type !== 'text') : -1;
38
- let str = children.slice(0, i === -1 ? undefined : i).map(String).join('').trim();
39
- if (str) {
40
- if (isInputbox) {
41
- str = str.toLowerCase();
87
+ }
88
+ /** @private */
89
+ toString(skip) {
90
+ return super.toString(skip, '=');
91
+ }
92
+ /** @private */
93
+ text() {
94
+ return this.childNodes.map(child => child.text().trim()).join('=');
95
+ }
96
+ /** @private */
97
+ lint(start = this.getAbsoluteIndex()) {
98
+ LINT: {
99
+ const rule = 'no-ignored', { lintConfig } = index_1.default, { name, length, firstChild: { childNodes }, previousSibling } = this, s = lintConfig.getSeverity(rule, name);
100
+ if (!s) {
101
+ return [];
102
+ }
103
+ const children = childNodes.filter(({ type }) => !skipTypes.has(type)), i = children.findIndex(({ type }) => type !== 'text');
104
+ let key = children.slice(0, i === -1 ? undefined : i).map(String).join('').trim(), wrong = false;
105
+ if (childNodes.some(({ type }) => type === 'ext') || length === 1 && i === -1 && key) {
106
+ wrong = true;
107
+ }
108
+ else if (key || length === 2) {
109
+ if (name === 'inputbox') {
110
+ key = key.toLowerCase();
111
+ }
112
+ const params = sharable_1.extParams[name];
113
+ if (i === -1
114
+ ? !params.some(p => p === key
115
+ || p.endsWith('$1') && key.startsWith(p.slice(0, -2)))
116
+ : !params.some(p => p.startsWith(key))) {
117
+ wrong = true;
118
+ }
42
119
  }
43
- const j = str.indexOf('='), key = str.slice(0, j === -1 ? undefined : j).trim(), params = sharable_1.extParams[name];
44
- if (j === -1 ? i === -1 || !params.some(p => p.startsWith(key)) : !params.includes(key)) {
45
- const e = (0, lint_1.generateForSelf)(this, { start }, rule, msg, s);
120
+ if (wrong) {
121
+ const e = (0, lint_1.generateForSelf)(this, { start }, rule, index_1.default.msg('invalid-parameter', name), s);
46
122
  if (lintConfig.computeEditInfo) {
47
- e.suggestions = [(0, lint_1.fixByRemove)(e)];
123
+ e.suggestions = [(0, lint_1.fixByRemove)(e, previousSibling ? -1 : 0)];
48
124
  }
49
125
  return [e];
50
126
  }
127
+ return super.lint(start, false);
51
128
  }
52
- return super.lint(start, false);
53
129
  }
54
- }
55
- }
130
+ /**
131
+ * Get a reasonable parameter name
132
+ *
133
+ * 获取合理的参数名
134
+ */
135
+ getKey() {
136
+ LINT: {
137
+ const { length, firstChild: { childNodes }, name } = this, isInputbox = name === 'inputbox';
138
+ return length === 1 || childNodes.some(({ type }) => type === 'ext')
139
+ ? undefined
140
+ : childNodes.map(child => isInputbox && child.type === 'text' ? child.data.toLowerCase() : child.text())
141
+ .join('')
142
+ .trim();
143
+ }
144
+ }
145
+ };
146
+ return ParamLineToken = _classThis;
147
+ })();
56
148
  exports.ParamLineToken = ParamLineToken;
@@ -23,4 +23,10 @@ export declare abstract class ParameterToken extends Token {
23
23
  * @param value 参数值
24
24
  */
25
25
  constructor(key?: string | number, value?: string, config?: Config, accum?: Token[]);
26
+ /**
27
+ * Get the parameter value
28
+ *
29
+ * 获取参数值
30
+ */
31
+ getValue(): string;
26
32
  }
@@ -61,7 +61,9 @@ class ParameterToken extends index_2.Token {
61
61
  }
62
62
  /** @private */
63
63
  text() {
64
- return this.anon ? this.lastChild.text() : super.text('=');
64
+ return this.anon
65
+ ? this.getValue()
66
+ : this.childNodes.map(child => child.text().trim()).join('=');
65
67
  }
66
68
  /** @private */
67
69
  getGaps() {
@@ -92,5 +94,17 @@ class ParameterToken extends index_2.Token {
92
94
  return errors;
93
95
  }
94
96
  }
97
+ /**
98
+ * Get the parameter value
99
+ *
100
+ * 获取参数值
101
+ */
102
+ getValue() {
103
+ const { parentNode, lastChild, anon, name } = this, value = (0, string_1.removeCommentLine)(lastChild.text());
104
+ return anon && (parentNode?.isTemplate() !== false
105
+ || name === '2' && parentNode.type === 'magic-word' && parentNode.name === 'tag')
106
+ ? value
107
+ : value.trim();
108
+ }
95
109
  }
96
110
  exports.ParameterToken = ParameterToken;
@@ -0,0 +1,21 @@
1
+ import { SingleLineToken } from './index';
2
+ import { ExtToken } from '../tagPair/ext';
3
+ import type { Config, LintError } from '../../base';
4
+ import type { Token, CharinsertToken, AstText } from '../../internal';
5
+ /**
6
+ * lines in `<charinsert>`
7
+ *
8
+ * `<charinsert>` 的行
9
+ * @classdesc `{childNodes: (AstText | ExtToken)[]}`
10
+ */
11
+ export declare abstract class CharinsertLineToken extends SingleLineToken {
12
+ readonly childNodes: readonly (AstText | ExtToken)[];
13
+ abstract get firstChild(): AstText | ExtToken | undefined;
14
+ abstract get lastChild(): AstText | ExtToken | undefined;
15
+ abstract get parentNode(): CharinsertToken | undefined;
16
+ abstract get previousSibling(): CharinsertLineToken | undefined;
17
+ abstract get nextSibling(): CharinsertLineToken | undefined;
18
+ get type(): 'charinsert-line';
19
+ /** @class */
20
+ constructor(wikitext: string | undefined, config: Config, accum: Token[]);
21
+ }
@@ -0,0 +1,69 @@
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.CharinsertLineToken = void 0;
7
+ const lint_1 = require("../../util/lint");
8
+ const rect_1 = require("../../lib/rect");
9
+ const index_1 = __importDefault(require("../../index"));
10
+ const index_2 = require("./index");
11
+ const ext_1 = require("../tagPair/ext");
12
+ /**
13
+ * lines in `<charinsert>`
14
+ *
15
+ * `<charinsert>` 的行
16
+ * @classdesc `{childNodes: (AstText | ExtToken)[]}`
17
+ */
18
+ class CharinsertLineToken extends index_2.SingleLineToken {
19
+ get type() {
20
+ return 'charinsert-line';
21
+ }
22
+ /** @class */
23
+ constructor(wikitext, config, accum) {
24
+ super(wikitext?.replace(/<(nowiki)>(.*?)<\/(nowiki)>/giu, (_, opening, content, closing) => {
25
+ // @ts-expect-error abstract class
26
+ new ext_1.ExtToken(opening, undefined, content, closing, config, false, accum);
27
+ return `\0${accum.length - 2}e\x7F`;
28
+ }), config, accum);
29
+ }
30
+ /** @private */
31
+ lint(start = this.getAbsoluteIndex()) {
32
+ LINT: {
33
+ const rule = 'no-ignored', s = index_1.default.lintConfig.getSeverity(rule, 'charinsert');
34
+ if (!s) {
35
+ return [];
36
+ }
37
+ const errors = [], str = this.childNodes.map(child => child.type === 'text'
38
+ ? child.data
39
+ : `<nowiki>${child.innerText.replace(/[^+]/gu, '_')}</nowiki>`).join(''), re = /(?:^|\s)\S+/gu, rect = new rect_1.BoundingRect(this, start), msg = index_1.default.msg('invalid-content', 'charinsert');
40
+ let mt = re.exec(str);
41
+ while (mt) {
42
+ const [item] = mt;
43
+ let i = item.indexOf('+');
44
+ if (i !== -1 && item.slice(0, i).trim()) {
45
+ i = item.indexOf('+', i + 1);
46
+ }
47
+ if (i !== -1) {
48
+ const e = (0, lint_1.generateForSelf)(this, rect, rule, msg, s), startOffset = mt.index + i, endOffset = mt.index + item.length;
49
+ e.endIndex = start + endOffset;
50
+ e.endCol = e.startCol + endOffset;
51
+ e.startIndex += startOffset;
52
+ e.startCol += startOffset;
53
+ errors.push(e);
54
+ }
55
+ mt = re.exec(str);
56
+ }
57
+ return errors;
58
+ }
59
+ }
60
+ /* NOT FOR BROWSER ONLY */
61
+ /** @private */
62
+ text() {
63
+ const entities = { '\t': '&#9;', '\r': '&#12;', ' ': '&#32;' };
64
+ return this.childNodes.map(child => child.type === 'text'
65
+ ? child.data
66
+ : child.innerText.replace(/[\t\r ]/gu, c => entities[c])).join('').trim().replace(/\n+/gu, ' ');
67
+ }
68
+ }
69
+ exports.CharinsertLineToken = CharinsertLineToken;
@@ -1,16 +1,17 @@
1
- import { Token } from './index';
2
- import { NoincludeToken } from './nowiki/noinclude';
3
- import { LinkToken } from './link/index';
4
- import { ExtLinkToken } from './extLink';
5
- import type { Config } from '../base';
6
- import type { AstText, ImagemapToken, GalleryImageToken } from '../internal';
1
+ import { SingleLineToken } from './index';
2
+ import { NoincludeToken } from '../nowiki/noinclude';
3
+ import { LinkToken } from '../link/index';
4
+ import { ExtLinkToken } from '../extLink';
5
+ import type { Config, LintError } from '../../base';
6
+ import type { AstText, ImagemapToken, GalleryImageToken, Token } from '../../internal';
7
7
  /**
8
8
  * link inside the `<imagemap>`
9
9
  *
10
10
  * `<imagemap>`内的链接
11
11
  * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
12
12
  */
13
- export declare abstract class ImagemapLinkToken extends Token {
13
+ export declare abstract class ImagemapLinkToken extends SingleLineToken {
14
+ #private;
14
15
  readonly childNodes: readonly [AstText, LinkToken | ExtLinkToken, NoincludeToken];
15
16
  abstract get firstChild(): AstText;
16
17
  abstract get lastChild(): NoincludeToken;