wikiparser-node 1.13.1-b → 1.13.1

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 (174) hide show
  1. package/config/.schema.json +203 -0
  2. package/config/default.json +32 -31
  3. package/config/enwiki.json +829 -15
  4. package/config/llwiki.json +56 -21
  5. package/config/moegirl.json +65 -21
  6. package/config/zhwiki.json +498 -32
  7. package/dist/addon/table.js +494 -0
  8. package/dist/addon/token.js +392 -0
  9. package/dist/addon/transclude.js +184 -0
  10. package/dist/base.d.ts +110 -0
  11. package/dist/base.js +67 -0
  12. package/dist/index.d.ts +33 -0
  13. package/dist/index.js +279 -0
  14. package/dist/internal.d.ts +47 -0
  15. package/dist/lib/element.d.ts +125 -0
  16. package/dist/lib/element.js +364 -0
  17. package/dist/lib/node.d.ts +173 -0
  18. package/dist/lib/node.js +478 -0
  19. package/dist/lib/range.d.ts +105 -0
  20. package/dist/lib/range.js +406 -0
  21. package/dist/lib/ranges.d.ts +28 -0
  22. package/dist/lib/ranges.js +126 -0
  23. package/dist/lib/rect.d.ts +18 -0
  24. package/dist/lib/rect.js +36 -0
  25. package/dist/lib/text.d.ts +58 -0
  26. package/dist/lib/text.js +414 -0
  27. package/dist/lib/title.d.ts +49 -0
  28. package/dist/lib/title.js +251 -0
  29. package/dist/mixin/attributesParent.d.ts +49 -0
  30. package/dist/mixin/attributesParent.js +80 -0
  31. package/dist/mixin/fixed.d.ts +5 -0
  32. package/dist/mixin/fixed.js +32 -0
  33. package/dist/mixin/flagsParent.d.ts +43 -0
  34. package/dist/mixin/flagsParent.js +64 -0
  35. package/dist/mixin/hidden.d.ts +7 -0
  36. package/dist/mixin/hidden.js +39 -0
  37. package/dist/mixin/magicLinkParent.d.ts +19 -0
  38. package/dist/mixin/magicLinkParent.js +43 -0
  39. package/dist/mixin/singleLine.d.ts +5 -0
  40. package/dist/mixin/singleLine.js +25 -0
  41. package/dist/mixin/sol.d.ts +6 -0
  42. package/dist/mixin/sol.js +45 -0
  43. package/dist/mixin/syntax.d.ts +8 -0
  44. package/dist/mixin/syntax.js +46 -0
  45. package/dist/parser/braces.js +152 -0
  46. package/dist/parser/commentAndExt.js +84 -0
  47. package/dist/parser/converter.js +41 -0
  48. package/dist/parser/externalLinks.js +39 -0
  49. package/dist/parser/hrAndDoubleUnderscore.js +44 -0
  50. package/dist/parser/html.js +40 -0
  51. package/dist/parser/links.js +103 -0
  52. package/dist/parser/list.js +116 -0
  53. package/dist/parser/magicLinks.js +55 -0
  54. package/dist/parser/quotes.js +69 -0
  55. package/dist/parser/redirect.js +28 -0
  56. package/dist/parser/selector.js +443 -0
  57. package/dist/parser/table.js +125 -0
  58. package/dist/src/arg.d.ts +49 -0
  59. package/dist/src/arg.js +220 -0
  60. package/dist/src/atom.d.ts +14 -0
  61. package/dist/src/atom.js +54 -0
  62. package/dist/src/attribute.d.ts +64 -0
  63. package/dist/src/attribute.js +482 -0
  64. package/dist/src/attributes.d.ts +103 -0
  65. package/dist/src/attributes.js +383 -0
  66. package/dist/src/converter.d.ts +28 -0
  67. package/dist/src/converter.js +153 -0
  68. package/dist/src/converterFlags.d.ts +80 -0
  69. package/dist/src/converterFlags.js +241 -0
  70. package/dist/src/converterRule.d.ts +71 -0
  71. package/dist/src/converterRule.js +218 -0
  72. package/dist/src/extLink.d.ts +36 -0
  73. package/dist/src/extLink.js +223 -0
  74. package/dist/src/gallery.d.ts +51 -0
  75. package/dist/src/gallery.js +166 -0
  76. package/dist/src/heading.d.ts +44 -0
  77. package/dist/src/heading.js +222 -0
  78. package/dist/src/hidden.d.ts +9 -0
  79. package/dist/src/hidden.js +82 -0
  80. package/dist/src/html.d.ts +61 -0
  81. package/dist/src/html.js +344 -0
  82. package/dist/src/imageParameter.d.ts +60 -0
  83. package/dist/src/imageParameter.js +262 -0
  84. package/dist/src/imagemap.d.ts +47 -0
  85. package/dist/src/imagemap.js +148 -0
  86. package/dist/src/imagemapLink.d.ts +35 -0
  87. package/dist/src/imagemapLink.js +99 -0
  88. package/dist/src/index.d.ts +136 -0
  89. package/dist/src/index.js +790 -0
  90. package/dist/src/link/base.d.ts +52 -0
  91. package/dist/src/link/base.js +258 -0
  92. package/dist/src/link/category.d.ts +22 -0
  93. package/dist/src/link/category.js +36 -0
  94. package/dist/src/link/file.d.ts +102 -0
  95. package/dist/src/link/file.js +345 -0
  96. package/dist/src/link/galleryImage.d.ts +29 -0
  97. package/dist/src/link/galleryImage.js +133 -0
  98. package/dist/src/link/index.d.ts +39 -0
  99. package/dist/src/link/index.js +100 -0
  100. package/dist/src/link/redirectTarget.d.ts +27 -0
  101. package/dist/src/link/redirectTarget.js +71 -0
  102. package/dist/src/magicLink.d.ts +57 -0
  103. package/dist/src/magicLink.js +261 -0
  104. package/dist/src/nested.d.ts +40 -0
  105. package/dist/src/nested.js +108 -0
  106. package/dist/src/nowiki/base.d.ts +28 -0
  107. package/dist/src/nowiki/base.js +90 -0
  108. package/dist/src/nowiki/comment.d.ts +14 -0
  109. package/dist/src/nowiki/comment.js +123 -0
  110. package/dist/src/nowiki/dd.d.ts +8 -0
  111. package/dist/src/nowiki/dd.js +74 -0
  112. package/dist/src/nowiki/doubleUnderscore.d.ts +15 -0
  113. package/dist/src/nowiki/doubleUnderscore.js +101 -0
  114. package/dist/src/nowiki/hr.d.ts +5 -0
  115. package/dist/src/nowiki/hr.js +72 -0
  116. package/dist/src/nowiki/index.d.ts +14 -0
  117. package/dist/src/nowiki/index.js +30 -0
  118. package/dist/src/nowiki/list.d.ts +5 -0
  119. package/dist/src/nowiki/list.js +67 -0
  120. package/dist/src/nowiki/listBase.d.ts +23 -0
  121. package/dist/src/nowiki/listBase.js +100 -0
  122. package/dist/src/nowiki/noinclude.d.ts +6 -0
  123. package/dist/src/nowiki/noinclude.js +77 -0
  124. package/dist/src/nowiki/quote.d.ts +14 -0
  125. package/dist/src/nowiki/quote.js +149 -0
  126. package/dist/src/onlyinclude.d.ts +13 -0
  127. package/dist/src/onlyinclude.js +60 -0
  128. package/dist/src/paramTag/index.d.ts +28 -0
  129. package/dist/src/paramTag/index.js +80 -0
  130. package/dist/src/paramTag/inputbox.d.ts +8 -0
  131. package/dist/src/paramTag/inputbox.js +38 -0
  132. package/dist/src/parameter.d.ts +60 -0
  133. package/dist/src/parameter.js +267 -0
  134. package/dist/src/pre.d.ts +28 -0
  135. package/dist/src/pre.js +70 -0
  136. package/dist/src/redirect.d.ts +30 -0
  137. package/dist/src/redirect.js +128 -0
  138. package/dist/src/syntax.d.ts +15 -0
  139. package/dist/src/syntax.js +87 -0
  140. package/dist/src/table/base.d.ts +28 -0
  141. package/dist/src/table/base.js +81 -0
  142. package/dist/src/table/index.d.ts +230 -0
  143. package/dist/src/table/index.js +506 -0
  144. package/dist/src/table/td.d.ts +72 -0
  145. package/dist/src/table/td.js +375 -0
  146. package/dist/src/table/tr.d.ts +30 -0
  147. package/dist/src/table/tr.js +61 -0
  148. package/dist/src/table/trBase.d.ts +49 -0
  149. package/dist/src/table/trBase.js +165 -0
  150. package/dist/src/tagPair/ext.d.ts +29 -0
  151. package/dist/src/tagPair/ext.js +229 -0
  152. package/dist/src/tagPair/include.d.ts +33 -0
  153. package/dist/src/tagPair/include.js +145 -0
  154. package/dist/src/tagPair/index.d.ts +23 -0
  155. package/dist/src/tagPair/index.js +130 -0
  156. package/dist/src/transclude.d.ts +159 -0
  157. package/dist/src/transclude.js +598 -0
  158. package/dist/util/constants.js +26 -0
  159. package/dist/util/debug.js +95 -0
  160. package/dist/util/diff.js +83 -0
  161. package/dist/util/html.js +146 -0
  162. package/dist/util/lint.js +32 -0
  163. package/dist/util/string.js +107 -0
  164. package/errors/README +3 -0
  165. package/package.json +21 -28
  166. package/printed/README +3 -0
  167. package/bundle/bundle.min.js +0 -37
  168. package/extensions/dist/base.js +0 -163
  169. package/extensions/dist/codejar.js +0 -53
  170. package/extensions/dist/editor.js +0 -159
  171. package/extensions/dist/highlight.js +0 -30
  172. package/extensions/dist/lint.js +0 -72
  173. package/extensions/editor.css +0 -59
  174. package/extensions/ui.css +0 -162
