wikiparser-node 1.0.0-beta.5 → 1.0.2-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 (148) hide show
  1. package/bundle/bundle.min.js +37 -0
  2. package/config/llwiki.json +1 -35
  3. package/config/moegirl.json +1 -44
  4. package/config/zhwiki.json +1 -466
  5. package/extensions/dist/base.js +70 -0
  6. package/extensions/dist/editor.js +172 -0
  7. package/extensions/dist/highlight.js +39 -0
  8. package/extensions/dist/lint.js +48 -0
  9. package/extensions/editor.css +63 -0
  10. package/extensions/ui.css +119 -0
  11. package/package.json +24 -12
  12. package/config/.schema.json +0 -160
  13. package/dist/bin/toc.js +0 -18
  14. package/dist/index.d.ts +0 -58
  15. package/dist/index.js +0 -313
  16. package/dist/internal.d.ts +0 -44
  17. package/dist/lib/element.d.ts +0 -167
  18. package/dist/lib/element.js +0 -659
  19. package/dist/lib/node.d.ts +0 -147
  20. package/dist/lib/node.js +0 -428
  21. package/dist/lib/range.d.ts +0 -139
  22. package/dist/lib/range.js +0 -412
  23. package/dist/lib/ranges.d.ts +0 -28
  24. package/dist/lib/ranges.js +0 -123
  25. package/dist/lib/text.d.ts +0 -63
  26. package/dist/lib/text.js +0 -216
  27. package/dist/lib/title.d.ts +0 -20
  28. package/dist/lib/title.js +0 -108
  29. package/dist/mixin/attributesParent.js +0 -92
  30. package/dist/mixin/fixed.js +0 -31
  31. package/dist/mixin/hidden.js +0 -22
  32. package/dist/mixin/singleLine.js +0 -25
  33. package/dist/mixin/sol.js +0 -43
  34. package/dist/mixin/syntax.js +0 -55
  35. package/dist/parser/braces.js +0 -120
  36. package/dist/parser/commentAndExt.js +0 -64
  37. package/dist/parser/converter.js +0 -39
  38. package/dist/parser/externalLinks.js +0 -27
  39. package/dist/parser/hrAndDoubleUnderscore.js +0 -37
  40. package/dist/parser/html.js +0 -35
  41. package/dist/parser/links.js +0 -93
  42. package/dist/parser/list.js +0 -58
  43. package/dist/parser/magicLinks.js +0 -39
  44. package/dist/parser/quotes.js +0 -66
  45. package/dist/parser/selector.js +0 -161
  46. package/dist/parser/table.js +0 -109
  47. package/dist/src/arg.d.ts +0 -58
  48. package/dist/src/arg.js +0 -186
  49. package/dist/src/atom.d.ts +0 -12
  50. package/dist/src/atom.js +0 -25
  51. package/dist/src/attribute.d.ts +0 -86
  52. package/dist/src/attribute.js +0 -417
  53. package/dist/src/attributes.d.ts +0 -108
  54. package/dist/src/attributes.js +0 -354
  55. package/dist/src/converter.d.ts +0 -63
  56. package/dist/src/converter.js +0 -126
  57. package/dist/src/converterFlags.d.ts +0 -84
  58. package/dist/src/converterFlags.js +0 -210
  59. package/dist/src/converterRule.d.ts +0 -84
  60. package/dist/src/converterRule.js +0 -244
  61. package/dist/src/extLink.d.ts +0 -51
  62. package/dist/src/extLink.js +0 -148
  63. package/dist/src/gallery.d.ts +0 -54
  64. package/dist/src/gallery.js +0 -119
  65. package/dist/src/heading.d.ts +0 -73
  66. package/dist/src/heading.js +0 -115
  67. package/dist/src/hidden.d.ts +0 -21
  68. package/dist/src/hidden.js +0 -22
  69. package/dist/src/html.d.ts +0 -100
  70. package/dist/src/html.js +0 -229
  71. package/dist/src/imageParameter.d.ts +0 -63
  72. package/dist/src/imageParameter.js +0 -246
  73. package/dist/src/imagemap.d.ts +0 -57
  74. package/dist/src/imagemap.js +0 -144
  75. package/dist/src/imagemapLink.d.ts +0 -57
  76. package/dist/src/imagemapLink.js +0 -39
  77. package/dist/src/index.d.ts +0 -148
  78. package/dist/src/index.js +0 -783
  79. package/dist/src/link/base.d.ts +0 -55
  80. package/dist/src/link/base.js +0 -221
  81. package/dist/src/link/category.d.ts +0 -13
  82. package/dist/src/link/category.js +0 -29
  83. package/dist/src/link/file.d.ts +0 -88
  84. package/dist/src/link/file.js +0 -251
  85. package/dist/src/link/galleryImage.d.ts +0 -47
  86. package/dist/src/link/galleryImage.js +0 -114
  87. package/dist/src/link/index.d.ts +0 -49
  88. package/dist/src/link/index.js +0 -136
  89. package/dist/src/magicLink.d.ts +0 -62
  90. package/dist/src/magicLink.js +0 -130
  91. package/dist/src/nested.d.ts +0 -44
  92. package/dist/src/nested.js +0 -85
  93. package/dist/src/nowiki/base.d.ts +0 -44
  94. package/dist/src/nowiki/base.js +0 -36
  95. package/dist/src/nowiki/comment.d.ts +0 -34
  96. package/dist/src/nowiki/comment.js +0 -52
  97. package/dist/src/nowiki/dd.d.ts +0 -5
  98. package/dist/src/nowiki/dd.js +0 -18
  99. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -47
  100. package/dist/src/nowiki/doubleUnderscore.js +0 -49
  101. package/dist/src/nowiki/hr.d.ts +0 -32
  102. package/dist/src/nowiki/hr.js +0 -14
  103. package/dist/src/nowiki/index.d.ts +0 -16
  104. package/dist/src/nowiki/index.js +0 -20
  105. package/dist/src/nowiki/list.d.ts +0 -24
  106. package/dist/src/nowiki/list.js +0 -31
  107. package/dist/src/nowiki/listBase.d.ts +0 -29
  108. package/dist/src/nowiki/listBase.js +0 -34
  109. package/dist/src/nowiki/noinclude.d.ts +0 -26
  110. package/dist/src/nowiki/noinclude.js +0 -25
  111. package/dist/src/nowiki/quote.d.ts +0 -22
  112. package/dist/src/nowiki/quote.js +0 -48
  113. package/dist/src/onlyinclude.d.ts +0 -14
  114. package/dist/src/onlyinclude.js +0 -49
  115. package/dist/src/paramTag/index.d.ts +0 -37
  116. package/dist/src/paramTag/index.js +0 -66
  117. package/dist/src/paramTag/inputbox.d.ts +0 -8
  118. package/dist/src/paramTag/inputbox.js +0 -22
  119. package/dist/src/parameter.d.ts +0 -82
  120. package/dist/src/parameter.js +0 -190
  121. package/dist/src/pre.d.ts +0 -28
  122. package/dist/src/pre.js +0 -49
  123. package/dist/src/syntax.d.ts +0 -24
  124. package/dist/src/syntax.js +0 -28
  125. package/dist/src/table/base.d.ts +0 -59
  126. package/dist/src/table/base.js +0 -80
  127. package/dist/src/table/index.d.ts +0 -239
  128. package/dist/src/table/index.js +0 -776
  129. package/dist/src/table/td.d.ts +0 -106
  130. package/dist/src/table/td.js +0 -256
  131. package/dist/src/table/tr.d.ts +0 -30
  132. package/dist/src/table/tr.js +0 -50
  133. package/dist/src/table/trBase.d.ts +0 -54
  134. package/dist/src/table/trBase.js +0 -151
  135. package/dist/src/tagPair/ext.d.ts +0 -56
  136. package/dist/src/tagPair/ext.js +0 -138
  137. package/dist/src/tagPair/include.d.ts +0 -46
  138. package/dist/src/tagPair/include.js +0 -41
  139. package/dist/src/tagPair/index.d.ts +0 -47
  140. package/dist/src/tagPair/index.js +0 -94
  141. package/dist/src/transclude.d.ts +0 -171
  142. package/dist/src/transclude.js +0 -697
  143. package/dist/util/debug.js +0 -42
  144. package/dist/util/diff.js +0 -72
  145. package/dist/util/lint.js +0 -48
  146. package/dist/util/string.js +0 -70
  147. package/errors/README +0 -1
  148. package/printed/README +0 -1
