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