wikiparser-node 1.4.2-b → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/config/.schema.json +172 -0
  2. package/config/enwiki.json +814 -1
  3. package/config/llwiki.json +35 -1
  4. package/config/moegirl.json +44 -1
  5. package/config/zhwiki.json +466 -1
  6. package/dist/addon/table.d.ts +6 -0
  7. package/dist/addon/table.js +560 -0
  8. package/dist/base.d.ts +53 -0
  9. package/dist/index.d.ts +32 -0
  10. package/dist/index.js +211 -0
  11. package/dist/internal.d.ts +44 -0
  12. package/dist/lib/element.d.ts +154 -0
  13. package/dist/lib/element.js +643 -0
  14. package/dist/lib/node.d.ts +146 -0
  15. package/dist/lib/node.js +425 -0
  16. package/dist/lib/range.d.ts +104 -0
  17. package/dist/lib/range.js +385 -0
  18. package/dist/lib/ranges.d.ts +26 -0
  19. package/dist/lib/ranges.js +118 -0
  20. package/dist/lib/text.d.ts +62 -0
  21. package/dist/lib/text.js +306 -0
  22. package/dist/lib/title.d.ts +38 -0
  23. package/dist/lib/title.js +172 -0
  24. package/dist/mixin/attributesParent.d.ts +20 -0
  25. package/dist/mixin/attributesParent.js +89 -0
  26. package/dist/mixin/fixed.d.ts +5 -0
  27. package/dist/mixin/fixed.js +28 -0
  28. package/dist/mixin/flagsParent.d.ts +61 -0
  29. package/dist/mixin/flagsParent.js +72 -0
  30. package/dist/mixin/hidden.d.ts +5 -0
  31. package/dist/mixin/hidden.js +24 -0
  32. package/dist/mixin/magicLinkParent.d.ts +34 -0
  33. package/dist/mixin/magicLinkParent.js +43 -0
  34. package/dist/mixin/singleLine.d.ts +5 -0
  35. package/dist/mixin/singleLine.js +25 -0
  36. package/dist/mixin/sol.d.ts +8 -0
  37. package/dist/mixin/sol.js +41 -0
  38. package/dist/mixin/syntax.d.ts +6 -0
  39. package/dist/mixin/syntax.js +54 -0
  40. package/dist/parser/braces.js +131 -0
  41. package/dist/parser/commentAndExt.js +90 -0
  42. package/dist/parser/converter.js +41 -0
  43. package/dist/parser/externalLinks.js +32 -0
  44. package/dist/parser/hrAndDoubleUnderscore.js +41 -0
  45. package/dist/parser/html.js +39 -0
  46. package/dist/parser/links.js +97 -0
  47. package/dist/parser/list.js +68 -0
  48. package/dist/parser/magicLinks.js +43 -0
  49. package/dist/parser/quotes.js +68 -0
  50. package/dist/parser/selector.js +162 -0
  51. package/dist/parser/table.js +124 -0
  52. package/dist/src/arg.d.ts +58 -0
  53. package/dist/src/arg.js +196 -0
  54. package/dist/src/atom.d.ts +12 -0
  55. package/dist/src/atom.js +27 -0
  56. package/dist/src/attribute.d.ts +67 -0
  57. package/dist/src/attribute.js +422 -0
  58. package/dist/src/attributes.d.ts +109 -0
  59. package/dist/src/attributes.js +347 -0
  60. package/dist/src/converter.d.ts +28 -0
  61. package/dist/src/converter.js +85 -0
  62. package/dist/src/converterFlags.d.ts +87 -0
  63. package/dist/src/converterFlags.js +227 -0
  64. package/dist/src/converterRule.d.ts +77 -0
  65. package/dist/src/converterRule.js +210 -0
  66. package/dist/src/extLink.d.ts +38 -0
  67. package/dist/src/extLink.js +137 -0
  68. package/dist/src/gallery.d.ts +54 -0
  69. package/dist/src/gallery.js +127 -0
  70. package/dist/src/heading.d.ts +47 -0
  71. package/dist/src/heading.js +143 -0
  72. package/dist/src/hidden.d.ts +7 -0
  73. package/dist/src/hidden.js +23 -0
  74. package/dist/src/html.d.ts +62 -0
  75. package/dist/src/html.js +286 -0
  76. package/dist/src/imageParameter.d.ts +65 -0
  77. package/dist/src/imageParameter.js +247 -0
  78. package/dist/src/imagemap.d.ts +56 -0
  79. package/dist/src/imagemap.js +156 -0
  80. package/dist/src/imagemapLink.d.ts +28 -0
  81. package/dist/src/imagemapLink.js +44 -0
  82. package/dist/src/index.d.ts +143 -0
  83. package/dist/src/index.js +804 -0
  84. package/dist/src/link/base.d.ts +52 -0
  85. package/dist/src/link/base.js +212 -0
  86. package/dist/src/link/category.d.ts +13 -0
  87. package/dist/src/link/category.js +28 -0
  88. package/dist/src/link/file.d.ts +96 -0
  89. package/dist/src/link/file.js +266 -0
  90. package/dist/src/link/galleryImage.d.ts +31 -0
  91. package/dist/src/link/galleryImage.js +109 -0
  92. package/dist/src/link/index.d.ts +56 -0
  93. package/dist/src/link/index.js +134 -0
  94. package/dist/src/magicLink.d.ts +51 -0
  95. package/dist/src/magicLink.js +149 -0
  96. package/dist/src/nested.d.ts +43 -0
  97. package/dist/src/nested.js +91 -0
  98. package/dist/src/nowiki/base.d.ts +27 -0
  99. package/dist/src/nowiki/base.js +42 -0
  100. package/dist/src/nowiki/comment.d.ts +27 -0
  101. package/dist/src/nowiki/comment.js +77 -0
  102. package/dist/src/nowiki/dd.d.ts +8 -0
  103. package/dist/src/nowiki/dd.js +24 -0
  104. package/dist/src/nowiki/doubleUnderscore.d.ts +18 -0
  105. package/dist/src/nowiki/doubleUnderscore.js +51 -0
  106. package/dist/src/nowiki/hr.d.ts +8 -0
  107. package/dist/src/nowiki/hr.js +14 -0
  108. package/dist/src/nowiki/index.d.ts +16 -0
  109. package/dist/src/nowiki/index.js +20 -0
  110. package/dist/src/nowiki/list.d.ts +19 -0
  111. package/dist/src/nowiki/list.js +48 -0
  112. package/dist/src/nowiki/listBase.d.ts +5 -0
  113. package/dist/src/nowiki/listBase.js +11 -0
  114. package/dist/src/nowiki/noinclude.d.ts +10 -0
  115. package/dist/src/nowiki/noinclude.js +23 -0
  116. package/dist/src/nowiki/quote.d.ts +14 -0
  117. package/dist/src/nowiki/quote.js +68 -0
  118. package/dist/src/onlyinclude.d.ts +16 -0
  119. package/dist/src/onlyinclude.js +57 -0
  120. package/dist/src/paramTag/index.d.ts +37 -0
  121. package/dist/src/paramTag/index.js +68 -0
  122. package/dist/src/paramTag/inputbox.d.ts +8 -0
  123. package/dist/src/paramTag/inputbox.js +22 -0
  124. package/dist/src/parameter.d.ts +67 -0
  125. package/dist/src/parameter.js +213 -0
  126. package/dist/src/pre.d.ts +28 -0
  127. package/dist/src/pre.js +54 -0
  128. package/dist/src/syntax.d.ts +14 -0
  129. package/dist/src/syntax.js +35 -0
  130. package/dist/src/table/base.d.ts +27 -0
  131. package/dist/src/table/base.js +81 -0
  132. package/dist/src/table/index.d.ts +230 -0
  133. package/dist/src/table/index.js +390 -0
  134. package/dist/src/table/td.d.ts +88 -0
  135. package/dist/src/table/td.js +284 -0
  136. package/dist/src/table/tr.d.ts +32 -0
  137. package/dist/src/table/tr.js +57 -0
  138. package/dist/src/table/trBase.d.ts +53 -0
  139. package/dist/src/table/trBase.js +154 -0
  140. package/dist/src/tagPair/ext.d.ts +29 -0
  141. package/dist/src/tagPair/ext.js +153 -0
  142. package/dist/src/tagPair/include.d.ts +37 -0
  143. package/dist/src/tagPair/include.js +71 -0
  144. package/dist/src/tagPair/index.d.ts +27 -0
  145. package/dist/src/tagPair/index.js +79 -0
  146. package/dist/src/transclude.d.ts +167 -0
  147. package/dist/src/transclude.js +715 -0
  148. package/dist/util/constants.js +113 -0
  149. package/dist/util/debug.js +90 -0
  150. package/dist/util/diff.js +82 -0
  151. package/dist/util/lint.js +30 -0
  152. package/dist/util/string.js +53 -0
  153. package/errors/README +1 -0
  154. package/package.json +15 -30
  155. package/printed/README +1 -0
  156. package/bundle/bundle.min.js +0 -36
  157. package/extensions/dist/base.js +0 -64
  158. package/extensions/dist/editor.js +0 -159
  159. package/extensions/dist/highlight.js +0 -59
  160. package/extensions/dist/lint.js +0 -48
  161. package/extensions/editor.css +0 -63
  162. package/extensions/ui.css +0 -141
@@ -0,0 +1,68 @@
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;
@@ -0,0 +1,8 @@
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
+ }
@@ -0,0 +1,22 @@
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;
@@ -0,0 +1,67 @@
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 {};
@@ -0,0 +1,213 @@
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;
@@ -0,0 +1,28 @@
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
+ }
@@ -0,0 +1,54 @@
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;
@@ -0,0 +1,14 @@
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 {};
@@ -0,0 +1,35 @@
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;
@@ -0,0 +1,27 @@
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 {};
@@ -0,0 +1,81 @@
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;