wikilint 2.18.4 → 2.20.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 (85) hide show
  1. package/config/default.json +49 -3
  2. package/config/minimum.json +5 -1
  3. package/data/ext/math.json +660 -0
  4. package/dist/base.d.mts +4 -3
  5. package/dist/base.d.ts +4 -3
  6. package/dist/bin/cli.js +19 -6
  7. package/dist/bin/config.js +26 -8
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.js +10 -1
  10. package/dist/internal.d.ts +2 -0
  11. package/dist/lib/document.d.ts +5 -0
  12. package/dist/lib/document.js +31 -1
  13. package/dist/lib/element.js +15 -4
  14. package/dist/lib/lsp.js +103 -41
  15. package/dist/lib/node.js +0 -7
  16. package/dist/lib/text.js +3 -7
  17. package/dist/lib/title.js +1 -6
  18. package/dist/mixin/attributesParent.js +1 -1
  19. package/dist/mixin/gapped.d.ts +4 -0
  20. package/dist/mixin/gapped.js +20 -0
  21. package/dist/mixin/hidden.js +1 -1
  22. package/dist/mixin/multiLine.d.ts +4 -0
  23. package/dist/mixin/multiLine.js +26 -0
  24. package/dist/mixin/padded.d.ts +5 -0
  25. package/dist/mixin/padded.js +20 -0
  26. package/dist/parser/braces.js +9 -13
  27. package/dist/parser/commentAndExt.js +18 -2
  28. package/dist/parser/magicLinks.js +1 -1
  29. package/dist/parser/selector.js +5 -2
  30. package/dist/src/arg.js +131 -84
  31. package/dist/src/attribute.js +4 -4
  32. package/dist/src/attributes.js +2 -2
  33. package/dist/src/commented.d.ts +19 -0
  34. package/dist/src/commented.js +41 -0
  35. package/dist/src/converter.js +90 -43
  36. package/dist/src/converterFlags.js +113 -66
  37. package/dist/src/converterRule.d.ts +1 -1
  38. package/dist/src/extLink.d.ts +2 -3
  39. package/dist/src/extLink.js +97 -54
  40. package/dist/src/gallery.d.ts +3 -4
  41. package/dist/src/gallery.js +114 -72
  42. package/dist/src/heading.js +10 -10
  43. package/dist/src/imageParameter.d.ts +1 -1
  44. package/dist/src/imageParameter.js +11 -8
  45. package/dist/src/imagemap.d.ts +1 -1
  46. package/dist/src/imagemap.js +126 -86
  47. package/dist/src/imagemapLink.d.ts +1 -1
  48. package/dist/src/index.js +18 -15
  49. package/dist/src/link/base.d.ts +2 -3
  50. package/dist/src/link/base.js +149 -105
  51. package/dist/src/link/file.d.ts +2 -3
  52. package/dist/src/link/file.js +2 -2
  53. package/dist/src/link/galleryImage.d.ts +2 -3
  54. package/dist/src/link/galleryImage.js +89 -47
  55. package/dist/src/nested.d.ts +1 -1
  56. package/dist/src/nowiki/comment.js +2 -5
  57. package/dist/src/nowiki/doubleUnderscore.js +2 -5
  58. package/dist/src/nowiki/index.d.ts +1 -1
  59. package/dist/src/nowiki/index.js +2 -1
  60. package/dist/src/onlyinclude.js +63 -15
  61. package/dist/src/paramTag/index.d.ts +1 -1
  62. package/dist/src/paramTag/index.js +89 -47
  63. package/dist/src/paramTag/inputbox.js +9 -4
  64. package/dist/src/parameter.d.ts +3 -4
  65. package/dist/src/parameter.js +4 -8
  66. package/dist/src/pre.d.ts +3 -4
  67. package/dist/src/pre.js +5 -9
  68. package/dist/src/syntax.d.ts +1 -1
  69. package/dist/src/table/base.d.ts +2 -2
  70. package/dist/src/table/base.js +3 -7
  71. package/dist/src/table/index.js +1 -1
  72. package/dist/src/table/td.d.ts +2 -3
  73. package/dist/src/table/td.js +3 -7
  74. package/dist/src/table/tr.d.ts +1 -1
  75. package/dist/src/tagPair/ext.js +38 -33
  76. package/dist/src/tagPair/index.d.ts +1 -1
  77. package/dist/src/tagPair/index.js +94 -47
  78. package/dist/src/tagPair/translate.d.ts +22 -0
  79. package/dist/src/tagPair/translate.js +48 -0
  80. package/dist/src/transclude.js +378 -332
  81. package/dist/util/lint.js +17 -30
  82. package/dist/util/sharable.js +29 -1
  83. package/dist/util/sharable.mjs +31 -3
  84. package/dist/util/string.js +14 -1
  85. package/package.json +8 -6
