wikiparser-node 1.2.0-b → 1.2.0

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/config/.schema.json +172 -0
  2. package/config/llwiki.json +35 -1
  3. package/config/moegirl.json +44 -1
  4. package/config/zhwiki.json +466 -1
  5. package/dist/addon/table.d.ts +6 -0
  6. package/dist/addon/table.js +564 -0
  7. package/dist/base.d.ts +46 -0
  8. package/dist/bin/toc.js +18 -0
  9. package/dist/index.d.ts +31 -0
  10. package/dist/index.js +209 -0
  11. package/dist/internal.d.ts +44 -0
  12. package/dist/lib/element.d.ts +155 -0
  13. package/dist/lib/element.js +654 -0
  14. package/dist/lib/node.d.ts +146 -0
  15. package/dist/lib/node.js +419 -0
  16. package/dist/lib/range.d.ts +104 -0
  17. package/dist/lib/range.js +385 -0
  18. package/dist/lib/ranges.d.ts +26 -0
  19. package/dist/lib/ranges.js +117 -0
  20. package/dist/lib/text.d.ts +62 -0
  21. package/dist/lib/text.js +235 -0
  22. package/dist/lib/title.d.ts +38 -0
  23. package/dist/lib/title.js +162 -0
  24. package/dist/mixin/attributesParent.js +94 -0
  25. package/dist/mixin/fixed.js +32 -0
  26. package/dist/mixin/flagsParent.js +70 -0
  27. package/dist/mixin/hidden.js +22 -0
  28. package/dist/mixin/magicLinkParent.js +41 -0
  29. package/dist/mixin/singleLine.js +25 -0
  30. package/dist/mixin/sol.js +43 -0
  31. package/dist/mixin/syntax.js +56 -0
  32. package/dist/parser/braces.js +123 -0
  33. package/dist/parser/commentAndExt.js +69 -0
  34. package/dist/parser/converter.js +40 -0
  35. package/dist/parser/externalLinks.js +28 -0
  36. package/dist/parser/hrAndDoubleUnderscore.js +38 -0
  37. package/dist/parser/html.js +36 -0
  38. package/dist/parser/links.js +94 -0
  39. package/dist/parser/list.js +59 -0
  40. package/dist/parser/magicLinks.js +40 -0
  41. package/dist/parser/quotes.js +67 -0
  42. package/dist/parser/selector.js +162 -0
  43. package/dist/parser/table.js +112 -0
  44. package/dist/src/arg.d.ts +58 -0
  45. package/dist/src/arg.js +190 -0
  46. package/dist/src/atom.d.ts +12 -0
  47. package/dist/src/atom.js +27 -0
  48. package/dist/src/attribute.d.ts +86 -0
  49. package/dist/src/attribute.js +392 -0
  50. package/dist/src/attributes.d.ts +107 -0
  51. package/dist/src/attributes.js +344 -0
  52. package/dist/src/converter.d.ts +51 -0
  53. package/dist/src/converter.js +79 -0
  54. package/dist/src/converterFlags.d.ts +87 -0
  55. package/dist/src/converterFlags.js +223 -0
  56. package/dist/src/converterRule.d.ts +81 -0
  57. package/dist/src/converterRule.js +212 -0
  58. package/dist/src/extLink.d.ts +53 -0
  59. package/dist/src/extLink.js +121 -0
  60. package/dist/src/gallery.d.ts +55 -0
  61. package/dist/src/gallery.js +123 -0
  62. package/dist/src/heading.d.ts +72 -0
  63. package/dist/src/heading.js +128 -0
  64. package/dist/src/hidden.d.ts +21 -0
  65. package/dist/src/hidden.js +23 -0
  66. package/dist/src/html.d.ts +103 -0
  67. package/dist/src/html.js +230 -0
  68. package/dist/src/imageParameter.d.ts +66 -0
  69. package/dist/src/imageParameter.js +247 -0
  70. package/dist/src/imagemap.d.ts +57 -0
  71. package/dist/src/imagemap.js +148 -0
  72. package/dist/src/imagemapLink.d.ts +57 -0
  73. package/dist/src/imagemapLink.js +40 -0
  74. package/dist/src/index.d.ts +146 -0
  75. package/dist/src/index.js +777 -0
  76. package/dist/src/link/base.d.ts +52 -0
  77. package/dist/src/link/base.js +207 -0
  78. package/dist/src/link/category.d.ts +13 -0
  79. package/dist/src/link/category.js +29 -0
  80. package/dist/src/link/file.d.ts +96 -0
  81. package/dist/src/link/file.js +253 -0
  82. package/dist/src/link/galleryImage.d.ts +43 -0
  83. package/dist/src/link/galleryImage.js +106 -0
  84. package/dist/src/link/index.d.ts +53 -0
  85. package/dist/src/link/index.js +123 -0
  86. package/dist/src/magicLink.d.ts +69 -0
  87. package/dist/src/magicLink.js +148 -0
  88. package/dist/src/nested.d.ts +44 -0
  89. package/dist/src/nested.js +87 -0
  90. package/dist/src/nowiki/base.d.ts +46 -0
  91. package/dist/src/nowiki/base.js +42 -0
  92. package/dist/src/nowiki/comment.d.ts +39 -0
  93. package/dist/src/nowiki/comment.js +67 -0
  94. package/dist/src/nowiki/dd.d.ts +8 -0
  95. package/dist/src/nowiki/dd.js +25 -0
  96. package/dist/src/nowiki/doubleUnderscore.d.ts +43 -0
  97. package/dist/src/nowiki/doubleUnderscore.js +50 -0
  98. package/dist/src/nowiki/hr.d.ts +29 -0
  99. package/dist/src/nowiki/hr.js +14 -0
  100. package/dist/src/nowiki/index.d.ts +16 -0
  101. package/dist/src/nowiki/index.js +21 -0
  102. package/dist/src/nowiki/list.d.ts +29 -0
  103. package/dist/src/nowiki/list.js +48 -0
  104. package/dist/src/nowiki/listBase.d.ts +18 -0
  105. package/dist/src/nowiki/listBase.js +12 -0
  106. package/dist/src/nowiki/noinclude.d.ts +25 -0
  107. package/dist/src/nowiki/noinclude.js +25 -0
  108. package/dist/src/nowiki/quote.d.ts +22 -0
  109. package/dist/src/nowiki/quote.js +50 -0
  110. package/dist/src/onlyinclude.d.ts +16 -0
  111. package/dist/src/onlyinclude.js +57 -0
  112. package/dist/src/paramTag/index.d.ts +37 -0
  113. package/dist/src/paramTag/index.js +68 -0
  114. package/dist/src/paramTag/inputbox.d.ts +8 -0
  115. package/dist/src/paramTag/inputbox.js +23 -0
  116. package/dist/src/parameter.d.ts +84 -0
  117. package/dist/src/parameter.js +206 -0
  118. package/dist/src/pre.d.ts +28 -0
  119. package/dist/src/pre.js +51 -0
  120. package/dist/src/syntax.d.ts +24 -0
  121. package/dist/src/syntax.js +30 -0
  122. package/dist/src/table/base.d.ts +52 -0
  123. package/dist/src/table/base.js +78 -0
  124. package/dist/src/table/index.d.ts +229 -0
  125. package/dist/src/table/index.js +380 -0
  126. package/dist/src/table/td.d.ts +103 -0
  127. package/dist/src/table/td.js +261 -0
  128. package/dist/src/table/tr.d.ts +32 -0
  129. package/dist/src/table/tr.js +56 -0
  130. package/dist/src/table/trBase.d.ts +54 -0
  131. package/dist/src/table/trBase.js +159 -0
  132. package/dist/src/tagPair/ext.d.ts +58 -0
  133. package/dist/src/tagPair/ext.js +142 -0
  134. package/dist/src/tagPair/include.d.ts +52 -0
  135. package/dist/src/tagPair/include.js +58 -0
  136. package/dist/src/tagPair/index.d.ts +47 -0
  137. package/dist/src/tagPair/index.js +93 -0
  138. package/dist/src/transclude.d.ts +167 -0
  139. package/dist/src/transclude.js +689 -0
  140. package/dist/util/constants.js +108 -0
  141. package/dist/util/debug.js +64 -0
  142. package/dist/util/diff.js +72 -0
  143. package/dist/util/lint.js +48 -0
  144. package/dist/util/string.js +61 -0
  145. package/errors/README +1 -0
  146. package/package.json +12 -32
  147. package/printed/README +1 -0
  148. package/bundle/bundle.min.js +0 -36
  149. package/extensions/dist/base.js +0 -68
  150. package/extensions/dist/editor.js +0 -159
  151. package/extensions/dist/highlight.js +0 -30
  152. package/extensions/dist/lint.js +0 -48
  153. package/extensions/editor.css +0 -63
  154. package/extensions/ui.css +0 -117
