wikiparser-node 1.4.2 → 1.4.3-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 (162) hide show
  1. package/bundle/bundle.min.js +36 -0
  2. package/config/enwiki.json +1 -814
  3. package/config/llwiki.json +1 -35
  4. package/config/moegirl.json +1 -44
  5. package/config/zhwiki.json +1 -466
  6. package/extensions/dist/base.js +64 -0
  7. package/extensions/dist/editor.js +159 -0
  8. package/extensions/dist/highlight.js +59 -0
  9. package/extensions/dist/lint.js +48 -0
  10. package/extensions/editor.css +63 -0
  11. package/extensions/ui.css +141 -0
  12. package/package.json +30 -15
  13. package/config/.schema.json +0 -172
  14. package/dist/addon/table.d.ts +0 -6
  15. package/dist/addon/table.js +0 -560
  16. package/dist/base.d.ts +0 -53
  17. package/dist/index.d.ts +0 -32
  18. package/dist/index.js +0 -211
  19. package/dist/internal.d.ts +0 -44
  20. package/dist/lib/element.d.ts +0 -154
  21. package/dist/lib/element.js +0 -643
  22. package/dist/lib/node.d.ts +0 -146
  23. package/dist/lib/node.js +0 -425
  24. package/dist/lib/range.d.ts +0 -104
  25. package/dist/lib/range.js +0 -385
  26. package/dist/lib/ranges.d.ts +0 -26
  27. package/dist/lib/ranges.js +0 -118
  28. package/dist/lib/text.d.ts +0 -62
  29. package/dist/lib/text.js +0 -306
  30. package/dist/lib/title.d.ts +0 -38
  31. package/dist/lib/title.js +0 -172
  32. package/dist/mixin/attributesParent.d.ts +0 -20
  33. package/dist/mixin/attributesParent.js +0 -89
  34. package/dist/mixin/fixed.d.ts +0 -5
  35. package/dist/mixin/fixed.js +0 -28
  36. package/dist/mixin/flagsParent.d.ts +0 -61
  37. package/dist/mixin/flagsParent.js +0 -72
  38. package/dist/mixin/hidden.d.ts +0 -5
  39. package/dist/mixin/hidden.js +0 -24
  40. package/dist/mixin/magicLinkParent.d.ts +0 -34
  41. package/dist/mixin/magicLinkParent.js +0 -43
  42. package/dist/mixin/singleLine.d.ts +0 -5
  43. package/dist/mixin/singleLine.js +0 -25
  44. package/dist/mixin/sol.d.ts +0 -8
  45. package/dist/mixin/sol.js +0 -41
  46. package/dist/mixin/syntax.d.ts +0 -6
  47. package/dist/mixin/syntax.js +0 -54
  48. package/dist/parser/braces.js +0 -131
  49. package/dist/parser/commentAndExt.js +0 -90
  50. package/dist/parser/converter.js +0 -41
  51. package/dist/parser/externalLinks.js +0 -32
  52. package/dist/parser/hrAndDoubleUnderscore.js +0 -41
  53. package/dist/parser/html.js +0 -39
  54. package/dist/parser/links.js +0 -97
  55. package/dist/parser/list.js +0 -68
  56. package/dist/parser/magicLinks.js +0 -43
  57. package/dist/parser/quotes.js +0 -68
  58. package/dist/parser/selector.js +0 -162
  59. package/dist/parser/table.js +0 -124
  60. package/dist/src/arg.d.ts +0 -58
  61. package/dist/src/arg.js +0 -196
  62. package/dist/src/atom.d.ts +0 -12
  63. package/dist/src/atom.js +0 -27
  64. package/dist/src/attribute.d.ts +0 -67
  65. package/dist/src/attribute.js +0 -422
  66. package/dist/src/attributes.d.ts +0 -109
  67. package/dist/src/attributes.js +0 -347
  68. package/dist/src/converter.d.ts +0 -28
  69. package/dist/src/converter.js +0 -85
  70. package/dist/src/converterFlags.d.ts +0 -87
  71. package/dist/src/converterFlags.js +0 -227
  72. package/dist/src/converterRule.d.ts +0 -77
  73. package/dist/src/converterRule.js +0 -210
  74. package/dist/src/extLink.d.ts +0 -38
  75. package/dist/src/extLink.js +0 -137
  76. package/dist/src/gallery.d.ts +0 -54
  77. package/dist/src/gallery.js +0 -127
  78. package/dist/src/heading.d.ts +0 -47
  79. package/dist/src/heading.js +0 -143
  80. package/dist/src/hidden.d.ts +0 -7
  81. package/dist/src/hidden.js +0 -23
  82. package/dist/src/html.d.ts +0 -62
  83. package/dist/src/html.js +0 -286
  84. package/dist/src/imageParameter.d.ts +0 -65
  85. package/dist/src/imageParameter.js +0 -247
  86. package/dist/src/imagemap.d.ts +0 -56
  87. package/dist/src/imagemap.js +0 -156
  88. package/dist/src/imagemapLink.d.ts +0 -28
  89. package/dist/src/imagemapLink.js +0 -44
  90. package/dist/src/index.d.ts +0 -143
  91. package/dist/src/index.js +0 -804
  92. package/dist/src/link/base.d.ts +0 -52
  93. package/dist/src/link/base.js +0 -212
  94. package/dist/src/link/category.d.ts +0 -13
  95. package/dist/src/link/category.js +0 -28
  96. package/dist/src/link/file.d.ts +0 -96
  97. package/dist/src/link/file.js +0 -266
  98. package/dist/src/link/galleryImage.d.ts +0 -31
  99. package/dist/src/link/galleryImage.js +0 -109
  100. package/dist/src/link/index.d.ts +0 -56
  101. package/dist/src/link/index.js +0 -134
  102. package/dist/src/magicLink.d.ts +0 -51
  103. package/dist/src/magicLink.js +0 -149
  104. package/dist/src/nested.d.ts +0 -43
  105. package/dist/src/nested.js +0 -91
  106. package/dist/src/nowiki/base.d.ts +0 -27
  107. package/dist/src/nowiki/base.js +0 -42
  108. package/dist/src/nowiki/comment.d.ts +0 -27
  109. package/dist/src/nowiki/comment.js +0 -77
  110. package/dist/src/nowiki/dd.d.ts +0 -8
  111. package/dist/src/nowiki/dd.js +0 -24
  112. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -18
  113. package/dist/src/nowiki/doubleUnderscore.js +0 -51
  114. package/dist/src/nowiki/hr.d.ts +0 -8
  115. package/dist/src/nowiki/hr.js +0 -14
  116. package/dist/src/nowiki/index.d.ts +0 -16
  117. package/dist/src/nowiki/index.js +0 -20
  118. package/dist/src/nowiki/list.d.ts +0 -19
  119. package/dist/src/nowiki/list.js +0 -48
  120. package/dist/src/nowiki/listBase.d.ts +0 -5
  121. package/dist/src/nowiki/listBase.js +0 -11
  122. package/dist/src/nowiki/noinclude.d.ts +0 -10
  123. package/dist/src/nowiki/noinclude.js +0 -23
  124. package/dist/src/nowiki/quote.d.ts +0 -14
  125. package/dist/src/nowiki/quote.js +0 -68
  126. package/dist/src/onlyinclude.d.ts +0 -16
  127. package/dist/src/onlyinclude.js +0 -57
  128. package/dist/src/paramTag/index.d.ts +0 -37
  129. package/dist/src/paramTag/index.js +0 -68
  130. package/dist/src/paramTag/inputbox.d.ts +0 -8
  131. package/dist/src/paramTag/inputbox.js +0 -22
  132. package/dist/src/parameter.d.ts +0 -67
  133. package/dist/src/parameter.js +0 -213
  134. package/dist/src/pre.d.ts +0 -28
  135. package/dist/src/pre.js +0 -54
  136. package/dist/src/syntax.d.ts +0 -14
  137. package/dist/src/syntax.js +0 -35
  138. package/dist/src/table/base.d.ts +0 -27
  139. package/dist/src/table/base.js +0 -81
  140. package/dist/src/table/index.d.ts +0 -230
  141. package/dist/src/table/index.js +0 -390
  142. package/dist/src/table/td.d.ts +0 -88
  143. package/dist/src/table/td.js +0 -284
  144. package/dist/src/table/tr.d.ts +0 -32
  145. package/dist/src/table/tr.js +0 -57
  146. package/dist/src/table/trBase.d.ts +0 -53
  147. package/dist/src/table/trBase.js +0 -154
  148. package/dist/src/tagPair/ext.d.ts +0 -29
  149. package/dist/src/tagPair/ext.js +0 -153
  150. package/dist/src/tagPair/include.d.ts +0 -37
  151. package/dist/src/tagPair/include.js +0 -71
  152. package/dist/src/tagPair/index.d.ts +0 -27
  153. package/dist/src/tagPair/index.js +0 -79
  154. package/dist/src/transclude.d.ts +0 -167
  155. package/dist/src/transclude.js +0 -715
  156. package/dist/util/constants.js +0 -113
  157. package/dist/util/debug.js +0 -90
  158. package/dist/util/diff.js +0 -82
  159. package/dist/util/lint.js +0 -30
  160. package/dist/util/string.js +0 -53
  161. package/errors/README +0 -1
  162. package/printed/README +0 -1
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParamTagToken = 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 singleLine_1 = require("../../mixin/singleLine");
8
- const index_1 = require("../../index");
9
- const index_2 = require("../index");
10
- const atom_1 = require("../atom");
11
- /**
12
- * `<dynamicpagelist>`
13
- * @classdesc `{childNodes: ...AtomToken}`
14
- */
15
- class ParamTagToken extends index_2.Token {
16
- type = 'ext-inner';
17
- /** @class */
18
- constructor(wikitext, config = index_1.default.getConfig(), accum = [], acceptable = {}) {
19
- super(undefined, config, accum, {
20
- SingleLineAtomToken: ':',
21
- });
22
- if (wikitext) {
23
- const SingleLineAtomToken = (0, singleLine_1.singleLine)(atom_1.AtomToken);
24
- this.append(...wikitext.split('\n').map(line => new SingleLineAtomToken(line, 'param-line', config, accum, {
25
- AstText: ':', ...acceptable,
26
- })));
27
- }
28
- }
29
- /** @private */
30
- toString() {
31
- return super.toString('\n');
32
- }
33
- /** @override */
34
- text() {
35
- return super.text('\n');
36
- }
37
- /** @private */
38
- getGaps() {
39
- return 1;
40
- }
41
- /** @override */
42
- lint(start = this.getAbsoluteIndex()) {
43
- let rect;
44
- return this.childNodes.filter(child => {
45
- const { childNodes } = child, i = childNodes.findIndex(({ type }) => type !== 'text'), str = (i >= 0 ? childNodes.slice(0, i).map(String).join('') : String(child)).trim();
46
- return str && !(i >= 0 ? /^[a-z]+(?:\[\])?\s*(?:=|$)/iu : /^[a-z]+(?:\[\])?\s*=/iu).test(str);
47
- }).map(child => {
48
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
49
- return (0, lint_1.generateForChild)(child, rect, index_1.default.msg('invalid parameter of <$1>', this.name));
50
- });
51
- }
52
- /** @override */
53
- print() {
54
- return super.print({ sep: '\n' });
55
- }
56
- /* NOT FOR BROWSER */
57
- /** @override */
58
- cloneNode() {
59
- const cloned = this.cloneChildNodes();
60
- return debug_1.Shadow.run(() => {
61
- const token = new this.constructor(undefined, this.getAttribute('config'));
62
- token.append(...cloned);
63
- return token;
64
- });
65
- }
66
- }
67
- exports.ParamTagToken = ParamTagToken;
68
- constants_1.classes['ParamTagToken'] = __filename;
@@ -1,8 +0,0 @@
1
- import Parser from '../../index';
2
- import { ParamTagToken } from './index';
3
- import type { Token } from '../index';
4
- /** `<inputbox>` */
5
- export declare abstract class InputboxToken extends ParamTagToken {
6
- /** @class */
7
- constructor(wikitext?: string, config?: Parser.Config, accum?: Token[]);
8
- }
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InputboxToken = void 0;
4
- const constants_1 = require("../../util/constants");
5
- const braces_1 = require("../../parser/braces");
6
- const index_1 = require("../../index");
7
- const index_2 = require("./index");
8
- /** `<inputbox>` */
9
- class InputboxToken extends index_2.ParamTagToken {
10
- /** @class */
11
- constructor(wikitext, config = index_1.default.getConfig(), accum = []) {
12
- const placeholder = Symbol('InputboxToken');
13
- accum.push(placeholder);
14
- wikitext &&= (0, braces_1.parseBraces)(wikitext, config, accum);
15
- accum.splice(accum.indexOf(placeholder), 1);
16
- super(wikitext, config, accum, {
17
- ArgToken: ':', TranscludeToken: ':',
18
- });
19
- }
20
- }
21
- exports.InputboxToken = InputboxToken;
22
- constants_1.classes['InputboxToken'] = __filename;
@@ -1,67 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import type { LintError } from '../base';
4
- import type { AtomToken, SyntaxToken, TranscludeToken } from '../internal';
5
- export declare abstract class ParameterToken extends Token {
6
- readonly type = "parameter";
7
- readonly name: string;
8
- readonly childNodes: readonly [Token, Token];
9
- abstract get children(): [Token, Token];
10
- abstract get firstChild(): Token;
11
- abstract get firstElementChild(): Token;
12
- abstract get lastChild(): Token;
13
- abstract get lastElementChild(): Token;
14
- abstract get parentNode(): TranscludeToken | undefined;
15
- abstract get parentElement(): TranscludeToken | undefined;
16
- abstract get nextSibling(): this | undefined;
17
- abstract get nextElementSibling(): this | undefined;
18
- abstract get previousSibling(): AtomToken | SyntaxToken | this;
19
- abstract get previousElementSibling(): AtomToken | SyntaxToken | this;
20
- /** 是否是匿名参数 */
21
- get anon(): boolean;
22
- set anon(value: boolean);
23
- /** getValue()的getter */
24
- get value(): string;
25
- set value(value: string);
26
- /** 是否是重复参数 */
27
- get duplicated(): boolean;
28
- set duplicated(value: boolean);
29
- /**
30
- * @param key 参数名
31
- * @param value 参数值
32
- */
33
- constructor(key?: string | number, value?: string, config?: Parser.Config, accum?: Token[]);
34
- /** @override */
35
- text(): string;
36
- /** @override */
37
- lint(start?: number): LintError[];
38
- /** @override */
39
- print(): string;
40
- /** @override */
41
- json(): object;
42
- /** @override */
43
- cloneNode(): this;
44
- /**
45
- * @override
46
- * @param token 待替换的节点
47
- */
48
- safeReplaceWith(token: this): void;
49
- /** 获取参数值 */
50
- getValue(): string;
51
- /**
52
- * 设置参数值
53
- * @param value 参数值
54
- */
55
- setValue(value: string): void;
56
- /**
57
- * 修改参数名
58
- * @param key 新参数名
59
- * @param force 是否无视冲突命名
60
- * @throws `Error` 仅用于模板参数
61
- * @throws `RangeError` 更名造成重复参数
62
- */
63
- rename(key: string, force?: boolean): void;
64
- /** 转义 `=` */
65
- escape(): void;
66
- }
67
- export {};
@@ -1,213 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParameterToken = void 0;
4
- const string_1 = require("../util/string");
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 index_1 = require("../index");
10
- const index_2 = require("./index");
11
- /**
12
- * 准确获取参数名
13
- * @param name 预定的参数名
14
- */
15
- const getName = (name) => name.text().replace(/^[ \t\n\0\v]+|([^ \t\n\0\v])[ \t\n\0\v]+$/gu, '$1');
16
- /**
17
- * 模板或魔术字参数
18
- * @classdesc `{childNodes: [Token, Token]}`
19
- */
20
- class ParameterToken extends (0, fixed_1.fixedToken)(index_2.Token) {
21
- type = 'parameter';
22
- /** 是否是匿名参数 */
23
- get anon() {
24
- return this.firstChild.length === 0;
25
- }
26
- /* NOT FOR BROWSER */
27
- set anon(value) {
28
- if (value) {
29
- throw new Error('无法将命名参数转换为匿名参数!');
30
- }
31
- this.parentNode?.anonToNamed();
32
- }
33
- /** getValue()的getter */
34
- get value() {
35
- return this.getValue();
36
- }
37
- set value(value) {
38
- this.setValue(value);
39
- }
40
- /** 是否是重复参数 */
41
- get duplicated() {
42
- try {
43
- return Boolean(this.parentNode?.getDuplicatedArgs().some(([key]) => key === this.name));
44
- }
45
- catch {
46
- return false;
47
- }
48
- }
49
- set duplicated(value) {
50
- if (this.duplicated && !value) {
51
- this.parentNode.fixDuplication();
52
- }
53
- }
54
- /* NOT FOR BROWSER END */
55
- /**
56
- * @param key 参数名
57
- * @param value 参数值
58
- */
59
- constructor(key, value, config = index_1.default.getConfig(), accum = []) {
60
- super(undefined, config, accum);
61
- const keyToken = new index_2.Token(typeof key === 'number' ? undefined : key, config, accum, {
62
- 'Stage-11': ':', '!HeadingToken': '',
63
- }), token = new index_2.Token(value, config, accum);
64
- keyToken.type = 'parameter-key';
65
- token.type = 'parameter-value';
66
- token.setAttribute('stage', 2);
67
- this.append(keyToken, token);
68
- }
69
- /** @private */
70
- afterBuild() {
71
- if (!this.anon) {
72
- const { parentNode, firstChild } = this, name = getName(firstChild);
73
- this.setAttribute('name', name);
74
- if (parentNode) {
75
- /* NOT FOR BROWSER */
76
- parentNode.getAttribute('keys').add(name);
77
- /* NOT FOR BROWSER END */
78
- parentNode.getArgs(name, false, false).add(this);
79
- }
80
- }
81
- /* NOT FOR BROWSER */
82
- const /** @implements */ parameterListener = ({ prevTarget }, data) => {
83
- if (!this.anon) { // 匿名参数不管怎么变动还是匿名
84
- const { firstChild, name } = this;
85
- if (prevTarget === firstChild) {
86
- const newKey = getName(firstChild);
87
- data.oldKey = name;
88
- data.newKey = newKey;
89
- this.setAttribute('name', newKey);
90
- }
91
- }
92
- };
93
- this.addEventListener(['remove', 'insert', 'replace', 'text'], parameterListener);
94
- }
95
- /** @private */
96
- toString() {
97
- return this.anon ? String(this.lastChild) : super.toString('=');
98
- }
99
- /** @override */
100
- text() {
101
- return this.anon ? this.lastChild.text() : super.text('=');
102
- }
103
- /** @private */
104
- getGaps() {
105
- return this.anon ? 0 : 1;
106
- }
107
- /** @override */
108
- lint(start = this.getAbsoluteIndex()) {
109
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
110
- /https?:\/\/(?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])(?:[^[\]<>"\0\t\n\p{Zs}]|\0\d+c\x7F)*$/iu;
111
- const errors = super.lint(start), { firstChild } = this, link = new RegExp(`https?://${string_1.extUrlCharFirst}${string_1.extUrlChar}$`, 'iu').exec(firstChild.text())?.[0];
112
- if (link && new URL(link).search) {
113
- const e = (0, lint_1.generateForChild)(firstChild, { start }, 'unescaped query string in an anonymous parameter');
114
- errors.push({
115
- ...e,
116
- startIndex: e.endIndex,
117
- endIndex: e.endIndex + 1,
118
- startLine: e.endLine,
119
- startCol: e.endCol,
120
- endCol: e.endCol + 1,
121
- });
122
- }
123
- return errors;
124
- }
125
- /** @override */
126
- print() {
127
- return super.print({ sep: this.anon ? '' : '=' });
128
- }
129
- /** @override */
130
- json() {
131
- return {
132
- ...super.json(),
133
- anon: this.anon,
134
- };
135
- }
136
- /* NOT FOR BROWSER */
137
- /** @override */
138
- cloneNode() {
139
- const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
140
- return debug_1.Shadow.run(() => {
141
- // @ts-expect-error abstract class
142
- const token = new ParameterToken(this.anon ? Number(this.name) : undefined, undefined, config);
143
- token.firstChild.safeReplaceWith(key);
144
- token.lastChild.safeReplaceWith(value);
145
- token.afterBuild();
146
- if (this.anon) {
147
- token.setAttribute('name', this.name);
148
- }
149
- return token;
150
- });
151
- }
152
- /**
153
- * @override
154
- * @param token 待替换的节点
155
- */
156
- safeReplaceWith(token) {
157
- index_1.default.warn(`${this.constructor.name}.safeReplaceWith 方法退化到 replaceWith。`);
158
- this.replaceWith(token);
159
- }
160
- /** 获取参数值 */
161
- getValue() {
162
- const value = this.lastChild.text();
163
- return this.anon && this.parentNode?.isTemplate() !== false ? value : value.trim();
164
- }
165
- /**
166
- * 设置参数值
167
- * @param value 参数值
168
- */
169
- setValue(value) {
170
- const { childNodes } = index_1.default.parse(value, this.getAttribute('include'), undefined, this.getAttribute('config'));
171
- this.lastChild.replaceChildren(...childNodes);
172
- }
173
- /**
174
- * 修改参数名
175
- * @param key 新参数名
176
- * @param force 是否无视冲突命名
177
- * @throws `Error` 仅用于模板参数
178
- * @throws `RangeError` 更名造成重复参数
179
- */
180
- rename(key, force = false) {
181
- const { parentNode, anon } = this;
182
- // 必须检测是否是TranscludeToken
183
- if (parentNode?.isTemplate() === false) {
184
- throw new Error('rename 方法仅用于模板参数!');
185
- }
186
- else if (anon) {
187
- parentNode?.anonToNamed();
188
- }
189
- const root = index_1.default.parse(key, this.getAttribute('include'), undefined, this.getAttribute('config')), name = getName(root);
190
- if (this.name === name) {
191
- index_1.default.warn('未改变实际参数名', name);
192
- }
193
- else if (parentNode?.hasArg(name)) {
194
- if (force) {
195
- index_1.default.warn('参数更名造成重复参数', name);
196
- }
197
- else {
198
- throw new RangeError(`参数更名造成重复参数:${name}`);
199
- }
200
- }
201
- this.firstChild.replaceChildren(...root.childNodes);
202
- }
203
- /** 转义 `=` */
204
- escape() {
205
- for (const child of this.lastChild.childNodes) {
206
- if (child.type === 'text') {
207
- child.escape();
208
- }
209
- }
210
- }
211
- }
212
- exports.ParameterToken = ParameterToken;
213
- constants_1.classes['ParameterToken'] = __filename;
package/dist/src/pre.d.ts DELETED
@@ -1,28 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import { NoincludeToken } from './nowiki/noinclude';
4
- import type { AstText, AttributesToken, ExtToken, ConverterToken } from '../internal';
5
- /**
6
- * `<pre>`
7
- * @classdesc `{childNodes: [...AstText|NoincludeToken|ConverterToken]}`
8
- */
9
- export declare abstract class PreToken extends Token {
10
- readonly type = "ext-inner";
11
- readonly name: 'pre';
12
- readonly childNodes: readonly (AstText | NoincludeToken | ConverterToken)[];
13
- abstract get children(): (NoincludeToken | ConverterToken)[];
14
- abstract get firstChild(): AstText | NoincludeToken | ConverterToken | undefined;
15
- abstract get firstElementChild(): NoincludeToken | ConverterToken | undefined;
16
- abstract get lastChild(): AstText | NoincludeToken | ConverterToken | undefined;
17
- abstract get lastElementChild(): NoincludeToken | ConverterToken | undefined;
18
- abstract get nextSibling(): undefined;
19
- abstract get nextElementSibling(): undefined;
20
- abstract get previousSibling(): AttributesToken;
21
- abstract get previousElementSibling(): AttributesToken;
22
- abstract get parentNode(): ExtToken | undefined;
23
- abstract get parentElement(): ExtToken | undefined;
24
- /** @class */
25
- constructor(wikitext?: string, config?: Parser.Config, accum?: Token[]);
26
- /** @override */
27
- cloneNode(): this;
28
- }
package/dist/src/pre.js DELETED
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PreToken = void 0;
4
- const constants_1 = require("../util/constants");
5
- const debug_1 = require("../util/debug");
6
- const index_1 = require("../index");
7
- const index_2 = require("./index");
8
- const noinclude_1 = require("./nowiki/noinclude");
9
- /**
10
- * `<pre>`
11
- * @classdesc `{childNodes: [...AstText|NoincludeToken|ConverterToken]}`
12
- */
13
- class PreToken extends index_2.Token {
14
- type = 'ext-inner';
15
- /** @class */
16
- constructor(wikitext, config = index_1.default.getConfig(), accum = []) {
17
- if (wikitext) {
18
- const opening = '<nowiki>', closing = '</nowiki>', { length } = opening;
19
- let i = wikitext.indexOf(opening), j = wikitext.indexOf(closing, i + length), str = '';
20
- while (i !== -1 && j !== -1) {
21
- // @ts-expect-error abstract class
22
- new noinclude_1.NoincludeToken(opening, config, accum);
23
- // @ts-expect-error abstract class
24
- new noinclude_1.NoincludeToken(closing, config, accum);
25
- str += `${wikitext.slice(0, i)}\0${accum.length - 1}c\x7F${wikitext.slice(i + length, j)}\0${accum.length}c\x7F`;
26
- wikitext = wikitext.slice(j + length + 1);
27
- i = wikitext.indexOf(opening);
28
- j = wikitext.indexOf(closing, i + length);
29
- }
30
- wikitext = `${str}${wikitext}`;
31
- }
32
- super(wikitext, config, accum, {
33
- AstText: ':', NoincludeToken: ':', ConverterToken: ':',
34
- });
35
- this.setAttribute('stage', constants_1.MAX_STAGE - 1);
36
- }
37
- /** @private */
38
- getAttribute(key) {
39
- return (key === 'plain') || super.getAttribute(key);
40
- }
41
- /* NOT FOR BROWSER */
42
- /** @override */
43
- cloneNode() {
44
- const cloned = this.cloneChildNodes();
45
- return debug_1.Shadow.run(() => {
46
- // @ts-expect-error abstract class
47
- const token = new PreToken(undefined, this.getAttribute('config'));
48
- token.append(...cloned);
49
- return token;
50
- });
51
- }
52
- }
53
- exports.PreToken = PreToken;
54
- constants_1.classes['PreToken'] = __filename;
@@ -1,14 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import type { LintError } from '../base';
4
- declare type SyntaxTypes = 'plain' | 'heading-trail' | 'magic-word-name' | 'table-syntax';
5
- export declare class SyntaxToken extends Token {
6
- type: SyntaxTypes;
7
- /** @param pattern 语法正则 */
8
- constructor(wikitext: string | undefined, pattern: RegExp, type?: SyntaxTypes, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
9
- /** @override */
10
- lint(): LintError[];
11
- /** @override */
12
- cloneNode(): this;
13
- }
14
- export {};
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SyntaxToken = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- const syntax_1 = require("../mixin/syntax");
7
- const index_1 = require("../index");
8
- const index_2 = require("./index");
9
- /** 满足特定语法格式的plain Token */
10
- class SyntaxToken extends (0, syntax_1.syntax)(index_2.Token) {
11
- /** @param pattern 语法正则 */
12
- constructor(wikitext, pattern, type = 'plain', config = index_1.default.getConfig(), accum = [], acceptable) {
13
- super(wikitext, config, accum, acceptable);
14
- this.type = type;
15
- /* NOT FOR BROWSER */
16
- this.setAttribute('pattern', pattern);
17
- }
18
- /** @override */
19
- lint() {
20
- return [];
21
- }
22
- /* NOT FOR BROWSER */
23
- /** @override */
24
- cloneNode() {
25
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAttribute('acceptable'), pattern = this.getAttribute('pattern');
26
- return debug_1.Shadow.run(() => {
27
- const token = new SyntaxToken(undefined, pattern, this.type, config, [], acceptable);
28
- token.append(...cloned);
29
- token.afterBuild();
30
- return token;
31
- });
32
- }
33
- }
34
- exports.SyntaxToken = SyntaxToken;
35
- 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 children(): [SyntaxToken, AttributesToken, ...Token[]];
12
- abstract get firstChild(): SyntaxToken;
13
- abstract get firstElementChild(): SyntaxToken;
14
- abstract get lastChild(): Token;
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
- : String(child)).join(''), { childNodes } = index_1.default.parse(wikitext, syntax.getAttribute('include'), 2, syntax.getAttribute('config'));
20
- syntax.replaceChildren(...childNodes);
21
- };
22
- /* NOT FOR BROWSER END */
23
- /**
24
- * 表格行,含开头的换行,不含结尾的换行
25
- * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ...Token]}`
26
- */
27
- class TableBaseToken extends (0, attributesParent_1.attributesParent)(index_2.Token, 1) {
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 = false) {
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;