wikiparser-node 1.2.0 → 1.3.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 (154) hide show
  1. package/bundle/bundle.min.js +36 -0
  2. package/config/llwiki.json +1 -35
  3. package/config/moegirl.json +1 -44
  4. package/config/zhwiki.json +1 -466
  5. package/extensions/dist/base.js +68 -0
  6. package/extensions/dist/editor.js +159 -0
  7. package/extensions/dist/highlight.js +30 -0
  8. package/extensions/dist/lint.js +48 -0
  9. package/extensions/editor.css +63 -0
  10. package/extensions/ui.css +117 -0
  11. package/package.json +33 -12
  12. package/config/.schema.json +0 -172
  13. package/dist/addon/table.d.ts +0 -6
  14. package/dist/addon/table.js +0 -564
  15. package/dist/base.d.ts +0 -46
  16. package/dist/bin/toc.js +0 -18
  17. package/dist/index.d.ts +0 -31
  18. package/dist/index.js +0 -209
  19. package/dist/internal.d.ts +0 -44
  20. package/dist/lib/element.d.ts +0 -155
  21. package/dist/lib/element.js +0 -654
  22. package/dist/lib/node.d.ts +0 -146
  23. package/dist/lib/node.js +0 -419
  24. package/dist/lib/range.d.ts +0 -104
  25. package/dist/lib/range.js +0 -385
  26. package/dist/lib/ranges.d.ts +0 -26
  27. package/dist/lib/ranges.js +0 -117
  28. package/dist/lib/text.d.ts +0 -62
  29. package/dist/lib/text.js +0 -235
  30. package/dist/lib/title.d.ts +0 -38
  31. package/dist/lib/title.js +0 -162
  32. package/dist/mixin/attributesParent.js +0 -94
  33. package/dist/mixin/fixed.js +0 -32
  34. package/dist/mixin/flagsParent.js +0 -70
  35. package/dist/mixin/hidden.js +0 -22
  36. package/dist/mixin/magicLinkParent.js +0 -41
  37. package/dist/mixin/singleLine.js +0 -25
  38. package/dist/mixin/sol.js +0 -43
  39. package/dist/mixin/syntax.js +0 -56
  40. package/dist/parser/braces.js +0 -123
  41. package/dist/parser/commentAndExt.js +0 -69
  42. package/dist/parser/converter.js +0 -40
  43. package/dist/parser/externalLinks.js +0 -28
  44. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  45. package/dist/parser/html.js +0 -36
  46. package/dist/parser/links.js +0 -94
  47. package/dist/parser/list.js +0 -59
  48. package/dist/parser/magicLinks.js +0 -40
  49. package/dist/parser/quotes.js +0 -67
  50. package/dist/parser/selector.js +0 -162
  51. package/dist/parser/table.js +0 -112
  52. package/dist/src/arg.d.ts +0 -58
  53. package/dist/src/arg.js +0 -190
  54. package/dist/src/atom.d.ts +0 -12
  55. package/dist/src/atom.js +0 -27
  56. package/dist/src/attribute.d.ts +0 -86
  57. package/dist/src/attribute.js +0 -392
  58. package/dist/src/attributes.d.ts +0 -107
  59. package/dist/src/attributes.js +0 -344
  60. package/dist/src/converter.d.ts +0 -51
  61. package/dist/src/converter.js +0 -79
  62. package/dist/src/converterFlags.d.ts +0 -87
  63. package/dist/src/converterFlags.js +0 -223
  64. package/dist/src/converterRule.d.ts +0 -81
  65. package/dist/src/converterRule.js +0 -212
  66. package/dist/src/extLink.d.ts +0 -53
  67. package/dist/src/extLink.js +0 -121
  68. package/dist/src/gallery.d.ts +0 -55
  69. package/dist/src/gallery.js +0 -123
  70. package/dist/src/heading.d.ts +0 -72
  71. package/dist/src/heading.js +0 -128
  72. package/dist/src/hidden.d.ts +0 -21
  73. package/dist/src/hidden.js +0 -23
  74. package/dist/src/html.d.ts +0 -103
  75. package/dist/src/html.js +0 -230
  76. package/dist/src/imageParameter.d.ts +0 -66
  77. package/dist/src/imageParameter.js +0 -247
  78. package/dist/src/imagemap.d.ts +0 -57
  79. package/dist/src/imagemap.js +0 -148
  80. package/dist/src/imagemapLink.d.ts +0 -57
  81. package/dist/src/imagemapLink.js +0 -40
  82. package/dist/src/index.d.ts +0 -146
  83. package/dist/src/index.js +0 -777
  84. package/dist/src/link/base.d.ts +0 -52
  85. package/dist/src/link/base.js +0 -207
  86. package/dist/src/link/category.d.ts +0 -13
  87. package/dist/src/link/category.js +0 -29
  88. package/dist/src/link/file.d.ts +0 -96
  89. package/dist/src/link/file.js +0 -253
  90. package/dist/src/link/galleryImage.d.ts +0 -43
  91. package/dist/src/link/galleryImage.js +0 -106
  92. package/dist/src/link/index.d.ts +0 -53
  93. package/dist/src/link/index.js +0 -123
  94. package/dist/src/magicLink.d.ts +0 -69
  95. package/dist/src/magicLink.js +0 -148
  96. package/dist/src/nested.d.ts +0 -44
  97. package/dist/src/nested.js +0 -87
  98. package/dist/src/nowiki/base.d.ts +0 -46
  99. package/dist/src/nowiki/base.js +0 -42
  100. package/dist/src/nowiki/comment.d.ts +0 -39
  101. package/dist/src/nowiki/comment.js +0 -67
  102. package/dist/src/nowiki/dd.d.ts +0 -8
  103. package/dist/src/nowiki/dd.js +0 -25
  104. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -43
  105. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  106. package/dist/src/nowiki/hr.d.ts +0 -29
  107. package/dist/src/nowiki/hr.js +0 -14
  108. package/dist/src/nowiki/index.d.ts +0 -16
  109. package/dist/src/nowiki/index.js +0 -21
  110. package/dist/src/nowiki/list.d.ts +0 -29
  111. package/dist/src/nowiki/list.js +0 -48
  112. package/dist/src/nowiki/listBase.d.ts +0 -18
  113. package/dist/src/nowiki/listBase.js +0 -12
  114. package/dist/src/nowiki/noinclude.d.ts +0 -25
  115. package/dist/src/nowiki/noinclude.js +0 -25
  116. package/dist/src/nowiki/quote.d.ts +0 -22
  117. package/dist/src/nowiki/quote.js +0 -50
  118. package/dist/src/onlyinclude.d.ts +0 -16
  119. package/dist/src/onlyinclude.js +0 -57
  120. package/dist/src/paramTag/index.d.ts +0 -37
  121. package/dist/src/paramTag/index.js +0 -68
  122. package/dist/src/paramTag/inputbox.d.ts +0 -8
  123. package/dist/src/paramTag/inputbox.js +0 -23
  124. package/dist/src/parameter.d.ts +0 -84
  125. package/dist/src/parameter.js +0 -206
  126. package/dist/src/pre.d.ts +0 -28
  127. package/dist/src/pre.js +0 -51
  128. package/dist/src/syntax.d.ts +0 -24
  129. package/dist/src/syntax.js +0 -30
  130. package/dist/src/table/base.d.ts +0 -52
  131. package/dist/src/table/base.js +0 -78
  132. package/dist/src/table/index.d.ts +0 -229
  133. package/dist/src/table/index.js +0 -380
  134. package/dist/src/table/td.d.ts +0 -103
  135. package/dist/src/table/td.js +0 -261
  136. package/dist/src/table/tr.d.ts +0 -32
  137. package/dist/src/table/tr.js +0 -56
  138. package/dist/src/table/trBase.d.ts +0 -54
  139. package/dist/src/table/trBase.js +0 -159
  140. package/dist/src/tagPair/ext.d.ts +0 -58
  141. package/dist/src/tagPair/ext.js +0 -142
  142. package/dist/src/tagPair/include.d.ts +0 -52
  143. package/dist/src/tagPair/include.js +0 -58
  144. package/dist/src/tagPair/index.d.ts +0 -47
  145. package/dist/src/tagPair/index.js +0 -93
  146. package/dist/src/transclude.d.ts +0 -167
  147. package/dist/src/transclude.js +0 -689
  148. package/dist/util/constants.js +0 -108
  149. package/dist/util/debug.js +0 -64
  150. package/dist/util/diff.js +0 -72
  151. package/dist/util/lint.js +0 -48
  152. package/dist/util/string.js +0 -61
  153. package/errors/README +0 -1
  154. package/printed/README +0 -1
