wikiparser-node 1.0.0-beta.3 → 1.0.1-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 (146) 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/package.json +35 -20
  14. package/config/.schema.json +0 -160
  15. package/dist/index.d.ts +0 -62
  16. package/dist/index.js +0 -305
  17. package/dist/internal.d.ts +0 -44
  18. package/dist/lib/element.d.ts +0 -186
  19. package/dist/lib/element.js +0 -659
  20. package/dist/lib/node.d.ts +0 -178
  21. package/dist/lib/node.js +0 -458
  22. package/dist/lib/range.d.ts +0 -132
  23. package/dist/lib/range.js +0 -387
  24. package/dist/lib/ranges.d.ts +0 -28
  25. package/dist/lib/ranges.js +0 -125
  26. package/dist/lib/text.d.ts +0 -78
  27. package/dist/lib/text.js +0 -227
  28. package/dist/lib/title.d.ts +0 -33
  29. package/dist/lib/title.js +0 -110
  30. package/dist/mixin/attributesParent.js +0 -93
  31. package/dist/mixin/fixed.js +0 -32
  32. package/dist/mixin/hidden.js +0 -23
  33. package/dist/mixin/singleLine.js +0 -26
  34. package/dist/mixin/sol.js +0 -44
  35. package/dist/parser/braces.js +0 -125
  36. package/dist/parser/commentAndExt.js +0 -58
  37. package/dist/parser/converter.js +0 -38
  38. package/dist/parser/externalLinks.js +0 -28
  39. package/dist/parser/hrAndDoubleUnderscore.js +0 -40
  40. package/dist/parser/html.js +0 -38
  41. package/dist/parser/links.js +0 -94
  42. package/dist/parser/list.js +0 -61
  43. package/dist/parser/magicLinks.js +0 -39
  44. package/dist/parser/quotes.js +0 -67
  45. package/dist/parser/selector.js +0 -165
  46. package/dist/parser/table.js +0 -117
  47. package/dist/src/arg.d.ts +0 -77
  48. package/dist/src/arg.js +0 -199
  49. package/dist/src/atom.d.ts +0 -11
  50. package/dist/src/atom.js +0 -24
  51. package/dist/src/attribute.d.ts +0 -106
  52. package/dist/src/attribute.js +0 -436
  53. package/dist/src/attributes.d.ts +0 -119
  54. package/dist/src/attributes.js +0 -366
  55. package/dist/src/converter.d.ts +0 -75
  56. package/dist/src/converter.js +0 -141
  57. package/dist/src/converterFlags.d.ts +0 -107
  58. package/dist/src/converterFlags.js +0 -238
  59. package/dist/src/converterRule.d.ts +0 -96
  60. package/dist/src/converterRule.js +0 -255
  61. package/dist/src/extLink.d.ts +0 -63
  62. package/dist/src/extLink.js +0 -157
  63. package/dist/src/gallery.d.ts +0 -70
  64. package/dist/src/gallery.js +0 -137
  65. package/dist/src/heading.d.ts +0 -82
  66. package/dist/src/heading.js +0 -135
  67. package/dist/src/hidden.d.ts +0 -19
  68. package/dist/src/hidden.js +0 -26
  69. package/dist/src/html.d.ts +0 -113
  70. package/dist/src/html.js +0 -245
  71. package/dist/src/imageParameter.d.ts +0 -82
  72. package/dist/src/imageParameter.js +0 -256
  73. package/dist/src/imagemap.d.ts +0 -77
  74. package/dist/src/imagemap.js +0 -169
  75. package/dist/src/imagemapLink.d.ts +0 -48
  76. package/dist/src/imagemapLink.js +0 -43
  77. package/dist/src/index.d.ts +0 -156
  78. package/dist/src/index.js +0 -819
  79. package/dist/src/link/base.d.ts +0 -69
  80. package/dist/src/link/base.js +0 -231
  81. package/dist/src/link/category.d.ts +0 -14
  82. package/dist/src/link/category.js +0 -28
  83. package/dist/src/link/file.d.ts +0 -105
  84. package/dist/src/link/file.js +0 -269
  85. package/dist/src/link/galleryImage.d.ts +0 -37
  86. package/dist/src/link/galleryImage.js +0 -100
  87. package/dist/src/link/index.d.ts +0 -50
  88. package/dist/src/link/index.js +0 -134
  89. package/dist/src/magicLink.d.ts +0 -46
  90. package/dist/src/magicLink.js +0 -131
  91. package/dist/src/nested.d.ts +0 -47
  92. package/dist/src/nested.js +0 -92
  93. package/dist/src/nowiki/base.d.ts +0 -38
  94. package/dist/src/nowiki/base.js +0 -31
  95. package/dist/src/nowiki/comment.d.ts +0 -42
  96. package/dist/src/nowiki/comment.js +0 -64
  97. package/dist/src/nowiki/dd.d.ts +0 -22
  98. package/dist/src/nowiki/dd.js +0 -46
  99. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -35
  100. package/dist/src/nowiki/doubleUnderscore.js +0 -48
  101. package/dist/src/nowiki/hr.d.ts +0 -30
  102. package/dist/src/nowiki/hr.js +0 -36
  103. package/dist/src/nowiki/index.d.ts +0 -19
  104. package/dist/src/nowiki/index.js +0 -23
  105. package/dist/src/nowiki/list.d.ts +0 -16
  106. package/dist/src/nowiki/list.js +0 -13
  107. package/dist/src/nowiki/noinclude.d.ts +0 -21
  108. package/dist/src/nowiki/noinclude.js +0 -24
  109. package/dist/src/nowiki/quote.d.ts +0 -27
  110. package/dist/src/nowiki/quote.js +0 -58
  111. package/dist/src/onlyinclude.d.ts +0 -38
  112. package/dist/src/onlyinclude.js +0 -66
  113. package/dist/src/paramTag/index.d.ts +0 -50
  114. package/dist/src/paramTag/index.js +0 -78
  115. package/dist/src/paramTag/inputbox.d.ts +0 -7
  116. package/dist/src/paramTag/inputbox.js +0 -21
  117. package/dist/src/parameter.d.ts +0 -95
  118. package/dist/src/parameter.js +0 -204
  119. package/dist/src/pre.d.ts +0 -27
  120. package/dist/src/pre.js +0 -44
  121. package/dist/src/syntax.d.ts +0 -22
  122. package/dist/src/syntax.js +0 -67
  123. package/dist/src/table/base.d.ts +0 -60
  124. package/dist/src/table/base.js +0 -80
  125. package/dist/src/table/index.d.ts +0 -247
  126. package/dist/src/table/index.js +0 -783
  127. package/dist/src/table/td.d.ts +0 -119
  128. package/dist/src/table/td.js +0 -268
  129. package/dist/src/table/tr.d.ts +0 -31
  130. package/dist/src/table/tr.js +0 -50
  131. package/dist/src/table/trBase.d.ts +0 -62
  132. package/dist/src/table/trBase.js +0 -157
  133. package/dist/src/tagPair/ext.d.ts +0 -54
  134. package/dist/src/tagPair/ext.js +0 -150
  135. package/dist/src/tagPair/include.d.ts +0 -43
  136. package/dist/src/tagPair/include.js +0 -43
  137. package/dist/src/tagPair/index.d.ts +0 -57
  138. package/dist/src/tagPair/index.js +0 -113
  139. package/dist/src/transclude.d.ts +0 -200
  140. package/dist/src/transclude.js +0 -732
  141. package/dist/util/debug.js +0 -42
  142. package/dist/util/diff.js +0 -71
  143. package/dist/util/lint.js +0 -38
  144. package/dist/util/string.js +0 -74
  145. package/errors/README +0 -1
  146. package/printed/README +0 -1
