wikiparser-node 1.3.8 → 1.3.9-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 (155) 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 +64 -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 +114 -0
  11. package/i18n/zh-hans.json +6 -1
  12. package/i18n/zh-hant.json +6 -1
  13. package/package.json +31 -13
  14. package/config/.schema.json +0 -172
  15. package/dist/addon/table.d.ts +0 -6
  16. package/dist/addon/table.js +0 -558
  17. package/dist/base.d.ts +0 -45
  18. package/dist/index.d.ts +0 -32
  19. package/dist/index.js +0 -209
  20. package/dist/internal.d.ts +0 -44
  21. package/dist/lib/element.d.ts +0 -154
  22. package/dist/lib/element.js +0 -630
  23. package/dist/lib/node.d.ts +0 -146
  24. package/dist/lib/node.js +0 -419
  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 -255
  31. package/dist/lib/title.d.ts +0 -38
  32. package/dist/lib/title.js +0 -163
  33. package/dist/mixin/attributesParent.js +0 -89
  34. package/dist/mixin/fixed.js +0 -25
  35. package/dist/mixin/flagsParent.js +0 -70
  36. package/dist/mixin/hidden.js +0 -25
  37. package/dist/mixin/magicLinkParent.js +0 -41
  38. package/dist/mixin/singleLine.js +0 -25
  39. package/dist/mixin/sol.js +0 -43
  40. package/dist/mixin/syntax.js +0 -54
  41. package/dist/parser/braces.js +0 -128
  42. package/dist/parser/commentAndExt.js +0 -85
  43. package/dist/parser/converter.js +0 -40
  44. package/dist/parser/externalLinks.js +0 -31
  45. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  46. package/dist/parser/html.js +0 -36
  47. package/dist/parser/links.js +0 -94
  48. package/dist/parser/list.js +0 -66
  49. package/dist/parser/magicLinks.js +0 -42
  50. package/dist/parser/quotes.js +0 -67
  51. package/dist/parser/selector.js +0 -162
  52. package/dist/parser/table.js +0 -120
  53. package/dist/src/arg.d.ts +0 -58
  54. package/dist/src/arg.js +0 -194
  55. package/dist/src/atom.d.ts +0 -12
  56. package/dist/src/atom.js +0 -27
  57. package/dist/src/attribute.d.ts +0 -88
  58. package/dist/src/attribute.js +0 -399
  59. package/dist/src/attributes.d.ts +0 -109
  60. package/dist/src/attributes.js +0 -343
  61. package/dist/src/converter.d.ts +0 -53
  62. package/dist/src/converter.js +0 -79
  63. package/dist/src/converterFlags.d.ts +0 -87
  64. package/dist/src/converterFlags.js +0 -224
  65. package/dist/src/converterRule.d.ts +0 -77
  66. package/dist/src/converterRule.js +0 -208
  67. package/dist/src/extLink.d.ts +0 -55
  68. package/dist/src/extLink.js +0 -122
  69. package/dist/src/gallery.d.ts +0 -54
  70. package/dist/src/gallery.js +0 -121
  71. package/dist/src/heading.d.ts +0 -78
  72. package/dist/src/heading.js +0 -134
  73. package/dist/src/hidden.d.ts +0 -23
  74. package/dist/src/hidden.js +0 -23
  75. package/dist/src/html.d.ts +0 -106
  76. package/dist/src/html.js +0 -234
  77. package/dist/src/imageParameter.d.ts +0 -65
  78. package/dist/src/imageParameter.js +0 -247
  79. package/dist/src/imagemap.d.ts +0 -56
  80. package/dist/src/imagemap.js +0 -147
  81. package/dist/src/imagemapLink.d.ts +0 -61
  82. package/dist/src/imagemapLink.js +0 -40
  83. package/dist/src/index.d.ts +0 -140
  84. package/dist/src/index.js +0 -769
  85. package/dist/src/link/base.d.ts +0 -52
  86. package/dist/src/link/base.js +0 -209
  87. package/dist/src/link/category.d.ts +0 -13
  88. package/dist/src/link/category.js +0 -29
  89. package/dist/src/link/file.d.ts +0 -96
  90. package/dist/src/link/file.js +0 -256
  91. package/dist/src/link/galleryImage.d.ts +0 -45
  92. package/dist/src/link/galleryImage.js +0 -106
  93. package/dist/src/link/index.d.ts +0 -53
  94. package/dist/src/link/index.js +0 -124
  95. package/dist/src/magicLink.d.ts +0 -69
  96. package/dist/src/magicLink.js +0 -147
  97. package/dist/src/nested.d.ts +0 -43
  98. package/dist/src/nested.js +0 -86
  99. package/dist/src/nowiki/base.d.ts +0 -48
  100. package/dist/src/nowiki/base.js +0 -42
  101. package/dist/src/nowiki/comment.d.ts +0 -43
  102. package/dist/src/nowiki/comment.js +0 -74
  103. package/dist/src/nowiki/dd.d.ts +0 -8
  104. package/dist/src/nowiki/dd.js +0 -25
  105. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -47
  106. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  107. package/dist/src/nowiki/hr.d.ts +0 -33
  108. package/dist/src/nowiki/hr.js +0 -14
  109. package/dist/src/nowiki/index.d.ts +0 -16
  110. package/dist/src/nowiki/index.js +0 -21
  111. package/dist/src/nowiki/list.d.ts +0 -31
  112. package/dist/src/nowiki/list.js +0 -48
  113. package/dist/src/nowiki/listBase.d.ts +0 -20
  114. package/dist/src/nowiki/listBase.js +0 -12
  115. package/dist/src/nowiki/noinclude.d.ts +0 -26
  116. package/dist/src/nowiki/noinclude.js +0 -24
  117. package/dist/src/nowiki/quote.d.ts +0 -24
  118. package/dist/src/nowiki/quote.js +0 -45
  119. package/dist/src/onlyinclude.d.ts +0 -16
  120. package/dist/src/onlyinclude.js +0 -57
  121. package/dist/src/paramTag/index.d.ts +0 -37
  122. package/dist/src/paramTag/index.js +0 -68
  123. package/dist/src/paramTag/inputbox.d.ts +0 -8
  124. package/dist/src/paramTag/inputbox.js +0 -23
  125. package/dist/src/parameter.d.ts +0 -88
  126. package/dist/src/parameter.js +0 -214
  127. package/dist/src/pre.d.ts +0 -28
  128. package/dist/src/pre.js +0 -51
  129. package/dist/src/syntax.d.ts +0 -30
  130. package/dist/src/syntax.js +0 -34
  131. package/dist/src/table/base.d.ts +0 -59
  132. package/dist/src/table/base.js +0 -78
  133. package/dist/src/table/index.d.ts +0 -230
  134. package/dist/src/table/index.js +0 -386
  135. package/dist/src/table/td.d.ts +0 -109
  136. package/dist/src/table/td.js +0 -270
  137. package/dist/src/table/tr.d.ts +0 -32
  138. package/dist/src/table/tr.js +0 -56
  139. package/dist/src/table/trBase.d.ts +0 -53
  140. package/dist/src/table/trBase.js +0 -153
  141. package/dist/src/tagPair/ext.d.ts +0 -57
  142. package/dist/src/tagPair/ext.js +0 -134
  143. package/dist/src/tagPair/include.d.ts +0 -56
  144. package/dist/src/tagPair/include.js +0 -70
  145. package/dist/src/tagPair/index.d.ts +0 -45
  146. package/dist/src/tagPair/index.js +0 -76
  147. package/dist/src/transclude.d.ts +0 -167
  148. package/dist/src/transclude.js +0 -693
  149. package/dist/util/constants.js +0 -113
  150. package/dist/util/debug.js +0 -83
  151. package/dist/util/diff.js +0 -72
  152. package/dist/util/lint.js +0 -30
  153. package/dist/util/string.js +0 -51
  154. package/errors/README +0 -1
  155. package/printed/README +0 -1
