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