wikiparser-node 0.6.1 → 0.6.5-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 (82) hide show
  1. package/bundle/bundle.min.js +40 -0
  2. package/package.json +9 -11
  3. package/README.md +0 -39
  4. package/config/default.json +0 -832
  5. package/config/llwiki.json +0 -630
  6. package/config/moegirl.json +0 -727
  7. package/config/zhwiki.json +0 -1269
  8. package/index.js +0 -277
  9. package/lib/element.js +0 -612
  10. package/lib/node.js +0 -771
  11. package/lib/ranges.js +0 -130
  12. package/lib/text.js +0 -175
  13. package/lib/title.js +0 -70
  14. package/mixin/attributeParent.js +0 -113
  15. package/mixin/fixedToken.js +0 -40
  16. package/mixin/hidden.js +0 -21
  17. package/mixin/sol.js +0 -68
  18. package/parser/brackets.js +0 -118
  19. package/parser/commentAndExt.js +0 -63
  20. package/parser/converter.js +0 -45
  21. package/parser/externalLinks.js +0 -31
  22. package/parser/hrAndDoubleUnderscore.js +0 -36
  23. package/parser/html.js +0 -42
  24. package/parser/links.js +0 -97
  25. package/parser/list.js +0 -59
  26. package/parser/magicLinks.js +0 -41
  27. package/parser/quotes.js +0 -64
  28. package/parser/selector.js +0 -175
  29. package/parser/table.js +0 -114
  30. package/src/arg.js +0 -198
  31. package/src/atom/hidden.js +0 -13
  32. package/src/atom/index.js +0 -43
  33. package/src/attribute.js +0 -460
  34. package/src/charinsert.js +0 -91
  35. package/src/converter.js +0 -176
  36. package/src/converterFlags.js +0 -279
  37. package/src/converterRule.js +0 -259
  38. package/src/extLink.js +0 -175
  39. package/src/gallery.js +0 -146
  40. package/src/hasNowiki/index.js +0 -42
  41. package/src/hasNowiki/pre.js +0 -40
  42. package/src/heading.js +0 -123
  43. package/src/html.js +0 -230
  44. package/src/imageParameter.js +0 -276
  45. package/src/imagemap.js +0 -205
  46. package/src/imagemapLink.js +0 -43
  47. package/src/index.js +0 -842
  48. package/src/link/category.js +0 -49
  49. package/src/link/file.js +0 -321
  50. package/src/link/galleryImage.js +0 -125
  51. package/src/link/index.js +0 -347
  52. package/src/magicLink.js +0 -135
  53. package/src/nested/choose.js +0 -24
  54. package/src/nested/combobox.js +0 -23
  55. package/src/nested/index.js +0 -88
  56. package/src/nested/references.js +0 -23
  57. package/src/nowiki/comment.js +0 -71
  58. package/src/nowiki/dd.js +0 -59
  59. package/src/nowiki/doubleUnderscore.js +0 -56
  60. package/src/nowiki/hr.js +0 -41
  61. package/src/nowiki/index.js +0 -56
  62. package/src/nowiki/list.js +0 -16
  63. package/src/nowiki/noinclude.js +0 -28
  64. package/src/nowiki/quote.js +0 -63
  65. package/src/onlyinclude.js +0 -61
  66. package/src/paramTag/index.js +0 -83
  67. package/src/paramTag/inputbox.js +0 -42
  68. package/src/parameter.js +0 -214
  69. package/src/syntax.js +0 -91
  70. package/src/table/index.js +0 -981
  71. package/src/table/td.js +0 -308
  72. package/src/table/tr.js +0 -299
  73. package/src/tagPair/ext.js +0 -122
  74. package/src/tagPair/include.js +0 -60
  75. package/src/tagPair/index.js +0 -126
  76. package/src/transclude.js +0 -751
  77. package/tool/index.js +0 -1199
  78. package/util/base.js +0 -17
  79. package/util/debug.js +0 -73
  80. package/util/diff.js +0 -76
  81. package/util/lint.js +0 -40
  82. package/util/string.js +0 -105
