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