wikiparser-node 0.4.0 → 0.5.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 (65) hide show
  1. package/index.js +25 -2
  2. package/lib/element.js +69 -185
  3. package/lib/node.js +159 -1
  4. package/lib/ranges.js +1 -2
  5. package/lib/text.js +35 -6
  6. package/lib/title.js +1 -1
  7. package/mixin/fixedToken.js +4 -4
  8. package/mixin/sol.js +17 -7
  9. package/package.json +11 -1
  10. package/parser/commentAndExt.js +1 -1
  11. package/parser/converter.js +1 -1
  12. package/parser/externalLinks.js +1 -1
  13. package/parser/hrAndDoubleUnderscore.js +6 -5
  14. package/parser/links.js +1 -2
  15. package/parser/magicLinks.js +1 -1
  16. package/parser/selector.js +5 -5
  17. package/parser/table.js +12 -12
  18. package/src/arg.js +44 -20
  19. package/src/attribute.js +34 -7
  20. package/src/converter.js +13 -5
  21. package/src/converterFlags.js +42 -5
  22. package/src/converterRule.js +25 -19
  23. package/src/extLink.js +20 -14
  24. package/src/gallery.js +35 -4
  25. package/src/heading.js +28 -9
  26. package/src/html.js +46 -18
  27. package/src/imageParameter.js +13 -7
  28. package/src/index.js +22 -15
  29. package/src/link/category.js +6 -6
  30. package/src/link/file.js +25 -5
  31. package/src/link/index.js +36 -33
  32. package/src/magicLink.js +32 -4
  33. package/src/nowiki/comment.js +14 -0
  34. package/src/nowiki/doubleUnderscore.js +5 -0
  35. package/src/nowiki/quote.js +28 -1
  36. package/src/onlyinclude.js +5 -0
  37. package/src/parameter.js +48 -35
  38. package/src/table/index.js +37 -24
  39. package/src/table/td.js +23 -17
  40. package/src/table/tr.js +47 -30
  41. package/src/tagPair/ext.js +4 -5
  42. package/src/tagPair/include.js +10 -0
  43. package/src/tagPair/index.js +8 -0
  44. package/src/transclude.js +79 -46
  45. package/tool/index.js +1 -1
  46. package/{test/util.js → util/diff.js} +14 -18
  47. package/util/lint.js +40 -0
  48. package/util/string.js +20 -3
  49. package/.eslintrc.json +0 -714
  50. package/errors/README +0 -1
  51. package/jsconfig.json +0 -7
  52. package/printed/README +0 -1
  53. package/printed/example.json +0 -120
  54. package/test/api.js +0 -83
  55. package/test/real.js +0 -133
  56. package/test/test.js +0 -28
  57. package/typings/api.d.ts +0 -13
  58. package/typings/array.d.ts +0 -28
  59. package/typings/event.d.ts +0 -24
  60. package/typings/index.d.ts +0 -94
  61. package/typings/node.d.ts +0 -29
  62. package/typings/parser.d.ts +0 -16
  63. package/typings/table.d.ts +0 -14
  64. package/typings/token.d.ts +0 -22
  65. package/typings/tool.d.ts +0 -11
@@ -1,4 +1,5 @@
1
1
  'use strict';
2
+
2
3
  const {spawn} = require('child_process'),
3
4
  fs = require('fs/promises');
4
5
 
@@ -49,32 +50,27 @@ const cmd = (command, args) => new Promise(resolve => {
49
50
 
50
51
  /**
51
52
  * 比较两个文件
52
- * @param {string} oldfile 旧文件
53
- * @param {string} newfile 新文件
53
+ * @param {string} oldStr 旧文本
54
+ * @param {string} newStr 新文本
55
+ * @param {string} uid 唯一标识
54
56
  */
55
- const diff = async (oldfile, newfile) => {
56
- if (oldfile === newfile) {
57
+ const diff = async (oldStr, newStr, uid = '') => {
58
+ if (oldStr === newStr) {
57
59
  return;
58
60
  }
59
- await Promise.all([fs.writeFile('npmTestOldContent', oldfile), fs.writeFile('npmTestNewContent', newfile)]);
61
+ const oldFile = `diffOld${uid}`,
62
+ newFile = `diffNew${uid}`;
63
+ await Promise.all([fs.writeFile(oldFile, oldStr), fs.writeFile(newFile, newStr)]);
60
64
  const stdout = await cmd('git', [
61
65
  'diff',
62
- '--color-words=[\xc0-\xff][\x80-\xbf]+|<?/?\\w+/?>?|[^[:space:]]',
66
+ '--color-words=[\xC0-\xFF][\x80-\xBF]+|<?/?\\w+/?>?|[^[:space:]]',
63
67
  '-U0',
64
68
  '--no-index',
65
- 'npmTestOldContent',
66
- 'npmTestNewContent',
69
+ oldFile,
70
+ newFile,
67
71
  ]);
68
- await Promise.all([fs.unlink('npmTestOldContent'), fs.unlink('npmTestNewContent')]);
72
+ await Promise.all([fs.unlink(oldFile), fs.unlink(newFile)]);
69
73
  console.log(stdout?.split('\n')?.slice(4)?.join('\n'));
70
74
  };
71
75
 
72
- /**
73
- * 延时
74
- * @param {number} t 秒数
75
- */
76
- const sleep = t => new Promise(resolve => {
77
- setTimeout(resolve, t * 1000);
78
- });
79
-
80
- module.exports = {diff, sleep};
76
+ module.exports = diff;
package/util/lint.js ADDED
@@ -0,0 +1,40 @@
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 CHANGED
@@ -13,6 +13,23 @@ const toCase = (val, i) => i ? val.toLowerCase() : val;
13
13
  */
14
14
  const removeComment = str => str.replaceAll(/\0\d+c\x7F/gu, '');
15
15
 
16
+ /**
17
+ * 以HTML格式打印
18
+ * @param {(AstText|AstElement)[]} childNodes 子节点
19
+ * @param {printOpt} opt 选项
20
+ */
21
+ const print = (childNodes, opt = {}) => {
22
+ const AstText = require('../lib/text'),
23
+ AstElement = require('../lib/element');
24
+ const {pre = '', post = '', sep = ''} = opt,
25
+ entities = {'&': 'amp', '<': 'lt', '>': 'gt'};
26
+ return `${pre}${childNodes.map(
27
+ child => child instanceof AstElement
28
+ ? child.print()
29
+ : String(child).replaceAll(/[&<>]/gu, p => `&${entities[p]};`),
30
+ ).join(sep)}${post}`;
31
+ };
32
+
16
33
  /**
17
34
  * escape special chars for RegExp constructor
18
35
  * @param {string} str RegExp source
@@ -82,7 +99,7 @@ const normalizeSpace = token => {
82
99
  }
83
100
  };
84
101
 
85
- const extUrlChar = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1f\\x7f\\p{Zs}\\ufffd])'
86
- + '(?:[^[\\]<>"\\0-\\x1f\\x7f\\p{Zs}\\ufffd]|\\0\\d+c\\x7f)*';
102
+ const extUrlChar = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD])'
103
+ + '(?:[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD]|\\0\\d+c\\x7F)*';
87
104
 
88
- module.exports = {toCase, removeComment, escapeRegExp, text, explode, noWrap, normalizeSpace, extUrlChar};
105
+ module.exports = {toCase, removeComment, print, escapeRegExp, text, explode, noWrap, normalizeSpace, extUrlChar};