wikiparser-node 1.6.2 → 1.7.0-b

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 (169) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/bundle/bundle.min.js +38 -0
  4. package/config/default.json +5 -0
  5. package/config/enwiki.json +4 -814
  6. package/config/llwiki.json +5 -35
  7. package/config/minimum.json +3 -0
  8. package/config/moegirl.json +5 -44
  9. package/config/zhwiki.json +6 -466
  10. package/extensions/dist/base.js +64 -0
  11. package/extensions/dist/editor.js +159 -0
  12. package/extensions/dist/highlight.js +58 -0
  13. package/extensions/dist/lint.js +72 -0
  14. package/extensions/editor.css +64 -0
  15. package/extensions/ui.css +144 -0
  16. package/i18n/zh-hans.json +2 -1
  17. package/i18n/zh-hant.json +2 -1
  18. package/package.json +37 -21
  19. package/config/.schema.json +0 -172
  20. package/dist/addon/table.d.ts +0 -1
  21. package/dist/addon/table.js +0 -485
  22. package/dist/base.d.ts +0 -69
  23. package/dist/base.js +0 -38
  24. package/dist/index.d.ts +0 -31
  25. package/dist/index.js +0 -212
  26. package/dist/internal.d.ts +0 -44
  27. package/dist/lib/element.d.ts +0 -151
  28. package/dist/lib/element.js +0 -618
  29. package/dist/lib/node.d.ts +0 -146
  30. package/dist/lib/node.js +0 -426
  31. package/dist/lib/range.d.ts +0 -104
  32. package/dist/lib/range.js +0 -385
  33. package/dist/lib/ranges.d.ts +0 -28
  34. package/dist/lib/ranges.js +0 -126
  35. package/dist/lib/text.d.ts +0 -63
  36. package/dist/lib/text.js +0 -354
  37. package/dist/lib/title.d.ts +0 -40
  38. package/dist/lib/title.js +0 -179
  39. package/dist/mixin/attributesParent.d.ts +0 -50
  40. package/dist/mixin/attributesParent.js +0 -81
  41. package/dist/mixin/fixed.d.ts +0 -6
  42. package/dist/mixin/fixed.js +0 -30
  43. package/dist/mixin/flagsParent.d.ts +0 -72
  44. package/dist/mixin/flagsParent.js +0 -59
  45. package/dist/mixin/hidden.d.ts +0 -5
  46. package/dist/mixin/hidden.js +0 -24
  47. package/dist/mixin/magicLinkParent.d.ts +0 -40
  48. package/dist/mixin/magicLinkParent.js +0 -42
  49. package/dist/mixin/singleLine.d.ts +0 -6
  50. package/dist/mixin/singleLine.js +0 -26
  51. package/dist/mixin/sol.d.ts +0 -6
  52. package/dist/mixin/sol.js +0 -43
  53. package/dist/mixin/syntax.d.ts +0 -9
  54. package/dist/mixin/syntax.js +0 -50
  55. package/dist/parser/braces.js +0 -130
  56. package/dist/parser/commentAndExt.js +0 -89
  57. package/dist/parser/converter.js +0 -40
  58. package/dist/parser/externalLinks.js +0 -45
  59. package/dist/parser/hrAndDoubleUnderscore.js +0 -40
  60. package/dist/parser/html.js +0 -38
  61. package/dist/parser/links.js +0 -97
  62. package/dist/parser/list.js +0 -97
  63. package/dist/parser/magicLinks.js +0 -42
  64. package/dist/parser/quotes.js +0 -67
  65. package/dist/parser/selector.js +0 -190
  66. package/dist/parser/table.js +0 -123
  67. package/dist/src/arg.d.ts +0 -58
  68. package/dist/src/arg.js +0 -214
  69. package/dist/src/atom.d.ts +0 -12
  70. package/dist/src/atom.js +0 -27
  71. package/dist/src/attribute.d.ts +0 -71
  72. package/dist/src/attribute.js +0 -502
  73. package/dist/src/attributes.d.ts +0 -109
  74. package/dist/src/attributes.js +0 -356
  75. package/dist/src/converter.d.ts +0 -33
  76. package/dist/src/converter.js +0 -134
  77. package/dist/src/converterFlags.d.ts +0 -87
  78. package/dist/src/converterFlags.js +0 -242
  79. package/dist/src/converterRule.d.ts +0 -77
  80. package/dist/src/converterRule.js +0 -209
  81. package/dist/src/extLink.d.ts +0 -43
  82. package/dist/src/extLink.js +0 -191
  83. package/dist/src/gallery.d.ts +0 -54
  84. package/dist/src/gallery.js +0 -139
  85. package/dist/src/heading.d.ts +0 -47
  86. package/dist/src/heading.js +0 -190
  87. package/dist/src/hidden.d.ts +0 -7
  88. package/dist/src/hidden.js +0 -23
  89. package/dist/src/html.d.ts +0 -65
  90. package/dist/src/html.js +0 -358
  91. package/dist/src/imageParameter.d.ts +0 -65
  92. package/dist/src/imageParameter.js +0 -257
  93. package/dist/src/imagemap.d.ts +0 -54
  94. package/dist/src/imagemap.js +0 -144
  95. package/dist/src/imagemapLink.d.ts +0 -31
  96. package/dist/src/imagemapLink.js +0 -93
  97. package/dist/src/index.d.ts +0 -143
  98. package/dist/src/index.js +0 -851
  99. package/dist/src/link/base.d.ts +0 -52
  100. package/dist/src/link/base.js +0 -228
  101. package/dist/src/link/category.d.ts +0 -13
  102. package/dist/src/link/category.js +0 -28
  103. package/dist/src/link/file.d.ts +0 -98
  104. package/dist/src/link/file.js +0 -272
  105. package/dist/src/link/galleryImage.d.ts +0 -32
  106. package/dist/src/link/galleryImage.js +0 -158
  107. package/dist/src/link/index.d.ts +0 -56
  108. package/dist/src/link/index.js +0 -133
  109. package/dist/src/magicLink.d.ts +0 -59
  110. package/dist/src/magicLink.js +0 -223
  111. package/dist/src/nested.d.ts +0 -43
  112. package/dist/src/nested.js +0 -105
  113. package/dist/src/nowiki/base.d.ts +0 -31
  114. package/dist/src/nowiki/base.js +0 -93
  115. package/dist/src/nowiki/comment.d.ts +0 -25
  116. package/dist/src/nowiki/comment.js +0 -76
  117. package/dist/src/nowiki/dd.d.ts +0 -8
  118. package/dist/src/nowiki/dd.js +0 -24
  119. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -18
  120. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  121. package/dist/src/nowiki/hr.d.ts +0 -5
  122. package/dist/src/nowiki/hr.js +0 -63
  123. package/dist/src/nowiki/index.d.ts +0 -16
  124. package/dist/src/nowiki/index.js +0 -27
  125. package/dist/src/nowiki/list.d.ts +0 -16
  126. package/dist/src/nowiki/list.js +0 -109
  127. package/dist/src/nowiki/listBase.d.ts +0 -5
  128. package/dist/src/nowiki/listBase.js +0 -61
  129. package/dist/src/nowiki/noinclude.d.ts +0 -10
  130. package/dist/src/nowiki/noinclude.js +0 -23
  131. package/dist/src/nowiki/quote.d.ts +0 -14
  132. package/dist/src/nowiki/quote.js +0 -131
  133. package/dist/src/onlyinclude.d.ts +0 -16
  134. package/dist/src/onlyinclude.js +0 -57
  135. package/dist/src/paramTag/index.d.ts +0 -37
  136. package/dist/src/paramTag/index.js +0 -77
  137. package/dist/src/paramTag/inputbox.d.ts +0 -8
  138. package/dist/src/paramTag/inputbox.js +0 -22
  139. package/dist/src/parameter.d.ts +0 -70
  140. package/dist/src/parameter.js +0 -264
  141. package/dist/src/pre.d.ts +0 -31
  142. package/dist/src/pre.js +0 -59
  143. package/dist/src/syntax.d.ts +0 -20
  144. package/dist/src/syntax.js +0 -86
  145. package/dist/src/table/base.d.ts +0 -27
  146. package/dist/src/table/base.js +0 -81
  147. package/dist/src/table/index.d.ts +0 -242
  148. package/dist/src/table/index.js +0 -497
  149. package/dist/src/table/td.d.ts +0 -86
  150. package/dist/src/table/td.js +0 -355
  151. package/dist/src/table/tr.d.ts +0 -32
  152. package/dist/src/table/tr.js +0 -58
  153. package/dist/src/table/trBase.d.ts +0 -53
  154. package/dist/src/table/trBase.js +0 -156
  155. package/dist/src/tagPair/ext.d.ts +0 -32
  156. package/dist/src/tagPair/ext.js +0 -203
  157. package/dist/src/tagPair/include.d.ts +0 -35
  158. package/dist/src/tagPair/include.js +0 -74
  159. package/dist/src/tagPair/index.d.ts +0 -27
  160. package/dist/src/tagPair/index.js +0 -128
  161. package/dist/src/transclude.d.ts +0 -167
  162. package/dist/src/transclude.js +0 -717
  163. package/dist/util/constants.js +0 -27
  164. package/dist/util/debug.js +0 -81
  165. package/dist/util/diff.js +0 -83
  166. package/dist/util/lint.js +0 -31
  167. package/dist/util/string.js +0 -60
  168. package/errors/README +0 -1
  169. package/printed/README +0 -1
