wikiparser-node 1.21.2 → 1.22.0
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 +9 -5
- package/bundle/bundle-es8.min.js +25 -25
- package/bundle/bundle-lsp.min.js +26 -26
- package/bundle/bundle.min.js +25 -25
- package/config/default.json +15 -11
- package/config/enwiki.json +1 -1
- package/config/jawiki.json +1 -1
- package/config/minimum.json +2 -3
- package/config/moegirl.json +152 -15
- package/config/zhwiki.json +1 -1
- package/dist/addon/token.js +3 -0
- package/dist/base.d.mts +16 -9
- package/dist/base.d.ts +16 -9
- package/dist/bin/config.js +23 -11
- package/dist/index.d.ts +33 -4
- package/dist/index.js +37 -2
- package/dist/lib/element.d.ts +4 -4
- package/dist/lib/element.js +6 -5
- package/dist/lib/lintConfig.d.ts +13 -0
- package/dist/lib/lintConfig.js +278 -0
- package/dist/lib/lsp.d.ts +7 -7
- package/dist/lib/lsp.js +18 -20
- package/dist/lib/node.d.ts +1 -1
- package/dist/lib/node.js +646 -606
- package/dist/lib/range.d.ts +2 -2
- package/dist/lib/range.js +2 -2
- package/dist/lib/text.js +76 -62
- package/dist/lib/title.d.ts +11 -4
- package/dist/lib/title.js +16 -6
- package/dist/mixin/attributesParent.d.ts +6 -6
- package/dist/mixin/attributesParent.js +4 -4
- package/dist/mixin/cached.d.ts +5 -0
- package/dist/mixin/cached.js +22 -0
- package/dist/mixin/clone.d.ts +5 -0
- package/dist/mixin/clone.js +23 -0
- package/dist/mixin/hidden.js +68 -18
- package/dist/mixin/sol.js +1 -1
- package/dist/parser/commentAndExt.js +6 -4
- package/dist/parser/converter.js +1 -1
- package/dist/parser/html.js +3 -3
- package/dist/parser/table.js +2 -2
- package/dist/src/arg.js +24 -17
- package/dist/src/atom.js +76 -31
- package/dist/src/attribute.js +79 -39
- package/dist/src/attributes.d.ts +7 -7
- package/dist/src/attributes.js +417 -366
- package/dist/src/commented.js +81 -35
- package/dist/src/converter.js +13 -7
- package/dist/src/converterFlags.js +33 -22
- package/dist/src/converterRule.js +263 -216
- package/dist/src/extLink.js +21 -16
- package/dist/src/gallery.js +44 -27
- package/dist/src/heading.js +48 -43
- package/dist/src/hidden.js +14 -9
- package/dist/src/html.js +92 -60
- package/dist/src/imageParameter.js +13 -6
- package/dist/src/imagemap.js +32 -25
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +61 -50
- package/dist/src/link/base.d.ts +1 -1
- package/dist/src/link/base.js +35 -23
- package/dist/src/link/file.js +409 -354
- package/dist/src/link/galleryImage.js +9 -5
- package/dist/src/link/index.d.ts +1 -1
- package/dist/src/link/index.js +8 -4
- package/dist/src/link/redirectTarget.js +7 -3
- package/dist/src/magicLink.js +39 -26
- package/dist/src/nested.js +122 -74
- package/dist/src/nowiki/base.js +5 -2
- package/dist/src/nowiki/comment.js +5 -1
- package/dist/src/nowiki/index.js +4 -4
- package/dist/src/nowiki/quote.js +32 -46
- package/dist/src/onlyinclude.js +17 -9
- package/dist/src/paramTag/index.js +21 -14
- package/dist/src/parameter.js +26 -20
- package/dist/src/pre.js +91 -45
- package/dist/src/syntax.js +14 -10
- package/dist/src/table/index.js +554 -501
- package/dist/src/table/td.d.ts +1 -1
- package/dist/src/table/td.js +91 -82
- package/dist/src/table/trBase.js +183 -130
- package/dist/src/tagPair/ext.js +38 -23
- package/dist/src/tagPair/include.js +5 -5
- package/dist/src/tagPair/index.js +2 -3
- package/dist/src/tagPair/translate.js +150 -103
- package/dist/src/transclude.d.ts +15 -1
- package/dist/src/transclude.js +56 -21
- package/dist/util/html.js +46 -41
- package/dist/util/lint.js +7 -9
- package/dist/util/sharable.js +1 -1
- package/dist/util/sharable.mjs +2 -2
- package/dist/util/string.js +13 -7
- package/extensions/dist/base.js +9 -2
- package/extensions/typings.d.ts +2 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +20 -15
package/dist/src/table/td.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import Parser from '../../index';
|
|
1
2
|
import { Token } from '../index';
|
|
2
3
|
import { TableBaseToken } from './base';
|
|
3
4
|
import type { Config, LintError, AST } from '../../base';
|
|
4
5
|
import type { SyntaxToken, AttributesToken, TrToken, TableToken } from '../../internal';
|
|
5
|
-
import Parser from '../../index';
|
|
6
6
|
export type TdSubtypes = 'td' | 'th' | 'caption';
|
|
7
7
|
export interface TdSpanAttrs {
|
|
8
8
|
rowspan?: number;
|
package/dist/src/table/td.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
3
|
+
var useValue = arguments.length > 2;
|
|
4
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
5
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
6
|
+
}
|
|
7
|
+
return useValue ? value : void 0;
|
|
8
|
+
};
|
|
2
9
|
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
10
|
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
11
|
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
@@ -26,12 +33,9 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
|
|
|
26
33
|
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
34
|
done = true;
|
|
28
35
|
};
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
-
}
|
|
34
|
-
return useValue ? value : void 0;
|
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
35
39
|
};
|
|
36
40
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
41
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -41,13 +45,14 @@ exports.createTd = exports.TdToken = void 0;
|
|
|
41
45
|
const lint_1 = require("../../util/lint");
|
|
42
46
|
const constants_1 = require("../../util/constants");
|
|
43
47
|
const rect_1 = require("../../lib/rect");
|
|
44
|
-
const
|
|
48
|
+
const cached_1 = require("../../mixin/cached");
|
|
49
|
+
const index_1 = __importDefault(require("../../index"));
|
|
50
|
+
const index_2 = require("../index");
|
|
45
51
|
const base_1 = require("./base");
|
|
46
52
|
/* NOT FOR BROWSER */
|
|
47
53
|
const debug_1 = require("../../util/debug");
|
|
48
54
|
const string_1 = require("../../util/string");
|
|
49
55
|
const fixed_1 = require("../../mixin/fixed");
|
|
50
|
-
const index_2 = __importDefault(require("../../index"));
|
|
51
56
|
/* NOT FOR BROWSER END */
|
|
52
57
|
/**
|
|
53
58
|
* `<td>`, `<th>` or `<caption>`
|
|
@@ -56,23 +61,73 @@ const index_2 = __importDefault(require("../../index"));
|
|
|
56
61
|
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, Token]}`
|
|
57
62
|
*/
|
|
58
63
|
let TdToken = (() => {
|
|
59
|
-
var _a;
|
|
60
64
|
let _classDecorators = [fixed_1.fixedToken];
|
|
61
65
|
let _classDescriptor;
|
|
62
66
|
let _classExtraInitializers = [];
|
|
63
67
|
let _classThis;
|
|
64
68
|
let _classSuper = base_1.TableBaseToken;
|
|
69
|
+
let _instanceExtraInitializers = [];
|
|
70
|
+
let _private_getSyntax_decorators;
|
|
71
|
+
let _private_getSyntax_descriptor;
|
|
72
|
+
let _toHtmlInternal_decorators;
|
|
65
73
|
var TdToken = class extends _classSuper {
|
|
66
74
|
static { _classThis = this; }
|
|
67
75
|
static {
|
|
68
76
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
77
|
+
_private_getSyntax_decorators = [(0, cached_1.cached)(false)];
|
|
78
|
+
_toHtmlInternal_decorators = [(0, cached_1.cached)()];
|
|
79
|
+
__esDecorate(this, _private_getSyntax_descriptor = { value: __setFunctionName(function () {
|
|
80
|
+
const syntax = this.firstChild.text(),
|
|
81
|
+
/* NOT FOR BROWSER */
|
|
82
|
+
esc = syntax.includes('{{'),
|
|
83
|
+
/* NOT FOR BROWSER END */
|
|
84
|
+
char = syntax.slice(-1);
|
|
85
|
+
let subtype = 'td';
|
|
86
|
+
if (char === '!') {
|
|
87
|
+
subtype = 'th';
|
|
88
|
+
}
|
|
89
|
+
else if (char === '+') {
|
|
90
|
+
subtype = 'caption';
|
|
91
|
+
}
|
|
92
|
+
if (this.isIndependent()) {
|
|
93
|
+
return {
|
|
94
|
+
subtype,
|
|
95
|
+
/* NOT FOR BROWSER */
|
|
96
|
+
escape: esc,
|
|
97
|
+
correction: false,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const { previousSibling } = this;
|
|
101
|
+
/* NOT FOR BROWSER */
|
|
102
|
+
if (!(previousSibling instanceof TdToken)) {
|
|
103
|
+
return { subtype, escape: esc, correction: true };
|
|
104
|
+
}
|
|
105
|
+
/* NOT FOR BROWSER END */
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
107
|
+
const result = { ...previousSibling.#getSyntax() };
|
|
108
|
+
/* NOT FOR BROWSER */
|
|
109
|
+
const str = previousSibling.lastChild.toString();
|
|
110
|
+
result.escape ||= esc;
|
|
111
|
+
result.correction = str.includes('\n') && debug_1.Shadow.run(() => new index_2.Token(str, this.getAttribute('config'))
|
|
112
|
+
.parseOnce(0, this.getAttribute('include'))
|
|
113
|
+
.parseOnce()
|
|
114
|
+
.parseOnce()
|
|
115
|
+
.toString()
|
|
116
|
+
.includes('\n'));
|
|
117
|
+
if (subtype === 'th' && result.subtype !== 'th') {
|
|
118
|
+
result.subtype = 'th';
|
|
119
|
+
result.correction = true;
|
|
120
|
+
}
|
|
121
|
+
/* NOT FOR BROWSER END */
|
|
122
|
+
return result;
|
|
123
|
+
}, "#getSyntax") }, _private_getSyntax_decorators, { kind: "method", name: "#getSyntax", static: false, private: true, access: { has: obj => #getSyntax in obj, get: obj => obj.#getSyntax }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
124
|
+
__esDecorate(this, null, _toHtmlInternal_decorators, { kind: "method", name: "toHtmlInternal", static: false, private: false, access: { has: obj => "toHtmlInternal" in obj, get: obj => obj.toHtmlInternal }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
69
125
|
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
70
126
|
TdToken = _classThis = _classDescriptor.value;
|
|
71
127
|
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
72
128
|
__runInitializers(_classThis, _classExtraInitializers);
|
|
73
129
|
}
|
|
74
|
-
#innerSyntax = '';
|
|
75
|
-
#syntax;
|
|
130
|
+
#innerSyntax = (__runInitializers(this, _instanceExtraInitializers), '');
|
|
76
131
|
/* NOT FOR BROWSER END */
|
|
77
132
|
get type() {
|
|
78
133
|
return 'td';
|
|
@@ -104,7 +159,7 @@ let TdToken = (() => {
|
|
|
104
159
|
return this.lastChild.text().trim();
|
|
105
160
|
}
|
|
106
161
|
set innerText(text) {
|
|
107
|
-
this.lastChild.replaceChildren(...
|
|
162
|
+
this.lastChild.replaceChildren(...index_1.default.parse(text, true, undefined, this.getAttribute('config')).childNodes);
|
|
108
163
|
}
|
|
109
164
|
/* NOT FOR BROWSER END */
|
|
110
165
|
/**
|
|
@@ -121,61 +176,13 @@ let TdToken = (() => {
|
|
|
121
176
|
if (innerSyntax) {
|
|
122
177
|
[this.#innerSyntax] = innerSyntax;
|
|
123
178
|
}
|
|
124
|
-
const innerToken = new
|
|
179
|
+
const innerToken = new index_2.Token(inner?.slice((innerSyntax?.index ?? NaN) + this.#innerSyntax.length), config, accum);
|
|
125
180
|
innerToken.type = 'td-inner';
|
|
126
181
|
innerToken.setAttribute('stage', 4);
|
|
127
182
|
this.insertAt(innerToken);
|
|
128
183
|
}
|
|
129
184
|
/** 表格语法信息 */
|
|
130
|
-
#getSyntax() {
|
|
131
|
-
return (0, lint_1.cache)(this.#syntax, () => {
|
|
132
|
-
const syntax = this.firstChild.text(),
|
|
133
|
-
/* NOT FOR BROWSER */
|
|
134
|
-
esc = syntax.includes('{{'),
|
|
135
|
-
/* NOT FOR BROWSER END */
|
|
136
|
-
char = syntax.slice(-1);
|
|
137
|
-
let subtype = 'td';
|
|
138
|
-
if (char === '!') {
|
|
139
|
-
subtype = 'th';
|
|
140
|
-
}
|
|
141
|
-
else if (char === '+') {
|
|
142
|
-
subtype = 'caption';
|
|
143
|
-
}
|
|
144
|
-
if (this.isIndependent()) {
|
|
145
|
-
return {
|
|
146
|
-
subtype,
|
|
147
|
-
/* NOT FOR BROWSER */
|
|
148
|
-
escape: esc,
|
|
149
|
-
correction: false,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
const { previousSibling } = this;
|
|
153
|
-
/* NOT FOR BROWSER */
|
|
154
|
-
if (!(previousSibling instanceof TdToken)) {
|
|
155
|
-
return { subtype, escape: esc, correction: true };
|
|
156
|
-
}
|
|
157
|
-
/* NOT FOR BROWSER END */
|
|
158
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
159
|
-
const result = { ...previousSibling.#getSyntax() };
|
|
160
|
-
/* NOT FOR BROWSER */
|
|
161
|
-
const str = previousSibling.lastChild.toString();
|
|
162
|
-
result.escape ||= esc;
|
|
163
|
-
result.correction = str.includes('\n') && debug_1.Shadow.run(() => new index_1.Token(str, this.getAttribute('config'))
|
|
164
|
-
.parseOnce(0, this.getAttribute('include'))
|
|
165
|
-
.parseOnce()
|
|
166
|
-
.parseOnce()
|
|
167
|
-
.toString()
|
|
168
|
-
.includes('\n'));
|
|
169
|
-
if (subtype === 'th' && result.subtype !== 'th') {
|
|
170
|
-
result.subtype = 'th';
|
|
171
|
-
result.correction = true;
|
|
172
|
-
}
|
|
173
|
-
/* NOT FOR BROWSER END */
|
|
174
|
-
return result;
|
|
175
|
-
}, value => {
|
|
176
|
-
this.#syntax = value;
|
|
177
|
-
});
|
|
178
|
-
}
|
|
185
|
+
get #getSyntax() { return _private_getSyntax_descriptor.value; }
|
|
179
186
|
/** @private */
|
|
180
187
|
afterBuild() {
|
|
181
188
|
if (this.#innerSyntax.includes('\0')) {
|
|
@@ -211,30 +218,33 @@ let TdToken = (() => {
|
|
|
211
218
|
}
|
|
212
219
|
/** @private */
|
|
213
220
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
214
|
-
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start + this.getRelativeIndex(this.length - 1));
|
|
221
|
+
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start + this.getRelativeIndex(this.length - 1)), rule = 'pipe-like', severities = ['td', 'double'].map(key => index_1.default.lintConfig.getSeverity(rule, key));
|
|
215
222
|
for (const child of this.lastChild.childNodes) {
|
|
216
223
|
if (child.type === 'text') {
|
|
217
224
|
const { data } = child;
|
|
218
225
|
if (data.includes('|')) {
|
|
219
|
-
const
|
|
220
|
-
if (
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
e.suggestions = [
|
|
230
|
-
{
|
|
231
|
-
desc: 'escape',
|
|
226
|
+
const double = data.includes('||'), s = severities[double ? 1 : 0];
|
|
227
|
+
if (s) {
|
|
228
|
+
const e = (0, lint_1.generateForChild)(child, rect, rule, 'additional "|" in a table cell', s);
|
|
229
|
+
if (double) {
|
|
230
|
+
const syntax = { caption: '|+', td: '|', th: '!' }[this.subtype];
|
|
231
|
+
e.fix = {
|
|
232
|
+
desc: 'newline',
|
|
232
233
|
range: [e.startIndex, e.endIndex],
|
|
233
|
-
text: data.replace(
|
|
234
|
-
}
|
|
235
|
-
|
|
234
|
+
text: data.replace(/\|\|/gu, `\n${syntax}`),
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
e.suggestions = [
|
|
239
|
+
{
|
|
240
|
+
desc: 'escape',
|
|
241
|
+
range: [e.startIndex, e.endIndex],
|
|
242
|
+
text: data.replace(/\|/gu, '|'),
|
|
243
|
+
},
|
|
244
|
+
];
|
|
245
|
+
}
|
|
246
|
+
errors.push(e);
|
|
236
247
|
}
|
|
237
|
-
errors.push(e);
|
|
238
248
|
}
|
|
239
249
|
}
|
|
240
250
|
}
|
|
@@ -367,7 +377,7 @@ exports.TdToken = TdToken;
|
|
|
367
377
|
* @param config
|
|
368
378
|
*/
|
|
369
379
|
const createTd = (inner, subtype = 'td', attr = {}, include, config) => {
|
|
370
|
-
const innerToken = typeof inner === 'string' ?
|
|
380
|
+
const innerToken = typeof inner === 'string' ? index_1.default.parse(inner, include, undefined, config) : inner,
|
|
371
381
|
// @ts-expect-error abstract class
|
|
372
382
|
token = debug_1.Shadow.run(() => new TdToken('\n|', undefined, config));
|
|
373
383
|
token.setSyntax(subtype);
|
|
@@ -376,5 +386,4 @@ const createTd = (inner, subtype = 'td', attr = {}, include, config) => {
|
|
|
376
386
|
return token;
|
|
377
387
|
};
|
|
378
388
|
exports.createTd = createTd;
|
|
379
|
-
/* NOT FOR BROWSER END */
|
|
380
389
|
constants_1.classes['TdToken'] = __filename;
|
package/dist/src/table/trBase.js
CHANGED
|
@@ -1,165 +1,218 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
3
|
+
var useValue = arguments.length > 2;
|
|
4
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
5
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
6
|
+
}
|
|
7
|
+
return useValue ? value : void 0;
|
|
8
|
+
};
|
|
9
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
+
var _, done = false;
|
|
15
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
+
var context = {};
|
|
17
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
+
if (kind === "accessor") {
|
|
22
|
+
if (result === void 0) continue;
|
|
23
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
27
|
+
}
|
|
28
|
+
else if (_ = accept(result)) {
|
|
29
|
+
if (kind === "field") initializers.unshift(_);
|
|
30
|
+
else descriptor[key] = _;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
+
done = true;
|
|
35
|
+
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
2
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
40
|
exports.TrBaseToken = void 0;
|
|
4
41
|
const lint_1 = require("../../util/lint");
|
|
42
|
+
const index_1 = __importDefault(require("../../index"));
|
|
5
43
|
const base_1 = require("./base");
|
|
6
44
|
const td_1 = require("./td");
|
|
7
45
|
/* NOT FOR BROWSER */
|
|
8
46
|
const debug_1 = require("../../util/debug");
|
|
9
47
|
const constants_1 = require("../../util/constants");
|
|
10
48
|
const html_1 = require("../../util/html");
|
|
11
|
-
const
|
|
49
|
+
const cached_1 = require("../../mixin/cached");
|
|
50
|
+
const index_2 = require("../index");
|
|
12
51
|
/**
|
|
13
52
|
* table row or table
|
|
14
53
|
*
|
|
15
54
|
* 表格行或表格
|
|
16
55
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
56
|
+
let TrBaseToken = (() => {
|
|
57
|
+
let _classSuper = base_1.TableBaseToken;
|
|
58
|
+
let _instanceExtraInitializers = [];
|
|
59
|
+
let _toHtmlInternal_decorators;
|
|
60
|
+
return class TrBaseToken extends _classSuper {
|
|
61
|
+
static {
|
|
62
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
63
|
+
_toHtmlInternal_decorators = [(0, cached_1.cached)()];
|
|
64
|
+
__esDecorate(this, null, _toHtmlInternal_decorators, { kind: "method", name: "toHtmlInternal", static: false, private: false, access: { has: obj => "toHtmlInternal" in obj, get: obj => obj.toHtmlInternal }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
65
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
23
66
|
}
|
|
24
|
-
|
|
25
|
-
|
|
67
|
+
/** @private */
|
|
68
|
+
lint(start = this.getAbsoluteIndex(), re) {
|
|
69
|
+
const errors = super.lint(start, re), inter = this.childNodes.find(({ type }) => type === 'table-inter');
|
|
70
|
+
if (!inter) {
|
|
71
|
+
return errors;
|
|
72
|
+
}
|
|
73
|
+
const severity = (0, lint_1.isFostered)(inter), rule = 'fostered-content', s = severity && index_1.default.lintConfig.getSeverity(rule, severity === 2 ? undefined : 'transclusion');
|
|
74
|
+
if (s) {
|
|
75
|
+
const error = (0, lint_1.generateForChild)(inter, { start }, rule, 'content to be moved outside the table', s);
|
|
76
|
+
error.startIndex++;
|
|
77
|
+
error.startLine++;
|
|
78
|
+
error.startCol = 0;
|
|
79
|
+
errors.push(error);
|
|
80
|
+
}
|
|
26
81
|
return errors;
|
|
27
82
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*
|
|
38
|
-
* 获取行数
|
|
39
|
-
*/
|
|
40
|
-
getRowCount() {
|
|
41
|
-
return Number(this.childNodes.some(child => child instanceof td_1.TdToken
|
|
42
|
-
&& child.isIndependent()
|
|
43
|
-
&& !child.firstChild.text().endsWith('+')));
|
|
44
|
-
}
|
|
45
|
-
getNthCol(n, insert) {
|
|
46
|
-
const nCols = this.getColCount();
|
|
47
|
-
n += n < 0 ? nCols : 0;
|
|
48
|
-
/* istanbul ignore if */
|
|
49
|
-
if (n < 0 || n > nCols || n === nCols && !insert) {
|
|
50
|
-
throw new RangeError(`There is no cell at position ${n}!`);
|
|
83
|
+
/**
|
|
84
|
+
* Get the number of rows
|
|
85
|
+
*
|
|
86
|
+
* 获取行数
|
|
87
|
+
*/
|
|
88
|
+
getRowCount() {
|
|
89
|
+
return Number(this.childNodes.some(child => child instanceof td_1.TdToken
|
|
90
|
+
&& child.isIndependent()
|
|
91
|
+
&& !child.firstChild.text().endsWith('+')));
|
|
51
92
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
93
|
+
getNthCol(n, insert) {
|
|
94
|
+
const nCols = this.getColCount();
|
|
95
|
+
n += n < 0 ? nCols : 0;
|
|
96
|
+
/* istanbul ignore if */
|
|
97
|
+
if (n < 0 || n > nCols || n === nCols && !insert) {
|
|
98
|
+
throw new RangeError(`There is no cell at position ${n}!`);
|
|
99
|
+
}
|
|
100
|
+
let last = 0;
|
|
101
|
+
for (const child of this.childNodes.slice(2)) {
|
|
102
|
+
if (child instanceof td_1.TdToken) {
|
|
103
|
+
if (child.isIndependent()) {
|
|
104
|
+
last = Number(child.subtype !== 'caption');
|
|
105
|
+
}
|
|
106
|
+
n -= last;
|
|
107
|
+
if (n < 0) {
|
|
108
|
+
return child;
|
|
109
|
+
}
|
|
57
110
|
}
|
|
58
|
-
|
|
59
|
-
if (n < 0) {
|
|
111
|
+
else if (child.is('tr') || child.is('table-syntax')) {
|
|
60
112
|
return child;
|
|
61
113
|
}
|
|
62
114
|
}
|
|
63
|
-
|
|
64
|
-
return child;
|
|
65
|
-
}
|
|
115
|
+
return undefined;
|
|
66
116
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
firstChild.insertData(0, '\n');
|
|
117
|
+
/** 修复简单的表格语法错误 */
|
|
118
|
+
#correct() {
|
|
119
|
+
const { childNodes: [, , child] } = this;
|
|
120
|
+
if (child?.constructor === index_2.Token) {
|
|
121
|
+
const { firstChild } = child;
|
|
122
|
+
if (firstChild?.type !== 'text') {
|
|
123
|
+
child.prepend('\n');
|
|
124
|
+
}
|
|
125
|
+
else if (!firstChild.data.startsWith('\n')) {
|
|
126
|
+
firstChild.insertData(0, '\n');
|
|
127
|
+
}
|
|
79
128
|
}
|
|
80
129
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
130
|
+
/** @private */
|
|
131
|
+
text() {
|
|
132
|
+
this.#correct();
|
|
133
|
+
return super.text();
|
|
134
|
+
}
|
|
135
|
+
/** @private */
|
|
136
|
+
toString(skip) {
|
|
137
|
+
this.#correct();
|
|
138
|
+
return super.toString(skip);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* @override
|
|
142
|
+
* @param i position of the child node / 移除位置
|
|
143
|
+
*/
|
|
144
|
+
removeAt(i) {
|
|
145
|
+
i += i < 0 ? this.length : 0;
|
|
146
|
+
const child = this.childNodes[i];
|
|
147
|
+
if (child instanceof td_1.TdToken && child.isIndependent()) {
|
|
148
|
+
const { nextSibling } = child;
|
|
149
|
+
if (nextSibling?.is('td')) {
|
|
150
|
+
nextSibling.independence();
|
|
151
|
+
}
|
|
103
152
|
}
|
|
153
|
+
return super.removeAt(i);
|
|
104
154
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
155
|
+
/**
|
|
156
|
+
* @override
|
|
157
|
+
* @param token node to be inserted / 待插入的子节点
|
|
158
|
+
* @param i position to be inserted at / 插入位置
|
|
159
|
+
*/
|
|
160
|
+
insertAt(token, i = this.length) {
|
|
161
|
+
if (!debug_1.Shadow.running && !token.is('td')) {
|
|
162
|
+
/* istanbul ignore next */
|
|
163
|
+
if (this.is('tr')) {
|
|
164
|
+
this.typeError('insertAt', 'TdToken');
|
|
165
|
+
}
|
|
166
|
+
else if (!token.is('tr')) {
|
|
167
|
+
this.typeError('insertAt', 'TrToken', 'TdToken');
|
|
168
|
+
}
|
|
117
169
|
}
|
|
118
|
-
|
|
119
|
-
|
|
170
|
+
i += i < 0 ? this.length : 0;
|
|
171
|
+
const child = this.childNodes[i];
|
|
172
|
+
if (token instanceof td_1.TdToken && token.isIndependent() && child instanceof td_1.TdToken) {
|
|
173
|
+
child.independence();
|
|
120
174
|
}
|
|
175
|
+
return super.insertAt(token, i);
|
|
121
176
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
getColCount() {
|
|
135
|
-
let count = 0, last = 0;
|
|
136
|
-
for (const child of this.childNodes) {
|
|
137
|
-
if (child instanceof td_1.TdToken) {
|
|
138
|
-
last = child.isIndependent() ? Number(child.subtype !== 'caption') : last;
|
|
139
|
-
count += last;
|
|
177
|
+
/**
|
|
178
|
+
* Get the number of columns
|
|
179
|
+
*
|
|
180
|
+
* 获取列数
|
|
181
|
+
*/
|
|
182
|
+
getColCount() {
|
|
183
|
+
let count = 0, last = 0;
|
|
184
|
+
for (const child of this.childNodes) {
|
|
185
|
+
if (child instanceof td_1.TdToken) {
|
|
186
|
+
last = child.isIndependent() ? Number(child.subtype !== 'caption') : last;
|
|
187
|
+
count += last;
|
|
188
|
+
}
|
|
140
189
|
}
|
|
190
|
+
return count;
|
|
141
191
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
192
|
+
/**
|
|
193
|
+
* Insert a new cell
|
|
194
|
+
*
|
|
195
|
+
* 插入新的单元格
|
|
196
|
+
* @param inner inner wikitext of the cell / 单元格内部wikitext
|
|
197
|
+
* @param {TableCoords} coord table coordinates of the cell / 单元格坐标
|
|
198
|
+
* @param subtype cell type / 单元格类型
|
|
199
|
+
* @param attr cell attribute / 单元格属性
|
|
200
|
+
*/
|
|
201
|
+
insertTableCell(inner, { column }, subtype = 'td', attr = {}) {
|
|
202
|
+
return this.insertBefore((0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config')), this.getNthCol(column, true));
|
|
203
|
+
}
|
|
204
|
+
/** @private */
|
|
205
|
+
toHtmlInternal(opt) {
|
|
206
|
+
const { childNodes, type } = this, td = childNodes.filter((0, debug_1.isToken)('td'));
|
|
207
|
+
return td.some(({ subtype }) => subtype !== 'caption')
|
|
208
|
+
? `<tr${type === 'tr' ? childNodes[1].toHtmlInternal() : ''}>${(0, html_1.html)(td, '', opt)}</tr>`
|
|
209
|
+
: (0, html_1.html)(td, '', opt);
|
|
210
|
+
}
|
|
211
|
+
constructor() {
|
|
212
|
+
super(...arguments);
|
|
213
|
+
__runInitializers(this, _instanceExtraInitializers);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
})();
|
|
164
217
|
exports.TrBaseToken = TrBaseToken;
|
|
165
218
|
constants_1.classes['TrBaseToken'] = __filename;
|