package/dist/bin/toc.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const fs = require("fs");
4
- const path = require("path");
5
- const { argv: [, , filename] } = process;
6
- if (!filename) {
7
- throw new RangeError('请指定文档文件!');
8
- }
9
- const fullpath = path.join(__dirname, '..', '..', 'wiki', `${filename}.md`);
10
- if (!fs.existsSync(fullpath)) {
11
- throw new RangeError(`文档 ${filename}.md 不存在!`);
12
- }
13
- const content = fs.readFileSync(fullpath, 'utf8');
14
- if (/^- \[[^\]]+\]\(#[^)]+\)$/mu.test(content)) {
15
- throw new Error(`文档 ${filename}.md 中已包含目录!`);
16
- }
17
- const toc = content.split('\n').filter(line => line.startsWith('#')).map(line => line.replace(/^(#+)\s+(\S.*)$/u, (_, { length }, title) => `${'\t'.repeat(length - 1)}- [${title}](#${title.toLowerCase().replaceAll(' ', '-').replaceAll('.', '')})`)).join('\n');
18
- fs.writeFileSync(fullpath, `<details>\n\t<summary>目录</summary>\n\n${toc}\n</details>\n\n${content}`);
package/dist/index.d.ts DELETED
@@ -1,58 +0,0 @@
1
- import type { Title } from './lib/title';
2
- import type { Token } from './internal';
3
- export interface Config {
4
- ext: string[];
5
- html: [string[], string[], string[]];
6
- namespaces: Record<string, string>;
7
- nsid: Record<string, number>;
8
- parserFunction: [Record<string, string>, string[], string[], string[]];
9
- doubleUnderscore: [string[], string[]];
10
- protocol: string;
11
- img: Record<string, string>;
12
- variants: string[];
13
- interwiki: string[];
14
- excludes?: string[];
15
- conversionTable?: [string, string][];
16
- redirects?: [string, string][];
17
- }
18
- export interface LintError {
19
- message: string;
20
- severity: 'error' | 'warning';
21
- startIndex: number;
22
- endIndex: number;
23
- startLine: number;
24
- startCol: number;
25
- endLine: number;
26
- endCol: number;
27
- excerpt: string;
28
- }
29
- declare interface Parser {
30
- config: string | Config;
31
- i18n?: string | Record<string, string>;
32
- conversionTable: Map<string, string>;
33
- redirects: Map<string, string>;
34
- /**
35
- * 规范化页面标题
36
- * @param title 标题(含或不含命名空间前缀)
37
- * @param defaultNs 命名空间
38
- * @param include 是否嵌入
39
- * @param halfParsed 是否是半解析状态
40
- * @param decode 是否需要解码
41
- * @param selfLink 是否允许selfLink
42
- */
43
- normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): Title;
44
- /**
45
- * 解析wikitext
46
- * @param include 是否嵌入
47
- * @param maxStage 最大解析层级
48
- */
49
- parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): Token;
50
- /**
51
- * 是否是跨维基链接
52
- * @param title 链接标题
53
- */
54
- isInterwiki(title: string, config?: Config): [string, string] | null;
55
- }
56
- declare const Parser: Parser;
57
- export = Parser;
58
- export type * from './internal';
package/dist/index.js DELETED
@@ -1,313 +0,0 @@
1
- "use strict";
2
- /* eslint n/exports-style: 0 */
3
- const fs = require("fs");
4
- const path = require("path");
5
- const diff_1 = require("./util/diff");
6
- /**
7
- * 从根路径require
8
- * @param file 文件名
9
- * @param dir 子路径
10
- */
11
- const rootRequire = (file, dir) => require(file.startsWith('/') ? file : `../${file.includes('/') ? '' : dir}${file}`);
12
- // eslint-disable-next-line @typescript-eslint/no-redeclare
13
- const Parser = {
14
- config: 'default',
15
- MAX_STAGE: 11,
16
- /* NOT FOR BROWSER */
17
- conversionTable: new Map(),
18
- redirects: new Map(),
19
- warning: true,
20
- debugging: false,
21
- running: false,
22
- classes: {},
23
- mixins: {},
24
- parsers: {},
25
- aliases: [
26
- ['AstText'],
27
- ['CommentToken', 'ExtToken', 'IncludeToken', 'NoincludeToken'],
28
- ['ArgToken', 'TranscludeToken', 'HeadingToken'],
29
- ['HtmlToken'],
30
- ['TableToken'],
31
- ['HrToken', 'DoubleUnderscoreToken'],
32
- ['LinkToken', 'FileToken', 'CategoryToken'],
33
- ['QuoteToken'],
34
- ['ExtLinkToken'],
35
- ['MagicLinkToken'],
36
- ['ListToken', 'DdToken'],
37
- ['ConverterToken'],
38
- ],
39
- typeAliases: {
40
- text: ['string', 'str'],
41
- plain: ['regular', 'normal'],
42
- // comment and extension
43
- onlyinclude: ['only-include'],
44
- noinclude: ['no-include'],
45
- include: ['includeonly', 'include-only'],
46
- comment: undefined,
47
- ext: ['extension'],
48
- 'ext-attrs': ['extension-attrs', 'ext-attributes', 'extension-attributes'],
49
- 'ext-attr-dirty': ['extension-attr-dirty', 'ext-attribute-dirty', 'extension-attribute-dirty'],
50
- 'ext-attr': ['extension-attr', 'ext-attribute', 'extension-attribute'],
51
- 'attr-key': ['attribute-key'],
52
- 'attr-value': ['attribute-value', 'attr-val', 'attribute-val'],
53
- 'ext-inner': ['extension-inner'],
54
- // triple braces
55
- arg: ['argument'],
56
- 'arg-name': ['argument-name'],
57
- 'arg-default': ['argument-default'],
58
- hidden: ['arg-redundant'],
59
- // double braces
60
- 'magic-word': ['parser-function', 'parser-func'],
61
- 'magic-word-name': ['parser-function-name', 'parser-func-name'],
62
- 'invoke-function': ['invoke-func', 'lua-function', 'lua-func', 'module-function', 'module-func'],
63
- 'invoke-module': ['lua-module'],
64
- template: undefined,
65
- 'template-name': undefined,
66
- parameter: ['param'],
67
- 'parameter-key': ['param-key'],
68
- 'parameter-value': ['parameter-val', 'param-value', 'param-val'],
69
- // heading
70
- heading: ['header'],
71
- 'heading-title': ['header-title'],
72
- 'heading-trail': ['header-trail'],
73
- // html
74
- html: undefined,
75
- 'html-attrs': ['html-attributes'],
76
- 'html-attr-dirty': ['html-attribute-dirty'],
77
- 'html-attr': ['html-attribute'],
78
- // table
79
- table: undefined,
80
- tr: ['table-row'],
81
- td: ['table-cell', 'table-data'],
82
- 'table-syntax': undefined,
83
- 'table-attrs': ['tr-attrs', 'td-attrs', 'table-attributes', 'tr-attributes', 'td-attributes'],
84
- 'table-attr-dirty': ['tr-attr-dirty', 'td-attr-dirty', 'table-attribute-dirty', 'tr-attribute-dirty', 'td-attribute-dirty'],
85
- 'table-attr': ['tr-attr', 'td-attr', 'table-attribute', 'tr-attribute', 'td-attribute'],
86
- 'table-inter': undefined,
87
- 'td-inner': ['table-cell-inner', 'table-data-inner'],
88
- // hr and double-underscore
89
- hr: ['horizontal'],
90
- 'double-underscore': ['underscore', 'behavior-switch', 'behaviour-switch'],
91
- // link
92
- link: ['wikilink'],
93
- 'link-target': ['wikilink-target'],
94
- 'link-text': ['wikilink-text'],
95
- category: ['category-link', 'cat', 'cat-link'],
96
- file: ['file-link', 'image', 'image-link', 'img', 'img-link'],
97
- 'gallery-image': ['gallery-file', 'gallery-img'],
98
- 'imagemap-image': ['imagemap-file', 'imagemap-img', 'image-map-image', 'image-map-file', 'image-map-img'],
99
- 'image-parameter': ['img-parameter', 'image-param', 'img-param'],
100
- // quotes
101
- quote: ['quotes', 'quot', 'apostrophe', 'apostrophes', 'apos'],
102
- // external link
103
- 'ext-link': ['external-link'],
104
- 'ext-link-text': ['external-link-text'],
105
- 'ext-link-url': ['external-link-url'],
106
- // magic link
107
- 'free-ext-link': ['free-external-link', 'magic-link'],
108
- // list
109
- list: ['ol', 'ordered-list', 'ul', 'unordered-list', 'dl', 'description-list'],
110
- dd: ['indent', 'indentation'],
111
- // converter
112
- converter: ['convert', 'conversion'],
113
- 'converter-flags': ['convert-flags', 'conversion-flags'],
114
- 'converter-flag': ['convert-flag', 'conversion-flag'],
115
- 'converter-rule': ['convert-rule', 'conversion-rule'],
116
- 'converter-rule-noconvert': ['convert-rule-noconvert', 'conversion-rule-noconvert'],
117
- 'converter-rule-variant': ['convert-rule-variant', 'conversion-rule-variant'],
118
- 'converter-rule-to': ['convert-rule-to', 'conversion-rule-to'],
119
- 'converter-rule-from': ['convert-rule-from', 'conversion-rule-from'],
120
- // specific extensions
121
- 'param-line': ['parameter-line'],
122
- 'imagemap-link': ['image-map-link'],
123
- },
124
- promises: [Promise.resolve()],
125
- /* NOT FOR BROWSER END */
126
- /** @implements */
127
- getConfig() {
128
- if (typeof this.config === 'string') {
129
- this.config = rootRequire(this.config, 'config/');
130
- const { config: { conversionTable, redirects } } = this;
131
- if (conversionTable) {
132
- this.conversionTable = new Map(conversionTable);
133
- }
134
- if (redirects) {
135
- this.redirects = new Map(redirects);
136
- }
137
- return this.getConfig();
138
- }
139
- return { ...this.config, excludes: [] };
140
- },
141
- /** @implements */
142
- msg(msg, arg = '') {
143
- if (typeof this.i18n === 'string') {
144
- this.i18n = rootRequire(this.i18n, 'i18n/');
145
- return this.msg(msg, arg);
146
- }
147
- return (this.i18n?.[msg] ?? msg).replace('$1', arg);
148
- },
149
- /** @implements */
150
- normalizeTitle(title, defaultNs = 0, include = false, config = Parser.getConfig(), halfParsed = false, decode = false, selfLink = false) {
151
- const { Title } = require('./lib/title');
152
- if (halfParsed) {
153
- return new Title(title, defaultNs, config, decode, selfLink);
154
- }
155
- const { Token } = require('./src/index');
156
- const token = this.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token), defaultNs, config, decode, selfLink);
157
- this.run(() => {
158
- for (const key of ['main', 'fragment']) {
159
- if (titleObj[key]?.includes('\0')) {
160
- titleObj[key] = token.buildFromStr(titleObj[key], 'text');
161
- }
162
- }
163
- });
164
- titleObj.conversionTable = this.conversionTable;
165
- titleObj.redirects = this.redirects;
166
- return titleObj;
167
- },
168
- /** @implements */
169
- parse(wikitext, include, maxStage = Parser.MAX_STAGE, config = Parser.getConfig()) {
170
- const { Token } = require('./src/index');
171
- let token;
172
- this.run(() => {
173
- token = new Token(wikitext.replace(/[\0\x7F]/gu, ''), config);
174
- try {
175
- token.parse(maxStage, include);
176
- }
177
- catch (e) {
178
- if (e instanceof Error) {
179
- const file = path.join(__dirname, '..', 'errors', new Date().toISOString()), stage = token.getAttribute('stage');
180
- fs.writeFileSync(file, stage === this.MAX_STAGE ? wikitext : String(token));
181
- fs.writeFileSync(`${file}.err`, e.stack);
182
- fs.writeFileSync(`${file}.json`, JSON.stringify({
183
- stage, include: token.getAttribute('include'), config: this.config,
184
- }, null, '\t'));
185
- }
186
- throw e;
187
- }
188
- });
189
- if (this.debugging) {
190
- let restored = String(token), process = '解析';
191
- if (restored === wikitext) {
192
- const entities = { lt: '<', gt: '>', amp: '&' };
193
- restored = token.print().replace(/<[^<]+?>|&([lg]t|amp);/gu, (_, s) => s ? entities[s] : '');
194
- process = '渲染HTML';
195
- }
196
- if (restored !== wikitext) {
197
- const { diff } = require('./util/diff');
198
- const { promises: { 0: cur, length } } = this;
199
- this.promises.unshift((async () => {
200
- await cur;
201
- this.error(`${process}过程中不可逆地修改了原始文本!`);
202
- return diff(wikitext, restored, length);
203
- })());
204
- }
205
- }
206
- return token;
207
- },
208
- /** @implements */
209
- run(callback) {
210
- const { running } = this;
211
- this.running = true;
212
- try {
213
- const result = callback();
214
- this.running = running;
215
- return result;
216
- }
217
- catch (e) {
218
- this.running = running;
219
- throw e;
220
- }
221
- },
222
- /* NOT FOR BROWSER */
223
- /** @implements */
224
- warn(msg, ...args) {
225
- if (this.warning) {
226
- console.warn('\x1B[33m%s\x1B[0m', msg, ...args);
227
- }
228
- },
229
- /** @implements */
230
- debug(msg, ...args) {
231
- if (this.debugging) {
232
- console.debug('\x1B[34m%s\x1B[0m', msg, ...args);
233
- }
234
- },
235
- /** @implements */
236
- error(msg, ...args) {
237
- console.error('\x1B[31m%s\x1B[0m', msg, ...args);
238
- },
239
- /** @implements */
240
- info(msg, ...args) {
241
- console.info('\x1B[32m%s\x1B[0m', msg, ...args);
242
- },
243
- /** @implements */
244
- log(f) {
245
- if (typeof f === 'function') {
246
- console.log(String(f));
247
- }
248
- },
249
- /** @implements */
250
- async clearCache() {
251
- const promise = (0, diff_1.cmd)('npm', ['run', 'build']), entries = [
252
- ...Object.entries(this.classes),
253
- ...Object.entries(this.mixins),
254
- ...Object.entries(this.parsers),
255
- ];
256
- for (const [, filePath] of entries) {
257
- try {
258
- delete require.cache[require.resolve(filePath)];
259
- }
260
- catch { }
261
- }
262
- await promise;
263
- for (const [name, filePath] of entries) {
264
- if (name in global) {
265
- // @ts-expect-error noImplicitAny
266
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
267
- global[name] = require(filePath)[name];
268
- }
269
- }
270
- this.info('已重新加载Parser');
271
- },
272
- /** @implements */
273
- isInterwiki(title, { interwiki } = Parser.getConfig()) {
274
- return new RegExp(`^(${interwiki.join('|')})\\s*:`, 'iu')
275
- .exec(title.replaceAll('_', ' ').replace(/^\s*:?\s*/u, ''));
276
- },
277
- /** @implements */
278
- reparse(date) {
279
- const main = fs.readdirSync(path.join(__dirname, '..', 'errors'))
280
- .find(name => name.startsWith(date) && name.endsWith('Z'));
281
- if (!main) {
282
- throw new RangeError(`找不到对应时间戳的错误记录:${date}`);
283
- }
284
- const file = path.join(__dirname, '..', 'errors', main), wikitext = fs.readFileSync(file, 'utf8');
285
- const { stage, include, config } = require(`${file}.json`), { Token } = require('./src');
286
- this.config = config;
287
- return this.run(() => {
288
- const halfParsed = stage < this.MAX_STAGE, token = new Token(halfParsed ? wikitext : wikitext.replace(/[\0\x7F]/gu, ''), this.getConfig());
289
- if (halfParsed) {
290
- token.setAttribute('stage', stage);
291
- token.parseOnce(stage, include);
292
- }
293
- else {
294
- token.parse(undefined, include);
295
- }
296
- fs.unlinkSync(file);
297
- fs.unlinkSync(`${file}.err`);
298
- fs.unlinkSync(`${file}.json`);
299
- return token;
300
- });
301
- },
302
- };
303
- const def = {}, immutable = new Set(['MAX_STAGE', 'aliases', 'typeAliases', 'promises']), enumerable = new Set(['config', 'conversionTable', 'redirects', 'normalizeTitle', 'parse', 'isInterwiki']);
304
- for (const key in Parser) {
305
- if (immutable.has(key)) {
306
- def[key] = { enumerable: false, writable: false };
307
- }
308
- else if (!enumerable.has(key)) {
309
- def[key] = { enumerable: false };
310
- }
311
- }
312
- Object.defineProperties(Parser, def);
313
- module.exports = Parser;
@@ -1,44 +0,0 @@
1
- export type { AstNodes, } from './lib/node';
2
- export type * from './lib/text';
3
- export type * from './src/index';
4
- export type * from './src/onlyinclude';
5
- export type * from './src/nowiki/noinclude';
6
- export type * from './src/tagPair/include';
7
- export type * from './src/nowiki/comment';
8
- export type * from './src/atom';
9
- export type { AttributeToken } from './src/attribute';
10
- export type * from './src/attributes';
11
- export type * from './src/tagPair/ext';
12
- export type * from './src/hidden';
13
- export type * from './src/arg';
14
- export type * from './src/syntax';
15
- export type * from './src/parameter';
16
- export type * from './src/transclude';
17
- export type * from './src/heading';
18
- export type * from './src/html';
19
- export type { TdToken } from './src/table/td';
20
- export type * from './src/table/tr';
21
- export type * from './src/table/index';
22
- export type * from './src/nowiki/hr';
23
- export type * from './src/nowiki/doubleUnderscore';
24
- export type * from './src/link/index';
25
- export type * from './src/link/category';
26
- export type * from './src/imageParameter';
27
- export type * from './src/link/file';
28
- export type * from './src/link/galleryImage';
29
- export type * from './src/nowiki/quote';
30
- export type * from './src/magicLink';
31
- export type * from './src/extLink';
32
- export type * from './src/nowiki/dd';
33
- export type * from './src/nowiki/list';
34
- export type * from './src/converterFlags';
35
- export type * from './src/converterRule';
36
- export type * from './src/converter';
37
- export type * from './src/nowiki/index';
38
- export type * from './src/pre';
39
- export type * from './src/paramTag/index';
40
- export type * from './src/paramTag/inputbox';
41
- export type * from './src/nested';
42
- export type * from './src/gallery';
43
- export type * from './src/imagemapLink';
44
- export type * from './src/imagemap';
@@ -1,167 +0,0 @@
1
- import { AstNode } from './node';
2
- import type { LintError } from '../index';
3
- import type { AstNodes, AstText, Token } from '../internal';
4
- /** 类似HTMLElement */
5
- export declare abstract class AstElement extends AstNode {
6
- #private;
7
- name?: string;
8
- /** 子节点总数 */
9
- get length(): number;
10
- /** 全部非文本子节点 */
11
- get children(): Token[];
12
- /** 首位非文本子节点 */
13
- get firstElementChild(): Token | undefined;
14
- /** 末位非文本子节点 */
15
- get lastElementChild(): Token | undefined;
16
- /** 非文本子节点总数 */
17
- get childElementCount(): number;
18
- /** 父节点 */
19
- get parentElement(): Token | undefined;
20
- /** AstElement.prototype.text()的getter写法 */
21
- get outerText(): string;
22
- /** 不可见 */
23
- get hidden(): boolean;
24
- /** 后一个可见的兄弟节点 */
25
- get nextVisibleSibling(): AstNodes | undefined;
26
- /** 前一个可见的兄弟节点 */
27
- get previousVisibleSibling(): AstNodes | undefined;
28
- /** 内部高度 */
29
- get clientHeight(): number | undefined;
30
- /** 内部宽度 */
31
- get clientWidth(): number | undefined;
32
- constructor();
33
- /**
34
- * 可见部分
35
- * @param separator 子节点间的连接符
36
- */
37
- text(separator?: string): string;
38
- /** 合并相邻的文本子节点 */
39
- normalize(): void;
40
- /**
41
- * 移除子节点
42
- * @param i 移除位置
43
- */
44
- removeAt(i: number): AstNodes;
45
- /**
46
- * 插入子节点
47
- * @param node 待插入的子节点
48
- * @param i 插入位置
49
- * @throws `RangeError` 不能插入祖先节点
50
- */
51
- insertAt<T extends AstNodes>(node: T, i?: number): T;
52
- /**
53
- * 最近的祖先节点
54
- * @param selector 选择器
55
- */
56
- closest(selector: string): Token | undefined;
57
- /**
58
- * 在末尾批量插入子节点
59
- * @param elements 插入节点
60
- */
61
- append(...elements: (AstNodes | string)[]): void;
62
- /**
63
- * 批量替换子节点
64
- * @param elements 新的子节点
65
- */
66
- replaceChildren(...elements: (AstNodes | string)[]): void;
67
- /**
68
- * 修改文本子节点
69
- * @param str 新文本
70
- * @param i 子节点位置
71
- * @throws `RangeError` 对应位置的子节点不是文本节点
72
- */
73
- setText(str: string, i?: number): string;
74
- /**
75
- * Linter
76
- * @param start
77
- */
78
- lint(start?: number): LintError[];
79
- /**
80
- * 以HTML格式打印
81
- * @param opt 选项
82
- */
83
- print(opt?: PrintOpt): string;
84
- /**
85
- * 保存为JSON
86
- * @param file 文件名
87
- */
88
- json(file?: string): unknown;
89
- /** 销毁 */
90
- destroy(): void;
91
- /**
92
- * 检查是否符合选择器
93
- * @param selector 选择器
94
- */
95
- matches(selector?: string): boolean;
96
- /**
97
- * 符合选择器的第一个后代节点
98
- * @param selector 选择器
99
- */
100
- querySelector(selector: string): Token | undefined;
101
- /**
102
- * 类型选择器
103
- * @param types
104
- */
105
- getElementByTypes(types: string): Token | undefined;
106
- /**
107
- * id选择器
108
- * @param id id名
109
- */
110
- getElementById(id: string): Token | undefined;
111
- /**
112
- * 符合选择器的所有后代节点
113
- * @param selector 选择器
114
- */
115
- querySelectorAll(selector: string): Token[];
116
- /**
117
- * 类选择器
118
- * @param className 类名之一
119
- */
120
- getElementsByClassName(className: string): Token[];
121
- /**
122
- * 标签名选择器
123
- * @param tag 标签名
124
- */
125
- getElementsByTagName(tag: string): Token[];
126
- /**
127
- * 获取某一行的wikitext
128
- * @param n 行号
129
- */
130
- getLine(n: number): string | undefined;
131
- /**
132
- * 在开头批量插入子节点
133
- * @param elements 插入节点
134
- */
135
- prepend(...elements: (AstNodes | string)[]): void;
136
- /**
137
- * 移除子节点
138
- * @param node 子节点
139
- */
140
- removeChild<T extends AstNodes>(node: T): T;
141
- /**
142
- * 在末尾插入子节点
143
- * @param node 插入节点
144
- */
145
- appendChild(node: string): AstText;
146
- /** @ignore */
147
- appendChild<T extends AstNodes>(node: T): T;
148
- /**
149
- * 在指定位置前插入子节点
150
- * @param child 插入节点
151
- * @param reference 指定位置处的子节点
152
- */
153
- insertBefore(child: string, reference?: AstNodes): AstText;
154
- /** @ignore */
155
- insertBefore<T extends AstNodes>(child: T, reference?: AstNodes): T;
156
- /**
157
- * 替换子节点
158
- * @param newChild 新子节点
159
- * @param oldChild 原子节点
160
- */
161
- replaceChild<T extends AstNodes>(newChild: AstNodes | string, oldChild: T): T;
162
- /**
163
- * 输出AST
164
- * @param depth 当前深度
165
- */
166
- echo(depth?: number): void;
167
- }