wikiparser-node 0.6.1 → 0.6.5-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 (82) hide show
  1. package/bundle/bundle.min.js +40 -0
  2. package/package.json +9 -11
  3. package/README.md +0 -39
  4. package/config/default.json +0 -832
  5. package/config/llwiki.json +0 -630
  6. package/config/moegirl.json +0 -727
  7. package/config/zhwiki.json +0 -1269
  8. package/index.js +0 -277
  9. package/lib/element.js +0 -612
  10. package/lib/node.js +0 -771
  11. package/lib/ranges.js +0 -130
  12. package/lib/text.js +0 -175
  13. package/lib/title.js +0 -70
  14. package/mixin/attributeParent.js +0 -113
  15. package/mixin/fixedToken.js +0 -40
  16. package/mixin/hidden.js +0 -21
  17. package/mixin/sol.js +0 -68
  18. package/parser/brackets.js +0 -118
  19. package/parser/commentAndExt.js +0 -63
  20. package/parser/converter.js +0 -45
  21. package/parser/externalLinks.js +0 -31
  22. package/parser/hrAndDoubleUnderscore.js +0 -36
  23. package/parser/html.js +0 -42
  24. package/parser/links.js +0 -97
  25. package/parser/list.js +0 -59
  26. package/parser/magicLinks.js +0 -41
  27. package/parser/quotes.js +0 -64
  28. package/parser/selector.js +0 -175
  29. package/parser/table.js +0 -114
  30. package/src/arg.js +0 -198
  31. package/src/atom/hidden.js +0 -13
  32. package/src/atom/index.js +0 -43
  33. package/src/attribute.js +0 -460
  34. package/src/charinsert.js +0 -91
  35. package/src/converter.js +0 -176
  36. package/src/converterFlags.js +0 -279
  37. package/src/converterRule.js +0 -259
  38. package/src/extLink.js +0 -175
  39. package/src/gallery.js +0 -146
  40. package/src/hasNowiki/index.js +0 -42
  41. package/src/hasNowiki/pre.js +0 -40
  42. package/src/heading.js +0 -123
  43. package/src/html.js +0 -230
  44. package/src/imageParameter.js +0 -276
  45. package/src/imagemap.js +0 -205
  46. package/src/imagemapLink.js +0 -43
  47. package/src/index.js +0 -842
  48. package/src/link/category.js +0 -49
  49. package/src/link/file.js +0 -321
  50. package/src/link/galleryImage.js +0 -125
  51. package/src/link/index.js +0 -347
  52. package/src/magicLink.js +0 -135
  53. package/src/nested/choose.js +0 -24
  54. package/src/nested/combobox.js +0 -23
  55. package/src/nested/index.js +0 -88
  56. package/src/nested/references.js +0 -23
  57. package/src/nowiki/comment.js +0 -71
  58. package/src/nowiki/dd.js +0 -59
  59. package/src/nowiki/doubleUnderscore.js +0 -56
  60. package/src/nowiki/hr.js +0 -41
  61. package/src/nowiki/index.js +0 -56
  62. package/src/nowiki/list.js +0 -16
  63. package/src/nowiki/noinclude.js +0 -28
  64. package/src/nowiki/quote.js +0 -63
  65. package/src/onlyinclude.js +0 -61
  66. package/src/paramTag/index.js +0 -83
  67. package/src/paramTag/inputbox.js +0 -42
  68. package/src/parameter.js +0 -214
  69. package/src/syntax.js +0 -91
  70. package/src/table/index.js +0 -981
  71. package/src/table/td.js +0 -308
  72. package/src/table/tr.js +0 -299
  73. package/src/tagPair/ext.js +0 -122
  74. package/src/tagPair/include.js +0 -60
  75. package/src/tagPair/index.js +0 -126
  76. package/src/transclude.js +0 -751
  77. package/tool/index.js +0 -1199
  78. package/util/base.js +0 -17
  79. package/util/debug.js +0 -73
  80. package/util/diff.js +0 -76
  81. package/util/lint.js +0 -40
  82. package/util/string.js +0 -105