@@ -1,106 +0,0 @@
1
- import { Token } from '.';
2
- import { AtomToken } from './atom';
3
- import type { LintError } from '../index';
4
- import type { AttributesToken } from '../internal';
5
- declare type AttributeTypes = 'ext-attr' | 'html-attr' | 'table-attr';
6
- declare const AttributeToken_base: ((abstract new (...args: any[]) => {
7
- removeAt(): never;
8
- insertAt(token: string, i?: number | undefined): import("../index").AstText;
9
- insertAt<T extends import("../index").AstNodes>(token: T, i?: number | undefined): T;
10
- length: number;
11
- toString(selector?: string | undefined, separator?: string | undefined): string;
12
- text(separator?: string | undefined): string;
13
- }) & {
14
- readonly fixed: true;
15
- }) & typeof Token;
16
- /**
17
- * 扩展和HTML标签属性
18
- * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
19
- */
20
- export declare abstract class AttributeToken extends AttributeToken_base {
21
- #private;
22
- type: AttributeTypes;
23
- name: string;
24
- childNodes: [AtomToken, Token];
25
- abstract get firstChild(): AtomToken;
26
- abstract get firstElementChild(): AtomToken;
27
- abstract get lastChild(): Token;
28
- abstract get lastElementChild(): Token;
29
- abstract get parentNode(): AttributesToken | undefined;
30
- abstract get parentElement(): AttributesToken | undefined;
31
- abstract get nextSibling(): AtomToken | this | undefined;
32
- abstract get nextElementSibling(): AtomToken | this | undefined;
33
- abstract get previousSibling(): AtomToken | this | undefined;
34
- abstract get previousElementSibling(): AtomToken | this | undefined;
35
- /**
36
- * 引号是否匹配
37
- * @browser
38
- */
39
- get balanced(): boolean;
40
- /**
41
- * 标签名
42
- * @browser
43
- */
44
- get tag(): string;
45
- /**
46
- * getValue()的getter
47
- * @browser
48
- */
49
- get value(): string | true;
50
- set value(value: string | true);
51
- /**
52
- * @browser
53
- * @param type 标签类型
54
- * @param tag 标签名
55
- * @param key 属性名
56
- * @param equal 等号
57
- * @param value 属性值
58
- * @param quotes 引号
59
- */
60
- constructor(type: AttributeTypes, tag: string, key: string, equal?: string, value?: string, quotes?: [string?, string?], config?: import("../index").Config, accum?: Token[]);
61
- /**
62
- * @override
63
- * @browser
64
- */
65
- toString(selector?: string): string;
66
- /**
67
- * @override
68
- * @browser
69
- */
70
- text(): string;
71
- /**
72
- * @override
73
- * @browser
74
- */
75
- print(): string;
76
- /**
77
- * @override
78
- * @browser
79
- */
80
- lint(start?: number): LintError[];
81
- /**
82
- * 获取属性值
83
- * @browser
84
- */
85
- getValue(): string | true;
86
- /** @override */
87
- cloneNode(): this;
88
- /** 转义等号 */
89
- escape(): void;
90
- /** 闭合引号 */
91
- close(): void;
92
- /**
93
- * 设置属性值
94
- * @param value 参数值
95
- * @throws `SyntaxError` 非法的标签属性
96
- */
97
- setValue(value: string | boolean): void;
98
- /**
99
- * 修改属性名
100
- * @param key 新属性名
101
- * @throws `Error` title属性不能更名
102
- * @throws `SyntaxError` 非法的标签属性名
103
- */
104
- rename(key: string): void;
105
- }
106
- export {};
@@ -1,436 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AttributeToken = void 0;
4
- const lint_1 = require("../util/lint");
5
- const string_1 = require("../util/string");
6
- const fixed_1 = require("../mixin/fixed");
7
- const index_1 = require("../index");
8
- const _1 = require(".");
9
- const atom_1 = require("./atom");
10
- const stages = { 'ext-attr': 0, 'html-attr': 2, 'table-attr': 3 }, pre = { 'ext-attr': '<pre ', 'html-attr': '<p ', 'table-attr': '{|' }, post = { 'ext-attr': '/>', 'html-attr': '>', 'table-attr': '' }, commonHtmlAttrs = new Set([
11
- 'id',
12
- 'class',
13
- 'style',
14
- 'lang',
15
- 'dir',
16
- 'title',
17
- 'tabindex',
18
- 'aria-describedby',
19
- 'aria-flowto',
20
- 'aria-hidden',
21
- 'aria-label',
22
- 'aria-labelledby',
23
- 'aria-owns',
24
- 'role',
25
- 'about',
26
- 'property',
27
- 'resource',
28
- 'datatype',
29
- 'typeof',
30
- 'itemid',
31
- 'itemprop',
32
- 'itemref',
33
- 'itemscope',
34
- 'itemtype',
35
- ]), blockAttrs = new Set(['align']), citeAttrs = new Set(['cite']), citeAndAttrs = new Set(['cite', 'datetime']), widthAttrs = new Set(['width']), tdAttrs = new Set(['align', 'valign', 'abbr', 'axis', 'headers', 'scope', 'rowspan', 'colspan', 'width', 'height', 'bgcolor']), typeAttrs = new Set(['type']), htmlAttrs = {
36
- div: blockAttrs,
37
- h1: blockAttrs,
38
- h2: blockAttrs,
39
- h3: blockAttrs,
40
- h4: blockAttrs,
41
- h5: blockAttrs,
42
- h6: blockAttrs,
43
- blockquote: citeAttrs,
44
- q: citeAttrs,
45
- p: blockAttrs,
46
- br: new Set(['clear']),
47
- pre: widthAttrs,
48
- ins: citeAndAttrs,
49
- del: citeAndAttrs,
50
- ul: typeAttrs,
51
- ol: new Set(['type', 'start', 'reversed']),
52
- li: new Set(['type', 'value']),
53
- table: new Set(['summary', 'width', 'border', 'frame', 'rules', 'cellspacing', 'cellpadding', 'align', 'bgcolor']),
54
- caption: blockAttrs,
55
- tr: new Set(['bgcolor', 'align', 'valign']),
56
- td: tdAttrs,
57
- th: tdAttrs,
58
- img: new Set(['alt', 'src', 'width', 'height', 'srcset']),
59
- font: new Set(['size', 'color', 'face']),
60
- hr: widthAttrs,
61
- rt: new Set(['rbspan']),
62
- data: new Set(['value']),
63
- time: new Set(['datetime']),
64
- meta: new Set(['itemprop', 'content']),
65
- link: new Set(['itemprop', 'href', 'title']),
66
- gallery: new Set(['mode', 'showfilename', 'caption', 'perrow', 'widths', 'heights', 'showthumbnails', 'type']),
67
- poem: new Set(['compact', 'align']),
68
- categorytree: new Set([
69
- 'align',
70
- 'hideroot',
71
- 'onlyroot',
72
- 'depth',
73
- 'mode',
74
- 'hideprefix',
75
- 'namespaces',
76
- 'showcount',
77
- 'notranslations',
78
- ]),
79
- combooption: new Set(['name', 'for', 'inline', 'align']),
80
- }, empty = new Set(), extAttrs = {
81
- nowiki: empty,
82
- indicator: new Set(['name']),
83
- langconvert: new Set(['from', 'to']),
84
- ref: new Set(['group', 'name', 'extends', 'follow', 'dir']),
85
- references: new Set(['group', 'responsive']),
86
- charinsert: new Set(['label']),
87
- choose: new Set(['uncached', 'before', 'after']),
88
- option: new Set(['weight']),
89
- imagemap: empty,
90
- inputbox: empty,
91
- templatestyles: new Set(['src', 'wrapper']),
92
- dynamicpagelist: empty,
93
- poll: new Set(['id', 'show-results-before-voting']),
94
- sm2: typeAttrs,
95
- flashmp3: typeAttrs,
96
- score: new Set([
97
- 'line_width_inches',
98
- 'lang',
99
- 'override_midi',
100
- 'raw',
101
- 'note-language',
102
- 'override_audio',
103
- 'override_ogg',
104
- 'sound',
105
- 'vorbis',
106
- ]),
107
- seo: new Set([
108
- 'title',
109
- 'title_mode',
110
- 'title_separator',
111
- 'keywords',
112
- 'description',
113
- 'robots',
114
- 'google_bot',
115
- 'image',
116
- 'image_width',
117
- 'image_height',
118
- 'image_alt',
119
- 'type',
120
- 'site_name',
121
- 'locale',
122
- 'section',
123
- 'author',
124
- 'published_time',
125
- 'twitter_site',
126
- ]),
127
- tab: new Set([
128
- 'nested',
129
- 'name',
130
- 'index',
131
- 'class',
132
- 'block',
133
- 'inline',
134
- 'openname',
135
- 'closename',
136
- 'collapsed',
137
- 'dropdown',
138
- 'style',
139
- 'bgcolor',
140
- 'container',
141
- 'id',
142
- 'title',
143
- ]),
144
- tabs: new Set(['plain', 'class', 'container', 'id', 'title', 'style']),
145
- combobox: new Set(['placeholder', 'value', 'id', 'class', 'text', 'dropdown', 'style']),
146
- }, insecureStyle = new RegExp(`${'expression'}|${'(?:filter|accelerator|-o-link(?:-source)?|-o-replace)\\s*:'}|${'(?:url|image(?:-set)?)\\s*\\('}|${'attr\\s*\\([^)]+[\\s,]url'}`, 'u');
147
- /**
148
- * 扩展和HTML标签属性
149
- * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
150
- */
151
- class AttributeToken extends (0, fixed_1.fixed)(_1.Token) {
152
- /** @browser */
153
- #equal;
154
- /** @browser */
155
- #quotes;
156
- /** @browser */
157
- #tag;
158
- /**
159
- * 引号是否匹配
160
- * @browser
161
- */
162
- get balanced() {
163
- return !this.#equal || this.#quotes[0] === this.#quotes[1];
164
- }
165
- /**
166
- * 标签名
167
- * @browser
168
- */
169
- get tag() {
170
- return this.#tag;
171
- }
172
- /**
173
- * getValue()的getter
174
- * @browser
175
- */
176
- get value() {
177
- return this.getValue();
178
- }
179
- set value(value) {
180
- this.setValue(value);
181
- }
182
- /**
183
- * @browser
184
- * @param type 标签类型
185
- * @param tag 标签名
186
- * @param key 属性名
187
- * @param equal 等号
188
- * @param value 属性值
189
- * @param quotes 引号
190
- */
191
- constructor(type, tag, key, equal = '', value = '', quotes = [], config = index_1.default.getConfig(), accum = []) {
192
- const keyToken = new atom_1.AtomToken(key, 'attr-key', config, accum, {
193
- [type === 'ext-attr' ? 'AstText' : 'Stage-1']: ':', ArgToken: ':', TranscludeToken: ':',
194
- });
195
- let valueToken;
196
- if (key === 'title') {
197
- valueToken = new _1.Token(value, config, true, accum, {
198
- [`Stage-${stages[type]}`]: ':', ConverterToken: ':',
199
- });
200
- valueToken.type = 'attr-value';
201
- valueToken.setAttribute('stage', index_1.default.MAX_STAGE - 1);
202
- }
203
- else if (tag === 'gallery' && key === 'caption') {
204
- const newConfig = { ...config, excludes: [...config.excludes, 'quote', 'extLink', 'magicLink', 'list'] };
205
- valueToken = new _1.Token(value, newConfig, true, accum, {
206
- AstText: ':', LinkToken: ':', FileToken: ':', CategoryToken: ':', ConverterToken: ':',
207
- });
208
- valueToken.type = 'attr-value';
209
- valueToken.setAttribute('stage', 5);
210
- }
211
- else if (tag === 'choose' && (key === 'before' || key === 'after')) {
212
- const newConfig = { ...config, excludes: [...config.excludes, 'heading', 'html', 'table', 'hr', 'list'] };
213
- valueToken = new _1.Token(value, newConfig, true, accum, {
214
- ArgToken: ':',
215
- TranscludeToken: ':',
216
- LinkToken: ':',
217
- FileToken: ':',
218
- CategoryToken: ':',
219
- QuoteToken: ':',
220
- ExtLinkToken: ':',
221
- MagicLinkToken: ':',
222
- ConverterToken: ':',
223
- });
224
- valueToken.type = 'attr-value';
225
- valueToken.setAttribute('stage', 1);
226
- }
227
- else {
228
- valueToken = new atom_1.AtomToken(value, 'attr-value', config, accum, {
229
- [`Stage-${stages[type]}`]: ':',
230
- });
231
- }
232
- super(undefined, config, true, accum);
233
- this.type = type;
234
- this.append(keyToken, valueToken);
235
- this.#equal = equal;
236
- this.#quotes = quotes;
237
- this.#tag = tag;
238
- this.setAttribute('name', (0, string_1.removeComment)(key).trim().toLowerCase());
239
- }
240
- /** @private */
241
- afterBuild() {
242
- if (this.#equal.includes('\0')) {
243
- this.#equal = this.buildFromStr(this.#equal, 'string');
244
- }
245
- if (this.parentNode) {
246
- this.#tag = this.parentNode.name;
247
- }
248
- this.setAttribute('name', this.firstChild.text().trim().toLowerCase());
249
- }
250
- /**
251
- * @override
252
- * @browser
253
- */
254
- toString(selector) {
255
- if (selector && this.matches(selector)) {
256
- return '';
257
- }
258
- const [quoteStart = '', quoteEnd = ''] = this.#quotes;
259
- return this.#equal
260
- ? `${super.toString(selector, `${this.#equal}${quoteStart}`)}${quoteEnd}`
261
- : this.firstChild.toString(selector);
262
- }
263
- /**
264
- * @override
265
- * @browser
266
- */
267
- text() {
268
- return this.#equal ? `${super.text(`${this.#equal.trim()}"`)}"` : this.firstChild.text();
269
- }
270
- /** @private */
271
- getGaps(i) {
272
- return this.#equal && i === 0 ? this.#equal.length + (this.#quotes[0]?.length ?? 0) : 0;
273
- }
274
- /**
275
- * @override
276
- * @browser
277
- */
278
- print() {
279
- const [quoteStart = '', quoteEnd = ''] = this.#quotes;
280
- return this.#equal ? super.print({ sep: `${this.#equal}${quoteStart}`, post: quoteEnd }) : super.print();
281
- }
282
- /**
283
- * @override
284
- * @browser
285
- */
286
- lint(start = this.getAbsoluteIndex()) {
287
- const errors = super.lint(start), { balanced, firstChild, lastChild, type, name, value } = this, tag = this.#tag;
288
- let rect;
289
- if (!balanced) {
290
- const root = this.getRootNode();
291
- rect = { start, ...root.posFromIndex(start) };
292
- const e = (0, lint_1.generateForChild)(lastChild, rect, 'unclosed quotes', 'warning'), startIndex = e.startIndex - 1, startCol = e.startCol - 1;
293
- errors.push({ ...e, startIndex, startCol, excerpt: String(root).slice(startIndex, startIndex + 50) });
294
- }
295
- if (extAttrs[tag] && !extAttrs[tag].has(name)
296
- || (type !== 'ext-attr' && !/\{\{[^{]+\}\}/u.test(name) || tag in htmlAttrs)
297
- && !htmlAttrs[tag]?.has(name) && !/^(?:xmlns:[\w:.-]+|data-[^:]*)$/u.test(name)
298
- && (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
299
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
300
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'illegal attribute name'));
301
- }
302
- else if (name === 'style' && typeof value === 'string' && insecureStyle.test(value)) {
303
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
304
- errors.push((0, lint_1.generateForChild)(lastChild, rect, 'insecure style'));
305
- }
306
- else if (name === 'tabindex' && typeof value === 'string' && value.trim() !== '0') {
307
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
308
- errors.push((0, lint_1.generateForChild)(lastChild, rect, 'nonzero tabindex'));
309
- }
310
- return errors;
311
- }
312
- /**
313
- * 获取属性值
314
- * @browser
315
- */
316
- getValue() {
317
- if (this.#equal) {
318
- const value = this.lastChild.text();
319
- if (this.#quotes[1]) {
320
- return value;
321
- }
322
- return this.#quotes[0] ? value.trimEnd() : value.trim();
323
- }
324
- return this.type === 'ext-attr' || '';
325
- }
326
- /** @private */
327
- getAttribute(key) {
328
- if (key === 'equal') {
329
- return this.#equal;
330
- }
331
- return key === 'quotes' ? this.#quotes : super.getAttribute(key);
332
- }
333
- /** @private */
334
- hasAttribute(key) {
335
- return key === 'equal' || key === 'quotes' || super.hasAttribute(key);
336
- }
337
- /** @override */
338
- cloneNode() {
339
- const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
340
- return index_1.default.run(() => {
341
- // @ts-expect-error abstract class
342
- const token = new AttributeToken(this.type, this.#tag, '', this.#equal, '', this.#quotes, config);
343
- token.firstChild.safeReplaceWith(key);
344
- token.lastChild.safeReplaceWith(value);
345
- token.afterBuild();
346
- return token;
347
- });
348
- }
349
- /** 转义等号 */
350
- escape() {
351
- this.#equal = '{{=}}';
352
- }
353
- /** 闭合引号 */
354
- close() {
355
- const [opening] = this.#quotes;
356
- if (opening) {
357
- this.#quotes[1] = opening;
358
- }
359
- }
360
- /**
361
- * 设置属性值
362
- * @param value 参数值
363
- * @throws `SyntaxError` 非法的标签属性
364
- */
365
- setValue(value) {
366
- if (value === false) {
367
- this.remove();
368
- return;
369
- }
370
- else if (value === true) {
371
- this.#equal = '';
372
- return;
373
- }
374
- const { type } = this, key = this.name === 'title' ? 'title' : 'data', wikitext = `${pre[type]}${key}="${value}"${post[type]}`, root = index_1.default.parse(wikitext, this.getAttribute('include'), stages[type] + 1, this.getAttribute('config')), { length, firstChild: tag } = root;
375
- let attrs;
376
- if (length !== 1 || tag.type !== type.slice(0, -5)) {
377
- throw new SyntaxError(`非法的标签属性:${(0, string_1.noWrap)(value)}`);
378
- }
379
- else if (type === 'table-attr') {
380
- if (tag.length !== 2) {
381
- throw new SyntaxError(`非法的标签属性:${(0, string_1.noWrap)(value)}`);
382
- }
383
- attrs = tag.lastChild;
384
- }
385
- else {
386
- attrs = tag.firstChild;
387
- }
388
- const { firstChild } = attrs;
389
- if (attrs.length !== 1 || firstChild.type !== this.type || firstChild.name !== key) {
390
- throw new SyntaxError(`非法的标签属性:${(0, string_1.noWrap)(value)}`);
391
- }
392
- const { lastChild } = firstChild;
393
- firstChild.destroy();
394
- this.lastChild.safeReplaceWith(lastChild);
395
- if (this.#quotes[0]) {
396
- this.close();
397
- }
398
- else {
399
- this.#quotes = ['"', '"'];
400
- }
401
- }
402
- /**
403
- * 修改属性名
404
- * @param key 新属性名
405
- * @throws `Error` title属性不能更名
406
- * @throws `SyntaxError` 非法的标签属性名
407
- */
408
- rename(key) {
409
- if (this.name === 'title') {
410
- throw new Error('title 属性不能更名!');
411
- }
412
- const { type } = this, wikitext = `${pre[type]}${key}${post[type]}`, root = index_1.default.parse(wikitext, this.getAttribute('include'), stages[type] + 1, this.getAttribute('config')), { length, firstChild: tag } = root;
413
- let attrs;
414
- if (length !== 1 || tag.type !== type.slice(0, -5)) {
415
- throw new SyntaxError(`非法的标签属性名:${(0, string_1.noWrap)(key)}`);
416
- }
417
- else if (type === 'table-attr') {
418
- if (tag.length !== 2) {
419
- throw new SyntaxError(`非法的标签属性名:${(0, string_1.noWrap)(key)}`);
420
- }
421
- attrs = tag.lastChild;
422
- }
423
- else {
424
- attrs = tag.firstChild;
425
- }
426
- const { firstChild: attr } = attrs;
427
- if (attrs.length !== 1 || attr.type !== this.type || attr.value !== true) {
428
- throw new SyntaxError(`非法的标签属性名:${(0, string_1.noWrap)(key)}`);
429
- }
430
- const { firstChild } = attr;
431
- attr.destroy();
432
- this.firstChild.safeReplaceWith(firstChild);
433
- }
434
- }
435
- exports.AttributeToken = AttributeToken;
436
- index_1.default.classes['AttributeToken'] = __filename;
@@ -1,119 +0,0 @@
1
- import { Token } from '.';
2
- import { AtomToken } from './atom';
3
- import { AttributeToken } from './attribute';
4
- import type { LintError } from '../index';
5
- import type { ExtToken, HtmlToken, TdToken, TrToken, TableToken } from '../internal';
6
- declare type AttributesTypes = 'ext-attrs' | 'html-attrs' | 'table-attrs';
7
- /**
8
- * 扩展和HTML标签属性
9
- * @classdesc `{childNodes: ...AtomToken|AttributeToken}`
10
- */
11
- export declare abstract class AttributesToken extends Token {
12
- #private;
13
- type: AttributesTypes;
14
- name: string;
15
- childNodes: (AtomToken | AttributeToken)[];
16
- abstract get children(): (AtomToken | AttributeToken)[];
17
- abstract get firstChild(): AtomToken | AttributeToken;
18
- abstract get firstElementChild(): AtomToken | AttributeToken;
19
- abstract get lastChild(): AtomToken | AttributeToken;
20
- abstract get lastElementChild(): AtomToken | AttributeToken;
21
- abstract get parentNode(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
22
- abstract get parentElement(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
23
- /** getAttrs()方法的getter写法 */
24
- get attributes(): Record<string, string | true>;
25
- /** 以字符串表示的class属性 */
26
- get className(): string;
27
- set className(className: string);
28
- /** 以Set表示的class属性 */
29
- get classList(): Set<string>;
30
- /** id属性 */
31
- get id(): string;
32
- set id(id: string);
33
- /** 是否含有无效属性 */
34
- get sanitized(): boolean;
35
- /**
36
- * @browser
37
- * @param attr 标签属性
38
- * @param type 标签类型
39
- * @param name 标签名
40
- */
41
- constructor(attr: string | undefined, type: AttributesTypes, name: string, config?: import("../index").Config, accum?: Token[]);
42
- /**
43
- * 所有指定属性名的AttributeToken
44
- * @browser
45
- * @param key 属性名
46
- */
47
- getAttrTokens(key: string): AttributeToken[];
48
- /**
49
- * 指定属性名的最后一个AttributeToken
50
- * @browser
51
- * @param key 属性名
52
- */
53
- getAttrToken(key: string): AttributeToken | undefined;
54
- /**
55
- * 获取标签属性
56
- * @browser
57
- * @param key 属性键
58
- */
59
- getAttr(key: string): string | true | undefined;
60
- /**
61
- * @override
62
- * @browser
63
- */
64
- lint(start?: number): LintError[];
65
- /**
66
- * @override
67
- * @browser
68
- */
69
- print(): string;
70
- /** 清理标签属性 */
71
- sanitize(): void;
72
- /** @override */
73
- cloneNode(): this;
74
- /** 所有无效属性 */
75
- getDirtyAttrs(): AtomToken[];
76
- /**
77
- * @override
78
- * @param token 待插入的子节点
79
- * @param i 插入位置
80
- * @throws `RangeError` 不是AttributeToken或标签不匹配
81
- */
82
- insertAt<T extends AttributeToken>(token: T, i?: number): T;
83
- /**
84
- * 设置标签属性
85
- * @param key 属性键
86
- * @param value 属性值
87
- * @throws `RangeError` 扩展标签属性不能包含">"
88
- * @throws `RangeError` 无效的属性名
89
- */
90
- setAttr(key: string, value: string | boolean): void;
91
- /**
92
- * 标签是否具有某属性
93
- * @param key 属性键
94
- */
95
- hasAttr(key: string): boolean;
96
- /** 获取全部的标签属性名 */
97
- getAttrNames(): Set<string>;
98
- /** 标签是否具有任意属性 */
99
- hasAttrs(): boolean;
100
- /** 获取全部标签属性 */
101
- getAttrs(): Record<string, string | true>;
102
- /**
103
- * 移除标签属性
104
- * @param key 属性键
105
- */
106
- removeAttr(key: string): void;
107
- /**
108
- * 开关标签属性
109
- * @param key 属性键
110
- * @param force 强制开启或关闭
111
- * @throws `RangeError` 不为Boolean类型的属性值
112
- */
113
- toggleAttr(key: string, force?: boolean): void;
114
- /** @override */
115
- toString(selector?: string): string;
116
- /** @override */
117
- text(): string;
118
- }
119
- export {};