wikiparser-node 1.10.0 → 1.11.0-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 (173) hide show
  1. package/bundle/bundle.min.js +38 -0
  2. package/config/enwiki.json +1 -814
  3. package/config/llwiki.json +1 -35
  4. package/config/moegirl.json +1 -44
  5. package/config/zhwiki.json +1 -466
  6. package/extensions/dist/base.js +64 -0
  7. package/extensions/dist/editor.js +159 -0
  8. package/extensions/dist/highlight.js +56 -0
  9. package/extensions/dist/lint.js +72 -0
  10. package/extensions/editor.css +64 -0
  11. package/extensions/ui.css +144 -0
  12. package/i18n/zh-hans.json +1 -1
  13. package/i18n/zh-hant.json +1 -1
  14. package/package.json +43 -33
  15. package/config/.schema.json +0 -186
  16. package/dist/addon/table.js +0 -486
  17. package/dist/addon/token.js +0 -324
  18. package/dist/addon/transclude.js +0 -185
  19. package/dist/base.d.ts +0 -81
  20. package/dist/base.js +0 -39
  21. package/dist/index.d.ts +0 -33
  22. package/dist/index.js +0 -231
  23. package/dist/internal.d.ts +0 -46
  24. package/dist/lib/element.d.ts +0 -125
  25. package/dist/lib/element.js +0 -374
  26. package/dist/lib/node.d.ts +0 -173
  27. package/dist/lib/node.js +0 -478
  28. package/dist/lib/range.d.ts +0 -105
  29. package/dist/lib/range.js +0 -406
  30. package/dist/lib/ranges.d.ts +0 -28
  31. package/dist/lib/ranges.js +0 -126
  32. package/dist/lib/rect.d.ts +0 -18
  33. package/dist/lib/rect.js +0 -34
  34. package/dist/lib/text.d.ts +0 -58
  35. package/dist/lib/text.js +0 -361
  36. package/dist/lib/title.d.ts +0 -42
  37. package/dist/lib/title.js +0 -205
  38. package/dist/mixin/attributesParent.d.ts +0 -49
  39. package/dist/mixin/attributesParent.js +0 -79
  40. package/dist/mixin/fixed.d.ts +0 -5
  41. package/dist/mixin/fixed.js +0 -32
  42. package/dist/mixin/flagsParent.d.ts +0 -41
  43. package/dist/mixin/flagsParent.js +0 -60
  44. package/dist/mixin/hidden.d.ts +0 -7
  45. package/dist/mixin/hidden.js +0 -37
  46. package/dist/mixin/magicLinkParent.d.ts +0 -19
  47. package/dist/mixin/magicLinkParent.js +0 -43
  48. package/dist/mixin/singleLine.d.ts +0 -5
  49. package/dist/mixin/singleLine.js +0 -25
  50. package/dist/mixin/sol.d.ts +0 -6
  51. package/dist/mixin/sol.js +0 -44
  52. package/dist/mixin/syntax.d.ts +0 -8
  53. package/dist/mixin/syntax.js +0 -46
  54. package/dist/parser/braces.js +0 -150
  55. package/dist/parser/commentAndExt.js +0 -79
  56. package/dist/parser/converter.js +0 -39
  57. package/dist/parser/externalLinks.js +0 -37
  58. package/dist/parser/hrAndDoubleUnderscore.js +0 -42
  59. package/dist/parser/html.js +0 -38
  60. package/dist/parser/links.js +0 -101
  61. package/dist/parser/list.js +0 -99
  62. package/dist/parser/magicLinks.js +0 -53
  63. package/dist/parser/quotes.js +0 -67
  64. package/dist/parser/redirect.js +0 -26
  65. package/dist/parser/selector.js +0 -394
  66. package/dist/parser/table.js +0 -123
  67. package/dist/src/arg.d.ts +0 -51
  68. package/dist/src/arg.js +0 -214
  69. package/dist/src/atom.d.ts +0 -14
  70. package/dist/src/atom.js +0 -52
  71. package/dist/src/attribute.d.ts +0 -64
  72. package/dist/src/attribute.js +0 -483
  73. package/dist/src/attributes.d.ts +0 -101
  74. package/dist/src/attributes.js +0 -382
  75. package/dist/src/converter.d.ts +0 -28
  76. package/dist/src/converter.js +0 -147
  77. package/dist/src/converterFlags.d.ts +0 -80
  78. package/dist/src/converterFlags.js +0 -242
  79. package/dist/src/converterRule.d.ts +0 -71
  80. package/dist/src/converterRule.js +0 -216
  81. package/dist/src/extLink.d.ts +0 -36
  82. package/dist/src/extLink.js +0 -198
  83. package/dist/src/gallery.d.ts +0 -47
  84. package/dist/src/gallery.js +0 -142
  85. package/dist/src/heading.d.ts +0 -40
  86. package/dist/src/heading.js +0 -191
  87. package/dist/src/hidden.d.ts +0 -9
  88. package/dist/src/hidden.js +0 -80
  89. package/dist/src/html.d.ts +0 -57
  90. package/dist/src/html.js +0 -343
  91. package/dist/src/imageParameter.d.ts +0 -58
  92. package/dist/src/imageParameter.js +0 -247
  93. package/dist/src/imagemap.d.ts +0 -47
  94. package/dist/src/imagemap.js +0 -146
  95. package/dist/src/imagemapLink.d.ts +0 -31
  96. package/dist/src/imagemapLink.js +0 -97
  97. package/dist/src/index.d.ts +0 -141
  98. package/dist/src/index.js +0 -795
  99. package/dist/src/link/base.d.ts +0 -54
  100. package/dist/src/link/base.js +0 -263
  101. package/dist/src/link/category.d.ts +0 -22
  102. package/dist/src/link/category.js +0 -34
  103. package/dist/src/link/file.d.ts +0 -96
  104. package/dist/src/link/file.js +0 -276
  105. package/dist/src/link/galleryImage.d.ts +0 -29
  106. package/dist/src/link/galleryImage.js +0 -132
  107. package/dist/src/link/index.d.ts +0 -39
  108. package/dist/src/link/index.js +0 -99
  109. package/dist/src/link/redirectTarget.d.ts +0 -27
  110. package/dist/src/link/redirectTarget.js +0 -72
  111. package/dist/src/magicLink.d.ts +0 -61
  112. package/dist/src/magicLink.js +0 -261
  113. package/dist/src/nested.d.ts +0 -40
  114. package/dist/src/nested.js +0 -106
  115. package/dist/src/nowiki/base.d.ts +0 -30
  116. package/dist/src/nowiki/base.js +0 -89
  117. package/dist/src/nowiki/comment.d.ts +0 -14
  118. package/dist/src/nowiki/comment.js +0 -124
  119. package/dist/src/nowiki/dd.d.ts +0 -8
  120. package/dist/src/nowiki/dd.js +0 -72
  121. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  122. package/dist/src/nowiki/doubleUnderscore.js +0 -97
  123. package/dist/src/nowiki/hr.d.ts +0 -5
  124. package/dist/src/nowiki/hr.js +0 -70
  125. package/dist/src/nowiki/index.d.ts +0 -14
  126. package/dist/src/nowiki/index.js +0 -31
  127. package/dist/src/nowiki/list.d.ts +0 -5
  128. package/dist/src/nowiki/list.js +0 -65
  129. package/dist/src/nowiki/listBase.d.ts +0 -17
  130. package/dist/src/nowiki/listBase.js +0 -75
  131. package/dist/src/nowiki/noinclude.d.ts +0 -6
  132. package/dist/src/nowiki/noinclude.js +0 -75
  133. package/dist/src/nowiki/quote.d.ts +0 -14
  134. package/dist/src/nowiki/quote.js +0 -135
  135. package/dist/src/onlyinclude.d.ts +0 -13
  136. package/dist/src/onlyinclude.js +0 -58
  137. package/dist/src/paramTag/index.d.ts +0 -30
  138. package/dist/src/paramTag/index.js +0 -78
  139. package/dist/src/paramTag/inputbox.d.ts +0 -8
  140. package/dist/src/paramTag/inputbox.js +0 -22
  141. package/dist/src/parameter.d.ts +0 -60
  142. package/dist/src/parameter.js +0 -268
  143. package/dist/src/pre.d.ts +0 -28
  144. package/dist/src/pre.js +0 -60
  145. package/dist/src/redirect.d.ts +0 -30
  146. package/dist/src/redirect.js +0 -126
  147. package/dist/src/syntax.d.ts +0 -17
  148. package/dist/src/syntax.js +0 -87
  149. package/dist/src/table/base.d.ts +0 -28
  150. package/dist/src/table/base.js +0 -81
  151. package/dist/src/table/index.d.ts +0 -230
  152. package/dist/src/table/index.js +0 -505
  153. package/dist/src/table/td.d.ts +0 -72
  154. package/dist/src/table/td.js +0 -370
  155. package/dist/src/table/tr.d.ts +0 -30
  156. package/dist/src/table/tr.js +0 -59
  157. package/dist/src/table/trBase.d.ts +0 -49
  158. package/dist/src/table/trBase.js +0 -164
  159. package/dist/src/tagPair/ext.d.ts +0 -29
  160. package/dist/src/tagPair/ext.js +0 -220
  161. package/dist/src/tagPair/include.d.ts +0 -33
  162. package/dist/src/tagPair/include.js +0 -130
  163. package/dist/src/tagPair/index.d.ts +0 -23
  164. package/dist/src/tagPair/index.js +0 -128
  165. package/dist/src/transclude.d.ts +0 -159
  166. package/dist/src/transclude.js +0 -587
  167. package/dist/util/constants.js +0 -25
  168. package/dist/util/debug.js +0 -95
  169. package/dist/util/diff.js +0 -83
  170. package/dist/util/lint.js +0 -32
  171. package/dist/util/string.js +0 -84
  172. package/errors/README +0 -3
  173. package/printed/README +0 -3