package/util/base.js DELETED
@@ -1,17 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * 是否是普通对象
5
- * @param {*} obj 对象
6
- */
7
- const isPlainObject = obj => Boolean(obj) && Object.getPrototypeOf(obj).constructor === Object;
8
-
9
- /**
10
- * 延时
11
- * @param {number} t 秒数
12
- */
13
- const sleep = t => new Promise(resolve => {
14
- setTimeout(resolve, t * 1000);
15
- });
16
-
17
- module.exports = {isPlainObject, sleep};
package/util/debug.js DELETED
@@ -1,73 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * 定制TypeError消息
5
- * @param {Function} constructor 类
6
- * @param {string} method
7
- * @param {...string} args 可接受的参数类型
8
- * @throws `TypeError`
9
- */
10
- const typeError = ({name}, method, ...args) => {
11
- throw new TypeError(`${name}.${method} 方法仅接受 ${args.join('、')} 作为输入参数!`);
12
- };
13
-
14
- /**
15
- * 不是被构造器或原型方法调用
16
- * @param {string} name 方法名称
17
- */
18
- const externalUse = name => {
19
- const Parser = require('..');
20
- if (Parser.running) {
21
- return false;
22
- }
23
- const regex = new RegExp(`^new \\w*Token$|^(?:Ast\\w*|\\w*Token)\\.(?!${name}$)`, 'u');
24
- try {
25
- throw new Error(); // eslint-disable-line unicorn/error-message
26
- } catch (e) {
27
- if (e instanceof Error) {
28
- const mt = e.stack.match(/(?<=^\s+at )(?:new )?[\w.]+(?= \(\/)/gmu);
29
- return !mt.slice(2).some(func => regex.test(func));
30
- }
31
- }
32
- return false;
33
- };
34
-
35
- /**
36
- * 撤销最近一次Mutation
37
- * @param {AstEvent} e 事件
38
- * @param {AstEventData} data 事件数据
39
- * @throws `RangeError` 无法撤销的事件类型
40
- */
41
- const undo = (e, data) => {
42
- const {target, type} = e;
43
- switch (type) {
44
- case 'remove': {
45
- const childNodes = [...target.childNodes];
46
- childNodes.splice(data.position, 0, data.removed);
47
- data.removed.setAttribute('parentNode', target);
48
- target.setAttribute('childNodes', childNodes);
49
- break;
50
- }
51
- case 'insert': {
52
- const childNodes = [...target.childNodes];
53
- childNodes.splice(data.position, 1);
54
- target.setAttribute('childNodes', childNodes);
55
- break;
56
- }
57
- case 'replace': {
58
- const {parentNode} = target,
59
- childNodes = [...parentNode.childNodes];
60
- childNodes.splice(data.position, 1, data.oldToken);
61
- data.oldToken.setAttribute('parentNode', parentNode);
62
- parentNode.setAttribute('childNodes', childNodes);
63
- break;
64
- }
65
- case 'text':
66
- target.replaceData(data.oldText);
67
- break;
68
- default:
69
- throw new RangeError(`无法撤销未知类型的事件:${type}`);
70
- }
71
- };
72
-
73
- module.exports = {typeError, externalUse, undo};
package/util/diff.js DELETED
@@ -1,76 +0,0 @@
1
- 'use strict';
2
-
3
- const {spawn} = require('child_process'),
4
- fs = require('fs/promises');
5
-
6
- process.on('unhandledRejection', e => {
7
- console.error(e);
8
- });
9
-
10
- /**
11
- * 将shell命令转化为Promise对象
12
- * @param {string} command shell指令
13
- * @param {string[]} args shell输入参数
14
- * @returns {Promise<?string>}
15
- */
16
- const cmd = (command, args) => new Promise(resolve => {
17
- let timer, shell;
18
-
19
- /**
20
- * 清除进程并返回
21
- * @param {*} val 返回值
22
- */
23
- const r = val => {
24
- clearTimeout(timer);
25
- shell.kill('SIGINT');
26
- resolve(val);
27
- };
28
- try {
29
- shell = spawn(command, args);
30
- timer = setTimeout(() => {
31
- shell.kill('SIGINT');
32
- }, 60 * 1000);
33
- let buf = '';
34
- shell.stdout.on('data', data => {
35
- buf += data.toString();
36
- });
37
- shell.stdout.on('end', () => {
38
- r(buf);
39
- });
40
- shell.on('exit', () => {
41
- r(shell.killed ? null : '');
42
- });
43
- shell.on('error', () => {
44
- r(null);
45
- });
46
- } catch {
47
- r(null);
48
- }
49
- });
50
-
51
- /**
52
- * 比较两个文件
53
- * @param {string} oldStr 旧文本
54
- * @param {string} newStr 新文本
55
- * @param {string} uid 唯一标识
56
- */
57
- const diff = async (oldStr, newStr, uid = '') => {
58
- if (oldStr === newStr) {
59
- return;
60
- }
61
- const oldFile = `diffOld${uid}`,
62
- newFile = `diffNew${uid}`;
63
- await Promise.all([fs.writeFile(oldFile, oldStr), fs.writeFile(newFile, newStr)]);
64
- const stdout = await cmd('git', [
65
- 'diff',
66
- '--color-words=[\xC0-\xFF][\x80-\xBF]+|<?/?\\w+/?>?|[^[:space:]]',
67
- '-U0',
68
- '--no-index',
69
- oldFile,
70
- newFile,
71
- ]);
72
- await Promise.all([fs.unlink(oldFile), fs.unlink(newFile)]);
73
- console.log(stdout?.split('\n')?.slice(4)?.join('\n'));
74
- };
75
-
76
- module.exports = diff;
package/util/lint.js DELETED
@@ -1,40 +0,0 @@
1
- 'use strict';
2
-
3
- const Token = require('../src');
4
-
5
- /**
6
- * 生成对于子节点的LintError对象
7
- * @param {Token} child 子节点
8
- * @param {{top: number, left: number}} boundingRect 父节点的绝对定位
9
- * @param {string} message 错误信息
10
- * @param {'error'|'warning'} severity 严重程度
11
- * @returns {LintError}
12
- */
13
- const generateForChild = (child, boundingRect, message, severity = 'error') => {
14
- const {style: {top: offsetTop, left: offsetLeft, height, width}} = child,
15
- {top, left} = boundingRect,
16
- startLine = top + offsetTop,
17
- endLine = startLine + height - 1,
18
- startCol = offsetTop ? offsetLeft : left + offsetLeft,
19
- endCol = height > 1 ? width : startCol + width;
20
- return {message, severity, startLine, endLine, startCol, endCol};
21
- };
22
-
23
- /**
24
- * 生成对于自己的LintError对象
25
- * @param {Token} token 节点
26
- * @param {{top: number, left: number}} boundingRect 绝对定位
27
- * @param {string} message 错误信息
28
- * @param {'error'|'warning'} severity 严重程度
29
- * @returns {LintError}
30
- */
31
- const generateForSelf = (token, boundingRect, message, severity = 'error') => ({
32
- message,
33
- severity,
34
- startLine: boundingRect.top,
35
- endLine: boundingRect.top + token.offsetHeight - 1,
36
- startCol: boundingRect.left,
37
- endCol: token.offsetHeight > 1 ? token.offsetWidth : boundingRect.left + token.offsetWidth,
38
- });
39
-
40
- module.exports = {generateForChild, generateForSelf};
package/util/string.js DELETED
@@ -1,105 +0,0 @@
1
- 'use strict';
2
-
3
- const extUrlChar = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD])'
4
- + '(?:[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD]|\\0\\d+c\\x7F)*';
5
-
6
- /**
7
- * remove half-parsed comment-like tokens
8
- * @param {string} str 原字符串
9
- */
10
- const removeComment = str => str.replaceAll(/\0\d+c\x7F/gu, '');
11
-
12
- /**
13
- * 以HTML格式打印
14
- * @param {(AstText|AstElement)[]} childNodes 子节点
15
- * @param {printOpt} opt 选项
16
- */
17
- const print = (childNodes, opt = {}) => {
18
- const AstText = require('../lib/text'),
19
- AstElement = require('../lib/element');
20
- const {pre = '', post = '', sep = ''} = opt,
21
- entities = {'&': 'amp', '<': 'lt', '>': 'gt'};
22
- return `${pre}${childNodes.map(
23
- child => child instanceof AstElement
24
- ? child.print()
25
- : String(child).replaceAll(/[&<>]/gu, p => `&${entities[p]};`),
26
- ).join(sep)}${post}`;
27
- };
28
-
29
- /**
30
- * escape special chars for RegExp constructor
31
- * @param {string} str RegExp source
32
- */
33
- const escapeRegExp = str => str.replaceAll(/[\\{}()|.?*+^$[\]]/gu, '\\$&');
34
-
35
- /**
36
- * a more sophisticated string-explode function
37
- * @param {string} start start syntax of a nested AST node
38
- * @param {string} end end syntax of a nested AST node
39
- * @param {string} separator syntax for explosion
40
- * @param {string} str string to be exploded
41
- */
42
- const explode = (start, end, separator, str) => {
43
- if (str === undefined) {
44
- return [];
45
- }
46
- const regex = new RegExp(`${[start, end, separator].map(escapeRegExp).join('|')}`, 'gu'),
47
- /** @type {string[]} */ exploded = [];
48
- let mt = regex.exec(str),
49
- depth = 0,
50
- lastIndex = 0;
51
- while (mt) {
52
- const {0: match, index} = mt;
53
- if (match !== separator) {
54
- depth += match === start ? 1 : -1;
55
- } else if (depth === 0) {
56
- exploded.push(str.slice(lastIndex, index));
57
- ({lastIndex} = regex);
58
- }
59
- mt = regex.exec(str);
60
- }
61
- exploded.push(str.slice(lastIndex));
62
- return exploded;
63
- };
64
-
65
- /**
66
- * optionally convert to lower cases
67
- * @param {string} val 属性值
68
- * @param {string|undefined} i 是否对大小写不敏感
69
- */
70
- const toCase = (val, i) => i ? val.toLowerCase() : val;
71
-
72
- /**
73
- * extract effective wikitext
74
- * @param {(string|AstNode)[]} childNodes a Token's contents
75
- * @param {string} separator delimiter between nodes
76
- */
77
- const text = (childNodes, separator = '') => {
78
- const AstNode = require('../lib/node');
79
- return childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
80
- };
81
-
82
- /**
83
- * escape newlines
84
- * @param {string} str 原字符串
85
- */
86
- const noWrap = str => str.replaceAll('\n', '\\n');
87
-
88
- /**
89
- * convert newline in text nodes to single whitespace
90
- * @param {Token & {childNodes: AstText[]}} token 父节点
91
- */
92
- const normalizeSpace = token => {
93
- if (token === undefined) {
94
- return;
95
- }
96
- const Token = require('../src'),
97
- AstText = require('../lib/text');
98
- for (const child of token.childNodes) {
99
- if (child.type === 'text') {
100
- child.replaceData(child.data.replaceAll('\n', ' '));
101
- }
102
- }
103
- };
104
-
105
- module.exports = {extUrlChar, removeComment, print, escapeRegExp, explode, toCase, text, noWrap, normalizeSpace};