wikiparser-node 1.3.1 → 1.3.2-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 (156) 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 +117 -0
  11. package/i18n/zh-hans.json +4 -3
  12. package/i18n/zh-hant.json +4 -3
  13. package/package.json +32 -12
  14. package/config/.schema.json +0 -172
  15. package/dist/addon/table.d.ts +0 -6
  16. package/dist/addon/table.js +0 -564
  17. package/dist/base.d.ts +0 -45
  18. package/dist/bin/toc.js +0 -18
  19. package/dist/index.d.ts +0 -31
  20. package/dist/index.js +0 -209
  21. package/dist/internal.d.ts +0 -44
  22. package/dist/lib/element.d.ts +0 -155
  23. package/dist/lib/element.js +0 -654
  24. package/dist/lib/node.d.ts +0 -146
  25. package/dist/lib/node.js +0 -419
  26. package/dist/lib/range.d.ts +0 -104
  27. package/dist/lib/range.js +0 -385
  28. package/dist/lib/ranges.d.ts +0 -26
  29. package/dist/lib/ranges.js +0 -117
  30. package/dist/lib/text.d.ts +0 -62
  31. package/dist/lib/text.js +0 -235
  32. package/dist/lib/title.d.ts +0 -38
  33. package/dist/lib/title.js +0 -162
  34. package/dist/mixin/attributesParent.js +0 -94
  35. package/dist/mixin/fixed.js +0 -32
  36. package/dist/mixin/flagsParent.js +0 -70
  37. package/dist/mixin/hidden.js +0 -22
  38. package/dist/mixin/magicLinkParent.js +0 -41
  39. package/dist/mixin/singleLine.js +0 -25
  40. package/dist/mixin/sol.js +0 -43
  41. package/dist/mixin/syntax.js +0 -56
  42. package/dist/parser/braces.js +0 -122
  43. package/dist/parser/commentAndExt.js +0 -69
  44. package/dist/parser/converter.js +0 -40
  45. package/dist/parser/externalLinks.js +0 -28
  46. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  47. package/dist/parser/html.js +0 -36
  48. package/dist/parser/links.js +0 -94
  49. package/dist/parser/list.js +0 -59
  50. package/dist/parser/magicLinks.js +0 -40
  51. package/dist/parser/quotes.js +0 -67
  52. package/dist/parser/selector.js +0 -162
  53. package/dist/parser/table.js +0 -112
  54. package/dist/src/arg.d.ts +0 -58
  55. package/dist/src/arg.js +0 -189
  56. package/dist/src/atom.d.ts +0 -12
  57. package/dist/src/atom.js +0 -27
  58. package/dist/src/attribute.d.ts +0 -86
  59. package/dist/src/attribute.js +0 -391
  60. package/dist/src/attributes.d.ts +0 -107
  61. package/dist/src/attributes.js +0 -341
  62. package/dist/src/converter.d.ts +0 -51
  63. package/dist/src/converter.js +0 -79
  64. package/dist/src/converterFlags.d.ts +0 -87
  65. package/dist/src/converterFlags.js +0 -222
  66. package/dist/src/converterRule.d.ts +0 -81
  67. package/dist/src/converterRule.js +0 -212
  68. package/dist/src/extLink.d.ts +0 -53
  69. package/dist/src/extLink.js +0 -121
  70. package/dist/src/gallery.d.ts +0 -55
  71. package/dist/src/gallery.js +0 -122
  72. package/dist/src/heading.d.ts +0 -72
  73. package/dist/src/heading.js +0 -127
  74. package/dist/src/hidden.d.ts +0 -21
  75. package/dist/src/hidden.js +0 -23
  76. package/dist/src/html.d.ts +0 -103
  77. package/dist/src/html.js +0 -222
  78. package/dist/src/imageParameter.d.ts +0 -66
  79. package/dist/src/imageParameter.js +0 -247
  80. package/dist/src/imagemap.d.ts +0 -57
  81. package/dist/src/imagemap.js +0 -148
  82. package/dist/src/imagemapLink.d.ts +0 -57
  83. package/dist/src/imagemapLink.js +0 -40
  84. package/dist/src/index.d.ts +0 -146
  85. package/dist/src/index.js +0 -777
  86. package/dist/src/link/base.d.ts +0 -52
  87. package/dist/src/link/base.js +0 -207
  88. package/dist/src/link/category.d.ts +0 -13
  89. package/dist/src/link/category.js +0 -29
  90. package/dist/src/link/file.d.ts +0 -96
  91. package/dist/src/link/file.js +0 -253
  92. package/dist/src/link/galleryImage.d.ts +0 -43
  93. package/dist/src/link/galleryImage.js +0 -106
  94. package/dist/src/link/index.d.ts +0 -53
  95. package/dist/src/link/index.js +0 -123
  96. package/dist/src/magicLink.d.ts +0 -69
  97. package/dist/src/magicLink.js +0 -147
  98. package/dist/src/nested.d.ts +0 -44
  99. package/dist/src/nested.js +0 -87
  100. package/dist/src/nowiki/base.d.ts +0 -46
  101. package/dist/src/nowiki/base.js +0 -42
  102. package/dist/src/nowiki/comment.d.ts +0 -39
  103. package/dist/src/nowiki/comment.js +0 -67
  104. package/dist/src/nowiki/dd.d.ts +0 -8
  105. package/dist/src/nowiki/dd.js +0 -25
  106. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -43
  107. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  108. package/dist/src/nowiki/hr.d.ts +0 -29
  109. package/dist/src/nowiki/hr.js +0 -14
  110. package/dist/src/nowiki/index.d.ts +0 -16
  111. package/dist/src/nowiki/index.js +0 -21
  112. package/dist/src/nowiki/list.d.ts +0 -29
  113. package/dist/src/nowiki/list.js +0 -48
  114. package/dist/src/nowiki/listBase.d.ts +0 -18
  115. package/dist/src/nowiki/listBase.js +0 -12
  116. package/dist/src/nowiki/noinclude.d.ts +0 -25
  117. package/dist/src/nowiki/noinclude.js +0 -25
  118. package/dist/src/nowiki/quote.d.ts +0 -22
  119. package/dist/src/nowiki/quote.js +0 -45
  120. package/dist/src/onlyinclude.d.ts +0 -16
  121. package/dist/src/onlyinclude.js +0 -57
  122. package/dist/src/paramTag/index.d.ts +0 -37
  123. package/dist/src/paramTag/index.js +0 -68
  124. package/dist/src/paramTag/inputbox.d.ts +0 -8
  125. package/dist/src/paramTag/inputbox.js +0 -23
  126. package/dist/src/parameter.d.ts +0 -84
  127. package/dist/src/parameter.js +0 -205
  128. package/dist/src/pre.d.ts +0 -28
  129. package/dist/src/pre.js +0 -51
  130. package/dist/src/syntax.d.ts +0 -24
  131. package/dist/src/syntax.js +0 -30
  132. package/dist/src/table/base.d.ts +0 -52
  133. package/dist/src/table/base.js +0 -78
  134. package/dist/src/table/index.d.ts +0 -229
  135. package/dist/src/table/index.js +0 -379
  136. package/dist/src/table/td.d.ts +0 -103
  137. package/dist/src/table/td.js +0 -261
  138. package/dist/src/table/tr.d.ts +0 -32
  139. package/dist/src/table/tr.js +0 -56
  140. package/dist/src/table/trBase.d.ts +0 -54
  141. package/dist/src/table/trBase.js +0 -158
  142. package/dist/src/tagPair/ext.d.ts +0 -58
  143. package/dist/src/tagPair/ext.js +0 -142
  144. package/dist/src/tagPair/include.d.ts +0 -52
  145. package/dist/src/tagPair/include.js +0 -58
  146. package/dist/src/tagPair/index.d.ts +0 -47
  147. package/dist/src/tagPair/index.js +0 -93
  148. package/dist/src/transclude.d.ts +0 -167
  149. package/dist/src/transclude.js +0 -689
  150. package/dist/util/constants.js +0 -108
  151. package/dist/util/debug.js +0 -64
  152. package/dist/util/diff.js +0 -72
  153. package/dist/util/lint.js +0 -46
  154. package/dist/util/string.js +0 -61
  155. package/errors/README +0 -1
  156. package/printed/README +0 -1
