wikiparser-node 1.0.0-beta.4 → 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.
- package/README.md +10 -9
- package/bundle/bundle.min.js +37 -0
- package/config/llwiki.json +1 -35
- package/config/moegirl.json +1 -44
- package/config/zhwiki.json +1 -466
- package/extensions/dist/base.js +105 -0
- package/extensions/dist/editor.js +172 -0
- package/extensions/dist/highlight.js +46 -0
- package/extensions/dist/lint.js +43 -0
- package/extensions/editor.css +63 -0
- package/extensions/ui.css +119 -0
- package/package.json +29 -16
- package/config/.schema.json +0 -160
- package/dist/index.d.ts +0 -62
- package/dist/index.js +0 -305
- package/dist/internal.d.ts +0 -44
- package/dist/lib/element.d.ts +0 -190
- package/dist/lib/element.js +0 -674
- package/dist/lib/node.d.ts +0 -178
- package/dist/lib/node.js +0 -457
- package/dist/lib/range.d.ts +0 -132
- package/dist/lib/range.js +0 -384
- package/dist/lib/ranges.d.ts +0 -28
- package/dist/lib/ranges.js +0 -125
- package/dist/lib/text.d.ts +0 -78
- package/dist/lib/text.js +0 -227
- package/dist/lib/title.d.ts +0 -34
- package/dist/lib/title.js +0 -111
- package/dist/mixin/attributesParent.js +0 -93
- package/dist/mixin/fixed.js +0 -32
- package/dist/mixin/hidden.js +0 -23
- package/dist/mixin/singleLine.js +0 -26
- package/dist/mixin/sol.js +0 -44
- package/dist/parser/braces.js +0 -120
- package/dist/parser/commentAndExt.js +0 -64
- package/dist/parser/converter.js +0 -39
- package/dist/parser/externalLinks.js +0 -27
- package/dist/parser/hrAndDoubleUnderscore.js +0 -37
- package/dist/parser/html.js +0 -35
- package/dist/parser/links.js +0 -93
- package/dist/parser/list.js +0 -58
- package/dist/parser/magicLinks.js +0 -39
- package/dist/parser/quotes.js +0 -66
- package/dist/parser/selector.js +0 -162
- package/dist/parser/table.js +0 -108
- package/dist/src/arg.d.ts +0 -78
- package/dist/src/arg.js +0 -203
- package/dist/src/atom.d.ts +0 -12
- package/dist/src/atom.js +0 -24
- package/dist/src/attribute.d.ts +0 -107
- package/dist/src/attribute.js +0 -446
- package/dist/src/attributes.d.ts +0 -120
- package/dist/src/attributes.js +0 -360
- package/dist/src/converter.d.ts +0 -76
- package/dist/src/converter.js +0 -134
- package/dist/src/converterFlags.d.ts +0 -108
- package/dist/src/converterFlags.js +0 -237
- package/dist/src/converterRule.d.ts +0 -97
- package/dist/src/converterRule.js +0 -253
- package/dist/src/extLink.d.ts +0 -64
- package/dist/src/extLink.js +0 -156
- package/dist/src/gallery.d.ts +0 -72
- package/dist/src/gallery.js +0 -133
- package/dist/src/heading.d.ts +0 -84
- package/dist/src/heading.js +0 -134
- package/dist/src/hidden.d.ts +0 -20
- package/dist/src/hidden.js +0 -26
- package/dist/src/html.d.ts +0 -115
- package/dist/src/html.js +0 -247
- package/dist/src/imageParameter.d.ts +0 -83
- package/dist/src/imageParameter.js +0 -255
- package/dist/src/imagemap.d.ts +0 -79
- package/dist/src/imagemap.js +0 -164
- package/dist/src/imagemapLink.d.ts +0 -49
- package/dist/src/imagemapLink.js +0 -39
- package/dist/src/index.d.ts +0 -157
- package/dist/src/index.js +0 -818
- package/dist/src/link/base.d.ts +0 -70
- package/dist/src/link/base.js +0 -229
- package/dist/src/link/category.d.ts +0 -14
- package/dist/src/link/category.js +0 -29
- package/dist/src/link/file.d.ts +0 -106
- package/dist/src/link/file.js +0 -271
- package/dist/src/link/galleryImage.d.ts +0 -37
- package/dist/src/link/galleryImage.js +0 -101
- package/dist/src/link/index.d.ts +0 -50
- package/dist/src/link/index.js +0 -136
- package/dist/src/magicLink.d.ts +0 -47
- package/dist/src/magicLink.js +0 -130
- package/dist/src/nested.d.ts +0 -49
- package/dist/src/nested.js +0 -88
- package/dist/src/nowiki/base.d.ts +0 -39
- package/dist/src/nowiki/base.js +0 -31
- package/dist/src/nowiki/comment.d.ts +0 -43
- package/dist/src/nowiki/comment.js +0 -62
- package/dist/src/nowiki/dd.d.ts +0 -22
- package/dist/src/nowiki/dd.js +0 -47
- package/dist/src/nowiki/doubleUnderscore.d.ts +0 -37
- package/dist/src/nowiki/doubleUnderscore.js +0 -48
- package/dist/src/nowiki/hr.d.ts +0 -24
- package/dist/src/nowiki/hr.js +0 -29
- package/dist/src/nowiki/index.d.ts +0 -20
- package/dist/src/nowiki/index.js +0 -24
- package/dist/src/nowiki/list.d.ts +0 -16
- package/dist/src/nowiki/list.js +0 -14
- package/dist/src/nowiki/noinclude.d.ts +0 -21
- package/dist/src/nowiki/noinclude.js +0 -25
- package/dist/src/nowiki/quote.d.ts +0 -20
- package/dist/src/nowiki/quote.js +0 -66
- package/dist/src/onlyinclude.d.ts +0 -39
- package/dist/src/onlyinclude.js +0 -66
- package/dist/src/paramTag/index.d.ts +0 -52
- package/dist/src/paramTag/index.js +0 -78
- package/dist/src/paramTag/inputbox.d.ts +0 -8
- package/dist/src/paramTag/inputbox.js +0 -22
- package/dist/src/parameter.d.ts +0 -96
- package/dist/src/parameter.js +0 -203
- package/dist/src/pre.d.ts +0 -29
- package/dist/src/pre.js +0 -49
- package/dist/src/syntax.d.ts +0 -23
- package/dist/src/syntax.js +0 -67
- package/dist/src/table/base.d.ts +0 -61
- package/dist/src/table/base.js +0 -78
- package/dist/src/table/index.d.ts +0 -248
- package/dist/src/table/index.js +0 -782
- package/dist/src/table/td.d.ts +0 -121
- package/dist/src/table/td.js +0 -267
- package/dist/src/table/tr.d.ts +0 -32
- package/dist/src/table/tr.js +0 -51
- package/dist/src/table/trBase.d.ts +0 -62
- package/dist/src/table/trBase.js +0 -157
- package/dist/src/tagPair/ext.d.ts +0 -55
- package/dist/src/tagPair/ext.js +0 -138
- package/dist/src/tagPair/include.d.ts +0 -43
- package/dist/src/tagPair/include.js +0 -42
- package/dist/src/tagPair/index.d.ts +0 -57
- package/dist/src/tagPair/index.js +0 -107
- package/dist/src/transclude.d.ts +0 -201
- package/dist/src/transclude.js +0 -727
- package/dist/util/debug.js +0 -42
- package/dist/util/diff.js +0 -71
- package/dist/util/lint.js +0 -48
- package/dist/util/string.js +0 -75
- package/errors/README +0 -1
- package/printed/README +0 -1
package/dist/src/attribute.js
DELETED
|
@@ -1,446 +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 Parser = 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 = Parser.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' || tag === 'img' && key === 'alt') {
|
|
197
|
-
valueToken = new _1.Token(value, config, true, accum, {
|
|
198
|
-
[`Stage-${stages[type]}`]: ':', ConverterToken: ':',
|
|
199
|
-
});
|
|
200
|
-
valueToken.type = 'attr-value';
|
|
201
|
-
valueToken.setAttribute('stage', Parser.MAX_STAGE - 1);
|
|
202
|
-
}
|
|
203
|
-
else if (tag === 'gallery' && key === 'caption') {
|
|
204
|
-
const newConfig = {
|
|
205
|
-
...config,
|
|
206
|
-
excludes: [...config.excludes, 'quote', 'extLink', 'magicLink', 'list'],
|
|
207
|
-
};
|
|
208
|
-
valueToken = new _1.Token(value, newConfig, true, accum, {
|
|
209
|
-
AstText: ':', LinkToken: ':', FileToken: ':', CategoryToken: ':', ConverterToken: ':',
|
|
210
|
-
});
|
|
211
|
-
valueToken.type = 'attr-value';
|
|
212
|
-
valueToken.setAttribute('stage', 5);
|
|
213
|
-
}
|
|
214
|
-
else if (tag === 'choose' && (key === 'before' || key === 'after')) {
|
|
215
|
-
const newConfig = {
|
|
216
|
-
...config,
|
|
217
|
-
excludes: [...config.excludes, 'heading', 'html', 'table', 'hr', 'list'],
|
|
218
|
-
};
|
|
219
|
-
valueToken = new _1.Token(value, newConfig, true, accum, {
|
|
220
|
-
ArgToken: ':',
|
|
221
|
-
TranscludeToken: ':',
|
|
222
|
-
LinkToken: ':',
|
|
223
|
-
FileToken: ':',
|
|
224
|
-
CategoryToken: ':',
|
|
225
|
-
QuoteToken: ':',
|
|
226
|
-
ExtLinkToken: ':',
|
|
227
|
-
MagicLinkToken: ':',
|
|
228
|
-
ConverterToken: ':',
|
|
229
|
-
});
|
|
230
|
-
valueToken.type = 'attr-value';
|
|
231
|
-
valueToken.setAttribute('stage', 1);
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
valueToken = new atom_1.AtomToken(value, 'attr-value', config, accum, {
|
|
235
|
-
[`Stage-${stages[type]}`]: ':',
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
super(undefined, config, true, accum);
|
|
239
|
-
this.type = type;
|
|
240
|
-
this.append(keyToken, valueToken);
|
|
241
|
-
this.#equal = equal;
|
|
242
|
-
this.#quotes = quotes;
|
|
243
|
-
this.#tag = tag;
|
|
244
|
-
this.setAttribute('name', (0, string_1.removeComment)(key).trim().toLowerCase());
|
|
245
|
-
}
|
|
246
|
-
/** @private */
|
|
247
|
-
afterBuild() {
|
|
248
|
-
if (this.#equal.includes('\0')) {
|
|
249
|
-
this.#equal = this.buildFromStr(this.#equal, 'string');
|
|
250
|
-
}
|
|
251
|
-
if (this.parentNode) {
|
|
252
|
-
this.#tag = this.parentNode.name;
|
|
253
|
-
}
|
|
254
|
-
this.setAttribute('name', this.firstChild.text().trim().toLowerCase());
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* @override
|
|
258
|
-
* @browser
|
|
259
|
-
*/
|
|
260
|
-
toString(omit) {
|
|
261
|
-
if (omit && this.matchesTypes(omit)) {
|
|
262
|
-
return '';
|
|
263
|
-
}
|
|
264
|
-
const [quoteStart = '', quoteEnd = ''] = this.#quotes;
|
|
265
|
-
return this.#equal
|
|
266
|
-
? `${super.toString(omit, `${this.#equal}${quoteStart}`)}${quoteEnd}`
|
|
267
|
-
: this.firstChild.toString(omit);
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* @override
|
|
271
|
-
* @browser
|
|
272
|
-
*/
|
|
273
|
-
text() {
|
|
274
|
-
return this.#equal ? `${super.text(`${this.#equal.trim()}"`)}"` : this.firstChild.text();
|
|
275
|
-
}
|
|
276
|
-
/** @private */
|
|
277
|
-
getGaps(i) {
|
|
278
|
-
return this.#equal && i === 0 ? this.#equal.length + (this.#quotes[0]?.length ?? 0) : 0;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* @override
|
|
282
|
-
* @browser
|
|
283
|
-
*/
|
|
284
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
285
|
-
const errors = super.lint(start), { balanced, firstChild, lastChild, type, name, value } = this, tag = this.#tag;
|
|
286
|
-
let rect;
|
|
287
|
-
if (!balanced) {
|
|
288
|
-
const root = this.getRootNode();
|
|
289
|
-
rect = { start, ...root.posFromIndex(start) };
|
|
290
|
-
const e = (0, lint_1.generateForChild)(lastChild, rect, 'unclosed quotes', 'warning'), startIndex = e.startIndex - 1;
|
|
291
|
-
errors.push({
|
|
292
|
-
...e,
|
|
293
|
-
startIndex,
|
|
294
|
-
startCol: e.startCol - 1,
|
|
295
|
-
excerpt: String(root).slice(startIndex, startIndex + 50),
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
if (extAttrs[tag] && !extAttrs[tag].has(name)
|
|
299
|
-
|| (type !== 'ext-attr' && !/\{\{[^{]+\}\}/u.test(name) || tag in htmlAttrs)
|
|
300
|
-
&& !htmlAttrs[tag]?.has(name) && !/^(?:xmlns:[\w:.-]+|data-[^:]*)$/u.test(name)
|
|
301
|
-
&& (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
|
|
302
|
-
rect ??= { start, ...this.getRootNode().posFromIndex(start) };
|
|
303
|
-
errors.push((0, lint_1.generateForChild)(firstChild, rect, 'illegal attribute name'));
|
|
304
|
-
}
|
|
305
|
-
else if (name === 'style' && typeof value === 'string' && insecureStyle.test(value)) {
|
|
306
|
-
rect ??= { start, ...this.getRootNode().posFromIndex(start) };
|
|
307
|
-
errors.push((0, lint_1.generateForChild)(lastChild, rect, 'insecure style'));
|
|
308
|
-
}
|
|
309
|
-
else if (name === 'tabindex' && typeof value === 'string' && value.trim() !== '0') {
|
|
310
|
-
rect ??= { start, ...this.getRootNode().posFromIndex(start) };
|
|
311
|
-
errors.push((0, lint_1.generateForChild)(lastChild, rect, 'nonzero tabindex'));
|
|
312
|
-
}
|
|
313
|
-
return errors;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* 获取属性值
|
|
317
|
-
* @browser
|
|
318
|
-
*/
|
|
319
|
-
getValue() {
|
|
320
|
-
if (this.#equal) {
|
|
321
|
-
const value = this.lastChild.text();
|
|
322
|
-
if (this.#quotes[1]) {
|
|
323
|
-
return value;
|
|
324
|
-
}
|
|
325
|
-
return this.#quotes[0] ? value.trimEnd() : value.trim();
|
|
326
|
-
}
|
|
327
|
-
return this.type === 'ext-attr' || '';
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* @override
|
|
331
|
-
* @browser
|
|
332
|
-
*/
|
|
333
|
-
print() {
|
|
334
|
-
const [quoteStart = '', quoteEnd = ''] = this.#quotes;
|
|
335
|
-
return this.#equal ? super.print({ sep: `${this.#equal}${quoteStart}`, post: quoteEnd }) : super.print();
|
|
336
|
-
}
|
|
337
|
-
/** @private */
|
|
338
|
-
getAttribute(key) {
|
|
339
|
-
if (key === 'equal') {
|
|
340
|
-
return this.#equal;
|
|
341
|
-
}
|
|
342
|
-
return key === 'quotes' ? this.#quotes : super.getAttribute(key);
|
|
343
|
-
}
|
|
344
|
-
/** @private */
|
|
345
|
-
hasAttribute(key) {
|
|
346
|
-
return key === 'equal' || key === 'quotes' || super.hasAttribute(key);
|
|
347
|
-
}
|
|
348
|
-
/** @override */
|
|
349
|
-
cloneNode() {
|
|
350
|
-
const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
|
|
351
|
-
return Parser.run(() => {
|
|
352
|
-
const token = new AttributeToken(this.type, this.#tag, '', this.#equal, '', this.#quotes, config);
|
|
353
|
-
token.firstChild.safeReplaceWith(key);
|
|
354
|
-
token.lastChild.safeReplaceWith(value);
|
|
355
|
-
token.afterBuild();
|
|
356
|
-
return token;
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
/** 转义等号 */
|
|
360
|
-
escape() {
|
|
361
|
-
this.#equal = '{{=}}';
|
|
362
|
-
}
|
|
363
|
-
/** 闭合引号 */
|
|
364
|
-
close() {
|
|
365
|
-
const [opening] = this.#quotes;
|
|
366
|
-
if (opening) {
|
|
367
|
-
this.#quotes[1] = opening;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* 设置属性值
|
|
372
|
-
* @param value 参数值
|
|
373
|
-
* @throws `SyntaxError` 非法的标签属性
|
|
374
|
-
*/
|
|
375
|
-
setValue(value) {
|
|
376
|
-
if (value === false) {
|
|
377
|
-
this.remove();
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
else if (value === true) {
|
|
381
|
-
this.#equal = '';
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
const { type, name } = this, key = name === 'title' ? 'title' : 'data', wikitext = `${pre[type]}${key}="${value}"${post[type]}`, root = Parser.parse(wikitext, this.getAttribute('include'), stages[type] + 1, this.getAttribute('config')), { length, firstChild: tag } = root;
|
|
385
|
-
let attrs;
|
|
386
|
-
if (length !== 1 || tag.type !== type.slice(0, -5)) {
|
|
387
|
-
throw new SyntaxError(`非法的标签属性:${(0, string_1.noWrap)(value)}`);
|
|
388
|
-
}
|
|
389
|
-
else if (type === 'table-attr') {
|
|
390
|
-
if (tag.length !== 2) {
|
|
391
|
-
throw new SyntaxError(`非法的标签属性:${(0, string_1.noWrap)(value)}`);
|
|
392
|
-
}
|
|
393
|
-
attrs = tag.lastChild;
|
|
394
|
-
}
|
|
395
|
-
else {
|
|
396
|
-
attrs = tag.firstChild;
|
|
397
|
-
}
|
|
398
|
-
const { firstChild } = attrs;
|
|
399
|
-
if (attrs.length !== 1 || firstChild.type !== type || firstChild.name !== key) {
|
|
400
|
-
throw new SyntaxError(`非法的标签属性:${(0, string_1.noWrap)(value)}`);
|
|
401
|
-
}
|
|
402
|
-
const { lastChild } = firstChild;
|
|
403
|
-
firstChild.destroy();
|
|
404
|
-
this.lastChild.safeReplaceWith(lastChild);
|
|
405
|
-
if (this.#quotes[0]) {
|
|
406
|
-
this.close();
|
|
407
|
-
}
|
|
408
|
-
else {
|
|
409
|
-
this.#quotes = ['"', '"'];
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* 修改属性名
|
|
414
|
-
* @param key 新属性名
|
|
415
|
-
* @throws `Error` title属性不能更名
|
|
416
|
-
* @throws `SyntaxError` 非法的标签属性名
|
|
417
|
-
*/
|
|
418
|
-
rename(key) {
|
|
419
|
-
if (this.name === 'title') {
|
|
420
|
-
throw new Error('title 属性不能更名!');
|
|
421
|
-
}
|
|
422
|
-
const { type } = this, wikitext = `${pre[type]}${key}${post[type]}`, root = Parser.parse(wikitext, this.getAttribute('include'), stages[type] + 1, this.getAttribute('config')), { length, firstChild: tag } = root;
|
|
423
|
-
let attrs;
|
|
424
|
-
if (length !== 1 || tag.type !== type.slice(0, -5)) {
|
|
425
|
-
throw new SyntaxError(`非法的标签属性名:${(0, string_1.noWrap)(key)}`);
|
|
426
|
-
}
|
|
427
|
-
else if (type === 'table-attr') {
|
|
428
|
-
if (tag.length !== 2) {
|
|
429
|
-
throw new SyntaxError(`非法的标签属性名:${(0, string_1.noWrap)(key)}`);
|
|
430
|
-
}
|
|
431
|
-
attrs = tag.lastChild;
|
|
432
|
-
}
|
|
433
|
-
else {
|
|
434
|
-
attrs = tag.firstChild;
|
|
435
|
-
}
|
|
436
|
-
const { firstChild: attr } = attrs;
|
|
437
|
-
if (attrs.length !== 1 || attr.type !== type || attr.value !== true) {
|
|
438
|
-
throw new SyntaxError(`非法的标签属性名:${(0, string_1.noWrap)(key)}`);
|
|
439
|
-
}
|
|
440
|
-
const { firstChild } = attr;
|
|
441
|
-
attr.destroy();
|
|
442
|
-
this.firstChild.safeReplaceWith(firstChild);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
exports.AttributeToken = AttributeToken;
|
|
446
|
-
Parser.classes['AttributeToken'] = __filename;
|
package/dist/src/attributes.d.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import * as Parser from '../index';
|
|
2
|
-
import { Token } from '.';
|
|
3
|
-
import { AtomToken } from './atom';
|
|
4
|
-
import { AttributeToken } from './attribute';
|
|
5
|
-
import type { LintError } from '../index';
|
|
6
|
-
import type { ExtToken, HtmlToken, TdToken, TrToken, TableToken } from '../internal';
|
|
7
|
-
declare type AttributesTypes = 'ext-attrs' | 'html-attrs' | 'table-attrs';
|
|
8
|
-
/**
|
|
9
|
-
* 扩展和HTML标签属性
|
|
10
|
-
* @classdesc `{childNodes: ...AtomToken|AttributeToken}`
|
|
11
|
-
*/
|
|
12
|
-
export declare class AttributesToken extends Token {
|
|
13
|
-
#private;
|
|
14
|
-
type: AttributesTypes;
|
|
15
|
-
name: string;
|
|
16
|
-
childNodes: (AtomToken | AttributeToken)[];
|
|
17
|
-
abstract get children(): (AtomToken | AttributeToken)[];
|
|
18
|
-
abstract get firstChild(): AtomToken | AttributeToken;
|
|
19
|
-
abstract get firstElementChild(): AtomToken | AttributeToken;
|
|
20
|
-
abstract get lastChild(): AtomToken | AttributeToken;
|
|
21
|
-
abstract get lastElementChild(): AtomToken | AttributeToken;
|
|
22
|
-
abstract get parentNode(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
|
|
23
|
-
abstract get parentElement(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
|
|
24
|
-
/** getAttrs()方法的getter写法 */
|
|
25
|
-
get attributes(): Record<string, string | true>;
|
|
26
|
-
/** 以字符串表示的class属性 */
|
|
27
|
-
get className(): string;
|
|
28
|
-
set className(className: string);
|
|
29
|
-
/** 以Set表示的class属性 */
|
|
30
|
-
get classList(): Set<string>;
|
|
31
|
-
/** id属性 */
|
|
32
|
-
get id(): string;
|
|
33
|
-
set id(id: string);
|
|
34
|
-
/** 是否含有无效属性 */
|
|
35
|
-
get sanitized(): boolean;
|
|
36
|
-
/**
|
|
37
|
-
* @browser
|
|
38
|
-
* @param attr 标签属性
|
|
39
|
-
* @param type 标签类型
|
|
40
|
-
* @param name 标签名
|
|
41
|
-
*/
|
|
42
|
-
constructor(attr: string | undefined, type: AttributesTypes, name: string, config?: Parser.Config, accum?: Token[]);
|
|
43
|
-
/**
|
|
44
|
-
* 所有指定属性名的AttributeToken
|
|
45
|
-
* @browser
|
|
46
|
-
* @param key 属性名
|
|
47
|
-
*/
|
|
48
|
-
getAttrTokens(key: string): AttributeToken[];
|
|
49
|
-
/**
|
|
50
|
-
* 指定属性名的最后一个AttributeToken
|
|
51
|
-
* @browser
|
|
52
|
-
* @param key 属性名
|
|
53
|
-
*/
|
|
54
|
-
getAttrToken(key: string): AttributeToken | undefined;
|
|
55
|
-
/**
|
|
56
|
-
* 获取标签属性
|
|
57
|
-
* @browser
|
|
58
|
-
* @param key 属性键
|
|
59
|
-
*/
|
|
60
|
-
getAttr(key: string): string | true | undefined;
|
|
61
|
-
/**
|
|
62
|
-
* @override
|
|
63
|
-
* @browser
|
|
64
|
-
*/
|
|
65
|
-
lint(start?: number): LintError[];
|
|
66
|
-
/**
|
|
67
|
-
* @override
|
|
68
|
-
* @browser
|
|
69
|
-
*/
|
|
70
|
-
print(): string;
|
|
71
|
-
/** 清理标签属性 */
|
|
72
|
-
sanitize(): void;
|
|
73
|
-
/** @override */
|
|
74
|
-
cloneNode(): this;
|
|
75
|
-
/** 所有无效属性 */
|
|
76
|
-
getDirtyAttrs(): AtomToken[];
|
|
77
|
-
/**
|
|
78
|
-
* @override
|
|
79
|
-
* @param token 待插入的子节点
|
|
80
|
-
* @param i 插入位置
|
|
81
|
-
* @throws `RangeError` 不是AttributeToken或标签不匹配
|
|
82
|
-
*/
|
|
83
|
-
insertAt<T extends AttributeToken>(token: T, i?: number): T;
|
|
84
|
-
/**
|
|
85
|
-
* 设置标签属性
|
|
86
|
-
* @param key 属性键
|
|
87
|
-
* @param value 属性值
|
|
88
|
-
* @throws `RangeError` 扩展标签属性不能包含">"
|
|
89
|
-
* @throws `RangeError` 无效的属性名
|
|
90
|
-
*/
|
|
91
|
-
setAttr(key: string, value: string | boolean): void;
|
|
92
|
-
/**
|
|
93
|
-
* 标签是否具有某属性
|
|
94
|
-
* @param key 属性键
|
|
95
|
-
*/
|
|
96
|
-
hasAttr(key: string): boolean;
|
|
97
|
-
/** 获取全部的标签属性名 */
|
|
98
|
-
getAttrNames(): Set<string>;
|
|
99
|
-
/** 标签是否具有任意属性 */
|
|
100
|
-
hasAttrs(): boolean;
|
|
101
|
-
/** 获取全部标签属性 */
|
|
102
|
-
getAttrs(): Record<string, string | true>;
|
|
103
|
-
/**
|
|
104
|
-
* 移除标签属性
|
|
105
|
-
* @param key 属性键
|
|
106
|
-
*/
|
|
107
|
-
removeAttr(key: string): void;
|
|
108
|
-
/**
|
|
109
|
-
* 开关标签属性
|
|
110
|
-
* @param key 属性键
|
|
111
|
-
* @param force 强制开启或关闭
|
|
112
|
-
* @throws `RangeError` 不为Boolean类型的属性值
|
|
113
|
-
*/
|
|
114
|
-
toggleAttr(key: string, force?: boolean): void;
|
|
115
|
-
/** @override */
|
|
116
|
-
toString(omit?: Set<string>): string;
|
|
117
|
-
/** @override */
|
|
118
|
-
text(): string;
|
|
119
|
-
}
|
|
120
|
-
export {};
|