wikiparser-node 1.3.2 → 1.3.3-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 (154) hide show
  1. package/bundle/bundle.min.js +36 -0
  2. package/config/llwiki.json +1 -35
  3. package/config/moegirl.json +1 -44
  4. package/config/zhwiki.json +1 -466
  5. package/extensions/dist/base.js +68 -0
  6. package/extensions/dist/editor.js +159 -0
  7. package/extensions/dist/highlight.js +30 -0
  8. package/extensions/dist/lint.js +48 -0
  9. package/extensions/editor.css +63 -0
  10. package/extensions/ui.css +114 -0
  11. package/package.json +32 -12
  12. package/config/.schema.json +0 -172
  13. package/dist/addon/table.d.ts +0 -6
  14. package/dist/addon/table.js +0 -564
  15. package/dist/base.d.ts +0 -45
  16. package/dist/bin/toc.js +0 -18
  17. package/dist/index.d.ts +0 -31
  18. package/dist/index.js +0 -209
  19. package/dist/internal.d.ts +0 -44
  20. package/dist/lib/element.d.ts +0 -155
  21. package/dist/lib/element.js +0 -634
  22. package/dist/lib/node.d.ts +0 -146
  23. package/dist/lib/node.js +0 -419
  24. package/dist/lib/range.d.ts +0 -104
  25. package/dist/lib/range.js +0 -385
  26. package/dist/lib/ranges.d.ts +0 -26
  27. package/dist/lib/ranges.js +0 -117
  28. package/dist/lib/text.d.ts +0 -62
  29. package/dist/lib/text.js +0 -248
  30. package/dist/lib/title.d.ts +0 -38
  31. package/dist/lib/title.js +0 -162
  32. package/dist/mixin/attributesParent.js +0 -94
  33. package/dist/mixin/fixed.js +0 -32
  34. package/dist/mixin/flagsParent.js +0 -70
  35. package/dist/mixin/hidden.js +0 -26
  36. package/dist/mixin/magicLinkParent.js +0 -41
  37. package/dist/mixin/singleLine.js +0 -25
  38. package/dist/mixin/sol.js +0 -43
  39. package/dist/mixin/syntax.js +0 -56
  40. package/dist/parser/braces.js +0 -121
  41. package/dist/parser/commentAndExt.js +0 -69
  42. package/dist/parser/converter.js +0 -40
  43. package/dist/parser/externalLinks.js +0 -28
  44. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  45. package/dist/parser/html.js +0 -36
  46. package/dist/parser/links.js +0 -94
  47. package/dist/parser/list.js +0 -59
  48. package/dist/parser/magicLinks.js +0 -40
  49. package/dist/parser/quotes.js +0 -67
  50. package/dist/parser/selector.js +0 -162
  51. package/dist/parser/table.js +0 -112
  52. package/dist/src/arg.d.ts +0 -58
  53. package/dist/src/arg.js +0 -189
  54. package/dist/src/atom.d.ts +0 -12
  55. package/dist/src/atom.js +0 -27
  56. package/dist/src/attribute.d.ts +0 -87
  57. package/dist/src/attribute.js +0 -392
  58. package/dist/src/attributes.d.ts +0 -107
  59. package/dist/src/attributes.js +0 -341
  60. package/dist/src/converter.d.ts +0 -52
  61. package/dist/src/converter.js +0 -79
  62. package/dist/src/converterFlags.d.ts +0 -87
  63. package/dist/src/converterFlags.js +0 -224
  64. package/dist/src/converterRule.d.ts +0 -81
  65. package/dist/src/converterRule.js +0 -212
  66. package/dist/src/extLink.d.ts +0 -54
  67. package/dist/src/extLink.js +0 -122
  68. package/dist/src/gallery.d.ts +0 -55
  69. package/dist/src/gallery.js +0 -122
  70. package/dist/src/heading.d.ts +0 -74
  71. package/dist/src/heading.js +0 -127
  72. package/dist/src/hidden.d.ts +0 -22
  73. package/dist/src/hidden.js +0 -23
  74. package/dist/src/html.d.ts +0 -101
  75. package/dist/src/html.js +0 -222
  76. package/dist/src/imageParameter.d.ts +0 -66
  77. package/dist/src/imageParameter.js +0 -247
  78. package/dist/src/imagemap.d.ts +0 -57
  79. package/dist/src/imagemap.js +0 -148
  80. package/dist/src/imagemapLink.d.ts +0 -59
  81. package/dist/src/imagemapLink.js +0 -40
  82. package/dist/src/index.d.ts +0 -146
  83. package/dist/src/index.js +0 -777
  84. package/dist/src/link/base.d.ts +0 -52
  85. package/dist/src/link/base.js +0 -209
  86. package/dist/src/link/category.d.ts +0 -13
  87. package/dist/src/link/category.js +0 -29
  88. package/dist/src/link/file.d.ts +0 -96
  89. package/dist/src/link/file.js +0 -255
  90. package/dist/src/link/galleryImage.d.ts +0 -44
  91. package/dist/src/link/galleryImage.js +0 -106
  92. package/dist/src/link/index.d.ts +0 -53
  93. package/dist/src/link/index.js +0 -123
  94. package/dist/src/magicLink.d.ts +0 -70
  95. package/dist/src/magicLink.js +0 -147
  96. package/dist/src/nested.d.ts +0 -44
  97. package/dist/src/nested.js +0 -87
  98. package/dist/src/nowiki/base.d.ts +0 -47
  99. package/dist/src/nowiki/base.js +0 -42
  100. package/dist/src/nowiki/comment.d.ts +0 -40
  101. package/dist/src/nowiki/comment.js +0 -67
  102. package/dist/src/nowiki/dd.d.ts +0 -8
  103. package/dist/src/nowiki/dd.js +0 -25
  104. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -45
  105. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  106. package/dist/src/nowiki/hr.d.ts +0 -31
  107. package/dist/src/nowiki/hr.js +0 -14
  108. package/dist/src/nowiki/index.d.ts +0 -16
  109. package/dist/src/nowiki/index.js +0 -21
  110. package/dist/src/nowiki/list.d.ts +0 -30
  111. package/dist/src/nowiki/list.js +0 -48
  112. package/dist/src/nowiki/listBase.d.ts +0 -19
  113. package/dist/src/nowiki/listBase.js +0 -12
  114. package/dist/src/nowiki/noinclude.d.ts +0 -26
  115. package/dist/src/nowiki/noinclude.js +0 -25
  116. package/dist/src/nowiki/quote.d.ts +0 -23
  117. package/dist/src/nowiki/quote.js +0 -45
  118. package/dist/src/onlyinclude.d.ts +0 -16
  119. package/dist/src/onlyinclude.js +0 -57
  120. package/dist/src/paramTag/index.d.ts +0 -37
  121. package/dist/src/paramTag/index.js +0 -68
  122. package/dist/src/paramTag/inputbox.d.ts +0 -8
  123. package/dist/src/paramTag/inputbox.js +0 -23
  124. package/dist/src/parameter.d.ts +0 -85
  125. package/dist/src/parameter.js +0 -205
  126. package/dist/src/pre.d.ts +0 -28
  127. package/dist/src/pre.js +0 -51
  128. package/dist/src/syntax.d.ts +0 -28
  129. package/dist/src/syntax.js +0 -34
  130. package/dist/src/table/base.d.ts +0 -53
  131. package/dist/src/table/base.js +0 -78
  132. package/dist/src/table/index.d.ts +0 -229
  133. package/dist/src/table/index.js +0 -379
  134. package/dist/src/table/td.d.ts +0 -104
  135. package/dist/src/table/td.js +0 -261
  136. package/dist/src/table/tr.d.ts +0 -32
  137. package/dist/src/table/tr.js +0 -56
  138. package/dist/src/table/trBase.d.ts +0 -54
  139. package/dist/src/table/trBase.js +0 -159
  140. package/dist/src/tagPair/ext.d.ts +0 -56
  141. package/dist/src/tagPair/ext.js +0 -142
  142. package/dist/src/tagPair/include.d.ts +0 -53
  143. package/dist/src/tagPair/include.js +0 -63
  144. package/dist/src/tagPair/index.d.ts +0 -48
  145. package/dist/src/tagPair/index.js +0 -93
  146. package/dist/src/transclude.d.ts +0 -167
  147. package/dist/src/transclude.js +0 -689
  148. package/dist/util/constants.js +0 -108
  149. package/dist/util/debug.js +0 -64
  150. package/dist/util/diff.js +0 -72
  151. package/dist/util/lint.js +0 -46
  152. package/dist/util/string.js +0 -61
  153. package/errors/README +0 -1
  154. package/printed/README +0 -1
