wikiparser-node 1.1.5 → 1.1.6-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 (154) hide show
  1. package/bundle/bundle.min.js +36 -0
  2. package/config/llwiki.json +1 -35
  3. package/config/moegirl.json +1 -44
  4. package/config/zhwiki.json +1 -466
  5. package/extensions/dist/base.js +68 -0
  6. package/extensions/dist/editor.js +159 -0
  7. package/extensions/dist/highlight.js +30 -0
  8. package/extensions/dist/lint.js +48 -0
  9. package/extensions/editor.css +63 -0
  10. package/extensions/ui.css +119 -0
  11. package/package.json +35 -15
  12. package/config/.schema.json +0 -172
  13. package/dist/addon/table.d.ts +0 -6
  14. package/dist/addon/table.js +0 -559
  15. package/dist/base.d.ts +0 -45
  16. package/dist/bin/toc.js +0 -18
  17. package/dist/index.d.ts +0 -31
  18. package/dist/index.js +0 -210
  19. package/dist/internal.d.ts +0 -44
  20. package/dist/lib/element.d.ts +0 -155
  21. package/dist/lib/element.js +0 -660
  22. package/dist/lib/node.d.ts +0 -146
  23. package/dist/lib/node.js +0 -419
  24. package/dist/lib/range.d.ts +0 -104
  25. package/dist/lib/range.js +0 -386
  26. package/dist/lib/ranges.d.ts +0 -26
  27. package/dist/lib/ranges.js +0 -117
  28. package/dist/lib/text.d.ts +0 -62
  29. package/dist/lib/text.js +0 -235
  30. package/dist/lib/title.d.ts +0 -38
  31. package/dist/lib/title.js +0 -162
  32. package/dist/mixin/attributesParent.js +0 -94
  33. package/dist/mixin/fixed.js +0 -32
  34. package/dist/mixin/flagsParent.js +0 -70
  35. package/dist/mixin/hidden.js +0 -22
  36. package/dist/mixin/magicLinkParent.js +0 -41
  37. package/dist/mixin/singleLine.js +0 -25
  38. package/dist/mixin/sol.js +0 -43
  39. package/dist/mixin/syntax.js +0 -56
  40. package/dist/parser/braces.js +0 -123
  41. package/dist/parser/commentAndExt.js +0 -69
  42. package/dist/parser/converter.js +0 -40
  43. package/dist/parser/externalLinks.js +0 -28
  44. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  45. package/dist/parser/html.js +0 -36
  46. package/dist/parser/links.js +0 -94
  47. package/dist/parser/list.js +0 -59
  48. package/dist/parser/magicLinks.js +0 -40
  49. package/dist/parser/quotes.js +0 -67
  50. package/dist/parser/selector.js +0 -163
  51. package/dist/parser/table.js +0 -110
  52. package/dist/src/arg.d.ts +0 -58
  53. package/dist/src/arg.js +0 -190
  54. package/dist/src/atom.d.ts +0 -12
  55. package/dist/src/atom.js +0 -27
  56. package/dist/src/attribute.d.ts +0 -86
  57. package/dist/src/attribute.js +0 -392
  58. package/dist/src/attributes.d.ts +0 -106
  59. package/dist/src/attributes.js +0 -338
  60. package/dist/src/converter.d.ts +0 -51
  61. package/dist/src/converter.js +0 -79
  62. package/dist/src/converterFlags.d.ts +0 -87
  63. package/dist/src/converterFlags.js +0 -223
  64. package/dist/src/converterRule.d.ts +0 -81
  65. package/dist/src/converterRule.js +0 -212
  66. package/dist/src/extLink.d.ts +0 -53
  67. package/dist/src/extLink.js +0 -121
  68. package/dist/src/gallery.d.ts +0 -55
  69. package/dist/src/gallery.js +0 -129
  70. package/dist/src/heading.d.ts +0 -72
  71. package/dist/src/heading.js +0 -128
  72. package/dist/src/hidden.d.ts +0 -21
  73. package/dist/src/hidden.js +0 -23
  74. package/dist/src/html.d.ts +0 -104
  75. package/dist/src/html.js +0 -231
  76. package/dist/src/imageParameter.d.ts +0 -66
  77. package/dist/src/imageParameter.js +0 -246
  78. package/dist/src/imagemap.d.ts +0 -57
  79. package/dist/src/imagemap.js +0 -148
  80. package/dist/src/imagemapLink.d.ts +0 -57
  81. package/dist/src/imagemapLink.js +0 -40
  82. package/dist/src/index.d.ts +0 -145
  83. package/dist/src/index.js +0 -777
  84. package/dist/src/link/base.d.ts +0 -52
  85. package/dist/src/link/base.js +0 -207
  86. package/dist/src/link/category.d.ts +0 -13
  87. package/dist/src/link/category.js +0 -29
  88. package/dist/src/link/file.d.ts +0 -96
  89. package/dist/src/link/file.js +0 -253
  90. package/dist/src/link/galleryImage.d.ts +0 -43
  91. package/dist/src/link/galleryImage.js +0 -106
  92. package/dist/src/link/index.d.ts +0 -53
  93. package/dist/src/link/index.js +0 -123
  94. package/dist/src/magicLink.d.ts +0 -69
  95. package/dist/src/magicLink.js +0 -148
  96. package/dist/src/nested.d.ts +0 -44
  97. package/dist/src/nested.js +0 -87
  98. package/dist/src/nowiki/base.d.ts +0 -46
  99. package/dist/src/nowiki/base.js +0 -42
  100. package/dist/src/nowiki/comment.d.ts +0 -39
  101. package/dist/src/nowiki/comment.js +0 -67
  102. package/dist/src/nowiki/dd.d.ts +0 -8
  103. package/dist/src/nowiki/dd.js +0 -25
  104. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -43
  105. package/dist/src/nowiki/doubleUnderscore.js +0 -51
  106. package/dist/src/nowiki/hr.d.ts +0 -29
  107. package/dist/src/nowiki/hr.js +0 -14
  108. package/dist/src/nowiki/index.d.ts +0 -16
  109. package/dist/src/nowiki/index.js +0 -21
  110. package/dist/src/nowiki/list.d.ts +0 -29
  111. package/dist/src/nowiki/list.js +0 -48
  112. package/dist/src/nowiki/listBase.d.ts +0 -18
  113. package/dist/src/nowiki/listBase.js +0 -12
  114. package/dist/src/nowiki/noinclude.d.ts +0 -25
  115. package/dist/src/nowiki/noinclude.js +0 -25
  116. package/dist/src/nowiki/quote.d.ts +0 -22
  117. package/dist/src/nowiki/quote.js +0 -50
  118. package/dist/src/onlyinclude.d.ts +0 -16
  119. package/dist/src/onlyinclude.js +0 -57
  120. package/dist/src/paramTag/index.d.ts +0 -37
  121. package/dist/src/paramTag/index.js +0 -68
  122. package/dist/src/paramTag/inputbox.d.ts +0 -8
  123. package/dist/src/paramTag/inputbox.js +0 -23
  124. package/dist/src/parameter.d.ts +0 -84
  125. package/dist/src/parameter.js +0 -206
  126. package/dist/src/pre.d.ts +0 -28
  127. package/dist/src/pre.js +0 -51
  128. package/dist/src/syntax.d.ts +0 -25
  129. package/dist/src/syntax.js +0 -30
  130. package/dist/src/table/base.d.ts +0 -52
  131. package/dist/src/table/base.js +0 -78
  132. package/dist/src/table/index.d.ts +0 -229
  133. package/dist/src/table/index.js +0 -379
  134. package/dist/src/table/td.d.ts +0 -102
  135. package/dist/src/table/td.js +0 -261
  136. package/dist/src/table/tr.d.ts +0 -32
  137. package/dist/src/table/tr.js +0 -56
  138. package/dist/src/table/trBase.d.ts +0 -54
  139. package/dist/src/table/trBase.js +0 -151
  140. package/dist/src/tagPair/ext.d.ts +0 -55
  141. package/dist/src/tagPair/ext.js +0 -142
  142. package/dist/src/tagPair/include.d.ts +0 -52
  143. package/dist/src/tagPair/include.js +0 -58
  144. package/dist/src/tagPair/index.d.ts +0 -47
  145. package/dist/src/tagPair/index.js +0 -93
  146. package/dist/src/transclude.d.ts +0 -167
  147. package/dist/src/transclude.js +0 -689
  148. package/dist/util/constants.js +0 -107
  149. package/dist/util/debug.js +0 -64
  150. package/dist/util/diff.js +0 -72
  151. package/dist/util/lint.js +0 -48
  152. package/dist/util/string.js +0 -61
  153. package/errors/README +0 -1
  154. package/printed/README +0 -1
