wikiparser-node 1.3.7 → 1.3.8-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 (153) 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/package.json +31 -13
  12. package/config/.schema.json +0 -172
  13. package/dist/addon/table.d.ts +0 -6
  14. package/dist/addon/table.js +0 -558
  15. package/dist/base.d.ts +0 -45
  16. package/dist/index.d.ts +0 -32
  17. package/dist/index.js +0 -209
  18. package/dist/internal.d.ts +0 -44
  19. package/dist/lib/element.d.ts +0 -154
  20. package/dist/lib/element.js +0 -630
  21. package/dist/lib/node.d.ts +0 -146
  22. package/dist/lib/node.js +0 -417
  23. package/dist/lib/range.d.ts +0 -104
  24. package/dist/lib/range.js +0 -385
  25. package/dist/lib/ranges.d.ts +0 -26
  26. package/dist/lib/ranges.js +0 -118
  27. package/dist/lib/text.d.ts +0 -62
  28. package/dist/lib/text.js +0 -255
  29. package/dist/lib/title.d.ts +0 -38
  30. package/dist/lib/title.js +0 -162
  31. package/dist/mixin/attributesParent.js +0 -89
  32. package/dist/mixin/fixed.js +0 -25
  33. package/dist/mixin/flagsParent.js +0 -70
  34. package/dist/mixin/hidden.js +0 -26
  35. package/dist/mixin/magicLinkParent.js +0 -41
  36. package/dist/mixin/singleLine.js +0 -25
  37. package/dist/mixin/sol.js +0 -43
  38. package/dist/mixin/syntax.js +0 -54
  39. package/dist/parser/braces.js +0 -128
  40. package/dist/parser/commentAndExt.js +0 -80
  41. package/dist/parser/converter.js +0 -40
  42. package/dist/parser/externalLinks.js +0 -28
  43. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  44. package/dist/parser/html.js +0 -36
  45. package/dist/parser/links.js +0 -94
  46. package/dist/parser/list.js +0 -66
  47. package/dist/parser/magicLinks.js +0 -40
  48. package/dist/parser/quotes.js +0 -67
  49. package/dist/parser/selector.js +0 -162
  50. package/dist/parser/table.js +0 -120
  51. package/dist/src/arg.d.ts +0 -56
  52. package/dist/src/arg.js +0 -187
  53. package/dist/src/atom.d.ts +0 -12
  54. package/dist/src/atom.js +0 -27
  55. package/dist/src/attribute.d.ts +0 -88
  56. package/dist/src/attribute.js +0 -398
  57. package/dist/src/attributes.d.ts +0 -109
  58. package/dist/src/attributes.js +0 -343
  59. package/dist/src/converter.d.ts +0 -53
  60. package/dist/src/converter.js +0 -79
  61. package/dist/src/converterFlags.d.ts +0 -87
  62. package/dist/src/converterFlags.js +0 -224
  63. package/dist/src/converterRule.d.ts +0 -77
  64. package/dist/src/converterRule.js +0 -208
  65. package/dist/src/extLink.d.ts +0 -55
  66. package/dist/src/extLink.js +0 -122
  67. package/dist/src/gallery.d.ts +0 -54
  68. package/dist/src/gallery.js +0 -121
  69. package/dist/src/heading.d.ts +0 -76
  70. package/dist/src/heading.js +0 -127
  71. package/dist/src/hidden.d.ts +0 -23
  72. package/dist/src/hidden.js +0 -23
  73. package/dist/src/html.d.ts +0 -104
  74. package/dist/src/html.js +0 -226
  75. package/dist/src/imageParameter.d.ts +0 -65
  76. package/dist/src/imageParameter.js +0 -245
  77. package/dist/src/imagemap.d.ts +0 -56
  78. package/dist/src/imagemap.js +0 -147
  79. package/dist/src/imagemapLink.d.ts +0 -61
  80. package/dist/src/imagemapLink.js +0 -40
  81. package/dist/src/index.d.ts +0 -140
  82. package/dist/src/index.js +0 -769
  83. package/dist/src/link/base.d.ts +0 -52
  84. package/dist/src/link/base.js +0 -209
  85. package/dist/src/link/category.d.ts +0 -13
  86. package/dist/src/link/category.js +0 -29
  87. package/dist/src/link/file.d.ts +0 -96
  88. package/dist/src/link/file.js +0 -257
  89. package/dist/src/link/galleryImage.d.ts +0 -45
  90. package/dist/src/link/galleryImage.js +0 -106
  91. package/dist/src/link/index.d.ts +0 -53
  92. package/dist/src/link/index.js +0 -124
  93. package/dist/src/magicLink.d.ts +0 -69
  94. package/dist/src/magicLink.js +0 -147
  95. package/dist/src/nested.d.ts +0 -43
  96. package/dist/src/nested.js +0 -86
  97. package/dist/src/nowiki/base.d.ts +0 -48
  98. package/dist/src/nowiki/base.js +0 -42
  99. package/dist/src/nowiki/comment.d.ts +0 -41
  100. package/dist/src/nowiki/comment.js +0 -67
  101. package/dist/src/nowiki/dd.d.ts +0 -8
  102. package/dist/src/nowiki/dd.js +0 -25
  103. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -47
  104. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  105. package/dist/src/nowiki/hr.d.ts +0 -33
  106. package/dist/src/nowiki/hr.js +0 -14
  107. package/dist/src/nowiki/index.d.ts +0 -16
  108. package/dist/src/nowiki/index.js +0 -21
  109. package/dist/src/nowiki/list.d.ts +0 -31
  110. package/dist/src/nowiki/list.js +0 -48
  111. package/dist/src/nowiki/listBase.d.ts +0 -20
  112. package/dist/src/nowiki/listBase.js +0 -12
  113. package/dist/src/nowiki/noinclude.d.ts +0 -26
  114. package/dist/src/nowiki/noinclude.js +0 -24
  115. package/dist/src/nowiki/quote.d.ts +0 -24
  116. package/dist/src/nowiki/quote.js +0 -45
  117. package/dist/src/onlyinclude.d.ts +0 -16
  118. package/dist/src/onlyinclude.js +0 -57
  119. package/dist/src/paramTag/index.d.ts +0 -37
  120. package/dist/src/paramTag/index.js +0 -68
  121. package/dist/src/paramTag/inputbox.d.ts +0 -8
  122. package/dist/src/paramTag/inputbox.js +0 -23
  123. package/dist/src/parameter.d.ts +0 -86
  124. package/dist/src/parameter.js +0 -205
  125. package/dist/src/pre.d.ts +0 -28
  126. package/dist/src/pre.js +0 -51
  127. package/dist/src/syntax.d.ts +0 -30
  128. package/dist/src/syntax.js +0 -34
  129. package/dist/src/table/base.d.ts +0 -59
  130. package/dist/src/table/base.js +0 -78
  131. package/dist/src/table/index.d.ts +0 -228
  132. package/dist/src/table/index.js +0 -379
  133. package/dist/src/table/td.d.ts +0 -107
  134. package/dist/src/table/td.js +0 -263
  135. package/dist/src/table/tr.d.ts +0 -32
  136. package/dist/src/table/tr.js +0 -56
  137. package/dist/src/table/trBase.d.ts +0 -53
  138. package/dist/src/table/trBase.js +0 -153
  139. package/dist/src/tagPair/ext.d.ts +0 -58
  140. package/dist/src/tagPair/ext.js +0 -140
  141. package/dist/src/tagPair/include.d.ts +0 -54
  142. package/dist/src/tagPair/include.js +0 -63
  143. package/dist/src/tagPair/index.d.ts +0 -49
  144. package/dist/src/tagPair/index.js +0 -93
  145. package/dist/src/transclude.d.ts +0 -167
  146. package/dist/src/transclude.js +0 -698
  147. package/dist/util/constants.js +0 -113
  148. package/dist/util/debug.js +0 -83
  149. package/dist/util/diff.js +0 -72
  150. package/dist/util/lint.js +0 -30
  151. package/dist/util/string.js +0 -51
  152. package/errors/README +0 -1
  153. package/printed/README +0 -1
