wikiparser-node 1.4.2 → 1.4.3

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 (103) hide show
  1. package/dist/addon/table.js +5 -1
  2. package/dist/base.d.ts +6 -1
  3. package/dist/index.d.ts +0 -2
  4. package/dist/index.js +3 -3
  5. package/dist/lib/element.d.ts +3 -2
  6. package/dist/lib/element.js +20 -13
  7. package/dist/lib/node.js +13 -10
  8. package/dist/lib/text.js +3 -3
  9. package/dist/lib/title.js +4 -12
  10. package/dist/mixin/attributesParent.d.ts +32 -2
  11. package/dist/mixin/attributesParent.js +14 -25
  12. package/dist/mixin/fixed.d.ts +2 -1
  13. package/dist/mixin/fixed.js +3 -1
  14. package/dist/mixin/flagsParent.d.ts +28 -17
  15. package/dist/mixin/flagsParent.js +12 -25
  16. package/dist/mixin/magicLinkParent.d.ts +14 -8
  17. package/dist/mixin/magicLinkParent.js +7 -8
  18. package/dist/mixin/singleLine.d.ts +2 -1
  19. package/dist/mixin/singleLine.js +3 -2
  20. package/dist/mixin/sol.d.ts +2 -4
  21. package/dist/mixin/sol.js +8 -6
  22. package/dist/mixin/syntax.d.ts +5 -2
  23. package/dist/mixin/syntax.js +14 -18
  24. package/dist/parser/links.js +1 -3
  25. package/dist/src/arg.d.ts +4 -4
  26. package/dist/src/arg.js +4 -4
  27. package/dist/src/attribute.d.ts +9 -7
  28. package/dist/src/attribute.js +271 -218
  29. package/dist/src/attributes.d.ts +3 -3
  30. package/dist/src/attributes.js +0 -1
  31. package/dist/src/converter.d.ts +7 -2
  32. package/dist/src/converter.js +113 -64
  33. package/dist/src/converterFlags.d.ts +5 -5
  34. package/dist/src/converterFlags.js +0 -1
  35. package/dist/src/converterRule.d.ts +5 -5
  36. package/dist/src/converterRule.js +0 -1
  37. package/dist/src/extLink.d.ts +7 -2
  38. package/dist/src/extLink.js +159 -110
  39. package/dist/src/gallery.d.ts +5 -5
  40. package/dist/src/gallery.js +0 -1
  41. package/dist/src/heading.d.ts +8 -8
  42. package/dist/src/heading.js +172 -125
  43. package/dist/src/html.d.ts +8 -5
  44. package/dist/src/html.js +263 -214
  45. package/dist/src/imageParameter.d.ts +2 -2
  46. package/dist/src/imageParameter.js +1 -0
  47. package/dist/src/imagemap.d.ts +5 -5
  48. package/dist/src/imagemap.js +4 -10
  49. package/dist/src/imagemapLink.d.ts +7 -4
  50. package/dist/src/imagemapLink.js +75 -26
  51. package/dist/src/index.js +3 -4
  52. package/dist/src/link/base.d.ts +2 -2
  53. package/dist/src/link/base.js +1 -4
  54. package/dist/src/link/file.d.ts +1 -1
  55. package/dist/src/link/file.js +0 -1
  56. package/dist/src/link/galleryImage.d.ts +2 -1
  57. package/dist/src/link/galleryImage.js +136 -88
  58. package/dist/src/link/index.js +0 -1
  59. package/dist/src/magicLink.d.ts +11 -3
  60. package/dist/src/magicLink.js +170 -120
  61. package/dist/src/nested.d.ts +5 -5
  62. package/dist/src/nested.js +1 -0
  63. package/dist/src/nowiki/base.d.ts +6 -2
  64. package/dist/src/nowiki/base.js +79 -28
  65. package/dist/src/nowiki/comment.d.ts +0 -2
  66. package/dist/src/nowiki/comment.js +0 -9
  67. package/dist/src/nowiki/doubleUnderscore.js +88 -38
  68. package/dist/src/nowiki/hr.d.ts +1 -4
  69. package/dist/src/nowiki/hr.js +53 -4
  70. package/dist/src/nowiki/index.d.ts +2 -2
  71. package/dist/src/nowiki/index.js +1 -0
  72. package/dist/src/nowiki/list.d.ts +1 -4
  73. package/dist/src/nowiki/list.js +88 -39
  74. package/dist/src/nowiki/listBase.d.ts +1 -1
  75. package/dist/src/nowiki/listBase.js +52 -2
  76. package/dist/src/nowiki/quote.d.ts +3 -3
  77. package/dist/src/nowiki/quote.js +102 -54
  78. package/dist/src/paramTag/index.d.ts +5 -5
  79. package/dist/src/paramTag/index.js +2 -1
  80. package/dist/src/parameter.d.ts +11 -8
  81. package/dist/src/parameter.js +225 -176
  82. package/dist/src/pre.d.ts +5 -5
  83. package/dist/src/pre.js +1 -0
  84. package/dist/src/syntax.d.ts +6 -0
  85. package/dist/src/syntax.js +74 -23
  86. package/dist/src/table/base.d.ts +6 -3
  87. package/dist/src/table/base.js +100 -49
  88. package/dist/src/table/index.d.ts +6 -3
  89. package/dist/src/table/index.js +5 -9
  90. package/dist/src/table/td.d.ts +9 -5
  91. package/dist/src/table/td.js +270 -217
  92. package/dist/src/table/tr.d.ts +4 -4
  93. package/dist/src/table/tr.js +1 -0
  94. package/dist/src/tagPair/ext.d.ts +6 -3
  95. package/dist/src/tagPair/ext.js +168 -118
  96. package/dist/src/tagPair/include.d.ts +2 -4
  97. package/dist/src/tagPair/include.js +0 -8
  98. package/dist/src/tagPair/index.d.ts +1 -1
  99. package/dist/src/tagPair/index.js +115 -66
  100. package/dist/src/transclude.d.ts +3 -3
  101. package/dist/src/transclude.js +4 -9
  102. package/dist/util/debug.js +0 -2
  103. package/package.json +3 -3