@@ -1,86 +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
- afterBuild(): void;
15
- getAttribute<T_1 extends string>(key: T_1): TokenAttributeGetter<T_1>;
16
- setAttribute<T_2 extends string>(key: T_2, value: TokenAttributeSetter<T_2>): void;
17
- addEventListener(events: string | string[], listener: AstListener): void;
18
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
19
- }) & {
20
- readonly fixed: true;
21
- }) & typeof Parser.Token;
22
- /**
23
- * 扩展和HTML标签属性
24
- * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
25
- */
26
- export declare class AttributeToken extends AttributeToken_base {
27
- #private;
28
- type: AttributeTypes;
29
- readonly name: string;
30
- readonly tag: string;
31
- readonly childNodes: [AtomToken, Token];
32
- abstract get children(): [AtomToken, Token];
33
- abstract get firstChild(): AtomToken;
34
- abstract get firstElementChild(): AtomToken;
35
- abstract get lastChild(): Token;
36
- abstract get lastElementChild(): Token;
37
- abstract get parentNode(): AttributesToken | undefined;
38
- abstract get parentElement(): AttributesToken | undefined;
39
- abstract get nextSibling(): AtomToken | this | undefined;
40
- abstract get nextElementSibling(): AtomToken | this | undefined;
41
- abstract get previousSibling(): AtomToken | this | undefined;
42
- abstract get previousElementSibling(): AtomToken | this | undefined;
43
- /** 引号是否匹配 */
44
- get balanced(): boolean;
45
- set balanced(value: boolean);
46
- /** getValue()的getter */
47
- get value(): string | true;
48
- set value(value: string | true);
49
- /**
50
- * @param type 标签类型
51
- * @param tag 标签名
52
- * @param key 属性名
53
- * @param equal 等号
54
- * @param value 属性值
55
- * @param quotes 引号
56
- */
57
- constructor(type: AttributeTypes, tag: string, key: string, equal?: string, value?: string, quotes?: readonly [string?, string?], config?: Parser.Config, accum?: Token[]);
58
- /** @override */
59
- text(): string;
60
- /** @override */
61
- lint(start?: number): LintError[];
62
- /** 获取属性值 */
63
- getValue(): string | true;
64
- /** @override */
65
- print(): string;
66
- /** @override */
67
- cloneNode(): this;
68
- /** 转义等号 */
69
- escape(): void;
70
- /** 闭合引号 */
71
- close(): void;
72
- /**
73
- * 设置属性值
74
- * @param value 参数值
75
- * @throws `RangeError` 扩展标签属性不能包含 ">"
76
- * @throws `RangeError` 同时包含单引号和双引号
77
- */
78
- setValue(value: string | boolean): void;
79
- /**
80
- * 修改属性名
81
- * @param key 新属性名
82
- * @throws `Error` title和alt属性不能更名
83
- */
84
- rename(key: string): void;
85
- }
86
- export {};
@@ -1,391 +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, 'unclosed 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) && !/^(?:xmlns:[\w:.-]+|data-[^:]*)$/u.test(name)
284
- && (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
285
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
286
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'illegal attribute name'));
287
- }
288
- else if (name === 'style' && typeof value === 'string' && insecureStyle.test(value)) {
289
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
290
- errors.push((0, lint_1.generateForChild)(lastChild, rect, 'insecure style'));
291
- }
292
- else if (name === 'tabindex' && typeof value === 'string' && value.trim() !== '0') {
293
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
294
- errors.push((0, lint_1.generateForChild)(lastChild, rect, 'nonzero tabindex'));
295
- }
296
- return errors;
297
- }
298
- /** 获取属性值 */
299
- getValue() {
300
- if (this.#equal) {
301
- const value = this.lastChild.text();
302
- if (this.#quotes[1]) {
303
- return value;
304
- }
305
- return this.#quotes[0] ? value.trimEnd() : value.trim();
306
- }
307
- return this.type === 'ext-attr' || '';
308
- }
309
- /** @override */
310
- print() {
311
- const [quoteStart = '', quoteEnd = ''] = this.#quotes;
312
- return this.#equal ? super.print({ sep: `${this.#equal}${quoteStart}`, post: quoteEnd }) : super.print();
313
- }
314
- /* NOT FOR BROWSER */
315
- /** @private */
316
- getAttribute(key) {
317
- if (key === 'equal') {
318
- return this.#equal;
319
- }
320
- return key === 'quotes' ? this.#quotes : super.getAttribute(key);
321
- }
322
- /** @override */
323
- cloneNode() {
324
- const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
325
- return debug_1.Shadow.run(() => {
326
- const token = new AttributeToken(this.type, this.tag, '', this.#equal, '', this.#quotes, config);
327
- token.firstChild.safeReplaceWith(key);
328
- token.lastChild.safeReplaceWith(value);
329
- token.setAttribute('name', this.name);
330
- return token;
331
- });
332
- }
333
- /** 转义等号 */
334
- escape() {
335
- this.#equal = '{{=}}';
336
- }
337
- /** 闭合引号 */
338
- close() {
339
- const [opening] = this.#quotes;
340
- if (opening) {
341
- this.#quotes[1] = opening;
342
- }
343
- }
344
- /**
345
- * 设置属性值
346
- * @param value 参数值
347
- * @throws `RangeError` 扩展标签属性不能包含 ">"
348
- * @throws `RangeError` 同时包含单引号和双引号
349
- */
350
- setValue(value) {
351
- if (value === false) {
352
- this.remove();
353
- return;
354
- }
355
- else if (value === true) {
356
- this.#equal = '';
357
- return;
358
- }
359
- else if (this.type === 'ext-attr' && value.includes('>')) {
360
- throw new RangeError('扩展标签属性不能包含 ">"!');
361
- }
362
- else if (value.includes('"') && value.includes("'")) {
363
- throw new RangeError('属性值不能同时包含单引号和双引号!');
364
- }
365
- const config = this.getAttribute('config'), { childNodes } = Parser.parse(value, this.getAttribute('include'), stages[this.type] + 1, config);
366
- this.lastChild.replaceChildren(...childNodes);
367
- if (value.includes('"')) {
368
- this.#quotes = ["'", "'"];
369
- }
370
- else if (value.includes("'") || !this.#quotes[0]) {
371
- this.#quotes = ['"', '"'];
372
- }
373
- else {
374
- this.close();
375
- }
376
- }
377
- /**
378
- * 修改属性名
379
- * @param key 新属性名
380
- * @throws `Error` title和alt属性不能更名
381
- */
382
- rename(key) {
383
- if (this.name === 'title' || this.name === 'alt' && this.tag === 'img') {
384
- throw new Error(`${this.name} 属性不能更名!`);
385
- }
386
- const config = this.getAttribute('config'), { childNodes } = Parser.parse(key, this.getAttribute('include'), stages[this.type] + 1, config);
387
- this.firstChild.replaceChildren(...childNodes);
388
- }
389
- }
390
- exports.AttributeToken = AttributeToken;
391
- 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 {};