wikiparser-node 0.9.0 → 0.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 (87) hide show
  1. package/bundle/bundle.min.js +38 -0
  2. package/extensions/editor.css +62 -0
  3. package/extensions/editor.js +328 -0
  4. package/extensions/ui.css +119 -0
  5. package/package.json +13 -12
  6. package/README.md +0 -39
  7. package/config/default.json +0 -832
  8. package/config/llwiki.json +0 -630
  9. package/config/moegirl.json +0 -729
  10. package/config/zhwiki.json +0 -1269
  11. package/index.js +0 -333
  12. package/lib/element.js +0 -611
  13. package/lib/node.js +0 -770
  14. package/lib/ranges.js +0 -130
  15. package/lib/text.js +0 -245
  16. package/lib/title.js +0 -83
  17. package/mixin/attributeParent.js +0 -117
  18. package/mixin/fixedToken.js +0 -40
  19. package/mixin/hidden.js +0 -21
  20. package/mixin/singleLine.js +0 -31
  21. package/mixin/sol.js +0 -54
  22. package/parser/brackets.js +0 -126
  23. package/parser/commentAndExt.js +0 -59
  24. package/parser/converter.js +0 -46
  25. package/parser/externalLinks.js +0 -33
  26. package/parser/hrAndDoubleUnderscore.js +0 -38
  27. package/parser/html.js +0 -42
  28. package/parser/links.js +0 -94
  29. package/parser/list.js +0 -59
  30. package/parser/magicLinks.js +0 -41
  31. package/parser/quotes.js +0 -64
  32. package/parser/selector.js +0 -177
  33. package/parser/table.js +0 -114
  34. package/src/arg.js +0 -207
  35. package/src/atom/hidden.js +0 -13
  36. package/src/atom/index.js +0 -43
  37. package/src/attribute.js +0 -470
  38. package/src/attributes.js +0 -453
  39. package/src/charinsert.js +0 -97
  40. package/src/converter.js +0 -176
  41. package/src/converterFlags.js +0 -284
  42. package/src/converterRule.js +0 -256
  43. package/src/extLink.js +0 -180
  44. package/src/gallery.js +0 -149
  45. package/src/hasNowiki/index.js +0 -44
  46. package/src/hasNowiki/pre.js +0 -40
  47. package/src/heading.js +0 -134
  48. package/src/html.js +0 -254
  49. package/src/imageParameter.js +0 -301
  50. package/src/imagemap.js +0 -199
  51. package/src/imagemapLink.js +0 -41
  52. package/src/index.js +0 -936
  53. package/src/link/category.js +0 -44
  54. package/src/link/file.js +0 -287
  55. package/src/link/galleryImage.js +0 -120
  56. package/src/link/index.js +0 -384
  57. package/src/magicLink.js +0 -149
  58. package/src/nested/choose.js +0 -24
  59. package/src/nested/combobox.js +0 -23
  60. package/src/nested/index.js +0 -93
  61. package/src/nested/references.js +0 -23
  62. package/src/nowiki/comment.js +0 -71
  63. package/src/nowiki/dd.js +0 -59
  64. package/src/nowiki/doubleUnderscore.js +0 -56
  65. package/src/nowiki/hr.js +0 -41
  66. package/src/nowiki/index.js +0 -56
  67. package/src/nowiki/list.js +0 -16
  68. package/src/nowiki/noinclude.js +0 -28
  69. package/src/nowiki/quote.js +0 -69
  70. package/src/onlyinclude.js +0 -64
  71. package/src/paramTag/index.js +0 -89
  72. package/src/paramTag/inputbox.js +0 -35
  73. package/src/parameter.js +0 -239
  74. package/src/syntax.js +0 -91
  75. package/src/table/index.js +0 -983
  76. package/src/table/td.js +0 -338
  77. package/src/table/tr.js +0 -319
  78. package/src/tagPair/ext.js +0 -148
  79. package/src/tagPair/include.js +0 -50
  80. package/src/tagPair/index.js +0 -126
  81. package/src/transclude.js +0 -843
  82. package/tool/index.js +0 -1202
  83. package/util/base.js +0 -17
  84. package/util/debug.js +0 -73
  85. package/util/diff.js +0 -76
  86. package/util/lint.js +0 -55
  87. package/util/string.js +0 -126
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 ? undefined : '');
42
- });
43
- shell.on('error', () => {
44
- r(undefined);
45
- });
46
- } catch {
47
- r(undefined);
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,55 +0,0 @@
1
- 'use strict';
2
-
3
- const Parser = require('..'),
4
- Token = require('../src');
5
-
6
- /**
7
- * 生成对于子节点的LintError对象
8
- * @param {Token} child 子节点
9
- * @param {{top: number, left: number, start: number}} boundingRect 父节点的绝对定位
10
- * @param {string} msg 错误信息
11
- * @param {'error'|'warning'} severity 严重程度
12
- * @returns {LintError}
13
- */
14
- const generateForChild = (child, boundingRect, msg, severity = 'error') => {
15
- const index = child.getRelativeIndex(),
16
- {offsetHeight, offsetWidth, parentNode, length} = child,
17
- {top: offsetTop, left: offsetLeft} = parentNode.posFromIndex(index),
18
- {start} = boundingRect,
19
- {top, left} = 'top' in boundingRect ? boundingRect : child.getRootNode().posFromIndex(start),
20
- excerpt = String(child).slice(0, 50),
21
- startIndex = start + index,
22
- endIndex = startIndex + length,
23
- startLine = top + offsetTop,
24
- endLine = startLine + offsetHeight - 1,
25
- startCol = offsetTop ? offsetLeft : left + offsetLeft,
26
- endCol = offsetHeight > 1 ? offsetWidth : startCol + offsetWidth;
27
- return {message: Parser.msg(msg), severity, startIndex, endIndex, startLine, endLine, startCol, endCol, excerpt};
28
- };
29
-
30
- /**
31
- * 生成对于自己的LintError对象
32
- * @param {Token} token 节点
33
- * @param {{top: number, left: number, start: number}} boundingRect 绝对定位
34
- * @param {string} msg 错误信息
35
- * @param {'error'|'warning'} severity 严重程度
36
- * @returns {LintError}
37
- */
38
- const generateForSelf = (token, boundingRect, msg, severity = 'error') => {
39
- const {start} = boundingRect,
40
- {offsetHeight, offsetWidth, length} = token,
41
- {top, left} = 'top' in boundingRect ? boundingRect : token.getRootNode().posFromIndex(start);
42
- return {
43
- message: Parser.msg(msg),
44
- severity,
45
- startIndex: start,
46
- endIndex: start + length,
47
- startLine: top,
48
- endLine: top + offsetHeight - 1,
49
- startCol: left,
50
- endCol: offsetHeight > 1 ? offsetWidth : left + offsetWidth,
51
- excerpt: String(token).slice(0, 50),
52
- };
53
- };
54
-
55
- module.exports = {generateForChild, generateForSelf};
package/util/string.js DELETED
@@ -1,126 +0,0 @@
1
- 'use strict';
2
-
3
- const extUrlCharFirst = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD])',
4
- extUrlChar = '(?:[^[\\]<>"\\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.replace(/\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).replace(/[&<>]/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.replace(/[\\{}()|.?*+^$[\]]/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
- * extract effective wikitext
67
- * @param {(string|AstNode)[]} childNodes a Token's contents
68
- * @param {string} separator delimiter between nodes
69
- */
70
- const text = (childNodes, separator = '') => {
71
- const AstNode = require('../lib/node');
72
- return childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
73
- };
74
-
75
- /**
76
- * decode HTML entities
77
- * @param {string} str 原字符串
78
- */
79
- const decodeHtml = str => str?.replace(
80
- /&#(\d+|x[\da-f]+);/giu,
81
- (_, code) => String.fromCodePoint(`${code[0].toLowerCase() === 'x' ? '0' : ''}${code}`),
82
- );
83
-
84
- /**
85
- * optionally convert to lower cases
86
- * @param {string} val 属性值
87
- * @param {string|undefined} i 是否对大小写不敏感
88
- */
89
- const toCase = (val, i) => i ? val.toLowerCase() : val;
90
-
91
- /**
92
- * escape newlines
93
- * @param {string} str 原字符串
94
- */
95
- const noWrap = str => str.replaceAll('\n', '\\n');
96
-
97
- /**
98
- * convert newline in text nodes to single whitespace
99
- * @param {Token & {childNodes: AstText[]}} token 父节点
100
- */
101
- const normalizeSpace = token => {
102
- if (token === undefined) {
103
- return;
104
- }
105
- const Token = require('../src'),
106
- AstText = require('../lib/text');
107
- for (const child of token.childNodes) {
108
- if (child.type === 'text') {
109
- child.replaceData(child.data.replaceAll('\n', ' '));
110
- }
111
- }
112
- };
113
-
114
- module.exports = {
115
- extUrlCharFirst,
116
- extUrlChar,
117
- removeComment,
118
- print,
119
- escapeRegExp,
120
- explode,
121
- text,
122
- decodeHtml,
123
- toCase,
124
- noWrap,
125
- normalizeSpace,
126
- };