wikiparser-node 1.9.0 → 1.9.1-b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/README.en.md +2 -2
  2. package/bundle/bundle.min.js +38 -0
  3. package/config/enwiki.json +1 -814
  4. package/config/llwiki.json +1 -35
  5. package/config/moegirl.json +1 -44
  6. package/config/zhwiki.json +1 -466
  7. package/extensions/dist/base.js +64 -0
  8. package/extensions/dist/editor.js +159 -0
  9. package/extensions/dist/highlight.js +58 -0
  10. package/extensions/dist/lint.js +72 -0
  11. package/extensions/editor.css +64 -0
  12. package/extensions/ui.css +144 -0
  13. package/package.json +38 -28
  14. package/config/.schema.json +0 -181
  15. package/dist/addon/table.js +0 -485
  16. package/dist/addon/token.js +0 -236
  17. package/dist/addon/transclude.js +0 -183
  18. package/dist/base.d.ts +0 -71
  19. package/dist/base.js +0 -39
  20. package/dist/index.d.ts +0 -33
  21. package/dist/index.js +0 -218
  22. package/dist/internal.d.ts +0 -46
  23. package/dist/lib/element.d.ts +0 -129
  24. package/dist/lib/element.js +0 -593
  25. package/dist/lib/node.d.ts +0 -166
  26. package/dist/lib/node.js +0 -480
  27. package/dist/lib/range.d.ts +0 -105
  28. package/dist/lib/range.js +0 -406
  29. package/dist/lib/ranges.d.ts +0 -28
  30. package/dist/lib/ranges.js +0 -126
  31. package/dist/lib/text.d.ts +0 -54
  32. package/dist/lib/text.js +0 -350
  33. package/dist/lib/title.d.ts +0 -40
  34. package/dist/lib/title.js +0 -197
  35. package/dist/mixin/attributesParent.d.ts +0 -49
  36. package/dist/mixin/attributesParent.js +0 -81
  37. package/dist/mixin/fixed.d.ts +0 -5
  38. package/dist/mixin/fixed.js +0 -30
  39. package/dist/mixin/flagsParent.d.ts +0 -41
  40. package/dist/mixin/flagsParent.js +0 -59
  41. package/dist/mixin/hidden.d.ts +0 -4
  42. package/dist/mixin/hidden.js +0 -24
  43. package/dist/mixin/magicLinkParent.d.ts +0 -19
  44. package/dist/mixin/magicLinkParent.js +0 -42
  45. package/dist/mixin/singleLine.d.ts +0 -5
  46. package/dist/mixin/singleLine.js +0 -26
  47. package/dist/mixin/sol.d.ts +0 -5
  48. package/dist/mixin/sol.js +0 -43
  49. package/dist/mixin/syntax.d.ts +0 -8
  50. package/dist/mixin/syntax.js +0 -50
  51. package/dist/parser/braces.js +0 -139
  52. package/dist/parser/commentAndExt.js +0 -89
  53. package/dist/parser/converter.js +0 -40
  54. package/dist/parser/externalLinks.js +0 -44
  55. package/dist/parser/hrAndDoubleUnderscore.js +0 -40
  56. package/dist/parser/html.js +0 -38
  57. package/dist/parser/links.js +0 -99
  58. package/dist/parser/list.js +0 -97
  59. package/dist/parser/magicLinks.js +0 -59
  60. package/dist/parser/quotes.js +0 -67
  61. package/dist/parser/redirect.js +0 -26
  62. package/dist/parser/selector.js +0 -190
  63. package/dist/parser/table.js +0 -123
  64. package/dist/src/arg.d.ts +0 -54
  65. package/dist/src/arg.js +0 -214
  66. package/dist/src/atom.d.ts +0 -12
  67. package/dist/src/atom.js +0 -27
  68. package/dist/src/attribute.d.ts +0 -67
  69. package/dist/src/attribute.js +0 -502
  70. package/dist/src/attributes.d.ts +0 -105
  71. package/dist/src/attributes.js +0 -356
  72. package/dist/src/converter.d.ts +0 -31
  73. package/dist/src/converter.js +0 -134
  74. package/dist/src/converterFlags.d.ts +0 -83
  75. package/dist/src/converterFlags.js +0 -242
  76. package/dist/src/converterRule.d.ts +0 -75
  77. package/dist/src/converterRule.js +0 -209
  78. package/dist/src/extLink.d.ts +0 -39
  79. package/dist/src/extLink.js +0 -191
  80. package/dist/src/gallery.d.ts +0 -50
  81. package/dist/src/gallery.js +0 -139
  82. package/dist/src/heading.d.ts +0 -43
  83. package/dist/src/heading.js +0 -190
  84. package/dist/src/hidden.d.ts +0 -7
  85. package/dist/src/hidden.js +0 -23
  86. package/dist/src/html.d.ts +0 -61
  87. package/dist/src/html.js +0 -358
  88. package/dist/src/imageParameter.d.ts +0 -61
  89. package/dist/src/imageParameter.js +0 -257
  90. package/dist/src/imagemap.d.ts +0 -50
  91. package/dist/src/imagemap.js +0 -144
  92. package/dist/src/imagemapLink.d.ts +0 -31
  93. package/dist/src/imagemapLink.js +0 -93
  94. package/dist/src/index.d.ts +0 -142
  95. package/dist/src/index.js +0 -717
  96. package/dist/src/link/base.d.ts +0 -48
  97. package/dist/src/link/base.js +0 -228
  98. package/dist/src/link/category.d.ts +0 -22
  99. package/dist/src/link/category.js +0 -30
  100. package/dist/src/link/file.d.ts +0 -96
  101. package/dist/src/link/file.js +0 -272
  102. package/dist/src/link/galleryImage.d.ts +0 -30
  103. package/dist/src/link/galleryImage.js +0 -157
  104. package/dist/src/link/index.d.ts +0 -54
  105. package/dist/src/link/index.js +0 -133
  106. package/dist/src/link/redirectTarget.d.ts +0 -49
  107. package/dist/src/link/redirectTarget.js +0 -101
  108. package/dist/src/magicLink.d.ts +0 -59
  109. package/dist/src/magicLink.js +0 -261
  110. package/dist/src/nested.d.ts +0 -41
  111. package/dist/src/nested.js +0 -105
  112. package/dist/src/nowiki/base.d.ts +0 -31
  113. package/dist/src/nowiki/base.js +0 -93
  114. package/dist/src/nowiki/comment.d.ts +0 -21
  115. package/dist/src/nowiki/comment.js +0 -76
  116. package/dist/src/nowiki/dd.d.ts +0 -8
  117. package/dist/src/nowiki/dd.js +0 -24
  118. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -16
  119. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  120. package/dist/src/nowiki/hr.d.ts +0 -5
  121. package/dist/src/nowiki/hr.js +0 -63
  122. package/dist/src/nowiki/index.d.ts +0 -14
  123. package/dist/src/nowiki/index.js +0 -27
  124. package/dist/src/nowiki/list.d.ts +0 -16
  125. package/dist/src/nowiki/list.js +0 -109
  126. package/dist/src/nowiki/listBase.d.ts +0 -5
  127. package/dist/src/nowiki/listBase.js +0 -61
  128. package/dist/src/nowiki/noinclude.d.ts +0 -10
  129. package/dist/src/nowiki/noinclude.js +0 -23
  130. package/dist/src/nowiki/quote.d.ts +0 -17
  131. package/dist/src/nowiki/quote.js +0 -137
  132. package/dist/src/onlyinclude.d.ts +0 -14
  133. package/dist/src/onlyinclude.js +0 -57
  134. package/dist/src/paramTag/index.d.ts +0 -33
  135. package/dist/src/paramTag/index.js +0 -77
  136. package/dist/src/paramTag/inputbox.d.ts +0 -8
  137. package/dist/src/paramTag/inputbox.js +0 -22
  138. package/dist/src/parameter.d.ts +0 -66
  139. package/dist/src/parameter.js +0 -264
  140. package/dist/src/pre.d.ts +0 -29
  141. package/dist/src/pre.js +0 -59
  142. package/dist/src/redirect.d.ts +0 -28
  143. package/dist/src/redirect.js +0 -119
  144. package/dist/src/syntax.d.ts +0 -17
  145. package/dist/src/syntax.js +0 -86
  146. package/dist/src/table/base.d.ts +0 -27
  147. package/dist/src/table/base.js +0 -81
  148. package/dist/src/table/index.d.ts +0 -240
  149. package/dist/src/table/index.js +0 -498
  150. package/dist/src/table/td.d.ts +0 -82
  151. package/dist/src/table/td.js +0 -358
  152. package/dist/src/table/tr.d.ts +0 -32
  153. package/dist/src/table/tr.js +0 -58
  154. package/dist/src/table/trBase.d.ts +0 -51
  155. package/dist/src/table/trBase.js +0 -156
  156. package/dist/src/tagPair/ext.d.ts +0 -30
  157. package/dist/src/tagPair/ext.js +0 -203
  158. package/dist/src/tagPair/include.d.ts +0 -33
  159. package/dist/src/tagPair/include.js +0 -74
  160. package/dist/src/tagPair/index.d.ts +0 -25
  161. package/dist/src/tagPair/index.js +0 -128
  162. package/dist/src/transclude.d.ts +0 -162
  163. package/dist/src/transclude.js +0 -584
  164. package/dist/util/constants.js +0 -27
  165. package/dist/util/debug.js +0 -81
  166. package/dist/util/diff.js +0 -83
  167. package/dist/util/lint.js +0 -31
  168. package/dist/util/string.js +0 -60
  169. package/errors/README +0 -1
  170. package/printed/README +0 -1
