wikiparser-node 1.4.1-b → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/config/.schema.json +172 -0
  2. package/config/enwiki.json +814 -1
  3. package/config/llwiki.json +35 -1
  4. package/config/moegirl.json +44 -1
  5. package/config/zhwiki.json +466 -1
  6. package/dist/addon/table.d.ts +6 -0
  7. package/dist/addon/table.js +560 -0
  8. package/dist/base.d.ts +53 -0
  9. package/dist/index.d.ts +32 -0
  10. package/dist/index.js +208 -0
  11. package/dist/internal.d.ts +44 -0
  12. package/dist/lib/element.d.ts +154 -0
  13. package/dist/lib/element.js +635 -0
  14. package/dist/lib/node.d.ts +146 -0
  15. package/dist/lib/node.js +419 -0
  16. package/dist/lib/range.d.ts +104 -0
  17. package/dist/lib/range.js +385 -0
  18. package/dist/lib/ranges.d.ts +26 -0
  19. package/dist/lib/ranges.js +118 -0
  20. package/dist/lib/text.d.ts +62 -0
  21. package/dist/lib/text.js +265 -0
  22. package/dist/lib/title.d.ts +38 -0
  23. package/dist/lib/title.js +163 -0
  24. package/dist/mixin/attributesParent.d.ts +20 -0
  25. package/dist/mixin/attributesParent.js +89 -0
  26. package/dist/mixin/fixed.d.ts +5 -0
  27. package/dist/mixin/fixed.js +28 -0
  28. package/dist/mixin/flagsParent.d.ts +61 -0
  29. package/dist/mixin/flagsParent.js +70 -0
  30. package/dist/mixin/hidden.d.ts +5 -0
  31. package/dist/mixin/hidden.js +24 -0
  32. package/dist/mixin/magicLinkParent.d.ts +34 -0
  33. package/dist/mixin/magicLinkParent.js +41 -0
  34. package/dist/mixin/singleLine.d.ts +5 -0
  35. package/dist/mixin/singleLine.js +25 -0
  36. package/dist/mixin/sol.d.ts +8 -0
  37. package/dist/mixin/sol.js +43 -0
  38. package/dist/mixin/syntax.d.ts +6 -0
  39. package/dist/mixin/syntax.js +54 -0
  40. package/dist/parser/braces.js +131 -0
  41. package/dist/parser/commentAndExt.js +90 -0
  42. package/dist/parser/converter.js +41 -0
  43. package/dist/parser/externalLinks.js +32 -0
  44. package/dist/parser/hrAndDoubleUnderscore.js +41 -0
  45. package/dist/parser/html.js +39 -0
  46. package/dist/parser/links.js +95 -0
  47. package/dist/parser/list.js +68 -0
  48. package/dist/parser/magicLinks.js +43 -0
  49. package/dist/parser/quotes.js +68 -0
  50. package/dist/parser/selector.js +162 -0
  51. package/dist/parser/table.js +124 -0
  52. package/dist/src/arg.d.ts +58 -0
  53. package/dist/src/arg.js +195 -0
  54. package/dist/src/atom.d.ts +12 -0
  55. package/dist/src/atom.js +27 -0
  56. package/dist/src/attribute.d.ts +67 -0
  57. package/dist/src/attribute.js +423 -0
  58. package/dist/src/attributes.d.ts +109 -0
  59. package/dist/src/attributes.js +347 -0
  60. package/dist/src/converter.d.ts +28 -0
  61. package/dist/src/converter.js +86 -0
  62. package/dist/src/converterFlags.d.ts +87 -0
  63. package/dist/src/converterFlags.js +225 -0
  64. package/dist/src/converterRule.d.ts +77 -0
  65. package/dist/src/converterRule.js +209 -0
  66. package/dist/src/extLink.d.ts +38 -0
  67. package/dist/src/extLink.js +133 -0
  68. package/dist/src/gallery.d.ts +54 -0
  69. package/dist/src/gallery.js +127 -0
  70. package/dist/src/heading.d.ts +47 -0
  71. package/dist/src/heading.js +144 -0
  72. package/dist/src/hidden.d.ts +7 -0
  73. package/dist/src/hidden.js +23 -0
  74. package/dist/src/html.d.ts +62 -0
  75. package/dist/src/html.js +285 -0
  76. package/dist/src/imageParameter.d.ts +65 -0
  77. package/dist/src/imageParameter.js +248 -0
  78. package/dist/src/imagemap.d.ts +56 -0
  79. package/dist/src/imagemap.js +152 -0
  80. package/dist/src/imagemapLink.d.ts +28 -0
  81. package/dist/src/imagemapLink.js +44 -0
  82. package/dist/src/index.d.ts +143 -0
  83. package/dist/src/index.js +791 -0
  84. package/dist/src/link/base.d.ts +52 -0
  85. package/dist/src/link/base.js +209 -0
  86. package/dist/src/link/category.d.ts +13 -0
  87. package/dist/src/link/category.js +28 -0
  88. package/dist/src/link/file.d.ts +96 -0
  89. package/dist/src/link/file.js +262 -0
  90. package/dist/src/link/galleryImage.d.ts +31 -0
  91. package/dist/src/link/galleryImage.js +105 -0
  92. package/dist/src/link/index.d.ts +56 -0
  93. package/dist/src/link/index.js +134 -0
  94. package/dist/src/magicLink.d.ts +51 -0
  95. package/dist/src/magicLink.js +148 -0
  96. package/dist/src/nested.d.ts +43 -0
  97. package/dist/src/nested.js +90 -0
  98. package/dist/src/nowiki/base.d.ts +27 -0
  99. package/dist/src/nowiki/base.js +42 -0
  100. package/dist/src/nowiki/comment.d.ts +27 -0
  101. package/dist/src/nowiki/comment.js +74 -0
  102. package/dist/src/nowiki/dd.d.ts +8 -0
  103. package/dist/src/nowiki/dd.js +24 -0
  104. package/dist/src/nowiki/doubleUnderscore.d.ts +18 -0
  105. package/dist/src/nowiki/doubleUnderscore.js +50 -0
  106. package/dist/src/nowiki/hr.d.ts +8 -0
  107. package/dist/src/nowiki/hr.js +13 -0
  108. package/dist/src/nowiki/index.d.ts +16 -0
  109. package/dist/src/nowiki/index.js +20 -0
  110. package/dist/src/nowiki/list.d.ts +19 -0
  111. package/dist/src/nowiki/list.js +47 -0
  112. package/dist/src/nowiki/listBase.d.ts +5 -0
  113. package/dist/src/nowiki/listBase.js +11 -0
  114. package/dist/src/nowiki/noinclude.d.ts +10 -0
  115. package/dist/src/nowiki/noinclude.js +23 -0
  116. package/dist/src/nowiki/quote.d.ts +14 -0
  117. package/dist/src/nowiki/quote.js +68 -0
  118. package/dist/src/onlyinclude.d.ts +16 -0
  119. package/dist/src/onlyinclude.js +57 -0
  120. package/dist/src/paramTag/index.d.ts +37 -0
  121. package/dist/src/paramTag/index.js +68 -0
  122. package/dist/src/paramTag/inputbox.d.ts +8 -0
  123. package/dist/src/paramTag/inputbox.js +22 -0
  124. package/dist/src/parameter.d.ts +67 -0
  125. package/dist/src/parameter.js +215 -0
  126. package/dist/src/pre.d.ts +28 -0
  127. package/dist/src/pre.js +54 -0
  128. package/dist/src/syntax.d.ts +14 -0
  129. package/dist/src/syntax.js +34 -0
  130. package/dist/src/table/base.d.ts +27 -0
  131. package/dist/src/table/base.js +80 -0
  132. package/dist/src/table/index.d.ts +230 -0
  133. package/dist/src/table/index.js +385 -0
  134. package/dist/src/table/td.d.ts +88 -0
  135. package/dist/src/table/td.js +273 -0
  136. package/dist/src/table/tr.d.ts +32 -0
  137. package/dist/src/table/tr.js +57 -0
  138. package/dist/src/table/trBase.d.ts +53 -0
  139. package/dist/src/table/trBase.js +154 -0
  140. package/dist/src/tagPair/ext.d.ts +29 -0
  141. package/dist/src/tagPair/ext.js +151 -0
  142. package/dist/src/tagPair/include.d.ts +37 -0
  143. package/dist/src/tagPair/include.js +71 -0
  144. package/dist/src/tagPair/index.d.ts +27 -0
  145. package/dist/src/tagPair/index.js +76 -0
  146. package/dist/src/transclude.d.ts +167 -0
  147. package/dist/src/transclude.js +700 -0
  148. package/dist/util/constants.js +113 -0
  149. package/dist/util/debug.js +83 -0
  150. package/dist/util/diff.js +72 -0
  151. package/dist/util/lint.js +30 -0
  152. package/dist/util/string.js +53 -0
  153. package/errors/README +1 -0
  154. package/package.json +14 -30
  155. package/printed/README +1 -0
  156. package/bundle/bundle.min.js +0 -36
  157. package/extensions/dist/base.js +0 -64
  158. package/extensions/dist/editor.js +0 -159
  159. package/extensions/dist/highlight.js +0 -59
  160. package/extensions/dist/lint.js +0 -48
  161. package/extensions/editor.css +0 -63
  162. package/extensions/ui.css +0 -141
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.createTd = exports.TdToken = void 0;
5
+ const lint_1 = require("../../util/lint");
6
+ const debug_1 = require("../../util/debug");
7
+ const constants_1 = require("../../util/constants");
8
+ const fixed_1 = require("../../mixin/fixed");
9
+ const Parser = require("../../index");
10
+ const index_1 = require("../index");
11
+ const base_1 = require("./base");
12
+ /**
13
+ * `<td>`、`<th>`和`<caption>`
14
+ * @classdesc `{childNodes: [SyntaxToken, AttributesToken, Token]}`
15
+ */
16
+ class TdToken extends (0, fixed_1.fixedToken)(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.slice(-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 _a)) {
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, constants_1.BuildMethod.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') {
130
+ const { data } = child;
131
+ if (data.includes('|')) {
132
+ errors.push((0, lint_1.generateForChild)(child, { start }, 'additional "|" in a table cell', data.includes('||') ? 'error' : 'warning'));
133
+ }
134
+ }
135
+ }
136
+ return errors;
137
+ }
138
+ /** @override */
139
+ print() {
140
+ const { childNodes: [syntax, attr, inner] } = this;
141
+ return `<span class="wpb-td">${syntax.print()}${attr.print()}${this.#innerSyntax}${inner.print()}</span>`;
142
+ }
143
+ /** @override */
144
+ json() {
145
+ return {
146
+ ...super.json(),
147
+ subtype: this.subtype,
148
+ };
149
+ }
150
+ /* NOT FOR BROWSER */
151
+ /** 是否位于行首 */
152
+ isIndependent() {
153
+ return this.firstChild.text().startsWith('\n');
154
+ }
155
+ /** @override */
156
+ cloneNode() {
157
+ const token = super.cloneNode();
158
+ token.setAttribute('innerSyntax', this.#innerSyntax);
159
+ return token;
160
+ }
161
+ /** @private */
162
+ getAttribute(key) {
163
+ return key === 'innerSyntax' ? this.#innerSyntax : super.getAttribute(key);
164
+ }
165
+ /** @private */
166
+ setAttribute(key, value) {
167
+ if (key === 'innerSyntax') {
168
+ this.#innerSyntax = value ?? '';
169
+ }
170
+ else {
171
+ super.setAttribute(key, value);
172
+ }
173
+ }
174
+ /**
175
+ * @override
176
+ * @param syntax 表格语法
177
+ * @param esc 是否需要转义
178
+ */
179
+ setSyntax(syntax, esc = false) {
180
+ const aliases = { td: '\n|', th: '\n!', caption: '\n|+' };
181
+ super.setSyntax(aliases[syntax] ?? syntax, esc);
182
+ }
183
+ /** 修复\<td\>语法 */
184
+ #correct() {
185
+ if (String(this.childNodes[1])) {
186
+ this.#innerSyntax ||= '|';
187
+ }
188
+ const { subtype, escape, correction } = this.#getSyntax();
189
+ if (correction) {
190
+ this.setSyntax(subtype, escape);
191
+ }
192
+ }
193
+ /** 改为独占一行 */
194
+ independence() {
195
+ if (!this.isIndependent()) {
196
+ const { subtype, escape } = this.#getSyntax();
197
+ this.setSyntax(subtype, escape);
198
+ }
199
+ }
200
+ /**
201
+ * @override
202
+ * @param key 属性键
203
+ */
204
+ getAttr(key) {
205
+ const value = super.getAttr(key);
206
+ key = key.toLowerCase().trim();
207
+ return (key === 'rowspan' || key === 'colspan' ? Number(value) || 1 : value);
208
+ }
209
+ /** @override */
210
+ getAttrs() {
211
+ const attr = super.getAttrs();
212
+ if ('rowspan' in attr) {
213
+ attr.rowspan = Number(attr.rowspan);
214
+ }
215
+ if ('colspan' in attr) {
216
+ attr.colspan = Number(attr.colspan);
217
+ }
218
+ return attr;
219
+ }
220
+ setAttr(keyOrProp, value) {
221
+ if (typeof keyOrProp !== 'string') {
222
+ for (const [key, val] of Object.entries(keyOrProp)) {
223
+ this.setAttr(key, val);
224
+ }
225
+ return;
226
+ }
227
+ const key = keyOrProp.toLowerCase().trim();
228
+ let v;
229
+ if (typeof value === 'number' && (key === 'rowspan' || key === 'colspan')) {
230
+ v = value === 1 ? false : String(value);
231
+ }
232
+ else {
233
+ v = value;
234
+ }
235
+ super.setAttr(key, v);
236
+ if (!String(this.childNodes[1])) {
237
+ this.#innerSyntax = '';
238
+ }
239
+ }
240
+ /** @override */
241
+ escape() {
242
+ super.escape();
243
+ if (String(this.childNodes[1])) {
244
+ this.#innerSyntax ||= '{{!}}';
245
+ }
246
+ if (this.#innerSyntax === '|') {
247
+ this.#innerSyntax = '{{!}}';
248
+ }
249
+ }
250
+ }
251
+ exports.TdToken = TdToken;
252
+ _a = TdToken;
253
+ /* NOT FOR BROWSER */
254
+ /**
255
+ * 创建新的单元格
256
+ * @param inner 内部wikitext
257
+ * @param subtype 单元格类型
258
+ * @param attr 单元格属性
259
+ * @param include 是否嵌入
260
+ * @param config
261
+ */
262
+ const createTd = (inner, subtype = 'td', attr = {}, include = false, config = Parser.getConfig()) => {
263
+ const innerToken = typeof inner === 'string' ? Parser.parse(inner, include, undefined, config) : inner,
264
+ // @ts-expect-error abstract class
265
+ token = debug_1.Shadow.run(() => new TdToken('\n|', undefined, config));
266
+ token.setSyntax(subtype);
267
+ token.lastChild.safeReplaceWith(innerToken);
268
+ token.setAttr(attr);
269
+ return token;
270
+ };
271
+ exports.createTd = createTd;
272
+ /* NOT FOR BROWSER END */
273
+ constants_1.classes['TdToken'] = __filename;
@@ -0,0 +1,32 @@
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 abstract class TrToken extends TrBaseToken {
9
+ #private;
10
+ readonly type = "tr";
11
+ readonly childNodes: readonly [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
+ }
@@ -0,0 +1,57 @@
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 Parser = 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
+ /**
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 _a && 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
+ _a = TrToken;
57
+ constants_1.classes['TrToken'] = __filename;
@@ -0,0 +1,53 @@
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
+ }
@@ -0,0 +1,154 @@
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, isArg = (0, debug_1.isToken)('arg'), isTransclude = (0, debug_1.isToken)('magic-word');
19
+ if (!first
20
+ || tdPattern.test(String(first))
21
+ || isArg(first) && tdPattern.test(first.default || '')) {
22
+ return errors;
23
+ }
24
+ else if (isTransclude(first)) {
25
+ try {
26
+ if (first.getPossibleValues().every(token => tdPattern.test(token.text()))) {
27
+ return errors;
28
+ }
29
+ }
30
+ catch { }
31
+ }
32
+ const error = (0, lint_1.generateForChild)(inter, { start }, 'content to be moved out from the table');
33
+ errors.push({
34
+ ...error,
35
+ severity: first.type === 'template' ? 'warning' : 'error',
36
+ startIndex: error.startIndex + 1,
37
+ startLine: error.startLine + 1,
38
+ startCol: 0,
39
+ });
40
+ return errors;
41
+ }
42
+ /* NOT FOR BROWSER */
43
+ /** 修复简单的表格语法错误 */
44
+ #correct() {
45
+ const { childNodes: [, , child] } = this;
46
+ if (child?.constructor === __1.Token) {
47
+ const { firstChild } = child;
48
+ if (firstChild?.type !== 'text') {
49
+ child.prepend('\n');
50
+ }
51
+ else if (!firstChild.data.startsWith('\n')) {
52
+ firstChild.insertData(0, '\n');
53
+ }
54
+ }
55
+ }
56
+ /** @override */
57
+ text() {
58
+ this.#correct();
59
+ return super.text();
60
+ }
61
+ /** @private */
62
+ toString(omit) {
63
+ this.#correct();
64
+ return super.toString(omit);
65
+ }
66
+ /**
67
+ * @override
68
+ * @param i 移除位置
69
+ */
70
+ removeAt(i) {
71
+ i += i < 0 ? this.length : 0;
72
+ const child = this.childNodes[i];
73
+ if (child instanceof td_1.TdToken && child.isIndependent()) {
74
+ const { nextSibling } = child;
75
+ if (nextSibling?.type === 'td') {
76
+ nextSibling.independence();
77
+ }
78
+ }
79
+ return super.removeAt(i);
80
+ }
81
+ /**
82
+ * @override
83
+ * @param token 待插入的子节点
84
+ * @param i 插入位置
85
+ */
86
+ insertAt(token, i = this.length) {
87
+ if (!debug_1.Shadow.running && token.type !== 'td') {
88
+ if (this.type === 'tr') {
89
+ this.typeError('insertAt', 'TdToken');
90
+ }
91
+ else if (token.type !== 'tr') {
92
+ this.typeError('insertAt', 'TrToken', 'TdToken');
93
+ }
94
+ }
95
+ i += i < 0 ? this.length : 0;
96
+ const child = this.childNodes[i];
97
+ if (token instanceof td_1.TdToken && token.isIndependent() && child instanceof td_1.TdToken) {
98
+ child.independence();
99
+ }
100
+ return super.insertAt(token, i);
101
+ }
102
+ /** 获取行数 */
103
+ getRowCount() {
104
+ return Number(this.childNodes.some(child => child instanceof td_1.TdToken && child.isIndependent() && !child.firstChild.text().endsWith('+')));
105
+ }
106
+ /** 获取列数 */
107
+ getColCount() {
108
+ let count = 0, last = 0;
109
+ for (const child of this.childNodes) {
110
+ if (child instanceof td_1.TdToken) {
111
+ last = child.isIndependent() ? Number(child.subtype !== 'caption') : last;
112
+ count += last;
113
+ }
114
+ }
115
+ return count;
116
+ }
117
+ getNthCol(n, insert = false) {
118
+ const nCols = this.getColCount();
119
+ n += n < 0 ? nCols : 0;
120
+ if (n < 0 || n > nCols || n === nCols && !insert) {
121
+ throw new RangeError(`不存在第 ${n} 个单元格!`);
122
+ }
123
+ let last = 0;
124
+ const isTr = (0, debug_1.isToken)('tr'), isSyntax = (0, debug_1.isToken)('table-syntax');
125
+ for (const child of this.childNodes.slice(2)) {
126
+ if (child instanceof td_1.TdToken) {
127
+ if (child.isIndependent()) {
128
+ last = Number(child.subtype !== 'caption');
129
+ }
130
+ n -= last;
131
+ if (n < 0) {
132
+ return child;
133
+ }
134
+ }
135
+ else if (isTr(child) || isSyntax(child)) {
136
+ return child;
137
+ }
138
+ }
139
+ return undefined;
140
+ }
141
+ /**
142
+ * 插入新的单元格
143
+ * @param inner 单元格内部wikitext
144
+ * @param {TableCoords} coord 单元格坐标
145
+ * @param subtype 单元格类型
146
+ * @param attr 单元格属性
147
+ */
148
+ insertTableCell(inner, { column }, subtype = 'td', attr = {}) {
149
+ const token = (0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
150
+ return this.insertBefore(token, this.getNthCol(column, true));
151
+ }
152
+ }
153
+ exports.TrBaseToken = TrBaseToken;
154
+ constants_1.classes['TrBaseToken'] = __filename;
@@ -0,0 +1,29 @@
1
+ import * as Parser from '../../index';
2
+ import { Token } from '../index';
3
+ import { TagPairToken } from './index';
4
+ import { AttributesToken } from '../attributes';
5
+ import type { LintError } from '../../base';
6
+ import type { AttributesParentBase } from '../../mixin/attributesParent';
7
+ export interface ExtToken extends AttributesParentBase {
8
+ }
9
+ export declare abstract class ExtToken extends TagPairToken {
10
+ readonly type = "ext";
11
+ closed: true;
12
+ readonly childNodes: readonly [AttributesToken, Token];
13
+ abstract get children(): [AttributesToken, Token];
14
+ abstract get firstChild(): AttributesToken;
15
+ abstract get firstElementChild(): AttributesToken;
16
+ abstract get lastChild(): Token;
17
+ /**
18
+ * @param name 标签名
19
+ * @param attr 标签属性
20
+ * @param inner 内部wikitext
21
+ * @param closed 是否封闭
22
+ */
23
+ constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Parser.Config, accum?: Token[]);
24
+ /** @override */
25
+ lint(start?: number): LintError[];
26
+ /** @override */
27
+ cloneNode(): this;
28
+ }
29
+ export {};