package/src/parameter.js DELETED
@@ -1,214 +0,0 @@
1
- 'use strict';
2
-
3
- const {noWrap} = require('../util/string'),
4
- fixedToken = require('../mixin/fixedToken'),
5
- Parser = require('..'),
6
- Token = require('.');
7
-
8
- /**
9
- * 模板或魔术字参数
10
- * @classdesc `{childNodes: [AtomToken, Token]}`
11
- */
12
- class ParameterToken extends fixedToken(Token) {
13
- type = 'parameter';
14
-
15
- /** 是否是匿名参数 */
16
- get anon() {
17
- return this.firstChild.childNodes.length === 0;
18
- }
19
-
20
- /** getValue()的getter */
21
- get value() {
22
- return this.getValue();
23
- }
24
-
25
- set value(value) {
26
- this.setValue(value);
27
- }
28
-
29
- /**
30
- * 是否是重复参数
31
- * @this {ParameterToken & {parentNode: TranscludeToken}}
32
- */
33
- get duplicated() {
34
- const TranscludeToken = require('./transclude');
35
- try {
36
- return Boolean(this.parentNode?.getDuplicatedArgs()?.some(([key]) => key === this.name));
37
- } catch {
38
- return false;
39
- }
40
- }
41
-
42
- /**
43
- * @param {string|number} key 参数名
44
- * @param {string} value 参数值
45
- * @param {accum} accum
46
- */
47
- constructor(key, value, config = Parser.getConfig(), accum = []) {
48
- super(undefined, config, true, accum);
49
- const AtomToken = require('./atom');
50
- const keyToken = new AtomToken(typeof key === 'number' ? undefined : key, 'parameter-key', config, accum, {
51
- 'Stage-2': ':', '!HeadingToken': '',
52
- }),
53
- token = new Token(value, config, true, accum);
54
- token.type = 'parameter-value';
55
- this.append(keyToken, token.setAttribute('stage', 2));
56
- }
57
-
58
- /** @override */
59
- afterBuild() {
60
- if (!this.anon) {
61
- const TranscludeToken = require('./transclude');
62
- const name = this.firstChild.text().trim(),
63
- {parentNode} = this;
64
- this.setAttribute('name', name);
65
- if (parentNode && parentNode instanceof TranscludeToken) {
66
- parentNode.getAttribute('keys').add(name);
67
- parentNode.getArgs(name, false, false).add(this);
68
- }
69
- }
70
- const /** @type {AstListener} */ parameterListener = ({prevTarget}, data) => {
71
- if (!this.anon) { // 匿名参数不管怎么变动还是匿名
72
- const {firstChild, name} = this;
73
- if (prevTarget === firstChild) {
74
- const newKey = firstChild.text().trim();
75
- data.oldKey = name;
76
- data.newKey = newKey;
77
- this.setAttribute('name', newKey);
78
- }
79
- }
80
- };
81
- this.addEventListener(['remove', 'insert', 'replace', 'text'], parameterListener);
82
- return this;
83
- }
84
-
85
- /**
86
- * @override
87
- * @param {string} selector
88
- * @returns {string}
89
- */
90
- toString(selector) {
91
- return this.anon && !(selector && this.matches(selector))
92
- ? this.lastChild.toString(selector)
93
- : super.toString(selector, '=');
94
- }
95
-
96
- /** @override */
97
- getGaps() {
98
- return this.anon ? 0 : 1;
99
- }
100
-
101
- /** @override */
102
- print() {
103
- return super.print({sep: this.anon ? '' : '='});
104
- }
105
-
106
- /** @override */
107
- cloneNode() {
108
- const [key, value] = this.cloneChildNodes(),
109
- config = this.getAttribute('config');
110
- return Parser.run(() => {
111
- const token = new ParameterToken(this.anon ? Number(this.name) : undefined, undefined, config);
112
- token.firstChild.safeReplaceWith(key);
113
- token.lastChild.safeReplaceWith(value);
114
- return token.afterBuild();
115
- });
116
- }
117
-
118
- /**
119
- * @override
120
- * @returns {string}
121
- */
122
- text() {
123
- return this.anon ? this.lastChild.text() : super.text('=');
124
- }
125
-
126
- /**
127
- * @override
128
- * @param {ParameterToken} token 待替换的节点
129
- * @complexity `n`
130
- */
131
- safeReplaceWith(token) {
132
- Parser.warn(`${this.constructor.name}.safeReplaceWith 方法退化到 replaceWith。`);
133
- return this.replaceWith(token);
134
- }
135
-
136
- /**
137
- * 获取参数值
138
- * @this {ParameterToken & {parentNode: TranscludeToken}}
139
- */
140
- getValue() {
141
- const TranscludeToken = require('./transclude');
142
- const value = this.lastChild.text();
143
- return this.anon && this.parentNode?.isTemplate() ? value : value.trim();
144
- }
145
-
146
- /**
147
- * 设置参数值
148
- * @this {ParameterToken & {parentNode: TranscludeToken}}
149
- * @param {string} value 参数值
150
- * @throws `SyntaxError` 非法的模板参数
151
- */
152
- setValue(value) {
153
- value = String(value);
154
- const TranscludeToken = require('./transclude');
155
- const templateLike = this.parentNode?.isTemplate(),
156
- wikitext = `{{${templateLike ? ':T|' : 'lc:'}${this.anon ? '' : '1='}${value}}}`,
157
- root = Parser.parse(wikitext, this.getAttribute('include'), 2, this.getAttribute('config')),
158
- {length, firstChild: transclude} = root,
159
- /** @type {Token & {lastChild: ParameterToken}} */
160
- {lastChild: parameter, type, name, length: transcludeLength} = transclude,
161
- targetType = templateLike ? 'template' : 'magic-word',
162
- targetName = templateLike ? 'T' : 'lc';
163
- if (length !== 1 || type !== targetType || name !== targetName || transcludeLength !== 2
164
- || parameter.anon !== this.anon || parameter.name !== '1'
165
- ) {
166
- throw new SyntaxError(`非法的模板参数:${noWrap(value)}`);
167
- }
168
- const {lastChild} = parameter;
169
- parameter.destroy(true);
170
- this.lastChild.safeReplaceWith(lastChild);
171
- }
172
-
173
- /**
174
- * 修改参数名
175
- * @this {ParameterToken & {parentNode: TranscludeToken}}
176
- * @param {string} key 新参数名
177
- * @param {boolean} force 是否无视冲突命名
178
- * @throws `Error` 仅用于模板参数
179
- * @throws `SyntaxError` 非法的模板参数名
180
- * @throws `RangeError` 更名造成重复参数
181
- */
182
- rename(key, force) {
183
- if (typeof key !== 'string') {
184
- this.typeError('rename', 'String');
185
- }
186
- const TranscludeToken = require('./transclude');
187
- const {parentNode} = this;
188
- // 必须检测是否是TranscludeToken
189
- if (!parentNode?.isTemplate() || !(parentNode instanceof TranscludeToken)) {
190
- throw new Error(`${this.constructor.name}.rename 方法仅用于模板参数!`);
191
- }
192
- const root = Parser.parse(`{{:T|${key}=}}`, this.getAttribute('include'), 2, this.getAttribute('config')),
193
- {length, firstChild: template} = root,
194
- {type, name, lastChild: parameter, length: templateLength} = template;
195
- if (length !== 1 || type !== 'template' || name !== 'T' || templateLength !== 2) {
196
- throw new SyntaxError(`非法的模板参数名:${key}`);
197
- }
198
- const {name: parameterName, firstChild} = parameter;
199
- if (this.name === parameterName) {
200
- Parser.warn('未改变实际参数名', parameterName);
201
- } else if (parentNode.hasArg(parameterName)) {
202
- if (force) {
203
- Parser.warn('参数更名造成重复参数', parameterName);
204
- } else {
205
- throw new RangeError(`参数更名造成重复参数:${parameterName}`);
206
- }
207
- }
208
- parameter.destroy(true);
209
- this.firstChild.safeReplaceWith(firstChild);
210
- }
211
- }
212
-
213
- Parser.classes.ParameterToken = __filename;
214
- module.exports = ParameterToken;
package/src/syntax.js DELETED
@@ -1,91 +0,0 @@
1
- 'use strict';
2
-
3
- const {undo} = require('../util/debug'),
4
- {text} = require('../util/string'),
5
- Parser = require('..'),
6
- Token = require('.');
7
-
8
- /**
9
- * 满足特定语法格式的plain Token
10
- * @classdesc `{childNodes: ...AstText|Token}`
11
- */
12
- class SyntaxToken extends Token {
13
- #pattern;
14
-
15
- /**
16
- * @param {string} wikitext 语法wikitext
17
- * @param {RegExp} pattern 语法正则
18
- * @param {string} type Token.type
19
- * @param {accum} accum
20
- * @param {acceptable} acceptable 可接受的子节点设置
21
- * @throws `RangeError` 含有g修饰符的语法正则
22
- */
23
- constructor(wikitext, pattern, type = 'plain', config = Parser.getConfig(), accum = [], acceptable = null) {
24
- if (pattern.global) {
25
- throw new RangeError(`SyntaxToken 的语法正则不能含有 g 修饰符:${pattern}`);
26
- }
27
- super(wikitext, config, true, accum, acceptable);
28
- 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
- return token.afterBuild();
41
- });
42
- }
43
-
44
- /** @override */
45
- afterBuild() {
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
- };
54
- this.addEventListener(['remove', 'insert', 'replace', 'text'], syntaxListener);
55
- return this;
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
- }
88
- }
89
-
90
- Parser.classes.SyntaxToken = __filename;
91
- module.exports = SyntaxToken;