@@ -1,9 +1,44 @@
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
  };
5
39
  Object.defineProperty(exports, "__esModule", { value: true });
6
40
  exports.GalleryToken = void 0;
41
+ const multiLine_1 = require("../mixin/multiLine");
7
42
  const index_1 = __importDefault(require("../index"));
8
43
  const index_2 = require("./index");
9
44
  const galleryImage_1 = require("./link/galleryImage");
@@ -14,80 +49,87 @@ const noinclude_1 = require("./nowiki/noinclude");
14
49
  * gallery标签
15
50
  * @classdesc `{childNodes: (GalleryImageToken|NoincludeToken|AstText)[]}`
16
51
  */
17
- class GalleryToken extends index_2.Token {
18
- get type() {
19
- return 'ext-inner';
20
- }
21
- /** @param inner 标签内部wikitext */
22
- constructor(inner, config = index_1.default.getConfig(), accum = []) {
23
- super(undefined, config, accum, {});
24
- for (const line of inner?.split('\n') ?? []) {
25
- const matches = /^([^|]+)(?:\|(.*))?/u.exec(line);
26
- if (!matches) {
27
- // @ts-expect-error abstract class
28
- super.insertAt((line.trim() ? new noinclude_1.NoincludeToken(line, config, accum) : line));
29
- continue;
30
- }
31
- const [, file, alt] = matches;
32
- if (this.#checkFile(file)) {
33
- // @ts-expect-error abstract class
34
- super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
35
- }
36
- else {
37
- // @ts-expect-error abstract class
38
- super.insertAt(new noinclude_1.NoincludeToken(line, config, accum));
39
- }
52
+ let GalleryToken = (() => {
53
+ let _classDecorators = [multiLine_1.multiLine];
54
+ let _classDescriptor;
55
+ let _classExtraInitializers = [];
56
+ let _classThis;
57
+ let _classSuper = index_2.Token;
58
+ var GalleryToken = class extends _classSuper {
59
+ static { _classThis = this; }
60
+ static {
61
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
62
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
63
+ GalleryToken = _classThis = _classDescriptor.value;
64
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
65
+ __runInitializers(_classThis, _classExtraInitializers);
40
66
  }
41
- }
42
- /**
43
- * 检查文件名是否有效
44
- * @param file 文件名
45
- */
46
- #checkFile(file) {
47
- return this.normalizeTitle(file, 6, { halfParsed: true, temporary: true, decode: true }).valid;
48
- }
49
- /** @private */
50
- toString(skip) {
51
- return super.toString(skip, '\n');
52
- }
53
- /** @private */
54
- text() {
55
- return super.text('\n').replace(/\n\s*\n/gu, '\n');
56
- }
57
- /** @private */
58
- getGaps() {
59
- return 1;
60
- }
61
- /** @private */
62
- lint(start = this.getAbsoluteIndex(), re) {
63
- const { top, left } = this.getRootNode().posFromIndex(start), errors = [];
64
- for (let i = 0; i < this.length; i++) {
65
- const child = this.childNodes[i], str = child.toString(), { length } = str, trimmed = str.trim(), { type } = child, startLine = top + i, startCol = i ? 0 : left;
66
- child.setAttribute('aIndex', start);
67
- if (type === 'noinclude' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
68
- const endIndex = start + length;
69
- errors.push({
70
- rule: 'no-ignored',
71
- message: index_1.default.msg('invalid content in <$1>', 'gallery'),
72
- severity: trimmed.startsWith('|') ? 'warning' : 'error',
73
- startIndex: start,
74
- endIndex,
75
- startLine,
76
- endLine: startLine,
77
- startCol,
78
- endCol: startCol + length,
79
- suggestions: [
80
- { desc: 'remove', range: [start, endIndex], text: '' },
81
- { desc: 'comment', range: [start, endIndex], text: `<!--${str}-->` },
82
- ],
83
- });
67
+ get type() {
68
+ return 'ext-inner';
69
+ }
70
+ /** @param inner 标签内部wikitext */
71
+ constructor(inner, config, accum = []) {
72
+ super(undefined, config, accum, {});
73
+ for (const line of inner?.split('\n') ?? []) {
74
+ const matches = /^([^|]+)(?:\|(.*))?/u.exec(line);
75
+ if (!matches) {
76
+ // @ts-expect-error abstract class
77
+ super.insertAt((line.trim() ? new noinclude_1.NoincludeToken(line, config, accum) : line));
78
+ continue;
79
+ }
80
+ const [, file, alt] = matches;
81
+ if (this.#checkFile(file)) {
82
+ // @ts-expect-error abstract class
83
+ super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
84
+ }
85
+ else {
86
+ // @ts-expect-error abstract class
87
+ super.insertAt(new noinclude_1.NoincludeToken(line, config, accum));
88
+ }
84
89
  }
85
- else if (type !== 'noinclude' && type !== 'text') {
86
- errors.push(...child.lint(start, re));
90
+ }
91
+ /**
92
+ * 检查文件名是否有效
93
+ * @param file 文件名
94
+ */
95
+ #checkFile(file) {
96
+ return this.normalizeTitle(file, 6, { halfParsed: true, temporary: true, decode: true }).valid;
97
+ }
98
+ /** @private */
99
+ lint(start = this.getAbsoluteIndex(), re) {
100
+ const { top, left } = this.getRootNode().posFromIndex(start), errors = [];
101
+ for (let i = 0; i < this.length; i++) {
102
+ const child = this.childNodes[i], str = child.toString(), { length } = str, trimmed = str.trim(), { type } = child, startLine = top + i, startCol = i ? 0 : left;
103
+ child.setAttribute('aIndex', start);
104
+ if (type === 'noinclude' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
105
+ const endIndex = start + length;
106
+ errors.push({
107
+ rule: 'no-ignored',
108
+ message: index_1.default.msg('invalid content in <$1>', 'gallery'),
109
+ severity: trimmed.startsWith('|') ? 'warning' : 'error',
110
+ startIndex: start,
111
+ endIndex,
112
+ startLine,
113
+ endLine: startLine,
114
+ startCol,
115
+ endCol: startCol + length,
116
+ suggestions: [
117
+ { desc: 'remove', range: [start, endIndex], text: '' },
118
+ { desc: 'comment', range: [start, endIndex], text: `<!--${str}-->` },
119
+ ],
120
+ });
121
+ }
122
+ else if (type !== 'noinclude' && type !== 'text') {
123
+ const childErrors = child.lint(start, re);
124
+ if (childErrors.length > 0) {
125
+ errors.push(...childErrors);
126
+ }
127
+ }
128
+ start += length + 1;
87
129
  }
88
- start += length + 1;
130
+ return errors;
89
131
  }
90
- return errors;
91
- }
92
- }
132
+ };
133
+ return GalleryToken = _classThis;
134
+ })();
93
135
  exports.GalleryToken = GalleryToken;
@@ -76,18 +76,18 @@ class HeadingToken extends index_2.Token {
76
76
  //
77
77
  }
78
78
  else if (unbalancedStart) {
79
- const [extra] = /^=+/u.exec(innerStr);
80
- e.suggestions = [
81
- { desc: `h${level}`, range: [e.startIndex, e.startIndex + extra.length], text: '' },
82
- { desc: `h${level + extra.length}`, range: [e.endIndex, e.endIndex], text: extra },
83
- ];
79
+ const [extra] = /^=+/u.exec(innerStr), newLevel = level + extra.length;
80
+ e.suggestions = [{ desc: `h${level}`, range: [e.startIndex, e.startIndex + extra.length], text: '' }];
81
+ if (newLevel < 7) {
82
+ e.suggestions.push({ desc: `h${newLevel}`, range: [e.endIndex, e.endIndex], text: extra });
83
+ }
84
84
  }
85
85
  else {
86
- const extra = /[^=](=+)$/u.exec(innerStr)[1];
87
- e.suggestions = [
88
- { desc: `h${level}`, range: [e.endIndex - extra.length, e.endIndex], text: '' },
89
- { desc: `h${level + extra.length}`, range: [e.startIndex, e.startIndex], text: extra },
90
- ];
86
+ const extra = /[^=](=+)$/u.exec(innerStr)[1], newLevel = level + extra.length;
87
+ e.suggestions = [{ desc: `h${level}`, range: [e.endIndex - extra.length, e.endIndex], text: '' }];
88
+ if (newLevel < 7) {
89
+ e.suggestions.push({ desc: `h${newLevel}`, range: [e.startIndex, e.startIndex], text: extra });
90
+ }
91
91
  }
92
92
  errors.push(e);
93
93
  }
@@ -13,7 +13,7 @@ export declare abstract class ImageParameterToken extends Token {
13
13
  readonly name: string;
14
14
  abstract get parentNode(): FileToken | undefined;
15
15
  abstract get nextSibling(): this | undefined;
16
- abstract get previousSibling(): AtomToken | this;
16
+ abstract get previousSibling(): AtomToken | this | undefined;
17
17
  get type(): 'image-parameter';
18
18
  /** image link / 图片链接 */
19
19
  get link(): string | Title | undefined;
@@ -14,7 +14,7 @@ const getUrlRegex = (0, common_1.getRegex)(protocol => new RegExp(String.raw `^(
14
14
  const getSyntaxRegex = (0, common_1.getRegex)(syntax => new RegExp(String.raw `^(\s*(?!\s))${syntax.replace('$1', '(.*)')}${syntax.endsWith('$1') ? '(?=$|\n)' : ''}(\s*)$`, 'u'));
15
15
  exports.galleryParams = new Set(['alt', 'link', 'lang', 'page', 'caption']);
16
16
  function validate(key, val, config, halfParsed, ext) {
17
- val = val.trim();
17
+ val = (0, string_1.removeComment)(val).trim();
18
18
  let value = val.replace(key === 'link' ? /\0\d+[tq]\x7F/gu : /\0\d+t\x7F/gu, '').trim();
19
19
  switch (key) {
20
20
  case 'width':
@@ -81,10 +81,12 @@ class ImageParameterToken extends index_2.Token {
81
81
  this.setAttribute('name', param[1]);
82
82
  return;
83
83
  }
84
- super(str, {
85
- ...config,
86
- excludes: [...config.excludes ?? [], 'list'],
87
- }, accum);
84
+ super(str, config.excludes.includes('list')
85
+ ? config
86
+ : {
87
+ ...config,
88
+ excludes: [...config.excludes, 'list'],
89
+ }, accum);
88
90
  this.setAttribute('name', 'caption');
89
91
  this.setAttribute('stage', 7);
90
92
  }
@@ -104,10 +106,11 @@ class ImageParameterToken extends index_2.Token {
104
106
  return this.#syntax ? this.#syntax.replace('$1', super.text()).trim() : super.text().trim();
105
107
  }
106
108
  /** @private */
109
+ isPlain() {
110
+ return this.name === 'caption';
111
+ }
112
+ /** @private */
107
113
  getAttribute(key) {
108
- if (key === 'plain') {
109
- return (this.name === 'caption');
110
- }
111
114
  return key === 'padding'
112
115
  ? Math.max(0, this.#syntax.indexOf('$1'))
113
116
  : super.getAttribute(key);
@@ -16,7 +16,7 @@ export declare abstract class ImagemapToken extends Token {
16
16
  abstract get firstChild(): Child | undefined;
17
17
  abstract get lastChild(): Child | ImagemapLinkToken | AstText | undefined;
18
18
  abstract get nextSibling(): undefined;
19
- abstract get previousSibling(): AttributesToken;
19
+ abstract get previousSibling(): AttributesToken | undefined;
20
20
  abstract get parentNode(): ExtToken | undefined;
21
21
  get type(): 'ext-inner';
22
22
  /** 图片 */
@@ -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
  };
@@ -7,6 +41,7 @@ exports.ImagemapToken = void 0;
7
41
  const lint_1 = require("../util/lint");
8
42
  const debug_1 = require("../util/debug");
9
43
  const rect_1 = require("../lib/rect");
44
+ const multiLine_1 = require("../mixin/multiLine");
10
45
  const index_1 = __importDefault(require("../index"));
11
46
  const index_2 = require("./index");
12
47
  const noinclude_1 = require("./nowiki/noinclude");
@@ -16,103 +51,108 @@ const imagemapLink_1 = require("./imagemapLink");
16
51
  * `<imagemap>`
17
52
  * @classdesc `{childNodes: [...NoincludeToken[], GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)[]]}`
18
53
  */
19
- class ImagemapToken extends index_2.Token {
20
- get type() {
21
- return 'ext-inner';
22
- }
23
- /** 图片 */
24
- get image() {
25
- return this.childNodes.find((0, debug_1.isToken)('imagemap-image'));
26
- }
27
- /** @param inner 标签内部wikitext */
28
- constructor(inner, config = index_1.default.getConfig(), accum = []) {
29
- super(undefined, config, accum, {});
30
- if (!inner) {
31
- return;
54
+ let ImagemapToken = (() => {
55
+ let _classDecorators = [multiLine_1.multiLine];
56
+ let _classDescriptor;
57
+ let _classExtraInitializers = [];
58
+ let _classThis;
59
+ let _classSuper = index_2.Token;
60
+ var ImagemapToken = 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
+ ImagemapToken = _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 'ext-inner';
32
71
  }
33
- const lines = inner.split('\n'), protocols = new Set(config.protocol.split('|')), SingleLineNoincludeToken = noinclude_1.NoincludeToken;
34
- let first = true, error = false;
35
- for (const line of lines) {
36
- const trimmed = line.trim();
37
- if (error || !trimmed || trimmed.startsWith('#')) {
38
- //
72
+ /** 图片 */
73
+ get image() {
74
+ return this.childNodes.find((0, debug_1.isToken)('imagemap-image'));
75
+ }
76
+ /** @param inner 标签内部wikitext */
77
+ constructor(inner, config = index_1.default.getConfig(), accum = []) {
78
+ super(undefined, config, accum, {});
79
+ if (!inner) {
80
+ return;
39
81
  }
40
- else if (first) {
41
- const pipe = line.indexOf('|'), file = pipe === -1 ? line : line.slice(0, pipe), { valid, ns, } = this.normalizeTitle(file, 0, { halfParsed: true, temporary: true });
42
- if (valid
43
- && ns === 6) {
44
- // @ts-expect-error abstract class
45
- const token = new galleryImage_1.GalleryImageToken('imagemap', file, pipe === -1 ? undefined : line.slice(pipe + 1), config, accum);
46
- super.insertAt(token);
47
- first = false;
48
- continue;
82
+ const lines = inner.split('\n'), protocols = new Set(config.protocol.split('|')), SingleLineNoincludeToken = noinclude_1.NoincludeToken;
83
+ let first = true, error = false;
84
+ for (const line of lines) {
85
+ const trimmed = line.trim();
86
+ if (error || !trimmed || trimmed.startsWith('#')) {
87
+ //
49
88
  }
50
- else {
51
- error = true;
52
- }
53
- }
54
- else if (line.trim().split(/[\t ]/u, 1)[0] === 'desc') {
55
- super.insertAt(line);
56
- continue;
57
- }
58
- else if (line.includes('[')) {
59
- const i = line.indexOf('['), substr = line.slice(i), mtIn = /^\[\[([^|]+)(?:\|([^\]]+))?\]\][\w\s]*$/u
60
- .exec(substr);
61
- if (mtIn) {
62
- if (this.normalizeTitle(mtIn[1], 0, { halfParsed: true, temporary: true, selfLink: true })
63
- .valid) {
89
+ else if (first) {
90
+ const pipe = line.indexOf('|'), file = pipe === -1 ? line : line.slice(0, pipe), { valid, ns, } = this.normalizeTitle(file, 0, { halfParsed: true, temporary: true });
91
+ if (valid
92
+ && ns === 6) {
64
93
  // @ts-expect-error abstract class
65
- super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtIn.slice(1), substr.slice(substr.indexOf(']]') + 2), config, accum));
94
+ const token = new galleryImage_1.GalleryImageToken('imagemap', file, pipe === -1 ? undefined : line.slice(pipe + 1), config, accum);
95
+ super.insertAt(token);
96
+ first = false;
66
97
  continue;
67
98
  }
99
+ else {
100
+ error = true;
101
+ }
102
+ }
103
+ else if (line.trim().split(/[\t ]/u, 1)[0] === 'desc') {
104
+ super.insertAt(line);
105
+ continue;
68
106
  }
69
- else if (protocols.has(substr.slice(1, substr.indexOf(':') + 1))
70
- || protocols.has(substr.slice(1, substr.indexOf('//') + 2))) {
71
- const mtEx = /^\[([^\]\s]+)(?:(\s+(?!\s))([^\]]*))?\][\w\s]*$/u
107
+ else if (line.includes('[')) {
108
+ const i = line.indexOf('['), substr = line.slice(i), mtIn = /^\[\[([^|]+)(?:\|([^\]]*))?\]\][\w\s]*$/u
72
109
  .exec(substr);
73
- if (mtEx) {
74
- // @ts-expect-error abstract class
75
- super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtEx.slice(1), substr.slice(substr.indexOf(']') + 1), config, accum));
76
- continue;
110
+ if (mtIn) {
111
+ if (this.normalizeTitle(mtIn[1], 0, { halfParsed: true, temporary: true, selfLink: true })
112
+ .valid) {
113
+ // @ts-expect-error abstract class
114
+ super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtIn.slice(1), substr.slice(substr.indexOf(']]') + 2), config, accum));
115
+ continue;
116
+ }
117
+ }
118
+ else if (substr.startsWith('[//')
119
+ || protocols.has(substr.slice(1, substr.indexOf(':') + 1))
120
+ || protocols.has(substr.slice(1, substr.indexOf('//') + 2))) {
121
+ const mtEx = /^\[([^\]\s]+)(?:(\s+(?!\s))([^\]]*))?\][\w\s]*$/u
122
+ .exec(substr);
123
+ if (mtEx) {
124
+ // @ts-expect-error abstract class
125
+ super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtEx.slice(1), substr.slice(substr.indexOf(']') + 1), config, accum));
126
+ continue;
127
+ }
77
128
  }
78
129
  }
130
+ // @ts-expect-error abstract class
131
+ super.insertAt(new SingleLineNoincludeToken(line, config, accum));
79
132
  }
80
- // @ts-expect-error abstract class
81
- super.insertAt(new SingleLineNoincludeToken(line, config, accum));
82
- }
83
- }
84
- /** @private */
85
- toString(skip) {
86
- return super.toString(skip, '\n');
87
- }
88
- /** @private */
89
- text() {
90
- return super.text('\n').replace(/\n{2,}/gu, '\n');
91
- }
92
- /** @private */
93
- getGaps() {
94
- return 1;
95
- }
96
- /** @private */
97
- lint(start = this.getAbsoluteIndex(), re) {
98
- const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
99
- if (this.image) {
100
- errors.push(...this.childNodes.filter(child => {
101
- const str = child.toString().trim();
102
- return child.type === 'noinclude' && str && !str.startsWith('#');
103
- }).map(child => {
104
- const e = (0, lint_1.generateForChild)(child, rect, 'invalid-imagemap', 'invalid link in <imagemap>');
105
- e.suggestions = [
106
- { desc: 'remove', range: [e.startIndex - 1, e.endIndex], text: '' },
107
- { desc: 'comment', range: [e.startIndex, e.startIndex], text: '# ' },
108
- ];
109
- return e;
110
- }));
111
133
  }
112
- else {
113
- errors.push((0, lint_1.generateForSelf)(this, rect, 'invalid-imagemap', '<imagemap> without an image'));
134
+ /** @private */
135
+ lint(start = this.getAbsoluteIndex(), re) {
136
+ const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
137
+ if (this.image) {
138
+ errors.push(...this.childNodes.filter(child => {
139
+ const str = child.toString().trim();
140
+ return child.type === 'noinclude' && str && !str.startsWith('#');
141
+ }).map(child => {
142
+ const e = (0, lint_1.generateForChild)(child, rect, 'invalid-imagemap', 'invalid link in <imagemap>');
143
+ e.suggestions = [
144
+ { desc: 'remove', range: [e.startIndex - 1, e.endIndex], text: '' },
145
+ { desc: 'comment', range: [e.startIndex, e.startIndex], text: '# ' },
146
+ ];
147
+ return e;
148
+ }));
149
+ }
150
+ else {
151
+ errors.push((0, lint_1.generateForSelf)(this, rect, 'invalid-imagemap', '<imagemap> without an image'));
152
+ }
153
+ return errors;
114
154
  }
115
- return errors;
116
- }
117
- }
155
+ };
156
+ return ImagemapToken = _classThis;
157
+ })();
118
158
  exports.ImagemapToken = ImagemapToken;
@@ -15,7 +15,7 @@ export declare abstract class ImagemapLinkToken extends Token {
15
15
  abstract get firstChild(): AstText;
16
16
  abstract get lastChild(): NoincludeToken;
17
17
  abstract get parentNode(): ImagemapToken | undefined;
18
- abstract get previousSibling(): GalleryImageToken | this | NoincludeToken | AstText;
18
+ abstract get previousSibling(): GalleryImageToken | this | NoincludeToken | AstText | undefined;
19
19
  abstract get nextSibling(): this | NoincludeToken | AstText | undefined;
20
20
  get type(): 'imagemap-link';
21
21
  /**