wikiparser-node 1.9.0 → 1.9.1-b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/README.en.md +2 -2
  2. package/bundle/bundle.min.js +38 -0
  3. package/config/enwiki.json +1 -814
  4. package/config/llwiki.json +1 -35
  5. package/config/moegirl.json +1 -44
  6. package/config/zhwiki.json +1 -466
  7. package/extensions/dist/base.js +64 -0
  8. package/extensions/dist/editor.js +159 -0
  9. package/extensions/dist/highlight.js +58 -0
  10. package/extensions/dist/lint.js +72 -0
  11. package/extensions/editor.css +64 -0
  12. package/extensions/ui.css +144 -0
  13. package/package.json +38 -28
  14. package/config/.schema.json +0 -181
  15. package/dist/addon/table.js +0 -485
  16. package/dist/addon/token.js +0 -236
  17. package/dist/addon/transclude.js +0 -183
  18. package/dist/base.d.ts +0 -71
  19. package/dist/base.js +0 -39
  20. package/dist/index.d.ts +0 -33
  21. package/dist/index.js +0 -218
  22. package/dist/internal.d.ts +0 -46
  23. package/dist/lib/element.d.ts +0 -129
  24. package/dist/lib/element.js +0 -593
  25. package/dist/lib/node.d.ts +0 -166
  26. package/dist/lib/node.js +0 -480
  27. package/dist/lib/range.d.ts +0 -105
  28. package/dist/lib/range.js +0 -406
  29. package/dist/lib/ranges.d.ts +0 -28
  30. package/dist/lib/ranges.js +0 -126
  31. package/dist/lib/text.d.ts +0 -54
  32. package/dist/lib/text.js +0 -350
  33. package/dist/lib/title.d.ts +0 -40
  34. package/dist/lib/title.js +0 -197
  35. package/dist/mixin/attributesParent.d.ts +0 -49
  36. package/dist/mixin/attributesParent.js +0 -81
  37. package/dist/mixin/fixed.d.ts +0 -5
  38. package/dist/mixin/fixed.js +0 -30
  39. package/dist/mixin/flagsParent.d.ts +0 -41
  40. package/dist/mixin/flagsParent.js +0 -59
  41. package/dist/mixin/hidden.d.ts +0 -4
  42. package/dist/mixin/hidden.js +0 -24
  43. package/dist/mixin/magicLinkParent.d.ts +0 -19
  44. package/dist/mixin/magicLinkParent.js +0 -42
  45. package/dist/mixin/singleLine.d.ts +0 -5
  46. package/dist/mixin/singleLine.js +0 -26
  47. package/dist/mixin/sol.d.ts +0 -5
  48. package/dist/mixin/sol.js +0 -43
  49. package/dist/mixin/syntax.d.ts +0 -8
  50. package/dist/mixin/syntax.js +0 -50
  51. package/dist/parser/braces.js +0 -139
  52. package/dist/parser/commentAndExt.js +0 -89
  53. package/dist/parser/converter.js +0 -40
  54. package/dist/parser/externalLinks.js +0 -44
  55. package/dist/parser/hrAndDoubleUnderscore.js +0 -40
  56. package/dist/parser/html.js +0 -38
  57. package/dist/parser/links.js +0 -99
  58. package/dist/parser/list.js +0 -97
  59. package/dist/parser/magicLinks.js +0 -59
  60. package/dist/parser/quotes.js +0 -67
  61. package/dist/parser/redirect.js +0 -26
  62. package/dist/parser/selector.js +0 -190
  63. package/dist/parser/table.js +0 -123
  64. package/dist/src/arg.d.ts +0 -54
  65. package/dist/src/arg.js +0 -214
  66. package/dist/src/atom.d.ts +0 -12
  67. package/dist/src/atom.js +0 -27
  68. package/dist/src/attribute.d.ts +0 -67
  69. package/dist/src/attribute.js +0 -502
  70. package/dist/src/attributes.d.ts +0 -105
  71. package/dist/src/attributes.js +0 -356
  72. package/dist/src/converter.d.ts +0 -31
  73. package/dist/src/converter.js +0 -134
  74. package/dist/src/converterFlags.d.ts +0 -83
  75. package/dist/src/converterFlags.js +0 -242
  76. package/dist/src/converterRule.d.ts +0 -75
  77. package/dist/src/converterRule.js +0 -209
  78. package/dist/src/extLink.d.ts +0 -39
  79. package/dist/src/extLink.js +0 -191
  80. package/dist/src/gallery.d.ts +0 -50
  81. package/dist/src/gallery.js +0 -139
  82. package/dist/src/heading.d.ts +0 -43
  83. package/dist/src/heading.js +0 -190
  84. package/dist/src/hidden.d.ts +0 -7
  85. package/dist/src/hidden.js +0 -23
  86. package/dist/src/html.d.ts +0 -61
  87. package/dist/src/html.js +0 -358
  88. package/dist/src/imageParameter.d.ts +0 -61
  89. package/dist/src/imageParameter.js +0 -257
  90. package/dist/src/imagemap.d.ts +0 -50
  91. package/dist/src/imagemap.js +0 -144
  92. package/dist/src/imagemapLink.d.ts +0 -31
  93. package/dist/src/imagemapLink.js +0 -93
  94. package/dist/src/index.d.ts +0 -142
  95. package/dist/src/index.js +0 -717
  96. package/dist/src/link/base.d.ts +0 -48
  97. package/dist/src/link/base.js +0 -228
  98. package/dist/src/link/category.d.ts +0 -22
  99. package/dist/src/link/category.js +0 -30
  100. package/dist/src/link/file.d.ts +0 -96
  101. package/dist/src/link/file.js +0 -272
  102. package/dist/src/link/galleryImage.d.ts +0 -30
  103. package/dist/src/link/galleryImage.js +0 -157
  104. package/dist/src/link/index.d.ts +0 -54
  105. package/dist/src/link/index.js +0 -133
  106. package/dist/src/link/redirectTarget.d.ts +0 -49
  107. package/dist/src/link/redirectTarget.js +0 -101
  108. package/dist/src/magicLink.d.ts +0 -59
  109. package/dist/src/magicLink.js +0 -261
  110. package/dist/src/nested.d.ts +0 -41
  111. package/dist/src/nested.js +0 -105
  112. package/dist/src/nowiki/base.d.ts +0 -31
  113. package/dist/src/nowiki/base.js +0 -93
  114. package/dist/src/nowiki/comment.d.ts +0 -21
  115. package/dist/src/nowiki/comment.js +0 -76
  116. package/dist/src/nowiki/dd.d.ts +0 -8
  117. package/dist/src/nowiki/dd.js +0 -24
  118. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -16
  119. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  120. package/dist/src/nowiki/hr.d.ts +0 -5
  121. package/dist/src/nowiki/hr.js +0 -63
  122. package/dist/src/nowiki/index.d.ts +0 -14
  123. package/dist/src/nowiki/index.js +0 -27
  124. package/dist/src/nowiki/list.d.ts +0 -16
  125. package/dist/src/nowiki/list.js +0 -109
  126. package/dist/src/nowiki/listBase.d.ts +0 -5
  127. package/dist/src/nowiki/listBase.js +0 -61
  128. package/dist/src/nowiki/noinclude.d.ts +0 -10
  129. package/dist/src/nowiki/noinclude.js +0 -23
  130. package/dist/src/nowiki/quote.d.ts +0 -17
  131. package/dist/src/nowiki/quote.js +0 -137
  132. package/dist/src/onlyinclude.d.ts +0 -14
  133. package/dist/src/onlyinclude.js +0 -57
  134. package/dist/src/paramTag/index.d.ts +0 -33
  135. package/dist/src/paramTag/index.js +0 -77
  136. package/dist/src/paramTag/inputbox.d.ts +0 -8
  137. package/dist/src/paramTag/inputbox.js +0 -22
  138. package/dist/src/parameter.d.ts +0 -66
  139. package/dist/src/parameter.js +0 -264
  140. package/dist/src/pre.d.ts +0 -29
  141. package/dist/src/pre.js +0 -59
  142. package/dist/src/redirect.d.ts +0 -28
  143. package/dist/src/redirect.js +0 -119
  144. package/dist/src/syntax.d.ts +0 -17
  145. package/dist/src/syntax.js +0 -86
  146. package/dist/src/table/base.d.ts +0 -27
  147. package/dist/src/table/base.js +0 -81
  148. package/dist/src/table/index.d.ts +0 -240
  149. package/dist/src/table/index.js +0 -498
  150. package/dist/src/table/td.d.ts +0 -82
  151. package/dist/src/table/td.js +0 -358
  152. package/dist/src/table/tr.d.ts +0 -32
  153. package/dist/src/table/tr.js +0 -58
  154. package/dist/src/table/trBase.d.ts +0 -51
  155. package/dist/src/table/trBase.js +0 -156
  156. package/dist/src/tagPair/ext.d.ts +0 -30
  157. package/dist/src/tagPair/ext.js +0 -203
  158. package/dist/src/tagPair/include.d.ts +0 -33
  159. package/dist/src/tagPair/include.js +0 -74
  160. package/dist/src/tagPair/index.d.ts +0 -25
  161. package/dist/src/tagPair/index.js +0 -128
  162. package/dist/src/transclude.d.ts +0 -162
  163. package/dist/src/transclude.js +0 -584
  164. package/dist/util/constants.js +0 -27
  165. package/dist/util/debug.js +0 -81
  166. package/dist/util/diff.js +0 -83
  167. package/dist/util/lint.js +0 -31
  168. package/dist/util/string.js +0 -60
  169. package/errors/README +0 -1
  170. package/printed/README +0 -1
