wikiparser-node 0.11.0 → 1.0.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 (179) hide show
  1. package/README.md +10 -9
  2. package/bundle/bundle.min.js +37 -0
  3. package/config/llwiki.json +1 -35
  4. package/config/minimum.json +136 -0
  5. package/config/moegirl.json +1 -44
  6. package/config/zhwiki.json +1 -466
  7. package/extensions/dist/base.js +105 -0
  8. package/extensions/dist/editor.js +172 -0
  9. package/extensions/dist/highlight.js +46 -0
  10. package/extensions/dist/lint.js +43 -0
  11. package/extensions/editor.css +63 -0
  12. package/extensions/ui.css +119 -0
  13. package/i18n/zh-hans.json +1 -0
  14. package/i18n/zh-hant.json +1 -0
  15. package/package.json +38 -31
  16. package/config/.schema.json +0 -134
  17. package/dist/index.d.ts +0 -114
  18. package/dist/lib/element.d.ts +0 -162
  19. package/dist/lib/node.d.ts +0 -291
  20. package/dist/lib/ranges.d.ts +0 -37
  21. package/dist/lib/text.d.ts +0 -64
  22. package/dist/lib/title.d.ts +0 -21
  23. package/dist/mixin/attributeParent.d.ts +0 -9
  24. package/dist/mixin/fixedToken.d.ts +0 -8
  25. package/dist/mixin/hidden.d.ts +0 -8
  26. package/dist/mixin/singleLine.d.ts +0 -8
  27. package/dist/mixin/sol.d.ts +0 -8
  28. package/dist/parser/brackets.d.ts +0 -12
  29. package/dist/parser/commentAndExt.d.ts +0 -8
  30. package/dist/parser/converter.d.ts +0 -7
  31. package/dist/parser/externalLinks.d.ts +0 -7
  32. package/dist/parser/hrAndDoubleUnderscore.d.ts +0 -11
  33. package/dist/parser/html.d.ts +0 -7
  34. package/dist/parser/links.d.ts +0 -7
  35. package/dist/parser/list.d.ts +0 -7
  36. package/dist/parser/magicLinks.d.ts +0 -7
  37. package/dist/parser/quotes.d.ts +0 -7
  38. package/dist/parser/selector.d.ts +0 -12
  39. package/dist/parser/table.d.ts +0 -11
  40. package/dist/src/arg.d.ts +0 -54
  41. package/dist/src/atom/hidden.d.ts +0 -5
  42. package/dist/src/atom/index.d.ts +0 -15
  43. package/dist/src/attribute.d.ts +0 -65
  44. package/dist/src/attributes.d.ts +0 -112
  45. package/dist/src/charinsert.d.ts +0 -32
  46. package/dist/src/converter.d.ts +0 -103
  47. package/dist/src/converterFlags.d.ts +0 -83
  48. package/dist/src/converterRule.d.ts +0 -75
  49. package/dist/src/extLink.d.ts +0 -62
  50. package/dist/src/gallery.d.ts +0 -33
  51. package/dist/src/hasNowiki/index.d.ts +0 -14
  52. package/dist/src/hasNowiki/pre.d.ts +0 -13
  53. package/dist/src/heading.d.ts +0 -44
  54. package/dist/src/html.d.ts +0 -56
  55. package/dist/src/imageParameter.d.ts +0 -65
  56. package/dist/src/imagemap.d.ts +0 -37
  57. package/dist/src/imagemapLink.d.ts +0 -21
  58. package/dist/src/index.d.ts +0 -186
  59. package/dist/src/link/category.d.ts +0 -16
  60. package/dist/src/link/file.d.ts +0 -85
  61. package/dist/src/link/galleryImage.d.ts +0 -15
  62. package/dist/src/link/index.d.ts +0 -88
  63. package/dist/src/magicLink.d.ts +0 -36
  64. package/dist/src/nested/choose.d.ts +0 -13
  65. package/dist/src/nested/combobox.d.ts +0 -13
  66. package/dist/src/nested/index.d.ts +0 -18
  67. package/dist/src/nested/references.d.ts +0 -13
  68. package/dist/src/nowiki/comment.d.ts +0 -31
  69. package/dist/src/nowiki/dd.d.ts +0 -17
  70. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -22
  71. package/dist/src/nowiki/hr.d.ts +0 -13
  72. package/dist/src/nowiki/index.d.ts +0 -27
  73. package/dist/src/nowiki/list.d.ts +0 -8
  74. package/dist/src/nowiki/noinclude.d.ts +0 -8
  75. package/dist/src/nowiki/quote.d.ts +0 -13
  76. package/dist/src/onlyinclude.d.ts +0 -24
  77. package/dist/src/paramTag/index.d.ts +0 -29
  78. package/dist/src/paramTag/inputbox.d.ts +0 -8
  79. package/dist/src/parameter.d.ts +0 -75
  80. package/dist/src/syntax.d.ts +0 -20
  81. package/dist/src/table/index.d.ts +0 -273
  82. package/dist/src/table/td.d.ts +0 -100
  83. package/dist/src/table/tr.d.ts +0 -91
  84. package/dist/src/tagPair/ext.d.ts +0 -18
  85. package/dist/src/tagPair/include.d.ts +0 -25
  86. package/dist/src/tagPair/index.d.ts +0 -41
  87. package/dist/src/transclude.d.ts +0 -199
  88. package/dist/tool/index.d.ts +0 -420
  89. package/dist/util/base.d.ts +0 -10
  90. package/dist/util/debug.d.ts +0 -20
  91. package/dist/util/diff.d.ts +0 -8
  92. package/dist/util/lint.d.ts +0 -28
  93. package/dist/util/string.d.ts +0 -55
  94. package/index.js +0 -333
  95. package/lib/element.js +0 -618
  96. package/lib/node.js +0 -730
  97. package/lib/ranges.js +0 -130
  98. package/lib/text.js +0 -265
  99. package/lib/title.js +0 -83
  100. package/mixin/attributeParent.js +0 -117
  101. package/mixin/fixedToken.js +0 -40
  102. package/mixin/hidden.js +0 -21
  103. package/mixin/singleLine.js +0 -31
  104. package/mixin/sol.js +0 -54
  105. package/parser/brackets.js +0 -128
  106. package/parser/commentAndExt.js +0 -62
  107. package/parser/converter.js +0 -46
  108. package/parser/externalLinks.js +0 -33
  109. package/parser/hrAndDoubleUnderscore.js +0 -49
  110. package/parser/html.js +0 -42
  111. package/parser/links.js +0 -94
  112. package/parser/list.js +0 -59
  113. package/parser/magicLinks.js +0 -41
  114. package/parser/quotes.js +0 -64
  115. package/parser/selector.js +0 -180
  116. package/parser/table.js +0 -114
  117. package/src/arg.js +0 -207
  118. package/src/atom/hidden.js +0 -13
  119. package/src/atom/index.js +0 -43
  120. package/src/attribute.js +0 -472
  121. package/src/attributes.js +0 -453
  122. package/src/charinsert.js +0 -97
  123. package/src/converter.js +0 -176
  124. package/src/converterFlags.js +0 -284
  125. package/src/converterRule.js +0 -256
  126. package/src/extLink.js +0 -180
  127. package/src/gallery.js +0 -149
  128. package/src/hasNowiki/index.js +0 -44
  129. package/src/hasNowiki/pre.js +0 -40
  130. package/src/heading.js +0 -134
  131. package/src/html.js +0 -254
  132. package/src/imageParameter.js +0 -303
  133. package/src/imagemap.js +0 -199
  134. package/src/imagemapLink.js +0 -41
  135. package/src/index.js +0 -938
  136. package/src/link/category.js +0 -44
  137. package/src/link/file.js +0 -287
  138. package/src/link/galleryImage.js +0 -120
  139. package/src/link/index.js +0 -388
  140. package/src/magicLink.js +0 -151
  141. package/src/nested/choose.js +0 -24
  142. package/src/nested/combobox.js +0 -23
  143. package/src/nested/index.js +0 -96
  144. package/src/nested/references.js +0 -23
  145. package/src/nowiki/comment.js +0 -71
  146. package/src/nowiki/dd.js +0 -59
  147. package/src/nowiki/doubleUnderscore.js +0 -56
  148. package/src/nowiki/hr.js +0 -41
  149. package/src/nowiki/index.js +0 -56
  150. package/src/nowiki/list.js +0 -16
  151. package/src/nowiki/noinclude.js +0 -28
  152. package/src/nowiki/quote.js +0 -69
  153. package/src/onlyinclude.js +0 -64
  154. package/src/paramTag/index.js +0 -89
  155. package/src/paramTag/inputbox.js +0 -35
  156. package/src/parameter.js +0 -239
  157. package/src/syntax.js +0 -91
  158. package/src/table/index.js +0 -985
  159. package/src/table/td.js +0 -343
  160. package/src/table/tr.js +0 -319
  161. package/src/tagPair/ext.js +0 -146
  162. package/src/tagPair/include.js +0 -50
  163. package/src/tagPair/index.js +0 -131
  164. package/src/transclude.js +0 -843
  165. package/tool/index.js +0 -1209
  166. package/typings/api.d.ts +0 -9
  167. package/typings/array.d.ts +0 -29
  168. package/typings/event.d.ts +0 -22
  169. package/typings/index.d.ts +0 -118
  170. package/typings/node.d.ts +0 -35
  171. package/typings/parser.d.ts +0 -12
  172. package/typings/table.d.ts +0 -10
  173. package/typings/token.d.ts +0 -31
  174. package/typings/tool.d.ts +0 -6
  175. package/util/base.js +0 -17
  176. package/util/debug.js +0 -73
  177. package/util/diff.js +0 -76
  178. package/util/lint.js +0 -57
  179. package/util/string.js +0 -126
