wikiparser-node 1.13.1-b → 1.13.1
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/config/.schema.json +203 -0
- package/config/default.json +32 -31
- package/config/enwiki.json +829 -15
- package/config/llwiki.json +56 -21
- package/config/moegirl.json +65 -21
- package/config/zhwiki.json +498 -32
- package/dist/addon/table.js +494 -0
- package/dist/addon/token.js +392 -0
- package/dist/addon/transclude.js +184 -0
- package/dist/base.d.ts +110 -0
- package/dist/base.js +67 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +279 -0
- package/dist/internal.d.ts +47 -0
- package/dist/lib/element.d.ts +125 -0
- package/dist/lib/element.js +364 -0
- package/dist/lib/node.d.ts +173 -0
- package/dist/lib/node.js +478 -0
- package/dist/lib/range.d.ts +105 -0
- package/dist/lib/range.js +406 -0
- package/dist/lib/ranges.d.ts +28 -0
- package/dist/lib/ranges.js +126 -0
- package/dist/lib/rect.d.ts +18 -0
- package/dist/lib/rect.js +36 -0
- package/dist/lib/text.d.ts +58 -0
- package/dist/lib/text.js +414 -0
- package/dist/lib/title.d.ts +49 -0
- package/dist/lib/title.js +251 -0
- package/dist/mixin/attributesParent.d.ts +49 -0
- package/dist/mixin/attributesParent.js +80 -0
- package/dist/mixin/fixed.d.ts +5 -0
- package/dist/mixin/fixed.js +32 -0
- package/dist/mixin/flagsParent.d.ts +43 -0
- package/dist/mixin/flagsParent.js +64 -0
- package/dist/mixin/hidden.d.ts +7 -0
- package/dist/mixin/hidden.js +39 -0
- package/dist/mixin/magicLinkParent.d.ts +19 -0
- package/dist/mixin/magicLinkParent.js +43 -0
- package/dist/mixin/singleLine.d.ts +5 -0
- package/dist/mixin/singleLine.js +25 -0
- package/dist/mixin/sol.d.ts +6 -0
- package/dist/mixin/sol.js +45 -0
- package/dist/mixin/syntax.d.ts +8 -0
- package/dist/mixin/syntax.js +46 -0
- package/dist/parser/braces.js +152 -0
- package/dist/parser/commentAndExt.js +84 -0
- package/dist/parser/converter.js +41 -0
- package/dist/parser/externalLinks.js +39 -0
- package/dist/parser/hrAndDoubleUnderscore.js +44 -0
- package/dist/parser/html.js +40 -0
- package/dist/parser/links.js +103 -0
- package/dist/parser/list.js +116 -0
- package/dist/parser/magicLinks.js +55 -0
- package/dist/parser/quotes.js +69 -0
- package/dist/parser/redirect.js +28 -0
- package/dist/parser/selector.js +443 -0
- package/dist/parser/table.js +125 -0
- package/dist/src/arg.d.ts +49 -0
- package/dist/src/arg.js +220 -0
- package/dist/src/atom.d.ts +14 -0
- package/dist/src/atom.js +54 -0
- package/dist/src/attribute.d.ts +64 -0
- package/dist/src/attribute.js +482 -0
- package/dist/src/attributes.d.ts +103 -0
- package/dist/src/attributes.js +383 -0
- package/dist/src/converter.d.ts +28 -0
- package/dist/src/converter.js +153 -0
- package/dist/src/converterFlags.d.ts +80 -0
- package/dist/src/converterFlags.js +241 -0
- package/dist/src/converterRule.d.ts +71 -0
- package/dist/src/converterRule.js +218 -0
- package/dist/src/extLink.d.ts +36 -0
- package/dist/src/extLink.js +223 -0
- package/dist/src/gallery.d.ts +51 -0
- package/dist/src/gallery.js +166 -0
- package/dist/src/heading.d.ts +44 -0
- package/dist/src/heading.js +222 -0
- package/dist/src/hidden.d.ts +9 -0
- package/dist/src/hidden.js +82 -0
- package/dist/src/html.d.ts +61 -0
- package/dist/src/html.js +344 -0
- package/dist/src/imageParameter.d.ts +60 -0
- package/dist/src/imageParameter.js +262 -0
- package/dist/src/imagemap.d.ts +47 -0
- package/dist/src/imagemap.js +148 -0
- package/dist/src/imagemapLink.d.ts +35 -0
- package/dist/src/imagemapLink.js +99 -0
- package/dist/src/index.d.ts +136 -0
- package/dist/src/index.js +790 -0
- package/dist/src/link/base.d.ts +52 -0
- package/dist/src/link/base.js +258 -0
- package/dist/src/link/category.d.ts +22 -0
- package/dist/src/link/category.js +36 -0
- package/dist/src/link/file.d.ts +102 -0
- package/dist/src/link/file.js +345 -0
- package/dist/src/link/galleryImage.d.ts +29 -0
- package/dist/src/link/galleryImage.js +133 -0
- package/dist/src/link/index.d.ts +39 -0
- package/dist/src/link/index.js +100 -0
- package/dist/src/link/redirectTarget.d.ts +27 -0
- package/dist/src/link/redirectTarget.js +71 -0
- package/dist/src/magicLink.d.ts +57 -0
- package/dist/src/magicLink.js +261 -0
- package/dist/src/nested.d.ts +40 -0
- package/dist/src/nested.js +108 -0
- package/dist/src/nowiki/base.d.ts +28 -0
- package/dist/src/nowiki/base.js +90 -0
- package/dist/src/nowiki/comment.d.ts +14 -0
- package/dist/src/nowiki/comment.js +123 -0
- package/dist/src/nowiki/dd.d.ts +8 -0
- package/dist/src/nowiki/dd.js +74 -0
- package/dist/src/nowiki/doubleUnderscore.d.ts +15 -0
- package/dist/src/nowiki/doubleUnderscore.js +101 -0
- package/dist/src/nowiki/hr.d.ts +5 -0
- package/dist/src/nowiki/hr.js +72 -0
- package/dist/src/nowiki/index.d.ts +14 -0
- package/dist/src/nowiki/index.js +30 -0
- package/dist/src/nowiki/list.d.ts +5 -0
- package/dist/src/nowiki/list.js +67 -0
- package/dist/src/nowiki/listBase.d.ts +23 -0
- package/dist/src/nowiki/listBase.js +100 -0
- package/dist/src/nowiki/noinclude.d.ts +6 -0
- package/dist/src/nowiki/noinclude.js +77 -0
- package/dist/src/nowiki/quote.d.ts +14 -0
- package/dist/src/nowiki/quote.js +149 -0
- package/dist/src/onlyinclude.d.ts +13 -0
- package/dist/src/onlyinclude.js +60 -0
- package/dist/src/paramTag/index.d.ts +28 -0
- package/dist/src/paramTag/index.js +80 -0
- package/dist/src/paramTag/inputbox.d.ts +8 -0
- package/dist/src/paramTag/inputbox.js +38 -0
- package/dist/src/parameter.d.ts +60 -0
- package/dist/src/parameter.js +267 -0
- package/dist/src/pre.d.ts +28 -0
- package/dist/src/pre.js +70 -0
- package/dist/src/redirect.d.ts +30 -0
- package/dist/src/redirect.js +128 -0
- package/dist/src/syntax.d.ts +15 -0
- package/dist/src/syntax.js +87 -0
- package/dist/src/table/base.d.ts +28 -0
- package/dist/src/table/base.js +81 -0
- package/dist/src/table/index.d.ts +230 -0
- package/dist/src/table/index.js +506 -0
- package/dist/src/table/td.d.ts +72 -0
- package/dist/src/table/td.js +375 -0
- package/dist/src/table/tr.d.ts +30 -0
- package/dist/src/table/tr.js +61 -0
- package/dist/src/table/trBase.d.ts +49 -0
- package/dist/src/table/trBase.js +165 -0
- package/dist/src/tagPair/ext.d.ts +29 -0
- package/dist/src/tagPair/ext.js +229 -0
- package/dist/src/tagPair/include.d.ts +33 -0
- package/dist/src/tagPair/include.js +145 -0
- package/dist/src/tagPair/index.d.ts +23 -0
- package/dist/src/tagPair/index.js +130 -0
- package/dist/src/transclude.d.ts +159 -0
- package/dist/src/transclude.js +598 -0
- package/dist/util/constants.js +26 -0
- package/dist/util/debug.js +95 -0
- package/dist/util/diff.js +83 -0
- package/dist/util/html.js +146 -0
- package/dist/util/lint.js +32 -0
- package/dist/util/string.js +107 -0
- package/errors/README +3 -0
- package/package.json +21 -28
- package/printed/README +3 -0
- package/bundle/bundle.min.js +0 -37
- package/extensions/dist/base.js +0 -163
- package/extensions/dist/codejar.js +0 -53
- package/extensions/dist/editor.js +0 -159
- package/extensions/dist/highlight.js +0 -30
- package/extensions/dist/lint.js +0 -72
- package/extensions/editor.css +0 -59
- package/extensions/ui.css +0 -162
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.createTd = exports.TdToken = void 0;
|
|
38
|
+
const lint_1 = require("../../util/lint");
|
|
39
|
+
const constants_1 = require("../../util/constants");
|
|
40
|
+
const debug_1 = require("../../util/debug");
|
|
41
|
+
const rect_1 = require("../../lib/rect");
|
|
42
|
+
const index_1 = require("../../index");
|
|
43
|
+
const index_2 = require("../index");
|
|
44
|
+
const base_1 = require("./base");
|
|
45
|
+
/* NOT FOR BROWSER */
|
|
46
|
+
const string_1 = require("../../util/string");
|
|
47
|
+
const fixed_1 = require("../../mixin/fixed");
|
|
48
|
+
/* NOT FOR BROWSER END */
|
|
49
|
+
/**
|
|
50
|
+
* `<td>`、`<th>`和`<caption>`
|
|
51
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, Token]}`
|
|
52
|
+
*/
|
|
53
|
+
let TdToken = (() => {
|
|
54
|
+
var _a;
|
|
55
|
+
let _classDecorators = [fixed_1.fixedToken];
|
|
56
|
+
let _classDescriptor;
|
|
57
|
+
let _classExtraInitializers = [];
|
|
58
|
+
let _classThis;
|
|
59
|
+
let _classSuper = base_1.TableBaseToken;
|
|
60
|
+
var TdToken = class extends _classSuper {
|
|
61
|
+
static { _classThis = this; }
|
|
62
|
+
static {
|
|
63
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
64
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
65
|
+
TdToken = _classThis = _classDescriptor.value;
|
|
66
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
67
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
68
|
+
}
|
|
69
|
+
#innerSyntax = '';
|
|
70
|
+
#syntax;
|
|
71
|
+
/* NOT FOR BROWSER END */
|
|
72
|
+
get type() {
|
|
73
|
+
return 'td';
|
|
74
|
+
}
|
|
75
|
+
/** rowspan */
|
|
76
|
+
get rowspan() {
|
|
77
|
+
return this.getAttr('rowspan');
|
|
78
|
+
}
|
|
79
|
+
/** colspan */
|
|
80
|
+
get colspan() {
|
|
81
|
+
return this.getAttr('colspan');
|
|
82
|
+
}
|
|
83
|
+
/** 单元格类型 */
|
|
84
|
+
get subtype() {
|
|
85
|
+
return this.#getSyntax().subtype;
|
|
86
|
+
}
|
|
87
|
+
/* NOT FOR BROWSER */
|
|
88
|
+
set subtype(subtype) {
|
|
89
|
+
this.setSyntax(subtype);
|
|
90
|
+
}
|
|
91
|
+
set rowspan(rowspan) {
|
|
92
|
+
this.setAttr('rowspan', rowspan);
|
|
93
|
+
}
|
|
94
|
+
set colspan(colspan) {
|
|
95
|
+
this.setAttr('colspan', colspan);
|
|
96
|
+
}
|
|
97
|
+
/** 内部wikitext */
|
|
98
|
+
get innerText() {
|
|
99
|
+
return this.lastChild.text().trim();
|
|
100
|
+
}
|
|
101
|
+
set innerText(text) {
|
|
102
|
+
this.lastChild.replaceChildren(...index_1.default.parse(text, true, undefined, this.getAttribute('config')).childNodes);
|
|
103
|
+
}
|
|
104
|
+
/* NOT FOR BROWSER END */
|
|
105
|
+
/**
|
|
106
|
+
* @param syntax 单元格语法
|
|
107
|
+
* @param inner 内部wikitext
|
|
108
|
+
*/
|
|
109
|
+
constructor(syntax, inner, config = index_1.default.getConfig(), accum = []) {
|
|
110
|
+
let innerSyntax = /\||\0\d+!\x7F/u.exec(inner ?? ''), attr = innerSyntax ? inner.slice(0, innerSyntax.index) : '';
|
|
111
|
+
if (/\[\[|-\{/u.test(attr)) {
|
|
112
|
+
innerSyntax = null;
|
|
113
|
+
attr = '';
|
|
114
|
+
}
|
|
115
|
+
super(/^(?:\n[^\S\n]*(?:[|!]|\|\+|\{\{\s*!\s*\}\}\+?)|(?:\||\{\{\s*!\s*\}\}){2}|!!|\{\{\s*!!\s*\}\})$/u, syntax, 'td', attr, config, accum, { SyntaxToken: 0, AttributesToken: 1, Token: 2 });
|
|
116
|
+
if (innerSyntax) {
|
|
117
|
+
[this.#innerSyntax] = innerSyntax;
|
|
118
|
+
}
|
|
119
|
+
const innerToken = new index_2.Token(inner?.slice((innerSyntax?.index ?? NaN) + this.#innerSyntax.length), config, accum);
|
|
120
|
+
innerToken.type = 'td-inner';
|
|
121
|
+
innerToken.setAttribute('stage', 4);
|
|
122
|
+
this.insertAt(innerToken);
|
|
123
|
+
}
|
|
124
|
+
/** 表格语法信息 */
|
|
125
|
+
#getSyntax() {
|
|
126
|
+
const { rev } = debug_1.Shadow;
|
|
127
|
+
if (this.#syntax && this.#syntax[0] !== rev) {
|
|
128
|
+
this.#syntax = undefined;
|
|
129
|
+
}
|
|
130
|
+
if (index_1.default.viewOnly) {
|
|
131
|
+
this.#syntax ??= [rev, this.#computeSyntax()];
|
|
132
|
+
return this.#syntax[1];
|
|
133
|
+
}
|
|
134
|
+
return this.#computeSyntax();
|
|
135
|
+
}
|
|
136
|
+
/** 表格语法信息 */
|
|
137
|
+
#computeSyntax() {
|
|
138
|
+
const syntax = this.firstChild.text(),
|
|
139
|
+
/* NOT FOR BROWSER */
|
|
140
|
+
esc = syntax.includes('{{'),
|
|
141
|
+
/* NOT FOR BROWSER END */
|
|
142
|
+
char = syntax.slice(-1);
|
|
143
|
+
let subtype = 'td';
|
|
144
|
+
if (char === '!') {
|
|
145
|
+
subtype = 'th';
|
|
146
|
+
}
|
|
147
|
+
else if (char === '+') {
|
|
148
|
+
subtype = 'caption';
|
|
149
|
+
}
|
|
150
|
+
if (this.isIndependent()) {
|
|
151
|
+
return {
|
|
152
|
+
subtype,
|
|
153
|
+
/* NOT FOR BROWSER */
|
|
154
|
+
escape: esc,
|
|
155
|
+
correction: false,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const { previousSibling } = this;
|
|
159
|
+
/* NOT FOR BROWSER */
|
|
160
|
+
if (!(previousSibling instanceof TdToken)) {
|
|
161
|
+
return { subtype, escape: esc, correction: true };
|
|
162
|
+
}
|
|
163
|
+
/* NOT FOR BROWSER END */
|
|
164
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
165
|
+
const result = { ...previousSibling.#getSyntax() };
|
|
166
|
+
/* NOT FOR BROWSER */
|
|
167
|
+
const str = previousSibling.lastChild.toString();
|
|
168
|
+
result.escape ||= esc;
|
|
169
|
+
result.correction = str.includes('\n') && debug_1.Shadow.run(() => {
|
|
170
|
+
const config = this.getAttribute('config'), include = this.getAttribute('include');
|
|
171
|
+
return new index_2.Token(str, config).parseOnce(0, include).parseOnce().parseOnce()
|
|
172
|
+
.toString()
|
|
173
|
+
.includes('\n');
|
|
174
|
+
});
|
|
175
|
+
if (subtype === 'th' && result.subtype !== 'th') {
|
|
176
|
+
result.subtype = 'th';
|
|
177
|
+
result.correction = true;
|
|
178
|
+
}
|
|
179
|
+
/* NOT FOR BROWSER END */
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
/** @private */
|
|
183
|
+
afterBuild() {
|
|
184
|
+
if (this.#innerSyntax.includes('\0')) {
|
|
185
|
+
this.#innerSyntax = this.buildFromStr(this.#innerSyntax, constants_1.BuildMethod.String);
|
|
186
|
+
}
|
|
187
|
+
super.afterBuild();
|
|
188
|
+
}
|
|
189
|
+
/** @private */
|
|
190
|
+
toString(skip) {
|
|
191
|
+
/* NOT FOR BROWSER */
|
|
192
|
+
this.#correct();
|
|
193
|
+
/* NOT FOR BROWSER END */
|
|
194
|
+
const { childNodes: [syntax, attr, inner] } = this;
|
|
195
|
+
return syntax.toString(skip) + attr.toString(skip) + this.#innerSyntax + inner.toString(skip);
|
|
196
|
+
}
|
|
197
|
+
/** @private */
|
|
198
|
+
text() {
|
|
199
|
+
/* NOT FOR BROWSER */
|
|
200
|
+
this.#correct();
|
|
201
|
+
/* NOT FOR BROWSER END */
|
|
202
|
+
const { childNodes: [syntax, attr, inner] } = this;
|
|
203
|
+
return syntax.text() + attr.text() + this.#innerSyntax + inner.text();
|
|
204
|
+
}
|
|
205
|
+
/** @private */
|
|
206
|
+
getGaps(i) {
|
|
207
|
+
if (i === 1) {
|
|
208
|
+
/* NOT FOR BROWSER */
|
|
209
|
+
this.#correct();
|
|
210
|
+
/* NOT FOR BROWSER END */
|
|
211
|
+
return this.#innerSyntax.length;
|
|
212
|
+
}
|
|
213
|
+
return 0;
|
|
214
|
+
}
|
|
215
|
+
/** @private */
|
|
216
|
+
lint(start = this.getAbsoluteIndex(), re) {
|
|
217
|
+
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start + this.getRelativeIndex(this.length - 1));
|
|
218
|
+
for (const child of this.lastChild.childNodes) {
|
|
219
|
+
if (child.type === 'text') {
|
|
220
|
+
const { data } = child;
|
|
221
|
+
if (data.includes('|')) {
|
|
222
|
+
const isError = data.includes('||'), e = (0, lint_1.generateForChild)(child, rect, 'pipe-like', 'additional "|" in a table cell', isError ? 'error' : 'warning');
|
|
223
|
+
if (isError) {
|
|
224
|
+
const syntax = { caption: '|+', td: '|', th: '!' }[this.subtype];
|
|
225
|
+
e.fix = {
|
|
226
|
+
range: [e.startIndex, e.endIndex],
|
|
227
|
+
text: data.replace(/\|\|/gu, `\n${syntax}`),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
e.suggestions = [
|
|
232
|
+
{
|
|
233
|
+
desc: 'escape',
|
|
234
|
+
range: [e.startIndex, e.endIndex],
|
|
235
|
+
text: data.replace(/\|/gu, '|'),
|
|
236
|
+
},
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
errors.push(e);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return errors;
|
|
244
|
+
}
|
|
245
|
+
/** 是否位于行首 */
|
|
246
|
+
isIndependent() {
|
|
247
|
+
return this.firstChild.text().startsWith('\n');
|
|
248
|
+
}
|
|
249
|
+
getAttr(key) {
|
|
250
|
+
const value = super.getAttr(key);
|
|
251
|
+
key = key.toLowerCase().trim();
|
|
252
|
+
return (key === 'rowspan' || key === 'colspan' ? parseInt(value) || 1 : value);
|
|
253
|
+
}
|
|
254
|
+
/** @private */
|
|
255
|
+
print() {
|
|
256
|
+
const { childNodes: [syntax, attr, inner] } = this;
|
|
257
|
+
return `<span class="wpb-td">${syntax.print()}${attr.print()}${this.#innerSyntax}${inner.print()}</span>`;
|
|
258
|
+
}
|
|
259
|
+
/** @override */
|
|
260
|
+
json() {
|
|
261
|
+
const json = super.json();
|
|
262
|
+
json['subtype'] = this.subtype;
|
|
263
|
+
return json;
|
|
264
|
+
}
|
|
265
|
+
/* NOT FOR BROWSER */
|
|
266
|
+
cloneNode() {
|
|
267
|
+
const token = super.cloneNode();
|
|
268
|
+
token.setAttribute('innerSyntax', this.#innerSyntax);
|
|
269
|
+
return token;
|
|
270
|
+
}
|
|
271
|
+
/** @private */
|
|
272
|
+
setAttribute(key, value) {
|
|
273
|
+
if (key === 'innerSyntax') {
|
|
274
|
+
this.#innerSyntax = (value ?? '');
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
super.setAttribute(key, value);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/** @private */
|
|
281
|
+
setSyntax(syntax, esc) {
|
|
282
|
+
const aliases = { td: '\n|', th: '\n!', caption: '\n|+' };
|
|
283
|
+
super.setSyntax(aliases[syntax] ?? syntax, esc);
|
|
284
|
+
}
|
|
285
|
+
/** 修复\<td\>语法 */
|
|
286
|
+
#correct() {
|
|
287
|
+
if (this.childNodes[1].toString()) {
|
|
288
|
+
this.#innerSyntax ||= '|';
|
|
289
|
+
}
|
|
290
|
+
const { subtype, escape, correction } = this.#getSyntax();
|
|
291
|
+
if (correction) {
|
|
292
|
+
this.setSyntax(subtype, escape);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/** 改为独占一行 */
|
|
296
|
+
independence() {
|
|
297
|
+
if (!this.isIndependent()) {
|
|
298
|
+
const { subtype, escape } = this.#getSyntax();
|
|
299
|
+
this.setSyntax(subtype, escape);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
getAttrs() {
|
|
303
|
+
const attr = super.getAttrs();
|
|
304
|
+
if ('rowspan' in attr) {
|
|
305
|
+
attr.rowspan = parseInt(attr.rowspan);
|
|
306
|
+
}
|
|
307
|
+
if ('colspan' in attr) {
|
|
308
|
+
attr.colspan = parseInt(attr.colspan);
|
|
309
|
+
}
|
|
310
|
+
return attr;
|
|
311
|
+
}
|
|
312
|
+
setAttr(keyOrProp, value) {
|
|
313
|
+
if (typeof keyOrProp !== 'string') {
|
|
314
|
+
for (const [key, val] of Object.entries(keyOrProp)) {
|
|
315
|
+
this.setAttr(key, val);
|
|
316
|
+
}
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const key = keyOrProp.toLowerCase().trim();
|
|
320
|
+
let v;
|
|
321
|
+
if (typeof value === 'number' && (key === 'rowspan' || key === 'colspan')) {
|
|
322
|
+
v = value === 1 ? false : String(value);
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
v = String(value);
|
|
326
|
+
}
|
|
327
|
+
super.setAttr(key, v);
|
|
328
|
+
if (!this.childNodes[1].toString()) {
|
|
329
|
+
this.#innerSyntax = '';
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
/** @private */
|
|
333
|
+
escape() {
|
|
334
|
+
super.escape();
|
|
335
|
+
if (this.childNodes[1].toString()) {
|
|
336
|
+
this.#innerSyntax ||= '{{!}}';
|
|
337
|
+
}
|
|
338
|
+
if (this.#innerSyntax === '|') {
|
|
339
|
+
this.#innerSyntax = '{{!}}';
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/** @private */
|
|
343
|
+
toHtmlInternal(nowrap) {
|
|
344
|
+
const { subtype, childNodes: [, attr, inner], nextSibling } = this, notEOL = nextSibling?.toString().startsWith('\n') === false, lf = nowrap ? ' ' : '\n';
|
|
345
|
+
let html = inner.toHtmlInternal(nowrap).replace(/^[^\S\n]*/u, '');
|
|
346
|
+
if (notEOL) {
|
|
347
|
+
html = html.replace(/(?<=[\S\n])[^\S\n]*$/u, '');
|
|
348
|
+
}
|
|
349
|
+
return `${lf}<${subtype}${attr.toHtmlInternal()}>${subtype === 'caption' ? (0, string_1.newline)(html) : html + (notEOL ? '' : lf)}</${subtype}>`;
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
return TdToken = _classThis;
|
|
353
|
+
})();
|
|
354
|
+
exports.TdToken = TdToken;
|
|
355
|
+
/* NOT FOR BROWSER */
|
|
356
|
+
/**
|
|
357
|
+
* 创建新的单元格
|
|
358
|
+
* @param inner 内部wikitext
|
|
359
|
+
* @param subtype 单元格类型
|
|
360
|
+
* @param attr 单元格属性
|
|
361
|
+
* @param include 是否嵌入
|
|
362
|
+
* @param config
|
|
363
|
+
*/
|
|
364
|
+
const createTd = (inner, subtype = 'td', attr = {}, include, config = index_1.default.getConfig()) => {
|
|
365
|
+
const innerToken = typeof inner === 'string' ? index_1.default.parse(inner, include, undefined, config) : inner,
|
|
366
|
+
// @ts-expect-error abstract class
|
|
367
|
+
token = debug_1.Shadow.run(() => new TdToken('\n|', undefined, config));
|
|
368
|
+
token.setSyntax(subtype);
|
|
369
|
+
token.lastChild.safeReplaceWith(innerToken);
|
|
370
|
+
token.setAttr(attr);
|
|
371
|
+
return token;
|
|
372
|
+
};
|
|
373
|
+
exports.createTd = createTd;
|
|
374
|
+
/* NOT FOR BROWSER END */
|
|
375
|
+
constants_1.classes['TdToken'] = __filename;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TrBaseToken } from './trBase';
|
|
2
|
+
import type { Config } from '../../base';
|
|
3
|
+
import type { Token, TdToken, TableToken, SyntaxToken, AttributesToken } from '../../internal';
|
|
4
|
+
/**
|
|
5
|
+
* 表格行,含开头的换行,不含结尾的换行
|
|
6
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken]}`
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class TrToken extends TrBaseToken {
|
|
9
|
+
#private;
|
|
10
|
+
readonly childNodes: readonly [SyntaxToken, AttributesToken, ...TdToken[]];
|
|
11
|
+
abstract get lastChild(): AttributesToken | TdToken;
|
|
12
|
+
abstract get parentNode(): TableToken | undefined;
|
|
13
|
+
abstract get nextSibling(): this | SyntaxToken | undefined;
|
|
14
|
+
abstract get previousSibling(): Token;
|
|
15
|
+
abstract get children(): [SyntaxToken, AttributesToken, ...TdToken[]];
|
|
16
|
+
abstract get lastElementChild(): AttributesToken | TdToken;
|
|
17
|
+
abstract get parentElement(): TableToken | undefined;
|
|
18
|
+
abstract get nextElementSibling(): this | SyntaxToken | undefined;
|
|
19
|
+
abstract get previousElementSibling(): Token;
|
|
20
|
+
get type(): 'tr';
|
|
21
|
+
/**
|
|
22
|
+
* @param syntax 表格语法
|
|
23
|
+
* @param attr 表格属性
|
|
24
|
+
*/
|
|
25
|
+
constructor(syntax: string, attr?: string, config?: Config, accum?: Token[]);
|
|
26
|
+
/** 获取下一行 */
|
|
27
|
+
getNextRow(): TrToken | undefined;
|
|
28
|
+
/** 获取前一行 */
|
|
29
|
+
getPreviousRow(): TrToken | undefined;
|
|
30
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.TrToken = void 0;
|
|
5
|
+
const trBase_1 = require("./trBase");
|
|
6
|
+
/* NOT FOR BROWSER */
|
|
7
|
+
const constants_1 = require("../../util/constants");
|
|
8
|
+
/* NOT FOR BROWSER END */
|
|
9
|
+
/**
|
|
10
|
+
* 表格行,含开头的换行,不含结尾的换行
|
|
11
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken]}`
|
|
12
|
+
*/
|
|
13
|
+
class TrToken extends trBase_1.TrBaseToken {
|
|
14
|
+
/* NOT FOR BROWSER END */
|
|
15
|
+
get type() {
|
|
16
|
+
return 'tr';
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @param syntax 表格语法
|
|
20
|
+
* @param attr 表格属性
|
|
21
|
+
*/
|
|
22
|
+
constructor(syntax, attr, config, accum) {
|
|
23
|
+
super(/^\n[^\S\n]*(?:\|-+|\{\{\s*!\s*\}\}-+|\{\{\s*!-\s*\}\}-*)$/u, syntax, 'tr', attr, config, accum, {
|
|
24
|
+
Token: 2, SyntaxToken: 0, AttributesToken: 1, TdToken: '2:',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/* NOT FOR BROWSER */
|
|
28
|
+
/** @private */
|
|
29
|
+
text() {
|
|
30
|
+
const str = super.text();
|
|
31
|
+
return str.trim().includes('\n') ? str : '';
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 获取相邻行
|
|
35
|
+
* @param subset 筛选兄弟节点的方法
|
|
36
|
+
*/
|
|
37
|
+
#getSiblingRow(subset) {
|
|
38
|
+
const { parentNode } = this;
|
|
39
|
+
if (!parentNode) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const { childNodes } = parentNode, index = childNodes.indexOf(this);
|
|
43
|
+
for (const child of subset(childNodes, index)) {
|
|
44
|
+
if (child instanceof _a && child.getRowCount()) {
|
|
45
|
+
return child;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
/** 获取下一行 */
|
|
51
|
+
getNextRow() {
|
|
52
|
+
return this.#getSiblingRow((childNodes, index) => childNodes.slice(index + 1));
|
|
53
|
+
}
|
|
54
|
+
/** 获取前一行 */
|
|
55
|
+
getPreviousRow() {
|
|
56
|
+
return this.#getSiblingRow((childNodes, index) => childNodes.slice(0, index).reverse());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.TrToken = TrToken;
|
|
60
|
+
_a = TrToken;
|
|
61
|
+
constants_1.classes['TrToken'] = __filename;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { TableBaseToken } from './base';
|
|
2
|
+
import { TdToken } from './td';
|
|
3
|
+
import type { LintError } from '../../base';
|
|
4
|
+
import type { AstNodes, SyntaxToken, TrToken } from '../../internal';
|
|
5
|
+
import { Token } from '../index';
|
|
6
|
+
import type { TdAttrs, TdSubtypes } from './td';
|
|
7
|
+
export interface TableCoords {
|
|
8
|
+
readonly row: number;
|
|
9
|
+
readonly column: number;
|
|
10
|
+
readonly x?: undefined;
|
|
11
|
+
readonly y?: undefined;
|
|
12
|
+
readonly start?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** 表格行或表格 */
|
|
15
|
+
export declare abstract class TrBaseToken extends TableBaseToken {
|
|
16
|
+
#private;
|
|
17
|
+
abstract get type(): 'table' | 'tr';
|
|
18
|
+
/** 获取行数 */
|
|
19
|
+
getRowCount(): number;
|
|
20
|
+
/**
|
|
21
|
+
* 获取第n列
|
|
22
|
+
* @param n 列号
|
|
23
|
+
* @param insert 是否用于判断插入新列的位置
|
|
24
|
+
* @throws `RangeError` 不存在对应单元格
|
|
25
|
+
*/
|
|
26
|
+
getNthCol(n: number, insert?: false): TdToken | undefined;
|
|
27
|
+
getNthCol(n: number, insert: true): TdToken | TrToken | SyntaxToken | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* @override
|
|
30
|
+
* @param i 移除位置
|
|
31
|
+
*/
|
|
32
|
+
removeAt(i: number): AstNodes;
|
|
33
|
+
/**
|
|
34
|
+
* @override
|
|
35
|
+
* @param token 待插入的子节点
|
|
36
|
+
* @param i 插入位置
|
|
37
|
+
*/
|
|
38
|
+
insertAt<T extends Token>(token: T, i?: number): T;
|
|
39
|
+
/** 获取列数 */
|
|
40
|
+
getColCount(): number;
|
|
41
|
+
/**
|
|
42
|
+
* 插入新的单元格
|
|
43
|
+
* @param inner 单元格内部wikitext
|
|
44
|
+
* @param {TableCoords} coord 单元格坐标
|
|
45
|
+
* @param subtype 单元格类型
|
|
46
|
+
* @param attr 单元格属性
|
|
47
|
+
*/
|
|
48
|
+
insertTableCell(inner: string | Token, { column }: TableCoords, subtype?: TdSubtypes, attr?: TdAttrs): TdToken;
|
|
49
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TrBaseToken = void 0;
|
|
4
|
+
const lint_1 = require("../../util/lint");
|
|
5
|
+
const base_1 = require("./base");
|
|
6
|
+
const td_1 = require("./td");
|
|
7
|
+
/* NOT FOR BROWSER */
|
|
8
|
+
const debug_1 = require("../../util/debug");
|
|
9
|
+
const constants_1 = require("../../util/constants");
|
|
10
|
+
const html_1 = require("../../util/html");
|
|
11
|
+
const debug_2 = require("../../util/debug");
|
|
12
|
+
const index_1 = require("../index");
|
|
13
|
+
/** 表格行或表格 */
|
|
14
|
+
class TrBaseToken extends base_1.TableBaseToken {
|
|
15
|
+
/** @private */
|
|
16
|
+
lint(start = this.getAbsoluteIndex(), re) {
|
|
17
|
+
const errors = super.lint(start, re), inter = this.childNodes.find(({ type }) => type === 'table-inter');
|
|
18
|
+
if (!inter) {
|
|
19
|
+
return errors;
|
|
20
|
+
}
|
|
21
|
+
const first = inter.childNodes.find(child => child.text().trim()), tdPattern = /^\s*(?:!|\{\{\s*![!-]?\s*\}\})/u;
|
|
22
|
+
if (!first
|
|
23
|
+
|| tdPattern.test(first.toString())
|
|
24
|
+
|| first.is('arg') && tdPattern.test(first.default || '')) {
|
|
25
|
+
return errors;
|
|
26
|
+
}
|
|
27
|
+
else if (first.is('magic-word')) {
|
|
28
|
+
try {
|
|
29
|
+
if (first.getPossibleValues().every(token => tdPattern.test(token.text()))) {
|
|
30
|
+
return errors;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch { }
|
|
34
|
+
}
|
|
35
|
+
const error = (0, lint_1.generateForChild)(inter, { start }, 'fostered-content', 'content to be moved out from the table');
|
|
36
|
+
error.severity = first.type === 'template' ? 'warning' : 'error';
|
|
37
|
+
error.startIndex++;
|
|
38
|
+
error.startLine++;
|
|
39
|
+
error.startCol = 0;
|
|
40
|
+
errors.push(error);
|
|
41
|
+
return errors;
|
|
42
|
+
}
|
|
43
|
+
/** 获取行数 */
|
|
44
|
+
getRowCount() {
|
|
45
|
+
return Number(this.childNodes.some(child => child instanceof td_1.TdToken && child.isIndependent() && !child.firstChild.text().endsWith('+')));
|
|
46
|
+
}
|
|
47
|
+
getNthCol(n, insert) {
|
|
48
|
+
/* NOT FOR BROWSER */
|
|
49
|
+
const nCols = this.getColCount();
|
|
50
|
+
n += n < 0 ? nCols : 0;
|
|
51
|
+
if (n < 0 || n > nCols || n === nCols && !insert) {
|
|
52
|
+
throw new RangeError(`There is no cell at position ${n}!`);
|
|
53
|
+
}
|
|
54
|
+
/* NOT FOR BROWSER END */
|
|
55
|
+
let last = 0;
|
|
56
|
+
for (const child of this.childNodes.slice(2)) {
|
|
57
|
+
if (child instanceof td_1.TdToken) {
|
|
58
|
+
if (child.isIndependent()) {
|
|
59
|
+
last = Number(child.subtype !== 'caption');
|
|
60
|
+
}
|
|
61
|
+
n -= last;
|
|
62
|
+
if (n < 0) {
|
|
63
|
+
return child;
|
|
64
|
+
}
|
|
65
|
+
/* NOT FOR BROWSER */
|
|
66
|
+
}
|
|
67
|
+
else if (child.is('tr') || child.is('table-syntax')) {
|
|
68
|
+
return child;
|
|
69
|
+
/* NOT FOR BROWSER END */
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
/* NOT FOR BROWSER */
|
|
75
|
+
/** 修复简单的表格语法错误 */
|
|
76
|
+
#correct() {
|
|
77
|
+
const { childNodes: [, , child] } = this;
|
|
78
|
+
if (child?.constructor === index_1.Token) {
|
|
79
|
+
const { firstChild } = child;
|
|
80
|
+
if (firstChild?.type !== 'text') {
|
|
81
|
+
child.prepend('\n');
|
|
82
|
+
}
|
|
83
|
+
else if (!firstChild.data.startsWith('\n')) {
|
|
84
|
+
firstChild.insertData(0, '\n');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** @private */
|
|
89
|
+
text() {
|
|
90
|
+
this.#correct();
|
|
91
|
+
return super.text();
|
|
92
|
+
}
|
|
93
|
+
/** @private */
|
|
94
|
+
toString(skip) {
|
|
95
|
+
this.#correct();
|
|
96
|
+
return super.toString(skip);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @override
|
|
100
|
+
* @param i 移除位置
|
|
101
|
+
*/
|
|
102
|
+
removeAt(i) {
|
|
103
|
+
i += i < 0 ? this.length : 0;
|
|
104
|
+
const child = this.childNodes[i];
|
|
105
|
+
if (child instanceof td_1.TdToken && child.isIndependent()) {
|
|
106
|
+
const { nextSibling } = child;
|
|
107
|
+
if (nextSibling?.type === 'td') {
|
|
108
|
+
nextSibling.independence();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return super.removeAt(i);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* @override
|
|
115
|
+
* @param token 待插入的子节点
|
|
116
|
+
* @param i 插入位置
|
|
117
|
+
*/
|
|
118
|
+
insertAt(token, i = this.length) {
|
|
119
|
+
if (!debug_1.Shadow.running && token.type !== 'td') {
|
|
120
|
+
if (this.type === 'tr') {
|
|
121
|
+
this.typeError('insertAt', 'TdToken');
|
|
122
|
+
}
|
|
123
|
+
else if (token.type !== 'tr') {
|
|
124
|
+
this.typeError('insertAt', 'TrToken', 'TdToken');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
i += i < 0 ? this.length : 0;
|
|
128
|
+
const child = this.childNodes[i];
|
|
129
|
+
if (token instanceof td_1.TdToken && token.isIndependent() && child instanceof td_1.TdToken) {
|
|
130
|
+
child.independence();
|
|
131
|
+
}
|
|
132
|
+
return super.insertAt(token, i);
|
|
133
|
+
}
|
|
134
|
+
/** 获取列数 */
|
|
135
|
+
getColCount() {
|
|
136
|
+
let count = 0, last = 0;
|
|
137
|
+
for (const child of this.childNodes) {
|
|
138
|
+
if (child instanceof td_1.TdToken) {
|
|
139
|
+
last = child.isIndependent() ? Number(child.subtype !== 'caption') : last;
|
|
140
|
+
count += last;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return count;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 插入新的单元格
|
|
147
|
+
* @param inner 单元格内部wikitext
|
|
148
|
+
* @param {TableCoords} coord 单元格坐标
|
|
149
|
+
* @param subtype 单元格类型
|
|
150
|
+
* @param attr 单元格属性
|
|
151
|
+
*/
|
|
152
|
+
insertTableCell(inner, { column }, subtype = 'td', attr = {}) {
|
|
153
|
+
const token = (0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
|
|
154
|
+
return this.insertBefore(token, this.getNthCol(column, true));
|
|
155
|
+
}
|
|
156
|
+
/** @private */
|
|
157
|
+
toHtmlInternal(nowrap) {
|
|
158
|
+
const { childNodes, type } = this, td = childNodes.filter((0, debug_2.isToken)('td'));
|
|
159
|
+
return td.some(({ subtype }) => subtype !== 'caption')
|
|
160
|
+
? `<tr${type === 'tr' ? childNodes[1].toHtmlInternal() : ''}>${(0, html_1.html)(td, '', nowrap)}</tr>`
|
|
161
|
+
: (0, html_1.html)(td, '', nowrap);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.TrBaseToken = TrBaseToken;
|
|
165
|
+
constants_1.classes['TrBaseToken'] = __filename;
|