@@ -1,108 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.promises = exports.typeAliases = exports.aliases = exports.parsers = exports.mixins = exports.classes = exports.MAX_STAGE = void 0;
4
- exports.MAX_STAGE = 11;
5
- /* NOT FOR BROWSER */
6
- exports.classes = {};
7
- exports.mixins = {};
8
- exports.parsers = {};
9
- exports.aliases = [
10
- ['AstText'],
11
- ['CommentToken', 'ExtToken', 'IncludeToken', 'NoincludeToken'],
12
- ['ArgToken', 'TranscludeToken', 'HeadingToken'],
13
- ['HtmlToken'],
14
- ['TableToken'],
15
- ['HrToken', 'DoubleUnderscoreToken'],
16
- ['LinkToken', 'FileToken', 'CategoryToken'],
17
- ['QuoteToken'],
18
- ['ExtLinkToken'],
19
- ['MagicLinkToken'],
20
- ['ListToken', 'DdToken'],
21
- ['ConverterToken'],
22
- ];
23
- exports.typeAliases = {
24
- text: ['string', 'str'],
25
- plain: ['regular', 'normal'],
26
- root: undefined,
27
- // comment and extension
28
- onlyinclude: ['only-include'],
29
- noinclude: ['no-include'],
30
- include: ['includeonly', 'include-only'],
31
- comment: undefined,
32
- ext: ['extension'],
33
- 'ext-attrs': ['extension-attrs', 'ext-attributes', 'extension-attributes'],
34
- 'ext-attr-dirty': ['extension-attr-dirty', 'ext-attribute-dirty', 'extension-attribute-dirty'],
35
- 'ext-attr': ['extension-attr', 'ext-attribute', 'extension-attribute'],
36
- 'attr-key': ['attribute-key'],
37
- 'attr-value': ['attribute-value', 'attr-val', 'attribute-val'],
38
- 'ext-inner': ['extension-inner'],
39
- // triple braces
40
- arg: ['argument'],
41
- 'arg-name': ['argument-name'],
42
- 'arg-default': ['argument-default'],
43
- hidden: ['arg-redundant'],
44
- // double braces
45
- 'magic-word': ['parser-function', 'parser-func'],
46
- 'magic-word-name': ['parser-function-name', 'parser-func-name'],
47
- 'invoke-function': ['invoke-func', 'lua-function', 'lua-func', 'module-function', 'module-func'],
48
- 'invoke-module': ['lua-module'],
49
- template: undefined,
50
- 'template-name': undefined,
51
- parameter: ['param'],
52
- 'parameter-key': ['param-key'],
53
- 'parameter-value': ['parameter-val', 'param-value', 'param-val'],
54
- // heading
55
- heading: ['header'],
56
- 'heading-title': ['header-title'],
57
- 'heading-trail': ['header-trail'],
58
- // html
59
- html: undefined,
60
- 'html-attrs': ['html-attributes'],
61
- 'html-attr-dirty': ['html-attribute-dirty'],
62
- 'html-attr': ['html-attribute'],
63
- // table
64
- table: undefined,
65
- tr: ['table-row'],
66
- td: ['table-cell', 'table-data'],
67
- 'table-syntax': undefined,
68
- 'table-attrs': ['tr-attrs', 'td-attrs', 'table-attributes', 'tr-attributes', 'td-attributes'],
69
- 'table-attr-dirty': ['tr-attr-dirty', 'td-attr-dirty', 'table-attribute-dirty', 'tr-attribute-dirty', 'td-attribute-dirty'],
70
- 'table-attr': ['tr-attr', 'td-attr', 'table-attribute', 'tr-attribute', 'td-attribute'],
71
- 'table-inter': undefined,
72
- 'td-inner': ['table-cell-inner', 'table-data-inner'],
73
- // hr and double-underscore
74
- hr: ['horizontal'],
75
- 'double-underscore': ['underscore', 'behavior-switch', 'behaviour-switch'],
76
- // link
77
- link: ['wikilink'],
78
- 'link-target': ['wikilink-target'],
79
- 'link-text': ['wikilink-text'],
80
- category: ['category-link', 'cat', 'cat-link'],
81
- file: ['file-link', 'image', 'image-link', 'img', 'img-link'],
82
- 'gallery-image': ['gallery-file', 'gallery-img'],
83
- 'imagemap-image': ['imagemap-file', 'imagemap-img', 'image-map-image', 'image-map-file', 'image-map-img'],
84
- 'image-parameter': ['img-parameter', 'image-param', 'img-param'],
85
- // quotes
86
- quote: ['quotes', 'quot', 'apostrophe', 'apostrophes', 'apos'],
87
- // external link
88
- 'ext-link': ['external-link'],
89
- 'ext-link-text': ['external-link-text'],
90
- 'ext-link-url': ['external-link-url'],
91
- // magic link
92
- 'free-ext-link': ['free-external-link', 'magic-link'],
93
- // list
94
- list: ['ol', 'ordered-list', 'ul', 'unordered-list', 'dl', 'description-list'],
95
- dd: ['indent', 'indentation'],
96
- // converter
97
- converter: ['convert', 'conversion'],
98
- 'converter-flags': ['convert-flags', 'conversion-flags'],
99
- 'converter-flag': ['convert-flag', 'conversion-flag'],
100
- 'converter-rule': ['convert-rule', 'conversion-rule'],
101
- 'converter-rule-variant': ['convert-rule-variant', 'conversion-rule-variant'],
102
- 'converter-rule-to': ['convert-rule-to', 'conversion-rule-to', 'converter-rule-noconvert'],
103
- 'converter-rule-from': ['convert-rule-from', 'conversion-rule-from'],
104
- // specific extensions
105
- 'param-line': ['parameter-line'],
106
- 'imagemap-link': ['image-map-link'],
107
- };
108
- exports.promises = [Promise.resolve()];
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.undo = exports.Shadow = void 0;
4
- exports.Shadow = {
5
- /* NOT FOR BROWSER */
6
- running: false,
7
- /* NOT FOR BROWSER END */
8
- /** @private */
9
- run(callback) {
10
- const { running } = this;
11
- this.running = true;
12
- try {
13
- const result = callback();
14
- this.running = running;
15
- return result;
16
- }
17
- catch (e) {
18
- this.running = running;
19
- throw e;
20
- }
21
- },
22
- };
23
- /* NOT FOR BROWSER */
24
- /**
25
- * 撤销最近一次Mutation
26
- * @param e 事件
27
- * @param data 事件数据
28
- * @throws `RangeError` 无法撤销的事件类型
29
- */
30
- const undo = (e, data) => {
31
- const { target, type } = e;
32
- switch (data.type) {
33
- case 'remove': {
34
- const childNodes = [...target.childNodes];
35
- childNodes.splice(data.position, 0, data.removed);
36
- data.removed.setAttribute('parentNode', target);
37
- target.setAttribute('childNodes', childNodes);
38
- break;
39
- }
40
- case 'insert': {
41
- const childNodes = [...target.childNodes];
42
- childNodes.splice(data.position, 1);
43
- data.inserted.setAttribute('parentNode', undefined);
44
- target.setAttribute('childNodes', childNodes);
45
- break;
46
- }
47
- case 'replace': {
48
- const { parentNode } = target, childNodes = [...parentNode.childNodes];
49
- childNodes.splice(data.position, 1, data.oldToken);
50
- data.oldToken.setAttribute('parentNode', parentNode);
51
- data.newToken.setAttribute('parentNode', undefined);
52
- parentNode.setAttribute('childNodes', childNodes);
53
- break;
54
- }
55
- case 'text':
56
- if (target.type === 'text') {
57
- target.replaceData(data.oldText);
58
- }
59
- break;
60
- default:
61
- throw new RangeError(`无法撤销未知类型的事件:${String(type)}`);
62
- }
63
- };
64
- exports.undo = undo;
package/dist/util/diff.js DELETED
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.diff = exports.cmd = void 0;
4
- const fs = require("fs/promises");
5
- const child_process_1 = require("child_process");
6
- process.on('unhandledRejection', e => {
7
- console.error(e);
8
- });
9
- /**
10
- * 将shell命令转化为Promise对象
11
- * @param command shell指令
12
- * @param args shell输入参数
13
- */
14
- const cmd = (command, args) => new Promise(resolve => {
15
- let timer, shell;
16
- /**
17
- * 清除进程并返回
18
- * @param val 返回值
19
- */
20
- const r = (val) => {
21
- clearTimeout(timer);
22
- shell?.kill('SIGINT');
23
- resolve(val);
24
- };
25
- try {
26
- shell = (0, child_process_1.spawn)(command, args);
27
- timer = setTimeout(() => {
28
- shell.kill('SIGINT');
29
- }, 60 * 1000);
30
- let buf = '';
31
- shell.stdout.on('data', data => {
32
- buf += String(data);
33
- });
34
- shell.stdout.on('end', () => {
35
- r(buf);
36
- });
37
- shell.on('exit', () => {
38
- r(shell.killed ? undefined : '');
39
- });
40
- shell.on('error', () => {
41
- r(undefined);
42
- });
43
- }
44
- catch {
45
- r(undefined);
46
- }
47
- });
48
- exports.cmd = cmd;
49
- /**
50
- * 比较两个文件
51
- * @param oldStr 旧文本
52
- * @param newStr 新文本
53
- * @param uid 唯一标识
54
- */
55
- const diff = async (oldStr, newStr, uid = -1) => {
56
- if (oldStr === newStr) {
57
- return;
58
- }
59
- const oldFile = `diffOld${uid}`, newFile = `diffNew${uid}`;
60
- await Promise.all([fs.writeFile(oldFile, oldStr), fs.writeFile(newFile, newStr)]);
61
- const stdout = await (0, exports.cmd)('git', [
62
- 'diff',
63
- '--color-words=[\xC0-\xFF][\x80-\xBF]+|<?/?\\w+/?>?|[^[:space:]]',
64
- '-U0',
65
- '--no-index',
66
- oldFile,
67
- newFile,
68
- ]);
69
- await Promise.all([fs.unlink(oldFile), fs.unlink(newFile)]);
70
- console.log(stdout?.split('\n').slice(4).join('\n'));
71
- };
72
- exports.diff = diff;
package/dist/util/lint.js DELETED
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateForSelf = exports.generateForChild = void 0;
4
- const Parser = require("../index");
5
- /**
6
- * 生成对于子节点的LintError对象
7
- * @param child 子节点
8
- * @param boundingRect 父节点的绝对定位
9
- * @param msg 错误信息
10
- * @param severity 严重程度
11
- */
12
- const generateForChild = (child, boundingRect, msg, severity = 'error') => {
13
- const index = child.getRelativeIndex(), { offsetHeight, offsetWidth, parentNode } = child, { top: offsetTop, left: offsetLeft } = parentNode.posFromIndex(index), { start } = boundingRect, { top, left } = 'top' in boundingRect ? boundingRect : child.getRootNode().posFromIndex(start), str = String(child), startIndex = start + index, startLine = top + offsetTop, startCol = offsetTop ? offsetLeft : left + offsetLeft;
14
- return {
15
- message: Parser.msg(msg),
16
- severity,
17
- startIndex,
18
- endIndex: startIndex + str.length,
19
- startLine,
20
- endLine: startLine + offsetHeight - 1,
21
- startCol,
22
- endCol: offsetHeight === 1 ? startCol + offsetWidth : offsetWidth,
23
- excerpt: str.slice(0, 50),
24
- };
25
- };
26
- exports.generateForChild = generateForChild;
27
- /**
28
- * 生成对于自己的LintError对象
29
- * @param token 节点
30
- * @param boundingRect 绝对定位
31
- * @param msg 错误信息
32
- * @param severity 严重程度
33
- */
34
- const generateForSelf = (token, boundingRect, msg, severity = 'error') => {
35
- const { start } = boundingRect, { offsetHeight, offsetWidth } = token, str = String(token), { top, left } = 'top' in boundingRect ? boundingRect : token.getRootNode().posFromIndex(start);
36
- return {
37
- message: Parser.msg(msg),
38
- severity,
39
- startIndex: start,
40
- endIndex: start + str.length,
41
- startLine: top,
42
- endLine: top + offsetHeight - 1,
43
- startCol: left,
44
- endCol: offsetHeight === 1 ? left + offsetWidth : offsetWidth,
45
- excerpt: str.slice(0, 50),
46
- };
47
- };
48
- exports.generateForSelf = generateForSelf;
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeSpace = exports.print = exports.noWrap = exports.decodeHtml = exports.text = exports.escapeRegExp = exports.removeComment = exports.extUrlChar = exports.extUrlCharFirst = void 0;
4
- exports.extUrlCharFirst = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD])';
5
- exports.extUrlChar = '(?:[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD]|\\0\\d+[c!~]\\x7F)*';
6
- /**
7
- * remove half-parsed comment-like tokens
8
- * @param str 原字符串
9
- */
10
- const removeComment = (str) => str.replace(/\0\d+c\x7F/gu, '');
11
- exports.removeComment = removeComment;
12
- /**
13
- * escape special chars for RegExp constructor
14
- * @param str RegExp source
15
- */
16
- const escapeRegExp = (str) => str.replace(/[\\{}()|.?*+^$[\]]/gu, '\\$&');
17
- exports.escapeRegExp = escapeRegExp;
18
- /**
19
- * extract effective wikitext
20
- * @param childNodes a Token's contents
21
- * @param separator delimiter between nodes
22
- */
23
- const text = (childNodes, separator = '') => childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
24
- exports.text = text;
25
- /**
26
- * decode HTML entities
27
- * @param str 原字符串
28
- */
29
- const decodeHtml = (str) => str.replace(/&#(\d+|x[\da-f]+);/giu, (_, code) => String.fromCodePoint(Number(`${code.toLowerCase().startsWith('x') ? '0' : ''}${code}`)));
30
- exports.decodeHtml = decodeHtml;
31
- /**
32
- * escape newlines
33
- * @param str 原字符串
34
- */
35
- const noWrap = (str) => str.replaceAll('\n', '\\n');
36
- exports.noWrap = noWrap;
37
- /**
38
- * 以HTML格式打印
39
- * @param childNodes 子节点
40
- * @param opt 选项
41
- */
42
- const print = (childNodes, opt = {}) => {
43
- const { pre = '', post = '', sep = '' } = opt;
44
- return `${pre}${childNodes.map(child => child.print()).join(sep)}${post}`;
45
- };
46
- exports.print = print;
47
- /* NOT FOR BROWSER */
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;
package/errors/README DELETED
@@ -1 +0,0 @@
1
- 这里记录解析失败时处于半解析状态的维基文本以及错误信息。
package/printed/README DELETED
@@ -1 +0,0 @@
1
- 这里存放以 JSON 格式打印的 AST。