@@ -1,257 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ImageParameterToken = exports.galleryParams = void 0;
4
- const string_1 = require("../util/string");
5
- const lint_1 = require("../util/lint");
6
- const debug_1 = require("../util/debug");
7
- const constants_1 = require("../util/constants");
8
- const index_1 = require("../index");
9
- const index_2 = require("./index");
10
- exports.galleryParams = new Set(['alt', 'link', 'lang', 'page', 'caption']);
11
- function validate(key, val, config, halfParsed, ext) {
12
- val = val.trim();
13
- let value = val.replace(/\0\d+t\x7F/gu, '').trim();
14
- switch (key) {
15
- case 'width':
16
- return !value || /^(?:\d+x?|\d*x\d+)(?:\s*px)?$/u.test(value);
17
- case 'link': {
18
- if (!value) {
19
- return val;
20
- }
21
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
22
- /^(?:\/\/(?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])|\0\d+m\x7F)(?:[^[\]<>"\0\t\n\p{Zs}]|\0\d+c\x7F)*$/iu;
23
- const regex = new RegExp(`^(?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\\d+m\x7F)${string_1.extUrlChar}$`, 'iu');
24
- if (regex.test(value)) {
25
- return val;
26
- }
27
- else if (value.startsWith('[[') && value.endsWith(']]')) {
28
- value = value.slice(2, -2);
29
- }
30
- const title = index_1.default.normalizeTitle(value, 0, false, config, halfParsed, true, true);
31
- return title.valid && title;
32
- }
33
- case 'lang':
34
- return (ext === 'svg' || ext === 'svgz') && !/[^a-z\d-]/u.test(value);
35
- case 'alt':
36
- case 'class':
37
- case 'manualthumb':
38
- return true;
39
- case 'page':
40
- return (ext === 'djvu' || ext === 'djv' || ext === 'pdf') && Number(value) > 0;
41
- default:
42
- return Boolean(value) && !isNaN(value);
43
- }
44
- }
45
- /** 图片参数 */
46
- class ImageParameterToken extends index_2.Token {
47
- type = 'image-parameter';
48
- #syntax = '';
49
- #extension;
50
- /* NOT FOR BROWSER END */
51
- /** 图片链接 */
52
- get link() {
53
- return this.name === 'link' ? validate('link', super.text(), this.getAttribute('config')) : undefined;
54
- }
55
- /* NOT FOR BROWSER */
56
- set link(value) {
57
- if (this.name === 'link') {
58
- this.setValue(value);
59
- }
60
- }
61
- /** getValue()的getter */
62
- get value() {
63
- return this.getValue();
64
- }
65
- set value(value) {
66
- this.setValue(value);
67
- }
68
- /** 图片大小 */
69
- get size() {
70
- if (this.name === 'width') {
71
- const size = this.getValue().trim();
72
- if (!size.includes('{{')) {
73
- const [width, height = ''] = size.split('x');
74
- return { width, height };
75
- }
76
- const token = index_1.default.parse(size, false, 2, this.getAttribute('config')), i = token.childNodes.findIndex(({ type, data }) => type === 'text' && data.includes('x'));
77
- if (i === -1) {
78
- return { width: size, height: '' };
79
- }
80
- const str = token.childNodes[i];
81
- str.splitText(str.data.indexOf('x')).splitText(1);
82
- return { width: (0, string_1.text)(token.childNodes.slice(0, i + 1)), height: (0, string_1.text)(token.childNodes.slice(i + 2)) };
83
- }
84
- return undefined;
85
- }
86
- set size(size) {
87
- if (this.name === 'width') {
88
- this.setValue(size && `${size.width}${size.height && 'x'}${size.height}`);
89
- }
90
- }
91
- /** 图片宽度 */
92
- get width() {
93
- return this.size?.width;
94
- }
95
- set width(width) {
96
- if (this.name === 'width') {
97
- const { height } = this;
98
- this.setValue(`${width || ''}${height && 'x'}${height}`);
99
- }
100
- }
101
- /** 图片高度 */
102
- get height() {
103
- return this.size?.height;
104
- }
105
- set height(height) {
106
- if (this.name === 'width') {
107
- this.setValue(`${this.width}${height ? `x${height}` : ''}`);
108
- }
109
- }
110
- /* NOT FOR BROWSER END */
111
- /** @param str 图片参数 */
112
- constructor(str, extension, config = index_1.default.getConfig(), accum = []) {
113
- let mt;
114
- const regexes = Object.entries(config.img).map(([syntax, param]) => [
115
- syntax,
116
- param,
117
- new RegExp(`^(\\s*)${syntax.replace('$1', '(.*)')}(\\s*)$`, 'u'),
118
- ]), param = regexes.find(([, key, regex]) => {
119
- mt = regex.exec(str);
120
- return mt
121
- && (mt.length !== 4
122
- || validate(key, mt[2], config, true, extension) !== false);
123
- });
124
- // @ts-expect-error mt already assigned
125
- if (param && mt) {
126
- if (mt.length === 3) {
127
- super(undefined, config, accum);
128
- this.#syntax = str;
129
- }
130
- else {
131
- super(mt[2], config, accum, {
132
- 'Stage-2': ':', '!HeadingToken': ':',
133
- });
134
- this.#syntax = `${mt[1]}${param[0]}${mt[3]}`;
135
- }
136
- this.setAttribute('name', param[1]);
137
- return;
138
- }
139
- super(str, { ...config, excludes: [...config.excludes ?? [], 'list'] }, accum);
140
- this.setAttribute('name', 'caption');
141
- this.setAttribute('stage', 7);
142
- /* NOT FOR BROWSER */
143
- this.#extension = extension;
144
- }
145
- /** @private */
146
- afterBuild() {
147
- if (this.parentNode?.type === 'gallery-image' && !exports.galleryParams.has(this.name)) {
148
- this.setAttribute('name', 'invalid');
149
- }
150
- }
151
- /** @private */
152
- toString() {
153
- return this.#syntax ? this.#syntax.replace('$1', super.toString()) : super.toString();
154
- }
155
- /** @override */
156
- text() {
157
- return this.#syntax ? this.#syntax.replace('$1', super.text()).trim() : super.text().trim();
158
- }
159
- /** @private */
160
- getAttribute(key) {
161
- if (key === 'plain') {
162
- return (this.name === 'caption');
163
- /* NOT FOR BROWSER */
164
- }
165
- else if (key === 'syntax') {
166
- return this.#syntax;
167
- /* NOT FOR BROWSER END */
168
- }
169
- return key === 'padding'
170
- ? Math.max(0, this.#syntax.indexOf('$1'))
171
- : super.getAttribute(key);
172
- }
173
- /** @override */
174
- lint(start = this.getAbsoluteIndex(), re) {
175
- const errors = super.lint(start, re), { link, name } = this;
176
- if (name === 'invalid') {
177
- const e = (0, lint_1.generateForSelf)(this, { start }, 'invalid-gallery', 'invalid gallery image parameter');
178
- e.fix = {
179
- range: [start, start + e.endIndex],
180
- text: '',
181
- };
182
- errors.push(e);
183
- }
184
- else if (typeof link === 'object' && link.encoded) {
185
- errors.push((0, lint_1.generateForSelf)(this, { start }, 'url-encoding', 'unnecessary URL encoding in an internal link'));
186
- }
187
- return errors;
188
- }
189
- /** 是否是不可变参数 */
190
- #isVoid() {
191
- return this.#syntax && !this.#syntax.includes('$1');
192
- }
193
- /** 获取参数值 */
194
- getValue() {
195
- return this.name === 'invalid' ? this.text() : this.#isVoid() || super.text();
196
- }
197
- /** @override */
198
- print() {
199
- if (this.#syntax) {
200
- return `<span class="wpb-image-parameter">${this.#syntax.replace('$1', `<span class="wpb-image-caption">${(0, string_1.print)(this.childNodes)}</span>`)}</span>`;
201
- }
202
- return super.print({ class: 'image-caption' });
203
- }
204
- /* NOT FOR BROWSER */
205
- /** @override */
206
- cloneNode() {
207
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config');
208
- return debug_1.Shadow.run(() => {
209
- // @ts-expect-error abstract class
210
- const token = new ImageParameterToken(this.#syntax.replace('$1', ''), this.#extension, config);
211
- token.replaceChildren(...cloned);
212
- token.setAttribute('name', this.name);
213
- token.setAttribute('syntax', this.#syntax);
214
- return token;
215
- });
216
- }
217
- /** @private */
218
- setAttribute(key, value) {
219
- if (key === 'syntax') {
220
- this.#syntax = value;
221
- }
222
- else {
223
- super.setAttribute(key, value);
224
- }
225
- }
226
- insertAt(token, i) {
227
- if (!debug_1.Shadow.running && this.#isVoid()) {
228
- throw new Error(`图片参数 ${this.name} 不接受自定义输入!`);
229
- }
230
- return super.insertAt(token, i);
231
- }
232
- /**
233
- * 设置参数值
234
- * @param value 参数值
235
- * @throws `Error` 无效参数
236
- */
237
- setValue(value = false) {
238
- const { name } = this;
239
- if (value === false) {
240
- this.remove();
241
- return;
242
- }
243
- else if (name === 'invalid') {
244
- throw new Error('当前节点是一个无效的图片参数!');
245
- }
246
- const type = this.#isVoid() ? 'Boolean' : 'String';
247
- if (typeof value !== type.toLowerCase()) { // eslint-disable-line valid-typeof
248
- this.typeError('setValue', type);
249
- }
250
- else if (value !== true) {
251
- const include = this.getAttribute('include'), config = this.getAttribute('config'), { childNodes } = index_1.default.parse(value, include, name === 'caption' ? undefined : 5, config);
252
- this.replaceChildren(...childNodes);
253
- }
254
- }
255
- }
256
- exports.ImageParameterToken = ImageParameterToken;
257
- constants_1.classes['ImageParameterToken'] = __filename;
@@ -1,54 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import { NoincludeToken } from './nowiki/noinclude';
4
- import { GalleryImageToken } from './link/galleryImage';
5
- import { ImagemapLinkToken } from './imagemapLink';
6
- import type { LintError } from '../base';
7
- import type { AstText, AttributesToken, ExtToken, AstNodes } from '../internal';
8
- /**
9
- * `<imagemap>`
10
- * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
11
- */
12
- export declare abstract class ImagemapToken extends Token {
13
- readonly type = "ext-inner";
14
- readonly name: 'imagemap';
15
- readonly childNodes: readonly (GalleryImageToken | NoincludeToken | ImagemapLinkToken | AstText)[];
16
- abstract get firstChild(): NoincludeToken | GalleryImageToken | undefined;
17
- abstract get lastChild(): GalleryImageToken | NoincludeToken | ImagemapLinkToken | AstText | undefined;
18
- abstract get nextSibling(): undefined;
19
- abstract get previousSibling(): AttributesToken;
20
- abstract get parentNode(): ExtToken | undefined;
21
- abstract get children(): (GalleryImageToken | NoincludeToken | ImagemapLinkToken)[];
22
- abstract get firstElementChild(): NoincludeToken | GalleryImageToken | undefined;
23
- abstract get lastElementChild(): GalleryImageToken | NoincludeToken | ImagemapLinkToken | undefined;
24
- abstract get nextElementSibling(): undefined;
25
- abstract get previousElementSibling(): AttributesToken;
26
- abstract get parentElement(): ExtToken | undefined;
27
- /** 图片 */
28
- get image(): GalleryImageToken | undefined;
29
- /** @param inner 标签内部wikitext */
30
- constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
31
- /** @override */
32
- text(): string;
33
- /** @override */
34
- lint(start?: number, re?: RegExp): LintError[];
35
- /** @override */
36
- print(): string;
37
- /**
38
- * @override
39
- * @param token 待插入的节点
40
- * @param i 插入位置
41
- * @throws `Error` 当前缺少合法图片
42
- * @throws `RangeError` 已有一张合法图片
43
- */
44
- insertAt(token: string, i?: number): AstText;
45
- insertAt<T extends AstNodes>(token: T, i?: number): T;
46
- /**
47
- * @override
48
- * @param i 移除位置
49
- * @throws `Error` 禁止移除图片
50
- */
51
- removeAt(i: number): AstNodes;
52
- /** @override */
53
- cloneNode(): this;
54
- }
@@ -1,144 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ImagemapToken = void 0;
4
- const lint_1 = require("../util/lint");
5
- const debug_1 = require("../util/debug");
6
- const constants_1 = require("../util/constants");
7
- const singleLine_1 = require("../mixin/singleLine");
8
- const index_1 = require("../index");
9
- const index_2 = require("./index");
10
- const noinclude_1 = require("./nowiki/noinclude");
11
- const galleryImage_1 = require("./link/galleryImage");
12
- const imagemapLink_1 = require("./imagemapLink");
13
- /**
14
- * `<imagemap>`
15
- * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
16
- */
17
- class ImagemapToken extends index_2.Token {
18
- type = 'ext-inner';
19
- /* NOT FOR BROWSER END */
20
- /** 图片 */
21
- get image() {
22
- return this.childNodes.find((0, debug_1.isToken)('imagemap-image'));
23
- }
24
- /** @param inner 标签内部wikitext */
25
- constructor(inner, config = index_1.default.getConfig(), accum = []) {
26
- super(undefined, config, accum, {
27
- GalleryImageToken: ':', ImagemapLinkToken: ':', NoincludeToken: ':', AstText: ':',
28
- });
29
- if (!inner) {
30
- return;
31
- }
32
- const lines = inner.split('\n'), protocols = new Set(config.protocol.split('|')), SingleLineNoincludeToken = (0, singleLine_1.singleLine)(noinclude_1.NoincludeToken);
33
- let first = true, error = false;
34
- for (const line of lines) {
35
- const trimmed = line.trim();
36
- if (error || !trimmed || trimmed.startsWith('#')) {
37
- //
38
- }
39
- else if (first) {
40
- const [file, ...options] = line.split('|'), title = this.normalizeTitle(file, 0, true);
41
- if (title.valid && !title.interwiki && title.ns === 6) {
42
- // @ts-expect-error abstract class
43
- const token = new galleryImage_1.GalleryImageToken('imagemap', file, options.length > 0 ? options.join('|') : undefined, config, accum);
44
- super.insertAt(token);
45
- first = false;
46
- continue;
47
- }
48
- else {
49
- error = true;
50
- }
51
- }
52
- else if (line.trim().split(/[\t ]/u)[0] === 'desc') {
53
- super.insertAt(line);
54
- continue;
55
- }
56
- else if (line.includes('[')) {
57
- const i = line.indexOf('['), substr = line.slice(i), mtIn = /^\[\[([^|]+)(?:\|([^\]]+))?\]\][\w\s]*$/u
58
- .exec(substr);
59
- if (mtIn) {
60
- if (this.normalizeTitle(mtIn[1], 0, true, false, true).valid) {
61
- // @ts-expect-error abstract class
62
- super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtIn.slice(1), substr.slice(substr.indexOf(']]') + 2), config, accum));
63
- continue;
64
- }
65
- }
66
- else if (protocols.has(substr.slice(1, substr.indexOf(':') + 1))
67
- || protocols.has(substr.slice(1, substr.indexOf('//') + 2))) {
68
- const mtEx = /^\[([^\]\s]+)(?:(\s+(?=\S))([^\]]*))?\][\w\s]*$/u
69
- .exec(substr);
70
- if (mtEx) {
71
- // @ts-expect-error abstract class
72
- super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtEx.slice(1), substr.slice(substr.indexOf(']') + 1), config, accum));
73
- continue;
74
- }
75
- }
76
- }
77
- // @ts-expect-error abstract class
78
- super.insertAt(new SingleLineNoincludeToken(line, config, accum));
79
- }
80
- }
81
- /** @private */
82
- toString() {
83
- return super.toString('\n');
84
- }
85
- /** @override */
86
- text() {
87
- return super.text('\n').replace(/\n{2,}/gu, '\n');
88
- }
89
- /** @private */
90
- getGaps() {
91
- return 1;
92
- }
93
- /** @override */
94
- lint(start = this.getAbsoluteIndex(), re) {
95
- const errors = super.lint(start, re), rect = { start, ...this.getRootNode().posFromIndex(start) };
96
- if (this.image) {
97
- errors.push(...this.childNodes.filter(child => {
98
- const str = String(child).trim();
99
- return child.type === 'noinclude' && str && !str.startsWith('#');
100
- }).map(child => (0, lint_1.generateForChild)(child, rect, 'invalid-imagemap', 'invalid link in <imagemap>')));
101
- }
102
- else {
103
- errors.push((0, lint_1.generateForSelf)(this, rect, 'invalid-imagemap', '<imagemap> without an image'));
104
- }
105
- return errors;
106
- }
107
- /** @override */
108
- print() {
109
- return super.print({ sep: '\n' });
110
- }
111
- insertAt(token, i) {
112
- const { image } = this;
113
- if (!image && (typeof token === 'string' || token.type === 'imagemap-link' || token.type === 'text')) {
114
- throw new Error('当前缺少一张合法图片!');
115
- }
116
- else if (image && typeof token !== 'string' && token.type === 'imagemap-image') {
117
- throw new RangeError('已有一张合法图片!');
118
- }
119
- return super.insertAt(token, i);
120
- }
121
- /**
122
- * @override
123
- * @param i 移除位置
124
- * @throws `Error` 禁止移除图片
125
- */
126
- removeAt(i) {
127
- if (this.childNodes[i]?.type === 'imagemap-image') {
128
- throw new Error('禁止移除<imagemap>内的图片!');
129
- }
130
- return super.removeAt(i);
131
- }
132
- /** @override */
133
- cloneNode() {
134
- const cloned = this.cloneChildNodes();
135
- return debug_1.Shadow.run(() => {
136
- // @ts-expect-error abstract class
137
- const token = new ImagemapToken(undefined, this.getAttribute('config'));
138
- token.append(...cloned);
139
- return token;
140
- });
141
- }
142
- }
143
- exports.ImagemapToken = ImagemapToken;
144
- constants_1.classes['ImagemapToken'] = __filename;
@@ -1,31 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import { NoincludeToken } from './nowiki/noinclude';
4
- import { LinkToken } from './link/index';
5
- import { ExtLinkToken } from './extLink';
6
- import type { Title } from '../lib/title';
7
- import type { AstText, ImagemapToken } from '../internal';
8
- /**
9
- * `<imagemap>`内的链接
10
- * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
11
- */
12
- export declare abstract class ImagemapLinkToken extends Token {
13
- readonly type = "imagemap-link";
14
- readonly childNodes: readonly [AstText, LinkToken | ExtLinkToken, NoincludeToken];
15
- abstract get firstChild(): AstText;
16
- abstract get lastChild(): NoincludeToken;
17
- abstract get parentNode(): ImagemapToken | undefined;
18
- abstract get children(): [LinkToken | ExtLinkToken, NoincludeToken];
19
- abstract get firstElementChild(): LinkToken | ExtLinkToken;
20
- abstract get lastElementChild(): NoincludeToken;
21
- abstract get parentElement(): ImagemapToken | undefined;
22
- /** 内外链接 */
23
- get link(): string | Title;
24
- set link(link: string);
25
- /**
26
- * @param pre 链接前的文本
27
- * @param linkStuff 内外链接
28
- * @param post 链接后的文本
29
- */
30
- constructor(pre: string, linkStuff: readonly [string, string | undefined, string | undefined] | readonly [string, string | undefined], post: string, config?: Parser.Config, accum?: Token[]);
31
- }
@@ -1,93 +0,0 @@
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.ImagemapLinkToken = void 0;
38
- const constants_1 = require("../util/constants");
39
- const fixed_1 = require("../mixin/fixed");
40
- const singleLine_1 = require("../mixin/singleLine");
41
- const index_1 = require("../index");
42
- const index_2 = require("./index");
43
- const noinclude_1 = require("./nowiki/noinclude");
44
- const index_3 = require("./link/index");
45
- const extLink_1 = require("./extLink");
46
- /**
47
- * `<imagemap>`内的链接
48
- * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
49
- */
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),
86
- // @ts-expect-error abstract class
87
- new noinclude_1.NoincludeToken(post, config, accum));
88
- }
89
- };
90
- return ImagemapLinkToken = _classThis;
91
- })();
92
- exports.ImagemapLinkToken = ImagemapLinkToken;
93
- constants_1.classes['ImagemapLinkToken'] = __filename;