package/dist/src/html.js DELETED
@@ -1,222 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HtmlToken = void 0;
4
- const lint_1 = require("../util/lint");
5
- const string_1 = require("../util/string");
6
- const debug_1 = require("../util/debug");
7
- const constants_1 = require("../util/constants");
8
- const fixed_1 = require("../mixin/fixed");
9
- const attributesParent_1 = require("../mixin/attributesParent");
10
- const Parser = require("../index");
11
- const index_1 = require("./index");
12
- const magicWords = new Set(['if', 'ifeq', 'ifexpr', 'ifexist', 'iferror', 'switch']);
13
- /**
14
- * HTML标签
15
- * @classdesc `{childNodes: [AttributesToken]}`
16
- */
17
- class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fixed)(index_1.Token)) {
18
- type = 'html';
19
- #closing;
20
- #selfClosing;
21
- #tag;
22
- /** 是否是闭合标签 */
23
- get closing() {
24
- return this.#closing;
25
- }
26
- /* NOT FOR BROWSER */
27
- /** @throws `Error` 自封闭标签或空标签 */
28
- set closing(value) {
29
- if (!value) {
30
- this.#closing = false;
31
- return;
32
- }
33
- else if (this.selfClosing) {
34
- throw new Error('这是一个自封闭标签!');
35
- }
36
- const { html: [, , tags] } = this.getAttribute('config');
37
- if (tags.includes(this.name)) {
38
- throw new Error('这是一个空标签!');
39
- }
40
- this.#closing = true;
41
- }
42
- /** 是否自封闭 */
43
- get selfClosing() {
44
- return this.#selfClosing;
45
- }
46
- /** @throws `Error` 闭合标签或无效自封闭标签 */
47
- set selfClosing(value) {
48
- if (!value) {
49
- this.#selfClosing = false;
50
- return;
51
- }
52
- else if (this.closing) {
53
- throw new Error('这是一个闭合标签!');
54
- }
55
- const { html: [tags] } = this.getAttribute('config');
56
- if (tags.includes(this.name)) {
57
- throw new Error(`<${this.name}>标签自封闭无效!`);
58
- }
59
- this.#selfClosing = true;
60
- }
61
- /* NOT FOR BROWSER END */
62
- /**
63
- * @param name 标签名
64
- * @param attr 标签属性
65
- * @param closing 是否闭合
66
- * @param selfClosing 是否自封闭
67
- */
68
- constructor(name, attr, closing, selfClosing, config = Parser.getConfig(), accum = []) {
69
- super(undefined, config, accum);
70
- this.insertAt(attr);
71
- this.setAttribute('name', name.toLowerCase());
72
- this.#closing = closing;
73
- this.#selfClosing = selfClosing;
74
- this.#tag = name;
75
- }
76
- /** @private */
77
- toString(omit) {
78
- return omit && this.matchesTypes(omit)
79
- ? ''
80
- : `<${this.closing ? '/' : ''}${this.#tag}${super.toString(omit)}${this.selfClosing ? '/' : ''}>`;
81
- }
82
- /** @override */
83
- text() {
84
- const { closing } = this;
85
- return `<${closing ? '/' : ''}${this.#tag}${closing ? '' : super.text()}${this.#selfClosing ? '/' : ''}>`;
86
- }
87
- /** @private */
88
- getAttribute(key) {
89
- if (key === 'tag') {
90
- return this.#tag;
91
- }
92
- return key === 'padding'
93
- ? this.#tag.length + (this.closing ? 2 : 1)
94
- : super.getAttribute(key);
95
- }
96
- /** @override */
97
- lint(start = this.getAbsoluteIndex()) {
98
- const errors = super.lint(start);
99
- let refError;
100
- if (this.name === 'h1' && !this.closing) {
101
- refError = (0, lint_1.generateForSelf)(this, { start }, '<h1>');
102
- errors.push(refError);
103
- }
104
- if (this.closest('table-attrs')) {
105
- refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
106
- errors.push({
107
- ...refError,
108
- message: Parser.msg('HTML tag in table attributes'),
109
- });
110
- }
111
- try {
112
- this.findMatchingTag();
113
- }
114
- catch (e) {
115
- if (e instanceof SyntaxError) {
116
- const { message: errorMsg } = e;
117
- refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
118
- const [msg] = errorMsg.split(':'), error = { ...refError, message: Parser.msg(msg) };
119
- if (msg === 'unclosed tag') {
120
- error.severity = 'warning';
121
- }
122
- else if (msg === 'unmatched closing tag') {
123
- const ancestor = this.closest('magic-word');
124
- if (ancestor && magicWords.has(ancestor.name)) {
125
- error.severity = 'warning';
126
- }
127
- }
128
- errors.push(error);
129
- }
130
- }
131
- return errors;
132
- }
133
- /**
134
- * 搜索匹配的标签
135
- * @throws `SyntaxError` 同时闭合和自封闭的标签
136
- * @throws `SyntaxError` 无效自封闭标签
137
- * @throws `SyntaxError` 未闭合的标签
138
- */
139
- findMatchingTag() {
140
- const { html } = this.getAttribute('config'), { name: tagName, parentNode, closing } = this, string = (0, string_1.noWrap)(String(this));
141
- if (closing && (this.#selfClosing || html[2].includes(tagName))) {
142
- throw new SyntaxError(`tag that is both closing and self-closing: ${string}`);
143
- }
144
- else if (html[2].includes(tagName) || this.#selfClosing && html[1].includes(tagName)) { // 自封闭标签
145
- return this;
146
- }
147
- else if (this.#selfClosing && html[0].includes(tagName)) {
148
- throw new SyntaxError(`invalid self-closing tag: ${string}`);
149
- }
150
- else if (!parentNode) {
151
- return undefined;
152
- }
153
- const { childNodes } = parentNode, i = childNodes.indexOf(this), siblings = (closing ? childNodes.slice(0, i).reverse() : childNodes.slice(i + 1))
154
- .filter((child) => child.type === 'html' && child.name === tagName);
155
- let imbalance = closing ? -1 : 1;
156
- for (const token of siblings) {
157
- if (token.#closing) {
158
- imbalance--;
159
- }
160
- else {
161
- imbalance++;
162
- }
163
- if (imbalance === 0) {
164
- return token;
165
- }
166
- }
167
- throw new SyntaxError(`${closing ? 'unmatched closing' : 'unclosed'} tag: ${string}`);
168
- }
169
- /** @override */
170
- print() {
171
- return super.print({
172
- pre: `&lt;${this.closing ? '/' : ''}${this.#tag}`,
173
- post: `${this.#selfClosing ? '/' : ''}&gt;`,
174
- });
175
- }
176
- /* NOT FOR BROWSER */
177
- /** @override */
178
- cloneNode() {
179
- const [attr] = this.cloneChildNodes(), config = this.getAttribute('config');
180
- return debug_1.Shadow.run(() => new HtmlToken(this.#tag, attr, this.closing, this.selfClosing, config));
181
- }
182
- /**
183
- * 更换标签名
184
- * @param tag 标签名
185
- * @throws `RangeError` 非法的HTML标签
186
- */
187
- replaceTag(tag) {
188
- const name = tag.toLowerCase();
189
- if (!this.getAttribute('config').html.flat().includes(name)) {
190
- throw new RangeError(`非法的HTML标签:${tag}`);
191
- }
192
- this.setAttribute('name', name);
193
- this.#tag = tag;
194
- }
195
- /**
196
- * 修复无效自封闭标签
197
- * @throws `Error` 无法修复无效自封闭标签
198
- */
199
- fix() {
200
- const config = this.getAttribute('config'), { parentNode, name: tagName, firstChild, selfClosing } = this;
201
- if (!parentNode || !selfClosing || !config.html[0].includes(tagName)) {
202
- return;
203
- }
204
- else if (firstChild.text().trim()) {
205
- this.#selfClosing = false;
206
- this.after(Parser.parse(`</${this.name}>`, false, 3, this.getAttribute('config')).firstChild);
207
- return;
208
- }
209
- const { childNodes } = parentNode, i = childNodes.indexOf(this), prevSiblings = childNodes.slice(0, i)
210
- .filter((child) => child.type === 'html' && child.name === tagName), imbalance = prevSiblings.reduce((acc, { closing }) => acc + (closing ? 1 : -1), 0);
211
- if (imbalance < 0) {
212
- this.#selfClosing = false;
213
- this.#closing = true;
214
- }
215
- else {
216
- Parser.warn('无法修复无效自封闭标签', (0, string_1.noWrap)(String(this)));
217
- throw new Error(`无法修复无效自封闭标签:前文共有 ${imbalance} 个未匹配的闭合标签`);
218
- }
219
- }
220
- }
221
- exports.HtmlToken = HtmlToken;
222
- constants_1.classes['HtmlToken'] = __filename;
@@ -1,66 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- import type { LintError } from '../base';
4
- import type { Title } from '../lib/title';
5
- import type { AstNodes, AstText, AtomToken, FileToken } from '../internal';
6
- export declare const galleryParams: Set<string>;
7
- /** 图片参数 */
8
- export declare class ImageParameterToken extends Token {
9
- #private;
10
- readonly type = "image-parameter";
11
- readonly name: string;
12
- abstract get parentNode(): FileToken | undefined;
13
- abstract get parentElement(): FileToken | undefined;
14
- abstract get nextSibling(): this | undefined;
15
- abstract get nextElementSibling(): this | undefined;
16
- abstract get previousSibling(): AtomToken | this;
17
- abstract get previousElementSibling(): AtomToken | this;
18
- /** 图片链接 */
19
- get link(): string | Title | undefined;
20
- set link(value: string);
21
- /** getValue()的getter */
22
- get value(): string | true;
23
- set value(value: string | true);
24
- /** 图片大小 */
25
- get size(): {
26
- width: string;
27
- height: string;
28
- } | undefined;
29
- set size(size: {
30
- width: string;
31
- height: string;
32
- } | undefined);
33
- /** 图片宽度 */
34
- get width(): string | undefined;
35
- set width(width: string | undefined);
36
- /** 图片高度 */
37
- get height(): string | undefined;
38
- set height(height: string | undefined);
39
- /** @param str 图片参数 */
40
- constructor(str: string, config?: Parser.Config, accum?: Token[]);
41
- /** @override */
42
- text(): string;
43
- /** @override */
44
- lint(start?: number): LintError[];
45
- /** @override */
46
- print(): string;
47
- /** @override */
48
- cloneNode(): this;
49
- /**
50
- * @override
51
- * @param token 待插入的子节点
52
- * @param i 插入位置
53
- * @throws `Error` 不接受自定义输入的图片参数
54
- */
55
- insertAt(token: string, i?: number): AstText;
56
- /** @ignore */
57
- insertAt<T extends AstNodes>(token: T, i?: number): T;
58
- /** 获取参数值 */
59
- getValue(): string | true;
60
- /**
61
- * 设置参数值
62
- * @param value 参数值
63
- * @throws `Error` 无效参数
64
- */
65
- setValue(value?: string | boolean): void;
66
- }
@@ -1,247 +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 Parser = require("../index");
9
- const index_1 = require("./index");
10
- exports.galleryParams = new Set(['alt', 'link', 'lang', 'page', 'caption']);
11
- /** @ignore */
12
- function validate(key, val, config = Parser.getConfig(), halfParsed = false) {
13
- val = val.trim();
14
- let value = val.replace(/\0\d+t\x7F/gu, '').trim();
15
- switch (key) {
16
- case 'width':
17
- return !value || /^(?:\d+x?|\d*x\d+)$/u.test(value);
18
- case 'link': {
19
- if (!value) {
20
- return val;
21
- }
22
- const regex = new RegExp(`^(?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\\d+m\x7F)${string_1.extUrlChar}$`, 'iu');
23
- if (regex.test(value)) {
24
- return val;
25
- }
26
- else if (value.startsWith('[[') && value.endsWith(']]')) {
27
- value = value.slice(2, -2);
28
- }
29
- const title = Parser.normalizeTitle(value, 0, false, config, halfParsed, true, true);
30
- return title.valid && title;
31
- }
32
- case 'lang':
33
- return !value || config.variants.includes(value);
34
- case 'alt':
35
- case 'class':
36
- case 'manualthumb':
37
- return true;
38
- default:
39
- return !Number.isNaN(Number(value));
40
- }
41
- }
42
- /** 图片参数 */
43
- class ImageParameterToken extends index_1.Token {
44
- type = 'image-parameter';
45
- #syntax = '';
46
- /** 图片链接 */
47
- get link() {
48
- return this.name === 'link' ? validate('link', super.text(), this.getAttribute('config')) : undefined;
49
- }
50
- /* NOT FOR BROWSER */
51
- set link(value) {
52
- if (this.name === 'link') {
53
- this.setValue(value);
54
- }
55
- }
56
- /** getValue()的getter */
57
- get value() {
58
- return this.getValue();
59
- }
60
- set value(value) {
61
- this.setValue(value);
62
- }
63
- /** 图片大小 */
64
- get size() {
65
- if (this.name === 'width') {
66
- const size = this.getValue().trim();
67
- if (!size.includes('{{')) {
68
- const [width, height = ''] = size.split('x');
69
- return { width, height };
70
- }
71
- const token = Parser.parse(size, false, 2, this.getAttribute('config')), i = token.childNodes.findIndex(({ type, data }) => type === 'text' && data.includes('x'));
72
- if (i === -1) {
73
- return { width: size, height: '' };
74
- }
75
- const str = token.childNodes[i];
76
- str.splitText(str.data.indexOf('x')).splitText(1);
77
- return { width: (0, string_1.text)(token.childNodes.slice(0, i + 1)), height: (0, string_1.text)(token.childNodes.slice(i + 2)) };
78
- }
79
- return undefined;
80
- }
81
- set size(size) {
82
- if (this.name === 'width') {
83
- this.setValue(size && `${size.width}${size.height && 'x'}${size.height}`);
84
- }
85
- }
86
- /** 图片宽度 */
87
- get width() {
88
- return this.size?.width;
89
- }
90
- set width(width) {
91
- if (this.name === 'width') {
92
- const { height } = this;
93
- this.setValue(`${width || ''}${height && 'x'}${height}`);
94
- }
95
- }
96
- /** 图片高度 */
97
- get height() {
98
- return this.size?.height;
99
- }
100
- set height(height) {
101
- if (this.name === 'width') {
102
- this.setValue(`${this.width}${height ? `x${height}` : ''}`);
103
- }
104
- }
105
- /* NOT FOR BROWSER END */
106
- /** @param str 图片参数 */
107
- constructor(str, config = Parser.getConfig(), accum = []) {
108
- let mt;
109
- const regexes = Object.entries(config.img).map(([syntax, param]) => [
110
- syntax,
111
- param,
112
- new RegExp(`^(\\s*)${syntax.replace('$1', '(.*)')}(\\s*)$`, 'u'),
113
- ]), param = regexes.find(([, key, regex]) => {
114
- mt = regex.exec(str);
115
- return mt
116
- && (mt.length !== 4 || validate(key, mt[2], config, true) !== false);
117
- });
118
- // @ts-expect-error mt already assigned
119
- if (param && mt) {
120
- if (mt.length === 3) {
121
- super(undefined, config, accum);
122
- this.#syntax = str;
123
- }
124
- else {
125
- super(mt[2], config, accum, {
126
- 'Stage-2': ':', '!HeadingToken': ':',
127
- });
128
- this.#syntax = `${mt[1]}${param[0]}${mt[3]}`;
129
- }
130
- this.setAttribute('name', param[1]);
131
- return;
132
- }
133
- super(str, { ...config, excludes: [...config.excludes ?? [], 'list'] }, accum);
134
- this.setAttribute('name', 'caption');
135
- this.setAttribute('stage', 7);
136
- }
137
- /** @private */
138
- afterBuild() {
139
- if (this.parentNode?.type === 'gallery-image' && !exports.galleryParams.has(this.name)) {
140
- this.setAttribute('name', 'invalid');
141
- }
142
- }
143
- /** @private */
144
- toString(omit) {
145
- return this.#syntax
146
- && !(omit && this.matchesTypes(omit))
147
- ? this.#syntax.replace('$1', super.toString(omit))
148
- : super.toString(omit);
149
- }
150
- /** @override */
151
- text() {
152
- return this.#syntax ? this.#syntax.replace('$1', super.text()).trim() : super.text().trim();
153
- }
154
- /** @private */
155
- getAttribute(key) {
156
- if (key === 'plain') {
157
- return (this.name === 'caption');
158
- }
159
- else if (key === 'syntax') {
160
- return this.#syntax;
161
- }
162
- return key === 'padding'
163
- ? Math.max(0, this.#syntax.indexOf('$1'))
164
- : super.getAttribute(key);
165
- }
166
- /** @override */
167
- lint(start = this.getAbsoluteIndex()) {
168
- const errors = super.lint(start), { link, name } = this;
169
- if (name === 'invalid') {
170
- errors.push((0, lint_1.generateForSelf)(this, { start }, 'invalid gallery image parameter'));
171
- }
172
- else if (typeof link === 'object' && link.encoded) {
173
- errors.push((0, lint_1.generateForSelf)(this, { start }, 'unnecessary URL encoding in an internal link'));
174
- }
175
- return errors;
176
- }
177
- /** @override */
178
- print() {
179
- if (this.#syntax) {
180
- return this.name === 'invalid'
181
- ? `<span class="wpb-image-invalid">${this.#syntax.replace('$1', (0, string_1.print)(this.childNodes))}</span>`
182
- : `<span class="wpb-image-parameter">${this.#syntax.replace('$1', `<span class="wpb-image-caption">${(0, string_1.print)(this.childNodes)}</span>`)}</span>`;
183
- }
184
- return super.print({ class: 'image-caption' });
185
- }
186
- /* NOT FOR BROWSER */
187
- /** @override */
188
- cloneNode() {
189
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config');
190
- return debug_1.Shadow.run(() => {
191
- const token = new ImageParameterToken(this.#syntax.replace('$1', ''), config);
192
- token.replaceChildren(...cloned);
193
- token.setAttribute('name', this.name);
194
- token.setAttribute('syntax', this.#syntax);
195
- return token;
196
- });
197
- }
198
- /** @private */
199
- setAttribute(key, value) {
200
- if (key === 'syntax') {
201
- this.#syntax = value;
202
- }
203
- else {
204
- super.setAttribute(key, value);
205
- }
206
- }
207
- /** 是否是不可变参数 */
208
- #isVoid() {
209
- return this.#syntax && !this.#syntax.includes('$1');
210
- }
211
- /** @ignore */
212
- insertAt(token, i) {
213
- if (!debug_1.Shadow.running && this.#isVoid()) {
214
- throw new Error(`图片参数 ${this.name} 不接受自定义输入!`);
215
- }
216
- return super.insertAt(token, i);
217
- }
218
- /** 获取参数值 */
219
- getValue() {
220
- return this.name === 'invalid' ? this.text() : this.#isVoid() || super.text();
221
- }
222
- /**
223
- * 设置参数值
224
- * @param value 参数值
225
- * @throws `Error` 无效参数
226
- */
227
- setValue(value = false) {
228
- const { name } = this;
229
- if (value === false) {
230
- this.remove();
231
- return;
232
- }
233
- else if (name === 'invalid') {
234
- throw new Error('当前节点是一个无效的图片参数!');
235
- }
236
- const type = this.#isVoid() ? 'Boolean' : 'String';
237
- if (typeof value !== type.toLowerCase()) { // eslint-disable-line valid-typeof
238
- this.typeError('setValue', type);
239
- }
240
- else if (value !== true) {
241
- const include = this.getAttribute('include'), config = this.getAttribute('config'), { childNodes } = Parser.parse(value, include, name === 'caption' ? undefined : 5, config);
242
- this.replaceChildren(...childNodes);
243
- }
244
- }
245
- }
246
- exports.ImageParameterToken = ImageParameterToken;
247
- constants_1.classes['ImageParameterToken'] = __filename;
@@ -1,57 +0,0 @@
1
- import * as 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 { AstNodes, AstText, AttributesToken, ExtToken } from '../internal';
8
- /**
9
- * `<imagemap>`
10
- * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
11
- */
12
- export declare class ImagemapToken extends Token {
13
- readonly type = "ext-inner";
14
- readonly name: 'imagemap';
15
- readonly childNodes: (GalleryImageToken | NoincludeToken | ImagemapLinkToken | AstText)[];
16
- abstract get children(): (GalleryImageToken | NoincludeToken | ImagemapLinkToken)[];
17
- abstract get firstChild(): NoincludeToken | GalleryImageToken | undefined;
18
- abstract get firstElementChild(): NoincludeToken | GalleryImageToken | undefined;
19
- abstract get lastChild(): GalleryImageToken | NoincludeToken | ImagemapLinkToken | AstText | undefined;
20
- abstract get lastElementChild(): GalleryImageToken | NoincludeToken | ImagemapLinkToken | undefined;
21
- abstract get nextSibling(): undefined;
22
- abstract get nextElementSibling(): undefined;
23
- abstract get previousSibling(): AttributesToken;
24
- abstract get previousElementSibling(): AttributesToken;
25
- abstract get parentNode(): ExtToken | undefined;
26
- abstract get parentElement(): ExtToken | undefined;
27
- /** 图片 */
28
- get image(): GalleryImageToken | undefined;
29
- /** 链接 */
30
- get links(): readonly ImagemapLinkToken[];
31
- /** @param inner 标签内部wikitext */
32
- constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
33
- /** @override */
34
- text(): string;
35
- /** @override */
36
- lint(start?: number): LintError[];
37
- /** @override */
38
- print(): string;
39
- /**
40
- * @override
41
- * @param token 待插入的节点
42
- * @param i 插入位置
43
- * @throws `Error` 当前缺少合法图片
44
- * @throws `RangeError` 已有一张合法图片
45
- */
46
- insertAt(token: string, i?: number): AstText;
47
- /** @ignore */
48
- insertAt<T extends AstNodes>(token: T, i?: number): T;
49
- /**
50
- * @override
51
- * @param i 移除位置
52
- * @throws `Error` 禁止移除图片
53
- */
54
- removeAt(i: number): AstNodes;
55
- /** @override */
56
- cloneNode(): this;
57
- }