package/dist/base.js ADDED
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rules = exports.stages = void 0;
4
+ exports.stages = {
5
+ redirect: 1,
6
+ onlyinclude: 1,
7
+ noinclude: 1,
8
+ include: 1,
9
+ comment: 1,
10
+ ext: 1,
11
+ arg: 2,
12
+ 'magic-word': 2,
13
+ template: 2,
14
+ heading: 2,
15
+ html: 3,
16
+ table: 4,
17
+ hr: 5,
18
+ 'double-underscore': 5,
19
+ link: 6,
20
+ category: 6,
21
+ file: 6,
22
+ quote: 7,
23
+ 'ext-link': 8,
24
+ 'free-ext-link': 9,
25
+ 'magic-link': 9,
26
+ list: 10,
27
+ dd: 10,
28
+ converter: 11,
29
+ };
30
+ Object.setPrototypeOf(exports.stages, null);
31
+ exports.rules = [
32
+ 'bold-header',
33
+ 'format-leakage',
34
+ 'fostered-content',
35
+ 'h1',
36
+ 'illegal-attr',
37
+ 'insecure-style',
38
+ 'invalid-gallery',
39
+ 'invalid-imagemap',
40
+ 'invalid-invoke',
41
+ 'invalid-isbn',
42
+ 'lonely-apos',
43
+ 'lonely-bracket',
44
+ 'lonely-http',
45
+ 'nested-link',
46
+ 'no-arg',
47
+ 'no-duplicate',
48
+ 'no-ignored',
49
+ 'obsolete-attr',
50
+ 'obsolete-tag',
51
+ 'parsing-order',
52
+ 'pipe-like',
53
+ 'table-layout',
54
+ 'tag-like',
55
+ 'unbalanced-header',
56
+ 'unclosed-comment',
57
+ 'unclosed-quote',
58
+ 'unclosed-table',
59
+ 'unescaped',
60
+ 'unknown-page',
61
+ 'unmatched-tag',
62
+ 'unterminated-url',
63
+ 'url-encoding',
64
+ 'var-anchor',
65
+ 'void-ext',
66
+ ];
67
+ Object.freeze(exports.rules);
@@ -0,0 +1,33 @@
1
+ import type { Config, LintError, TokenTypes, Parser as ParserBase, Stage } from './base';
2
+ import type { Title } from './lib/title';
3
+ import type { Token } from './internal';
4
+ declare interface Parser extends ParserBase {
5
+ rules: readonly LintError.Rule[];
6
+ viewOnly: boolean;
7
+ conversionTable: Map<string, string>;
8
+ redirects: Map<string, string>;
9
+ templateDir?: string;
10
+ templates: Map<string, string>;
11
+ warning: boolean;
12
+ debugging: boolean;
13
+ /**
14
+ * 规范化页面标题
15
+ * @param title 标题(含或不含命名空间前缀)
16
+ * @param defaultNs 命名空间
17
+ * @param include 是否嵌入
18
+ */
19
+ normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config): Title;
20
+ parse(wikitext: string, include?: boolean, maxStage?: number | Stage | Stage[], config?: Config): Token;
21
+ /**
22
+ * 是否是跨维基链接
23
+ * @param title 链接标题
24
+ */
25
+ isInterwiki(title: string, config?: Config): RegExpExecArray | null;
26
+ }
27
+ declare const Parser: Parser;
28
+ // @ts-expect-error mixed export styles
29
+ export = Parser;
30
+ export default Parser;
31
+ export type { Config, LintError, TokenTypes };
32
+ export type * from './internal';
33
+ declare global { type Acceptable = unknown; }
package/dist/index.js ADDED
@@ -0,0 +1,279 @@
1
+ "use strict";
2
+ /* eslint n/exports-style: 0 */
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const base_1 = require("./base");
6
+ const debug_1 = require("./util/debug");
7
+ const constants_1 = require("./util/constants");
8
+ const string_1 = require("./util/string");
9
+ /* NOT FOR BROWSER */
10
+ const chalk = require("chalk");
11
+ const diff_1 = require("./util/diff");
12
+ /**
13
+ * 从根路径require
14
+ * @param file 文件名
15
+ * @param dir 子路径
16
+ */
17
+ const rootRequire = (file, dir) => require(path.isAbsolute(file) ? file : path.join('..', file.includes('/') ? '' : dir, file));
18
+ /* NOT FOR BROWSER */
19
+ /**
20
+ * 快速规范化页面标题
21
+ * @param title 标题
22
+ */
23
+ const normalizeTitle = (title) => String(Parser.normalizeTitle(title));
24
+ /** 重定向列表 */
25
+ class RedirectMap extends Map {
26
+ /** @ignore */
27
+ constructor(entries) {
28
+ super();
29
+ if (entries) {
30
+ for (const [k, v] of entries) {
31
+ this.set(k, v);
32
+ }
33
+ }
34
+ }
35
+ set(key, value) {
36
+ return super.set(normalizeTitle(key), normalizeTitle(value));
37
+ }
38
+ }
39
+ const promises = [Promise.resolve()];
40
+ let viewOnly = false, redirectMap = new RedirectMap();
41
+ /* NOT FOR BROWSER END */
42
+ const Parser = {
43
+ config: 'default',
44
+ i18n: undefined,
45
+ rules: base_1.rules,
46
+ /* NOT FOR BROWSER */
47
+ /** @implements */
48
+ get viewOnly() {
49
+ return viewOnly;
50
+ },
51
+ set viewOnly(value) {
52
+ if (viewOnly && !value) {
53
+ debug_1.Shadow.rev++;
54
+ }
55
+ viewOnly = value;
56
+ },
57
+ /** @implements */
58
+ get redirects() {
59
+ return redirectMap;
60
+ },
61
+ set redirects(redirects) {
62
+ redirectMap = new RedirectMap(redirects);
63
+ },
64
+ conversionTable: new Map(),
65
+ templates: new Map(),
66
+ warning: true,
67
+ debugging: false,
68
+ /* NOT FOR BROWSER END */
69
+ /** @implements */
70
+ getConfig() {
71
+ if (typeof this.config === 'string') {
72
+ this.config = rootRequire(this.config, 'config');
73
+ if (this.config.doubleUnderscore.length < 3) {
74
+ (0, diff_1.error)(`The schema (${path.resolve(__dirname, '..', 'config', '.schema.json')}) of parser configuration is updated.`);
75
+ }
76
+ /* NOT FOR BROWSER */
77
+ const { config: { conversionTable, redirects } } = this;
78
+ if (conversionTable) {
79
+ this.conversionTable = new Map(conversionTable);
80
+ }
81
+ if (redirects) {
82
+ this.redirects = new Map(redirects);
83
+ }
84
+ /* NOT FOR BROWSER END */
85
+ return this.getConfig();
86
+ }
87
+ const { doubleUnderscore } = this.config;
88
+ if (doubleUnderscore.length > 2 && doubleUnderscore[0].length === 0) {
89
+ doubleUnderscore[0] = Object.keys(doubleUnderscore[2]);
90
+ }
91
+ return {
92
+ ...this.config,
93
+ excludes: [],
94
+ };
95
+ },
96
+ /** @implements */
97
+ msg(msg, arg = '') {
98
+ if (typeof this.i18n === 'string') {
99
+ this.i18n = rootRequire(this.i18n, 'i18n');
100
+ return this.msg(msg, arg);
101
+ }
102
+ return msg && (this.i18n?.[msg] ?? msg).replace('$1', this.msg(arg));
103
+ },
104
+ /** @implements */
105
+ normalizeTitle(title, defaultNs = 0, include, config = Parser.getConfig(), halfParsed, decode = false, selfLink = false) {
106
+ const { Title } = require('./lib/title');
107
+ let titleObj;
108
+ if (halfParsed) {
109
+ titleObj = new Title(title, defaultNs, config, decode, selfLink);
110
+ }
111
+ else {
112
+ const { Token } = require('./src/index');
113
+ titleObj = debug_1.Shadow.run(() => {
114
+ const root = new Token(title, config);
115
+ root.type = 'root';
116
+ root.parseOnce(0, include).parseOnce();
117
+ const t = new Title(root.toString(), defaultNs, config, decode, selfLink);
118
+ for (const key of ['main', 'fragment']) {
119
+ const str = t[key];
120
+ if (str?.includes('\0')) {
121
+ const s = root.buildFromStr(str, constants_1.BuildMethod.Text);
122
+ if (key === 'main') {
123
+ t.main = s;
124
+ }
125
+ else {
126
+ t.setFragment(s);
127
+ }
128
+ }
129
+ }
130
+ return t;
131
+ });
132
+ }
133
+ /* NOT FOR BROWSER */
134
+ titleObj.conversionTable = this.conversionTable;
135
+ titleObj.redirects = this.redirects;
136
+ /* NOT FOR BROWSER END */
137
+ return titleObj;
138
+ },
139
+ /** @implements */
140
+ parse(wikitext, include, maxStage = constants_1.MAX_STAGE, config = Parser.getConfig()) {
141
+ wikitext = (0, string_1.tidy)(wikitext);
142
+ if (typeof maxStage !== 'number') {
143
+ const types = Array.isArray(maxStage) ? maxStage : [maxStage];
144
+ maxStage = Math.max(...types.map(t => base_1.stages[t] || constants_1.MAX_STAGE));
145
+ }
146
+ const { Token } = require('./src/index');
147
+ const root = debug_1.Shadow.run(() => {
148
+ const token = new Token(wikitext, config);
149
+ token.type = 'root';
150
+ try {
151
+ return token.parse(maxStage, include);
152
+ }
153
+ catch (e) {
154
+ if (e instanceof Error) {
155
+ const file = path.join(__dirname, '..', 'errors', new Date().toISOString()), stage = token.getAttribute('stage');
156
+ fs.writeFileSync(file, stage === constants_1.MAX_STAGE ? wikitext : token.toString());
157
+ fs.writeFileSync(`${file}.err`, e.stack);
158
+ fs.writeFileSync(`${file}.json`, JSON.stringify({ stage, include, config }, null, '\t'));
159
+ }
160
+ throw e;
161
+ }
162
+ });
163
+ /* NOT FOR BROWSER */
164
+ if (this.debugging) {
165
+ let restored = root.toString(), process = 'parsing';
166
+ if (restored === wikitext) {
167
+ const entities = { lt: '<', gt: '>', amp: '&' };
168
+ restored = root.print().replace(/<[^<]+?>|&([lg]t|amp);/gu, (_, s) => s ? entities[s] : '');
169
+ process = 'printing';
170
+ }
171
+ if (restored !== wikitext) {
172
+ const { 0: cur, length } = promises;
173
+ promises.unshift((async () => {
174
+ await cur;
175
+ this.error(`Original wikitext is altered when ${process}!`);
176
+ return (0, diff_1.diff)(wikitext, restored, length);
177
+ })());
178
+ }
179
+ }
180
+ /* NOT FOR BROWSER END */
181
+ return root;
182
+ },
183
+ /* NOT FOR BROWSER */
184
+ /** @implements */
185
+ warn(msg, ...args) {
186
+ if (this.warning) {
187
+ console.warn(chalk.yellow(msg), ...args);
188
+ }
189
+ },
190
+ /** @implements */
191
+ debug(msg, ...args) {
192
+ if (this.debugging) {
193
+ console.debug(chalk.blue(msg), ...args);
194
+ }
195
+ },
196
+ error: diff_1.error,
197
+ info: diff_1.info,
198
+ /** @implements */
199
+ log(f) {
200
+ if (typeof f === 'function') {
201
+ console.log(String(f));
202
+ }
203
+ },
204
+ /** @implements */
205
+ require(name) {
206
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
207
+ return Object.hasOwn(constants_1.classes, name) ? require(constants_1.classes[name])[name] : require(path.join(__dirname, name));
208
+ },
209
+ /** @implements */
210
+ async clearCache() {
211
+ await (0, diff_1.cmd)('npm', ['--prefix', path.join(__dirname, '..'), 'run', 'build:core']);
212
+ const entries = Object.entries(constants_1.classes);
213
+ for (const [, filePath] of entries) {
214
+ try {
215
+ delete require.cache[require.resolve(filePath)];
216
+ }
217
+ catch { }
218
+ }
219
+ for (const [name, filePath] of entries) {
220
+ if (name in global) {
221
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
222
+ Object.assign(global, { [name]: require(filePath)[name] });
223
+ }
224
+ }
225
+ this.info('已重新加载Parser');
226
+ },
227
+ /** @implements */
228
+ isInterwiki(title, { interwiki } = Parser.getConfig()) {
229
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
230
+ /^(zh|en)\s*:/diu;
231
+ return interwiki.length > 0
232
+ ? new RegExp(String.raw `^(${interwiki.join('|')})\s*:`, 'diu')
233
+ .exec(title.replaceAll('_', ' ').replace(/^\s*:?\s*/u, ''))
234
+ : null;
235
+ },
236
+ /** @implements */
237
+ reparse(date = '') {
238
+ const main = fs.readdirSync(path.join(__dirname, '..', 'errors'))
239
+ .find(name => name.startsWith(date) && name.endsWith('Z'));
240
+ if (!main) {
241
+ throw new RangeError(`找不到对应时间戳的错误记录:${date}`);
242
+ }
243
+ const file = path.join(__dirname, '..', 'errors', main), wikitext = fs.readFileSync(file, 'utf8');
244
+ const { stage, include, config } = require(`${file}.json`), { Token } = require('./src/index');
245
+ debug_1.Shadow.run(() => {
246
+ const halfParsed = stage < constants_1.MAX_STAGE, token = new Token(halfParsed ? wikitext : (0, string_1.tidy)(wikitext), config);
247
+ token.type = 'root';
248
+ if (halfParsed) {
249
+ token.setAttribute('stage', stage);
250
+ token.parseOnce(stage, include);
251
+ }
252
+ else {
253
+ token.parse(undefined, include);
254
+ }
255
+ fs.unlinkSync(file);
256
+ fs.unlinkSync(`${file}.err`);
257
+ fs.unlinkSync(`${file}.json`);
258
+ });
259
+ },
260
+ };
261
+ const def = {
262
+ default: { value: Parser },
263
+ }, enumerable = new Set([
264
+ 'normalizeTitle',
265
+ 'parse',
266
+ /* NOT FOR BROWSER */
267
+ 'conversionTable',
268
+ 'warning',
269
+ 'debugging',
270
+ 'isInterwiki',
271
+ ]);
272
+ for (const key in Parser) {
273
+ if (!enumerable.has(key)) {
274
+ def[key] = { enumerable: false };
275
+ }
276
+ }
277
+ Object.defineProperties(Parser, def);
278
+ exports.default = Parser;
279
+ module.exports = Parser;
@@ -0,0 +1,47 @@
1
+ export type { AstNodes, } from './lib/node';
2
+ export type * from './lib/text';
3
+ export type { Token } from './src/index';
4
+ export type * from './src/redirect';
5
+ export type * from './src/link/redirectTarget';
6
+ export type * from './src/onlyinclude';
7
+ export type * from './src/nowiki/noinclude';
8
+ export type * from './src/tagPair/include';
9
+ export type * from './src/nowiki/comment';
10
+ export type * from './src/atom';
11
+ export type { AttributeToken } from './src/attribute';
12
+ export type * from './src/attributes';
13
+ export type * from './src/tagPair/ext';
14
+ export type * from './src/hidden';
15
+ export type * from './src/arg';
16
+ export type * from './src/syntax';
17
+ export type * from './src/parameter';
18
+ export type * from './src/transclude';
19
+ export type * from './src/heading';
20
+ export type * from './src/html';
21
+ export type { TdToken } from './src/table/td';
22
+ export type * from './src/table/tr';
23
+ export type { TableToken } from './src/table/index';
24
+ export type * from './src/nowiki/hr';
25
+ export type * from './src/nowiki/doubleUnderscore';
26
+ export type * from './src/link/index';
27
+ export type * from './src/link/category';
28
+ export type { ImageParameterToken } from './src/imageParameter';
29
+ export type * from './src/link/file';
30
+ export type * from './src/link/galleryImage';
31
+ export type * from './src/nowiki/quote';
32
+ export type * from './src/magicLink';
33
+ export type * from './src/extLink';
34
+ export type { ListRangeToken } from './src/nowiki/listBase';
35
+ export type * from './src/nowiki/dd';
36
+ export type * from './src/nowiki/list';
37
+ export type * from './src/converterFlags';
38
+ export type * from './src/converterRule';
39
+ export type * from './src/converter';
40
+ export type * from './src/nowiki/index';
41
+ export type * from './src/pre';
42
+ export type * from './src/paramTag/index';
43
+ export type * from './src/paramTag/inputbox';
44
+ export type * from './src/nested';
45
+ export type * from './src/gallery';
46
+ export type * from './src/imagemapLink';
47
+ export type * from './src/imagemap';
@@ -0,0 +1,125 @@
1
+ import { AstNode } from './node';
2
+ import type { LintError, AST } from '../base';
3
+ import type { AstNodes, AstText, Token } from '../internal';
4
+ /** 类似HTMLElement */
5
+ export declare abstract class AstElement extends AstNode {
6
+ #private;
7
+ readonly name?: string;
8
+ readonly data: undefined;
9
+ /** 子节点总数 */
10
+ get length(): number;
11
+ set length(n: number);
12
+ /** 全部非文本子节点 */
13
+ get children(): Token[];
14
+ /** 首位非文本子节点 */
15
+ get firstElementChild(): Token | undefined;
16
+ /** 末位非文本子节点 */
17
+ get lastElementChild(): Token | undefined;
18
+ /** 非文本子节点总数 */
19
+ get childElementCount(): number;
20
+ /** 父节点 */
21
+ get parentElement(): Token | undefined;
22
+ /** AstElement.prototype.text()的getter写法 */
23
+ get outerText(): string;
24
+ /** 不可见 */
25
+ get hidden(): boolean;
26
+ /** 内部高度 */
27
+ get clientHeight(): number | undefined;
28
+ /** 内部宽度 */
29
+ get clientWidth(): number | undefined;
30
+ constructor();
31
+ /** 合并相邻的文本子节点 */
32
+ normalize(): void;
33
+ /**
34
+ * 移除子节点
35
+ * @param i 移除位置
36
+ */
37
+ removeAt(i: number): AstNodes;
38
+ /**
39
+ * 插入子节点
40
+ * @param node 待插入的子节点
41
+ * @param i 插入位置
42
+ * @throws `RangeError` 不能插入祖先或子节点
43
+ */
44
+ insertAt<T extends AstNodes>(node: T, i?: number): T;
45
+ /**
46
+ * 最近的祖先节点
47
+ * @param selector 选择器
48
+ */
49
+ closest<T = Token>(selector: string): T | undefined;
50
+ /**
51
+ * 符合选择器的第一个后代节点
52
+ * @param selector 选择器
53
+ */
54
+ querySelector<T = Token>(selector: string): T | undefined;
55
+ /**
56
+ * 符合选择器的所有后代节点
57
+ * @param selector 选择器
58
+ */
59
+ querySelectorAll<T = Token>(selector: string): T[];
60
+ /**
61
+ * 在末尾批量插入子节点
62
+ * @param elements 插入节点
63
+ */
64
+ append(...elements: (AstNodes | string)[]): void;
65
+ /**
66
+ * 批量替换子节点
67
+ * @param elements 新的子节点
68
+ */
69
+ replaceChildren(...elements: (AstNodes | string)[]): void;
70
+ /**
71
+ * 修改文本子节点
72
+ * @param str 新文本
73
+ * @param i 子节点位置
74
+ * @throws `RangeError` 对应位置的子节点不是文本节点
75
+ */
76
+ setText(str: string, i?: number): string;
77
+ /**
78
+ * 保存为JSON
79
+ * @param file 文件名
80
+ * @param start
81
+ */
82
+ json(file?: string, start?: number): AST;
83
+ /**
84
+ * 检查是否符合选择器
85
+ * @param selector 选择器
86
+ */
87
+ matches<T>(selector?: string): this is T;
88
+ /**
89
+ * 类型选择器
90
+ * @param types
91
+ */
92
+ getElementByTypes<T = Token>(types: string): T | undefined;
93
+ /**
94
+ * id选择器
95
+ * @param id id名
96
+ */
97
+ getElementById<T = Token>(id: string): T | undefined;
98
+ /**
99
+ * 类选择器
100
+ * @param className 类名之一
101
+ */
102
+ getElementsByClassName<T = Token>(className: string): T[];
103
+ /**
104
+ * 标签名选择器
105
+ * @param tag 标签名
106
+ */
107
+ getElementsByTagName<T = Token>(tag: string): T[];
108
+ /**
109
+ * 在开头批量插入子节点
110
+ * @param elements 插入节点
111
+ */
112
+ prepend(...elements: (AstNodes | string)[]): void;
113
+ /**
114
+ * 移除子节点
115
+ * @param node 子节点
116
+ */
117
+ removeChild<T extends AstNodes>(node: T): T;
118
+ /**
119
+ * 在指定位置前插入子节点
120
+ * @param child 插入节点
121
+ * @param reference 指定位置处的子节点
122
+ */
123
+ insertBefore(child: string, reference?: AstNodes): AstText;
124
+ insertBefore<T extends AstNodes>(child: T, reference?: AstNodes): T;
125
+ }