wikiparser-node 1.5.0 → 1.5.1-b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/bundle/bundle.min.js +37 -0
  2. package/config/default.json +1 -1
  3. package/config/enwiki.json +2 -815
  4. package/config/llwiki.json +2 -36
  5. package/config/minimum.json +3 -6
  6. package/config/moegirl.json +1 -44
  7. package/config/zhwiki.json +2 -467
  8. package/extensions/dist/base.js +64 -0
  9. package/extensions/dist/editor.js +159 -0
  10. package/extensions/dist/highlight.js +59 -0
  11. package/extensions/dist/lint.js +60 -0
  12. package/extensions/editor.css +63 -0
  13. package/extensions/ui.css +141 -0
  14. package/package.json +27 -14
  15. package/config/.schema.json +0 -172
  16. package/dist/addon/table.d.ts +0 -6
  17. package/dist/addon/table.js +0 -564
  18. package/dist/base.d.ts +0 -70
  19. package/dist/index.d.ts +0 -30
  20. package/dist/index.js +0 -212
  21. package/dist/internal.d.ts +0 -44
  22. package/dist/lib/element.d.ts +0 -150
  23. package/dist/lib/element.js +0 -617
  24. package/dist/lib/node.d.ts +0 -146
  25. package/dist/lib/node.js +0 -428
  26. package/dist/lib/range.d.ts +0 -104
  27. package/dist/lib/range.js +0 -385
  28. package/dist/lib/ranges.d.ts +0 -26
  29. package/dist/lib/ranges.js +0 -118
  30. package/dist/lib/text.d.ts +0 -62
  31. package/dist/lib/text.js +0 -351
  32. package/dist/lib/title.d.ts +0 -38
  33. package/dist/lib/title.js +0 -164
  34. package/dist/mixin/attributesParent.d.ts +0 -50
  35. package/dist/mixin/attributesParent.js +0 -78
  36. package/dist/mixin/fixed.d.ts +0 -6
  37. package/dist/mixin/fixed.js +0 -30
  38. package/dist/mixin/flagsParent.d.ts +0 -72
  39. package/dist/mixin/flagsParent.js +0 -59
  40. package/dist/mixin/hidden.d.ts +0 -5
  41. package/dist/mixin/hidden.js +0 -24
  42. package/dist/mixin/magicLinkParent.d.ts +0 -40
  43. package/dist/mixin/magicLinkParent.js +0 -42
  44. package/dist/mixin/singleLine.d.ts +0 -6
  45. package/dist/mixin/singleLine.js +0 -26
  46. package/dist/mixin/sol.d.ts +0 -6
  47. package/dist/mixin/sol.js +0 -43
  48. package/dist/mixin/syntax.d.ts +0 -9
  49. package/dist/mixin/syntax.js +0 -50
  50. package/dist/parser/braces.js +0 -131
  51. package/dist/parser/commentAndExt.js +0 -90
  52. package/dist/parser/converter.js +0 -41
  53. package/dist/parser/externalLinks.js +0 -32
  54. package/dist/parser/hrAndDoubleUnderscore.js +0 -41
  55. package/dist/parser/html.js +0 -39
  56. package/dist/parser/links.js +0 -95
  57. package/dist/parser/list.js +0 -68
  58. package/dist/parser/magicLinks.js +0 -43
  59. package/dist/parser/quotes.js +0 -68
  60. package/dist/parser/selector.js +0 -162
  61. package/dist/parser/table.js +0 -124
  62. package/dist/src/arg.d.ts +0 -58
  63. package/dist/src/arg.js +0 -214
  64. package/dist/src/atom.d.ts +0 -12
  65. package/dist/src/atom.js +0 -27
  66. package/dist/src/attribute.d.ts +0 -69
  67. package/dist/src/attribute.js +0 -501
  68. package/dist/src/attributes.d.ts +0 -109
  69. package/dist/src/attributes.js +0 -356
  70. package/dist/src/converter.d.ts +0 -33
  71. package/dist/src/converter.js +0 -134
  72. package/dist/src/converterFlags.d.ts +0 -87
  73. package/dist/src/converterFlags.js +0 -242
  74. package/dist/src/converterRule.d.ts +0 -77
  75. package/dist/src/converterRule.js +0 -209
  76. package/dist/src/extLink.d.ts +0 -43
  77. package/dist/src/extLink.js +0 -186
  78. package/dist/src/gallery.d.ts +0 -54
  79. package/dist/src/gallery.js +0 -139
  80. package/dist/src/heading.d.ts +0 -47
  81. package/dist/src/heading.js +0 -190
  82. package/dist/src/hidden.d.ts +0 -7
  83. package/dist/src/hidden.js +0 -23
  84. package/dist/src/html.d.ts +0 -65
  85. package/dist/src/html.js +0 -358
  86. package/dist/src/imageParameter.d.ts +0 -65
  87. package/dist/src/imageParameter.js +0 -251
  88. package/dist/src/imagemap.d.ts +0 -56
  89. package/dist/src/imagemap.js +0 -150
  90. package/dist/src/imagemapLink.d.ts +0 -31
  91. package/dist/src/imagemapLink.js +0 -93
  92. package/dist/src/index.d.ts +0 -143
  93. package/dist/src/index.js +0 -813
  94. package/dist/src/link/base.d.ts +0 -52
  95. package/dist/src/link/base.js +0 -229
  96. package/dist/src/link/category.d.ts +0 -13
  97. package/dist/src/link/category.js +0 -28
  98. package/dist/src/link/file.d.ts +0 -96
  99. package/dist/src/link/file.js +0 -265
  100. package/dist/src/link/galleryImage.d.ts +0 -32
  101. package/dist/src/link/galleryImage.js +0 -157
  102. package/dist/src/link/index.d.ts +0 -56
  103. package/dist/src/link/index.js +0 -133
  104. package/dist/src/magicLink.d.ts +0 -59
  105. package/dist/src/magicLink.js +0 -223
  106. package/dist/src/nested.d.ts +0 -43
  107. package/dist/src/nested.js +0 -105
  108. package/dist/src/nowiki/base.d.ts +0 -31
  109. package/dist/src/nowiki/base.js +0 -93
  110. package/dist/src/nowiki/comment.d.ts +0 -25
  111. package/dist/src/nowiki/comment.js +0 -76
  112. package/dist/src/nowiki/dd.d.ts +0 -8
  113. package/dist/src/nowiki/dd.js +0 -24
  114. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -18
  115. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  116. package/dist/src/nowiki/hr.d.ts +0 -5
  117. package/dist/src/nowiki/hr.js +0 -63
  118. package/dist/src/nowiki/index.d.ts +0 -16
  119. package/dist/src/nowiki/index.js +0 -27
  120. package/dist/src/nowiki/list.d.ts +0 -16
  121. package/dist/src/nowiki/list.js +0 -97
  122. package/dist/src/nowiki/listBase.d.ts +0 -5
  123. package/dist/src/nowiki/listBase.js +0 -61
  124. package/dist/src/nowiki/noinclude.d.ts +0 -10
  125. package/dist/src/nowiki/noinclude.js +0 -23
  126. package/dist/src/nowiki/quote.d.ts +0 -14
  127. package/dist/src/nowiki/quote.js +0 -131
  128. package/dist/src/onlyinclude.d.ts +0 -16
  129. package/dist/src/onlyinclude.js +0 -57
  130. package/dist/src/paramTag/index.d.ts +0 -37
  131. package/dist/src/paramTag/index.js +0 -77
  132. package/dist/src/paramTag/inputbox.d.ts +0 -8
  133. package/dist/src/paramTag/inputbox.js +0 -22
  134. package/dist/src/parameter.d.ts +0 -70
  135. package/dist/src/parameter.js +0 -264
  136. package/dist/src/pre.d.ts +0 -28
  137. package/dist/src/pre.js +0 -55
  138. package/dist/src/syntax.d.ts +0 -20
  139. package/dist/src/syntax.js +0 -86
  140. package/dist/src/table/base.d.ts +0 -30
  141. package/dist/src/table/base.js +0 -132
  142. package/dist/src/table/index.d.ts +0 -233
  143. package/dist/src/table/index.js +0 -396
  144. package/dist/src/table/td.d.ts +0 -92
  145. package/dist/src/table/td.js +0 -354
  146. package/dist/src/table/tr.d.ts +0 -32
  147. package/dist/src/table/tr.js +0 -58
  148. package/dist/src/table/trBase.d.ts +0 -53
  149. package/dist/src/table/trBase.js +0 -152
  150. package/dist/src/tagPair/ext.d.ts +0 -32
  151. package/dist/src/tagPair/ext.js +0 -203
  152. package/dist/src/tagPair/include.d.ts +0 -35
  153. package/dist/src/tagPair/include.js +0 -71
  154. package/dist/src/tagPair/index.d.ts +0 -27
  155. package/dist/src/tagPair/index.js +0 -128
  156. package/dist/src/transclude.d.ts +0 -167
  157. package/dist/src/transclude.js +0 -717
  158. package/dist/util/constants.js +0 -113
  159. package/dist/util/debug.js +0 -88
  160. package/dist/util/diff.js +0 -83
  161. package/dist/util/lint.js +0 -31
  162. package/dist/util/string.js +0 -53
  163. package/errors/README +0 -1
  164. package/printed/README +0 -1
