wikiparser-node 0.8.1 → 0.9.0-m

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 (83) hide show
  1. package/config/default.json +0 -1
  2. package/config/llwiki.json +0 -35
  3. package/config/moegirl.json +1 -44
  4. package/config/zhwiki.json +0 -466
  5. package/i18n/zh-hans.json +44 -0
  6. package/i18n/zh-hant.json +44 -0
  7. package/index.js +16 -256
  8. package/lib/element.js +29 -504
  9. package/lib/node.js +6 -542
  10. package/lib/text.js +10 -127
  11. package/lib/title.js +7 -32
  12. package/mixin/hidden.js +0 -3
  13. package/package.json +8 -8
  14. package/parser/brackets.js +8 -3
  15. package/parser/commentAndExt.js +1 -5
  16. package/parser/converter.js +0 -1
  17. package/parser/externalLinks.js +0 -1
  18. package/parser/hrAndDoubleUnderscore.js +0 -1
  19. package/parser/html.js +0 -1
  20. package/parser/links.js +5 -6
  21. package/parser/list.js +0 -1
  22. package/parser/magicLinks.js +0 -1
  23. package/parser/quotes.js +1 -2
  24. package/parser/table.js +0 -1
  25. package/src/arg.js +9 -119
  26. package/src/atom/hidden.js +0 -2
  27. package/src/atom/index.js +0 -17
  28. package/src/attribute.js +7 -181
  29. package/src/attributes.js +8 -312
  30. package/src/converter.js +2 -108
  31. package/src/converterFlags.js +3 -190
  32. package/src/converterRule.js +3 -187
  33. package/src/extLink.js +2 -121
  34. package/src/gallery.js +5 -62
  35. package/src/hasNowiki/index.js +0 -12
  36. package/src/hasNowiki/pre.js +0 -12
  37. package/src/heading.js +7 -58
  38. package/src/html.js +18 -127
  39. package/src/imageParameter.js +61 -200
  40. package/src/imagemap.js +7 -66
  41. package/src/imagemapLink.js +2 -14
  42. package/src/index.js +11 -534
  43. package/src/link/category.js +1 -37
  44. package/src/link/file.js +18 -168
  45. package/src/link/galleryImage.js +6 -64
  46. package/src/link/index.js +9 -277
  47. package/src/magicLink.js +2 -85
  48. package/src/nested/choose.js +0 -1
  49. package/src/nested/combobox.js +0 -1
  50. package/src/nested/index.js +3 -33
  51. package/src/nested/references.js +0 -1
  52. package/src/nowiki/comment.js +3 -27
  53. package/src/nowiki/dd.js +1 -47
  54. package/src/nowiki/doubleUnderscore.js +1 -31
  55. package/src/nowiki/hr.js +1 -20
  56. package/src/nowiki/index.js +3 -25
  57. package/src/nowiki/list.js +2 -5
  58. package/src/nowiki/noinclude.js +0 -14
  59. package/src/nowiki/quote.js +3 -17
  60. package/src/onlyinclude.js +1 -26
  61. package/src/paramTag/index.js +4 -27
  62. package/src/paramTag/inputbox.js +1 -4
  63. package/src/parameter.js +7 -149
  64. package/src/syntax.js +0 -68
  65. package/src/table/index.js +4 -942
  66. package/src/table/td.js +9 -230
  67. package/src/table/tr.js +4 -249
  68. package/src/tagPair/ext.js +13 -27
  69. package/src/tagPair/include.js +0 -24
  70. package/src/tagPair/index.js +2 -51
  71. package/src/transclude.js +38 -528
  72. package/util/lint.js +8 -7
  73. package/util/string.js +12 -44
  74. package/README.md +0 -39
  75. package/lib/ranges.js +0 -130
  76. package/mixin/attributeParent.js +0 -117
  77. package/mixin/fixedToken.js +0 -40
  78. package/mixin/singleLine.js +0 -31
  79. package/mixin/sol.js +0 -65
  80. package/parser/selector.js +0 -177
  81. package/src/charinsert.js +0 -97
  82. package/tool/index.js +0 -1202
  83. package/util/debug.js +0 -73
package/src/syntax.js CHANGED
@@ -1,8 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const Parser = require('..'),
4
- {undo} = require('../util/debug'),
5
- {text} = require('../util/string'),
6
4
  Token = require('.');
7
5
 
8
6
  /**
@@ -10,82 +8,16 @@ const Parser = require('..'),
10
8
  * @classdesc `{childNodes: ...AstText|Token}`
11
9
  */
12
10
  class SyntaxToken extends Token {
13
- #pattern;
14
-
15
11
  /**
16
12
  * @param {string} wikitext 语法wikitext
17
13
  * @param {RegExp} pattern 语法正则
18
14
  * @param {string} type Token.type
19
15
  * @param {accum} accum
20
- * @param {acceptable} acceptable 可接受的子节点设置
21
- * @throws `RangeError` 含有g修饰符的语法正则
22
16
  */
23
17
  constructor(wikitext, pattern, type = 'plain', config = Parser.getConfig(), accum = [], acceptable = undefined) {
24
- if (pattern.global) {
25
- throw new RangeError(`SyntaxToken 的语法正则不能含有 g 修饰符:${pattern}`);
26
- }
27
18
  super(wikitext, config, true, accum, acceptable);
28
19
  this.type = type;
29
- this.#pattern = pattern;
30
- }
31
-
32
- /** @override */
33
- cloneNode() {
34
- const cloned = this.cloneChildNodes(),
35
- config = this.getAttribute('config'),
36
- acceptable = this.getAttribute('acceptable');
37
- return Parser.run(() => {
38
- const token = new SyntaxToken(undefined, this.#pattern, this.type, config, [], acceptable);
39
- token.append(...cloned);
40
- token.afterBuild();
41
- return token;
42
- });
43
- }
44
-
45
- /** @override */
46
- afterBuild() {
47
- const /** @type {AstListener} */ syntaxListener = (e, data) => {
48
- const pattern = this.#pattern;
49
- if (!Parser.running && !pattern.test(this.text())) {
50
- undo(e, data);
51
- Parser.error(`不可修改 ${this.constructor.name} 的语法!`, pattern);
52
- throw new Error(`不可修改 ${this.constructor.name} 的语法!`);
53
- }
54
- };
55
- this.addEventListener(['remove', 'insert', 'replace', 'text'], syntaxListener);
56
- }
57
-
58
- /**
59
- * @override
60
- * @template {string} T
61
- * @param {T} key 属性键
62
- * @returns {TokenAttribute<T>}
63
- */
64
- getAttribute(key) {
65
- return key === 'pattern' ? this.#pattern : super.getAttribute(key);
66
- }
67
-
68
- /**
69
- * @override
70
- * @param {PropertyKey} key 属性键
71
- */
72
- hasAttribute(key) {
73
- return key === 'pattern' || super.hasAttribute(key);
74
- }
75
-
76
- /**
77
- * @override
78
- * @param {...Token} elements 待替换的子节点
79
- * @complexity `n`
80
- */
81
- replaceChildren(...elements) {
82
- if (this.#pattern.test(text(elements))) {
83
- Parser.run(() => {
84
- super.replaceChildren(...elements);
85
- });
86
- }
87
20
  }
88
21
  }
89
22
 
90
- Parser.classes.SyntaxToken = __filename;
91
23
  module.exports = SyntaxToken;