package/dist/index.js DELETED
@@ -1,218 +0,0 @@
1
- "use strict";
2
- /* eslint n/exports-style: 0 */
3
- const fs = require("fs");
4
- const path = require("path");
5
- const chalk = require("chalk");
6
- const base_1 = require("./base");
7
- const debug_1 = require("./util/debug");
8
- const constants_1 = require("./util/constants");
9
- const string_1 = require("./util/string");
10
- const diff_1 = require("./util/diff");
11
- /**
12
- * 从根路径require
13
- * @param file 文件名
14
- * @param dir 子路径
15
- */
16
- const rootRequire = (file, dir) => require(file.startsWith('/') ? file : `../${file.includes('/') ? '' : dir}${file}`);
17
- const promises = [Promise.resolve()];
18
- // eslint-disable-next-line @typescript-eslint/no-redeclare
19
- const Parser = {
20
- config: 'default',
21
- i18n: undefined,
22
- rules: base_1.rules,
23
- /* NOT FOR BROWSER */
24
- viewOnly: false,
25
- conversionTable: new Map(),
26
- redirects: new Map(),
27
- warning: true,
28
- debugging: false,
29
- /* NOT FOR BROWSER END */
30
- /** @implements */
31
- getConfig() {
32
- if (typeof this.config === 'string') {
33
- this.config = rootRequire(this.config, 'config/');
34
- /* NOT FOR BROWSER */
35
- const { config: { conversionTable, redirects } } = this;
36
- if (conversionTable) {
37
- this.conversionTable = new Map(conversionTable);
38
- }
39
- if (redirects) {
40
- this.redirects = new Map(redirects);
41
- }
42
- /* NOT FOR BROWSER END */
43
- return this.getConfig();
44
- }
45
- return {
46
- ...this.config,
47
- excludes: [],
48
- };
49
- },
50
- /** @implements */
51
- msg(msg, arg = '') {
52
- if (typeof this.i18n === 'string') {
53
- this.i18n = rootRequire(this.i18n, 'i18n/');
54
- return this.msg(msg, arg);
55
- }
56
- return msg && (this.i18n?.[msg] ?? msg).replace('$1', this.msg(arg));
57
- },
58
- /** @implements */
59
- normalizeTitle(title, defaultNs = 0, include, config = Parser.getConfig(), halfParsed, decode = false, selfLink = false) {
60
- const { Title } = require('./lib/title');
61
- if (halfParsed) {
62
- return new Title(title, defaultNs, config, decode, selfLink);
63
- }
64
- const { Token } = require('./src/index');
65
- const token = debug_1.Shadow.run(() => {
66
- const root = new Token(title, config);
67
- root.type = 'root';
68
- return root.parseOnce(0, include).parseOnce();
69
- }), titleObj = new Title(token.toString(), defaultNs, config, decode, selfLink);
70
- debug_1.Shadow.run(() => {
71
- for (const key of ['main', 'fragment']) {
72
- const str = titleObj[key];
73
- if (str?.includes('\0')) {
74
- titleObj[key] = token.buildFromStr(str, constants_1.BuildMethod.Text);
75
- }
76
- }
77
- });
78
- /* NOT FOR BROWSER */
79
- titleObj.conversionTable = this.conversionTable;
80
- titleObj.redirects = this.redirects;
81
- /* NOT FOR BROWSER END */
82
- return titleObj;
83
- },
84
- /** @implements */
85
- parse(wikitext, include, maxStage = constants_1.MAX_STAGE, config = Parser.getConfig()) {
86
- wikitext = (0, string_1.tidy)(wikitext);
87
- const { Token } = require('./src/index');
88
- const root = debug_1.Shadow.run(() => {
89
- const token = new Token(wikitext, config);
90
- token.type = 'root';
91
- try {
92
- return token.parse(maxStage, include);
93
- }
94
- catch (e) {
95
- if (e instanceof Error) {
96
- const file = path.join(__dirname, '..', 'errors', new Date().toISOString()), stage = token.getAttribute('stage');
97
- fs.writeFileSync(file, stage === constants_1.MAX_STAGE ? wikitext : token.toString());
98
- fs.writeFileSync(`${file}.err`, e.stack);
99
- fs.writeFileSync(`${file}.json`, JSON.stringify({ stage, include, config }, null, '\t'));
100
- }
101
- throw e;
102
- }
103
- });
104
- /* NOT FOR BROWSER */
105
- if (this.debugging) {
106
- let restored = root.toString(), process = 'parsing';
107
- if (restored === wikitext) {
108
- const entities = { lt: '<', gt: '>', amp: '&' };
109
- restored = root.print().replace(/<[^<]+?>|&([lg]t|amp);/gu, (_, s) => s ? entities[s] : '');
110
- process = 'printing';
111
- }
112
- if (restored !== wikitext) {
113
- const { 0: cur, length } = promises;
114
- promises.unshift((async () => {
115
- await cur;
116
- this.error(`Original wikitext is altered when ${process}!`);
117
- return (0, diff_1.diff)(wikitext, restored, length);
118
- })());
119
- }
120
- }
121
- /* NOT FOR BROWSER END */
122
- return root;
123
- },
124
- /* NOT FOR BROWSER */
125
- /** @implements */
126
- warn(msg, ...args) {
127
- if (this.warning) {
128
- console.warn(chalk.yellow(msg), ...args);
129
- }
130
- },
131
- /** @implements */
132
- debug(msg, ...args) {
133
- if (this.debugging) {
134
- console.debug(chalk.blue(msg), ...args);
135
- }
136
- },
137
- error: diff_1.error,
138
- info: diff_1.info,
139
- /** @implements */
140
- log(f) {
141
- if (typeof f === 'function') {
142
- console.log(String(f));
143
- }
144
- },
145
- /** @implements */
146
- async clearCache() {
147
- const promise = (0, diff_1.cmd)('npm', ['run', 'build']), entries = [
148
- ...Object.entries(constants_1.classes),
149
- ...Object.entries(constants_1.mixins),
150
- ...Object.entries(constants_1.parsers),
151
- ];
152
- for (const [, filePath] of entries) {
153
- try {
154
- delete require.cache[require.resolve(filePath)];
155
- }
156
- catch { }
157
- }
158
- await promise;
159
- for (const [name, filePath] of entries) {
160
- if (name in global) {
161
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
162
- Object.assign(global, { [name]: require(filePath)[name] });
163
- }
164
- }
165
- this.info('已重新加载Parser');
166
- },
167
- /** @implements */
168
- isInterwiki(title, { interwiki } = Parser.getConfig()) {
169
- return interwiki.length > 0
170
- ? new RegExp(`^(${interwiki.join('|')})\\s*:`, 'diu')
171
- .exec(title.replace(/_/gu, ' ').replace(/^\s*:?\s*/u, ''))
172
- : null;
173
- },
174
- /** @implements */
175
- reparse(date = '') {
176
- const main = fs.readdirSync(path.join(__dirname, '..', 'errors'))
177
- .find(name => name.startsWith(date) && name.endsWith('Z'));
178
- if (!main) {
179
- throw new RangeError(`找不到对应时间戳的错误记录:${date}`);
180
- }
181
- const file = path.join(__dirname, '..', 'errors', main), wikitext = fs.readFileSync(file, 'utf8');
182
- const { stage, include, config } = require(`${file}.json`), { Token } = require('./src/index');
183
- return debug_1.Shadow.run(() => {
184
- const halfParsed = stage < constants_1.MAX_STAGE, token = new Token(halfParsed ? wikitext : (0, string_1.tidy)(wikitext), config);
185
- token.type = 'root';
186
- if (halfParsed) {
187
- token.setAttribute('stage', stage);
188
- token.parseOnce(stage, include);
189
- }
190
- else {
191
- token.parse(undefined, include);
192
- }
193
- fs.unlinkSync(file);
194
- fs.unlinkSync(`${file}.err`);
195
- fs.unlinkSync(`${file}.json`);
196
- return token;
197
- });
198
- },
199
- };
200
- const def = {
201
- default: { value: Parser },
202
- }, enumerable = new Set([
203
- 'normalizeTitle',
204
- 'parse',
205
- /* NOT FOR BROWSER */
206
- 'conversionTable',
207
- 'redirects',
208
- 'warning',
209
- 'debugging',
210
- 'isInterwiki',
211
- ]);
212
- for (const key in Parser) {
213
- if (!enumerable.has(key)) {
214
- def[key] = { enumerable: false };
215
- }
216
- }
217
- Object.defineProperties(Parser, def);
218
- module.exports = Parser;
@@ -1,46 +0,0 @@
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 * from './src/nowiki/dd';
35
- export type * from './src/nowiki/list';
36
- export type * from './src/converterFlags';
37
- export type * from './src/converterRule';
38
- export type * from './src/converter';
39
- export type * from './src/nowiki/index';
40
- export type * from './src/pre';
41
- export type * from './src/paramTag/index';
42
- export type * from './src/paramTag/inputbox';
43
- export type * from './src/nested';
44
- export type * from './src/gallery';
45
- export type * from './src/imagemapLink';
46
- export type * from './src/imagemap';
@@ -1,129 +0,0 @@
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
- /** 全部非文本子节点 */
12
- get children(): Token[];
13
- /** 首位非文本子节点 */
14
- get firstElementChild(): Token | undefined;
15
- /** 末位非文本子节点 */
16
- get lastElementChild(): Token | undefined;
17
- /** 非文本子节点总数 */
18
- get childElementCount(): number;
19
- /** 父节点 */
20
- get parentElement(): Token | undefined;
21
- /** AstElement.prototype.text()的getter写法 */
22
- get outerText(): string;
23
- /** 不可见 */
24
- get hidden(): boolean;
25
- /** 内部高度 */
26
- get clientHeight(): number | undefined;
27
- /** 内部宽度 */
28
- get clientWidth(): number | undefined;
29
- constructor();
30
- /**
31
- * 可见部分
32
- * @param separator 子节点间的连接符
33
- */
34
- text(separator?: string): string;
35
- /** 合并相邻的文本子节点 */
36
- normalize(): void;
37
- /**
38
- * 移除子节点
39
- * @param i 移除位置
40
- */
41
- removeAt(i: number): AstNodes;
42
- /**
43
- * 插入子节点
44
- * @param node 待插入的子节点
45
- * @param i 插入位置
46
- * @throws `RangeError` 不能插入祖先或子节点
47
- */
48
- insertAt<T extends AstNodes>(node: T, i?: number): T;
49
- /**
50
- * 最近的祖先节点
51
- * @param selector 选择器
52
- */
53
- closest<T = Token>(selector: string): T | undefined;
54
- /**
55
- * 符合选择器的第一个后代节点
56
- * @param selector 选择器
57
- */
58
- querySelector<T = Token>(selector: string): T | undefined;
59
- /**
60
- * 符合选择器的所有后代节点
61
- * @param selector 选择器
62
- */
63
- querySelectorAll<T = Token>(selector: string): T[];
64
- /**
65
- * 在末尾批量插入子节点
66
- * @param elements 插入节点
67
- */
68
- append(...elements: (AstNodes | string)[]): void;
69
- /**
70
- * 批量替换子节点
71
- * @param elements 新的子节点
72
- */
73
- replaceChildren(...elements: (AstNodes | string)[]): void;
74
- /**
75
- * 修改文本子节点
76
- * @param str 新文本
77
- * @param i 子节点位置
78
- * @throws `RangeError` 对应位置的子节点不是文本节点
79
- */
80
- setText(str: string, i?: number): string;
81
- /**
82
- * 保存为JSON
83
- * @param file 文件名
84
- * @param start
85
- */
86
- json(file?: string, start?: number): AST;
87
- /**
88
- * 检查是否符合选择器
89
- * @param selector 选择器
90
- */
91
- matches<T>(selector?: string): this is T;
92
- /**
93
- * 类型选择器
94
- * @param types
95
- */
96
- getElementByTypes<T = Token>(types: string): T | undefined;
97
- /**
98
- * id选择器
99
- * @param id id名
100
- */
101
- getElementById<T = Token>(id: string): T | undefined;
102
- /**
103
- * 类选择器
104
- * @param className 类名之一
105
- */
106
- getElementsByClassName<T = Token>(className: string): T[];
107
- /**
108
- * 标签名选择器
109
- * @param tag 标签名
110
- */
111
- getElementsByTagName<T = Token>(tag: string): T[];
112
- /**
113
- * 在开头批量插入子节点
114
- * @param elements 插入节点
115
- */
116
- prepend(...elements: (AstNodes | string)[]): void;
117
- /**
118
- * 移除子节点
119
- * @param node 子节点
120
- */
121
- removeChild<T extends AstNodes>(node: T): T;
122
- /**
123
- * 在指定位置前插入子节点
124
- * @param child 插入节点
125
- * @param reference 指定位置处的子节点
126
- */
127
- insertBefore(child: string, reference?: AstNodes): AstText;
128
- insertBefore<T extends AstNodes>(child: T, reference?: AstNodes): T;
129
- }