@@ -1,92 +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
- * @override
59
- * @param syntax 表格语法
60
- * @param esc 是否需要转义
61
- */
62
- setSyntax(syntax: string, esc?: boolean): void;
63
- /** 改为独占一行 */
64
- independence(): void;
65
- /**
66
- * @override
67
- * @param key 属性键
68
- */
69
- getAttr<T extends string>(key: T): TdAttrGetter<T>;
70
- /** @override */
71
- getAttrs(): TdAttrs;
72
- /**
73
- * @override
74
- * @param key 属性键
75
- * @param value 属性值
76
- * @param prop 属性对象
77
- */
78
- setAttr<T extends string>(key: T, value: TdAttrSetter<T>): void;
79
- setAttr(prop: Record<string, string | number | boolean>): void;
80
- /** @override */
81
- escape(): void;
82
- }
83
- /**
84
- * 创建新的单元格
85
- * @param inner 内部wikitext
86
- * @param subtype 单元格类型
87
- * @param attr 单元格属性
88
- * @param include 是否嵌入
89
- * @param config
90
- */
91
- export declare const createTd: (inner: string | Token, subtype?: TdSubtypes, attr?: TdAttrs, include?: boolean, config?: Parser.Config) => TdToken;
92
- export {};
@@ -1,354 +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
- /**
255
- * @override
256
- * @param syntax 表格语法
257
- * @param esc 是否需要转义
258
- */
259
- setSyntax(syntax, esc = false) {
260
- const aliases = { td: '\n|', th: '\n!', caption: '\n|+' };
261
- super.setSyntax(aliases[syntax] ?? syntax, esc);
262
- }
263
- /** 修复\<td\>语法 */
264
- #correct() {
265
- if (String(this.childNodes[1])) {
266
- this.#innerSyntax ||= '|';
267
- }
268
- const { subtype, escape, correction } = this.#getSyntax();
269
- if (correction) {
270
- this.setSyntax(subtype, escape);
271
- }
272
- }
273
- /** 改为独占一行 */
274
- independence() {
275
- if (!this.isIndependent()) {
276
- const { subtype, escape } = this.#getSyntax();
277
- this.setSyntax(subtype, escape);
278
- }
279
- }
280
- /**
281
- * @override
282
- * @param key 属性键
283
- */
284
- getAttr(key) {
285
- const value = super.getAttr(key);
286
- key = key.toLowerCase().trim();
287
- return (key === 'rowspan' || key === 'colspan' ? Number(value) || 1 : value);
288
- }
289
- /** @override */
290
- getAttrs() {
291
- const attr = super.getAttrs();
292
- if ('rowspan' in attr) {
293
- attr.rowspan = Number(attr.rowspan);
294
- }
295
- if ('colspan' in attr) {
296
- attr.colspan = Number(attr.colspan);
297
- }
298
- return attr;
299
- }
300
- setAttr(keyOrProp, value) {
301
- if (typeof keyOrProp !== 'string') {
302
- for (const [key, val] of Object.entries(keyOrProp)) {
303
- this.setAttr(key, val);
304
- }
305
- return;
306
- }
307
- const key = keyOrProp.toLowerCase().trim();
308
- let v;
309
- if (typeof value === 'number' && (key === 'rowspan' || key === 'colspan')) {
310
- v = value === 1 ? false : String(value);
311
- }
312
- else {
313
- v = value;
314
- }
315
- super.setAttr(key, v);
316
- if (!String(this.childNodes[1])) {
317
- this.#innerSyntax = '';
318
- }
319
- }
320
- /** @override */
321
- escape() {
322
- super.escape();
323
- if (String(this.childNodes[1])) {
324
- this.#innerSyntax ||= '{{!}}';
325
- }
326
- if (this.#innerSyntax === '|') {
327
- this.#innerSyntax = '{{!}}';
328
- }
329
- }
330
- };
331
- return TdToken = _classThis;
332
- })();
333
- exports.TdToken = TdToken;
334
- /* NOT FOR BROWSER */
335
- /**
336
- * 创建新的单元格
337
- * @param inner 内部wikitext
338
- * @param subtype 单元格类型
339
- * @param attr 单元格属性
340
- * @param include 是否嵌入
341
- * @param config
342
- */
343
- const createTd = (inner, subtype = 'td', attr = {}, include = false, config = index_1.default.getConfig()) => {
344
- const innerToken = typeof inner === 'string' ? index_1.default.parse(inner, include, undefined, config) : inner,
345
- // @ts-expect-error abstract class
346
- token = debug_1.Shadow.run(() => new TdToken('\n|', undefined, config));
347
- token.setSyntax(subtype);
348
- token.lastChild.safeReplaceWith(innerToken);
349
- token.setAttr(attr);
350
- return token;
351
- };
352
- exports.createTd = createTd;
353
- /* NOT FOR BROWSER END */
354
- 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
- }