wikiparser-node 1.4.3 → 1.4.4-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 (166) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/bundle/bundle.min.js +36 -0
  4. package/config/enwiki.json +1 -814
  5. package/config/llwiki.json +1 -35
  6. package/config/moegirl.json +1 -44
  7. package/config/zhwiki.json +1 -466
  8. package/extensions/dist/base.js +64 -0
  9. package/extensions/dist/editor.js +159 -0
  10. package/extensions/dist/highlight.js +59 -0
  11. package/extensions/dist/lint.js +48 -0
  12. package/extensions/editor.css +63 -0
  13. package/extensions/ui.css +141 -0
  14. package/i18n/zh-hans.json +1 -0
  15. package/i18n/zh-hant.json +1 -0
  16. package/package.json +28 -15
  17. package/config/.schema.json +0 -172
  18. package/dist/addon/table.d.ts +0 -6
  19. package/dist/addon/table.js +0 -564
  20. package/dist/base.d.ts +0 -58
  21. package/dist/index.d.ts +0 -30
  22. package/dist/index.js +0 -211
  23. package/dist/internal.d.ts +0 -44
  24. package/dist/lib/element.d.ts +0 -155
  25. package/dist/lib/element.js +0 -650
  26. package/dist/lib/node.d.ts +0 -146
  27. package/dist/lib/node.js +0 -428
  28. package/dist/lib/range.d.ts +0 -104
  29. package/dist/lib/range.js +0 -385
  30. package/dist/lib/ranges.d.ts +0 -26
  31. package/dist/lib/ranges.js +0 -118
  32. package/dist/lib/text.d.ts +0 -62
  33. package/dist/lib/text.js +0 -306
  34. package/dist/lib/title.d.ts +0 -38
  35. package/dist/lib/title.js +0 -164
  36. package/dist/mixin/attributesParent.d.ts +0 -50
  37. package/dist/mixin/attributesParent.js +0 -78
  38. package/dist/mixin/fixed.d.ts +0 -6
  39. package/dist/mixin/fixed.js +0 -30
  40. package/dist/mixin/flagsParent.d.ts +0 -72
  41. package/dist/mixin/flagsParent.js +0 -59
  42. package/dist/mixin/hidden.d.ts +0 -5
  43. package/dist/mixin/hidden.js +0 -24
  44. package/dist/mixin/magicLinkParent.d.ts +0 -40
  45. package/dist/mixin/magicLinkParent.js +0 -42
  46. package/dist/mixin/singleLine.d.ts +0 -6
  47. package/dist/mixin/singleLine.js +0 -26
  48. package/dist/mixin/sol.d.ts +0 -6
  49. package/dist/mixin/sol.js +0 -43
  50. package/dist/mixin/syntax.d.ts +0 -9
  51. package/dist/mixin/syntax.js +0 -50
  52. package/dist/parser/braces.js +0 -131
  53. package/dist/parser/commentAndExt.js +0 -90
  54. package/dist/parser/converter.js +0 -41
  55. package/dist/parser/externalLinks.js +0 -32
  56. package/dist/parser/hrAndDoubleUnderscore.js +0 -41
  57. package/dist/parser/html.js +0 -39
  58. package/dist/parser/links.js +0 -95
  59. package/dist/parser/list.js +0 -68
  60. package/dist/parser/magicLinks.js +0 -43
  61. package/dist/parser/quotes.js +0 -68
  62. package/dist/parser/selector.js +0 -162
  63. package/dist/parser/table.js +0 -124
  64. package/dist/src/arg.d.ts +0 -58
  65. package/dist/src/arg.js +0 -196
  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 -69
  69. package/dist/src/attribute.js +0 -475
  70. package/dist/src/attributes.d.ts +0 -109
  71. package/dist/src/attributes.js +0 -346
  72. package/dist/src/converter.d.ts +0 -33
  73. package/dist/src/converter.js +0 -134
  74. package/dist/src/converterFlags.d.ts +0 -87
  75. package/dist/src/converterFlags.js +0 -226
  76. package/dist/src/converterRule.d.ts +0 -77
  77. package/dist/src/converterRule.js +0 -209
  78. package/dist/src/extLink.d.ts +0 -43
  79. package/dist/src/extLink.js +0 -186
  80. package/dist/src/gallery.d.ts +0 -54
  81. package/dist/src/gallery.js +0 -126
  82. package/dist/src/heading.d.ts +0 -47
  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 -65
  87. package/dist/src/html.js +0 -335
  88. package/dist/src/imageParameter.d.ts +0 -65
  89. package/dist/src/imageParameter.js +0 -248
  90. package/dist/src/imagemap.d.ts +0 -56
  91. package/dist/src/imagemap.js +0 -150
  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 -143
  95. package/dist/src/index.js +0 -803
  96. package/dist/src/link/base.d.ts +0 -52
  97. package/dist/src/link/base.js +0 -209
  98. package/dist/src/link/category.d.ts +0 -13
  99. package/dist/src/link/category.js +0 -28
  100. package/dist/src/link/file.d.ts +0 -96
  101. package/dist/src/link/file.js +0 -265
  102. package/dist/src/link/galleryImage.d.ts +0 -32
  103. package/dist/src/link/galleryImage.js +0 -157
  104. package/dist/src/link/index.d.ts +0 -56
  105. package/dist/src/link/index.js +0 -133
  106. package/dist/src/magicLink.d.ts +0 -59
  107. package/dist/src/magicLink.js +0 -199
  108. package/dist/src/nested.d.ts +0 -43
  109. package/dist/src/nested.js +0 -92
  110. package/dist/src/nowiki/base.d.ts +0 -31
  111. package/dist/src/nowiki/base.js +0 -93
  112. package/dist/src/nowiki/comment.d.ts +0 -25
  113. package/dist/src/nowiki/comment.js +0 -68
  114. package/dist/src/nowiki/dd.d.ts +0 -8
  115. package/dist/src/nowiki/dd.js +0 -24
  116. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -18
  117. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  118. package/dist/src/nowiki/hr.d.ts +0 -5
  119. package/dist/src/nowiki/hr.js +0 -63
  120. package/dist/src/nowiki/index.d.ts +0 -16
  121. package/dist/src/nowiki/index.js +0 -21
  122. package/dist/src/nowiki/list.d.ts +0 -16
  123. package/dist/src/nowiki/list.js +0 -97
  124. package/dist/src/nowiki/listBase.d.ts +0 -5
  125. package/dist/src/nowiki/listBase.js +0 -61
  126. package/dist/src/nowiki/noinclude.d.ts +0 -10
  127. package/dist/src/nowiki/noinclude.js +0 -23
  128. package/dist/src/nowiki/quote.d.ts +0 -14
  129. package/dist/src/nowiki/quote.js +0 -116
  130. package/dist/src/onlyinclude.d.ts +0 -16
  131. package/dist/src/onlyinclude.js +0 -57
  132. package/dist/src/paramTag/index.d.ts +0 -37
  133. package/dist/src/paramTag/index.js +0 -69
  134. package/dist/src/paramTag/inputbox.d.ts +0 -8
  135. package/dist/src/paramTag/inputbox.js +0 -22
  136. package/dist/src/parameter.d.ts +0 -70
  137. package/dist/src/parameter.js +0 -262
  138. package/dist/src/pre.d.ts +0 -28
  139. package/dist/src/pre.js +0 -55
  140. package/dist/src/syntax.d.ts +0 -20
  141. package/dist/src/syntax.js +0 -86
  142. package/dist/src/table/base.d.ts +0 -30
  143. package/dist/src/table/base.js +0 -132
  144. package/dist/src/table/index.d.ts +0 -233
  145. package/dist/src/table/index.js +0 -386
  146. package/dist/src/table/td.d.ts +0 -92
  147. package/dist/src/table/td.js +0 -337
  148. package/dist/src/table/tr.d.ts +0 -32
  149. package/dist/src/table/tr.js +0 -58
  150. package/dist/src/table/trBase.d.ts +0 -53
  151. package/dist/src/table/trBase.js +0 -154
  152. package/dist/src/tagPair/ext.d.ts +0 -32
  153. package/dist/src/tagPair/ext.js +0 -203
  154. package/dist/src/tagPair/include.d.ts +0 -35
  155. package/dist/src/tagPair/include.js +0 -63
  156. package/dist/src/tagPair/index.d.ts +0 -27
  157. package/dist/src/tagPair/index.js +0 -128
  158. package/dist/src/transclude.d.ts +0 -167
  159. package/dist/src/transclude.js +0 -710
  160. package/dist/util/constants.js +0 -113
  161. package/dist/util/debug.js +0 -88
  162. package/dist/util/diff.js +0 -82
  163. package/dist/util/lint.js +0 -30
  164. package/dist/util/string.js +0 -53
  165. package/errors/README +0 -1
  166. package/printed/README +0 -1