@@ -1,95 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.undo = exports.mixin = exports.emptyArray = exports.setChildNodes = exports.isToken = exports.Shadow = void 0;
4
- exports.Shadow = {
5
- running: false,
6
- /** @private */
7
- run(callback) {
8
- const { running } = this;
9
- this.running = true;
10
- try {
11
- const { Token: AnyToken } = require('../src/index');
12
- const result = callback();
13
- if (result instanceof AnyToken && !result.getAttribute('built')) {
14
- result.afterBuild();
15
- }
16
- this.running = running;
17
- return result;
18
- }
19
- catch (e) {
20
- this.running = running;
21
- throw e;
22
- }
23
- },
24
- rev: 0,
25
- };
26
- /**
27
- * 是否是某一特定类型的节点
28
- * @param type 节点类型
29
- */
30
- const isToken = (type) => (node) => node.type === type;
31
- exports.isToken = isToken;
32
- /**
33
- * 更新chldNodes
34
- * @param parent 父节点
35
- * @param position 子节点位置
36
- * @param deleteCount 移除的子节点数量
37
- * @param inserted 插入的子节点
38
- */
39
- const setChildNodes = (parent, position, deleteCount, inserted = []) => {
40
- const childNodes = [...parent.childNodes], removed = childNodes.splice(position, deleteCount, ...inserted);
41
- parent.setAttribute('childNodes', childNodes);
42
- for (const node of inserted) {
43
- node.setAttribute('parentNode', parent);
44
- }
45
- /* NOT FOR BROWSER */
46
- for (const node of removed) {
47
- node.setAttribute('parentNode', undefined);
48
- }
49
- /* NOT FOR BROWSER END */
50
- return removed;
51
- };
52
- exports.setChildNodes = setChildNodes;
53
- /**
54
- * 生成一个指定长度的空数组
55
- * @param n 数组长度
56
- * @param callback 回调函数
57
- */
58
- const emptyArray = (n, callback) => new Array(n).fill(undefined).map((_, i) => callback(i));
59
- exports.emptyArray = emptyArray;
60
- /**
61
- * 同步混入的类名
62
- * @param target 混入的目标
63
- * @param source 混入的源
64
- */
65
- const mixin = (target, source) => {
66
- Object.defineProperty(target, 'name', { value: source.name });
67
- };
68
- exports.mixin = mixin;
69
- /* NOT FOR BROWSER */
70
- /**
71
- * 撤销最近一次Mutation
72
- * @param e 事件
73
- * @param data 事件数据
74
- * @throws `RangeError` 无法撤销的事件类型
75
- */
76
- const undo = (e, data) => {
77
- const { target, type } = e;
78
- switch (data.type) {
79
- case 'remove':
80
- (0, exports.setChildNodes)(target, data.position, 0, [data.removed]);
81
- break;
82
- case 'insert':
83
- (0, exports.setChildNodes)(target, data.position, 1);
84
- break;
85
- case 'replace':
86
- (0, exports.setChildNodes)(target.parentNode, data.position, 1, [data.oldToken]);
87
- break;
88
- case 'text':
89
- target.replaceData(data.oldText);
90
- break;
91
- default:
92
- throw new RangeError(`Unable to undo events with an unknown type: ${type}`);
93
- }
94
- };
95
- exports.undo = undo;
package/dist/util/diff.js DELETED
@@ -1,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.info = exports.error = exports.diff = exports.cmd = void 0;
4
- const fs = require("fs/promises");
5
- const child_process_1 = require("child_process");
6
- const chalk = require("chalk");
7
- process.on('unhandledRejection', e => {
8
- console.error(e);
9
- });
10
- /**
11
- * 将shell命令转化为Promise对象
12
- * @param command shell指令
13
- * @param args shell输入参数
14
- */
15
- const cmd = (command, args) => new Promise(resolve => {
16
- let timer, shell;
17
- /**
18
- * 清除进程并返回
19
- * @param val 返回值
20
- */
21
- const r = (val) => {
22
- clearTimeout(timer);
23
- shell?.kill('SIGINT');
24
- resolve(val);
25
- };
26
- try {
27
- shell = (0, child_process_1.spawn)(command, args);
28
- timer = setTimeout(() => {
29
- shell.kill('SIGINT');
30
- }, 60 * 1000);
31
- let buf = '';
32
- shell.stdout.on('data', data => {
33
- buf += String(data);
34
- });
35
- shell.stdout.on('end', () => {
36
- r(buf);
37
- });
38
- shell.on('exit', () => {
39
- r(shell.killed ? undefined : '');
40
- });
41
- shell.on('error', () => {
42
- r(undefined);
43
- });
44
- }
45
- catch {
46
- r(undefined);
47
- }
48
- });
49
- exports.cmd = cmd;
50
- /**
51
- * 比较两个文件
52
- * @param oldStr 旧文本
53
- * @param newStr 新文本
54
- * @param uid 唯一标识
55
- */
56
- const diff = async (oldStr, newStr, uid) => {
57
- if (oldStr === newStr) {
58
- return;
59
- }
60
- const oldFile = `diffOld${uid}`, newFile = `diffNew${uid}`;
61
- await Promise.all([fs.writeFile(oldFile, oldStr), fs.writeFile(newFile, newStr)]);
62
- const stdout = await (0, exports.cmd)('git', [
63
- 'diff',
64
- '--color-words=[\xC0-\xFF][\x80-\xBF]+|<?/?\\w+/?>?|[^[:space:]]',
65
- '-U0',
66
- '--no-index',
67
- oldFile,
68
- newFile,
69
- ]);
70
- console.log(stdout?.split('\n').slice(4).join('\n'));
71
- await Promise.all([fs.unlink(oldFile), fs.unlink(newFile)]);
72
- };
73
- exports.diff = diff;
74
- /** @implements */
75
- const error = (msg, ...args) => {
76
- console.error(chalk.red(msg), ...args);
77
- };
78
- exports.error = error;
79
- /** @implements */
80
- const info = (msg, ...args) => {
81
- console.info(chalk.green(msg), ...args);
82
- };
83
- exports.info = info;
package/dist/util/lint.js DELETED
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateForSelf = exports.generateForChild = void 0;
4
- const rect_1 = require("../lib/rect");
5
- const index_1 = require("../index");
6
- /**
7
- * 生成lint函数
8
- * @param func lint函数
9
- */
10
- const factory = (func) => (token, rect, rule, msg, severity = 'error') => {
11
- const { start } = rect, { top, left } = rect instanceof rect_1.BoundingRect ? rect : new rect_1.BoundingRect(token, start), { offsetHeight, offsetWidth } = token, { startIndex, startLine, startCol } = func(token, start, top, left);
12
- return {
13
- rule,
14
- message: index_1.default.msg(msg),
15
- severity,
16
- startIndex,
17
- endIndex: startIndex + token.toString().length,
18
- startLine,
19
- endLine: startLine + offsetHeight - 1,
20
- startCol,
21
- endCol: offsetHeight === 1 ? startCol + offsetWidth : offsetWidth,
22
- };
23
- };
24
- exports.generateForChild = factory((child, start, line, col) => {
25
- const index = child.getRelativeIndex(), { top, left } = child.parentNode.posFromIndex(index);
26
- return {
27
- startIndex: start + index,
28
- startLine: line + top,
29
- startCol: top ? left : col + left,
30
- };
31
- });
32
- exports.generateForSelf = factory((_, startIndex, startLine, startCol) => ({ startIndex, startLine, startCol }));
@@ -1,84 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.newline = exports.font = exports.html = exports.sanitize = exports.normalizeSpace = exports.encode = exports.print = exports.escape = exports.noWrap = exports.decodeHtml = exports.text = exports.escapeRegExp = exports.removeComment = exports.tidy = exports.extUrlChar = exports.extUrlCharFirst = void 0;
4
- const commonExtUrlChar = String.raw `[^[\]<>"\0-\x1F\x7F\p{Zs}\uFFFD]`;
5
- exports.extUrlCharFirst = String.raw `(?:\[[\da-f:.]+\]|${commonExtUrlChar})`;
6
- exports.extUrlChar = String.raw `(?:${commonExtUrlChar}|\0\d+[c!~]\x7F)*`;
7
- /**
8
- * 生成正则替换函数
9
- * @param regex 正则表达式
10
- * @param replace 替换字符串或函数
11
- */
12
- const factory = (regex, replace) => (str) => str.replace(regex, replace);
13
- /** 清理解析专用的不可见字符 */
14
- exports.tidy = factory(/[\0\x7F]|\r$/gmu, '');
15
- /** remove half-parsed comment-like tokens */
16
- exports.removeComment = factory(/\0\d+c\x7F/gu, '');
17
- /** escape special chars for RegExp constructor */
18
- exports.escapeRegExp = factory(/[\\{}()|.?*+^$[\]]/gu, String.raw `\$&`);
19
- /**
20
- * extract effective wikitext
21
- * @param childNodes a Token's contents
22
- * @param separator delimiter between nodes
23
- */
24
- const text = (childNodes, separator = '') => childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
25
- exports.text = text;
26
- const names = { lt: '<', gt: '>', lbrack: '[', rbrack: ']', lbrace: '{', rbrace: '}' };
27
- /** decode HTML entities */
28
- exports.decodeHtml = factory(/&(?:#(\d+|x[\da-fA-F]+)|([lLgG][tT]|[lr]brac[ke]));/gu, (_, code, name) => code
29
- ? String.fromCodePoint(Number((/^x/iu.test(code) ? '0' : '') + code))
30
- : names[name.toLowerCase()]);
31
- /** escape newlines */
32
- exports.noWrap = factory(/\n/gu, String.raw `\n`);
33
- const entities = { '&': 'amp', '<': 'lt', '>': 'gt' };
34
- /** escape HTML entities */
35
- exports.escape = factory(/[&<>]/gu, p => `&${entities[p]};`);
36
- /**
37
- * 以HTML格式打印
38
- * @param childNodes 子节点
39
- * @param opt 选项
40
- */
41
- const print = (childNodes, opt = {}) => {
42
- const { pre = '', post = '', sep = '' } = opt;
43
- return pre + childNodes.map(child => child.print()).join(sep) + post;
44
- };
45
- exports.print = print;
46
- /* NOT FOR BROWSER */
47
- exports.encode = factory(/[<>[\]#|=]+/gu, encodeURIComponent);
48
- /**
49
- * convert newline in text nodes to single whitespace
50
- * @param token 父节点
51
- */
52
- const normalizeSpace = (token) => {
53
- if (token) {
54
- for (const child of token.childNodes) {
55
- if (child.type === 'text') {
56
- child.replaceData(child.data.replace(/\n+/gu, ' '));
57
- }
58
- }
59
- }
60
- };
61
- exports.normalizeSpace = normalizeSpace;
62
- /** escape HTML entities */
63
- exports.sanitize = factory(/[<>]/gu, p => `&${entities[p]};`);
64
- /**
65
- * convert to HTML
66
- * @param childNodes a Token's contents
67
- * @param separator delimiter between nodes
68
- * @param nowrap whether to normalize newlines
69
- */
70
- const html = (childNodes, separator = '', nowrap) => childNodes.map(child => child.toHtml(nowrap)).join(separator);
71
- exports.html = html;
72
- /**
73
- * wrap text with <b> and <i> tags
74
- * @param node
75
- * @param str
76
- */
77
- const font = (node, str) => {
78
- const { font: { bold, italic } } = node, i = str.indexOf('\n');
79
- const wrap = /** @ignore */ (s) => (bold ? '<b>' : '') + (italic ? '<i>' : '') + s + (italic ? '</i>' : '') + (bold ? '</b>' : '');
80
- return i === -1 ? wrap(str) : wrap(str.slice(0, i)) + str.slice(i);
81
- };
82
- exports.font = font;
83
- /** escape newline */
84
- exports.newline = factory(/\n/gu, '&#10;');
package/errors/README DELETED
@@ -1,3 +0,0 @@
1
- 这里记录解析失败时处于半解析状态的维基文本以及错误信息。
2
-
3
- When parsing fails, the half-parsed wikitext and the error message are recorded here.
package/printed/README DELETED
@@ -1,3 +0,0 @@
1
- 这里存放以 JSON 格式打印的 AST。
2
-
3
- AST as JSON files are saved here.