wikiparser-node 0.3.1 → 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 (80) hide show
  1. package/README.md +1 -1
  2. package/config/default.json +13 -17
  3. package/config/llwiki.json +11 -79
  4. package/config/moegirl.json +7 -1
  5. package/config/zhwiki.json +1269 -0
  6. package/index.js +130 -97
  7. package/lib/element.js +410 -518
  8. package/lib/node.js +493 -115
  9. package/lib/ranges.js +27 -19
  10. package/lib/text.js +175 -0
  11. package/lib/title.js +14 -6
  12. package/mixin/attributeParent.js +70 -24
  13. package/mixin/fixedToken.js +18 -10
  14. package/mixin/hidden.js +6 -4
  15. package/mixin/sol.js +39 -12
  16. package/package.json +17 -4
  17. package/parser/brackets.js +18 -18
  18. package/parser/commentAndExt.js +16 -14
  19. package/parser/converter.js +14 -13
  20. package/parser/externalLinks.js +12 -11
  21. package/parser/hrAndDoubleUnderscore.js +24 -14
  22. package/parser/html.js +8 -7
  23. package/parser/links.js +13 -13
  24. package/parser/list.js +12 -11
  25. package/parser/magicLinks.js +11 -10
  26. package/parser/quotes.js +6 -5
  27. package/parser/selector.js +175 -0
  28. package/parser/table.js +31 -24
  29. package/src/arg.js +91 -43
  30. package/src/atom/hidden.js +5 -2
  31. package/src/atom/index.js +17 -9
  32. package/src/attribute.js +210 -101
  33. package/src/converter.js +78 -43
  34. package/src/converterFlags.js +104 -45
  35. package/src/converterRule.js +136 -78
  36. package/src/extLink.js +81 -27
  37. package/src/gallery.js +63 -20
  38. package/src/heading.js +58 -20
  39. package/src/html.js +138 -48
  40. package/src/imageParameter.js +93 -58
  41. package/src/index.js +314 -186
  42. package/src/link/category.js +22 -54
  43. package/src/link/file.js +83 -32
  44. package/src/link/galleryImage.js +21 -7
  45. package/src/link/index.js +170 -81
  46. package/src/magicLink.js +64 -14
  47. package/src/nowiki/comment.js +36 -10
  48. package/src/nowiki/dd.js +37 -22
  49. package/src/nowiki/doubleUnderscore.js +21 -7
  50. package/src/nowiki/hr.js +11 -7
  51. package/src/nowiki/index.js +16 -9
  52. package/src/nowiki/list.js +2 -2
  53. package/src/nowiki/noinclude.js +8 -4
  54. package/src/nowiki/quote.js +38 -7
  55. package/src/onlyinclude.js +24 -7
  56. package/src/parameter.js +102 -62
  57. package/src/syntax.js +23 -20
  58. package/src/table/index.js +282 -174
  59. package/src/table/td.js +112 -61
  60. package/src/table/tr.js +135 -74
  61. package/src/tagPair/ext.js +30 -23
  62. package/src/tagPair/include.js +26 -11
  63. package/src/tagPair/index.js +72 -29
  64. package/src/transclude.js +235 -127
  65. package/tool/index.js +42 -32
  66. package/util/debug.js +21 -18
  67. package/util/diff.js +76 -0
  68. package/util/lint.js +40 -0
  69. package/util/string.js +56 -26
  70. package/.eslintrc.json +0 -319
  71. package/errors/README +0 -1
  72. package/jsconfig.json +0 -7
  73. package/printed/README +0 -1
  74. package/typings/element.d.ts +0 -28
  75. package/typings/index.d.ts +0 -52
  76. package/typings/node.d.ts +0 -23
  77. package/typings/parser.d.ts +0 -9
  78. package/typings/table.d.ts +0 -14
  79. package/typings/token.d.ts +0 -22
  80. package/typings/tool.d.ts +0 -10
package/src/syntax.js CHANGED
@@ -2,21 +2,23 @@
2
2
 
3
3
  const {undo} = require('../util/debug'),
4
4
  {text} = require('../util/string'),
5
- /** @type {Parser} */ Parser = require('..'),
5
+ Parser = require('..'),
6
6
  Token = require('.');
7
7
 
8
8
  /**
9
9
  * 满足特定语法格式的plain Token
10
- * @classdesc `{childNodes: (string|Token)[]}`
10
+ * @classdesc `{childNodes: (AstText|Token)[]}`
11
11
  */
12
12
  class SyntaxToken extends Token {
13
13
  #pattern;
14
14
 
15
15
  /**
16
- * @param {?string} wikitext
17
- * @param {RegExp} pattern
16
+ * @param {string} wikitext 语法wikitext
17
+ * @param {RegExp} pattern 语法正则
18
+ * @param {string} type Token.type
18
19
  * @param {accum} accum
19
- * @param {acceptable} acceptable
20
+ * @param {acceptable} acceptable 可接受的子节点设置
21
+ * @throws `RangeError` 含有g修饰符的语法正则
20
22
  */
21
23
  constructor(wikitext, pattern, type = 'plain', config = Parser.getConfig(), accum = [], acceptable = null) {
22
24
  if (pattern.global) {
@@ -27,8 +29,9 @@ class SyntaxToken extends Token {
27
29
  this.#pattern = pattern;
28
30
  }
29
31
 
32
+ /** @override */
30
33
  cloneNode() {
31
- const cloned = this.cloneChildren(),
34
+ const cloned = this.cloneChildNodes(),
32
35
  config = this.getAttribute('config'),
33
36
  acceptable = this.getAttribute('acceptable');
34
37
  return Parser.run(() => {
@@ -38,33 +41,33 @@ class SyntaxToken extends Token {
38
41
  });
39
42
  }
40
43
 
44
+ /** @override */
41
45
  afterBuild() {
42
- const that = this,
43
- /** @type {AstListener} */ syntaxListener = (e, data) => {
44
- const pattern = that.#pattern;
45
- if (!Parser.running && !pattern.test(that.text())) {
46
- undo(e, data);
47
- throw new Error(`不可修改 ${that.constructor.name} 的语法:/${pattern.source}/${pattern.flags}`);
48
- }
49
- };
46
+ const /** @type {AstListener} */ syntaxListener = (e, data) => {
47
+ const pattern = this.#pattern;
48
+ if (!Parser.running && !pattern.test(this.text())) {
49
+ undo(e, data);
50
+ Parser.error(`不可修改 ${this.constructor.name} 的语法!`, pattern);
51
+ throw new Error(`不可修改 ${this.constructor.name} 的语法!`);
52
+ }
53
+ };
50
54
  this.addEventListener(['remove', 'insert', 'replace', 'text'], syntaxListener);
51
55
  return this;
52
56
  }
53
57
 
54
58
  /**
59
+ * @override
55
60
  * @template {string} T
56
- * @param {T} key
61
+ * @param {T} key 属性键
57
62
  * @returns {TokenAttribute<T>}
58
63
  */
59
64
  getAttribute(key) {
60
- if (key === 'pattern') {
61
- return this.#pattern;
62
- }
63
- return super.getAttribute(key);
65
+ return key === 'pattern' ? this.#pattern : super.getAttribute(key);
64
66
  }
65
67
 
66
68
  /**
67
- * @param {...string|Token} elements
69
+ * @override
70
+ * @param {...Token} elements 待替换的子节点
68
71
  * @complexity `n`
69
72
  */
70
73
  replaceChildren(...elements) {