wikiparser-node 1.3.2 → 1.3.3-b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/bundle.min.js +36 -0
- package/config/llwiki.json +1 -35
- package/config/moegirl.json +1 -44
- package/config/zhwiki.json +1 -466
- package/extensions/dist/base.js +68 -0
- package/extensions/dist/editor.js +159 -0
- package/extensions/dist/highlight.js +30 -0
- package/extensions/dist/lint.js +48 -0
- package/extensions/editor.css +63 -0
- package/extensions/ui.css +114 -0
- package/package.json +32 -12
- package/config/.schema.json +0 -172
- package/dist/addon/table.d.ts +0 -6
- package/dist/addon/table.js +0 -564
- package/dist/base.d.ts +0 -45
- package/dist/bin/toc.js +0 -18
- package/dist/index.d.ts +0 -31
- package/dist/index.js +0 -209
- package/dist/internal.d.ts +0 -44
- package/dist/lib/element.d.ts +0 -155
- package/dist/lib/element.js +0 -634
- package/dist/lib/node.d.ts +0 -146
- package/dist/lib/node.js +0 -419
- package/dist/lib/range.d.ts +0 -104
- package/dist/lib/range.js +0 -385
- package/dist/lib/ranges.d.ts +0 -26
- package/dist/lib/ranges.js +0 -117
- package/dist/lib/text.d.ts +0 -62
- package/dist/lib/text.js +0 -248
- package/dist/lib/title.d.ts +0 -38
- package/dist/lib/title.js +0 -162
- package/dist/mixin/attributesParent.js +0 -94
- package/dist/mixin/fixed.js +0 -32
- package/dist/mixin/flagsParent.js +0 -70
- package/dist/mixin/hidden.js +0 -26
- package/dist/mixin/magicLinkParent.js +0 -41
- package/dist/mixin/singleLine.js +0 -25
- package/dist/mixin/sol.js +0 -43
- package/dist/mixin/syntax.js +0 -56
- package/dist/parser/braces.js +0 -121
- package/dist/parser/commentAndExt.js +0 -69
- package/dist/parser/converter.js +0 -40
- package/dist/parser/externalLinks.js +0 -28
- package/dist/parser/hrAndDoubleUnderscore.js +0 -38
- package/dist/parser/html.js +0 -36
- package/dist/parser/links.js +0 -94
- package/dist/parser/list.js +0 -59
- package/dist/parser/magicLinks.js +0 -40
- package/dist/parser/quotes.js +0 -67
- package/dist/parser/selector.js +0 -162
- package/dist/parser/table.js +0 -112
- package/dist/src/arg.d.ts +0 -58
- package/dist/src/arg.js +0 -189
- package/dist/src/atom.d.ts +0 -12
- package/dist/src/atom.js +0 -27
- package/dist/src/attribute.d.ts +0 -87
- package/dist/src/attribute.js +0 -392
- package/dist/src/attributes.d.ts +0 -107
- package/dist/src/attributes.js +0 -341
- package/dist/src/converter.d.ts +0 -52
- package/dist/src/converter.js +0 -79
- package/dist/src/converterFlags.d.ts +0 -87
- package/dist/src/converterFlags.js +0 -224
- package/dist/src/converterRule.d.ts +0 -81
- package/dist/src/converterRule.js +0 -212
- package/dist/src/extLink.d.ts +0 -54
- package/dist/src/extLink.js +0 -122
- package/dist/src/gallery.d.ts +0 -55
- package/dist/src/gallery.js +0 -122
- package/dist/src/heading.d.ts +0 -74
- package/dist/src/heading.js +0 -127
- package/dist/src/hidden.d.ts +0 -22
- package/dist/src/hidden.js +0 -23
- package/dist/src/html.d.ts +0 -101
- package/dist/src/html.js +0 -222
- package/dist/src/imageParameter.d.ts +0 -66
- package/dist/src/imageParameter.js +0 -247
- package/dist/src/imagemap.d.ts +0 -57
- package/dist/src/imagemap.js +0 -148
- package/dist/src/imagemapLink.d.ts +0 -59
- package/dist/src/imagemapLink.js +0 -40
- package/dist/src/index.d.ts +0 -146
- package/dist/src/index.js +0 -777
- package/dist/src/link/base.d.ts +0 -52
- package/dist/src/link/base.js +0 -209
- package/dist/src/link/category.d.ts +0 -13
- package/dist/src/link/category.js +0 -29
- package/dist/src/link/file.d.ts +0 -96
- package/dist/src/link/file.js +0 -255
- package/dist/src/link/galleryImage.d.ts +0 -44
- package/dist/src/link/galleryImage.js +0 -106
- package/dist/src/link/index.d.ts +0 -53
- package/dist/src/link/index.js +0 -123
- package/dist/src/magicLink.d.ts +0 -70
- package/dist/src/magicLink.js +0 -147
- package/dist/src/nested.d.ts +0 -44
- package/dist/src/nested.js +0 -87
- package/dist/src/nowiki/base.d.ts +0 -47
- package/dist/src/nowiki/base.js +0 -42
- package/dist/src/nowiki/comment.d.ts +0 -40
- package/dist/src/nowiki/comment.js +0 -67
- package/dist/src/nowiki/dd.d.ts +0 -8
- package/dist/src/nowiki/dd.js +0 -25
- package/dist/src/nowiki/doubleUnderscore.d.ts +0 -45
- package/dist/src/nowiki/doubleUnderscore.js +0 -50
- package/dist/src/nowiki/hr.d.ts +0 -31
- package/dist/src/nowiki/hr.js +0 -14
- package/dist/src/nowiki/index.d.ts +0 -16
- package/dist/src/nowiki/index.js +0 -21
- package/dist/src/nowiki/list.d.ts +0 -30
- package/dist/src/nowiki/list.js +0 -48
- package/dist/src/nowiki/listBase.d.ts +0 -19
- package/dist/src/nowiki/listBase.js +0 -12
- package/dist/src/nowiki/noinclude.d.ts +0 -26
- package/dist/src/nowiki/noinclude.js +0 -25
- package/dist/src/nowiki/quote.d.ts +0 -23
- package/dist/src/nowiki/quote.js +0 -45
- package/dist/src/onlyinclude.d.ts +0 -16
- package/dist/src/onlyinclude.js +0 -57
- package/dist/src/paramTag/index.d.ts +0 -37
- package/dist/src/paramTag/index.js +0 -68
- package/dist/src/paramTag/inputbox.d.ts +0 -8
- package/dist/src/paramTag/inputbox.js +0 -23
- package/dist/src/parameter.d.ts +0 -85
- package/dist/src/parameter.js +0 -205
- package/dist/src/pre.d.ts +0 -28
- package/dist/src/pre.js +0 -51
- package/dist/src/syntax.d.ts +0 -28
- package/dist/src/syntax.js +0 -34
- package/dist/src/table/base.d.ts +0 -53
- package/dist/src/table/base.js +0 -78
- package/dist/src/table/index.d.ts +0 -229
- package/dist/src/table/index.js +0 -379
- package/dist/src/table/td.d.ts +0 -104
- package/dist/src/table/td.js +0 -261
- package/dist/src/table/tr.d.ts +0 -32
- package/dist/src/table/tr.js +0 -56
- package/dist/src/table/trBase.d.ts +0 -54
- package/dist/src/table/trBase.js +0 -159
- package/dist/src/tagPair/ext.d.ts +0 -56
- package/dist/src/tagPair/ext.js +0 -142
- package/dist/src/tagPair/include.d.ts +0 -53
- package/dist/src/tagPair/include.js +0 -63
- package/dist/src/tagPair/index.d.ts +0 -48
- package/dist/src/tagPair/index.js +0 -93
- package/dist/src/transclude.d.ts +0 -167
- package/dist/src/transclude.js +0 -689
- package/dist/util/constants.js +0 -108
- package/dist/util/debug.js +0 -64
- package/dist/util/diff.js +0 -72
- package/dist/util/lint.js +0 -46
- package/dist/util/string.js +0 -61
- package/errors/README +0 -1
- package/printed/README +0 -1
package/dist/src/attributes.js
DELETED
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AttributesToken = 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 Parser = require("../index");
|
|
9
|
-
const index_1 = require("./index");
|
|
10
|
-
const atom_1 = require("./atom");
|
|
11
|
-
const attribute_1 = require("./attribute");
|
|
12
|
-
/* NOT FOR BROWSER */
|
|
13
|
-
const stages = { 'ext-attrs': 0, 'html-attrs': 2, 'table-attrs': 3 };
|
|
14
|
-
/** @ignore */
|
|
15
|
-
const toAttributeType = (type) => type.slice(0, -1);
|
|
16
|
-
/** @ignore */
|
|
17
|
-
const toDirty = (type) => `${toAttributeType(type)}-dirty`;
|
|
18
|
-
/**
|
|
19
|
-
* 扩展和HTML标签属性
|
|
20
|
-
* @classdesc `{childNodes: ...AtomToken|AttributeToken}`
|
|
21
|
-
*/
|
|
22
|
-
class AttributesToken extends index_1.Token {
|
|
23
|
-
/* NOT FOR BROWSER */
|
|
24
|
-
/** getAttrs()方法的getter写法 */
|
|
25
|
-
get attributes() {
|
|
26
|
-
return this.getAttrs();
|
|
27
|
-
}
|
|
28
|
-
set attributes(attrs) {
|
|
29
|
-
this.replaceChildren();
|
|
30
|
-
for (const [key, value] of Object.entries(attrs)) {
|
|
31
|
-
this.setAttr(key, value);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/** 以字符串表示的class属性 */
|
|
35
|
-
get className() {
|
|
36
|
-
const attr = this.getAttr('class');
|
|
37
|
-
return typeof attr === 'string' ? attr : '';
|
|
38
|
-
}
|
|
39
|
-
set className(className) {
|
|
40
|
-
this.setAttr('class', className || false);
|
|
41
|
-
}
|
|
42
|
-
/** 以Set表示的class属性 */
|
|
43
|
-
get classList() {
|
|
44
|
-
return new Set(this.className.split(/\s/u));
|
|
45
|
-
}
|
|
46
|
-
set classList(classList) {
|
|
47
|
-
this.setAttr('class', [...classList].join(' '));
|
|
48
|
-
}
|
|
49
|
-
/** id属性 */
|
|
50
|
-
get id() {
|
|
51
|
-
const attr = this.getAttr('id');
|
|
52
|
-
return typeof attr === 'string' ? attr : '';
|
|
53
|
-
}
|
|
54
|
-
set id(id) {
|
|
55
|
-
this.setAttr('id', id || false);
|
|
56
|
-
}
|
|
57
|
-
/** 是否含有无效属性 */
|
|
58
|
-
get sanitized() {
|
|
59
|
-
return this.childNodes.filter(child => child instanceof atom_1.AtomToken && child.text().trim()).length === 0;
|
|
60
|
-
}
|
|
61
|
-
set sanitized(sanitized) {
|
|
62
|
-
if (sanitized) {
|
|
63
|
-
this.sanitize();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/* NOT FOR BROWSER END */
|
|
67
|
-
/**
|
|
68
|
-
* @param attr 标签属性
|
|
69
|
-
* @param type 标签类型
|
|
70
|
-
* @param name 标签名
|
|
71
|
-
*/
|
|
72
|
-
constructor(attr, type, name, config = Parser.getConfig(), accum = []) {
|
|
73
|
-
super(undefined, config, accum, {
|
|
74
|
-
AtomToken: ':', AttributeToken: ':',
|
|
75
|
-
});
|
|
76
|
-
this.type = type;
|
|
77
|
-
this.setAttribute('name', name);
|
|
78
|
-
if (attr) {
|
|
79
|
-
const regex = new RegExp(`([^\\s/](?:(?!\0\\d+~\x7F)[^\\s/=])*)` // 属性名
|
|
80
|
-
+ '(?:'
|
|
81
|
-
+ '((?:\\s|\0\\d+c\x7F)*' // `=`前的空白字符
|
|
82
|
-
+ '(?:=|\0\\d+~\x7F)' // `=`
|
|
83
|
-
+ '(?:\\s|\0\\d+c\x7F)*)' // `=`后的空白字符
|
|
84
|
-
+ `(?:(["'])(.*?)(\\3|$)|(\\S*))` // 属性值
|
|
85
|
-
+ ')?', 'gsu');
|
|
86
|
-
let out = '', mt = regex.exec(attr), lastIndex = 0;
|
|
87
|
-
const insertDirty = /** 插入无效属性 */ () => {
|
|
88
|
-
if (out) {
|
|
89
|
-
super.insertAt(new atom_1.AtomToken(out, toDirty(type), config, accum, {
|
|
90
|
-
[`Stage-${stages[type]}`]: ':',
|
|
91
|
-
}));
|
|
92
|
-
out = '';
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
while (mt) {
|
|
96
|
-
const { index, 0: full, 1: key, 2: equal, 3: quoteStart, 4: quoted, 5: quoteEnd, 6: unquoted } = mt;
|
|
97
|
-
out += attr.slice(lastIndex, index);
|
|
98
|
-
if (/^(?:[\w:]|\0\d+[t!~{}+-]\x7F)(?:[\w:.-]|\0\d+[t!~{}+-]\x7F)*$/u.test((0, string_1.removeComment)(key).trim())) {
|
|
99
|
-
const value = quoted ?? unquoted, quotes = [quoteStart, quoteEnd], token = new attribute_1.AttributeToken(toAttributeType(type), name, key, equal, value, quotes, config, accum);
|
|
100
|
-
insertDirty();
|
|
101
|
-
super.insertAt(token);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
out += full;
|
|
105
|
-
}
|
|
106
|
-
({ lastIndex } = regex);
|
|
107
|
-
mt = regex.exec(attr);
|
|
108
|
-
}
|
|
109
|
-
out += attr.slice(lastIndex);
|
|
110
|
-
insertDirty();
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
/** @private */
|
|
114
|
-
afterBuild() {
|
|
115
|
-
if (this.type === 'table-attrs') {
|
|
116
|
-
const { parentNode } = this;
|
|
117
|
-
this.setAttribute('name', parentNode?.type === 'td' && parentNode.subtype === 'caption' ? 'caption' : parentNode?.type);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* 所有指定属性名的AttributeToken
|
|
122
|
-
* @param key 属性名
|
|
123
|
-
*/
|
|
124
|
-
getAttrTokens(key) {
|
|
125
|
-
return this.childNodes.filter((child) => child instanceof attribute_1.AttributeToken && (!key || child.name === key.toLowerCase().trim()));
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* 指定属性名的最后一个AttributeToken
|
|
129
|
-
* @param key 属性名
|
|
130
|
-
*/
|
|
131
|
-
getAttrToken(key) {
|
|
132
|
-
const tokens = this.getAttrTokens(key);
|
|
133
|
-
return tokens.at(-1);
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* 获取指定属性
|
|
137
|
-
* @param key 属性键
|
|
138
|
-
*/
|
|
139
|
-
getAttr(key) {
|
|
140
|
-
return this.getAttrToken(key)?.getValue();
|
|
141
|
-
}
|
|
142
|
-
/** @override */
|
|
143
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
144
|
-
const errors = super.lint(start), { parentNode, length, childNodes } = this, attrs = new Map(), duplicated = new Set();
|
|
145
|
-
let rect;
|
|
146
|
-
if (parentNode?.type === 'html' && parentNode.closing && this.text().trim()) {
|
|
147
|
-
rect = { start, ...this.getRootNode().posFromIndex(start) };
|
|
148
|
-
errors.push((0, lint_1.generateForSelf)(this, rect, 'attributes of a closing tag'));
|
|
149
|
-
}
|
|
150
|
-
for (let i = 0; i < length; i++) {
|
|
151
|
-
const attr = childNodes[i];
|
|
152
|
-
if (attr instanceof atom_1.AtomToken && attr.text().trim()) {
|
|
153
|
-
rect ??= { start, ...this.getRootNode().posFromIndex(start) };
|
|
154
|
-
errors.push((0, lint_1.generateForChild)(attr, rect, 'containing invalid attribute'));
|
|
155
|
-
}
|
|
156
|
-
else if (attr instanceof attribute_1.AttributeToken) {
|
|
157
|
-
const { name } = attr;
|
|
158
|
-
if (attrs.has(name)) {
|
|
159
|
-
duplicated.add(name);
|
|
160
|
-
attrs.get(name).push(attr);
|
|
161
|
-
}
|
|
162
|
-
else if (name !== 'class') {
|
|
163
|
-
attrs.set(name, [attr]);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
if (duplicated.size > 0) {
|
|
168
|
-
rect ??= { start, ...this.getRootNode().posFromIndex(start) };
|
|
169
|
-
for (const key of duplicated) {
|
|
170
|
-
errors.push(...attrs.get(key).map(attr => (0, lint_1.generateForChild)(attr, rect, Parser.msg('duplicated $1 attribute', key))));
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return errors;
|
|
174
|
-
}
|
|
175
|
-
/** @override */
|
|
176
|
-
print() {
|
|
177
|
-
return String(this)
|
|
178
|
-
? `<span class="wpb-${this.type}">${this.childNodes.map(child => child.print(child instanceof atom_1.AtomToken && child.text().trim() ? { class: 'attr-dirty' } : undefined)).join('')}</span>`
|
|
179
|
-
: '';
|
|
180
|
-
}
|
|
181
|
-
/* NOT FOR BROWSER */
|
|
182
|
-
/** 清理无效属性 */
|
|
183
|
-
sanitize() {
|
|
184
|
-
let dirty = false;
|
|
185
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
186
|
-
const child = this.childNodes[i];
|
|
187
|
-
if (child instanceof atom_1.AtomToken && child.text().trim()) {
|
|
188
|
-
dirty = true;
|
|
189
|
-
this.removeAt(i);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
if (!debug_1.Shadow.running && dirty) {
|
|
193
|
-
Parser.warn(`${this.constructor.name}.sanitize 方法将清理无效属性!`);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
/** @override */
|
|
197
|
-
cloneNode() {
|
|
198
|
-
const cloned = this.cloneChildNodes();
|
|
199
|
-
return debug_1.Shadow.run(() => {
|
|
200
|
-
const token = new AttributesToken(undefined, this.type, this.name, this.getAttribute('config'));
|
|
201
|
-
token.append(...cloned);
|
|
202
|
-
token.setAttribute('name', this.name);
|
|
203
|
-
return token;
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* @override
|
|
208
|
-
* @param token 待插入的子节点
|
|
209
|
-
* @param i 插入位置
|
|
210
|
-
* @throws `RangeError` 不是AttributeToken或标签不匹配
|
|
211
|
-
*/
|
|
212
|
-
insertAt(token, i = this.length) {
|
|
213
|
-
if (!(token instanceof attribute_1.AttributeToken)) {
|
|
214
|
-
if (String(token).trim()) {
|
|
215
|
-
throw new RangeError(`${this.constructor.name}只能插入AttributeToken!`);
|
|
216
|
-
}
|
|
217
|
-
return super.insertAt(token, i);
|
|
218
|
-
}
|
|
219
|
-
else if (token.type !== this.type.slice(0, -1) || token.tag !== this.name) {
|
|
220
|
-
throw new RangeError(`待插入的AttributeToken只可用于${token.tag}标签!`);
|
|
221
|
-
}
|
|
222
|
-
else if (i === this.length) {
|
|
223
|
-
const { lastChild } = this;
|
|
224
|
-
if (lastChild instanceof attribute_1.AttributeToken) {
|
|
225
|
-
lastChild.close();
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
token.close();
|
|
230
|
-
}
|
|
231
|
-
if (this.closest('parameter')) {
|
|
232
|
-
token.escape();
|
|
233
|
-
}
|
|
234
|
-
super.insertAt(token, i);
|
|
235
|
-
const { previousVisibleSibling, nextVisibleSibling } = token, type = toDirty(this.type), config = this.getAttribute('config'), acceptable = { [`Stage-${stages[this.type]}`]: ':' };
|
|
236
|
-
if (nextVisibleSibling && !/^\s/u.test(String(nextVisibleSibling))) {
|
|
237
|
-
super.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(' ', type, config, [], acceptable)), i + 1);
|
|
238
|
-
}
|
|
239
|
-
if (previousVisibleSibling && !/\s$/u.test(String(previousVisibleSibling))) {
|
|
240
|
-
super.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(' ', type, config, [], acceptable)), i);
|
|
241
|
-
}
|
|
242
|
-
return token;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* 设置指定属性
|
|
246
|
-
* @param key 属性键
|
|
247
|
-
* @param value 属性值
|
|
248
|
-
* @throws `RangeError` 扩展标签属性不能包含">"
|
|
249
|
-
*/
|
|
250
|
-
setAttr(key, value) {
|
|
251
|
-
if (this.type === 'ext-attrs' && typeof value === 'string' && value.includes('>')) {
|
|
252
|
-
throw new RangeError('扩展标签属性不能包含 ">"!');
|
|
253
|
-
}
|
|
254
|
-
key = key.toLowerCase().trim();
|
|
255
|
-
const attr = this.getAttrToken(key);
|
|
256
|
-
if (attr) {
|
|
257
|
-
attr.setValue(value);
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
else if (value === false) {
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
const token = debug_1.Shadow.run(() => new attribute_1.AttributeToken(toAttributeType(this.type), this.name, key, value === true ? '' : '=', value === true ? '' : value, ['"', '"'], this.getAttribute('config')));
|
|
264
|
-
this.insertAt(token);
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* 标签是否具有某属性
|
|
268
|
-
* @param key 属性键
|
|
269
|
-
*/
|
|
270
|
-
hasAttr(key) {
|
|
271
|
-
return this.getAttrTokens(key).length > 0;
|
|
272
|
-
}
|
|
273
|
-
/** 获取全部的属性名 */
|
|
274
|
-
getAttrNames() {
|
|
275
|
-
return new Set(this.getAttrTokens().map(({ name }) => name));
|
|
276
|
-
}
|
|
277
|
-
/** 获取全部属性 */
|
|
278
|
-
getAttrs() {
|
|
279
|
-
return Object.fromEntries(this.getAttrTokens().map(({ name, value }) => [name, value]));
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* 移除指定属性
|
|
283
|
-
* @param key 属性键
|
|
284
|
-
*/
|
|
285
|
-
removeAttr(key) {
|
|
286
|
-
for (const attr of this.getAttrTokens(key)) {
|
|
287
|
-
attr.remove();
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* 开关指定属性
|
|
292
|
-
* @param key 属性键
|
|
293
|
-
* @param force 强制开启或关闭
|
|
294
|
-
* @throws `RangeError` 不为Boolean类型的属性值
|
|
295
|
-
*/
|
|
296
|
-
toggleAttr(key, force) {
|
|
297
|
-
key = key.toLowerCase().trim();
|
|
298
|
-
const attr = this.getAttrToken(key);
|
|
299
|
-
if (attr && attr.getValue() !== true) {
|
|
300
|
-
throw new RangeError(`${key} 属性的值不为 Boolean!`);
|
|
301
|
-
}
|
|
302
|
-
else if (attr) {
|
|
303
|
-
attr.setValue(force === true);
|
|
304
|
-
}
|
|
305
|
-
else if (force !== false) {
|
|
306
|
-
this.setAttr(key, true);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* 生成引导空格
|
|
311
|
-
* @param str 属性字符串
|
|
312
|
-
*/
|
|
313
|
-
#leadingSpace(str) {
|
|
314
|
-
const { type } = this, leadingRegex = { 'ext-attrs': /^\s/u, 'html-attrs': /^[/\s]/u };
|
|
315
|
-
return str && type !== 'table-attrs' && !leadingRegex[type].test(str) ? ' ' : '';
|
|
316
|
-
}
|
|
317
|
-
/** @private */
|
|
318
|
-
toString(omit) {
|
|
319
|
-
if (this.type === 'table-attrs') {
|
|
320
|
-
(0, string_1.normalizeSpace)(this);
|
|
321
|
-
}
|
|
322
|
-
const str = super.toString(omit);
|
|
323
|
-
return `${this.#leadingSpace(str)}${str}`;
|
|
324
|
-
}
|
|
325
|
-
/** @private */
|
|
326
|
-
getAttribute(key) {
|
|
327
|
-
return key === 'padding'
|
|
328
|
-
? this.#leadingSpace(super.toString()).length
|
|
329
|
-
: super.getAttribute(key);
|
|
330
|
-
}
|
|
331
|
-
/** @override */
|
|
332
|
-
text() {
|
|
333
|
-
if (this.type === 'table-attrs') {
|
|
334
|
-
(0, string_1.normalizeSpace)(this);
|
|
335
|
-
}
|
|
336
|
-
const str = (0, string_1.text)(this.childNodes.filter(child => child instanceof attribute_1.AttributeToken), ' ');
|
|
337
|
-
return `${this.#leadingSpace(str)}${str}`;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
exports.AttributesToken = AttributesToken;
|
|
341
|
-
constants_1.classes['AttributesToken'] = __filename;
|
package/dist/src/converter.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import * as Parser from '../index';
|
|
2
|
-
import { Token } from './index';
|
|
3
|
-
import { ConverterFlagsToken } from './converterFlags';
|
|
4
|
-
import { ConverterRuleToken } from './converterRule';
|
|
5
|
-
declare const ConverterToken_base: (abstract new (...args: any[]) => {
|
|
6
|
-
readonly firstChild: Parser.ConverterFlagsToken;
|
|
7
|
-
readonly firstElementChild: Parser.ConverterFlagsToken;
|
|
8
|
-
flags: Set<string>;
|
|
9
|
-
getAllFlags(): Set<string>;
|
|
10
|
-
getEffectiveFlags(): Set<string>;
|
|
11
|
-
getUnknownFlags(): Set<string>;
|
|
12
|
-
hasFlag(flag: string): boolean;
|
|
13
|
-
hasEffectiveFlag(flag: string): boolean;
|
|
14
|
-
removeFlag(flag: string): void;
|
|
15
|
-
setFlag(flag: string): void;
|
|
16
|
-
toggleFlag(flag: string): void;
|
|
17
|
-
readonly length: number;
|
|
18
|
-
toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
|
|
19
|
-
text(separator?: string | undefined): string;
|
|
20
|
-
lint(start?: number | undefined): Parser.LintError[];
|
|
21
|
-
insertAt(token: unknown, i?: number | undefined): unknown;
|
|
22
|
-
afterBuild(): void;
|
|
23
|
-
getAttribute<T extends string>(key: T): TokenAttributeGetter<T>;
|
|
24
|
-
setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
|
|
25
|
-
addEventListener(events: string | string[], listener: AstListener): void;
|
|
26
|
-
replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
|
|
27
|
-
}) & typeof Parser.Token;
|
|
28
|
-
/**
|
|
29
|
-
* 转换
|
|
30
|
-
* @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken]}`
|
|
31
|
-
*/
|
|
32
|
-
export declare class ConverterToken extends ConverterToken_base {
|
|
33
|
-
readonly type = "converter";
|
|
34
|
-
readonly childNodes: [ConverterFlagsToken, ...ConverterRuleToken[]];
|
|
35
|
-
abstract get children(): [ConverterFlagsToken, ...ConverterRuleToken[]];
|
|
36
|
-
abstract get lastChild(): ConverterFlagsToken | ConverterRuleToken;
|
|
37
|
-
abstract get lastElementChild(): ConverterFlagsToken | ConverterRuleToken;
|
|
38
|
-
/** 是否不转换 */
|
|
39
|
-
get noConvert(): boolean;
|
|
40
|
-
/**
|
|
41
|
-
* @param flags 转换类型标记
|
|
42
|
-
* @param rules 转换规则
|
|
43
|
-
*/
|
|
44
|
-
constructor(flags: readonly string[], rules: readonly [string, ...string[]], config?: Parser.Config, accum?: Token[]);
|
|
45
|
-
/** @override */
|
|
46
|
-
text(): string;
|
|
47
|
-
/** @override */
|
|
48
|
-
print(): string;
|
|
49
|
-
/** @override */
|
|
50
|
-
cloneNode(): this;
|
|
51
|
-
}
|
|
52
|
-
export {};
|
package/dist/src/converter.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConverterToken = void 0;
|
|
4
|
-
const string_1 = require("../util/string");
|
|
5
|
-
const debug_1 = require("../util/debug");
|
|
6
|
-
const constants_1 = require("../util/constants");
|
|
7
|
-
const flagsParent_1 = require("../mixin/flagsParent");
|
|
8
|
-
const Parser = require("../index");
|
|
9
|
-
const index_1 = require("./index");
|
|
10
|
-
const converterFlags_1 = require("./converterFlags");
|
|
11
|
-
const converterRule_1 = require("./converterRule");
|
|
12
|
-
/**
|
|
13
|
-
* 转换
|
|
14
|
-
* @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken]}`
|
|
15
|
-
*/
|
|
16
|
-
class ConverterToken extends (0, flagsParent_1.flagsParent)(index_1.Token) {
|
|
17
|
-
type = 'converter';
|
|
18
|
-
/* NOT FOR BROWSER */
|
|
19
|
-
/** 是否不转换 */
|
|
20
|
-
get noConvert() {
|
|
21
|
-
return this.hasFlag('R') || this.length === 2 && this.lastChild.length === 1;
|
|
22
|
-
}
|
|
23
|
-
/* NOT FOR BROWSER END */
|
|
24
|
-
/**
|
|
25
|
-
* @param flags 转换类型标记
|
|
26
|
-
* @param rules 转换规则
|
|
27
|
-
*/
|
|
28
|
-
constructor(flags, rules, config = Parser.getConfig(), accum = []) {
|
|
29
|
-
super(undefined, config, accum);
|
|
30
|
-
this.append(new converterFlags_1.ConverterFlagsToken(flags, config, accum));
|
|
31
|
-
const [firstRule] = rules, hasColon = firstRule.includes(':'), firstRuleToken = new converterRule_1.ConverterRuleToken(firstRule, hasColon, config, accum);
|
|
32
|
-
if (hasColon && firstRuleToken.length === 1) {
|
|
33
|
-
this.insertAt(new converterRule_1.ConverterRuleToken(rules.join(';'), false, config, accum));
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
this.append(firstRuleToken, ...rules.slice(1).map(rule => new converterRule_1.ConverterRuleToken(rule, true, config, accum)));
|
|
37
|
-
}
|
|
38
|
-
this.protectChildren(0);
|
|
39
|
-
}
|
|
40
|
-
/** @private */
|
|
41
|
-
toString(omit) {
|
|
42
|
-
const { childNodes: [flags, ...rules] } = this;
|
|
43
|
-
return omit && this.matchesTypes(omit)
|
|
44
|
-
? ''
|
|
45
|
-
: `-{${flags.toString(omit)}${flags.length > 0 ? '|' : ''}${rules.map(rule => rule.toString(omit)).join(';')}}-`;
|
|
46
|
-
}
|
|
47
|
-
/** @override */
|
|
48
|
-
text() {
|
|
49
|
-
const { childNodes: [flags, ...rules] } = this;
|
|
50
|
-
return `-{${flags.text()}|${(0, string_1.text)(rules, ';')}}-`;
|
|
51
|
-
}
|
|
52
|
-
/** @private */
|
|
53
|
-
getAttribute(key) {
|
|
54
|
-
return key === 'padding' ? 2 : super.getAttribute(key);
|
|
55
|
-
}
|
|
56
|
-
/** @private */
|
|
57
|
-
getGaps(i) {
|
|
58
|
-
return i || this.firstChild.length > 0 ? 1 : 0;
|
|
59
|
-
}
|
|
60
|
-
/** @override */
|
|
61
|
-
print() {
|
|
62
|
-
const { childNodes: [flags, ...rules] } = this;
|
|
63
|
-
return `<span class="wpb-converter">-{${flags.print()}${flags.length > 0 ? '|' : ''}${(0, string_1.print)(rules, { sep: ';' })}}-</span>`;
|
|
64
|
-
}
|
|
65
|
-
/* NOT FOR BROWSER */
|
|
66
|
-
/** @override */
|
|
67
|
-
cloneNode() {
|
|
68
|
-
const [flags, ...rules] = this.cloneChildNodes();
|
|
69
|
-
return debug_1.Shadow.run(() => {
|
|
70
|
-
const token = new ConverterToken([], [''], this.getAttribute('config'));
|
|
71
|
-
token.firstChild.safeReplaceWith(flags);
|
|
72
|
-
token.removeAt(1);
|
|
73
|
-
token.append(...rules);
|
|
74
|
-
return token;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.ConverterToken = ConverterToken;
|
|
79
|
-
constants_1.classes['ConverterToken'] = __filename;
|
|
@@ -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 { ConverterToken, ConverterRuleToken } from '../internal';
|
|
6
|
-
/**
|
|
7
|
-
* 转换flags
|
|
8
|
-
* @classdesc `{childNodes: ...AtomToken}`
|
|
9
|
-
*/
|
|
10
|
-
export declare class ConverterFlagsToken extends Token {
|
|
11
|
-
#private;
|
|
12
|
-
readonly type = "converter-flags";
|
|
13
|
-
readonly childNodes: AtomToken[];
|
|
14
|
-
abstract get children(): AtomToken[];
|
|
15
|
-
abstract get firstChild(): AtomToken | undefined;
|
|
16
|
-
abstract get firstElementChild(): AtomToken | undefined;
|
|
17
|
-
abstract get lastChild(): AtomToken | undefined;
|
|
18
|
-
abstract get lastElementChild(): AtomToken | undefined;
|
|
19
|
-
abstract get parentNode(): ConverterToken | undefined;
|
|
20
|
-
abstract get parentElement(): ConverterToken | undefined;
|
|
21
|
-
abstract get previousSibling(): undefined;
|
|
22
|
-
abstract get previousElementSibling(): undefined;
|
|
23
|
-
abstract get nextSibling(): ConverterRuleToken | undefined;
|
|
24
|
-
abstract get nextElementSibling(): ConverterRuleToken | undefined;
|
|
25
|
-
/** 所有转换类型标记 */
|
|
26
|
-
get flags(): Set<string>;
|
|
27
|
-
set flags(value: Set<string>);
|
|
28
|
-
/** @param flags 转换类型标记 */
|
|
29
|
-
constructor(flags: readonly string[], config?: Parser.Config, accum?: Token[]);
|
|
30
|
-
/** @override */
|
|
31
|
-
text(): string;
|
|
32
|
-
/** 获取未知的转换类型标记 */
|
|
33
|
-
getUnknownFlags(): Set<string>;
|
|
34
|
-
/** 获取指定语言变体的转换标记 */
|
|
35
|
-
getVariantFlags(): Set<string>;
|
|
36
|
-
/** @override */
|
|
37
|
-
lint(start?: number): LintError[];
|
|
38
|
-
/** @override */
|
|
39
|
-
print(): string;
|
|
40
|
-
/** @override */
|
|
41
|
-
cloneNode(): this;
|
|
42
|
-
/**
|
|
43
|
-
* @override
|
|
44
|
-
* @param i 移除位置
|
|
45
|
-
*/
|
|
46
|
-
removeAt(i: number): AtomToken;
|
|
47
|
-
/**
|
|
48
|
-
* @override
|
|
49
|
-
* @param token 待插入的子节点
|
|
50
|
-
* @param i 插入位置
|
|
51
|
-
*/
|
|
52
|
-
insertAt<T extends AtomToken>(token: T, i?: number): T;
|
|
53
|
-
/** 获取所有转换类型标记 */
|
|
54
|
-
getAllFlags(): Set<string>;
|
|
55
|
-
/**
|
|
56
|
-
* 获取转换类型标记节点
|
|
57
|
-
* @param flag 转换类型标记
|
|
58
|
-
*/
|
|
59
|
-
getFlagTokens(flag: string): readonly AtomToken[];
|
|
60
|
-
/** 获取有效的转换类型标记 */
|
|
61
|
-
getEffectiveFlags(): Set<string>;
|
|
62
|
-
/**
|
|
63
|
-
* 是否具有某转换类型标记
|
|
64
|
-
* @param flag 转换类型标记
|
|
65
|
-
*/
|
|
66
|
-
hasFlag(flag: string): boolean;
|
|
67
|
-
/**
|
|
68
|
-
* 是否具有某有效的转换类型标记
|
|
69
|
-
* @param flag 转换类型标记
|
|
70
|
-
*/
|
|
71
|
-
hasEffectiveFlag(flag: string): boolean;
|
|
72
|
-
/**
|
|
73
|
-
* 移除某转换类型标记
|
|
74
|
-
* @param flag 转换类型标记
|
|
75
|
-
*/
|
|
76
|
-
removeFlag(flag: string): void;
|
|
77
|
-
/**
|
|
78
|
-
* 设置转换类型标记
|
|
79
|
-
* @param flag 转换类型标记
|
|
80
|
-
*/
|
|
81
|
-
setFlag(flag: string): void;
|
|
82
|
-
/**
|
|
83
|
-
* 开关转换类型标记
|
|
84
|
-
* @param flag 转换类型标记
|
|
85
|
-
*/
|
|
86
|
-
toggleFlag(flag: string): void;
|
|
87
|
-
}
|