@@ -1,119 +0,0 @@
1
- "use strict";
2
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
- var _, done = false;
8
- for (var i = decorators.length - 1; i >= 0; i--) {
9
- var context = {};
10
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
- if (kind === "accessor") {
15
- if (result === void 0) continue;
16
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
- if (_ = accept(result.get)) descriptor.get = _;
18
- if (_ = accept(result.set)) descriptor.set = _;
19
- if (_ = accept(result.init)) initializers.unshift(_);
20
- }
21
- else if (_ = accept(result)) {
22
- if (kind === "field") initializers.unshift(_);
23
- else descriptor[key] = _;
24
- }
25
- }
26
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
- done = true;
28
- };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.RedirectToken = void 0;
38
- const constants_1 = require("../util/constants");
39
- const debug_1 = require("../util/debug");
40
- const hidden_1 = require("../mixin/hidden");
41
- const fixed_1 = require("../mixin/fixed");
42
- const index_1 = require("../index");
43
- const index_2 = require("./index");
44
- const syntax_1 = require("./syntax");
45
- const redirectTarget_1 = require("./link/redirectTarget");
46
- /**
47
- * 重定向
48
- * @classdesc `{childNodes: [SyntaxToken, LinkToken]}`
49
- */
50
- let RedirectToken = (() => {
51
- let _classDecorators = [fixed_1.fixedToken];
52
- let _classDescriptor;
53
- let _classExtraInitializers = [];
54
- let _classThis;
55
- let _classSuper = (0, hidden_1.hiddenToken)(index_2.Token);
56
- var RedirectToken = class extends _classSuper {
57
- static { _classThis = this; }
58
- static {
59
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
60
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
61
- RedirectToken = _classThis = _classDescriptor.value;
62
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
63
- __runInitializers(_classThis, _classExtraInitializers);
64
- }
65
- type = 'redirect';
66
- #pre;
67
- #post;
68
- /* NOT FOR BROWSER END */
69
- /**
70
- * @param pre leading whitespace
71
- * @param syntax 重定向魔术字
72
- * @param link 重定向目标
73
- * @param text 重定向显示文本(无效)
74
- * @param post trailing whitespace
75
- */
76
- constructor(pre, syntax, link, text, post, config = index_1.default.getConfig(), accum = []) {
77
- super(undefined, config, accum);
78
- this.#pre = pre;
79
- this.#post = post;
80
- const pattern = new RegExp(`^(?:${config.redirection.join('|')})\\s*(?::\\s*)?$`, 'iu');
81
- this.append(new syntax_1.SyntaxToken(syntax, pattern, 'redirect-syntax', config, accum, {
82
- AstText: ':',
83
- }),
84
- // @ts-expect-error abstract class
85
- new redirectTarget_1.RedirectTargetToken(link, text?.slice(1), config, accum));
86
- }
87
- /** @private */
88
- getAttribute(key) {
89
- return key === 'padding' ? this.#pre.length : super.getAttribute(key);
90
- }
91
- /** @private */
92
- toString() {
93
- return this.#pre + super.toString() + this.#post;
94
- }
95
- /** @private */
96
- lint(start = this.getAbsoluteIndex()) {
97
- return this.lastChild.lint(start + this.#pre.length + this.firstChild.toString().length);
98
- }
99
- /** @private */
100
- print() {
101
- return super.print({ pre: this.#pre, post: this.#post });
102
- }
103
- /* NOT FOR BROWSER */
104
- /** @override */
105
- cloneNode() {
106
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config');
107
- return debug_1.Shadow.run(() => {
108
- // @ts-expect-error abstract class
109
- const token = new RedirectToken([this.#pre, undefined, '', undefined, this.#post], config, []);
110
- token.firstChild.safeReplaceWith(cloned[0]);
111
- token.lastChild.safeReplaceWith(cloned[1]);
112
- return token;
113
- });
114
- }
115
- };
116
- return RedirectToken = _classThis;
117
- })();
118
- exports.RedirectToken = RedirectToken;
119
- constants_1.classes['RedirectToken'] = __filename;
@@ -1,17 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import type { SyntaxBase } from '../mixin/syntax';
4
- declare type SyntaxTypes = 'plain' | 'heading-trail' | 'magic-word-name' | 'table-syntax' | 'redirect-syntax';
5
- /** NOT FOR BROWSER */
6
- export interface SyntaxToken extends SyntaxBase {
7
- }
8
- /** NOT FOR BROWSER END */
9
- /** 满足特定语法格式的plain Token */
10
- export declare class SyntaxToken extends Token {
11
- type: SyntaxTypes;
12
- /** @param pattern 语法正则 */
13
- constructor(wikitext: string | undefined, pattern: RegExp, type?: SyntaxTypes, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
14
- /** @override */
15
- cloneNode(): this;
16
- }
17
- export {};
@@ -1,86 +0,0 @@
1
- "use strict";
2
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
- var _, done = false;
8
- for (var i = decorators.length - 1; i >= 0; i--) {
9
- var context = {};
10
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
- if (kind === "accessor") {
15
- if (result === void 0) continue;
16
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
- if (_ = accept(result.get)) descriptor.get = _;
18
- if (_ = accept(result.set)) descriptor.set = _;
19
- if (_ = accept(result.init)) initializers.unshift(_);
20
- }
21
- else if (_ = accept(result)) {
22
- if (kind === "field") initializers.unshift(_);
23
- else descriptor[key] = _;
24
- }
25
- }
26
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
- done = true;
28
- };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.SyntaxToken = void 0;
38
- const debug_1 = require("../util/debug");
39
- const constants_1 = require("../util/constants");
40
- const syntax_1 = require("../mixin/syntax");
41
- const index_1 = require("../index");
42
- const index_2 = require("./index");
43
- /** NOT FOR BROWSER END */
44
- /** 满足特定语法格式的plain Token */
45
- let SyntaxToken = (() => {
46
- let _classDecorators = [(0, syntax_1.syntax)()];
47
- let _classDescriptor;
48
- let _classExtraInitializers = [];
49
- let _classThis;
50
- let _classSuper = index_2.Token;
51
- var SyntaxToken = class extends _classSuper {
52
- static { _classThis = this; }
53
- static {
54
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
55
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
56
- SyntaxToken = _classThis = _classDescriptor.value;
57
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
58
- __runInitializers(_classThis, _classExtraInitializers);
59
- }
60
- /** @param pattern 语法正则 */
61
- constructor(wikitext, pattern, type = 'plain', config = index_1.default.getConfig(), accum = [], acceptable) {
62
- super(wikitext, config, accum, acceptable);
63
- this.type = type;
64
- /* NOT FOR BROWSER */
65
- this.setAttribute('pattern', pattern);
66
- }
67
- /** @private */
68
- lint() {
69
- return [];
70
- }
71
- /* NOT FOR BROWSER */
72
- /** @override */
73
- cloneNode() {
74
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAttribute('acceptable');
75
- return debug_1.Shadow.run(() => {
76
- const token = new SyntaxToken(undefined, this.pattern, this.type, config, [], acceptable);
77
- token.append(...cloned);
78
- token.afterBuild();
79
- return token;
80
- });
81
- }
82
- };
83
- return SyntaxToken = _classThis;
84
- })();
85
- exports.SyntaxToken = SyntaxToken;
86
- constants_1.classes['SyntaxToken'] = __filename;
@@ -1,27 +0,0 @@
1
- import Parser from '../../index';
2
- import { Token } from '../index';
3
- import { SyntaxToken } from '../syntax';
4
- import { AttributesToken } from '../attributes';
5
- import type { AttributesParentBase } from '../../mixin/attributesParent';
6
- export interface TableBaseToken extends AttributesParentBase {
7
- }
8
- export declare abstract class TableBaseToken extends Token {
9
- type: 'table' | 'tr' | 'td';
10
- readonly childNodes: readonly [SyntaxToken, AttributesToken, ...Token[]];
11
- abstract get firstChild(): SyntaxToken;
12
- abstract get lastChild(): Token;
13
- abstract get children(): [SyntaxToken, AttributesToken, ...Token[]];
14
- abstract get firstElementChild(): SyntaxToken;
15
- abstract get lastElementChild(): Token;
16
- /**
17
- * @param pattern 表格语法正则
18
- * @param syntax 表格语法
19
- * @param attr 表格属性
20
- */
21
- constructor(pattern: RegExp, syntax?: string, attr?: string, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
22
- /** @override */
23
- cloneNode(): this;
24
- /** 转义表格语法 */
25
- escape(): void;
26
- }
27
- export {};
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TableBaseToken = void 0;
4
- const debug_1 = require("../../util/debug");
5
- const constants_1 = require("../../util/constants");
6
- const attributesParent_1 = require("../../mixin/attributesParent");
7
- const index_1 = require("../../index");
8
- const index_2 = require("../index");
9
- const syntax_1 = require("../syntax");
10
- const attributes_1 = require("../attributes");
11
- /* NOT FOR BROWSER */
12
- /**
13
- * 转义表格语法
14
- * @param syntax 表格语法节点
15
- */
16
- const escapeTable = (syntax) => {
17
- const wikitext = syntax.childNodes.map(child => child.type === 'text'
18
- ? child.data.replace(/\|/gu, '{{!}}')
19
- : child.toString()).join(''), { childNodes } = index_1.default.parse(wikitext, syntax.getAttribute('include'), 2, syntax.getAttribute('config'));
20
- syntax.replaceChildren(...childNodes);
21
- };
22
- /**
23
- * 表格行,含开头的换行,不含结尾的换行
24
- * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ...Token]}`
25
- */
26
- class TableBaseToken extends (0, attributesParent_1.attributesParent)(1)(index_2.Token) {
27
- /* NOT FOR BROWSER END */
28
- /**
29
- * @param pattern 表格语法正则
30
- * @param syntax 表格语法
31
- * @param attr 表格属性
32
- */
33
- constructor(pattern, syntax, attr, config = index_1.default.getConfig(), accum = [], acceptable = {}) {
34
- super(undefined, config, accum, acceptable);
35
- this.append(new syntax_1.SyntaxToken(syntax, pattern, 'table-syntax', config, accum, {
36
- 'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':',
37
- }),
38
- // @ts-expect-error abstract class
39
- new attributes_1.AttributesToken(attr, 'table-attrs', this.type, config, accum));
40
- /* NOT FOR BROWSER */
41
- this.protectChildren(0, 1);
42
- }
43
- /* NOT FOR BROWSER */
44
- /** @override */
45
- cloneNode() {
46
- const [syntax, attr, ...cloned] = this.cloneChildNodes();
47
- return debug_1.Shadow.run(() => {
48
- const { constructor } = this, token = new constructor(undefined, undefined, this.getAttribute('config'));
49
- token.firstChild.safeReplaceWith(syntax);
50
- token.childNodes[1].safeReplaceWith(attr);
51
- if (token.type === 'td') { // TdToken
52
- token.childNodes[2].safeReplaceWith(cloned[0]);
53
- }
54
- else {
55
- token.append(...cloned);
56
- }
57
- return token;
58
- });
59
- }
60
- /** 转义表格语法 */
61
- escape() {
62
- for (const child of this.childNodes) {
63
- if (child instanceof syntax_1.SyntaxToken) {
64
- escapeTable(child);
65
- }
66
- else if (child instanceof TableBaseToken) {
67
- child.escape();
68
- }
69
- }
70
- }
71
- /** @private */
72
- setSyntax(syntax, esc) {
73
- const { firstChild } = this;
74
- firstChild.replaceChildren(syntax);
75
- if (esc) {
76
- escapeTable(firstChild);
77
- }
78
- }
79
- }
80
- exports.TableBaseToken = TableBaseToken;
81
- constants_1.classes['TableBaseToken'] = __filename;
@@ -1,240 +0,0 @@
1
- import Parser from '../../index';
2
- import { TrBaseToken } from './trBase';
3
- import { SyntaxToken } from '../syntax';
4
- import type { LintError, AST } from '../../base';
5
- import type { SyntaxBase } from '../../mixin/syntax';
6
- import type { AttributesToken, TdToken, TrToken, Token } from '../../internal';
7
- import type { TableCoords } from './trBase';
8
- import type { TdAttrs, TdSubtypes, TdSpanAttrs } from './td';
9
- export interface TableRenderedCoords {
10
- readonly row?: undefined;
11
- readonly column?: undefined;
12
- readonly x: number;
13
- readonly y: number;
14
- }
15
- export interface TableToken extends SyntaxBase {
16
- }
17
- /**
18
- * 是否是行尾
19
- * @param {Token} cell 表格单元格
20
- */
21
- export declare const isRowEnd: ({ type }: Token) => boolean;
22
- /** @extends {Array<TableCoords[]>} */
23
- export declare class Layout extends Array<TableCoords[]> {
24
- /** 打印表格布局 */
25
- print(): void;
26
- }
27
- /**
28
- * 表格
29
- * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken, ...TrToken, ?SyntaxToken]}`
30
- */
31
- export declare abstract class TableToken extends TrBaseToken {
32
- readonly type = "table";
33
- readonly childNodes: readonly [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[], SyntaxToken] | readonly [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[]];
34
- abstract get lastChild(): AttributesToken | TdToken | TrToken | SyntaxToken;
35
- abstract get children(): [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[], SyntaxToken] | [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[]];
36
- abstract get lastElementChild(): AttributesToken | TdToken | TrToken | SyntaxToken;
37
- /** 表格是否闭合 */
38
- get closed(): boolean;
39
- set closed(closed: boolean);
40
- /**
41
- * @param syntax 表格语法
42
- * @param attr 表格属性
43
- */
44
- constructor(syntax: string, attr?: string, config?: Parser.Config, accum?: Token[]);
45
- /**
46
- * 闭合表格语法
47
- * @param syntax 表格结尾语法
48
- * @param halfParsed
49
- */
50
- close(syntax?: string, halfParsed?: boolean): void;
51
- /**
52
- * 获取表格布局
53
- * @param stop 中止条件
54
- * @param stop.row 中止行
55
- * @param stop.column 中止列
56
- * @param stop.x 中止行
57
- * @param stop.y 中止列
58
- */
59
- getLayout(stop?: {
60
- row?: number;
61
- column?: number;
62
- x?: number;
63
- y?: number;
64
- }): Layout;
65
- /** 获取所有行 */
66
- getAllRows(): (TrToken | this)[];
67
- /**
68
- * 获取指定坐标的单元格
69
- * @param coords 表格坐标
70
- */
71
- getNthCell(coords: TableCoords | TableRenderedCoords): TdToken | undefined;
72
- /**
73
- * 获取第n行
74
- * @param n 行号
75
- * @param force 是否将表格自身视为第一行
76
- * @param insert 是否用于判断插入新行的位置
77
- * @throws `RangeError` 不存在该行
78
- */
79
- getNthRow(n: number, force?: boolean, insert?: false): TrToken | this | undefined;
80
- getNthRow(n: number, force: boolean, insert: true): TrToken | this | SyntaxToken | undefined;
81
- /** @override */
82
- json(): AST;
83
- /**
84
- * @override
85
- * @param token 待插入的子节点
86
- * @param i 插入位置
87
- * @throws `SyntaxError` 表格的闭合部分非法
88
- */
89
- insertAt<T extends Token>(token: T, i?: number): T;
90
- /** @override */
91
- getRowCount(): number;
92
- /** 获取下一行 */
93
- getNextRow(): TrToken | undefined;
94
- /** 打印表格布局 */
95
- printLayout(): void;
96
- /**
97
- * 转换为渲染后的表格坐标
98
- * @param {TableCoords} coord wikitext中的表格坐标
99
- */
100
- toRenderedCoords(coord: TableCoords): TableRenderedCoords | undefined;
101
- /**
102
- * 转换为wikitext中的表格坐标
103
- * @param {TableRenderedCoords} coord 渲染后的表格坐标
104
- */
105
- toRawCoords(coord: TableRenderedCoords): TableCoords | undefined;
106
- /**
107
- * 获取完整行
108
- * @param y 行号
109
- */
110
- getFullRow(y: number): Map<TdToken, boolean>;
111
- /**
112
- * 获取完整列
113
- * @param x 列号
114
- */
115
- getFullCol(x: number): Map<TdToken, boolean>;
116
- /**
117
- * 设置行格式
118
- * @param y 行号
119
- * @param attr 表格属性
120
- * @param multiRow 是否对所有单元格设置,或是仅对行首单元格设置
121
- */
122
- formatTableRow(y: number, attr?: TdAttrs | string, multiRow?: boolean): void;
123
- /**
124
- * 设置列格式
125
- * @param x 列号
126
- * @param attr 表格属性
127
- * @param multiCol 是否对所有单元格设置,或是仅对行首单元格设置
128
- */
129
- formatTableCol(x: number, attr?: TdAttrs | string, multiCol?: boolean): void;
130
- /**
131
- * 填补表格行
132
- * @param y 行号
133
- * @param inner 填充内容
134
- * @param subtype 单元格类型
135
- * @param attr 表格属性
136
- */
137
- fillTableRow(y: number, inner: string | Token, subtype?: TdSubtypes, attr?: TdAttrs): void;
138
- /**
139
- * 填补表格
140
- * @param inner 填充内容
141
- * @param subtype 单元格类型
142
- * @param attr 表格属性
143
- */
144
- fillTable(inner: string | Token, subtype?: TdSubtypes, attr?: TdAttrs): void;
145
- /**
146
- * @override
147
- * @param inner 单元格内部wikitext
148
- * @param coords 单元格坐标
149
- * @param subtype 单元格类型
150
- * @param attr 单元格属性
151
- * @throws `RangeError` 指定的坐标不是单元格起始点
152
- */
153
- insertTableCell(inner: string | Token, coords: TableCoords | TableRenderedCoords, subtype?: TdSubtypes, attr?: TdAttrs): TdToken;
154
- /**
155
- * 插入表格行
156
- * @param y 行号
157
- * @param attr 表格行属性
158
- * @param inner 内部wikitext
159
- * @param subtype 单元格类型
160
- * @param innerAttr 单元格属性
161
- */
162
- insertTableRow(y: number, attr?: Record<string, string | true>, inner?: string | Token, subtype?: TdSubtypes, innerAttr?: TdAttrs): TrToken;
163
- /**
164
- * 插入表格列
165
- * @param x 列号
166
- * @param inner 内部wikitext
167
- * @param subtype 单元格类型
168
- * @param attr 单元格属性
169
- * @throws `RangeError` 列号过大
170
- */
171
- insertTableCol(x: number, inner: string | Token, subtype?: TdSubtypes, attr?: TdAttrs): void;
172
- /**
173
- * 移除表格行
174
- * @param y 行号
175
- */
176
- removeTableRow(y: number): TrToken;
177
- /**
178
- * 移除表格列
179
- * @param x 列号
180
- */
181
- removeTableCol(x: number): void;
182
- /**
183
- * 合并单元格
184
- * @param xlim 列范围
185
- * @param ylim 行范围
186
- * @throws `RangeError` 待合并区域与外侧区域有重叠
187
- */
188
- mergeCells(xlim: readonly [number, number], ylim: readonly [number, number]): TdToken;
189
- /**
190
- * 分裂成多行
191
- * @param coords 单元格坐标
192
- */
193
- splitIntoRows(coords: TableCoords | TableRenderedCoords): void;
194
- /**
195
- * 分裂成多列
196
- * @param coords 单元格坐标
197
- */
198
- splitIntoCols(coords: TableCoords | TableRenderedCoords): void;
199
- /**
200
- * 分裂成单元格
201
- * @param coords 单元格坐标
202
- */
203
- splitIntoCells(coords: TableCoords | TableRenderedCoords): void;
204
- /**
205
- * 复制一行并插入该行之前
206
- * @param row 行号
207
- */
208
- replicateTableRow(row: number): TrToken;
209
- /**
210
- * 复制一列并插入该列之前
211
- * @param x 列号
212
- */
213
- replicateTableCol(x: number): TdToken[];
214
- /**
215
- * 移动表格行
216
- * @param y 行号
217
- * @param before 新位置
218
- * @throws `RangeError` 无法移动
219
- */
220
- moveTableRowBefore(y: number, before: number): TrToken;
221
- /**
222
- * 移动表格行
223
- * @param y 行号
224
- * @param after 新位置
225
- * @throws `RangeError` 无法移动
226
- */
227
- moveTableRowAfter(y: number, after: number): TrToken;
228
- /**
229
- * 移动表格列
230
- * @param x 列号
231
- * @param before 新位置
232
- */
233
- moveTableColBefore(x: number, before: number): void;
234
- /**
235
- * 移动表格列
236
- * @param x 列号
237
- * @param after 新位置
238
- */
239
- moveTableColAfter(x: number, after: number): void;
240
- }