@@ -1,44 +0,0 @@
1
- 'use strict';
2
-
3
- const {decodeHtml} = require('../../util/string'),
4
- Parser = require('../..'),
5
- LinkToken = require('.');
6
-
7
- /**
8
- * 分类
9
- * @classdesc `{childNodes: [AtomToken, ?Token]}`
10
- */
11
- class CategoryToken extends LinkToken {
12
- type = 'category';
13
-
14
- /** 分类排序关键字 */
15
- get sortkey() {
16
- return decodeHtml(this.childNodes[1]?.text());
17
- }
18
-
19
- set sortkey(text) {
20
- this.setSortkey(text);
21
- }
22
-
23
- /**
24
- * @param {string} link 分类名
25
- * @param {string|undefined} text 排序关键字
26
- * @param {import('../../typings/token').accum} accum
27
- * @param {string} delimiter `|`
28
- */
29
- constructor(link, text, config = Parser.getConfig(), accum = [], delimiter = '|') {
30
- super(link, text, config, accum, delimiter);
31
- this.seal(['selfLink', 'interwiki', 'setLangLink', 'setFragment', 'asSelfLink', 'pipeTrick'], true);
32
- }
33
-
34
- /**
35
- * 设置排序关键字
36
- * @param {string} text 排序关键字
37
- */
38
- setSortkey(text) {
39
- this.setLinkText(text);
40
- }
41
- }
42
-
43
- Parser.classes.CategoryToken = __filename;
44
- module.exports = CategoryToken;
package/src/link/file.js DELETED
@@ -1,287 +0,0 @@
1
- 'use strict';
2
-
3
- const {explode, noWrap} = require('../../util/string'),
4
- {generateForChild} = require('../../util/lint'),
5
- Parser = require('../..'),
6
- LinkToken = require('.'),
7
- ImageParameterToken = require('../imageParameter');
8
-
9
- const frame = new Set(['manualthumb', 'frameless', 'framed', 'thumbnail']),
10
- horizAlign = new Set(['left', 'right', 'center', 'none']),
11
- vertAlign = new Set(['baseline', 'sub', 'super', 'top', 'text-top', 'middle', 'bottom', 'text-bottom']);
12
-
13
- /**
14
- * 图片
15
- * @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
16
- */
17
- class FileToken extends LinkToken {
18
- type = 'file';
19
-
20
- /** 图片链接 */
21
- get link() {
22
- return this.getArg('link')?.link;
23
- }
24
-
25
- set link(value) {
26
- this.setValue('link', value);
27
- }
28
-
29
- /** 图片大小 */
30
- get size() {
31
- return this.getArg('width')?.size;
32
- }
33
-
34
- /** 图片宽度 */
35
- get width() {
36
- return this.size?.width;
37
- }
38
-
39
- set width(width) {
40
- const arg = this.getArg('width');
41
- if (arg) {
42
- arg.width = width;
43
- } else {
44
- this.setValue('width', width);
45
- }
46
- }
47
-
48
- /** 图片高度 */
49
- get height() {
50
- return this.size?.height;
51
- }
52
-
53
- set height(height) {
54
- const arg = this.getArg('width');
55
- if (arg) {
56
- arg.height = height;
57
- } else {
58
- this.setValue('width', `x${height}`);
59
- }
60
- }
61
-
62
- /**
63
- * @param {string} link 文件名
64
- * @param {string|undefined} text 图片参数
65
- * @param {import('../../typings/token').accum} accum
66
- * @param {string} delimiter `|`
67
- * @complexity `n`
68
- */
69
- constructor(link, text, config = Parser.getConfig(), accum = [], delimiter = '|') {
70
- super(link, undefined, config, accum, delimiter);
71
- this.setAttribute('acceptable', {AtomToken: 0, ImageParameterToken: '1:'});
72
- this.append(...explode('-{', '}-', '|', text).map(part => new ImageParameterToken(part, config, accum)));
73
- this.seal(
74
- ['selfLink', 'interwiki', 'setLangLink', 'setFragment', 'asSelfLink', 'setLinkText', 'pipeTrick'],
75
- true,
76
- );
77
- }
78
-
79
- /**
80
- * @override
81
- * @param {number} start 起始位置
82
- */
83
- lint(start = this.getAbsoluteIndex()) {
84
- const errors = super.lint(start),
85
- args = this.getAllArgs().filter(({childNodes}) => {
86
- const visibleNodes = childNodes.filter(node => node.text().trim());
87
- return visibleNodes.length !== 1 || visibleNodes[0].type !== 'arg';
88
- }),
89
- keys = [...new Set(args.map(({name}) => name))].filter(key => key !== 'invalid'),
90
- frameKeys = keys.filter(key => frame.has(key)),
91
- horizAlignKeys = keys.filter(key => horizAlign.has(key)),
92
- vertAlignKeys = keys.filter(key => vertAlign.has(key));
93
- if (args.length === keys.length
94
- && frameKeys.length < 2 && horizAlignKeys.length < 2 && vertAlignKeys.length < 2
95
- ) {
96
- return errors;
97
- }
98
- const rect = {start, ...this.getRootNode().posFromIndex(start)};
99
- for (const key of keys) {
100
- let relevantArgs = args.filter(({name}) => name === key);
101
- if (key === 'caption') {
102
- relevantArgs = [
103
- ...relevantArgs.slice(0, -1).filter(arg => arg.text()),
104
- relevantArgs.at(-1),
105
- ];
106
- }
107
- if (relevantArgs.length > 1) {
108
- errors.push(...relevantArgs.map(
109
- arg => generateForChild(arg, rect, Parser.msg('duplicated image $1 parameter', key)),
110
- ));
111
- }
112
- }
113
- if (frameKeys.size > 1) {
114
- errors.push(
115
- ...args.filter(({name}) => frame.has(name)).map(
116
- arg => generateForChild(arg, rect, 'conflicting image $1 parameter', 'frame'),
117
- ),
118
- );
119
- }
120
- if (horizAlignKeys.size > 1) {
121
- errors.push(
122
- ...args.filter(({name}) => horizAlign.has(name))
123
- .map(arg => generateForChild(arg, rect, 'conflicting image $1 parameter', 'horizontal-alignment')),
124
- );
125
- }
126
- if (vertAlignKeys.size > 1) {
127
- errors.push(
128
- ...args.filter(({name}) => vertAlign.has(name))
129
- .map(arg => generateForChild(arg, rect, 'conflicting image $1 parameter', 'vertical-alignment')),
130
- );
131
- }
132
- return errors;
133
- }
134
-
135
- /**
136
- * 获取所有图片参数节点
137
- * @returns {ImageParameterToken[]}
138
- */
139
- getAllArgs() {
140
- return this.childNodes.slice(1);
141
- }
142
-
143
- /**
144
- * 获取指定图片参数
145
- * @param {string} key 参数名
146
- * @complexity `n`
147
- */
148
- getArgs(key) {
149
- return typeof key === 'string'
150
- ? this.getAllArgs().filter(({name}) => key === name)
151
- : this.typeError('getArgs', 'String');
152
- }
153
-
154
- /**
155
- * 获取特定类型的图片属性参数节点
156
- * @param {Set<string>} keys 接受的参数名
157
- * @param {type} type 类型名
158
- * @complexity `n`
159
- */
160
- #getTypedArgs(keys, type) {
161
- const args = this.getAllArgs().filter(({name}) => keys.has(name));
162
- if (args.length > 1) {
163
- Parser.warn(`图片 ${this.name} 带有 ${args.length} 个${type}参数,只有最后 1 个 ${args[0].name} 会生效!`);
164
- }
165
- return args;
166
- }
167
-
168
- /** 获取图片框架属性参数节点 */
169
- getFrameArgs() {
170
- return this.#getTypedArgs(frame, '框架');
171
- }
172
-
173
- /** 获取图片水平对齐参数节点 */
174
- getHorizAlignArgs() {
175
- return this.#getTypedArgs(horizAlign, '水平对齐');
176
- }
177
-
178
- /** 获取图片垂直对齐参数节点 */
179
- getVertAlignArgs() {
180
- return this.#getTypedArgs(vertAlign, '垂直对齐');
181
- }
182
-
183
- /**
184
- * 获取生效的指定图片参数
185
- * @param {string} key 参数名
186
- * @complexity `n`
187
- */
188
- getArg(key) {
189
- return this.getArgs(key).at(-1);
190
- }
191
-
192
- /**
193
- * 是否具有指定图片参数
194
- * @param {string} key 参数名
195
- * @complexity `n`
196
- */
197
- hasArg(key) {
198
- return this.getArgs(key).length > 0;
199
- }
200
-
201
- /**
202
- * 移除指定图片参数
203
- * @param {string} key 参数名
204
- * @complexity `n`
205
- */
206
- removeArg(key) {
207
- for (const token of this.getArgs(key)) {
208
- this.removeChild(token);
209
- }
210
- }
211
-
212
- /**
213
- * 获取图片参数名
214
- * @complexity `n`
215
- */
216
- getKeys() {
217
- return this.getAllArgs().map(({name}) => name);
218
- }
219
-
220
- /**
221
- * 获取指定的图片参数值
222
- * @param {string} key 参数名
223
- * @complexity `n`
224
- */
225
- getValues(key) {
226
- return this.getArgs(key).map(token => token.getValue());
227
- }
228
-
229
- /**
230
- * 获取生效的指定图片参数值
231
- * @param {string} key 参数名
232
- * @complexity `n`
233
- */
234
- getValue(key) {
235
- return this.getArg(key)?.getValue();
236
- }
237
-
238
- /**
239
- * 设置图片参数
240
- * @param {string} key 参数名
241
- * @param {string|boolean} value 参数值
242
- * @complexity `n`
243
- * @throws `RangeError` 未定义的图片参数
244
- * @throws `SyntaxError` 非法的参数
245
- */
246
- setValue(key, value) {
247
- if (typeof key !== 'string') {
248
- this.typeError('setValue', 'String');
249
- } else if (value === false) {
250
- this.removeArg(key);
251
- return;
252
- }
253
- const token = this.getArg(key);
254
- value = value === true ? value : String(value);
255
- if (token) {
256
- token.setValue(value);
257
- return;
258
- }
259
- let syntax = '';
260
- const config = this.getAttribute('config');
261
- if (key !== 'caption') {
262
- syntax = Object.entries(config.img).find(([, name]) => name === key)?.[0];
263
- if (!syntax) {
264
- throw new RangeError(`未定义的图片参数: ${key}`);
265
- }
266
- }
267
- if (value === true) {
268
- if (syntax.includes('$1')) {
269
- this.typeError('setValue', 'Boolean');
270
- }
271
- const newArg = Parser.run(() => new ImageParameterToken(syntax, config));
272
- this.insertAt(newArg);
273
- return;
274
- }
275
- const wikitext = `[[File:F|${syntax ? syntax.replace('$1', value) : value}]]`,
276
- root = Parser.parse(wikitext, this.getAttribute('include'), 6, config),
277
- {length, firstChild: file} = root,
278
- {name, type, length: fileLength, lastChild: imageParameter} = file;
279
- if (length !== 1 || type !== 'file' || name !== 'File:F' || fileLength !== 2 || imageParameter.name !== key) {
280
- throw new SyntaxError(`非法的 ${key} 参数:${noWrap(value)}`);
281
- }
282
- this.insertAt(imageParameter);
283
- }
284
- }
285
-
286
- Parser.classes.FileToken = __filename;
287
- module.exports = FileToken;
@@ -1,120 +0,0 @@
1
- 'use strict';
2
-
3
- const {generateForSelf} = require('../../util/lint'),
4
- {undo} = require('../../util/debug'),
5
- singleLine = require('../../mixin/singleLine'),
6
- Parser = require('../..'),
7
- Token = require('..'),
8
- FileToken = require('./file');
9
-
10
- /**
11
- * 图片
12
- * @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
13
- */
14
- class GalleryImageToken extends singleLine(FileToken) {
15
- type = 'gallery-image';
16
- #invalid = false;
17
-
18
- /** 图片链接 */
19
- get link() {
20
- return this.type === 'imagemap-image' ? undefined : super.link;
21
- }
22
-
23
- set link(value) {
24
- if (this.type !== 'imagemap-image') {
25
- super.link = value;
26
- }
27
- }
28
-
29
- /**
30
- * @param {string} link 图片文件名
31
- * @param {string|undefined} text 图片参数
32
- * @param {import('../../typings/token').accum} accum
33
- */
34
- constructor(link, text, config = Parser.getConfig(), accum = []) {
35
- let token;
36
- if (text !== undefined) {
37
- token = new Token(text, config, true, accum);
38
- token.type = 'temp';
39
- for (let n = 1; n < Parser.MAX_STAGE; n++) {
40
- token.getAttribute('parseOnce')();
41
- }
42
- accum.splice(accum.indexOf(token), 1);
43
- }
44
- super(link, token?.toString(), config, accum);
45
- this.setAttribute('bracket', false);
46
- if (!Object.values(config.img).includes('width')) {
47
- this.seal(['size', 'width', 'height'], true);
48
- }
49
- }
50
-
51
- /**
52
- * @override
53
- * @throws `Error` 非法的内链目标
54
- * @throws `Error` 不可更改命名空间
55
- */
56
- afterBuild() {
57
- const initImagemap = this.type === 'imagemap-image',
58
- titleObj = this.normalizeTitle(String(this.firstChild), initImagemap ? 0 : 6, true, !initImagemap);
59
- this.setAttribute('name', titleObj.title);
60
- this.#invalid = titleObj.interwiki || titleObj.ns !== 6; // 只用于gallery-image的首次解析
61
- const /** @type {import('../../typings/event').AstListener} */ linkListener = (e, data) => {
62
- const {prevTarget} = e;
63
- if (prevTarget?.type === 'link-target') {
64
- const name = String(prevTarget),
65
- imagemap = this.type === 'imagemap-image',
66
- {title, interwiki, ns, valid} = this.normalizeTitle(name, imagemap ? 0 : 6, true, !imagemap);
67
- if (!valid) {
68
- undo(e, data);
69
- throw new Error(`非法的图片文件名:${name}`);
70
- } else if (interwiki || ns !== 6) {
71
- undo(e, data);
72
- throw new Error(`图片链接不可更改命名空间:${name}`);
73
- }
74
- this.setAttribute('name', title);
75
- this.#invalid = false;
76
- }
77
- };
78
- this.addEventListener(['remove', 'insert', 'replace', 'text'], linkListener);
79
- }
80
-
81
- /** @override */
82
- getPadding() {
83
- return 0;
84
- }
85
-
86
- /**
87
- * @override
88
- * @param {number} start 起始位置
89
- */
90
- lint(start = this.getAbsoluteIndex()) {
91
- const errors = super.lint(start);
92
- if (this.#invalid) {
93
- errors.push(generateForSelf(this, {start}, 'invalid gallery image'));
94
- }
95
- return errors;
96
- }
97
-
98
- /**
99
- * @override
100
- * @param {string} link 链接目标
101
- * @throws `SyntaxError` 非法的链接目标
102
- */
103
- setTarget(link) {
104
- link = String(link);
105
- const include = this.getAttribute('include'),
106
- config = this.getAttribute('config'),
107
- root = Parser.parse(`<gallery>${link}</gallery>`, include, 1, config),
108
- {length, firstChild: gallery} = root,
109
- {type, lastChild: {length: galleryLength, firstChild: image}} = gallery;
110
- if (length !== 1 || type !== 'ext' || galleryLength !== 1 || image.type !== 'gallery-image') {
111
- throw new SyntaxError(`非法的图库文件名:${link}`);
112
- }
113
- const {firstChild} = image;
114
- image.destroy();
115
- this.firstChild.safeReplaceWith(firstChild);
116
- }
117
- }
118
-
119
- Parser.classes.GalleryImageToken = __filename;
120
- module.exports = GalleryImageToken;