@@ -0,0 +1,108 @@
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()];
@@ -0,0 +1,64 @@
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;
@@ -0,0 +1,72 @@
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;
@@ -0,0 +1,48 @@
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;
@@ -0,0 +1,61 @@
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 ADDED
@@ -0,0 +1 @@
1
+ 这里记录解析失败时处于半解析状态的维基文本以及错误信息。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikiparser-node",
3
- "version": "1.2.0-b",
3
+ "version": "1.2.0",
4
4
  "description": "A Node.js parser for MediaWiki markup with AST",
5
5
  "keywords": [
6
6
  "mediawiki",
@@ -14,54 +14,37 @@
14
14
  "license": "GPL-3.0",
15
15
  "author": "Bhsd",
16
16
  "files": [
17
- "/bundle/bundle.min.js",
18
- "/extensions/dist/",
19
- "/extensions/*.css",
20
- "!/extensions/dist/gh-page.js",
21
- "!/extensions/gh-page.css",
17
+ "/errors/README",
18
+ "/printed/README",
22
19
  "/config/",
23
20
  "/i18n/",
24
- "!/config/.schema.json"
21
+ "/dist/"
25
22
  ],
26
- "browser": "/bundle/bundle.min.js",
27
- "main": "./bundle/bundle.js",
28
- "types": "./extensions/typings.d.ts",
23
+ "main": "./dist/index.js",
29
24
  "repository": {
30
25
  "type": "git",
31
26
  "url": "git+https://github.com/bhsd-harry/wikiparser-node.git"
32
27
  },
33
28
  "scripts": {
34
- "prepublishOnly": "npm run build:prod && npm run build:ext",
35
- "build:dev": "esbuild index.ts --bundle --target=es2018 --outfile=bundle/bundle.js",
36
- "build:prod": "esbuild index.ts --bundle --minify --target=es2018 --outfile=bundle/bundle.min.js",
37
- "build:core": "rm bundle/*.js; npm run build:dev; npm run build:prod; eslint --no-eslintrc -c .eslintrc.browser.json bundle/",
38
- "build:ext": "bash build-ext.sh",
39
- "build:test": "rm -rf dist/; tsc; gsed -i 's|../config/minimum|../../config/minimum|' dist/util/constants.js",
40
- "build": "npm run build:core && npm run build:ext",
29
+ "toc": "node ./dist/bin/toc.js",
30
+ "prepublishOnly": "npm run build; rm dist/internal.js dist/base.js dist/[bmpu]*/*.d.ts; rm -r dist/test",
31
+ "build": "rm -rf dist/; tsc; grep -rl --include='*.d.ts' '@private' dist/ | xargs gsed -i '/@private/,+1d'",
41
32
  "diff": "git diff --ignore-all-space --color-moved",
42
- "lint:ts": "tsc --noEmit && tsc --noEmit --project extensions/tsconfig.json && eslint --cache .",
33
+ "lint:ts": "tsc --noEmit && eslint --cache .",
43
34
  "lint:json": "ajv -s config/.schema.json -d 'config/*.json' --strict=true --strict-required=false",
44
- "lint:css": "stylelint extensions/*.css",
45
- "lint": "npm run lint:ts && npm run lint:json && npm run lint:css",
46
- "server": "http-server .. -c-1 --cors &",
47
- "test": "npm run server; open http://127.0.0.1:8080/wikiparser-node/index.html",
48
- "test:end": "pkill -x http-server",
35
+ "lint": "npm run lint:ts && npm run lint:json",
36
+ "test": "node dist/test/test.js",
49
37
  "test:real": "node dist/test/real.js",
50
- "test:single": "node dist/test/single.js"
38
+ "test:single": "node dist/test/single.js; node --prof dist/test/single.js && node --prof-process isolate-0x*-v8.log > test/processed.txt && rm isolate-0x*-v8.log"
51
39
  },
52
40
  "devDependencies": {
53
- "@bhsd/codemirror-mediawiki": "^2.0.13",
54
- "@codemirror/lint": "^6.4.2",
55
- "@codemirror/view": "^6.22.2",
56
41
  "@cypress/request": "^3.0.1",
57
42
  "@types/node": "^20.9.0",
58
43
  "@types/request": "^2.48.12",
59
44
  "@typescript-eslint/eslint-plugin": "^6.12.0",
60
45
  "@typescript-eslint/parser": "^6.12.0",
61
46
  "ajv-cli": "^5.0.0",
62
- "esbuild": "^0.19.7",
63
47
  "eslint": "^8.56.0",
64
- "eslint-plugin-es-x": "^7.3.0",
65
48
  "eslint-plugin-eslint-comments": "^3.2.0",
66
49
  "eslint-plugin-jsdoc": "^47.0.2",
67
50
  "eslint-plugin-json-es": "^1.5.7",
@@ -69,9 +52,6 @@
69
52
  "eslint-plugin-promise": "^6.1.1",
70
53
  "eslint-plugin-regexp": "^2.1.1",
71
54
  "eslint-plugin-unicorn": "^50.0.1",
72
- "http-server": "^14.1.0",
73
- "stylelint": "^15.11.0",
74
- "stylelint-config-recommended": "^13.0.0",
75
55
  "typescript": "^5.1.6"
76
56
  },
77
57
  "engines": {
package/printed/README ADDED
@@ -0,0 +1 @@
1
+ 这里存放以 JSON 格式打印的 AST。