wikiparser-node 1.3.1 → 1.3.2-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 (156) 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/i18n/zh-hans.json +4 -3
  12. package/i18n/zh-hant.json +4 -3
  13. package/package.json +32 -12
  14. package/config/.schema.json +0 -172
  15. package/dist/addon/table.d.ts +0 -6
  16. package/dist/addon/table.js +0 -564
  17. package/dist/base.d.ts +0 -45
  18. package/dist/bin/toc.js +0 -18
  19. package/dist/index.d.ts +0 -31
  20. package/dist/index.js +0 -209
  21. package/dist/internal.d.ts +0 -44
  22. package/dist/lib/element.d.ts +0 -155
  23. package/dist/lib/element.js +0 -654
  24. package/dist/lib/node.d.ts +0 -146
  25. package/dist/lib/node.js +0 -419
  26. package/dist/lib/range.d.ts +0 -104
  27. package/dist/lib/range.js +0 -385
  28. package/dist/lib/ranges.d.ts +0 -26
  29. package/dist/lib/ranges.js +0 -117
  30. package/dist/lib/text.d.ts +0 -62
  31. package/dist/lib/text.js +0 -235
  32. package/dist/lib/title.d.ts +0 -38
  33. package/dist/lib/title.js +0 -162
  34. package/dist/mixin/attributesParent.js +0 -94
  35. package/dist/mixin/fixed.js +0 -32
  36. package/dist/mixin/flagsParent.js +0 -70
  37. package/dist/mixin/hidden.js +0 -22
  38. package/dist/mixin/magicLinkParent.js +0 -41
  39. package/dist/mixin/singleLine.js +0 -25
  40. package/dist/mixin/sol.js +0 -43
  41. package/dist/mixin/syntax.js +0 -56
  42. package/dist/parser/braces.js +0 -122
  43. package/dist/parser/commentAndExt.js +0 -69
  44. package/dist/parser/converter.js +0 -40
  45. package/dist/parser/externalLinks.js +0 -28
  46. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  47. package/dist/parser/html.js +0 -36
  48. package/dist/parser/links.js +0 -94
  49. package/dist/parser/list.js +0 -59
  50. package/dist/parser/magicLinks.js +0 -40
  51. package/dist/parser/quotes.js +0 -67
  52. package/dist/parser/selector.js +0 -162
  53. package/dist/parser/table.js +0 -112
  54. package/dist/src/arg.d.ts +0 -58
  55. package/dist/src/arg.js +0 -189
  56. package/dist/src/atom.d.ts +0 -12
  57. package/dist/src/atom.js +0 -27
  58. package/dist/src/attribute.d.ts +0 -86
  59. package/dist/src/attribute.js +0 -391
  60. package/dist/src/attributes.d.ts +0 -107
  61. package/dist/src/attributes.js +0 -341
  62. package/dist/src/converter.d.ts +0 -51
  63. package/dist/src/converter.js +0 -79
  64. package/dist/src/converterFlags.d.ts +0 -87
  65. package/dist/src/converterFlags.js +0 -222
  66. package/dist/src/converterRule.d.ts +0 -81
  67. package/dist/src/converterRule.js +0 -212
  68. package/dist/src/extLink.d.ts +0 -53
  69. package/dist/src/extLink.js +0 -121
  70. package/dist/src/gallery.d.ts +0 -55
  71. package/dist/src/gallery.js +0 -122
  72. package/dist/src/heading.d.ts +0 -72
  73. package/dist/src/heading.js +0 -127
  74. package/dist/src/hidden.d.ts +0 -21
  75. package/dist/src/hidden.js +0 -23
  76. package/dist/src/html.d.ts +0 -103
  77. package/dist/src/html.js +0 -222
  78. package/dist/src/imageParameter.d.ts +0 -66
  79. package/dist/src/imageParameter.js +0 -247
  80. package/dist/src/imagemap.d.ts +0 -57
  81. package/dist/src/imagemap.js +0 -148
  82. package/dist/src/imagemapLink.d.ts +0 -57
  83. package/dist/src/imagemapLink.js +0 -40
  84. package/dist/src/index.d.ts +0 -146
  85. package/dist/src/index.js +0 -777
  86. package/dist/src/link/base.d.ts +0 -52
  87. package/dist/src/link/base.js +0 -207
  88. package/dist/src/link/category.d.ts +0 -13
  89. package/dist/src/link/category.js +0 -29
  90. package/dist/src/link/file.d.ts +0 -96
  91. package/dist/src/link/file.js +0 -253
  92. package/dist/src/link/galleryImage.d.ts +0 -43
  93. package/dist/src/link/galleryImage.js +0 -106
  94. package/dist/src/link/index.d.ts +0 -53
  95. package/dist/src/link/index.js +0 -123
  96. package/dist/src/magicLink.d.ts +0 -69
  97. package/dist/src/magicLink.js +0 -147
  98. package/dist/src/nested.d.ts +0 -44
  99. package/dist/src/nested.js +0 -87
  100. package/dist/src/nowiki/base.d.ts +0 -46
  101. package/dist/src/nowiki/base.js +0 -42
  102. package/dist/src/nowiki/comment.d.ts +0 -39
  103. package/dist/src/nowiki/comment.js +0 -67
  104. package/dist/src/nowiki/dd.d.ts +0 -8
  105. package/dist/src/nowiki/dd.js +0 -25
  106. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -43
  107. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  108. package/dist/src/nowiki/hr.d.ts +0 -29
  109. package/dist/src/nowiki/hr.js +0 -14
  110. package/dist/src/nowiki/index.d.ts +0 -16
  111. package/dist/src/nowiki/index.js +0 -21
  112. package/dist/src/nowiki/list.d.ts +0 -29
  113. package/dist/src/nowiki/list.js +0 -48
  114. package/dist/src/nowiki/listBase.d.ts +0 -18
  115. package/dist/src/nowiki/listBase.js +0 -12
  116. package/dist/src/nowiki/noinclude.d.ts +0 -25
  117. package/dist/src/nowiki/noinclude.js +0 -25
  118. package/dist/src/nowiki/quote.d.ts +0 -22
  119. package/dist/src/nowiki/quote.js +0 -45
  120. package/dist/src/onlyinclude.d.ts +0 -16
  121. package/dist/src/onlyinclude.js +0 -57
  122. package/dist/src/paramTag/index.d.ts +0 -37
  123. package/dist/src/paramTag/index.js +0 -68
  124. package/dist/src/paramTag/inputbox.d.ts +0 -8
  125. package/dist/src/paramTag/inputbox.js +0 -23
  126. package/dist/src/parameter.d.ts +0 -84
  127. package/dist/src/parameter.js +0 -205
  128. package/dist/src/pre.d.ts +0 -28
  129. package/dist/src/pre.js +0 -51
  130. package/dist/src/syntax.d.ts +0 -24
  131. package/dist/src/syntax.js +0 -30
  132. package/dist/src/table/base.d.ts +0 -52
  133. package/dist/src/table/base.js +0 -78
  134. package/dist/src/table/index.d.ts +0 -229
  135. package/dist/src/table/index.js +0 -379
  136. package/dist/src/table/td.d.ts +0 -103
  137. package/dist/src/table/td.js +0 -261
  138. package/dist/src/table/tr.d.ts +0 -32
  139. package/dist/src/table/tr.js +0 -56
  140. package/dist/src/table/trBase.d.ts +0 -54
  141. package/dist/src/table/trBase.js +0 -158
  142. package/dist/src/tagPair/ext.d.ts +0 -58
  143. package/dist/src/tagPair/ext.js +0 -142
  144. package/dist/src/tagPair/include.d.ts +0 -52
  145. package/dist/src/tagPair/include.js +0 -58
  146. package/dist/src/tagPair/index.d.ts +0 -47
  147. package/dist/src/tagPair/index.js +0 -93
  148. package/dist/src/transclude.d.ts +0 -167
  149. package/dist/src/transclude.js +0 -689
  150. package/dist/util/constants.js +0 -108
  151. package/dist/util/debug.js +0 -64
  152. package/dist/util/diff.js +0 -72
  153. package/dist/util/lint.js +0 -46
  154. package/dist/util/string.js +0 -61
  155. package/errors/README +0 -1
  156. 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,46 +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), 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 + String(child).length,
19
- startLine,
20
- endLine: startLine + offsetHeight - 1,
21
- startCol,
22
- endCol: offsetHeight === 1 ? startCol + offsetWidth : offsetWidth,
23
- };
24
- };
25
- exports.generateForChild = generateForChild;
26
- /**
27
- * 生成对于自己的LintError对象
28
- * @param token 节点
29
- * @param boundingRect 绝对定位
30
- * @param msg 错误信息
31
- * @param severity 严重程度
32
- */
33
- const generateForSelf = (token, boundingRect, msg, severity = 'error') => {
34
- const { start } = boundingRect, { offsetHeight, offsetWidth } = token, { top, left } = 'top' in boundingRect ? boundingRect : token.getRootNode().posFromIndex(start);
35
- return {
36
- message: Parser.msg(msg),
37
- severity,
38
- startIndex: start,
39
- endIndex: start + String(token).length,
40
- startLine: top,
41
- endLine: top + offsetHeight - 1,
42
- startCol: left,
43
- endCol: offsetHeight === 1 ? left + offsetWidth : offsetWidth,
44
- };
45
- };
46
- 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。