@@ -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
  Object.defineProperty(exports, "__esModule", { value: true });
3
37
  exports.ImagemapLinkToken = void 0;
4
38
  const constants_1 = require("../util/constants");
@@ -13,32 +47,47 @@ const extLink_1 = require("./extLink");
13
47
  * `<imagemap>`内的链接
14
48
  * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
15
49
  */
16
- class ImagemapLinkToken extends (0, fixed_1.fixedToken)((0, singleLine_1.singleLine)(index_2.Token)) {
17
- type = 'imagemap-link';
18
- /* NOT FOR BROWSER */
19
- /** 内外链接 */
20
- get link() {
21
- return this.childNodes[1].link;
22
- }
23
- set link(link) {
24
- this.childNodes[1].link = link;
25
- }
26
- /* NOT FOR BROWSER END */
27
- /**
28
- * @param pre 链接前的文本
29
- * @param linkStuff 内外链接
30
- * @param post 链接后的文本
31
- */
32
- constructor(pre, linkStuff, post, config = index_1.default.getConfig(), accum = []) {
33
- super(undefined, config, accum);
34
- this.append(pre, linkStuff.length === 2
35
- // @ts-expect-error abstract class
36
- ? new index_3.LinkToken(...linkStuff, config, accum)
50
+ let ImagemapLinkToken = (() => {
51
+ let _classDecorators = [fixed_1.fixedToken, singleLine_1.singleLine];
52
+ let _classDescriptor;
53
+ let _classExtraInitializers = [];
54
+ let _classThis;
55
+ let _classSuper = index_2.Token;
56
+ var ImagemapLinkToken = class extends _classSuper {
57
+ static { _classThis = this; }
58
+ static {
59
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
60
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
61
+ ImagemapLinkToken = _classThis = _classDescriptor.value;
62
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
63
+ __runInitializers(_classThis, _classExtraInitializers);
64
+ }
65
+ type = 'imagemap-link';
66
+ /** 内外链接 */
67
+ get link() {
68
+ return this.childNodes[1].link;
69
+ }
70
+ set link(link) {
71
+ this.childNodes[1].link = link;
72
+ }
73
+ /* NOT FOR BROWSER END */
74
+ /**
75
+ * @param pre 链接前的文本
76
+ * @param linkStuff 内外链接
77
+ * @param post 链接后的文本
78
+ */
79
+ constructor(pre, linkStuff, post, config = index_1.default.getConfig(), accum = []) {
80
+ super(undefined, config, accum);
81
+ this.append(pre, linkStuff.length === 2
82
+ // @ts-expect-error abstract class
83
+ ? new index_3.LinkToken(...linkStuff, config, accum)
84
+ // @ts-expect-error abstract class
85
+ : new extLink_1.ExtLinkToken(...linkStuff, config, accum),
37
86
  // @ts-expect-error abstract class
38
- : new extLink_1.ExtLinkToken(...linkStuff, config, accum),
39
- // @ts-expect-error abstract class
40
- new noinclude_1.NoincludeToken(post, config, accum));
41
- }
42
- }
87
+ new noinclude_1.NoincludeToken(post, config, accum));
88
+ }
89
+ };
90
+ return ImagemapLinkToken = _classThis;
91
+ })();
43
92
  exports.ImagemapLinkToken = ImagemapLinkToken;