package/dist/index.js DELETED
@@ -1,211 +0,0 @@
1
- "use strict";
2
- /* eslint n/exports-style: 0 */
3
- const fs = require("fs");
4
- const path = require("path");
5
- const debug_1 = require("./util/debug");
6
- const constants_1 = require("./util/constants");
7
- const string_1 = require("./util/string");
8
- const diff_1 = require("./util/diff");
9
- /**
10
- * 从根路径require
11
- * @param file 文件名
12
- * @param dir 子路径
13
- */
14
- const rootRequire = (file, dir) => require(file.startsWith('/') ? file : `../${file.includes('/') ? '' : dir}${file}`);
15
- // eslint-disable-next-line @typescript-eslint/no-redeclare
16
- const Parser = {
17
- config: 'default',
18
- i18n: undefined,
19
- /* NOT FOR BROWSER */
20
- conversionTable: new Map(),
21
- redirects: new Map(),
22
- warning: true,
23
- debugging: false,
24
- /* NOT FOR BROWSER END */
25
- /** @implements */
26
- getConfig() {
27
- if (typeof this.config === 'string') {
28
- this.config = rootRequire(this.config, 'config/');
29
- /* NOT FOR BROWSER */
30
- const { config: { conversionTable, redirects } } = this;
31
- if (conversionTable) {
32
- this.conversionTable = new Map(conversionTable);
33
- }
34
- if (redirects) {
35
- this.redirects = new Map(redirects);
36
- }
37
- /* NOT FOR BROWSER END */
38
- return this.getConfig();
39
- }
40
- return {
41
- ...this.config,
42
- excludes: [],
43
- };
44
- },
45
- /** @implements */
46
- msg(msg, arg = '') {
47
- if (typeof this.i18n === 'string') {
48
- this.i18n = rootRequire(this.i18n, 'i18n/');
49
- return this.msg(msg, arg);
50
- }
51
- return msg && (this.i18n?.[msg] ?? msg).replace('$1', this.msg(arg));
52
- },
53
- /** @implements */
54
- normalizeTitle(title, defaultNs = 0, include = false, config = Parser.getConfig(), halfParsed = false, decode = false, selfLink = false) {
55
- const { Title } = require('./lib/title');
56
- if (halfParsed) {
57
- return new Title(title, defaultNs, config, decode, selfLink);
58
- }
59
- const { Token } = require('./src/index');
60
- const token = debug_1.Shadow.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token), defaultNs, config, decode, selfLink);
61
- /* NOT FOR BROWSER */
62
- debug_1.Shadow.run(() => {
63
- for (const key of ['main', 'fragment']) {
64
- const str = titleObj[key];
65
- if (str?.includes('\0')) {
66
- titleObj[key] = token.buildFromStr(str, constants_1.BuildMethod.Text);
67
- }
68
- }
69
- });
70
- titleObj.conversionTable = this.conversionTable;
71
- titleObj.redirects = this.redirects;
72
- /* NOT FOR BROWSER END */
73
- return titleObj;
74
- },
75
- /** @implements */
76
- parse(wikitext, include, maxStage = constants_1.MAX_STAGE, config = Parser.getConfig()) {
77
- wikitext = (0, string_1.tidy)(wikitext);
78
- const { Token } = require('./src/index');
79
- const root = debug_1.Shadow.run(() => {
80
- const token = new Token(wikitext, config);
81
- try {
82
- return token.parse(maxStage, include);
83
- }
84
- catch (e) {
85
- if (e instanceof Error) {
86
- const file = path.join(__dirname, '..', 'errors', new Date().toISOString()), stage = token.getAttribute('stage');
87
- fs.writeFileSync(file, stage === constants_1.MAX_STAGE ? wikitext : String(token));
88
- fs.writeFileSync(`${file}.err`, e.stack);
89
- fs.writeFileSync(`${file}.json`, JSON.stringify({
90
- stage, include: token.getAttribute('include'), config: this.config,
91
- }, null, '\t'));
92
- }
93
- throw e;
94
- }
95
- });
96
- /* NOT FOR BROWSER */
97
- if (this.debugging) {
98
- let restored = String(root), process = '解析';
99
- if (restored === wikitext) {
100
- const entities = { lt: '<', gt: '>', amp: '&' };
101
- restored = root.print().replace(/<[^<]+?>|&([lg]t|amp);/gu, (_, s) => s ? entities[s] : '');
102
- process = '渲染HTML';
103
- }
104
- if (restored !== wikitext) {
105
- const { diff } = require('./util/diff');
106
- const { 0: cur, length } = constants_1.promises;
107
- constants_1.promises.unshift((async () => {
108
- await cur;
109
- this.error(`${process}过程中不可逆地修改了原始文本!`);
110
- return diff(wikitext, restored, length);
111
- })());
112
- }
113
- }
114
- /* NOT FOR BROWSER END */
115
- return root;
116
- },
117
- /* NOT FOR BROWSER */
118
- /** @implements */
119
- warn(msg, ...args) {
120
- if (this.warning) {
121
- console.warn('\x1B[33m%s\x1B[0m', msg, ...args);
122
- }
123
- },
124
- /** @implements */
125
- debug(msg, ...args) {
126
- if (this.debugging) {
127
- console.debug('\x1B[34m%s\x1B[0m', msg, ...args);
128
- }
129
- },
130
- error: diff_1.error,
131
- info: diff_1.info,
132
- /** @implements */
133
- log(f) {
134
- if (typeof f === 'function') {
135
- console.log(String(f));
136
- }
137
- },
138
- /** @implements */
139
- async clearCache() {
140
- const promise = (0, diff_1.cmd)('npm', ['run', 'build']), entries = [
141
- ...Object.entries(constants_1.classes),
142
- ...Object.entries(constants_1.mixins),
143
- ...Object.entries(constants_1.parsers),
144
- ];
145
- for (const [, filePath] of entries) {
146
- try {
147
- delete require.cache[require.resolve(filePath)];
148
- }
149
- catch { }
150
- }
151
- await promise;
152
- for (const [name, filePath] of entries) {
153
- if (name in global) {
154
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
155
- Object.assign(global, { [name]: require(filePath)[name] });
156
- }
157
- }
158
- this.info('已重新加载Parser');
159
- },
160
- /** @implements */
161
- isInterwiki(title, { interwiki } = Parser.getConfig()) {
162
- return interwiki.length > 0
163
- ? new RegExp(`^(${interwiki.join('|')})\\s*:`, 'diu')
164
- .exec(title.replace(/_/gu, ' ').replace(/^\s*:?\s*/u, ''))
165
- : null;
166
- },
167
- /** @implements */
168
- reparse(date) {
169
- const main = fs.readdirSync(path.join(__dirname, '..', 'errors'))
170
- .find(name => name.startsWith(date) && name.endsWith('Z'));
171
- if (!main) {
172
- throw new RangeError(`找不到对应时间戳的错误记录:${date}`);
173
- }
174
- const file = path.join(__dirname, '..', 'errors', main), wikitext = fs.readFileSync(file, 'utf8');
175
- const { stage, include, config } = require(`${file}.json`), { Token } = require('./src');
176
- this.config = config;
177
- return debug_1.Shadow.run(() => {
178
- const halfParsed = stage < constants_1.MAX_STAGE, token = new Token(halfParsed ? wikitext : (0, string_1.tidy)(wikitext), this.getConfig());
179
- if (halfParsed) {
180
- token.setAttribute('stage', stage);
181
- token.parseOnce(stage, include);
182
- }
183
- else {
184
- token.parse(undefined, include);
185
- }
186
- fs.unlinkSync(file);
187
- fs.unlinkSync(`${file}.err`);
188
- fs.unlinkSync(`${file}.json`);
189
- return token;
190
- });
191
- },
192
- };
193
- const def = {
194
- default: { value: Parser },
195
- }, enumerable = new Set([
196
- 'normalizeTitle',
197
- 'parse',
198
- /* NOT FOR BROWSER */
199
- 'conversionTable',
200
- 'redirects',
201
- 'warning',
202
- 'debugging',
203
- 'isInterwiki',
204
- ]);
205
- for (const key in Parser) {
206
- if (!enumerable.has(key)) {
207
- def[key] = { enumerable: false };
208
- }
209
- }
210
- Object.defineProperties(Parser, def);
211
- 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 { TableToken } 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 { ImageParameterToken } 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,155 +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 nextVisibleSibling(): AstNodes | undefined;
27
- /** 前一个可见的兄弟节点 */
28
- get previousVisibleSibling(): AstNodes | undefined;
29
- /** 内部高度 */
30
- get clientHeight(): number | undefined;
31
- /** 内部宽度 */
32
- get clientWidth(): number | undefined;
33
- constructor();
34
- /**
35
- * 可见部分
36
- * @param separator 子节点间的连接符
37
- */
38
- text(separator?: string): string;
39
- /** 合并相邻的文本子节点 */
40
- normalize(): void;
41
- /**
42
- * 移除子节点
43
- * @param i 移除位置
44
- */
45
- removeAt(i: number): AstNodes;
46
- /**
47
- * 插入子节点
48
- * @param node 待插入的子节点
49
- * @param i 插入位置
50
- * @throws `RangeError` 不能插入祖先或子节点
51
- */
52
- insertAt<T extends AstNodes>(node: T, i?: number): T;
53
- /**
54
- * 最近的祖先节点
55
- * @param selector 选择器
56
- */
57
- closest<T = Token>(selector: string): T | undefined;
58
- /**
59
- * 在末尾批量插入子节点
60
- * @param elements 插入节点
61
- */
62
- append(...elements: (AstNodes | string)[]): void;
63
- /**
64
- * 批量替换子节点
65
- * @param elements 新的子节点
66
- */
67
- replaceChildren(...elements: (AstNodes | string)[]): void;
68
- /**
69
- * 修改文本子节点
70
- * @param str 新文本
71
- * @param i 子节点位置
72
- * @throws `RangeError` 对应位置的子节点不是文本节点
73
- */
74
- setText(str: string, i?: number): string;
75
- /**
76
- * @override
77
- * @param start
78
- */
79
- lint(start?: number): LintError[];
80
- /**
81
- * @override
82
- * @param opt 选项
83
- */
84
- print(opt?: PrintOpt): string;
85
- /**
86
- * 保存为JSON
87
- * @param file 文件名
88
- * @param start
89
- */
90
- json(file?: string, start?: number): AST;
91
- /** 销毁 */
92
- destroy(): void;
93
- /**
94
- * 检查是否符合选择器
95
- * @param selector 选择器
96
- */
97
- matches<T>(selector?: string): this is T;
98
- /**
99
- * 符合选择器的第一个后代节点
100
- * @param selector 选择器
101
- */
102
- querySelector<T = Token>(selector: string): T | undefined;
103
- /**
104
- * 类型选择器
105
- * @param types
106
- */
107
- getElementByTypes<T = Token>(types: string): T | undefined;
108
- /**
109
- * id选择器
110
- * @param id id名
111
- */
112
- getElementById<T = Token>(id: string): T | undefined;
113
- /**
114
- * 符合选择器的所有后代节点
115
- * @param selector 选择器
116
- */
117
- querySelectorAll<T = Token>(selector: string): T[];
118
- /**
119
- * 类选择器
120
- * @param className 类名之一
121
- */
122
- getElementsByClassName<T = Token>(className: string): T[];
123
- /**
124
- * 标签名选择器
125
- * @param tag 标签名
126
- */
127
- getElementsByTagName<T = Token>(tag: string): T[];
128
- /**
129
- * 获取某一行的wikitext
130
- * @param n 行号
131
- */
132
- getLine(n: number): string | undefined;
133
- /**
134
- * 在开头批量插入子节点
135
- * @param elements 插入节点
136
- */
137
- prepend(...elements: (AstNodes | string)[]): void;
138
- /**
139
- * 移除子节点
140
- * @param node 子节点
141
- */
142
- removeChild<T extends AstNodes>(node: T): T;
143
- /**
144
- * 在指定位置前插入子节点
145
- * @param child 插入节点
146
- * @param reference 指定位置处的子节点
147
- */
148
- insertBefore(child: string, reference?: AstNodes): AstText;
149
- insertBefore<T extends AstNodes>(child: T, reference?: AstNodes): T;
150
- /**
151
- * 输出AST
152
- * @param depth 当前深度
153
- */
154
- echo(depth?: number): void;
155
- }