@@ -1,263 +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
- /* NOT FOR BROWSER */
144
- /** 是否位于行首 */
145
- isIndependent() {
146
- return this.firstChild.text().startsWith('\n');
147
- }
148
- /** @override */
149
- cloneNode() {
150
- const token = super.cloneNode();
151
- token.setAttribute('innerSyntax', this.#innerSyntax);
152
- return token;
153
- }
154
- /** @private */
155
- getAttribute(key) {
156
- return key === 'innerSyntax' ? this.#innerSyntax : super.getAttribute(key);
157
- }
158
- /** @private */
159
- setAttribute(key, value) {
160
- if (key === 'innerSyntax') {
161
- this.#innerSyntax = value ?? '';
162
- }
163
- else {
164
- super.setAttribute(key, value);
165
- }
166
- }
167
- /**
168
- * @override
169
- * @param syntax 表格语法
170
- * @param esc 是否需要转义
171
- */
172
- setSyntax(syntax, esc = false) {
173
- const aliases = { td: '\n|', th: '\n!', caption: '\n|+' };
174
- super.setSyntax(aliases[syntax] ?? syntax, esc);
175
- }
176
- /** 修复\<td\>语法 */
177
- #correct() {
178
- if (String(this.childNodes[1])) {
179
- this.#innerSyntax ||= '|';
180
- }
181
- const { subtype, escape, correction } = this.#getSyntax();
182
- if (correction) {
183
- this.setSyntax(subtype, escape);
184
- }
185
- }
186
- /** 改为独占一行 */
187
- independence() {
188
- if (!this.isIndependent()) {
189
- const { subtype, escape } = this.#getSyntax();
190
- this.setSyntax(subtype, escape);
191
- }
192
- }
193
- /**
194
- * @override
195
- * @param key 属性键
196
- */
197
- getAttr(key) {
198
- const value = super.getAttr(key);
199
- key = key.toLowerCase().trim();
200
- return (key === 'rowspan' || key === 'colspan' ? Number(value) || 1 : value);
201
- }
202
- /** @override */
203
- getAttrs() {
204
- const attr = super.getAttrs();
205
- if ('rowspan' in attr) {
206
- attr.rowspan = Number(attr.rowspan);
207
- }
208
- if ('colspan' in attr) {
209
- attr.colspan = Number(attr.colspan);
210
- }
211
- return attr;
212
- }
213
- setAttr(keyOrProp, value) {
214
- if (typeof keyOrProp !== 'string') {
215
- for (const [key, val] of Object.entries(keyOrProp)) {
216
- this.setAttr(key, val);
217
- }
218
- return;
219
- }
220
- const key = keyOrProp.toLowerCase().trim();
221
- let v;
222
- if (typeof value === 'number' && (key === 'rowspan' || key === 'colspan')) {
223
- v = value === 1 ? false : String(value);
224
- }
225
- else {
226
- v = value;
227
- }
228
- super.setAttr(key, v);
229
- if (!String(this.childNodes[1])) {
230
- this.#innerSyntax = '';
231
- }
232
- }
233
- /** @override */
234
- escape() {
235
- super.escape();
236
- if (String(this.childNodes[1])) {
237
- this.#innerSyntax ||= '{{!}}';
238
- }
239
- if (this.#innerSyntax === '|') {
240
- this.#innerSyntax = '{{!}}';
241
- }
242
- }
243
- }
244
- exports.TdToken = TdToken;
245
- /* NOT FOR BROWSER */
246
- /**
247
- * 创建新的单元格
248
- * @param inner 内部wikitext
249
- * @param subtype 单元格类型
250
- * @param attr 单元格属性
251
- * @param include 是否嵌入
252
- * @param config
253
- */
254
- const createTd = (inner, subtype = 'td', attr = {}, include = false, config = Parser.getConfig()) => {
255
- const innerToken = typeof inner === 'string' ? Parser.parse(inner, include, undefined, config) : inner, token = debug_1.Shadow.run(() => new TdToken('\n|', undefined, config));
256
- token.setSyntax(subtype);
257
- token.lastChild.safeReplaceWith(innerToken);
258
- token.setAttr(attr);
259
- return token;
260
- };
261
- exports.createTd = createTd;
262
- /* NOT FOR BROWSER END */
263
- 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,58 +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; /** @override */
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
- readonly childNodes: [AttributesToken, Token];
40
- abstract get children(): [AttributesToken, Token];
41
- abstract get firstChild(): AttributesToken;
42
- abstract get firstElementChild(): AttributesToken;
43
- abstract get lastChild(): Token;
44
- /** @override */
45
- get closed(): boolean;
46
- /**
47
- * @param name 标签名
48
- * @param attr 标签属性
49
- * @param inner 内部wikitext
50
- * @param closed 是否封闭
51
- */
52
- constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Parser.Config, accum?: Token[]);
53
- /** @override */
54
- lint(start?: number): LintError[];
55
- /** @override */
56
- cloneNode(): this;
57
- }
58
- export {};