@@ -1,270 +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.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 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, 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
- /* NOT FOR BROWSER */
253
- /**
254
- * 创建新的单元格
255
- * @param inner 内部wikitext
256
- * @param subtype 单元格类型
257
- * @param attr 单元格属性
258
- * @param include 是否嵌入
259
- * @param config
260
- */
261
- const createTd = (inner, subtype = 'td', attr = {}, include = false, config = Parser.getConfig()) => {
262
- const innerToken = typeof inner === 'string' ? Parser.parse(inner, include, undefined, config) : inner, token = debug_1.Shadow.run(() => new TdToken('\n|', undefined, config));
263
- token.setSyntax(subtype);
264
- token.lastChild.safeReplaceWith(innerToken);
265
- token.setAttr(attr);
266
- return token;
267
- };
268
- exports.createTd = createTd;
269
- /* NOT FOR BROWSER END */
270
- 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
- readonly 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,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
- }
@@ -1,153 +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, 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
- startIndex: error.startIndex + 1,
36
- startLine: error.startLine + 1,
37
- startCol: 0,
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
- i += i < 0 ? this.length : 0;
71
- const child = this.childNodes[i];
72
- if (child instanceof td_1.TdToken && child.isIndependent()) {
73
- const { nextSibling } = child;
74
- if (nextSibling?.type === 'td') {
75
- nextSibling.independence();
76
- }
77
- }
78
- return super.removeAt(i);
79
- }
80
- /**
81
- * @override
82
- * @param token 待插入的子节点
83
- * @param i 插入位置
84
- */
85
- insertAt(token, i = this.length) {
86
- if (!debug_1.Shadow.running && token.type !== 'td') {
87
- if (this.type === 'tr') {
88
- this.typeError('insertAt', 'TdToken');
89
- }
90
- else if (token.type !== 'tr') {
91
- this.typeError('insertAt', 'TrToken', 'TdToken');
92
- }
93
- }
94
- i += i < 0 ? this.length : 0;
95
- const child = this.childNodes[i];
96
- if (token instanceof td_1.TdToken && token.isIndependent() && child instanceof td_1.TdToken) {
97
- child.independence();
98
- }
99
- return super.insertAt(token, i);
100
- }
101
- /** 获取行数 */
102
- getRowCount() {
103
- return Number(this.childNodes.some(child => child instanceof td_1.TdToken && child.isIndependent() && !child.firstChild.text().endsWith('+')));
104
- }
105
- /** 获取列数 */
106
- getColCount() {
107
- let count = 0, last = 0;
108
- for (const child of this.childNodes) {
109
- if (child instanceof td_1.TdToken) {
110
- last = child.isIndependent() ? Number(child.subtype !== 'caption') : last;
111
- count += last;
112
- }
113
- }
114
- return count;
115
- }
116
- getNthCol(n, insert = false) {
117
- const nCols = this.getColCount();
118
- n += n < 0 ? nCols : 0;
119
- if (n < 0 || n > nCols || n === nCols && !insert) {
120
- throw new RangeError(`不存在第 ${n} 个单元格!`);
121
- }
122
- let last = 0;
123
- const isTr = (0, debug_1.isToken)('tr'), isSyntax = (0, debug_1.isToken)('table-syntax');
124
- for (const child of this.childNodes.slice(2)) {
125
- if (child instanceof td_1.TdToken) {
126
- if (child.isIndependent()) {
127
- last = Number(child.subtype !== 'caption');
128
- }
129
- n -= last;
130
- if (n < 0) {
131
- return child;
132
- }
133
- }
134
- else if (isTr(child) || isSyntax(child)) {
135
- return child;
136
- }
137
- }
138
- return undefined;
139
- }
140
- /**
141
- * 插入新的单元格
142
- * @param inner 单元格内部wikitext
143
- * @param {TableCoords} coord 单元格坐标
144
- * @param subtype 单元格类型
145
- * @param attr 单元格属性
146
- */
147
- insertTableCell(inner, { column }, subtype = 'td', attr = {}) {
148
- const token = (0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
149
- return this.insertBefore(token, this.getNthCol(column, true));
150
- }
151
- }
152
- exports.TrBaseToken = TrBaseToken;
153
- constants_1.classes['TrBaseToken'] = __filename;
@@ -1,57 +0,0 @@
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
- declare const ExtToken_base: (abstract new (...args: any[]) => {
7
- readonly childNodes: Parser.AstNodes[];
8
- readonly "__#7@#attributesChild": Parser.AttributesToken;
9
- attributes: Record<string, string | true>;
10
- className: string;
11
- classList: Set<string>;
12
- id: string;
13
- hasAttr(key: string): boolean;
14
- getAttr(key: string): string | true | undefined;
15
- getAttrNames(): Set<string>;
16
- getAttrs(): Record<string, string | true>;
17
- setAttr(key: string, value: string | boolean): void;
18
- setAttr(prop: Record<string, string | boolean>): void;
19
- removeAttr(key: string): void;
20
- toggleAttr(key: string, force?: boolean | undefined): void;
21
- readonly length: number;
22
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
23
- text(separator?: string | undefined): string;
24
- lint(start?: number | undefined): Parser.LintError[];
25
- insertAt(token: unknown, i?: number | undefined): unknown;
26
- afterBuild(): void;
27
- getAttribute<T extends string>(key: T): TokenAttributeGetter<T>;
28
- setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
29
- addEventListener(events: string | string[], listener: AstListener): void;
30
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
31
- constructorError(msg: string): never;
32
- }) & typeof TagPairToken;
33
- /**
34
- * 扩展标签
35
- * @classdesc `{childNodes: [AttributesToken, Token]}`
36
- */
37
- export declare class ExtToken extends ExtToken_base {
38
- readonly type = "ext";
39
- closed: true;
40
- readonly childNodes: [AttributesToken, Token];
41
- abstract get children(): [AttributesToken, Token];
42
- abstract get firstChild(): AttributesToken;
43
- abstract get firstElementChild(): AttributesToken;
44
- abstract get lastChild(): Token;
45
- /**
46
- * @param name 标签名
47
- * @param attr 标签属性
48
- * @param inner 内部wikitext
49
- * @param closed 是否封闭
50
- */
51
- constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Parser.Config, accum?: Token[]);
52
- /** @override */
53
- lint(start?: number): LintError[];
54
- /** @override */
55
- cloneNode(): this;
56
- }
57
- export {};