@@ -1,102 +0,0 @@
1
- import * as Parser from '../../index';
2
- import { Token } from '../index';
3
- import { TableBaseToken } from './base';
4
- import type { LintError } from '../../base';
5
- import type { SyntaxToken, AttributesToken, TrToken, TableToken } from '../../internal';
6
- export type TdSubtypes = 'td' | 'th' | 'caption';
7
- declare type TdAttrGetter<T extends string> = T extends 'rowspan' | 'colspan' ? number : string | true | undefined;
8
- declare type TdAttrSetter<T extends string> = T extends 'rowspan' | 'colspan' ? number : string | boolean;
9
- export type TdAttrs = Record<string, string | true> & {
10
- rowspan?: number;
11
- colspan?: number;
12
- };
13
- declare const TdToken_base: ((abstract new (...args: any[]) => {
14
- removeAt(): never;
15
- insertAt(token: string, i?: number | undefined): Parser.AstText;
16
- insertAt<T extends Parser.AstNodes>(token: T, i?: number | undefined): T;
17
- length: number;
18
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
19
- text(separator?: string | undefined): string;
20
- afterBuild(): void;
21
- getAttribute<T_1 extends string>(key: T_1): TokenAttributeGetter<T_1>;
22
- setAttribute<T_2 extends string>(key: T_2, value: TokenAttributeSetter<T_2>): void;
23
- addEventListener(events: string | string[], listener: AstListener): void;
24
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
25
- }) & {
26
- readonly fixed: true;
27
- }) & typeof TableBaseToken;
28
- /**
29
- * `<td>`、`<th>`和`<caption>`
30
- * @classdesc `{childNodes: [SyntaxToken, AttributesToken, Token]}`
31
- */
32
- export declare class TdToken extends TdToken_base {
33
- #private;
34
- readonly type = "td";
35
- childNodes: [SyntaxToken, AttributesToken, Token];
36
- abstract get children(): [SyntaxToken, AttributesToken, Token];
37
- abstract get parentNode(): TrToken | TableToken | undefined;
38
- abstract get parentElement(): TrToken | TableToken | undefined;
39
- abstract get nextSibling(): this | TrToken | SyntaxToken | undefined;
40
- abstract get nextElementSibling(): this | TrToken | SyntaxToken | undefined;
41
- abstract get previousSibling(): Token | undefined;
42
- /** 单元格类型 */
43
- get subtype(): TdSubtypes;
44
- set subtype(subtype: TdSubtypes);
45
- /** rowspan */
46
- get rowspan(): number;
47
- set rowspan(rowspan: number);
48
- /** colspan */
49
- get colspan(): number;
50
- set colspan(colspan: number);
51
- /** 内部wikitext */
52
- get innerText(): string;
53
- set innerText(text: string);
54
- /**
55
- * @param syntax 单元格语法
56
- * @param inner 内部wikitext
57
- */
58
- constructor(syntax: string, inner?: string, config?: Parser.Config, accum?: Token[]);
59
- /** @override */
60
- text(): string;
61
- /** @override */
62
- lint(start?: number): LintError[];
63
- /** @override */
64
- print(): string;
65
- /** 是否位于行首 */
66
- isIndependent(): boolean;
67
- /** @override */
68
- cloneNode(): this;
69
- /**
70
- * @override
71
- * @param syntax 表格语法
72
- * @param esc 是否需要转义
73
- */
74
- setSyntax(syntax: string, esc?: boolean): void;
75
- /** 改为独占一行 */
76
- independence(): void;
77
- /**
78
- * @override
79
- * @param key 属性键
80
- */
81
- getAttr<T extends string>(key: T): TdAttrGetter<T>;
82
- /** @override */
83
- getAttrs(): TdAttrs;
84
- /**
85
- * @override
86
- * @param key 属性键
87
- * @param value 属性值
88
- */
89
- setAttr<T extends string>(key: T, value: TdAttrSetter<T>): void;
90
- /** @override */
91
- escape(): void;
92
- }
93
- /**
94
- * 创建新的单元格
95
- * @param inner 内部wikitext
96
- * @param subtype 单元格类型
97
- * @param attr 单元格属性
98
- * @param include 是否嵌入
99
- * @param config
100
- */
101
- export declare const createTd: (inner: string | Token, subtype?: TdSubtypes, attr?: TdAttrs, include?: boolean, config?: Parser.Config) => TdToken;
102
- export {};
@@ -1,261 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTd = exports.TdToken = void 0;
4
- const lint_1 = require("../../util/lint");
5
- const debug_1 = require("../../util/debug");
6
- const constants_1 = require("../../util/constants");
7
- const fixed_1 = require("../../mixin/fixed");
8
- const Parser = require("../../index");
9
- const index_1 = require("../index");
10
- const base_1 = require("./base");
11
- /**
12
- * `<td>`、`<th>`和`<caption>`
13
- * @classdesc `{childNodes: [SyntaxToken, AttributesToken, Token]}`
14
- */
15
- // @ts-expect-error not implementing all abstract methods
16
- class TdToken extends (0, fixed_1.fixed)(base_1.TableBaseToken) {
17
- type = 'td';
18
- #innerSyntax = '';
19
- /** 单元格类型 */
20
- get subtype() {
21
- return this.#getSyntax().subtype;
22
- }
23
- /* NOT FOR BROWSER */
24
- set subtype(subtype) {
25
- this.setSyntax(subtype);
26
- }
27
- /** rowspan */
28
- get rowspan() {
29
- return this.getAttr('rowspan');
30
- }
31
- set rowspan(rowspan) {
32
- this.setAttr('rowspan', rowspan);
33
- }
34
- /** colspan */
35
- get colspan() {
36
- return this.getAttr('colspan');
37
- }
38
- set colspan(colspan) {
39
- this.setAttr('colspan', colspan);
40
- }
41
- /** 内部wikitext */
42
- get innerText() {
43
- return this.lastChild.text();
44
- }
45
- set innerText(text) {
46
- this.lastChild.replaceChildren(...Parser.parse(text, true, undefined, this.getAttribute('config')).childNodes);
47
- }
48
- /* NOT FOR BROWSER END */
49
- /**
50
- * @param syntax 单元格语法
51
- * @param inner 内部wikitext
52
- */
53
- constructor(syntax, inner, config = Parser.getConfig(), accum = []) {
54
- let innerSyntax = /\||\0\d+!\x7F/u.exec(inner ?? ''), attr = innerSyntax ? inner.slice(0, innerSyntax.index) : '';
55
- if (/\[\[|-\{/u.test(attr)) {
56
- innerSyntax = null;
57
- attr = '';
58
- }
59
- super(/^(?:\n[^\S\n]*(?:[|!]|\|\+|\{\{\s*!\s*\}\}\+?)|(?:\||\{\{\s*!\s*\}\}){2}|!!|\{\{\s*!!\s*\}\})$/u, syntax, attr, config, accum, { SyntaxToken: 0, AttributesToken: 1, Token: 2 });
60
- if (innerSyntax) {
61
- [this.#innerSyntax] = innerSyntax;
62
- }
63
- const innerToken = new index_1.Token(inner?.slice((innerSyntax?.index ?? NaN) + this.#innerSyntax.length), config, accum);
64
- innerToken.type = 'td-inner';
65
- innerToken.setAttribute('stage', 4);
66
- this.insertAt(innerToken);
67
- }
68
- /** 表格语法信息 */
69
- #getSyntax() {
70
- const syntax = this.firstChild.text(), esc = syntax.includes('{{'), char = syntax.at(-1);
71
- let subtype = 'td';
72
- if (char === '!') {
73
- subtype = 'th';
74
- }
75
- else if (char === '+') {
76
- subtype = 'caption';
77
- }
78
- if (this.isIndependent()) {
79
- return { subtype, escape: esc, correction: false };
80
- }
81
- const { previousSibling } = this;
82
- if (!(previousSibling instanceof TdToken)) {
83
- return { subtype, escape: esc, correction: true };
84
- }
85
- const result = previousSibling.#getSyntax();
86
- result.escape ||= esc;
87
- result.correction = previousSibling.lastChild
88
- .toString(new Set(['comment', 'ext', 'include', 'noinclude', 'arg', 'template', 'magic-word']))
89
- .includes('\n');
90
- if (subtype === 'th' && result.subtype !== 'th') {
91
- result.subtype = 'th';
92
- result.correction = true;
93
- }
94
- return result;
95
- }
96
- /** @private */
97
- afterBuild() {
98
- if (this.#innerSyntax.includes('\0')) {
99
- this.#innerSyntax = this.buildFromStr(this.#innerSyntax, 'string');
100
- }
101
- }
102
- /** @private */
103
- toString(omit) {
104
- this.#correct();
105
- const { childNodes: [syntax, attr, inner] } = this;
106
- return omit && this.matchesTypes(omit)
107
- ? ''
108
- : `${syntax.toString(omit)}${attr.toString(omit)}${this.#innerSyntax}${inner.toString(omit)}`;
109
- }
110
- /** @override */
111
- text() {
112
- this.#correct();
113
- const { childNodes: [syntax, attr, inner] } = this;
114
- return `${syntax.text()}${attr.text()}${this.#innerSyntax}${inner.text()}`;
115
- }
116
- /** @private */
117
- getGaps(i) {
118
- if (i === 1) {
119
- this.#correct();
120
- return this.#innerSyntax.length;
121
- }
122
- return 0;
123
- }
124
- /** @override */
125
- lint(start = this.getAbsoluteIndex()) {
126
- const errors = super.lint(start);
127
- start += this.getRelativeIndex(this.length - 1);
128
- for (const child of this.lastChild.childNodes) {
129
- if (child.type === 'text' && child.data.includes('|')) {
130
- errors.push((0, lint_1.generateForChild)(child, { start }, 'additional "|" in a table cell', 'warning'));
131
- }
132
- }
133
- return errors;
134
- }
135
- /** @override */
136
- print() {
137
- const { childNodes: [syntax, attr, inner] } = this;
138
- return `<span class="wpb-td">${syntax.print()}${attr.print()}${this.#innerSyntax}${inner.print()}</span>`;
139
- }
140
- /* NOT FOR BROWSER */
141
- /** 是否位于行首 */
142
- isIndependent() {
143
- return this.firstChild.text().startsWith('\n');
144
- }
145
- /** @override */
146
- cloneNode() {
147
- const token = super.cloneNode();
148
- token.setAttribute('innerSyntax', this.#innerSyntax);
149
- return token;
150
- }
151
- /** @private */
152
- getAttribute(key) {
153
- return key === 'innerSyntax' ? this.#innerSyntax : super.getAttribute(key);
154
- }
155
- /** @private */
156
- setAttribute(key, value) {
157
- if (key === 'innerSyntax') {
158
- this.#innerSyntax = value ?? '';
159
- }
160
- else {
161
- super.setAttribute(key, value);
162
- }
163
- }
164
- /**
165
- * @override
166
- * @param syntax 表格语法
167
- * @param esc 是否需要转义
168
- */
169
- setSyntax(syntax, esc = false) {
170
- const aliases = { td: '\n|', th: '\n!', caption: '\n|+' };
171
- super.setSyntax(aliases[syntax] ?? syntax, esc);
172
- }
173
- /** 修复\<td\>语法 */
174
- #correct() {
175
- if (String(this.childNodes[1])) {
176
- this.#innerSyntax ||= '|';
177
- }
178
- const { subtype, escape, correction } = this.#getSyntax();
179
- if (correction) {
180
- this.setSyntax(subtype, escape);
181
- }
182
- }
183
- /** 改为独占一行 */
184
- independence() {
185
- if (!this.isIndependent()) {
186
- const { subtype, escape } = this.#getSyntax();
187
- this.setSyntax(subtype, escape);
188
- }
189
- }
190
- /**
191
- * @override
192
- * @param key 属性键
193
- */
194
- getAttr(key) {
195
- const value = super.getAttr(key);
196
- key = key.toLowerCase().trim();
197
- return (key === 'rowspan' || key === 'colspan' ? Number(value) || 1 : value);
198
- }
199
- /** @override */
200
- getAttrs() {
201
- const attr = super.getAttrs();
202
- if ('rowspan' in attr) {
203
- attr.rowspan = Number(attr.rowspan);
204
- }
205
- if ('colspan' in attr) {
206
- attr.colspan = Number(attr.colspan);
207
- }
208
- return attr;
209
- }
210
- /**
211
- * @override
212
- * @param key 属性键
213
- * @param value 属性值
214
- */
215
- setAttr(key, value) {
216
- key = key.toLowerCase().trim();
217
- let v;
218
- if (typeof value === 'number' && (key === 'rowspan' || key === 'colspan')) {
219
- v = value === 1 ? false : String(value);
220
- }
221
- else {
222
- v = value;
223
- }
224
- super.setAttr(key, v);
225
- if (!String(this.childNodes[1])) {
226
- this.#innerSyntax = '';
227
- }
228
- }
229
- /** @override */
230
- escape() {
231
- super.escape();
232
- if (String(this.childNodes[1])) {
233
- this.#innerSyntax ||= '{{!}}';
234
- }
235
- if (this.#innerSyntax === '|') {
236
- this.#innerSyntax = '{{!}}';
237
- }
238
- }
239
- }
240
- exports.TdToken = TdToken;
241
- /* NOT FOR BROWSER */
242
- /**
243
- * 创建新的单元格
244
- * @param inner 内部wikitext
245
- * @param subtype 单元格类型
246
- * @param attr 单元格属性
247
- * @param include 是否嵌入
248
- * @param config
249
- */
250
- const createTd = (inner, subtype = 'td', attr = {}, include = false, config = Parser.getConfig()) => {
251
- const innerToken = typeof inner === 'string' ? Parser.parse(inner, include, undefined, config) : inner, token = debug_1.Shadow.run(() => new TdToken('\n|', undefined, config));
252
- token.setSyntax(subtype);
253
- token.lastChild.safeReplaceWith(innerToken);
254
- for (const [k, v] of Object.entries(attr)) {
255
- token.setAttr(k, v);
256
- }
257
- return token;
258
- };
259
- exports.createTd = createTd;
260
- /* NOT FOR BROWSER END */
261
- constants_1.classes['TdToken'] = __filename;
@@ -1,32 +0,0 @@
1
- import * as 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 class TrToken extends TrBaseToken {
9
- #private;
10
- readonly type = "tr";
11
- childNodes: [SyntaxToken, AttributesToken, ...TdToken[]];
12
- abstract get children(): [SyntaxToken, AttributesToken, ...TdToken[]];
13
- abstract get lastChild(): AttributesToken | TdToken;
14
- abstract get lastElementChild(): AttributesToken | TdToken;
15
- abstract get parentNode(): TableToken | undefined;
16
- abstract get parentElement(): TableToken | undefined;
17
- abstract get nextSibling(): this | SyntaxToken | undefined;
18
- abstract get nextElementSibling(): this | SyntaxToken | undefined;
19
- abstract get previousSibling(): Token;
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,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TrToken = void 0;
4
- const constants_1 = require("../../util/constants");
5
- const Parser = require("../../index");
6
- const trBase_1 = require("./trBase");
7
- /**
8
- * 表格行,含开头的换行,不含结尾的换行
9
- * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken]}`
10
- */
11
- // @ts-expect-error not implementing all abstract methods
12
- class TrToken extends trBase_1.TrBaseToken {
13
- type = 'tr';
14
- /**
15
- * @param syntax 表格语法
16
- * @param attr 表格属性
17
- */
18
- constructor(syntax, attr, config = Parser.getConfig(), accum = []) {
19
- super(/^\n[^\S\n]*(?:\|-+|\{\{\s*!\s*\}\}-+|\{\{\s*!-\s*\}\}-*)$/u, syntax, attr, config, accum, {
20
- Token: 2, SyntaxToken: 0, AttributesToken: 1, TdToken: '2:',
21
- });
22
- }
23
- /* NOT FOR BROWSER */
24
- /** @override */
25
- text() {
26
- const str = super.text();
27
- return str.trim().includes('\n') ? str : '';
28
- }
29
- /**
30
- * 获取相邻行
31
- * @param subset 筛选兄弟节点的方法
32
- */
33
- #getSiblingRow(subset) {
34
- const { parentNode } = this;
35
- if (!parentNode) {
36
- return undefined;
37
- }
38
- const { childNodes } = parentNode, index = childNodes.indexOf(this);
39
- for (const child of subset(childNodes, index)) {
40
- if (child instanceof TrToken && child.getRowCount()) {
41
- return child;
42
- }
43
- }
44
- return undefined;
45
- }
46
- /** 获取下一行 */
47
- getNextRow() {
48
- return this.#getSiblingRow((childNodes, index) => childNodes.slice(index + 1));
49
- }
50
- /** 获取前一行 */
51
- getPreviousRow() {
52
- return this.#getSiblingRow((childNodes, index) => childNodes.slice(0, index).reverse());
53
- }
54
- }
55
- exports.TrToken = TrToken;
56
- constants_1.classes['TrToken'] = __filename;
@@ -1,54 +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
- row: number;
9
- column: number;
10
- x?: undefined;
11
- y?: undefined;
12
- 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
- /** @ignore */
45
- getNthCol(n: number, insert: true): TdToken | TrToken | SyntaxToken | undefined;
46
- /**
47
- * 插入新的单元格
48
- * @param inner 单元格内部wikitext
49
- * @param {TableCoords} coord 单元格坐标
50
- * @param subtype 单元格类型
51
- * @param attr 单元格属性
52
- */
53
- insertTableCell(inner: string | Token, { column }: TableCoords, subtype?: TdSubtypes, attr?: TdAttrs): TdToken;
54
- }
@@ -1,151 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TrBaseToken = void 0;
4
- const lint_1 = require("../../util/lint");
5
- const debug_1 = require("../../util/debug");
6
- const constants_1 = require("../../util/constants");
7
- const __1 = require("..");
8
- const base_1 = require("./base");
9
- const td_1 = require("./td");
10
- /** 表格行或表格 */
11
- class TrBaseToken extends base_1.TableBaseToken {
12
- /** @override */
13
- lint(start = this.getAbsoluteIndex()) {
14
- const errors = super.lint(start), inter = this.childNodes.find(({ type }) => type === 'table-inter');
15
- if (!inter) {
16
- return errors;
17
- }
18
- const first = inter.childNodes.find(child => child.text().trim()), tdPattern = /^\s*(?:!|\{\{\s*![!-]?\s*\}\})/u;
19
- if (!first || tdPattern.test(String(first))
20
- || first.type === 'arg' && tdPattern.test(first.default || '')) {
21
- return errors;
22
- }
23
- else if (first.type === 'magic-word') {
24
- try {
25
- if (first.getPossibleValues().every(token => tdPattern.test(token.text()))) {
26
- return errors;
27
- }
28
- }
29
- catch { }
30
- }
31
- const error = (0, lint_1.generateForChild)(inter, { start }, 'content to be moved out from the table');
32
- errors.push({
33
- ...error,
34
- startIndex: error.startIndex + 1,
35
- startLine: error.startLine + 1,
36
- startCol: 0,
37
- excerpt: error.excerpt.slice(1),
38
- });
39
- return errors;
40
- }
41
- /* NOT FOR BROWSER */
42
- /** 修复简单的表格语法错误 */
43
- #correct() {
44
- const { childNodes: [, , child] } = this;
45
- if (child?.constructor === __1.Token) {
46
- const { firstChild } = child;
47
- if (firstChild?.type !== 'text') {
48
- child.prepend('\n');
49
- }
50
- else if (!firstChild.data.startsWith('\n')) {
51
- firstChild.insertData(0, '\n');
52
- }
53
- }
54
- }
55
- /** @override */
56
- text() {
57
- this.#correct();
58
- return super.text();
59
- }
60
- /** @private */
61
- toString(omit) {
62
- this.#correct();
63
- return super.toString(omit);
64
- }
65
- /**
66
- * @override
67
- * @param i 移除位置
68
- */
69
- removeAt(i) {
70
- const child = this.childNodes.at(i);
71
- if (child instanceof td_1.TdToken && child.isIndependent()) {
72
- const { nextSibling } = child;
73
- if (nextSibling?.type === 'td') {
74
- nextSibling.independence();
75
- }
76
- }
77
- return super.removeAt(i);
78
- }
79
- /**
80
- * @override
81
- * @param token 待插入的子节点
82
- * @param i 插入位置
83
- */
84
- insertAt(token, i = this.length) {
85
- if (!debug_1.Shadow.running && token.type !== 'td') {
86
- if (this.type === 'tr') {
87
- this.typeError('insertAt', 'TdToken');
88
- }
89
- else if (token.type !== 'tr') {
90
- this.typeError('insertAt', 'TrToken', 'TdToken');
91
- }
92
- }
93
- const child = this.childNodes.at(i);
94
- if (token instanceof td_1.TdToken && token.isIndependent() && child instanceof td_1.TdToken) {
95
- child.independence();
96
- }
97
- return super.insertAt(token, i);
98
- }
99
- /** 获取行数 */
100
- getRowCount() {
101
- return Number(this.childNodes.some(child => child instanceof td_1.TdToken && child.isIndependent() && !child.firstChild.text().endsWith('+')));
102
- }
103
- /** 获取列数 */
104
- getColCount() {
105
- let count = 0, last = 0;
106
- for (const child of this.childNodes) {
107
- if (child instanceof td_1.TdToken) {
108
- last = child.isIndependent() ? Number(child.subtype !== 'caption') : last;
109
- count += last;
110
- }
111
- }
112
- return count;
113
- }
114
- /** @ignore */
115
- getNthCol(n, insert = false) {
116
- const nCols = this.getColCount();
117
- n += n < 0 ? nCols : 0;
118
- if (n < 0 || n > nCols || n === nCols && !insert) {
119
- throw new RangeError(`不存在第 ${n} 个单元格!`);
120
- }
121
- let last = 0;
122
- for (const child of this.childNodes.slice(2)) {
123
- if (child instanceof td_1.TdToken) {
124
- if (child.isIndependent()) {
125
- last = Number(child.subtype !== 'caption');
126
- }
127
- n -= last;
128
- if (n < 0) {
129
- return child;
130
- }
131
- }
132
- else if (child.type === 'tr' || child.type === 'table-syntax') {
133
- return child;
134
- }
135
- }
136
- return undefined;
137
- }
138
- /**
139
- * 插入新的单元格
140
- * @param inner 单元格内部wikitext
141
- * @param {TableCoords} coord 单元格坐标
142
- * @param subtype 单元格类型
143
- * @param attr 单元格属性
144
- */
145
- insertTableCell(inner, { column }, subtype = 'td', attr = {}) {
146
- const token = (0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
147
- return this.insertBefore(token, this.getNthCol(column, true));
148
- }
149
- }
150
- exports.TrBaseToken = TrBaseToken;
151
- constants_1.classes['TrBaseToken'] = __filename;