44
93
  constants_1.classes['ImagemapLinkToken'] = __filename;
package/dist/src/index.js CHANGED
@@ -86,10 +86,9 @@ class Token extends element_1.AstElement {
86
86
  }
87
87
  this.#config = config;
88
88
  this.#accum = accum;
89
+ accum.push(this);
89
90
  /* NOT FOR BROWSER */
90
91
  this.setAttribute('acceptable', acceptable);
91
- /* NOT FOR BROWSER END */
92
- accum.push(this);
93
92
  }
94
93
  /** @private */
95
94
  parseOnce(n = this.#stage, include = false) {
@@ -302,8 +301,6 @@ class Token extends element_1.AstElement {
302
301
  return (this.constructor === Token);
303
302
  case 'config':
304
303
  return structuredClone(this.#config);
305
- case 'accum':
306
- return this.#accum;
307
304
  case 'include': {
308
305
  if (this.#include !== undefined) {
309
306
  return this.#include;
@@ -311,6 +308,8 @@ class Token extends element_1.AstElement {
311
308
  const root = this.getRootNode();
312
309
  return (root !== this && root.getAttribute('include'));
313
310
  }
311
+ case 'accum':
312
+ return this.#accum;
314
313
  /* NOT FOR BROWSER */
315
314
  case 'stage':
316
315
  return this.#stage;
@@ -12,10 +12,10 @@ export declare abstract class LinkBaseToken extends Token {
12
12
  type: 'link' | 'category' | 'file' | 'gallery-image' | 'imagemap-image';
13
13
  readonly name: string;
14
14
  readonly childNodes: readonly [AtomToken, ...Token[]];
15
- abstract get children(): [AtomToken, ...Token[]];
16
15
  abstract get firstChild(): AtomToken;
17
- abstract get firstElementChild(): AtomToken;
18
16
  abstract get lastChild(): Token;
17
+ abstract get children(): [AtomToken, ...Token[]];
18
+ abstract get firstElementChild(): AtomToken;
19
19
  abstract get lastElementChild(): Token;
20
20
  /** 完整链接 */
21
21
  get link(): string | Title;
@@ -16,7 +16,6 @@ class LinkBaseToken extends index_2.Token {
16
16
  #bracket = true;
17
17
  #delimiter;
18
18
  #title;
19
- /* NOT FOR BROWSER */
20
19
  /** 完整链接 */
21
20
  get link() {
22
21
  return this.#title;
@@ -61,13 +60,11 @@ class LinkBaseToken extends index_2.Token {
61
60
  /** @private */
62
61
  afterBuild() {
63
62
  this.#title = this.getTitle();
64
- /* NOT FOR BROWSER */
65
- this.setAttribute('name', this.#title.title);
66
- /* NOT FOR BROWSER END */
67
63
  if (this.#delimiter.includes('\0')) {
68
64
  this.#delimiter = this.buildFromStr(this.#delimiter, constants_1.BuildMethod.String);
69
65
  }
70
66
  /* NOT FOR BROWSER */
67
+ this.setAttribute('name', this.#title.title);
71
68
  const /** @implements */ linkListener = (e, data) => {
72
69
  const { prevTarget } = e;
73
70
  if (prevTarget?.type === 'link-target') {
@@ -12,8 +12,8 @@ export declare abstract class FileToken extends LinkBaseToken {
12
12
  #private;
13
13
  readonly type: 'file' | 'gallery-image' | 'imagemap-image';
14
14
  readonly childNodes: readonly [AtomToken, ...ImageParameterToken[]];
15
- abstract get children(): [AtomToken, ...ImageParameterToken[]];
16
15
  abstract get lastChild(): AtomToken | ImageParameterToken;
16
+ abstract get children(): [AtomToken, ...ImageParameterToken[]];
17
17
  abstract get lastElementChild(): AtomToken | ImageParameterToken;
18
18
  /** 图片链接 */
19
19
  get link(): string | Title;
@@ -42,7 +42,6 @@ const explode = (start, end, separator, str) => {
42
42
  */
43
43
  class FileToken extends base_1.LinkBaseToken {
44
44
  type = 'file';
45
- /* NOT FOR BROWSER */
46
45
  /** 图片链接 */
47
46
  get link() {
48
47
  return this.getArg('link')?.link ?? super.link;
@@ -1,10 +1,11 @@
1
1
  import Parser from '../../index';
2
2
  import { Token } from '../index';
3
+ import { FileToken } from './file';
3
4
  import type { Title } from '../../lib/title';
4
5
  import type { LintError } from '../../base';
5
6
  import type { AtomToken, ImageParameterToken } from '../../internal';
6
7
  declare type GalleryTypes = 'gallery' | 'imagemap';
7
- import {FileToken} from './file';
8
+ /** 图库图片 */
8
9
  export declare abstract class GalleryImageToken extends FileToken {
9
10
  #private;
10
11
  type: `${GalleryTypes}-image`;
@@ -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
  Object.defineProperty(exports, "__esModule", { value: true });
3
37
  exports.GalleryImageToken = void 0;
4
38
  const lint_1 = require("../../util/lint");
@@ -10,100 +44,114 @@ const index_2 = require("../index");
10
44
  const file_1 = require("./file");
11
45
  const imageParameter_1 = require("../imageParameter");
12
46
  /** 图库图片 */
13
- class GalleryImageToken extends (0, singleLine_1.singleLine)(file_1.FileToken) {
14
- /* NOT FOR BROWSER */
15
- /** 图片链接 */
16
- get link() {
17
- return this.type === 'imagemap-image' ? '' : super.link;
18
- }
19
- set link(value) {
20
- if (this.type !== 'imagemap-image') {
21
- super.link = value;
22
- }
23
- }
24
- /* NOT FOR BROWSER END */
25
- /**
26
- * @param type 图片类型
27
- * @param link 图片文件名
28
- * @param text 图片参数
29
- */
30
- constructor(type, link, text, config = index_1.default.getConfig(), accum = []) {
31
- let token;
32
- if (text !== undefined) {
33
- token = new index_2.Token(text, config, accum);
34
- token.type = 'plain';
35
- for (let n = 1; n < constants_1.MAX_STAGE; n++) {
36
- token.parseOnce();
37
- }
38
- accum.splice(accum.indexOf(token), 1);
47
+ let GalleryImageToken = (() => {
48
+ let _classDecorators = [singleLine_1.singleLine];
49
+ let _classDescriptor;
50
+ let _classExtraInitializers = [];
51
+ let _classThis;
52
+ let _classSuper = file_1.FileToken;
53
+ var GalleryImageToken = class extends _classSuper {
54
+ static { _classThis = this; }
55
+ static {
56
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
57
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
58
+ GalleryImageToken = _classThis = _classDescriptor.value;
59
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
60
+ __runInitializers(_classThis, _classExtraInitializers);
39
61
  }
40
- super(link, token?.toString(), config, accum);
41
- this.setAttribute('bracket', false);
42
- this.type = `${type}-image`;
43
- }
44
- /** @private */
45
- getTitle() {
46
- const imagemap = this.type === 'imagemap-image';
47
- return this.normalizeTitle(String(this.firstChild), imagemap ? 0 : 6, true, !imagemap);
48
- }
49
- /** @private */
50
- getAttribute(key) {
51
- return key === 'padding' ? 0 : super.getAttribute(key);
52
- }
53
- /** @override */
54
- lint(start = this.getAbsoluteIndex()) {
55
- const errors = super.lint(start), { ns,
56
62
  /* NOT FOR BROWSER */
57
- interwiki, } = this.getAttribute('title');
58
- if (interwiki || ns !== 6) {
59
- errors.push((0, lint_1.generateForSelf)(this, { start }, 'invalid gallery image'));
63
+ /** 图片链接 */
64
+ get link() {
65
+ return this.type === 'imagemap-image' ? '' : super.link;
60
66
  }
61
- return errors;
62
- }
63
- /**
64
- * 设置`#title`
65
- * @param title Title对象
66
- */
67
- #setName(title) {
68
- this.setAttribute('title', title);
69
- /* NOT FOR BROWSER */
70
- this.setAttribute('name', title.title);
71
- }
72
- /** @private */
73
- afterBuild() {
74
- this.#setName(this.getTitle());
75
- /* NOT FOR BROWSER */
76
- const /** @implements */ linkListener = (e, data) => {
77
- const { prevTarget } = e;
78
- if (prevTarget?.type === 'link-target') {
79
- const name = String(prevTarget), title = this.getTitle(), { interwiki, ns, valid } = title;
80
- if (!valid) {
81
- (0, debug_1.undo)(e, data);
82
- throw new Error(`非法的图片文件名:${name}`);
67
+ set link(value) {
68
+ if (this.type !== 'imagemap-image') {
69
+ super.link = value;
70
+ }
71
+ }
72
+ /* NOT FOR BROWSER END */
73
+ /**
74
+ * @param type 图片类型
75
+ * @param link 图片文件名
76
+ * @param text 图片参数
77
+ */
78
+ constructor(type, link, text, config = index_1.default.getConfig(), accum = []) {
79
+ let token;
80
+ if (text !== undefined) {
81
+ token = new index_2.Token(text, config, accum);
82
+ token.type = 'plain';
83
+ for (let n = 1; n < constants_1.MAX_STAGE; n++) {
84
+ token.parseOnce();
83
85
  }
84
- else if (interwiki || ns !== 6) {
85
- (0, debug_1.undo)(e, data);
86
- throw new Error(`图片链接不可更改命名空间:${name}`);
86
+ accum.splice(accum.indexOf(token), 1);
87
+ }
88
+ super(link, token?.toString(), config, accum);
89
+ this.setAttribute('bracket', false);
90
+ this.type = `${type}-image`;
91
+ }
92
+ /** @private */
93
+ getTitle() {
94
+ const imagemap = this.type === 'imagemap-image';
95
+ return this.normalizeTitle(String(this.firstChild), imagemap ? 0 : 6, true, !imagemap);
96
+ }
97
+ /** @private */
98
+ getAttribute(key) {
99
+ return key === 'padding' ? 0 : super.getAttribute(key);
100
+ }
101
+ /** @override */
102
+ lint(start = this.getAbsoluteIndex()) {
103
+ const errors = super.lint(start), { ns, interwiki } = this.getAttribute('title');
104
+ if (interwiki || ns !== 6) {
105
+ errors.push((0, lint_1.generateForSelf)(this, { start }, 'invalid gallery image'));
106
+ }
107
+ return errors;
108
+ }
109
+ /**
110
+ * 设置`#title`
111
+ * @param title Title对象
112
+ */
113
+ #setName(title) {
114
+ this.setAttribute('title', title);
115
+ /* NOT FOR BROWSER */
116
+ this.setAttribute('name', title.title);
117
+ }
118
+ /** @private */
119
+ afterBuild() {
120
+ this.#setName(this.getTitle());
121
+ /* NOT FOR BROWSER */
122
+ const /** @implements */ linkListener = (e, data) => {
123
+ const { prevTarget } = e;
124
+ if (prevTarget?.type === 'link-target') {
125
+ const name = String(prevTarget), title = this.getTitle(), { interwiki, ns, valid } = title;
126
+ if (!valid) {
127
+ (0, debug_1.undo)(e, data);
128
+ throw new Error(`非法的图片文件名:${name}`);
129
+ }
130
+ else if (interwiki || ns !== 6) {
131
+ (0, debug_1.undo)(e, data);
132
+ throw new Error(`图片链接不可更改命名空间:${name}`);
133
+ }
134
+ this.#setName(title);
87
135
  }
88
- this.#setName(title);
136
+ };
137
+ this.addEventListener(['remove', 'insert', 'replace', 'text'], linkListener);
138
+ }
139
+ /* NOT FOR BROWSER */
140
+ /**
141
+ * @override
142
+ * @param token 待插入的子节点
143
+ * @param i 插入位置
144
+ * @throws `RangeError` 不可插入多余子节点
145
+ * @throws `TypeError` 不可插入文本节点
146
+ */
147
+ insertAt(child, i) {
148
+ if (this.type === 'gallery-image' && child.type === 'image-parameter' && !imageParameter_1.galleryParams.has(child.name)) {
149
+ child.setAttribute('name', 'invalid');
89
150
  }
90
- };
91
- this.addEventListener(['remove', 'insert', 'replace', 'text'], linkListener);
92
- }
93
- /* NOT FOR BROWSER */
94
- /**
95
- * @override
96
- * @param token 待插入的子节点
97
- * @param i 插入位置
98
- * @throws `RangeError` 不可插入多余子节点
99
- * @throws `TypeError` 不可插入文本节点
100
- */
101
- insertAt(child, i) {
102
- if (this.type === 'gallery-image' && child.type === 'image-parameter' && !imageParameter_1.galleryParams.has(child.name)) {
103
- child.setAttribute('name', 'invalid');
151
+ return super.insertAt(child, i);
104
152
  }
105
- return super.insertAt(child, i);
106
- }
107
- }
153
+ };
154
+ return GalleryImageToken = _classThis;
155
+ })();
108
156
  exports.GalleryImageToken = GalleryImageToken;
109
157
  constants_1.classes['GalleryImageToken'] = __filename;
@@ -10,7 +10,6 @@ const base_1 = require("./base");
10
10
  */
11
11
  class LinkToken extends base_1.LinkBaseToken {
12
12
  type = 'link';
13
- /* NOT FOR BROWSER */
14
13
  /** 链接显示文字 */
15
14
  get innerText() {
16
15
  return this.length > 1 ? this.lastChild.text() : this.firstChild.text().replace(/^\s*:/u, '');
@@ -1,14 +1,23 @@
1
1
  import Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import type { LintError } from '../base';
4
+ import type { SyntaxBase } from '../mixin/syntax';
4
5
  import type { AstText, CommentToken, IncludeToken, NoincludeToken, TranscludeToken, AstNodes } from '../internal';
6
+ /** NOT FOR BROWSER */
7
+ export interface MagicLinkToken extends SyntaxBase {
8
+ }
9
+ /** NOT FOR BROWSER END */
10
+ /**
11
+ * 自由外链
12
+ * @classdesc `{childNodes: ...AstText|CommentToken|IncludeToken|NoincludeToken}`
13
+ */
5
14
  export declare abstract class MagicLinkToken extends Token {
6
15
  type: 'free-ext-link' | 'ext-link-url';
7
16
  readonly childNodes: readonly (AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken)[];
8
- abstract get children(): (CommentToken | IncludeToken | NoincludeToken | TranscludeToken)[];
9
17
  abstract get firstChild(): AstText | TranscludeToken;
10
- abstract get firstElementChild(): CommentToken | IncludeToken | NoincludeToken | TranscludeToken | undefined;
11
18
  abstract get lastChild(): AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken;
19
+ abstract get children(): (CommentToken | IncludeToken | NoincludeToken | TranscludeToken)[];
20
+ abstract get firstElementChild(): CommentToken | IncludeToken | NoincludeToken | TranscludeToken | undefined;
12
21
  abstract get lastElementChild(): CommentToken | IncludeToken | NoincludeToken | TranscludeToken | undefined;
13
22
  /** 协议 */
14
23
  get protocol(): string | undefined;
@@ -48,4 +57,3 @@ export declare abstract class MagicLinkToken extends Token {
48
57
  /** 转义 `=` */
49
58
  escape(): void;
50
59
  }
51
- export {};